diff --git a/Pinta.Tools/Handles/MoveHandle.cs b/Pinta.Tools/Handles/MoveHandle.cs index 8bf0ef7cc..fae542b39 100644 --- a/Pinta.Tools/Handles/MoveHandle.cs +++ b/Pinta.Tools/Handles/MoveHandle.cs @@ -12,6 +12,7 @@ public sealed class MoveHandle : IToolHandle private static readonly Cairo.Color fill_color = new (0, 0, 1, 1); private static readonly Cairo.Color selection_fill_color = new (1, 0.5, 0, 1); private static readonly Cairo.Color stroke_color = new (1, 1, 1, 0.7); + private static Gdk.Cursor default_cursor = GdkExtensions.CursorFromName (Pinta.Resources.StandardCursors.Default); public PointD CanvasPosition { get; set; } @@ -25,7 +26,7 @@ public sealed class MoveHandle : IToolHandle /// public bool Selected { get; set; } = false; - public string CursorName { get; init; } = Pinta.Resources.StandardCursors.Default; + public Gdk.Cursor Cursor { get; init; } = default_cursor; /// /// Tests whether the window point is inside the handle's area. diff --git a/Pinta.Tools/Tools/EllipseSelectTool.cs b/Pinta.Tools/Tools/EllipseSelectTool.cs index 5d3d03bd5..b59cd3337 100644 --- a/Pinta.Tools/Tools/EllipseSelectTool.cs +++ b/Pinta.Tools/Tools/EllipseSelectTool.cs @@ -31,12 +31,15 @@ namespace Pinta.Tools; public sealed class EllipseSelectTool : SelectTool { - public EllipseSelectTool (IServiceProvider services) : base (services) { } + public EllipseSelectTool (IServiceProvider services) : base (services) + { + DefaultCursor = Gdk.Cursor.NewFromTexture (Resources.GetIcon ("Cursor.EllipseSelect.png"), 9, 18, null); + } public override string Name => Translations.GetString ("Ellipse Select"); public override string Icon => Pinta.Resources.Icons.ToolSelectEllipse; public override string StatusBarText => Translations.GetString ("Click and drag to draw an elliptical selection.\nHold Shift to constrain to a circle."); - public override Gdk.Cursor DefaultCursor => Gdk.Cursor.NewFromTexture (Resources.GetIcon ("Cursor.EllipseSelect.png"), 9, 18, null); + public override Gdk.Cursor DefaultCursor { get; } public override int Priority => 15; protected override void DrawShape (Document document, RectangleD r, Layer l) diff --git a/Pinta.Tools/Tools/EllipseTool.cs b/Pinta.Tools/Tools/EllipseTool.cs index 8d75fb575..775eef23b 100644 --- a/Pinta.Tools/Tools/EllipseTool.cs +++ b/Pinta.Tools/Tools/EllipseTool.cs @@ -36,6 +36,8 @@ public sealed class EllipseTool : ShapeTool public EllipseTool (IServiceProvider services) : base (services) { this.services = services; + DefaultCursor = Gdk.Cursor.NewFromTexture (Resources.GetIcon ("Cursor.Ellipse.png"), 9, 18, null); + BaseEditEngine.CorrespondingTools[ShapeType] = this; } @@ -45,8 +47,7 @@ public override string Name public override string Icon => Pinta.Resources.Icons.ToolEllipse; - public override Gdk.Cursor DefaultCursor - => Gdk.Cursor.NewFromTexture (Resources.GetIcon ("Cursor.Ellipse.png"), 9, 18, null); + public override Gdk.Cursor DefaultCursor { get; } public override int Priority => 43; diff --git a/Pinta.Tools/Tools/LineCurveTool.cs b/Pinta.Tools/Tools/LineCurveTool.cs index bbb2aec76..046f3f6f4 100644 --- a/Pinta.Tools/Tools/LineCurveTool.cs +++ b/Pinta.Tools/Tools/LineCurveTool.cs @@ -35,12 +35,14 @@ public sealed class LineCurveTool : ShapeTool public LineCurveTool (IServiceProvider services) : base (services) { this.services = services; + DefaultCursor = Gdk.Cursor.NewFromTexture (Resources.GetIcon ("Cursor.Line.png"), 9, 18, null); + BaseEditEngine.CorrespondingTools[ShapeType] = this; } public override string Name => Translations.GetString ("Line/Curve"); public override string Icon => Pinta.Resources.Icons.ToolLine; - public override Gdk.Cursor DefaultCursor => Gdk.Cursor.NewFromTexture (Resources.GetIcon ("Cursor.Line.png"), 9, 18, null); + public override Gdk.Cursor DefaultCursor { get; } public override int Priority => 37; public override BaseEditEngine.ShapeTypes ShapeType diff --git a/Pinta.Tools/Tools/RectangleSelectTool.cs b/Pinta.Tools/Tools/RectangleSelectTool.cs index 2f834f554..7dd052145 100644 --- a/Pinta.Tools/Tools/RectangleSelectTool.cs +++ b/Pinta.Tools/Tools/RectangleSelectTool.cs @@ -31,14 +31,17 @@ namespace Pinta.Tools; public sealed class RectangleSelectTool : SelectTool { - public RectangleSelectTool (IServiceProvider services) : base (services) { } + public RectangleSelectTool (IServiceProvider services) : base (services) + { + DefaultCursor = Gdk.Cursor.NewFromTexture (Resources.GetIcon ("Cursor.RectangleSelect.png"), 9, 18, null); + } public override string Name => Translations.GetString ("Rectangle Select"); public override string Icon => Pinta.Resources.Icons.ToolSelectRectangle; public override string StatusBarText => Translations.GetString ( "Click and drag to draw a rectangular selection." + "\nHold Shift to constrain to a square."); - public override Gdk.Cursor DefaultCursor => Gdk.Cursor.NewFromTexture (Resources.GetIcon ("Cursor.RectangleSelect.png"), 9, 18, null); + public override Gdk.Cursor DefaultCursor { get; } public override int Priority => 13; protected override void DrawShape (Document document, RectangleD r, Layer l) diff --git a/Pinta.Tools/Tools/RectangleTool.cs b/Pinta.Tools/Tools/RectangleTool.cs index a42c273b5..66750fccf 100644 --- a/Pinta.Tools/Tools/RectangleTool.cs +++ b/Pinta.Tools/Tools/RectangleTool.cs @@ -35,12 +35,14 @@ public sealed class RectangleTool : ShapeTool public RectangleTool (IServiceProvider services) : base (services) { this.services = services; + DefaultCursor = Gdk.Cursor.NewFromTexture (Resources.GetIcon ("Cursor.Rectangle.png"), 9, 18, null); + BaseEditEngine.CorrespondingTools[ShapeType] = this; } public override string Name => Translations.GetString ("Rectangle"); public override string Icon => Pinta.Resources.Icons.ToolRectangle; - public override Gdk.Cursor DefaultCursor => Gdk.Cursor.NewFromTexture (Resources.GetIcon ("Cursor.Rectangle.png"), 9, 18, null); + public override Gdk.Cursor DefaultCursor { get; } public override int Priority => 39; public override BaseEditEngine.ShapeTypes ShapeType diff --git a/Pinta.Tools/Tools/RoundedRectangleTool.cs b/Pinta.Tools/Tools/RoundedRectangleTool.cs index 7e07cf6e5..2148cd0e7 100644 --- a/Pinta.Tools/Tools/RoundedRectangleTool.cs +++ b/Pinta.Tools/Tools/RoundedRectangleTool.cs @@ -35,6 +35,8 @@ public sealed class RoundedRectangleTool : ShapeTool public RoundedRectangleTool (IServiceProvider services) : base (services) { this.services = services; + DefaultCursor = Gdk.Cursor.NewFromTexture (Resources.GetIcon ("Cursor.RoundedRectangle.png"), 9, 18, null); + BaseEditEngine.CorrespondingTools[ShapeType] = this; } @@ -44,8 +46,7 @@ public override string Name public override string Icon => Pinta.Resources.Icons.ToolRectangleRounded; - public override Gdk.Cursor DefaultCursor - => Gdk.Cursor.NewFromTexture (Resources.GetIcon ("Cursor.RoundedRectangle.png"), 9, 18, null); + public override Gdk.Cursor DefaultCursor { get; } public override int Priority => 41; diff --git a/Pinta.Tools/Tools/SelectTool.cs b/Pinta.Tools/Tools/SelectTool.cs index 9ac6e972c..0549183c3 100644 --- a/Pinta.Tools/Tools/SelectTool.cs +++ b/Pinta.Tools/Tools/SelectTool.cs @@ -48,7 +48,6 @@ public abstract class SelectTool : BaseTool private readonly MoveHandle[] handles = new MoveHandle[8]; private int? active_handle; - private string? active_cursor_name; public override Gdk.Key ShortcutKey => Gdk.Key.S; protected override bool ShowAntialiasingButton => false; @@ -59,14 +58,14 @@ public SelectTool (IServiceProvider services) : base (services) tools = services.GetService (); workspace = services.GetService (); - handles[0] = new MoveHandle { CursorName = Pinta.Resources.StandardCursors.ResizeNW }; - handles[1] = new MoveHandle { CursorName = Pinta.Resources.StandardCursors.ResizeSW }; - handles[2] = new MoveHandle { CursorName = Pinta.Resources.StandardCursors.ResizeNE }; - handles[3] = new MoveHandle { CursorName = Pinta.Resources.StandardCursors.ResizeSE }; - handles[4] = new MoveHandle { CursorName = Pinta.Resources.StandardCursors.ResizeW }; - handles[5] = new MoveHandle { CursorName = Pinta.Resources.StandardCursors.ResizeN }; - handles[6] = new MoveHandle { CursorName = Pinta.Resources.StandardCursors.ResizeE }; - handles[7] = new MoveHandle { CursorName = Pinta.Resources.StandardCursors.ResizeS }; + handles[0] = new MoveHandle { Cursor = GdkExtensions.CursorFromName (Pinta.Resources.StandardCursors.ResizeNW) }; + handles[1] = new MoveHandle { Cursor = GdkExtensions.CursorFromName (Pinta.Resources.StandardCursors.ResizeSW) }; + handles[2] = new MoveHandle { Cursor = GdkExtensions.CursorFromName (Pinta.Resources.StandardCursors.ResizeNE) }; + handles[3] = new MoveHandle { Cursor = GdkExtensions.CursorFromName (Pinta.Resources.StandardCursors.ResizeSE) }; + handles[4] = new MoveHandle { Cursor = GdkExtensions.CursorFromName (Pinta.Resources.StandardCursors.ResizeW) }; + handles[5] = new MoveHandle { Cursor = GdkExtensions.CursorFromName (Pinta.Resources.StandardCursors.ResizeN) }; + handles[6] = new MoveHandle { Cursor = GdkExtensions.CursorFromName (Pinta.Resources.StandardCursors.ResizeE) }; + handles[7] = new MoveHandle { Cursor = GdkExtensions.CursorFromName (Pinta.Resources.StandardCursors.ResizeS) }; workspace.SelectionChanged += AfterSelectionChange; } @@ -347,14 +346,12 @@ private void UpdateCursor (Document document, PointD window_point) { var active_handle = FindHandleUnderPoint (window_point); if (active_handle is not null) { - SetCursor (Cursor.NewFromName (active_handle.CursorName, null)); - active_cursor_name = active_handle.CursorName; + SetCursor (active_handle.Cursor); return; } - if (active_cursor_name != null) { + if (CurrentCursor != DefaultCursor) { SetCursor (DefaultCursor); - active_cursor_name = null; } } diff --git a/Pinta.Tools/Tools/TextTool.cs b/Pinta.Tools/Tools/TextTool.cs index 6b599526c..8dcc38b19 100644 --- a/Pinta.Tools/Tools/TextTool.cs +++ b/Pinta.Tools/Tools/TextTool.cs @@ -96,8 +96,7 @@ public override int Priority public override string StatusBarText => Translations.GetString ("Left click to place cursor, then type desired text. Text color is primary color."); - public override Gdk.Cursor DefaultCursor - => GdkExtensions.CursorFromName (Pinta.Resources.StandardCursors.Text); + public override Gdk.Cursor DefaultCursor { get; } private readonly IWorkspaceService workspace; private readonly IPaletteService palette; @@ -118,6 +117,8 @@ public TextTool (IServiceProvider services) : base (services) im_context.OnPreeditEnd += OnPreeditEnd; layout = new Pinta.Core.TextLayout (); + + DefaultCursor = GdkExtensions.CursorFromName (Pinta.Resources.StandardCursors.Text); } #endregion