Example #1
0
        private void Activate()
        {
            Debug.Assert(this.active != true, "already active!");
            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.panTracking = false;
            this.panMode     = false;
            this.mouseDown   = 0;
            this.savedTiles  = null;
            this.saveRegion  = null;

            this.scratchSurface = DocumentWorkspace.BorrowScratchSurface(this.GetType().Name + ": Tool.Activate()");
#if DEBUG
            this.haveClearedScratch = false;
#endif

            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();
        }
Example #2
0
        private void Deactivate()
        {
            Debug.Assert(this.active != false, "not active!");

            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;
            }
        }
Example #3
0
        private void Deactivate()
        {
            Debug.Assert(this.active != false, "not active!");

            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;
            }
        }
Example #4
0
        private void Activate()
        {
            Debug.Assert(this.active != true, "already active!");
            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.panTracking = false;
            this.panMode = false;
            this.mouseDown = 0;
            this.savedTiles = null;
            this.saveRegion = null;

            this.scratchSurface = DocumentWorkspace.BorrowScratchSurface(this.GetType().Name + ": Tool.Activate()");
            #if DEBUG
            this.haveClearedScratch = false;
            #endif

            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();
        }
Example #5
0
        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();
        }
Example #6
0
        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();
        }
Example #7
0
        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);
        }
Example #8
0
        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);
        }
Example #9
0
        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;
            }
        }
Example #10
0
        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);
        }