Skip to content

Commit

Permalink
Add keyboard shortcut for changing the brush size or line width (#1155)
Browse files Browse the repository at this point in the history
* Add keyboard shortcut for changing the brush size or line width

* Refactor brush size changing code

* Add tooltip to brush size SpinButton
  • Loading branch information
solarnomad7 authored Nov 22, 2024
1 parent 4b59487 commit 280d2fd
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
10 changes: 8 additions & 2 deletions Pinta.Tools/Editable/EditEngines/BaseEditEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,7 @@ public ShapeEngine? ActiveShapeEngine {

protected virtual void BrushMinusButtonClickedEvent (object? o, EventArgs args)
{
if (BrushWidth > 1)
BrushWidth--;
BrushWidth--;

//No need to store previous settings or redraw, as this is done in the Changed event handler.
}
Expand Down Expand Up @@ -278,6 +277,7 @@ public virtual void HandleBuildToolBar (Gtk.Box tb, ISettingsService settings, s
if (brush_width == null) {

brush_width = GtkExtensions.CreateToolBarSpinButton (1, 1e5, 1, settings.GetSetting (BRUSH_WIDTH_SETTING (toolPrefix), BaseTool.DEFAULT_BRUSH_WIDTH));
brush_width.TooltipText = Translations.GetString ("Change brush width. Shortcut keys: [ ]");

brush_width.OnValueChanged += (o, e) => {

Expand Down Expand Up @@ -489,6 +489,12 @@ public virtual bool HandleKeyDown (Document document, ToolKeyEventArgs e)
case Gdk.Key.Right:
HandleRight (e);
return true;
case Gdk.Key.bracketleft:
BrushWidth--;
return true;
case Gdk.Key.bracketright:
BrushWidth++;
return true;
default:
if (keyPressed.IsControlKey ()) {
// Redraw since the Ctrl key affects the hover cursor, etc
Expand Down
25 changes: 24 additions & 1 deletion Pinta.Tools/Tools/BaseBrushTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,19 @@ public abstract class BaseBrushTool : BaseTool
protected BaseBrushTool (IServiceProvider services) : base (services)
{
Palette = services.GetService<IPaletteService> ();

BrushWidthSpinButton.TooltipText = Translations.GetString ("Change brush width. Shortcut keys: [ ]");
}

protected override bool ShowAntialiasingButton => true;

protected int BrushWidth => brush_width?.GetValueAsInt () ?? DEFAULT_BRUSH_WIDTH;
protected int BrushWidth {
get => brush_width?.GetValueAsInt () ?? DEFAULT_BRUSH_WIDTH;
set {
if (brush_width is not null)
brush_width.Value = value;
}
}

protected override void OnBuildToolBar (Box tb)
{
Expand Down Expand Up @@ -86,6 +94,21 @@ protected override void OnMouseUp (Document document, ToolMouseEventArgs e)
mouse_button = MouseButton.None;
}

protected override bool OnKeyDown (Document document, ToolKeyEventArgs e)
{
Gdk.Key keyPressed = e.Key;
switch (keyPressed) {
case Gdk.Key.bracketleft:
BrushWidth--;
return true;
case Gdk.Key.bracketright:
BrushWidth++;
return true;
}

return base.OnKeyDown (document, e);
}

protected override void OnSaveSettings (ISettingsService settings)
{
base.OnSaveSettings (settings);
Expand Down

0 comments on commit 280d2fd

Please sign in to comment.