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; 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; 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(); }