Ejemplo n.º 1
0
        public PintaCanvas(CanvasWindow window, Document document)
        {
            CanvasWindow  = window;
            this.document = document;

            cr = new CanvasRenderer(true);

            // Keep the widget the same size as the canvas
            document.Workspace.CanvasSizeChanged += delegate(object sender, EventArgs e) {
                SetRequisition(document.Workspace.CanvasSize);
            };

            // Update the canvas when the image changes
            document.Workspace.CanvasInvalidated += delegate(object sender, CanvasInvalidatedEventArgs e) {
                // If GTK+ hasn't created the canvas window yet, no need to invalidate it
                if (GdkWindow == null)
                {
                    return;
                }

                if (e.EntireSurface)
                {
                    GdkWindow.Invalidate();
                }
                else
                {
                    GdkWindow.InvalidateRect(e.Rectangle, false);
                }
            };

            // Give mouse press events to the current tool
            ButtonPressEvent += delegate(object sender, ButtonPressEventArgs e) {
                // The canvas gets the button press before the tab system, so
                // if this click is on a canvas that isn't currently the ActiveDocument yet,
                // we need to go ahead and make it the active document for the tools
                // to use it, even though right after this the tab system would have switched it
                if (PintaCore.Workspace.ActiveDocument != document)
                {
                    PintaCore.Workspace.SetActiveDocument(document);
                }

                PintaCore.Tools.CurrentTool.DoMouseDown(this, e, document.Workspace.WindowPointToCanvas(e.Event.X, e.Event.Y));
            };

            // Give mouse release events to the current tool
            ButtonReleaseEvent += delegate(object sender, ButtonReleaseEventArgs e) {
                PintaCore.Tools.CurrentTool.DoMouseUp(this, e, document.Workspace.WindowPointToCanvas(e.Event.X, e.Event.Y));
            };

            // Give mouse move events to the current tool
            MotionNotifyEvent += delegate(object sender, MotionNotifyEventArgs e) {
                var point = document.Workspace.WindowPointToCanvas(e.Event.X, e.Event.Y);

                if (document.Workspace.PointInCanvas(point))
                {
                    PintaCore.Chrome.LastCanvasCursorPoint = point.ToGdkPoint();
                }

                if (PintaCore.Tools.CurrentTool != null)
                {
                    PintaCore.Tools.CurrentTool.DoMouseMove((DrawingArea)sender, e, point);
                }
            };
        }
Ejemplo n.º 2
0
        public PintaCanvas()
        {
            cr = new CanvasRenderer();

            // Keep the widget the same size as the canvas
            PintaCore.Workspace.CanvasSizeChanged += delegate(object sender, EventArgs e) {
                SetRequisition(PintaCore.Workspace.CanvasSize);
            };

            // Update the canvas when the image changes
            PintaCore.Workspace.CanvasInvalidated += delegate(object sender, CanvasInvalidatedEventArgs e) {
                if (e.EntireSurface)
                {
                    GdkWindow.Invalidate();
                }
                else
                {
                    GdkWindow.InvalidateRect(e.Rectangle, false);
                }
            };

            // Give mouse press events to the current tool
            ButtonPressEvent += delegate(object sender, ButtonPressEventArgs e) {
                if (PintaCore.Workspace.HasOpenDocuments)
                {
                    PintaCore.Tools.CurrentTool.DoMouseDown(this, e, PintaCore.Workspace.WindowPointToCanvas(e.Event.X, e.Event.Y));
                }
            };

            // Give mouse release events to the current tool
            ButtonReleaseEvent += delegate(object sender, ButtonReleaseEventArgs e) {
                if (PintaCore.Workspace.HasOpenDocuments)
                {
                    PintaCore.Tools.CurrentTool.DoMouseUp(this, e, PintaCore.Workspace.WindowPointToCanvas(e.Event.X, e.Event.Y));
                }
            };

            // Give mouse move events to the current tool
            MotionNotifyEvent += delegate(object sender, MotionNotifyEventArgs e) {
                if (!PintaCore.Workspace.HasOpenDocuments)
                {
                    return;
                }

                Cairo.PointD point = PintaCore.Workspace.ActiveWorkspace.WindowPointToCanvas(e.Event.X, e.Event.Y);

                if (PintaCore.Workspace.ActiveWorkspace.PointInCanvas(point))
                {
                    PintaCore.Chrome.LastCanvasCursorPoint = point.ToGdkPoint();
                }

                if (PintaCore.Tools.CurrentTool != null)
                {
                    PintaCore.Tools.CurrentTool.DoMouseMove(sender, e, point);
                }
            };

            // Handle key press/release events
            KeyPressEvent   += new KeyPressEventHandler(PintaCanvas_KeyPressEvent);
            KeyReleaseEvent += new KeyReleaseEventHandler(PintaCanvas_KeyReleaseEvent);
        }