Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions Pinta.Tools/Tools/SelectTool.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
//

Check failure on line 1 in Pinta.Tools/Tools/SelectTool.cs

View workflow job for this annotation

GitHub Actions / build-ubuntu (10.0.x)

Fix whitespace formatting. Replace 1 characters with '\n'.
// SelectTool.cs

Check failure on line 2 in Pinta.Tools/Tools/SelectTool.cs

View workflow job for this annotation

GitHub Actions / build-ubuntu (10.0.x)

Fix whitespace formatting. Replace 1 characters with '\n'.
//

Check failure on line 3 in Pinta.Tools/Tools/SelectTool.cs

View workflow job for this annotation

GitHub Actions / build-ubuntu (10.0.x)

Fix whitespace formatting. Replace 1 characters with '\n'.
// Author:

Check failure on line 4 in Pinta.Tools/Tools/SelectTool.cs

View workflow job for this annotation

GitHub Actions / build-ubuntu (10.0.x)

Fix whitespace formatting. Replace 1 characters with '\n'.
// Jonathan Pobst <monkey@jpobst.com>

Check failure on line 5 in Pinta.Tools/Tools/SelectTool.cs

View workflow job for this annotation

GitHub Actions / build-ubuntu (10.0.x)

Fix whitespace formatting. Replace 1 characters with '\n'.
//

Check failure on line 6 in Pinta.Tools/Tools/SelectTool.cs

View workflow job for this annotation

GitHub Actions / build-ubuntu (10.0.x)

Fix whitespace formatting. Replace 1 characters with '\n'.
// Copyright (c) 2010 Jonathan Pobst

Check failure on line 7 in Pinta.Tools/Tools/SelectTool.cs

View workflow job for this annotation

GitHub Actions / build-ubuntu (10.0.x)

Fix whitespace formatting. Replace 1 characters with '\n'.
//

Check failure on line 8 in Pinta.Tools/Tools/SelectTool.cs

View workflow job for this annotation

GitHub Actions / build-ubuntu (10.0.x)

Fix whitespace formatting. Replace 1 characters with '\n'.
// Permission is hereby granted, free of charge, to any person obtaining a copy

Check failure on line 9 in Pinta.Tools/Tools/SelectTool.cs

View workflow job for this annotation

GitHub Actions / build-ubuntu (10.0.x)

Fix whitespace formatting. Replace 1 characters with '\n'.
// of this software and associated documentation files (the "Software"), to deal

Check failure on line 10 in Pinta.Tools/Tools/SelectTool.cs

View workflow job for this annotation

GitHub Actions / build-ubuntu (10.0.x)

Fix whitespace formatting. Replace 1 characters with '\n'.
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
Expand All @@ -28,6 +28,7 @@
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using Gtk;
using Pinta.Core;

namespace Pinta.Tools;
Expand All @@ -39,6 +40,9 @@

private SelectionHistoryItem? hist = default;
private CombineMode combine_mode = default;
private Separator? mode_sep;
private Label? movable_view_label;
private CheckButton? movable_view;

public override Gdk.Key ShortcutKey => new (Gdk.Constants.KEY_S);
public override bool IsSelectionTool => true;
Expand All @@ -62,6 +66,12 @@
{
base.OnBuildToolBar (tb);
workspace.SelectionHandler.BuildToolbar (tb, Settings);

tb.Append (Separator);

tb.Append (MovableViewLabel);
tb.Append (MovableView);
MovableView.Active = true;
}

protected override void OnMouseDown (Document document, ToolMouseEventArgs e)
Expand Down Expand Up @@ -101,6 +111,29 @@
ReDraw (document);

SelectionModeHandler.PerformSelectionMode (document, combine_mode, document.Selection.SelectionPolygons);

if (!MovableView.Active)
return;

var view = (Gtk.Viewport) document.Workspace.Canvas.Parent!;
var h_adjust = view.GetHadjustment ()!.PageSize;
var v_adjust = view.GetVadjustment ()!.PageSize;

//step of 10 pixels or of 2% of visible area, whichever is greater
int canvasStep = (int)Math.Max (10, h_adjust * 0.02);

PointI direction = default;
if (e.RootPoint.X < 0)
direction = new PointI (-canvasStep, 0); //move left
if (e.RootPoint.Y < 0)
direction = new PointI (0, -canvasStep); //move up
if (e.RootPoint.X > h_adjust)
direction = new PointI (canvasStep, 0); //move right
if (e.RootPoint.Y > v_adjust)
direction = new PointI (0, canvasStep); //move down

if (direction != default)
document.Workspace.ScrollCanvas (direction);
}

protected override void OnMouseUp (Document document, ToolMouseEventArgs e)
Expand Down Expand Up @@ -211,4 +244,8 @@
handle.Rectangle = selection.HandleBounds;
ShowHandles (document.Selection.Visible && tools.CurrentTool == this);
}

private Separator Separator => mode_sep ??= GtkExtensions.CreateToolBarSeparator ();
private Label MovableViewLabel => movable_view_label ??= Label.New ((string.Format (" {0}: ", Translations.GetString ("Movable view"))));
private CheckButton MovableView => movable_view ??= CheckButton.New ();
}
Loading