예제 #1
0
        /// <summary>
        /// Finalize re-editable text (if applicable).
        /// </summary>
        public void FinalizeText()
        {
            //If this is true, don't finalize any text - this is used to prevent the code from looping recursively.
            if (!ignoreCloneFinalizations)
            {
                //Only bother finalizing text if editing.
                if (CurrentTextEngine.State != TextMode.Unchanged)
                {
                    //Start ignoring any Surface.Clone calls from this point on (so that it doesn't start to loop).
                    ignoreCloneFinalizations = true;
                    Document doc = PintaCore.Workspace.ActiveDocument;

                    //Create a backup of everything before redrawing the text and etc.
                    Cairo.ImageSurface oldTextSurface = doc.Layers.CurrentUserLayer.TextLayer.Layer.Surface.Clone();
                    Cairo.ImageSurface oldUserSurface = doc.Layers.CurrentUserLayer.Surface.Clone();
                    TextEngine         oldTextEngine  = CurrentTextEngine.Clone();

                    //Draw the text onto the UserLayer (without the cursor) rather than the TextLayer.
                    RedrawText(false, false);

                    //Clear the TextLayer.
                    doc.Layers.CurrentUserLayer.TextLayer.Layer.Clear();

                    //Clear the text and its boundaries.
                    CurrentTextEngine.Clear();
                    CurrentTextBounds = Gdk.Rectangle.Zero;

                    //Create a new TextHistoryItem so that the finalization of the text can be undone. Construct
                    //it on the spot so that it is more memory efficient if the changes are small.
                    TextHistoryItem hist = new TextHistoryItem(Icon, FinalizeName, oldTextSurface, oldUserSurface,
                                                               oldTextEngine, doc.Layers.CurrentUserLayer);

                    //Add the new TextHistoryItem.
                    doc.History.PushNewItem(hist);

                    //Stop ignoring any Surface.Clone calls from this point on.
                    ignoreCloneFinalizations = false;

                    //Now that the text has been finalized, change its state.
                    CurrentTextEngine.State = TextMode.Unchanged;

                    if (selection != null)
                    {
                        selection.Dispose();
                        selection = null;
                    }
                }
            }
        }
예제 #2
0
        protected override void OnMouseDown(Document document, ToolMouseEventArgs e)
        {
            ctrlKey = e.IsControlPressed;

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

            // Grab focus so we can get keystrokes
            imContext.FocusIn();

            if (selection != null)
            {
                selection.Dispose();
            }
            selection = document.Selection.Clone();

            // A right click allows you to move the text around
            if (e.MouseButton == MouseButton.Right)
            {
                //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    = e.PointDouble;
                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 (e.MouseButton == MouseButton.Left)
            {
                // 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 document.Layers.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.
                            document.Layers.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();
                        UpdateFont();
                        clickPoint.Offset(0, -CurrentTextLayout.FontHeight / 2);
                        CurrentTextEngine.Origin = clickPoint;
                        StartEditing();
                        RedrawText(true, true);
                    }
                }
            }
        }
예제 #3
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.DisposeSelection();
            }
            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.
                    Position p = CurrentTextEngine.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.EditMode)
                {
                // We were editing, save and stop
                case EditingMode.Editing:
                    StopEditing(true);
                    break;

                // We were editing, but nothing had been
                // keyed. Stop editing.
                case EditingMode.EmptyEdit:
                    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.
                            Position p = CurrentTextEngine.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.textMode == 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, -CurrentTextEngine.FontHeight / 2);
                        CurrentTextEngine.Origin = clickPoint;
                        StartEditing();
                        RedrawText(true, true);
                    }
                }
            }
        }