Commit ffe42081 authored by Sergey.Luzyanin's avatar Sergey.Luzyanin Committed by Alexander.Trofimov

git-svn-id: svn://192.168.3.15/activex/AVS/Sources/TeamlabOffice/trunk/OfficeWeb@47566 954022d7-b5bf-4e40-9824-e11837661b57
parent b7a6181f
......@@ -150,8 +150,9 @@
<script src="model/DrawingObjects/Format/GroupShape.js"></script>
<script src="model/DrawingObjects/Format/Image.js"></script>
<script src="model/DrawingObjects/Format/Shape.js"></script>
<script src="model/DrawingObjects/Tracks/ResizeTracks.js"></script>
<script src="model/DrawingObjects/Tracks/AdjustmentTracks.js"></script>
<script src="model/DrawingObjects/Tracks/ResizeTracks.js"></script>
<script src="model/DrawingObjects/Tracks/RotateTracks.js"></script>
<script src="model/DrawingObjects/Tracks/NewShapeTracks.js"></script>
<script src="model/DrawingObjects/Hit.js"></script>
......
......@@ -82,6 +82,12 @@ DrawingObjectsController.prototype =
this.arrTrackObjects[i].track(dx, dy);
},
trackAdjObject: function(x, y)
{
if(this.arrTrackObjects.length > 0)
this.arrPreTrackObjects[0].track(x, y);
},
trackEnd: function()
{
for(var i = 0; i < this.arrTrackObjects.length; ++i)
......@@ -99,26 +105,166 @@ DrawingObjectsController.prototype =
this.arrTrackObjects[i].draw(overlay);
},
drawSelection: function(drawingDocument)
{
switch (this.curState.id)
{
default :
{
var selected_objects = this.selectedObjects;
for(var i = 0; i < selected_objects.length; ++i)
{
drawingDocument.DrawTrack(TYPE_TRACK_SHAPE, selected_objects[i].getTransform(), 0, 0, selected_objects[i].extX, selected_objects[i].extY, false, selected_objects[i].canRotate());
}
break;
}
}
},
isPointInDrawingObjects: function(x, y)
{
var selected_objects = this.selectedObjects;
var selected_objects = this.drawingObjectsController.selectedObjects;
if(selected_objects.length === 1)
{
if(selected_objects[0].hitToAdjustment(x, y).hit)
var hit_to_adj = selected_objects[0].hitToAdjustment(x, y);
if(hit_to_adj.hit)
{
return true;
}
}
for(var i = selected_objects.length - 1; i > -1; --i)
{
if(selected_objects[i].hitToHandles(x, y) > -1)
var hit_to_handles = selected_objects[i].hitToHandles(x, y);
if(hit_to_handles > -1)
{
if(hit_to_handles === 8)
{
if(!selected_objects[i].canRotate())
return false;
}
else
{
if(!selected_objects[i].canResize())
return false;
}
return true;
}
}
var arr_objects = [];//TODO
for(i = arr_objects.length - 1; i > -1; --i)
for(i = selected_objects.length - 1; i > -1; --i)
{
if(arr_objects[i].hit(x, y))
return true;
if(selected_objects[i].hitInBoundingRect(x, y))
{
return selected_objects[i].canMove();
}
}
var arr_drawing_objects = this.drawingObjects.getDrawingObjects();
for(i = arr_drawing_objects.length-1; i > -1; --i)
{
var cur_drawing_base = arr_drawing_objects[i];
if(cur_drawing_base.isGraphicObject())
{
var cur_drawing = cur_drawing_base.graphicObject;
if(cur_drawing.isSimpleObject())
{
var hit_in_inner_area = cur_drawing.hitInInnerArea(x, y);
var hit_in_path = cur_drawing.hitInPath(x, y);
var hit_in_text_rect = cur_drawing.hitInTextRect(x, y);
if(hit_in_inner_area && !hit_in_text_rect || hit_in_path)
{
if(!cur_drawing.canMove())
return false;
return true;
}
else if(hit_in_text_rect)
{
return false
}
}
else
{
}
}
}
return false;
},
isPointInDrawingObjects2: function(x, y)
{
var selected_objects = this.drawingObjectsController.selectedObjects;
if(selected_objects.length === 1)
{
var hit_to_adj = selected_objects[0].hitToAdjustment(x, y);
if(hit_to_adj.hit)
{
return true;
}
}
for(var i = selected_objects.length - 1; i > -1; --i)
{
var hit_to_handles = selected_objects[i].hitToHandles(x, y);
if(hit_to_handles > -1)
{
if(hit_to_handles === 8)
{
if(!selected_objects[i].canRotate())
return false;
}
else
{
if(!selected_objects[i].canResize())
return false;
}
return true;
}
}
for(i = selected_objects.length - 1; i > -1; --i)
{
if(selected_objects[i].hitInBoundingRect(x, y))
{
if(!selected_objects[i].canMove())
return;
for(var j = 0; j < selected_objects.length; ++j)
{
this.drawingObjectsController.addPreTrackObject(selected_objects[j].createMoveTrack());
}
this.drawingObjectsController.changeCurrentState(new PreMoveState(this.drawingObjectsController, this.drawingObjects, x, y));
return true;
}
}
var arr_drawing_objects = this.drawingObjects.getDrawingObjects();
for(i = arr_drawing_objects.length-1; i > -1; --i)
{
var cur_drawing_base = arr_drawing_objects[i];
if(cur_drawing_base.isGraphicObject())
{
var cur_drawing = cur_drawing_base.graphicObject;
if(cur_drawing.isSimpleObject())
{
var hit_in_inner_area = cur_drawing.hitInInnerArea(x, y);
var hit_in_path = cur_drawing.hitInPath(x, y);
var hit_in_text_rect = cur_drawing.hitInTextRect(x, y);
if(hit_in_inner_area && !hit_in_text_rect || hit_in_path)
{
}
else if(hit_in_text_rect)
{
}
}
else
{
}
}
}
}
};
\ No newline at end of file
......@@ -144,6 +144,37 @@ CShape.prototype =
this.spPr.ln = line;
},
setAdjustmentValue: function(ref1, value1, ref2, value2)
{
if(this.spPr.geometry)
{
/*var data = {};
data.Type = historyitem_SetAdjValue;
data.ref1 = ref1;
data.newValue1 = value1;
data.ref2 = ref2;
data.newValue2 = value2;
data.oldValue1 = this.spPr.geometry.gdLst[ref1];
data.oldValue2 = this.spPr.geometry.gdLst[ref2];
History.Add(this, data);*/
var geometry = this.spPr.geometry;
if(typeof geometry.gdLst[ref1] === "number")
{
geometry.gdLst[ref1] = value1;
}
if(typeof geometry.gdLst[ref2] === "number")
{
geometry.gdLst[ref2] = value2;
}
geometry.Recalculate(this.extX, this.extY);
/*this.calculateContent();
this.calculateTransformTextMatrix(); */
}
},
select: function(drawingObjectsController)
{
this.selected = true;
......
......@@ -16,6 +16,8 @@ var STATES_ID_BEGIN_TRACK_NEW_SHAPE = 0x06;
var STATES_ID_TRACK_NEW_SHAPE = 0x07;
var STATES_ID_PRE_MOVE = 0x08;
var STATES_ID_MOVE = 0x09;
var STATES_ID_PRE_CHANGE_ADJ = 0x10;
var STATES_ID_CHANGE_ADJ = 0x11;
var asc = window["Asc"] ? window["Asc"] : (window["Asc"] = {});
......@@ -33,7 +35,12 @@ function NullState(drawingObjectsController, drawingObjects)
var hit_to_adj = selected_objects[0].hitToAdjustment(x, y);
if(hit_to_adj.hit)
{
//TODO
if(hit_to_adj.adjPolarFlag === false)
this.drawingObjectsController.addPreTrackObject(new XYAdjustmentTrack(selected_objects[0], hit_to_adj.adjNum));
else
this.drawingObjectsController.addPreTrackObject(new PolarAdjustmentTrack(selected_objects[0], hit_to_adj.adjNum));
this.drawingObjectsController.changeCurrentState(new PreChangeAdjState(this.drawingObjectsController, this.drawingObjects));
return;
}
}
......@@ -84,7 +91,7 @@ function NullState(drawingObjectsController, drawingObjects)
{
this.drawingObjectsController.addPreTrackObject(selected_objects[j].createMoveTrack());
}
this.drawingObjectsController.changeCurrentState(new PreMoveState(this.drawingObjectsController, this.drawingObjects, x, y));
this.drawingObjectsController.changeCurrentState(new PreMoveState(this.drawingObjectsController, this.drawingObjects, x, y, e.shiftKey, e.ctrl, selected_objects[j].isGroup() ? selected_objects[j] : null));
return;
}
}
......@@ -93,7 +100,6 @@ function NullState(drawingObjectsController, drawingObjects)
for(i = arr_drawing_objects.length-1; i > -1; --i)
{
var cur_drawing_base = arr_drawing_objects[i];
//TODO: пока работаем только с шейпами
if(cur_drawing_base.isGraphicObject())
{
var cur_drawing = cur_drawing_base.graphicObject;
......@@ -104,11 +110,18 @@ function NullState(drawingObjectsController, drawingObjects)
var hit_in_text_rect = cur_drawing.hitInTextRect(x, y);
if(hit_in_inner_area && !hit_in_text_rect || hit_in_path)
{
if(!cur_drawing.canMove())
return;
for(var j = 0; j < selected_objects.length; ++j)
{
this.drawingObjectsController.addPreTrackObject(selected_objects[j].createMoveTrack());
}
this.changeCurrentState(new PreMoveState(this.drawingObjectsController, this.drawingObjects,x, y, e.shiftKey, e.ctrl, cur_drawing.isGroup() ? cur_drawing : null));
return;
}
else if(hit_in_text_rect)
{
//TODO
}
}
else
......@@ -124,7 +137,6 @@ function NullState(drawingObjectsController, drawingObjects)
this.onMouseUp = function(e, x, y)
{
asc.editor.asc_endAddShape();
}
}
......@@ -295,6 +307,7 @@ function TrackNewShapeState(drawingObjectsController, drawingObjects)
this.drawingObjectsController.trackEnd();
this.drawingObjectsController.clearTrackObjects();
this.drawingObjectsController.changeCurrentState(new NullState(this.drawingObjectsController, this.drawingObjects));
asc.editor.asc_endAddShape();
}
}
......@@ -342,6 +355,7 @@ function MoveState(drawingObjectsController, drawingObjects, startX, startY)
this.onMouseMove = function(e, x, y)
{
this.drawingObjectsController.trackMoveObjects(x - this.startX, y - this.startY);
this.drawingObjects.showOverlayGraphicObjects();
};
this.onMouseUp = function(e, x, y)
......@@ -351,3 +365,54 @@ function MoveState(drawingObjectsController, drawingObjects, startX, startY)
this.drawingObjectsController.changeCurrentState(new NullState(this.drawingObjectsController, this.drawingObjects));
}
}
function PreChangeAdjState(drawingObjectsController, drawingObjects)
{
this.id = STATES_ID_PRE_CHANGE_ADJ;
this.drawingObjectsController = drawingObjectsController;
this.drawingObjects = drawingObjects;
this.onMouseDown = function(e, x, y)
{
};
this.onMouseMove = function(e, x, y)
{
this.drawingObjectsController.swapTrackObjects();
this.drawingObjectsController.trackAdjObject(x, y);
this.drawingObjectsController.changeCurrentState(new ChangeAdjState(this.drawingObjectsController, this.drawingObjects))
};
this.onMouseUp = function(e, x, y)
{
this.drawingObjectsController.clearPreTrackObjects();
this.drawingObjectsController.changeCurrentState(new NullState(this.drawingObjectsController, this.drawingObjects));
}
}
function ChangeAdjState(drawingObjectsController, drawingObjects)
{
this.id = STATES_ID_CHANGE_ADJ;
this.drawingObjectsController = drawingObjectsController;
this.drawingObjects = drawingObjects;
this.onMouseDown = function(e, x, y)
{
};
this.onMouseMove = function(e, x, y)
{
this.drawingObjectsController.trackAdjObject(x, y);
this.drawingObjects.showOverlayGraphicObjects();
};
this.onMouseUp = function(e, x, y)
{
this.drawingObjectsController.clearTrackObjects();
this.drawingObjectsController.changeCurrentState(new NullState(this.drawingObjectsController, this.drawingObjects));
}
}
/**
* Created with JetBrains WebStorm.
* User: Sergey.Luzyanin
* Date: 7/1/13
* Time: 11:15 AM
* To change this template use File | Settings | File Templates.
*/
function XYAdjustmentTrack(originalShape, adjIndex)
{
this.originalShape = originalShape;
this.geometry = originalShape.spPr.geometry.createDuplicate();
this.adjastment = this.geometry.ahXYLst[adjIndex];
this.shapeWidth = this.originalShape.extX;
this.shapeHeight = this.originalShape.extY;
this.xFlag = false;
this.yFlag = false;
this.refX = null;
this.refY = null;
if(this.adjastment !== null && typeof this.adjastment === "object")
{
var _ref_x = this.adjastment.gdRefX;
var _gd_lst = this.geometry.gdLst;
if(typeof _ref_x === "string" && typeof _gd_lst[_ref_x] === "number"
&& typeof this.adjastment.minX === "number" && typeof this.adjastment.maxX === "number")
{
_gd_lst[_ref_x] = this.adjastment.minX;
this.geometry.Recalculate(this.shapeWidth, this.shapeHeight);
this.minRealX = this.adjastment.posX;
_gd_lst[_ref_x] = this.adjastment.maxX;
this.geometry.Recalculate(this.shapeWidth, this.shapeHeight);
this.maxRealX = this.adjastment.posX;
this.maximalRealX = Math.max(this.maxRealX, this.minRealX);
this.minimalRealX = Math.min(this.maxRealX, this.minRealX);
this.minimalRealativeX = Math.min(this.adjastment.minX, this.adjastment.maxX);
this.maximalRealativeX = Math.max(this.adjastment.minX, this.adjastment.maxX);
if(this.maximalRealX - this.minimalRealX > 0)
{
this.coeffX = (this.adjastment.maxX - this.adjastment.minX)/(this.maxRealX - this.minRealX);
this.xFlag = true;
}
}
var _ref_y = this.adjastment.gdRefY;
if(typeof _ref_y === "string" && typeof _gd_lst[_ref_y] === "number"
&& typeof this.adjastment.minY === "number" && typeof this.adjastment.maxY === "number")
{
_gd_lst[_ref_y] = this.adjastment.minY;
this.geometry.Recalculate(this.shapeWidth, this.shapeHeight);
this.minRealY = this.adjastment.posY;
_gd_lst[_ref_y] = this.adjastment.maxY;
this.geometry.Recalculate(this.shapeWidth, this.shapeHeight);
this.maxRealY = this.adjastment.posY;
this.maximalRealY = Math.max(this.maxRealY, this.minRealY);
this.minimalRealY = Math.min(this.maxRealY, this.minRealY);
this.minimalRealativeY = Math.min(this.adjastment.minY, this.adjastment.maxY);
this.maximalRealativeY = Math.max(this.adjastment.minY, this.adjastment.maxY);
if(this.maximalRealY - this.minimalRealY > 0)
{
this.coeffY = (this.adjastment.maxY - this.adjastment.minY)/(this.maxRealY - this.minRealY);
this.yFlag = true;
}
}
if(this.xFlag)
{
this.refX = _ref_x;
}
if(this.yFlag)
{
this.refY = _ref_y;
}
}
this.overlayObject = new OverlayObject(this.geometry, originalShape.extX, originalShape.extY, originalShape.brush, originalShape.pen, originalShape.transform);
this.draw = function(overlay)
{
this.overlayObject.draw(overlay);
};
this.getBounds = function()
{
var bounds_checker = new CSlideBoundsChecker();
bounds_checker.init(Page_Width, Page_Height, Page_Width, Page_Height);
this.draw(bounds_checker);
return {l: bounds_checker.Bounds.min_x, t: bounds_checker.Bounds.min_y, r: bounds_checker.Bounds.max_x , b: bounds_checker.Bounds.max_y};
};
this.track = function(posX, posY)
{
var invert_transform = this.originalShape.invertTransform;
var _relative_x = invert_transform.TransformPointX(posX, posY);
var _relative_y = invert_transform.TransformPointY(posX, posY);
var bRecalculate = false;
if(this.xFlag)
{
var _new_x = this.adjastment.minX + this.coeffX*(_relative_x - this.minRealX);
if(_new_x <= this.maximalRealativeX && _new_x >= this.minimalRealativeX)
{
if(this.geometry.gdLst[this.adjastment.gdRefX] !== _new_x)
bRecalculate = true;
this.geometry.gdLst[this.adjastment.gdRefX] = _new_x;
}
else if( _new_x > this.maximalRealativeX)
{
if(this.geometry.gdLst[this.adjastment.gdRefX] !== this.maximalRealativeX)
bRecalculate = true;
this.geometry.gdLst[this.adjastment.gdRefX] = this.maximalRealativeX;
}
else
{
if(this.geometry.gdLst[this.adjastment.gdRefX] !== this.minimalRealativeX)
bRecalculate = true;
this.geometry.gdLst[this.adjastment.gdRefX] = this.minimalRealativeX;
}
}
if(this.yFlag)
{
var _new_y = this.adjastment.minY + this.coeffY*(_relative_y - this.minRealY);
if(_new_y <= this.maximalRealativeY && _new_y >= this.minimalRealativeY)
{
if(this.geometry.gdLst[this.adjastment.gdRefY] !== _new_y)
bRecalculate = true;
this.geometry.gdLst[this.adjastment.gdRefY] = _new_y;
}
else if(_new_y > this.maximalRealativeY)
{
if(this.geometry.gdLst[this.adjastment.gdRefY] !== this.maximalRealativeY)
bRecalculate = true;
this.geometry.gdLst[this.adjastment.gdRefY] = this.maximalRealativeY;
}
else
{
if(this.geometry.gdLst[this.adjastment.gdRefY] !== this.minimalRealativeY)
bRecalculate = true;
this.geometry.gdLst[this.adjastment.gdRefY] = this.minimalRealativeY;
}
}
if(bRecalculate)
this.geometry.Recalculate(this.shapeWidth, this.shapeHeight);
};
this.trackEnd = function()
{
this.originalShape.setAdjustmentValue(this.refX, this.geometry.gdLst[this.adjastment.gdRefX], this.refY, this.geometry.gdLst[this.adjastment.gdRefY]);
};
}
function PolarAdjustmentTrack(originalShape, adjIndex)
{
this.originalShape = originalShape;
this.geometry = originalShape.spPr.geometry.createDuplicate();
this.adjastment = this.geometry.ahPolarLst[adjIndex];
this.shapeWidth = this.originalShape.extX;
this.shapeHeight = this.originalShape.extY;
this.radiusFlag = false;
this.angleFlag = false;
this.refR = null;
this.refAng = null;
if(this.adjastment !== null && typeof this.adjastment === "object")
{
var _ref_r = this.adjastment.gdRefR;
var _gd_lst = this.geometry.gdLst;
if(typeof _ref_r === "string" && typeof _gd_lst[_ref_r] === "number"
&& typeof this.adjastment.minR === "number" && typeof this.adjastment.maxR === "number")
{
_gd_lst[_ref_r] = this.adjastment.minR;
this.geometry.Recalculate(this.shapeWidth, this.shapeHeight);
var _dx = this.adjastment.posX - this.shapeWidth*0.5;
var _dy = this.adjastment.posY - this.shapeWidth*0.5;
this.minRealR = Math.sqrt(_dx*_dx + _dy*_dy);
_gd_lst[_ref_r] = this.adjastment.maxR;
this.geometry.Recalculate(this.shapeWidth, this.shapeHeight);
_dx = this.adjastment.posX - this.shapeWidth*0.5;
_dy = this.adjastment.posY - this.shapeHeight*0.5;
this.maxRealR = Math.sqrt(_dx*_dx + _dy*_dy);
this.maximalRealRadius = Math.max(this.maxRealR, this.minRealR);
this.minimalRealRadius = Math.min(this.maxRealR, this.minRealR);
this.minimalRealativeRadius = Math.min(this.adjastment.minR, this.adjastment.maxR);
this.maximalRealativeRadius = Math.max(this.adjastment.minR, this.adjastment.maxR);
if(this.maximalRealRadius - this.minimalRealRadius > 0)
{
this.coeffR = (this.adjastment.maxR - this.adjastment.minR)/(this.maxRealR - this.minRealR);
this.radiusFlag = true;
}
}
var _ref_ang = this.adjastment.gdRefAng;
if(typeof _ref_ang === "string" && typeof _gd_lst[_ref_ang] === "number"
&& typeof this.adjastment.minAng === "number" && typeof this.adjastment.maxAng === "number")
{
this.angleFlag = true;
this.minimalAngle = Math.min(this.adjastment.minAng, this.adjastment.maxAng);
this.maximalAngle = Math.max(this.adjastment.minAng, this.adjastment.maxAng);
}
if(this.radiusFlag)
{
this.refR = _ref_r;
}
if(this.angleFlag)
{
this.refAng = _ref_ang;
}
}
this.overlayObject = new OverlayObject(this.geometry, this.originalShape.extX, this.originalShape.extY, this.originalShape.brush, this.originalShape.pen, this.originalShape.transform);
this.draw = function(overlay)
{
this.overlayObject.draw(overlay)
};
this.getBounds = function()
{
var bounds_checker = new CSlideBoundsChecker();
bounds_checker.init(Page_Width, Page_Height, Page_Width, Page_Height);
this.draw(bounds_checker);
return {l: bounds_checker.Bounds.min_x, t: bounds_checker.Bounds.min_y, r: bounds_checker.Bounds.max_x , b: bounds_checker.Bounds.max_y};
};
this.track = function(posX, posY)
{
var _temp_x = posX - this.xLT;
var _temp_y = posY - this.yLT;
var _sin = this.sin;
var _cos = this.cos;
var invert_transform = this.originalShape.invertTransform;
var _relative_x = invert_transform.TransformPointX(posX, posY);
var _relative_y = invert_transform.TransformPointY(posX, posY);
var _pos_x_relative_center = _relative_x - this.shapeHeight*0.5;
var _pos_y_relative_center = _relative_y - this.shapeWidth*0.5;
if(this.radiusFlag)
{
var _radius = Math.sqrt(_pos_x_relative_center*_pos_x_relative_center + _pos_y_relative_center*_pos_y_relative_center);
var _new_radius = this.adjastment.minR + this.coeffR*(_radius - this.minRealR);
if(_new_radius <= this.maximalRealativeRadius && _new_radius >= this.minimalRealativeRadius)
{
this.geometry.gdLst[this.adjastment.gdRefR] = _new_radius;
}
else if( _new_radius > this.maximalRealativeRadius)
{
this.geometry.gdLst[this.adjastment.gdRefR] = this.maximalRealativeRadius;
}
else
{
this.geometry.gdLst[this.adjastment.gdRefR] = this.minimalRealativeRadius;
}
}
if(this.angleFlag)
{
var _angle = Math.atan2(_pos_y_relative_center, _pos_x_relative_center);
while(_angle < 0)
_angle += 2*Math.PI;
while(_angle >= 2*Math.PI)
_angle -= 2*Math.PI;
_angle *= cToDeg;
if(_angle >= this.minimalAngle && _angle <= this.maximalAngle)
{
this.geometry.gdLst[this.adjastment.gdRefAng]= _angle;
}
else if(_angle >= this.maximalAngle)
{
this.geometry.gdLst[this.adjastment.gdRefAng] = this.maximalAngle;
}
else if(_angle <= this.minimalAngle)
{
this.geometry.gdLst[this.adjastment.gdRefAng] = this.minimalAngle;
}
}
this.geometry.Recalculate(this.shapeWidth, this.shapeHeight);
};
this.trackEnd = function()
{
this.originalShape.setAdjustmentValue(this.refR, this.geometry.gdLst[this.adjastment.gdRefR], this.refAng, this.geometry.gdLst[this.adjastment.gdRefAng]);
};
}
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment