Commit graph

257 commits

Author SHA1 Message Date
Karol Kosek
5a5f6d11ef PixelPaint: Close image tabs on middle click 2021-09-25 23:34:02 +02:00
Karol Kosek
df195188bc PixelPaint: Close New Image dialog after pressing return key
13e526de43 added the feature to new Layer
dialog. This patch adds it to Image dialog to stay consistent across
the app. :^)
2021-09-25 23:34:02 +02:00
Marcus Nilsson
f9e0815c3b PixelPaint: Move Tools to it's own subdirectory
The PixelPaint source directory was getting a bit large, let's move all
the Tools to it's own subdirectory. Also remove some unused includes.
2021-09-20 03:04:24 +00:00
Karol Kosek
65a5d66387 PixelPaint: Use main window's icon in the 'Create new image' widget 2021-09-19 20:05:58 +02:00
Mustafa Quraish
090962823b PixelPaint: Allow selecting a custom aspect ratio for RectangleTool
If you enter a custom aspect ratio, and are not holding down shift,
the rectangle will be constrained to the entered aspect ratio
2021-09-17 11:54:13 +02:00
Mustafa Quraish
6ba3fc559f PixelPaint: Allow selecting a custom aspect ratio for EllipseTool
If you enter a custom aspect ratio, and are not holding down shift,
the bounding rect for the ellipse will be constrained to the entered
aspect ratio
2021-09-17 11:54:13 +02:00
Mustafa Quraish
f14c891ba5 LibGfx+PixelPaint: Add Point::end_point_for_aspect_ratio method
Previously we only had `Point::end_point_for_square_aspect_ratio`,
which was convenient for PixelPaint but assumed the aspect ratio
was always fixed at 1. This patch replaces it with a new mthod that
takes in an arbitrary aspect ratio and computes the end point based
off that.

There's some explicit casting going on in `Point.cpp` to ensure that
the types line up, since we're templating Point based on `T`.`
2021-09-17 11:54:13 +02:00
Marcus Nilsson
dc9b18da22 PixelPaint: Implement automatic scrolling in LayerListWidget
The previous implementation of automatic scrolling in LayerListWidget
relied on mousemove events to perform the scrolling, which didn't
produce the expected behavior. Instead use the new auto scroll timer.
2021-09-16 22:29:21 +02:00
Marcus Nilsson
9fe43041f5 PixelPaint: Tweak layer/tool properties widget heights
There's no use for these two to be larger than necessary when
resizing the window.
2021-09-16 16:54:34 +02:00
Marcus Nilsson
b76fe6357a PixelPaint: Don't select the same layer twice in LayerListWidget
Without this check we would do an unnecessary partial second round
trip because of the call chain:
LayerListWidget::set_selected_layer() ->
LayerListWidget::on_layer_select() ->
ImageEditor::set_active_layer() ->
ImageEditor::on_active_layer_change() ->
LayerListWidget::set_selected_layer()
2021-09-16 16:54:34 +02:00
Marcus Nilsson
eaa99968fb PixelPaint: Don't update ImageEditor in set_active_layer()
Setting the active layer does not cause anything to render differently.
Thus no update is needed and the call to layers_did_change() is
unnecessary.
2021-09-16 16:54:34 +02:00
Zyper
344397557c PixelPaint: Add ability to draw squares and circles
Shift-key modifier for tools forces square aspect ratio.
It allows drawing squares with Rectangle Tool and circles
with Ellipse Tool.
2021-09-15 00:10:14 +00:00
Mustafa Quraish
0f749681a9 Everywhere: Use my fancy new serenityos.org email :^) 2021-09-13 20:51:50 +00:00
Mustafa Quraish
f28b2a875a PixelPaint: Make CloneTool change cursor temporarily while selecting
This just provides some nice visual feedback when you are in the
middle of selecting a color. An eyedropper might not be the ideal
choice here, but among the cursors we already have it is the
best one.
2021-09-13 22:13:22 +02:00
Mustafa Quraish
11263beaca PixelPaint: Add ImageEditor::update_tool_cursor() method
This just allows us to ask the image editor to update the tool's
current cursor. This is useful in cases where a tool may want to
change it's cursor for some operation, and wants to invalidate the
active cursor cached in the ImageEditor.
2021-09-13 22:13:22 +02:00
Mustafa Quraish
0472063b96 PixelPaint: Add a marker for CloneTool's selected position
Now we add a little marker to show the current sample position of
the CloneTool. The current implementation for updating the cursor
location is really dumb since it just updates the whole editor,
but that's a yak on the stack to fix.
2021-09-13 22:13:22 +02:00
Mustafa Quraish
fafbe417d1 PixelPaint: Incorporate CloneTool into toolbox 2021-09-13 22:13:22 +02:00
Mustafa Quraish
22b78226b3 PixelPaint: Add Clone Tool :^)
There's still a lot to be desired in terms of functionality and
usability, but this is a start. When using the clone tool, you
can press Alt to sample a location, and then the brush will clone
the color from there.
2021-09-13 22:13:22 +02:00
Mustafa Quraish
1d47d41c01 PixelPaint: Fix Line/Rectangle second paint alignment with pixels
The problem was a bit more complex than originally anticipated,
and the root of the problem is that the "coordinates" of a pixel
are actually the top left of the pixel, and when we're really
zoomed in, the difference in editor coordinates of the top-left
and the center of the pixel is significant.

So, we need to offset the "start" point when we are painting on
the editor to account for this, based on the current scale. This
patch adds a `editor_stroke_position` in `Tool` which can be used
to compute what point (in editor coords) we should use for a given
pixel and it's corresponding stroke thickness.

Note that this doesn't really work well with the ellipse, since that
is drawn with a different mechanism. Using this new method with the
`EllipseTool` seems to give the same (or slightly worse) results, so
I have not changed anything there for now.
2021-09-13 13:43:53 +02:00
Mustafa Quraish
9097f86e51 PixelPaint: Call Layer::did_modify_bitmap() after drawing Ellipse
Previously, Any potential ImageClients would not have received an
update about the layer bitmap having been modified. This is similar
to what the other shape tools do upon completion.
2021-09-13 13:43:53 +02:00
Mustafa Quraish
a5c8d1f7dd PixelPaint: Update editor after drawing shapes to clear outside
Previously, we didn't ask the editor to update after drawing a
Rectangle/Line. This meant that if any part of your shape went
outside the bounds of the image, that part would not be cleared out
until the next update of the editor.
2021-09-13 13:43:53 +02:00
Mustafa Quraish
36bcd63c0c PixelPaint: Ensure thickness of shapes is never 0 when drawing
When drawing a line/rectangle/ellipse in `Tool::on_second_paint()`,
if `m_thickness * m_editor->scale()` was less than one, it would
get converted to 0 because of truncation. This was causing infinite
loops somewhere in the painter code and causing the application to
freeze.

Fixes #9986.
2021-09-13 13:43:53 +02:00
Mustafa Quraish
c0373c3119 PixelPaint: Allowing drawing line from center, like other shapes
You could draw a Rectangle/Ellipse from the center by pressing down
the Alt key, but this was missing for lines. This commit adds it in
to keep consistency among the different shapes.
2021-09-13 13:43:53 +02:00
Mustafa Quraish
c5b14fce54 PixelPaint: Adjust menu ampersand shortcut characters
A few of the menu items were missing shortcut characters completely,
so in the interest of keyboard navigation some have been added (even
if they are not ideal).

In a few menus, severals actions had the same menu shortcut, so the
later ones were not accessible through it. These have also been
differentiated.
2021-09-13 13:43:53 +02:00
Mustafa Quraish
351dee4f8f PixelPaint: Properly transfer active tool to editor on tab close
Previously the code assumed that the active tool had a reference to
the old editor, which is the only way we had to check if it is
active without having a reference to the editor. However, when a
tab in PixelPaint is closed, the editor is destroyed, so the `WeakPtr`
in a tool referencing the old editor is no longer valid.

This made it so that if you closed a tab, the tool would appear to be
selected in the ToolBox, but the editor would not know about it at all.
2021-09-13 13:43:53 +02:00
Mustafa Quraish
ecf8f243a6 PixelPaint: Have ToolboxWidget keep track of active tool
Since there's only one global toolbox, it makes sense to store the
active tool in here, since we don't really have control over the
deletion of an editor.
2021-09-13 13:43:53 +02:00
Mustafa Quraish
ee25e2adc2 PixelPaint: Call Layer::did_modify_bitmap() when applying filters
Previously applying filters was not calling this method, which was
not correctly triggering the `image_did_modify_bitmap` call for
the `ImageClient`s. This patch makes the filter actions call this
method.

It seems that just opening one of the Window menus triggers a repaint
of the entire editor, which is what was causing filters to update
earlier, since we were only accessing them from the menu. Using
the keyboard shortcut added in a previous commit highlighted this issue.
2021-09-13 13:43:53 +02:00
Mustafa Quraish
672c4cdbc2 PixelPaint: Add keyboard shortcut for Invert filter
Many of the popular photo editing applications have Ctrl+I as a
shortcut to invert the colors, so let's get on board :^)
2021-09-13 13:43:53 +02:00
Mustafa Quraish
3dccafb2a0 PixelPaint: Draw layers from the top of LayerList
As pointed out by Andreas, drawing them from the bottom feels odd
since no other list in the UI is bottom-justified. The commit draws
the layers from the top of the list again.
2021-09-13 13:43:53 +02:00
Mustafa Quraish
2afa28d297 PixelPaint: Let PickerTool optionally sample all layers
Previously, only the color from the selected layer would be picked.
Now, we allow the user to select if they want to sample the color
from all layers.
2021-09-12 17:48:14 +02:00
Mustafa Quraish
70d13ea66b PixelPaint: Write changed settings back to config file
In a previous commit we read default values from a commit file, this
commit now also writes back any changes to those settings made by
the user. Persistent settings always feel good :^)
2021-09-12 17:15:30 +02:00
Mustafa Quraish
677aa7b769 PixelPaint: Use config to get default values for Guides/Rulers/PixelGrid
Someone may not want to have these things enabled by default on every
startup, but toggle them on manually. So instead of having hard-coded
everything to be enabled by default, we now query LibConfig to find
out what the preference is. These values can still always be changed
from the Menus / with shortcuts.

It's not really ideal querying LibConfig twice, but when initializing
the menu we may not have an active editor, so we need to get the
value for both the menu checkbox as well as the internal property.
This shouldn't be too much of a big deal since LibConfig caches the
values anyway :^)
2021-09-12 17:15:30 +02:00
Mustafa Quraish
dd0cc58d6c PixelPaint: Allow panning when right-clicking with MoveTool
The MoveTool now lets you pan if you're dragging with a right click.
Previously, right-clicking did not perform any actions at all, so this
isn't removing any old functionality.
2021-09-12 17:14:57 +02:00
Mustafa Quraish
abefe2391d PixelPaint: Add setter/getter for ImageEditor::m_pan_origin
This allows us to use tools to change the panned position, since
right now this is only accessible internally to the editor.
2021-09-12 17:14:57 +02:00
Tobias Christiansen
acf3e230b0 PixelPaint: Fix zooming to cursor
This patch fixes the behavior of zooming. Now the cursor stays over the
same spot in the image when zooming.
2021-09-12 16:30:09 +02:00
Mustafa Quraish
d38d03ce28 PixelPaint: Fit image to view when opened
When opening a file, make it fit on the screen. I think this is
sensible default behaviour.
2021-09-12 00:17:04 +02:00
Mustafa Quraish
f890f8529a PixelPaint: Make Fit Image To View account for rulers
Because of the way rulers are implemented in the ImageEditor
currently, the `Fit Image To View` action doesn't work correctly
with them enabled. This patch makes them adjust to the effective
viewport area and account for the rulers.

This is a bit of a hack, but the correct way to deal with this would
be to put the rulers in a new widget so they don't interfere with
the actual viewport rect (which is being used all over).
2021-09-12 00:17:04 +02:00
Mustafa Quraish
1e1e5bb5f7 PixelPaint: Remove unused methods to access files directly
After transitioning to FileSystemAccessServer, some of the methods
in `MainWidget` and `ProjectLoader` for opening files directly with
a filename as opposed to with a file descriptor are unused. This
commit removes them.
2021-09-12 00:17:04 +02:00
Mustafa Quraish
f337580191 PixelPaint: Use FileSystemAccessServer exclusively, remove unveil
Use the newly added API in FileSystemAccessServer to get read-only
access to a file specified on the commandline. We no longer need to
unveil any image / .pp files on the filesystem :^)
2021-09-12 00:17:04 +02:00
Mustafa Quraish
3141d51164 PixelPaint: Use LibConfig to allow custom pixel grid threshold
Depending on the size / scaling of the UI, someone might want to
change what the threshold is to show the pixel grid. For instance
if you are working on a 50x50 image, and want to see the grid while
still fitting the whole image in the editor.

Since there's no UI for settings in PixelPaint right now, this
commit just uses LibConfig to read the following entry:
    ("PixelPaint", "PixelGrid", "Threshold")
which is then used when drawing the grid.
2021-09-12 00:17:04 +02:00
Mustafa Quraish
451cba8b47 PixelPaint: Don't draw pixel grid outside image bounds
Fixes #9971
2021-09-12 00:17:04 +02:00
David Isaksson
a5ff941c86 PixelPaint: Add mouse indicators to the rulers 2021-09-11 19:16:29 +02:00
David Isaksson
e56764bd74 PixelPaint: Add rulers 2021-09-11 19:16:29 +02:00
David Isaksson
9bc8707cda PixelPaint: Draw guide lines and selections above the pixel grid 2021-09-11 19:16:29 +02:00
Mustafa Quraish
79bcb90887 PixelPaint: Add menu action to toggle pixel grid visibility
You can now toggle on/off the visibility of the pixel grid from
the View menu, if you don't want it shown for some reason.
2021-09-11 13:17:31 +02:00
Mustafa Quraish
4af0a99634 PixelPaint: Show a pixel grid when zoomed in enough
The editor now draws a grid showing the pixels if you are zoomed
in enough. Currently the threshold is a scale of 15 (so if one
pixel side on the image takes up > 15 pixels in the editor)
2021-09-11 13:17:31 +02:00
Tobias Christiansen
6f2a016565 PixelPaint: Add "Clear Guides" to remove all Guides
This patch adds a "Clear Guides" option to the "View"-menu.
2021-09-11 00:28:27 +02:00
Mustafa Quraish
d9832f8d0b PixelPaint: Add Fit Image To View action
This is a feature I missed from Photoshop: it sets the scale and
position so that the image fits (it's longest dimension) into
the editor view. There's a 5% border left around the image to
provide context. This is just arbitrary seemed like the right
amount after some trial and error.
2021-09-09 11:35:50 +02:00
Mustafa Quraish
111ef19114 PixelPaint: Add "Brush Mode" to EraseTool :^)
Previously EraseTool would only let you have hard lines, similar
to PenTool. After inheriting from BrushTool in previous commits,
making the eraser (optionally) behave like a brush is much easier.

We only need to change how the colors are handled for the hardness,
which is why the `draw_point()` call is a bit more involved. Just
blending the colors doesn't work here since we actually want to
replace the previous color, unlike in BrushTool where we are just
layering the color on top.
2021-09-09 11:35:50 +02:00
Mustafa Quraish
ec73247e90 PixelPaint: Make EraseTool inherit from BrushTool
This removes all the code to handle events that was essentially
duplicated from BrushTool anyway :^)

I've also renamed "thickness"->"size" to have consistent
terminology.
2021-09-09 11:35:50 +02:00