public void Execute() { StageView stage = MainForm.CurrentStage; prevLocation = stage.Selection.StrokeBounds.Point; stage.ScaleSelectionAt(scaleX, scaleY, scaleCenter); }
public Matrix GetRotatedMatrix(float angle, Vex.Point center) { Matrix m = transformMatrix.Clone(); m.RotateAt(angle, center.SysPointF(), MatrixOrder.Append); return(m); }
public void ScaleAt(float scaleX, float scaleY, Vex.Point center) { scaleX = (Math.Abs(scaleX) < .01) ? .01f : scaleX; scaleY = (Math.Abs(scaleY) < .01) ? .01f : scaleY; Matrix tm = TransformMatrix.Clone(); tm.Translate(-TransformMatrix.OffsetX, -TransformMatrix.OffsetY, MatrixOrder.Append); Matrix itm = tm.Clone(); itm.Invert(); foreach (uint id in list) { DesignInstance inst = instanceManager[id]; using (Matrix ms = inst.GetMatrix().SysMatrix()) { ms.Translate(-center.X, -center.Y, MatrixOrder.Append); ms.Multiply(itm, MatrixOrder.Append); ms.Scale(scaleX, scaleY, MatrixOrder.Append); ms.Multiply(tm, MatrixOrder.Append); ms.Translate(center.X, center.Y, MatrixOrder.Append); inst.SetMatrix(ms.VexMatrix()); } } tm.Dispose(); itm.Dispose(); transformMatrix.ScaleAt(scaleX, scaleY, center.SysPointF()); isDirty = true; MainForm.CurrentStage.InvalidateTransformedSelection(); }
public Matrix GetScaledMatrix(float scaleX, float scaleY, Vex.Point center) { Matrix m = transformMatrix.Clone(); m.ScaleAt(scaleX, scaleY, center.SysPointF()); return(m); }
public static Vex.Point GetScalingOrigin(this ColorMask colorMask, Vex.Rectangle r) { Vex.Point result = r.Point; switch (colorMask) { case ColorMask.ScaleTopLeft: case ColorMask.ScaleLeftCenter: case ColorMask.ScaleTopCenter: case ColorMask.RulerSelLeft: case ColorMask.RulerSelTop: result = new Vex.Point(r.Right, r.Bottom); break; case ColorMask.ScaleTopRight: result = new Vex.Point(r.Left, r.Bottom); break; case ColorMask.ScaleBottomRight: case ColorMask.ScaleBottomCenter: case ColorMask.ScaleRightCenter: case ColorMask.RulerSelRight: case ColorMask.RulerSelBottom: result = r.Point; break; case ColorMask.ScaleBottomLeft: result = new Vex.Point(r.Right, r.Top); break; } return(result); }
public ImportFileCommand(string filename, Vex.Point location) { this.filename = filename; this.location = location; addToStage = true; addInstanceCommands = new List <AddInstancesCommand>(); }
public void Execute() { StageView stage = MainForm.CurrentStage; this.rotateCenter = stage.Selection.GlobalRotationCenter; stage.RotateSelectionAt(angle, rotateCenter); }
public void ResetTransform() { if (transformMatrix != null) { transformMatrix.Dispose(); } if (list.Count == 1) { DesignInstance di = instanceManager[list[0]]; transformMatrix = di.GetMatrix().SysMatrix(); center = di.RotationCenter; untransformedBounds = di.Definition.StrokeBounds;//.TranslatedRectangle(-di.Location.X, -di.Location.Y); } else { transformMatrix = new Matrix(); transformMatrix.Translate(StrokeBounds.Left, StrokeBounds.Top, MatrixOrder.Append); center = StrokeBounds.LocalCenter; //center = StrokeBounds.LocalCenter.Translate(StrokeBounds.Point); untransformedBounds = StrokeBounds.TranslatedRectangle(-StrokeBounds.Left, -StrokeBounds.Top); } isTransformDirty = false; }
public void AppendNudge(int xAmount, int yAmount) { StageView stage = MainForm.CurrentStage; stage.TranslateSelection(new Vex.Point(xAmount, yAmount), false, addedBonds, previousBonds); offset = new Vex.Point(offset.X + xAmount, offset.Y + yAmount); }
public void TranslateSelection(Vex.Point offset) { Dictionary <uint, Vex.Rectangle> alreadyDiscovered = new Dictionary <uint, Vex.Rectangle>(); MainForm.CurrentStage.CurrentEditItem.BondStore.GetRelatedObjectTransforms(list, alreadyDiscovered, offset); relatedIds = alreadyDiscovered.Keys.ToArray(); foreach (uint id in alreadyDiscovered.Keys) { TranslateElement(id, alreadyDiscovered[id].Left, alreadyDiscovered[id].Top); } ResetTransform(); MainForm.CurrentStage.InvalidateTransformedSelection(); }
public void RotateAt(float angle, Vex.Point center) { foreach (uint id in list) { DesignInstance inst = instanceManager[id]; using (Matrix mr = inst.GetMatrix().SysMatrix()) { mr.RotateAt(angle, center.SysPointF(), MatrixOrder.Append); inst.SetMatrix(mr.VexMatrix()); } } transformMatrix.RotateAt(angle, center.SysPointF(), MatrixOrder.Append); isDirty = true; MainForm.CurrentStage.InvalidateTransformedSelection(); }
public void DrawRotated(Graphics g, float angle, Vex.Point center) { Matrix m = g.Transform; foreach (uint id in list) { DesignInstance inst = instanceManager[id]; using (Matrix mr = inst.GetMatrix().SysMatrix()) { mr.RotateAt(angle, center.SysPointF(), MatrixOrder.Append); mr.Multiply(m, MatrixOrder.Append); g.Transform = mr; inst.DrawOutlineIntoRaw(g, 0, 0); } } g.Transform = m; }
public void Execute() { StageView stage = MainForm.CurrentStage; LibraryView currentLibraryView = MainForm.CurrentLibraryView; string ext = Path.GetExtension(filename).ToUpperInvariant(); if (ext == ".SWF") { libraryItems = currentLibraryView.AddSwf(filename); } else if (ext == ".BMP" || ext == ".JPG" || ext == ".GIF" || ext == ".PNG") { libraryItems = new LibraryItem[] { currentLibraryView.AddImage(filename) }; } if (currentLibraryView.GetSelectedNode() == null && libraryItems.Length > 0) { currentLibraryView.SelectNode(libraryItems[0].DefinitionId); } else { currentLibraryView.RefreshCurrentNode(); } if (addToStage) { uint[] itemIds = new uint[libraryItems.Length]; Vex.Point[] locs = new Vex.Point[libraryItems.Length]; for (int i = 0; i < libraryItems.Length; i++) { itemIds[i] = libraryItems[i].Definition.Id; Vex.Point centerOffset = libraryItems[i].Definition.StrokeBounds.Center.Negate(); locs[i] = location.Translate(centerOffset); } AddInstancesCommand aic = new AddInstancesCommand(itemIds, locs); aic.Execute(); addInstanceCommands.Add(aic); stage.InvalidateAll(); } stage.HasSaveableChanges = true; currentLibraryView.Invalidate(); }
public void Execute() { StageView stage = MainForm.CurrentStage; // store old selection prevSelected = stage.Selection.IdsByDepth;// SelectedIds; prevOffset = stage.Selection.StrokeBounds.Point; // create symbol from selected Vex.Timeline tl = new Vex.Timeline(stage.Library.NextLibraryId()); tl.Name = stage.Library.GetNextDefaultName(); tl.StrokeBounds = stage.Selection.StrokeBounds.TranslatedRectangle(-prevOffset.X, -prevOffset.Y); // delete old symbols DesignInstance[] oldInstances = stage.RemoveInstancesById(prevSelected); for (int i = 0; i < prevSelected.Length; i++) { DesignInstance inst = oldInstances[i];// instMgr[prevSelected[i]]; Vex.Matrix m = inst.GetMatrix(); m.TranslateX -= prevOffset.X; m.TranslateY -= prevOffset.Y; inst.SetMatrix(m); tl.AddInstance(inst.Instance); stage.InstanceManager.AddInstance(inst); // reusing, so must readd (todo: don't reuse ids?) } LibraryItem li = stage.CreateLibraryItem(tl, true); newLibraryItemId = li.DefinitionId; stage.Library.AddLibraryItem(li); LibraryView.CurrentLibraryView.AddItemToLibrary(li); // add new symbol to stage DesignInstance di = stage.AddInstance(tl.Id, prevOffset); newInstanceId = di.InstanceHash; // select new symbol stage.Selection.Set(new uint[] { di.InstanceHash }); stage.ResetTransformHandles(); stage.InvalidateSelection(); }
public static Vex.Point GetHandleOffset(this ColorMask colorMask, Vex.Rectangle r, Vex.Point mouseDownLocation) { Vex.Point result = Vex.Point.Zero; switch (colorMask) { case ColorMask.ScaleTopLeft: case ColorMask.RotateTopLeft: result = mouseDownLocation.Translate(new Vex.Point(-r.Left, -r.Top)); break; case ColorMask.ScaleTopRight: case ColorMask.RotateTopRight: result = mouseDownLocation.Translate(new Vex.Point(-r.Right, -r.Top)); break; case ColorMask.ScaleBottomRight: case ColorMask.RotateBottomRight: result = mouseDownLocation.Translate(new Vex.Point(-r.Right, -r.Bottom)); break; case ColorMask.ScaleBottomLeft: case ColorMask.RotateBottomLeft: result = mouseDownLocation.Translate(new Vex.Point(-r.Left, -r.Bottom)); break; case ColorMask.RulerSelLeft: result = mouseDownLocation.Translate(new Vex.Point(-r.Left, 0)); break; case ColorMask.RulerSelTop: result = mouseDownLocation.Translate(new Vex.Point(0, -r.Top)); break; case ColorMask.RulerSelRight: result = mouseDownLocation.Translate(new Vex.Point(-r.Right, 0)); break; case ColorMask.RulerSelBottom: result = mouseDownLocation.Translate(new Vex.Point(0, -r.Bottom)); break; } return(result); }
public void Execute() { StageView stage = MainForm.CurrentStage; InstanceGroup sel = stage.Selection; this.prevSelected = sel.SelectedIds; Vex.Point selRotCent = sel.GlobalRotationCenter.Translate(sel.Location.Negate()); uint[] libraryIds = new uint[prevSelected.Length]; Vex.Point[] locations = new Vex.Point[prevSelected.Length]; for (int i = 0; i < prevSelected.Length; i++) { DesignInstance di = MainForm.CurrentInstanceManager[prevSelected[i]]; libraryIds[i] = di.LibraryItem.DefinitionId; locations[i] = new Vex.Point(di.Location.X + offset.X, di.Location.Y + offset.Y); } if (newInstanceIds == null) { newInstanceIds = stage.AddInstances(libraryIds, locations); for (int i = 0; i < newInstanceIds.Length; i++) { DesignInstance oldDi = MainForm.CurrentInstanceManager[prevSelected[i]]; DesignInstance newDi = MainForm.CurrentInstanceManager[newInstanceIds[i]]; Vex.Matrix m = oldDi.GetMatrix(); stage.SetDesignInstanceMatrix(newDi, new Vex.Matrix(m.ScaleX, m.Rotate0, m.Rotate1, m.ScaleY, newDi.Location.X, newDi.Location.Y)); newDi.RotationCenter = oldDi.RotationCenter; } } else { stage.AddInstancesById(newInstanceIds); } sel.Set(newInstanceIds); sel.GlobalRotationCenter = selRotCent.Translate(sel.Location); stage.ResetTransformHandles(); stage.InvalidateTransformedSelection(); }
public void DrawScaled(Graphics g, float scaleX, float scaleY, Vex.Point center) { Matrix m = g.Transform; scaleX = (Math.Abs(scaleX) < .01) ? .01f : scaleX; scaleY = (Math.Abs(scaleY) < .01) ? .01f : scaleY; Matrix tm = TransformMatrix.Clone(); tm.Translate(-TransformMatrix.OffsetX, -TransformMatrix.OffsetY, MatrixOrder.Append); Matrix itm = tm.Clone(); itm.Invert(); foreach (uint id in list) { DesignInstance inst = instanceManager[id]; using (Matrix ms = inst.GetMatrix().SysMatrix()) { ms.Translate(-center.X, -center.Y, MatrixOrder.Append); ms.Multiply(itm, MatrixOrder.Append); ms.Scale(scaleX, scaleY, MatrixOrder.Append); ms.Multiply(tm, MatrixOrder.Append); ms.Translate(center.X, center.Y, MatrixOrder.Append); ms.Multiply(m, MatrixOrder.Append); g.Transform = ms; inst.DrawOutlineIntoRaw(g, 0, 0); } } tm.Dispose(); itm.Dispose(); g.Transform = m; }
public Vex.Rectangle CalculateBounds(uint[] instances, out Vex.Point topLeft) { Vex.Rectangle bounds = Vex.Rectangle.Empty; float top = int.MaxValue; float left = int.MaxValue; foreach (uint id in instances) { DesignInstance inst = instanceManager[id]; if (bounds.IsEmpty) { bounds = inst.StrokeBounds; } else { bounds = inst.StrokeBounds.Union(bounds);// Rectangle.Union(bounds, inst.Bounds); } left = Math.Min(left, inst.Location.X); top = Math.Min(top, inst.Location.Y); } topLeft = new Vex.Point(left, top); return(bounds); }
public ScaleTransformCommand(float scaleX, float scaleY, Vex.Point scaleCenter) { this.scaleX = scaleX; this.scaleY = scaleY; this.scaleCenter = scaleCenter; }
public Vex.Point LocalToTransform(Vex.Point p) { return(Gdi.GdiRenderer.GetTransformedPoint(p.SysPointF(), TransformMatrix, false).VexPoint()); }
public Vex.Point TransformToLocal(Vex.Point p) { return(Gdi.GdiRenderer.GetTransformedPoint(p.SysPointF(), TransformMatrix, true).VexPoint()); }
public DuplicateSelectedCommand(Vex.Point offset) { this.offset = offset; }
public NudgeSelectionCommand(float xAmount, float yAmount) { offset = new Vex.Point(xAmount, yAmount); }
public TranslateRotationCenterCommand(Vex.Point prevLocation, Vex.Point newLocation) { this.prevLocation = prevLocation; this.newLocation = newLocation; }
public void Translate(Vex.Point p) { TranslateX += p.X; TranslateY += p.Y; }
public void Execute() { StageView stage = MainForm.CurrentStage; InstanceGroup sel = stage.Selection; InstanceManager instMgr = stage.InstanceManager; prevSelection = sel.IdsByDepth; List <uint> addedInstances = new List <uint>(); List <uint> newSelection = new List <uint>(); List <uint> toBreakApart = new List <uint>(); List <int> originalDepths = new List <int>(); for (int i = 0; i < prevSelection.Length; i++) { DesignInstance di = instMgr[prevSelection[i]]; if (CanBreakApart(di)) { toBreakApart.Add(prevSelection[i]); originalDepths.Add(di.Depth); } else { newSelection.Add(prevSelection[i]); } } prevInstances = toBreakApart.ToArray(); prevDepths = originalDepths.ToArray(); sel.Clear(); for (int i = 0; i < toBreakApart.Count; i++) { uint id = toBreakApart[i]; DesignInstance di = instMgr[id]; int orgDepth = di.Depth; Matrix orgMatrix = di.GetSysMatrix(); Vex.Point offset = di.Location; uint[] instances = ((DesignTimeline)di).InstanceIds; for (int j = instances.Length - 1; j >= 0; j--) { DesignInstance orgInstance = instMgr[instances[j]]; uint subLibId = orgInstance.LibraryItem.DefinitionId; DesignInstance inst = stage.AddInstance(subLibId, Vex.Point.Zero); stage.CurrentEditItem.ChangeDepth(inst.Depth, orgDepth); using (Matrix m = orgInstance.GetSysMatrix().Clone()) { m.Multiply(orgMatrix, MatrixOrder.Append); stage.SetDesignInstanceMatrix(inst, m.VexMatrix()); } addedInstances.Add(inst.InstanceHash); newSelection.Add(inst.InstanceHash); } stage.RemoveInstancesById(new uint[] { id }); } newInstances = addedInstances.ToArray(); sel.Set(newSelection.ToArray()); stage.ResetTransformHandles(); }