private void Activate() { this._active = true; this.HandCursor = new Cursor(PdnResources.GetResourceStream("Cursors.PanToolCursor.cur")); this.HandCursorMouseDown = new Cursor(PdnResources.GetResourceStream("Cursors.PanToolCursorMouseDown.cur")); this.HandCursorInvalid = new Cursor(PdnResources.GetResourceStream("Cursors.PanToolCursorInvalid.cur")); this.HandCursor = Cursors.Hand; this.HandCursorMouseDown = Cursors.Arrow; this.HandCursorInvalid = Cursors.Arrow; this._mouseDownCount = 0; this._savedTiles = null; this._saveRegion = null; this._scratchSurface = DocumentWorkspace.BorrowScratchSurface(); // // Selection.Changing += new EventHandler(SelectionChangingHandler); // Selection.Changed += new EventHandler(SelectionChangedHandler); // HistoryStack.ExecutingHistoryMemento += new ExecutingHistoryMementoEventHandler(ExecutingHistoryMemento); // HistoryStack.ExecutedHistoryMemento += new ExecutedHistoryMementoEventHandler(ExecutedHistoryMemento); // HistoryStack.FinishedStepGroup += new EventHandler(FinishedHistoryStepGroup); this._trackingNub = new MoveNubRenderer(this.RendererList); this._trackingNub.Visible = false; this._trackingNub.Size = new SizeF(10, 10); this._trackingNub.Shape = MoveNubShape.Compass; this.RendererList.Add(this._trackingNub, false); OnActivate(); }
protected void DetermineMoveMode(MouseEventArgs e, out Mode mode, out Edge edge) { mode = Mode.Translate; edge = Edge.None; if (e.Button == MouseButtons.Right) { mode = Mode.Rotate; } else { float minDistance = float.MaxValue; Point mousePt = new Point(e.X, e.Y); for (int i = 0; i < this.moveNubs.Length; ++i) { MoveNubRenderer nub = this.moveNubs[i]; if (nub.IsPointTouching(mousePt, true)) { float distance = Utility.Distance((PointF)mousePt, nub.Location); if (distance < minDistance) { minDistance = distance; mode = Mode.Scale; edge = (Edge)i; } } } } return; }
protected override void OnActivate() { this.toolCursor = new Cursor(PdnResources.GetResourceStream("Cursors.GenericToolCursor.cur")); this.toolMouseDownCursor = new Cursor(PdnResources.GetResourceStream("Cursors.GenericToolCursorMouseDown.cur")); this.Cursor = this.toolCursor; this.toolIcon = this.Image; this.startNub = new MoveNubRenderer(RendererList); this.startNub.Visible = false; this.startNub.Shape = MoveNubShape.Circle; RendererList.Add(this.startNub, false); this.endNub = new MoveNubRenderer(RendererList); this.endNub.Visible = false; this.endNub.Shape = MoveNubShape.Circle; RendererList.Add(this.endNub, false); this.moveNubs = new MoveNubRenderer[] { this.startNub, this.endNub }; AppEnvironment.PrimaryColorChanged += new EventHandler(RenderBecauseOfEvent); AppEnvironment.SecondaryColorChanged += new EventHandler(RenderBecauseOfEvent); AppEnvironment.GradientInfoChanged += new EventHandler(RenderBecauseOfEvent); AppEnvironment.AlphaBlendingChanged += new EventHandler(RenderBecauseOfEvent); AppWorkspace.UnitsChanged += new EventHandler(RenderBecauseOfEvent); base.OnActivate(); }
private void Deactivate() { this._active = false; // Selection.Changing -= new EventHandler(SelectionChangingHandler); // Selection.Changed -= new EventHandler(SelectionChangedHandler); // // HistoryStack.ExecutingHistoryMemento -= new ExecutingHistoryMementoEventHandler(ExecutingHistoryMemento); // HistoryStack.ExecutedHistoryMemento -= new ExecutedHistoryMementoEventHandler(ExecutedHistoryMemento); // HistoryStack.FinishedStepGroup -= new EventHandler(FinishedHistoryStepGroup); OnDeactivate(); this.RendererList.Remove(this._trackingNub); this._trackingNub.Dispose(); this._trackingNub = null; DocumentWorkspace.ReturnScratchSurface(this._scratchSurface); this._scratchSurface = null; if (this._saveRegion != null) { this._saveRegion.Dispose(); this._saveRegion = null; } this._savedTiles = null; if (this.HandCursor != null) { this.HandCursor.Dispose(); this.HandCursor = null; } if (this.HandCursorMouseDown != null) { this.HandCursorMouseDown.Dispose(); this.HandCursorMouseDown = null; } if (this.HandCursorInvalid != null) { this.HandCursorInvalid.Dispose(); this.HandCursorInvalid = null; } }
protected override void OnDeactivate() { AppEnvironment.PrimaryColorChanged -= new EventHandler(RenderBecauseOfEvent); AppEnvironment.SecondaryColorChanged -= new EventHandler(RenderBecauseOfEvent); AppEnvironment.GradientInfoChanged -= new EventHandler(RenderBecauseOfEvent); AppEnvironment.AlphaBlendingChanged -= new EventHandler(RenderBecauseOfEvent); AppWorkspace.UnitsChanged -= new EventHandler(RenderBecauseOfEvent); if (this.gradientActive) { CommitGradient(); this.mouseButton = MouseButtons.None; } if (this.startNub != null) { RendererList.Remove(this.startNub); this.startNub.Dispose(); this.startNub = null; } if (this.endNub != null) { RendererList.Remove(this.endNub); this.endNub.Dispose(); this.endNub = null; } this.moveNubs = null; if (this.toolCursor != null) { this.toolCursor.Dispose(); this.toolCursor = null; } if (this.toolMouseDownCursor != null) { this.toolMouseDownCursor.Dispose(); this.toolMouseDownCursor = null; } base.OnDeactivate(); }
private void OnMouseMoveImpl(MouseEventArgs e, StringBuilder sbLogger) { if (!this.tracking) { sbLogger.Append("1 "); Cursor cursor = this.moveToolCursor; for (int i = 0; i < this.moveNubs.Length; ++i) { sbLogger.Append("2 "); MoveNubRenderer nub = this.moveNubs[i]; sbLogger.Append("3 "); if (nub.Visible && nub.IsPointTouching(new Point(e.X, e.Y), true)) { sbLogger.Append("4 "); cursor = this.handCursor; break; } } this.Cursor = cursor; sbLogger.Append("5 "); } else { sbLogger.Append("6 "); if (this.context.currentMode != Mode.Translate) { sbLogger.Append("7 "); this.Cursor = this.handCursorMouseDown; } sbLogger.Append("8 "); Point newMouseXY = new Point(e.X, e.Y); Point newOffset = new Point(newMouseXY.X - context.startMouseXY.X, newMouseXY.Y - context.startMouseXY.Y); PreRender(); this.dontDrop = true; sbLogger.Append("9 "); Selection.PerformChanging(); using (Matrix translateMatrix = new Matrix()) { RectangleF rect; translateMatrix.Reset(); if (this.context.baseTransform != null) { Selection.SetInterimTransform(this.context.baseTransform); } Matrix interim = Selection.GetInterimTransformCopy(); switch (this.context.currentMode) { case Mode.Translate: translateMatrix.Translate((float)newOffset.X, (float)newOffset.Y, MatrixOrder.Append); break; case Mode.Rotate: rect = this.context.liftedBounds; PointF center = new PointF(rect.X + (rect.Width / 2.0f), rect.Y + (rect.Height / 2.0f)); center = Utility.TransformOnePoint(interim, center); double theta1 = Math.Atan2(context.startMouseXY.Y - center.Y, context.startMouseXY.X - center.X); double theta2 = Math.Atan2(e.Y - center.Y, e.X - center.X); double thetaDelta = theta2 - theta1; this.angleDelta = (float)(thetaDelta * (180.0f / Math.PI)); float angle = this.context.startAngle + this.angleDelta; if ((ModifierKeys & Keys.Shift) != 0) { angle = ConstrainAngle(angle); angleDelta = angle - this.context.startAngle; } translateMatrix.RotateAt(angleDelta, center, MatrixOrder.Append); this.rotateNub.Location = center; this.rotateNub.Angle = this.context.startAngle + angleDelta; break; case Mode.Scale: PointF xyAxes = GetEdgeVector(this.context.startEdge); PointF xAxis = new PointF(xyAxes.X, 0); PointF yAxis = new PointF(0, xyAxes.Y); PointF edgeX = Utility.TransformOneVector(interim, xAxis); PointF edgeY = Utility.TransformOneVector(interim, yAxis); PointF edgeXN = Utility.NormalizeVector2(edgeX); PointF edgeYN = Utility.NormalizeVector2(edgeY); PointF xu; float xulen; PointF xv; Utility.GetProjection((PointF)newOffset, edgeXN, out xu, out xulen, out xv); PointF yu; float yulen; PointF yv; Utility.GetProjection((PointF)newOffset, edgeYN, out yu, out yulen, out yv); PdnGraphicsPath startPath2 = this.context.startPath.Clone(); RectangleF sp2Bounds = startPath2.GetBounds(); PointF sp2BoundsCenter = new PointF((sp2Bounds.Left + sp2Bounds.Right) / 2.0f, (sp2Bounds.Top + sp2Bounds.Bottom) / 2.0f); float tAngle = Utility.GetAngleOfTransform(interim); bool isFlipped = Utility.IsTransformFlipped(interim); using (Matrix spm = new Matrix()) { spm.Reset(); spm.RotateAt(-tAngle, sp2BoundsCenter, MatrixOrder.Append); translateMatrix.RotateAt(-tAngle, sp2BoundsCenter, MatrixOrder.Append); startPath2.Transform(spm); } RectangleF spBounds2 = startPath2.GetBounds(); startPath2.Dispose(); startPath2 = null; float xTranslate; float yTranslate; bool allowConstrain; Edge theEdge = this.context.startEdge; // If the transform is flipped, then GetTransformAngle will return 180 degrees // even though no rotation has actually taken place. Thus we have to scratch // our head and go "hmm, let's make some adjustments to this." Otherwise stretching // the top and bottom nubs goes in the wrong direction. if (isFlipped) { theEdge = FlipEdgeVertically(theEdge); } switch (theEdge) { default: throw new InvalidEnumArgumentException(); case Edge.TopLeft: allowConstrain = true; xTranslate = -spBounds2.X - spBounds2.Width; yTranslate = -spBounds2.Y - spBounds2.Height; break; case Edge.Top: allowConstrain = false; xTranslate = 0; yTranslate = -spBounds2.Y - spBounds2.Height; break; case Edge.TopRight: allowConstrain = true; xTranslate = -spBounds2.X; yTranslate = -spBounds2.Y - spBounds2.Height; break; case Edge.Left: allowConstrain = false; xTranslate = -spBounds2.X - spBounds2.Width; yTranslate = 0; break; case Edge.Right: allowConstrain = false; xTranslate = -spBounds2.X; yTranslate = 0; break; case Edge.BottomLeft: allowConstrain = true; xTranslate = -spBounds2.X - spBounds2.Width; yTranslate = -spBounds2.Y; break; case Edge.Bottom: allowConstrain = false; xTranslate = 0; yTranslate = -spBounds2.Y; break; case Edge.BottomRight: allowConstrain = true; xTranslate = -spBounds2.X; yTranslate = -spBounds2.Y; break; } translateMatrix.Translate(xTranslate, yTranslate, MatrixOrder.Append); float newWidth = spBounds2.Width + xulen; float newHeight = spBounds2.Height + yulen; float xScale = newWidth / spBounds2.Width; float yScale = newHeight / spBounds2.Height; if (allowConstrain && (this.ModifierKeys & Keys.Shift) != 0) { ConstrainScaling(this.context.liftedBounds, spBounds2.Width, spBounds2.Height, newWidth, newHeight, out xScale, out yScale); } translateMatrix.Scale(xScale, yScale, MatrixOrder.Append); translateMatrix.Translate(-xTranslate, -yTranslate, MatrixOrder.Append); translateMatrix.RotateAt(+tAngle, sp2BoundsCenter, MatrixOrder.Append); break; default: throw new InvalidEnumArgumentException(); } this.context.deltaTransform.Reset(); this.context.deltaTransform.Multiply(this.context.liftTransform, MatrixOrder.Append); this.context.deltaTransform.Multiply(translateMatrix, MatrixOrder.Append); translateMatrix.Multiply(this.context.baseTransform, MatrixOrder.Prepend); Selection.SetInterimTransform(translateMatrix); interim.Dispose(); interim = null; } // advertise our angle of rotation to any host (i.e. mainform) that might want to use that information this.hostShouldShowAngle = this.rotateNub.Visible; this.hostAngle = -this.rotateNub.Angle; Selection.PerformChanged(); dontDrop = false; Render(newOffset, true); Update(); sbLogger.Append("a "); this.context.offset = newOffset; sbLogger.Append("b "); if (this.enableOutline) { DocumentWorkspace.ResetOutlineWhiteOpacity(); } sbLogger.Append("c "); } sbLogger.Append("d "); }
protected override void OnMouseMove(MouseEventArgs e) { PointF mousePtF = new PointF(e.X, e.Y); MoveNubRenderer mouseCursorNub = PointToNub(mousePtF); if (this.mouseButton == MouseButtons.None) { // No mouse button dragging is being tracked. this.mouseNub = mouseCursorNub; if (this.mouseNub == this.startNub || this.mouseNub == this.endNub) { Cursor = this.handCursor; } else { Cursor = this.toolCursor; } } else { if (this.mouseNub == this.startNub) { // Dragging the start nub if (this.shouldConstrain && !this.shouldMoveBothNubs) { ConstrainPoints(this.endPoint, ref mousePtF); } this.startNub.Location = mousePtF; SizeF delta = new SizeF( this.startNub.Location.X - this.startPoint.X, this.startNub.Location.Y - this.startPoint.Y); this.startPoint = mousePtF; if (this.shouldMoveBothNubs) { this.endNub.Location += delta; this.endPoint += delta; } } else if (this.mouseNub == this.endNub) { // Dragging the ending nub if (this.shouldConstrain && !this.shouldMoveBothNubs) { ConstrainPoints(this.startPoint, ref mousePtF); } this.endNub.Location = mousePtF; SizeF delta = new SizeF( this.endNub.Location.X - this.endPoint.X, this.endNub.Location.Y - this.endPoint.Y); this.endPoint = mousePtF; if (this.shouldMoveBothNubs) { this.startNub.Location += delta; this.startPoint += delta; } } else { // Initial drawing if (this.shouldMoveBothNubs) { SizeF delta = new SizeF( this.endNub.Location.X - mousePtF.X, this.endNub.Location.Y - mousePtF.Y); this.startNub.Location -= delta; this.startPoint -= delta; } else if (this.shouldConstrain) { ConstrainPoints(this.startPoint, ref mousePtF); } this.endNub.Location = mousePtF; this.endPoint = mousePtF; } RenderGradient(); } base.OnMouseMove(e); }
protected override void OnMouseDown(MouseEventArgs e) { PointF mousePt = new PointF(e.X, e.Y); MoveNubRenderer mouseCursorNub = PointToNub(mousePt); if (this.mouseButton != MouseButtons.None) { this.shouldMoveBothNubs = !this.shouldMoveBothNubs; } else { bool startNewGradient = true; this.mouseButton = e.Button; if (!this.gradientActive) { this.shouldSwapColors = (this.mouseButton == MouseButtons.Right); } else { this.shouldMoveBothNubs = false; // We are already in the process of drawing or adjusting a gradient. // Determine if they clicked to drag one of the nubs for adjusting. if (mouseCursorNub == null) { // No. Commit the old gradient and begin a new one. CommitGradient(); startNewGradient = true; this.shouldSwapColors = (this.mouseButton == MouseButtons.Right); } else { // Yes. Continue adjusting the old gradient. Cursor = this.handCursorMouseDown; this.mouseNub = mouseCursorNub; this.mouseNub.Location = mousePt; if (this.mouseNub == this.startNub) { this.startPoint = mousePt; } else { this.endPoint = mousePt; } if (this.mouseButton == MouseButtons.Right) { this.shouldSwapColors = !this.shouldSwapColors; } RenderGradient(); startNewGradient = false; } } if (startNewGradient) { // Brand new gradient. Set everything up. this.startPoint = mousePt; this.startNub.Location = mousePt; this.startNub.Visible = true; this.endNub.Location = mousePt; this.endNub.Visible = true; this.endPoint = mousePt; this.mouseNub = mouseCursorNub; Cursor = this.toolMouseDownCursor; this.gradientActive = true; ClearSavedRegion(); RenderGradient(); this.historyMemento = new CompoundHistoryMemento(StaticName, StaticImage); HistoryStack.PushNewMemento(this.historyMemento); // this makes it so they can push Esc to undo } } base.OnMouseDown(e); }
protected override void OnDeactivate() { PdnBaseForm.UnregisterFormHotKey(Keys.Back, OnBackspaceTyped); base.OnDeactivate(); switch (mode) { case EditingMode.Editing: SaveHistoryMemento(); break; case EditingMode.EmptyEdit: RedrawText(false); break; case EditingMode.NotEditing: break; default: throw new InvalidEnumArgumentException("Invalid Editing Mode"); } if (ra != null) { ra.Dispose(); ra = null; } if (saved != null) { saved.Dispose(); saved = null; } AppEnvironment.BrushInfoChanged -= brushChangedDelegate; AppEnvironment.FontInfoChanged -= fontChangedDelegate; AppEnvironment.FontSmoothingChanged -= fontSmoothingChangedDelegate; AppEnvironment.TextAlignmentChanged -= alignmentChangedDelegate; AppEnvironment.AntiAliasingChanged -= antiAliasChangedDelegate; AppEnvironment.PrimaryColorChanged -= foreColorChangedDelegate; AppEnvironment.SecondaryColorChanged -= new EventHandler(BackColorChangedHandler); AppEnvironment.AlphaBlendingChanged -= new EventHandler(AlphaBlendingChangedHandler); StopEditing(); this.threadPool = null; this.RendererList.Remove(this.moveNub); this.moveNub.Dispose(); this.moveNub = null; if (this.textToolCursor != null) { this.textToolCursor.Dispose(); this.textToolCursor = null; } }
protected override void OnActivate() { PdnBaseForm.RegisterFormHotKey(Keys.Back, OnBackspaceTyped); base.OnActivate(); this.textToolCursor = new Cursor(PdnResources.GetResourceStream("Cursors.TextToolCursor.cur")); this.Cursor = this.textToolCursor; fontChangedDelegate = new EventHandler(FontChangedHandler); fontSmoothingChangedDelegate = new EventHandler(FontSmoothingChangedHandler); alignmentChangedDelegate = new EventHandler(AlignmentChangedHandler); brushChangedDelegate = new EventHandler(BrushChangedHandler); antiAliasChangedDelegate = new EventHandler(AntiAliasChangedHandler); foreColorChangedDelegate = new EventHandler(ForeColorChangedHandler); ra = new RenderArgs(((BitmapLayer)ActiveLayer).Surface); mode = EditingMode.NotEditing; font = AppEnvironment.FontInfo.CreateFont(); alignment = AppEnvironment.TextAlignment; AppEnvironment.BrushInfoChanged += brushChangedDelegate; AppEnvironment.FontInfoChanged += fontChangedDelegate; AppEnvironment.FontSmoothingChanged += fontSmoothingChangedDelegate; AppEnvironment.TextAlignmentChanged += alignmentChangedDelegate; AppEnvironment.AntiAliasingChanged += antiAliasChangedDelegate; AppEnvironment.PrimaryColorChanged += foreColorChangedDelegate; AppEnvironment.SecondaryColorChanged += new EventHandler(BackColorChangedHandler); AppEnvironment.AlphaBlendingChanged += new EventHandler(AlphaBlendingChangedHandler); this.threadPool = new PaintDotNet.Threading.ThreadPool(); this.moveNub = new MoveNubRenderer(this.RendererList); this.moveNub.Shape = MoveNubShape.Compass; this.moveNub.Size = new SizeF(10, 10); this.moveNub.Visible = false; this.RendererList.Add(this.moveNub, false); }