Skip to content

Added polygon select to lasso tool (#1096) #1725

Merged
cameronwhite merged 8 commits into
PintaProject:masterfrom
PabloRufianJimenez:polygon-select
Sep 12, 2025
Merged

Added polygon select to lasso tool (#1096) #1725
cameronwhite merged 8 commits into
PintaProject:masterfrom
PabloRufianJimenez:polygon-select

Conversation

@PabloRufianJimenez
Copy link
Copy Markdown
Contributor

  • Added new dropdown button to the tool bar of the lasso tool. You can now select between "Freeform mode" and "Polygon mode".
  • Freeform mode works like the old tool.
  • On Polygon mode, when you click, a new point is added to a selection polygon. While holding click, you can move the new point, useful for precision.
  • On Polygon mode, pressing Enter finishes the polygon selection and adds it as to the history. Deselecting the Lasso tool also does this.
  • On Polygon mode, pressing Backspace removes the last point. This can be done consecutively until you remove all points, in which case the selection reverts back to before using the tool.

Let me know if I missed something of if there's something a have to change.

@Lehonti
Copy link
Copy Markdown
Contributor

Lehonti commented Sep 5, 2025

@PabloRufianJimenez, I've had the same build error in 228379e before.

I think it's likely that the files you pushed have a mix of LF and CRLF line endings, and to fix this I would suggest you normalize the line endings to LF before your next commit.

I don't know what development environment you are using, but I think it's Visual Studio (it often messes up line endings when I make changes), and in this case it is easy to do:

image

@PabloRufianJimenez
Copy link
Copy Markdown
Contributor Author

I use JetBrains Rider, but I've checked and all the files I pushed are set to LF.

imagen

@Lehonti
Copy link
Copy Markdown
Contributor

Lehonti commented Sep 5, 2025

@PabloRufianJimenez I see. In any case I think the problem might have something to do with whitespace (the online build tool checks and is picky about these kinds of things). I'd try running dotnet format and see if anything changes.

@PabloRufianJimenez
Copy link
Copy Markdown
Contributor Author

It seems the error was fixed. Thank you!

Copy link
Copy Markdown
Member

@cameronwhite cameronwhite left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great overall!

One thing I noticed during testing is that pressing Ctrl+Shift+A to deselect before finishing the selection doesn't really work to cancel the selection, and any further clicks just resume from before.
I think implementing OnCommit() might be the right way to handle this (and probably fix other similar situations), so that the tool can finalize the selection first

Comment thread Pinta.Tools/Tools/LassoSelectTool.cs Outdated
private CombineMode combine_mode;
private SelectionHistoryItem? hist;

private Path? path;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are some unused variable warnings here, so I think this can be removed? It looks like the original code wasn't really making use of it (probably some leftover code from before the different selection intersection modes were added)

Comment thread Pinta.Tools/Tools/LassoSelectTool.cs Outdated
public override string Name => Translations.GetString ("Lasso Select");
public override string Icon => Pinta.Resources.Icons.ToolSelectLasso;
public override string StatusBarText => Translations.GetString ("Click and drag to draw the outline for a selection area.");
public override string StatusBarText => Translations.GetString ("On Freeform mode, click and drag to draw the outline for a selection area." +
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a couple minor fixes for grammar:

  • I think it should say In Freeform / Polygon mode rather than On
  • The last two lines should also end with a period .

Comment thread Pinta.Tools/Tools/LassoSelectTool.cs Outdated
lasso_polygon.RemoveAt (lasso_polygon.Count - 1);

if (lasso_polygon.Count == 0) {
hist?.Undo ();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this method just have a if (hist == null) return; check at the start, to make it more clear what the preconditions are? If there isn't a history item then there shouldn't be anything to backtrack, from my reading of the code

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Backtrack is not only for reverting to the previous history item, it's also to remove points from the polygon (i.e. vertices). The former only happens after all points are removed, so as to cancel the selection. Even if there's no history item, the user can still remove the last points they added if they messed up and retry.

#1096 (comment)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense, it's really just the hist?.Undo() that I'm concerned about here which implies that hist may or may not be null here

hist is the history item we created in OnMouseDown for the in-progress edit, so it must be non-null if we have a non-empty lasso_polygon right?

Copy link
Copy Markdown
Contributor Author

@PabloRufianJimenez PabloRufianJimenez Sep 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's true. A non-empty lasso_polygon must imply that hist is non-null. The reason I added the question mark in hist?.Undo() is to avoid possible null reference warning. Tell me if you would like to have this removed.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the best solution would be to add something like ArgumentNullException.ThrowIfNull (hist) earlier on in the method. That should you eliminate the ? operator and also makes it more clear what the preconditions are here

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this an icon you created, or one from an existing source? Just checking so that we correctly record the source of it for licensing purposes

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the icon was created by me in Inkscape.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! This can be added to Pinta.Resources/icons/pinta-icons.md then, which lists some of the icons contributed by developers


private Separator? mode_sep;
private Label? lasso_mode_label;
private ToolBarDropDownButton? lasso_mode_buttom;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't notice this before, but the tool should also save the setting to Pinta's preferences and restore it when loading. Something like the Recolor tool would be a simple example to follow (implementing OnSaveSettings() and loading the setting when creating the widget

The selection mode should also have been saving its settings like SelectTool.OnSaveSettings() does..

@cameronwhite cameronwhite linked an issue Sep 10, 2025 that may be closed by this pull request
@cameronwhite cameronwhite merged commit cefb7f7 into PintaProject:master Sep 12, 2025
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Polygon Select to the Lasso tool

4 participants