Esempio n. 1
0
        protected override void OnMouseDown(DrawingArea canvas, ButtonPressEventArgs args, Cairo.PointD point)
        {
            Point pt = point.ToGdkPoint();

            // Grab focus so we can get keystrokes
            PintaCore.Chrome.Canvas.GrabFocus();

            // If we're in editing mode, a right click
            // allows you to move the text around
            if (is_editing && (args.Event.Button == 3))
            {
                tracking        = true;
                startMouseXY    = point;
                startClickPoint = clickPoint;

                SetCursor(cursor_hand);
                return;
            }

            // The user clicked the left mouse button
            if (args.Event.Button == 1)
            {
                // If we're editing and the user clicked within the text,
                // move the cursor to the click location
                if (is_editing && old_bounds.ContainsCorrect(pt))
                {
                    Position p = engine.PointToTextPosition(pt);
                    engine.SetCursorPosition(p);
                    RedrawText(true, true);
                    return;
                }

                // We're already editing and the user clicked outside the text,
                // commit the user's work, and start a new edit
                if (is_editing)
                {
                    switch (engine.EditMode)
                    {
                    // We were editing, save and stop
                    case EditingMode.Editing:
                        StopEditing();
                        break;

                    // We were editing, but nothing had been
                    // keyed. Stop editing.
                    case EditingMode.EmptyEdit:
                        StopEditing();
                        break;
                    }
                }

                // Start editing at the cursor location
                clickPoint = pt;
                StartEditing();
                engine.Origin = clickPoint;
                RedrawText(true, true);
                PintaCore.Workspace.Invalidate();
            }
        }
Esempio n. 2
0
        public PintaCanvas()
        {
            cr = new CanvasRenderer(true);

            // 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);
                }
            };
        }
Esempio n. 3
0
        protected override void OnMouseMove(object o, MotionNotifyEventArgs args, Cairo.PointD point)
        {
            ctrlKey = (args.Event.State & ModifierType.ControlMask) != 0;

            lastMousePosition = point.ToGdkPoint();

            // If we're dragging the text around, do that
            if (tracking)
            {
                Cairo.PointD delta = new Cairo.PointD(point.X - startMouseXY.X, point.Y - startMouseXY.Y);

                clickPoint = new Point((int)(startClickPoint.X + delta.X), (int)(startClickPoint.Y + delta.Y));
                CurrentTextEngine.Origin = clickPoint;

                RedrawText(true, true);
            }
            else
            {
                UpdateMouseCursor();
            }
        }
Esempio n. 4
0
        protected override void OnMouseDown(Gtk.DrawingArea canvas, Gtk.ButtonPressEventArgs args, Cairo.PointD point)
        {
            Document doc = PintaCore.Workspace.ActiveDocument;

            // We only do stuff with the left mouse button
            if (args.Event.Button != 1)
            {
                return;
            }

            // Ctrl click is set origin, regular click is begin drawing
            if (!args.Event.IsControlPressed())
            {
                if (origin.IsNotSet())
                {
                    return;
                }

                painting = true;

                if (offset.IsNotSet())
                {
                    offset = new Point((int)point.X - origin.X, (int)point.Y - origin.Y);
                }

                doc.ToolLayer.Clear();
                doc.ToolLayer.Hidden = false;

                surface_modified = false;
                undo_surface     = doc.CurrentUserLayer.Surface.Clone();
            }
            else
            {
                origin = point.ToGdkPoint();
            }
        }
Esempio n. 5
0
        protected override void OnMouseDown(DrawingArea canvas, ButtonPressEventArgs args, Cairo.PointD point)
        {
            ctrlKey = (args.Event.State & ModifierType.ControlMask) != 0;

            //Store the mouse position.
            Point pt = point.ToGdkPoint();

            // Grab focus so we can get keystrokes
            PintaCore.Chrome.Canvas.GrabFocus();

            if (selection != null)
            {
                selection.Dispose();
            }
            selection = PintaCore.Workspace.ActiveDocument.Selection.Clone();

            // A right click allows you to move the text around
            if (args.Event.Button == 3)
            {
                //The user is dragging text with the right mouse button held down, so track the mouse as it moves.
                tracking = true;

                //Remember the position of the mouse before the text is dragged.
                startMouseXY    = point;
                startClickPoint = clickPoint;

                //Change the cursor to indicate that the text is being dragged.
                SetCursor(cursor_hand);

                return;
            }

            // The user clicked the left mouse button
            if (args.Event.Button == 1)
            {
                // If the user is [editing or holding down Ctrl] and clicked
                //within the text, move the cursor to the click location
                if ((is_editing || ctrlKey) && CurrentTextBounds.ContainsCorrect(pt))
                {
                    StartEditing();

                    //Change the position of the cursor to where the mouse clicked.
                    TextPosition p = CurrentTextLayout.PointToTextPosition(pt);
                    CurrentTextEngine.SetCursorPosition(p, true);

                    //Redraw the text with the new cursor position.
                    RedrawText(true, true);

                    return;
                }

                // We're already editing and the user clicked outside the text,
                // commit the user's work, and start a new edit
                switch (CurrentTextEngine.State)
                {
                // We were editing, save and stop
                case TextMode.Uncommitted:
                    StopEditing(true);
                    break;

                // We were editing, but nothing had been
                // keyed. Stop editing.
                case TextMode.Unchanged:
                    StopEditing(false);
                    break;
                }

                if (ctrlKey)
                {
                    //Go through every UserLayer.
                    foreach (UserLayer ul in PintaCore.Workspace.ActiveDocument.UserLayers)
                    {
                        //Check each UserLayer's editable text boundaries to see if they contain the mouse position.
                        if (ul.textBounds.ContainsCorrect(pt))
                        {
                            //The mouse clicked on editable text.

                            //Change the current UserLayer to the Layer that contains the text that was clicked on.
                            PintaCore.Workspace.ActiveDocument.SetCurrentUserLayer(ul);

                            //The user is editing text now.
                            is_editing = true;

                            //Set the cursor in the editable text where the mouse was clicked.
                            TextPosition p = CurrentTextLayout.PointToTextPosition(pt);
                            CurrentTextEngine.SetCursorPosition(p, true);

                            //Redraw the editable text with the cursor.
                            RedrawText(true, true);

                            //Don't check any more UserLayers - stop at the first UserLayer that has editable text containing the mouse position.
                            return;
                        }
                    }
                }
                else
                {
                    if (CurrentTextEngine.State == TextMode.NotFinalized)
                    {
                        //The user is making a new text and the old text hasn't been finalized yet.
                        FinalizeText();
                    }

                    if (!is_editing)
                    {
                        // Start editing at the cursor location
                        clickPoint = pt;
                        CurrentTextEngine.Clear();
                        clickPoint.Offset(0, -CurrentTextLayout.FontHeight / 2);
                        CurrentTextEngine.Origin = clickPoint;
                        StartEditing();
                        RedrawText(true, true);
                    }
                }
            }
        }