Commit Graph

400 Commits

Author SHA1 Message Date
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
Mustafa Quraish
160bd33874 PixelPaint: Make PenTool inherit from BrushTool
Most of the logic implemented in PenTool was the same as BrushTool
anyway, with the only difference being how the actual lines were
drawn at the end. We now just override the `draw_line()` and
`draw_point()` methods instead.

We don't strictly need to override `draw_line()` here, but that
would just result in repeated calls to `draw_point()`, which is
wasteful.

Also renamed "thickness"->"size" to have consistent terminology.
2021-09-09 11:35:50 +02:00
Mustafa Quraish
fbfa6543ab PixelPaint: Reoriganize drawing in BrushTool to allow more code reuse
The BrushTool is very cool, but it doesn't allow us to re-use any
of the code in other classes. Many of the other tools have duplicated
code for handling mouse events / keeping track of previous location,
etc.

This commit sets up BrushTool so that other tools can inherit from
it and override some virtual functions to allow similar behavior
without re-writing the code to keep track of mouse positions, etc.
In particular, we add public setters/getters for `size` and
`hardness` properties, and make `draw_point()` and `draw_line()`
virtual so that derived classes can override them.

Note: We still pass in `color` as a parameter for `draw_line()` and
`draw_point()` instead of using `color_for()` directly because it
doesn't really make sense to be constantly asking the ImageEditor
for the color when it's not really changing (for instance along all
the points of a line)
2021-09-09 11:35:50 +02:00
Mustafa Quraish
30df74b015 PixelPaint: Allow drawing line between 2 points with BrushTool
Sometimes you want to draw a straight line between 2 points, but
using the nice-looking brush we have instead of the hard line we
would get using the LineTool.

This patch adds the ability to click somewhere with the brush, and
then Shift+click somewhere else to draw a line between the two
points using the brush stroke. Seems like an obvious addition
considering we already have a helper function to draw lines :^)
2021-09-09 11:35:50 +02:00
Mustafa Quraish
3bf204fd03 PixelPaint: Fix BucketTool out of memory crashes
The BFS implementation for BucketTool's flood-fill had sitations
which could result in infinite loop, causing OOM crashes due to
the queue growing unbounded. The way to fix this is to keep track
of the pixels we have already visited in the flood-fill algorithm
and ignore those if we ever encounter them again.

This also fixes the crashing issue from #9003. We still need a
better way to account for transparency, but that is beyond the scope
of this commit, and this issue still exists without any transparent
pixels.
2021-09-09 11:27:48 +02:00
Mustafa Quraish
405b282bc3 PixelPaint: Show mouse position in statusbar without active tool
Showing the position only with an active tool seems a bit confusing,
if you've opened up an image just to find out the coordinates of
a pixel for instance, there shouldn't be a need to have to select
a tool first.
2021-09-07 16:53:40 +02:00
Mustafa Quraish
736ab4f83a PixelPaint: Add Menu action/shortcut to close current image tab
Ctrl+W now closes the current Image tab.
2021-09-07 16:53:40 +02:00
Mustafa Quraish
255f729c1f PixelPaint: Register RectangleTool thickness slider as primary
... So we can use `[` and `]` shortcuts to change the size.
2021-09-07 16:53:40 +02:00
Mustafa Quraish
d6348e1b32 PixelPaint: Use correct thickness in RectangleTool::on_second_paint()
Previously, we were ignoring the scale of the editor in the second
paint step. If you were zoomed in, the size while you were drawing
was not the same as the size of the final shape.
2021-09-07 16:53:40 +02:00
Mustafa Quraish
603d3a5dc6 PixelPaint: Use correct thickness in LineTool::on_second_paint()
Previously, we were ignoring the scale of the editor in the second
paint step. If you were zoomed in, the size while you were drawing
was not the same as the size of the final shape.
2021-09-07 16:53:40 +02:00
Mustafa Quraish
0a9c64a4f5 PixelPaint: Use correct thickness in EllipseTool::on_second_paint()
Previously, we were ignoring the scale of the editor in the second
paint step. If you were zoomed in, the size while you were drawing
was not the same as the size of the final shape.
2021-09-07 16:53:40 +02:00
Mustafa Quraish
285a888b61 PixelPaint: Fix layer dragging bug
A previous commit I made broke layer dragging since the hole_index
was always being computed with respect to the top of the layer list
widget, however we were now drawing layers from the bottom. When
you didn't have enough layers to fill up the full height, dragging
them around would be weird.

This patch computes the hole index correctly using the same offset
we start drawing from, and fixes the behavior.
2021-09-07 00:48:48 +02:00
Mustafa Quraish
905bc79387 PixelPaint: Add Crop to Selection Action
In addition to adding the action, this commit also makes the
`did_change_rect()` method take in an optional rect, which
represents the new rect position. By default it is the same as
`rect()`.

When we are cropping an image, we don't want to move the whole
cropped section to the top-left of the original image in the
ImageEditor widget, so this allows us to keep the cropped image's
position fixed.
2021-09-06 23:43:49 +02:00
Mustafa Quraish
f8570bd773 PixelPaint: Allow opening of files dropped onto application :^)
We can now drag-and-drop files onto PixelPaint to be able to open
them. Each dropped file opens in a separate editor (which is the
default behavior of Photoshop).
2021-09-06 10:36:08 +02:00
Mustafa Quraish
5a8c6b95e6 PixelPaint: Refactor main.cpp into MainWidget
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.

Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.

This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 10:36:08 +02:00
Ali Mohammad Pur
97e97bccab Everywhere: Make ByteBuffer::{create_*,copy}() OOM-safe 2021-09-06 01:53:26 +02:00
Tobias Christiansen
5d732711a2 PixelPaint: Fix broken opening of files from Shell
The fd would get closed when the File went out of scope, so we couldn't
open any file specified by 'pp <path to file>'. We need the fd to be
alive and we solemnly swear to take good care of it and close it
ourselves later.
2021-09-04 16:07:10 +02:00
Mustafa Quraish
92df9d464a PixelPaint: Use Zoom and Eyedropper cursors
Use the newly added cursors for ZoomTool and PickerTool
2021-09-04 03:35:23 +02:00
Musab Kılıç
81326ac8c7 PixelPaint: Add invert filter 2021-09-04 03:35:17 +02:00
Mustafa Quraish
280cbf2e18 PixelPaint: Make tools use the new API for property change shortcuts
Every tool that has a slider now registers the primary/secondary
sliders and now uses the same keyboard shortcuts to modify the
primary and secondary properties. `[` and `]` for the primary,
`{` and `}` for the secondary.
2021-09-04 03:33:44 +02:00
Mustafa Quraish
d28fb8926f PixelPaint: Add mechanism for tools to use keyboard shortcuts
There are quite a few tools that might want to change certain values
based on consistent keyboard shortcuts. This commit allows tools to
hook up a "primary" and "secondary" slider with the base `Tool`
class, which can then handle updating those sliders with the common
shortcuts.

Note that any derived classes that want to override the `on_keydown`
function will manually need to call `Tool::on_keydown()`.
2021-09-04 03:33:44 +02:00
Mustafa Quraish
d645f637f1 PixelPaint: Add separator in image menu
I think it looks a bit nicer having a separator between the
"flip" and "rotate" sections.
2021-09-04 03:30:03 +02:00
Mustafa Quraish
7263e57ce8 PixelPaint: Allow modifiable thickness for RectangleTool :^) 2021-09-04 03:30:03 +02:00
Mustafa Quraish
6910cbc075 PixelPaint: Add Copy Merged action
This allows the user to copy the merged bitmap (all visible layers).
2021-09-04 03:30:03 +02:00
Tobias Christiansen
65d52467f4 PixelPaint: Parse saved Guides from the ProjectLoader in main
This patch allows PixelPaint to recreate saved Guides from .pp files.
2021-09-04 03:29:09 +02:00
Tobias Christiansen
508d563189 PixelPaint: Add ProjectLoader to abstract away opening of files
This new class will open and parse files (either images directly or .pp
project files) and one can get the parsed Image as well as other
information from it.

This patch removes a bunch of 'try_create_from..." methods from Image in
favor of using the ProjectLoader.

The only json_metadata that is available are Guides for now.
2021-09-04 03:29:09 +02:00
Tobias Christiansen
b3f53a0b5a PixelPaint: Save Guides when writing project to file 2021-09-04 03:29:09 +02:00
Tobias Christiansen
e867e4b84b PixelPaint: Move saving a project from Image into ImageEditor
The ImageEditor knows more about the image than Image itself. So to save
a project with all the information known to the program about an image
it's logical that ImageEditor performs that task rather than the Image.

There isn't any additional data added yet, but now there's the
possibility to do so.
2021-09-04 03:29:09 +02:00
Tobias Christiansen
60e526fdd2 PixelPaint: Move serialization of Image into seperate function
This eliminates duplicated code.
2021-09-04 03:29:09 +02:00
Andreas Kling
eaf88cc78a AK: Rename create<T> => make_ref_counted<T>
And also try_create<T> => try_make_ref_counted<T>.

A global "create" was a bit much. The new name matches make<T> better,
which we've used for making single-owner objects since forever.
2021-09-03 02:36:09 +02:00
Mustafa Quraish
ca6c9be94c PixelPaint: Add actions to rotate image left/right
This also required adding a new hook to `ImageClient`, since there
wasn't a way of telling the ImageEditor that the full rect of the
image has changed (as when we rotate).
2021-09-03 01:50:11 +02:00
Mustafa Quraish
6a8c408856 PixelPaint: Add actions to flip image vertically/horizontally 2021-09-03 01:50:11 +02:00
Mustafa Quraish
0c56f06994 PixelPaint: Draw layers from bottom of panel, adjust spacing
If we don't have enough layers to be able to scroll, the layers
are pushed to be at the top of the layer list. This doesn't make
much sense now that we are correctly drawing the layers in the
right order, so now we draw them justified towards the bottom.

Previously we were also clipping the bottom gadget slightly when
there were enough layers to scroll. Now, I'm adding some offset to
the total height to account for this and give equivalent spacing
from the top and bottom layers.
2021-09-03 01:49:32 +02:00
Mustafa Quraish
339f0d5bca PixelPaint: Add Merge Active Layer Down action
This allows you to merge the active layer with the one below it.
2021-09-03 01:49:32 +02:00
Mustafa Quraish
97cc34c034 PixelPaint: Fix the displayed order of layers in LayerListWidget
Previously the background layer was shown at the top, and layers
in front of it were shown below it. This was really unintuitive.

This patch fixes LayerListWidget to now properly differentiate
between the index of a gadget, and the index of a layer, since they
are essentially mirrored. I chose not to modify the order in which
layers are stored since back-to-front makes it really convenient
there.
2021-09-03 01:49:32 +02:00
Mustafa Quraish
dd5ceb74e9 PixelPaint: Ctrl+click on palette colors now sets primary/secondary
Previously it would only change the color of the ColorWidget itself,
but not make it the primary/secondary color. I think it feels nicer
this way, if I'm adding a color to the palette I likely want to use
it.

If you *really* need to only change the color of the palette, you
can just Ctrl+Middle click.
2021-09-02 09:09:12 +02:00
Mustafa Quraish
8d8ec6365b PixelPaint: Allow changing colors temporarily without palette
Previously, if you wanted to use a custom color, the only way to
do so was to first Ctrl+click on one of the pallette colors, which
would just change that palette item. Then, you would need to
manually click on that color.

Now, you can just click on the preview of the primary/secondary
color to open up the picker and only temporarily use the new color
without affecting the palette at all.
2021-09-02 09:09:12 +02:00
sin-ack
8ea22121ac Userland: Migrate to argument-less deferred_invoke
Only one place used this argument and it was to hold on to a strong ref
for the object. Since we already do that now, there's no need to keep
this argument around since this can be easily captured.

This commit contains no changes.
2021-09-02 03:47:47 +04:30
Tobias Christiansen
8a7ce4eea3 PixelPaint: Add "Change Offset" to the GuideTool
This opens the EditGuideDialog with the values of the currently
selected Guide and allows the user to change them to the desired values.
:^)
2021-09-01 13:46:44 +02:00
Tobias Christiansen
e9595dcb79 PixelPaint: Add setter for the orientation of a Guide
Also add an additional value to the Orientation enum called "Unset".
2021-09-01 13:46:44 +02:00
Tobias Christiansen
c9e6afe6a8 PixelPaint: Allow initial values for the EditGuideDialog
This way we can feed it the values if we wanted to change an existing
Guide and handle the default as before.
That we have to pass a String here is a bit ugly.
2021-09-01 13:46:44 +02:00
Tobias Christiansen
7e2028a3cd PixelPaint: Move the conversion to pixels into the EditGuideDialog
This seems like the most appropriate location to put this.
2021-09-01 13:46:44 +02:00
Tobias Christiansen
abcb982485 PixelPaint: Rename CreateNewGuideDialog to EditGuideDialog
This doesn't change the behavior at all but sets the naming up be more
descriptive on what it does in the next patches.
2021-09-01 13:46:44 +02:00
Marcus Nilsson
1d253880e6 PixelPaint: Tweak palette height
The height of the bottom color container was cut off at the bottom.
This adjusts the heights and also the primary/secondary color
widget so that it's in line.
2021-09-01 13:43:55 +02:00
savary1
dd912bd351 PixelPaint: Add grayscale filter
Add a new Color category to the Filter menu. Add the Grayscale
filter under Filter->Color to turn the selected layer to grey colors.
Created GrayscaleFilter.h. Modify Filter.h to allow filters
without parameters.
2021-08-31 17:02:27 +02:00
Mustafa Quraish
c853bc2ba6 PixelPaint: Rename Mode to FillMode for Ellipse/Rectangle
The prior commits add the `DrawMode` enum to keep track of where
the shape is being drawn from. With this addition, the prior `Mode`
enum name is confusing, so this commit renames it to `FillMode` to
be more explicit :^)
2021-08-31 16:45:57 +02:00
Mustafa Quraish
6ccdc018b4 PixelPaint: Add ability to draw rectangle from center
Essentially the same logic as the prior commit, but now for the
`RectangleTool` class. Pressing `alt` lets you draw the rectangle
with the starting position as the center.
2021-08-31 16:45:57 +02:00
Mustafa Quraish
1a3481f35b PixelPaint: Add ability to draw ellipse from center
Like other common image editing applications, now if you press
`alt` while drawing an ellipse, it uses the starting position as
the center of the ellipse as opposed to one of the corners of the
bounding rect.

The EllipseTool class now keeps track of a `DrawMode`, which is
either `DrawMode::FromCorner` (default), or `DrawMode::FromCenter`
(the option added by this commit).

The `draw_using()` function was modified to now take in the start
and end positions and construct the `ellipse_intersecting_rect`
itself, since we need to construct it differently based on the
drawing mode.
2021-08-31 16:45:57 +02:00
Andreas Kling
087bd7f767 Userland: Use Rect::centered_within() where useful 2021-08-31 01:35:08 +02:00
Mustafa Quraish
5a8ac56fb9 PixelPaint: Always change cursor when active tool is set
Previously, if you used one of the keyboard shortcuts to select a
different tool, it didn't change the cursor to the corresponding
one till you clicked somewhere / did something else to trigger an
update. This was pretty jarring since there's no indication as to
whether the tool change was successful or not.

This patch just calls `set_override_cursor()` when a valid active
tool is set to immediately update it.
2021-08-28 08:10:44 +01:00
Mustafa Quraish
75a706b6eb Everywhere: Use the Optional<T>::operator==(T) operator
In general, I think `opt == x` looks much nicer than
`opt.has_value() && opt.value() == x`, so I'm updating
the remaining few instances I could find with some regex
magic in my search.
2021-08-27 23:13:51 +02:00
Maciej Zygmanowski
3ad9df1522 PixelPaint: Make Layer passed to tools a pointer
Some tools (e.g. ZoomTool) doesn't need layer to work. This commit
makes mouse events fire even if there is no layer. This fixes
a bug that ZoomTool didn't work when there is no layers.
2021-08-27 12:45:06 +02:00
Maciej Zygmanowski
0224dc2882 PixelPaint: Pass raw mouse event to Tools and wrap them all in a struct
This commit adds a Tool::MouseEvent struct, which contains events that
may be needed by tools: layer-relative, image-relative and raw (editor-
relative) event.

The raw event is used by ZoomTool to properly pan the view. This fixes
a bug which caused image to snap out of sight.
2021-08-27 12:45:06 +02:00
Maciej Zygmanowski
635130ef76 PixelPaint: Make scaling exponential
This matches behaviour of other image editors, e.g GIMP.
The default ZoomTool sensitivity was increased for better zooming
experience :^)
2021-08-27 12:45:06 +02:00
Andreas Kling
13f4890c38 LibCore: Make Core::File::open() return OSError in case of failure 2021-08-20 15:31:46 +02:00
sin-ack
e11d177618 Userland+LibGUI: Add shorthand versions of the Margins constructor
This allows for typing [8] instead of [8, 8, 8, 8] to specify the same
margin on all edges, for example. The constructors follow CSS' style of
specifying margins. The added constructors are:

- Margins(int all): Sets the same margin on all edges.
- Margins(int vertical, int horizontal): Sets the first argument to top
  and bottom margins, and the second argument to left and right margins.
- Margins(int top, int vertical, int bottom): Sets the first argument to
  the top margin, the second argument to the left and right margins,
  and the third argument to the bottom margin.
2021-08-18 10:30:50 +02:00
sin-ack
9c9a5c55cb Userland+LibGUI: Make Margins arguments match CSS ordering
Previously the argument order for Margins was (left, top, right,
bottom). To make it more familiar and closer to how CSS does it, the
argument order is now (top, right, bottom, left).
2021-08-18 10:30:50 +02:00
Marcus Nilsson
f080691424 PixelPaint: Disable context menu for GuideTool when no guide is found
Previously the context menu would popup even when closest_guide()
returned nullptr, making the Delete action do nothing.
2021-08-14 12:45:48 +02:00
Marcus Nilsson
1ad08ab7d6 PixelPaint: Show Guides on GuideTool activation
This adds on_tool_activation() to Tool which GuideTool can use
to show guides, if they're hidden, when it's activated. Also
show guides on mousedown since there's no use in drawing invisible
guides.
2021-08-14 12:45:48 +02:00
Marcus Nilsson
3b3df40eb9 PixelPaint: Revert update rect tightening for Selection
Tightening of the update rect when firing the marching ants timer
unfortunately meant that only finalized selections would be redrawn,
and any new selection drawn outside of the update rect would not
update.
2021-08-14 12:45:48 +02:00
Tobias Christiansen
2a77abf85e Everywhere: Use tobyase@serenityos.org for my copyright headers 2021-08-09 21:43:05 +02:00
Marcus Nilsson
b1b6a6d6e8 PixelPaint: Let Tools have different cursors
This adds support for the Tools in PixelPaint to use different cursors
within ImageEditor. For now most of them get the crosshair cursor since
it's the most fitting, but in the future we will want to add custom
cursors.
2021-08-09 00:57:44 +02:00
Marcus Nilsson
854e16797e PixelPaint: Tighten update rects for Tools
This tightens the update rects for EraseTool, BrushTool And the marching
ants update in Selection. Inflate Selection update rect by 10x10 to
avoid misalignment when zoomed out.
2021-08-08 13:55:39 +02:00
Marcus Nilsson
8c81d195c7 PixelPaint: Inflate update rect for PenTool
Previously using PenTool while zoomed in could cause rendering glitches
since the update rect was misaligned with the image, most likely because
of rounding errors.
Loosening the rect with 1 pixel on either side takes care of this.
2021-08-08 13:55:39 +02:00
Tobias Christiansen
4f5c69a04c PixelPaint: Add snapping to the GuideTool
When holding Shift, the Guide snaps to a multiple of the specified
number from the properties widget.
2021-08-08 00:30:41 +02:00
Tobias Christiansen
58cb668257 PixelPaint: Add tooltip to GuideTool to show current offset
The offset of the currently edited Guide is shown in a tooltip when
using the GuideTool.
2021-08-08 00:30:41 +02:00
Timothy
1927dbf025 PixelPaint: Use unveil to hide file system 2021-08-07 12:48:22 +02:00
Tobias Christiansen
0ca085910e PixelPaint: Make Guides' visibility optional
Whether Guides are drawn or not is now controlled via the menu-entry
View->Show Guides.
2021-08-07 02:52:47 +04:30
Tobias Christiansen
193f1e01cf PixelPaint: Add the GuideTool to the Toolbox
This also adds a custom icon for the GuideTool.
2021-08-07 02:52:47 +04:30
Tobias Christiansen
7923929a4d PixelPaint: Add GuideTool for editing Guides
This patch adds the logic for the GuideTool. Pulling in from outside the
image creates a new Guide, moving a Guide outside of the image deletes
it and a Guide can be deleteted via the context menu.
A Guide is considered clicked when the cursor is less than 20 pixels
away from the line.
2021-08-07 02:52:47 +04:30
Tobias Christiansen
d4cf4b74c1 PixelPaint: Allow creation of Guides via the View-Menu
You can specify the offset in percent, and it's getting parsed and
calculated appropriately.
2021-08-07 02:52:47 +04:30
Tobias Christiansen
515bbd0b83 PixelPaint: Add a Dialog for the creation of a Guide
You can select whether you want a horizontal or a vertical Guide and
specify the offset you want it to be at.
2021-08-07 02:52:47 +04:30
Tobias Christiansen
a717caa4b7 PixelPaint: Include Guides in the ImageEditor
The ImageEditor knows about its Guides, how to draw them and exposes
ways to manipulate them.
2021-08-07 02:52:47 +04:30
Tobias Christiansen
7e01d06226 PixelPaint: Add Guide class
This will allow the user to add Guides to the image, that will only be
visible in the Editor, not affecting the image.
2021-08-07 02:52:47 +04:30
Marcus Nilsson
4a57a4a0b3 PixelPaint: Use a StackWidget in ToolPropertiesWidget
Previously changing tools while simultaneously using a widget like a
slider would result in a event_dispatch() failure.
Instead use a StackWidget to set the active widget.
2021-08-06 23:59:14 +02:00
Marcus Nilsson
868be680c2 PixelPaint: Use the ValueSlider widget for Tool properties
Use the new ValueSlider and get rid of the temporary solution with
tooltips :^)
2021-08-06 23:35:48 +02:00
Marcus Nilsson
b6200a3ed8 PixelPaint: Add tooltips for sliders in ToolPropertiesWidget
This adds a tooltip to all the slider properties showing their
current value. Previously there was no indication of what
value they had. Also rename the SprayTool property 'thickness' to
'size' like BrushTool calls it.
2021-08-03 18:53:54 +02:00
Marcus Nilsson
0c4977161f PixelPaint: Move properties for LineTool to ToolPropertiesWidget
Remove the context menu for LineTool and use the tool properties
widget for options instead.
2021-08-03 09:04:57 +02:00
Marcus Nilsson
201b901cb1 PixelPaint: Move properties for RectangleTool to ToolPropertiesWidget
Remove the context menu and move the options to the tool properties
widget.
2021-08-03 09:04:57 +02:00
Marcus Nilsson
3392c66c94 PixelPaint: Remove context menu for MoveTool
Remove the context menu for MoveTool and move the actions to the layer
menu instead.
2021-08-03 09:04:57 +02:00
Marcus Nilsson
15e9d0b4d8 PixelPaint: Remove context menu for SprayTool
Remove the context menu for SprayTool and just use the tool properties
widget for options.
2021-08-03 09:04:57 +02:00
Marcus Nilsson
b257d8d284 PixelPaint: Move properties for EllipseTool to ToolPropertiesWidget
Remove the context menu for EllipseTool and use the properties widget
instead for consistency between tools.
2021-08-03 09:04:57 +02:00
Marcus Nilsson
cb6e63e579 PixelPaint: Remove context menu for PenTool
Remove the context menu for PenTool and just use the tool properties
widget.
2021-08-03 09:04:57 +02:00
Marcus Nilsson
e342bef854 PixelPaint: Move properties for EraserTool to ToolPropertiesWidget
Removes the context menu for EraserTool and instead use the
tool properties widget for options.
2021-08-03 09:04:57 +02:00
Clément Sibille
fb099ad38b PixelPaint: Show image coordinates in the status bar 2021-08-02 00:49:24 +02:00
Brian Gianforcaro
a51e6547aa Applications: Remove unused header includes 2021-08-01 08:10:16 +02:00
Andreas Kling
687a12d7fb Userland: Add GUI::Window::add_menu() and use it everywhere
Applications previously had to create a GUI::Menubar object, add menus
to it, and then call GUI::Window::set_menubar().

This patch introduces GUI::Window::add_menu() which creates the menubar
automatically and adds items to it. Application code becomes slightly
simpler as a result. :^)
2021-07-21 21:24:26 +02:00
Andreas Kling
c7d891765c LibGfx: Use "try_" prefix for static factory functions
Also mark them as [[nodiscard]].
2021-07-21 18:02:15 +02:00
Hendiadyoin1
ed46d52252 Everywhere: Use AK/Math.h if applicable
AK's version should see better inlining behaviors, than the LibM one.
We avoid mixed usage for now though.

Also clean up some stale math includes and improper floatingpoint usage.
2021-07-19 16:34:21 +04:30
Gavin Downard
bd4e88ae3d PixelPaint: Fix crash when copying empty selection
Previously, trying to copy when there is no selection would crash,
trying to call mmap with a size of 0. Now it just leaves the clipboard
as it is.
2021-07-15 13:25:39 +02:00
Marcus Nilsson
e718de454e PixelPaint: Check modifier on mousemove in LineTool
Previously m_constrain_angle could end up not being reset if the
keyup-event was lost, for example when opening a dialog. Instead check
the modifiers in on_mousemove().
2021-07-10 21:23:36 +02:00
Andreas Kling
fd898be51a PixelPaint: Only update the layer thumbnail on layer bitmap changes
When a layer bitmap is modified, we don't have to repaint the whole
layer gadget in the layer list, only the little thumbnail. :^)
2021-07-09 22:07:00 +02:00
Andreas Kling
285f0383d4 PixelPaint: Move LayerListWidget gadget rect computation to a function
This will allow functions other than paint_event() to use the various
gadget rects (thumbnail, text, etc.)
2021-07-09 22:07:00 +02:00
Andreas Kling
1cec672e69 PixelPaint: Remove unused member from LayerListWidget::Gadget 2021-07-09 22:07:00 +02:00
Andreas Kling
0ef3cf7b0f PixelPaint: Call correct base class in LayerListWidget::resize_event() 2021-07-09 22:07:00 +02:00
Andreas Kling
bce1d633ca PixelPaint: Make PenTool invalidate even less when drawing :^) 2021-07-09 22:07:00 +02:00
Marcus Nilsson
c59c970363 PixelPaint: Don't deselect layers in LayerListWidget
There is really no reason to be able to deselect layers, so just ignore
when the user clicks outside of a layer gadget.
2021-07-09 18:04:01 +02:00
Marcus Nilsson
95710b0147 PixelPaint: Make sure that a layer is always selected
Make sure that a layer is selected after creating it, removing
one or creating a new image. Also make layer_properties_widget
update on tab change.
2021-07-09 18:04:01 +02:00
Marcus Nilsson
f3cdb9bfeb PixelPaint: Only scroll into view in LayerListWidget when needed
This makes sure that scroll_into_view is not called when not necessary,
or when m_layers is empty, which previously caused a crash upon
removing the last layer.
2021-07-09 18:04:01 +02:00
Marcus Nilsson
791a018c99 PixelPaint: Add method to merge visible layers
This adds a function that merges all visible layers to one, ignoring the
invisible.
2021-07-08 20:16:26 +02:00
Marcus Nilsson
0900e31fe0 PixelPaint: Scroll into view when reordering layers
Make LayerListWidget scroll into view when reordering layers.
2021-07-08 20:16:26 +02:00
Marcus Nilsson
618bb2d33e PixelPaint: Make brush draw on mousedown
This makes the brush tool start drawing a point before the user moves
the mouse, like in Photoshop and Gimp. The number of iterations of
draw_point makes for roughly 4 clicks to full opacity.
2021-07-08 20:16:26 +02:00
Marcus Nilsson
9be08e33ea PixelPaint: Add method to flatten image layers
This adds Image::flatten_all_layers() that allows the user to flatten
all the visible layers into one.
2021-07-08 20:16:26 +02:00
Andreas Kling
8975caca45 PixelPaint: Make SprayTool only invalidate the modified area :^) 2021-07-07 13:01:20 +02:00
Andreas Kling
e28b22c316 PixelPaint: Make BrushTool only invalidate the modified area :^) 2021-07-07 13:01:20 +02:00
Andreas Kling
7cbcf5a5fa PixelPaint: Make PenTool only invalidate the modified area :^) 2021-07-07 13:01:20 +02:00
Andreas Kling
f7053059c9 PixelPaint: Allow partial invalidation of Layer and Image
Let's give ourselves the tools needed to update less than the entire
image every time we paint.

This patch adds plumbing so that Layer invalidations have a modified
rect that gets passed on to Image, and then on to ImageEditor.
2021-07-07 13:01:20 +02:00
Andreas Kling
73183ee5c4 PixelPaint: Paint the area around the image with ColorRole::Tray
It didn't really make sense for the transparency grid to extend
infinitely around the image. Now the grid is only visible underneath
the image, which matches how most other editors behave.
2021-07-06 12:24:51 +02:00
Andreas Kling
b650bb602a PixelPaint: Don't repaint area outside image when image itself changed 2021-07-06 12:24:51 +02:00
Marcus Nilsson
e1906d74b8 PixelPaint: Make move_selection() cycle through layers
Previously move_selection() did not work as expected. Instead store the
selected layer index in a member variable and continue to cycle through
the layers when you come to the start/end. Also use it to scroll into
view. Lastly rename the function to cycle_through_selection() to make it
clearer what it does.
2021-07-05 20:39:30 +02:00
Marcus Nilsson
8d205ae62e PixelPaint: Use layer menu as context menu in LayerListWidget
This enables the layer menu as a context menu in LayerListWidget,
setting the clicked layer as active for now, but in the future it
would be nice to have custom menu applying to the clicked layer instead
of the active layer.
2021-07-05 20:39:30 +02:00
Marcus Nilsson
9df3550e58 PixelPaint: Change color of disabled layers in LayerListWidget 2021-07-05 20:39:30 +02:00
Marcus Nilsson
36abb38f26 PixelPaint: Make LayerListWidget scrollable
Previously only a couple of layers would fit in the layer widget, this
makes it scrollable and also tweaks some sizes and coordinates.
2021-07-05 20:39:30 +02:00
Marcus Nilsson
13e526de43 PixelPaint: Change the default layer name to "Layer"
Change the default layer name to "Layer" and enable the user to press
return to quickly close the dialog.
2021-07-05 20:39:30 +02:00
Marcus Nilsson
2183d01eb0 PixelPaint: Ask to preserve transparency when exporting
Previously the alpha channel was thrown away when exporting to BMP or
PNG in PixelPaint, instead let the user decide.
2021-07-05 00:43:00 +02:00
Marcus Nilsson
05e8bea736 PixelPaint: Reset layer widgets when closing last tab
When closing the last tab the layer list widget and layer properties
widget did not reset since they still had a pointer to the image.
2021-07-02 17:54:01 +02:00
Marcus Nilsson
54d4df668a PixelPaint: Add layer to image before setting properties
Previously when opening an image with layers that had properties like
visibility set, PixelPaint would crash when trying to trigger
layer_did_modify_properties() without in image. Avoid this by
adding the layer to the image before setting the properties.
2021-07-02 17:54:01 +02:00
Max Wipfli
fc6d051dfd AK+Everywhere: Add and use static APIs for LexicalPath
The LexicalPath instance methods dirname(), basename(), title() and
extension() will be changed to return StringView const& in a further
commit. Due to this, users creating temporary LexicalPath objects just
to call one of those getters will recieve a StringView const& pointing
to a possible freed buffer.

To avoid this, static methods for those APIs have been added, which will
return a String by value to avoid those problems. All cases where
temporary LexicalPath objects have been used as described above haven
been changed to use the static APIs.
2021-06-30 11:13:54 +02:00
Andreas Kling
ee3a73ddbb AK: Rename downcast<T> => verify_cast<T>
This makes it much clearer what this cast actually does: it will
VERIFY that the thing we're casting is a T (using is<T>()).
2021-06-24 19:57:01 +02:00
Davipb
20b2c46019 PixelPaint: Allow copying arbitrary selections
This replaces the naive copy algorithm that only supported rectangular
and 100% opaque selections with a more general approach that supports
any shape and alpha value.

Note that we now make a brand new bitmap with a hardcoded format instead
of just cropping the layer's existing bitmap. This is done to ensure
that the final clipboard image will have an alpha channel.
2021-06-22 11:00:00 +02:00
Davipb
e58f78e667 PixelPaint: Add more options to RectangleSelectTool
A "feather" value sets by how much the borders of the selection will be
smoothed, and a "mode" value sets how the newly selected region will
interact with an existing image selection (if any).
2021-06-22 11:00:00 +02:00
Davipb
22585e2845 PixelPaint: Expose more complex selection operations
Now that we use RectMask internally to store the selection, we can
expose more powerful APIs to allow for better control over the image
selection.
2021-06-22 11:00:00 +02:00
Davipb
d922e35579 PixelPaint: Use Mask internally in Selection
While the external API has not changed, this will allow us to have
non-rectangular selections in the future.
2021-06-22 11:00:00 +02:00
Davipb
0828c75e57 PixelPaint: Add a Mask class
The Mask class represents an opacity mask over a rectangular section
of an image, linking every pixel to an alpha value ranging from 0 (not
selected) to 255 (fully selected). "Partially selected" pixels can be
used to simulate anti-aliased curves.

This class will be used as the basis for the new non-rectangular
selection feature.
2021-06-22 11:00:00 +02:00
Felix Rauch
8d91dbf6c0 PixelPaint: Add loading and saving of color palettes
Color palettes can now be stored in and read from files. The default
palette will be read from `/res/color-palettes/default.palette`
instead of being hard-coded in PaletteWidget.

The file format is one color per line, in any format that can be
understood by `Gfx::Color::from_string`.
2021-06-21 22:32:58 +02:00
Marcus Nilsson
f2aa5efbeb PixelPaint: Add basic support for closing tabs
This enables closing of tabs in PixelPaint, for the moment
very basic with no checking if the image is modified or saved.
2021-06-20 15:16:26 +02:00
Elliot Maisl
90873781c1 PixelPaint: Add new selection moving modes
If you press "spacebar" while moving a selection, it will now move the
origin point of the selection; and if you press "control" it will move
it relatively to the center.
2021-06-17 23:02:53 +02:00
Erik Sommer
96588adbd4
PixelPaint: Update debug message in the copy action to the used method (#8113) 2021-06-17 19:53:45 +02:00
Gunnar Beutner
631d36fd98 Everywhere: Add component declarations
This adds component declarations so that users can select to not build
certain parts of the OS.
2021-06-17 11:03:51 +02:00
Aatos Majava
a49a15cabf PixelPaint: Set the image title when creating a new image 2021-06-16 21:27:05 +02:00
Andreas Kling
0c8dce60a2 PixelPaint: Don't open new images in background tabs
When opening/creating a new image, let's make it the foreground tab.
2021-06-16 12:12:39 +02:00
Andreas Kling
abc40af809 PixelPaint: Make images keep track of their path & title
The title is either "Untitled" (default), or the basename of the
image after we've opened or saved it.
2021-06-16 12:12:39 +02:00
Andreas Kling
35456f035c PixelPaint: Make ImageEditor::image() return a reference (Image&)
In the new tabbed world, every ImageEditor always has an associated
Image, so this simplifies a bunch of things. :^)
2021-06-16 12:12:39 +02:00
Andreas Kling
c6dd3377ee PixelPaint: Make the main UI tabbed and allow multiple open images :^)
This patch adds a GUI::TabWidget to the main UI and allows having
multiple images open at the same time.

Some of the changes here are a bit hackish and mechanical and there's
still code around that needs more work to fit better in the new world.

One nice side-effect of this change is that ImageEditor now always
has one Image associated with it, and it never changes.
2021-06-16 12:12:39 +02:00
Andreas Kling
8763492e34 PixelPaint: Make main window a little bit taller by default 2021-06-16 12:12:39 +02:00
Mateusz Górzyński
4aff4249aa PixelPaint: Alternate selection outline between black and white 2021-06-15 16:15:09 +02:00
Andreas Kling
2052796947 PixelPaint: Clear selection when opening a new image 2021-06-15 13:38:43 +02:00
Andreas Kling
91100f2f94 PixelPaint: Display an error message if exporting to PNG/BMP fails 2021-06-15 13:38:43 +02:00
Andreas Kling
3e4b48f68e PixelPaint: Avoid unnecessary temporary layer bitmaps during PP load
When opening a PP file, we were creating a layer first with an empty
bitmap, and then replacing it with the loaded bitmap from the file.

This patch reorders things so we never create the empty bitmap in
between, saving time and avoiding a memory spike.
2021-06-15 10:05:50 +02:00
Andreas Kling
398bf045c6 PixelPaint: Increase default size of new images from 1x1 to 480x360 2021-06-15 10:05:16 +02:00
Andreas Kling
eb76b18ee3 PixelPaint: Don't allow creating empty layers or images 2021-06-15 10:05:16 +02:00
Andreas Kling
8731bc9ead PixelPaint: Display an error message if opening a file fails 2021-06-15 10:05:16 +02:00
Andreas Kling
c333aec9f3 PixelPaint: Display an error message if saving to PP file fails 2021-06-15 01:16:34 +02:00
Andreas Kling
fa7bb98b1e PixelPaint: No need to pass ImageEditor& to Selection::paint()
It already has a reference to the editor in m_editor.
2021-06-15 01:16:34 +02:00
LepkoQQ
e6f27cec39 PixelPaint: Add actions to swap colors or reset them to default values 2021-06-15 00:13:03 +02:00
LepkoQQ
db99e0917c PixelPaint: Add menu items for Select All and Clear Selection
We also need to update the image editor when clearing selection
otherwise the last state of the selection will be displayed until an
update happens.
2021-06-15 00:13:03 +02:00
Andreas Kling
068ca3a394 PixelPaint: Always animate marching ants during interactive selection
The Selection object now tracks whether there is an ongoing interactive
selection (originating from one of the selection tools). If so it makes
sure to pump the marching ants animation.
2021-06-14 18:25:17 +02:00
Andreas Kling
f54164e8ae PixelPaint: Make new pasted layer active immediately
Also clear any selection that existed before pasting. This feels a bit
more intuitive. We may also want to consider switching to the "Move"
tool automatically on paste, but I'm less sure about that.
2021-06-14 18:25:17 +02:00
Andreas Kling
765286f691 PixelPaint: Add copy action (copies the selection from active layer)
You can now select a part of a layer, copy it, and then paste it as
a new layer. Very cool :^)
2021-06-14 18:25:17 +02:00
Andreas Kling
4cecd79000 PixelPaint: Draw the current editor selection as marching ants
This patch moves the marching ants painting code to Selection and
unifies the timer mechanism so that all marching ants are synchronized
which looks neat. :^)
2021-06-14 18:25:17 +02:00
Andreas Kling
1b897ec561 PixelPaint: Add a Selection class (ImageEditor has a Selection)
This will represent a complex, region-based selection in the future.
For now though, it's just a simple rectangle. :^)
2021-06-14 18:25:17 +02:00
Andreas Kling
96b52f13e4 PixelPaint: Implement basic rectangular selection (preview only)
Using the rectangle select tool, you can now drag out a selection which
will be drawn in the form of "marching ants" :^)
2021-06-14 18:25:17 +02:00
Andreas Kling
4bd905de0e PixelPaint: Add a new "Rectangle Select" tool :^)
This patch only adds the tool along with a toolbar icon for it.
It doesn't do anything yet.
2021-06-14 18:25:17 +02:00
Andreas Kling
68a307be4e PixelPaint: Use ImageDecoder to load images out-of-process
This sandboxes the image decoding work done by PixelPaint to prevent
bugs in the decoding framework from compromising PixelPaint itself. :^)
2021-06-12 11:19:29 +02:00
Andreas Kling
92203c9821 PixelPaint: Don't allow Image::try_create_from_bitmap(nullptr)
This is not a valid use-case so let's prevent it at compile time.
2021-06-12 11:19:29 +02:00
Andreas Kling
9038bc675f PixelPaint: Guarantee that constructed Layer always has a Gfx::Bitmap
Hoist any allocation failures so that layer factories never return a
bitmap-less layer.
2021-06-12 11:19:29 +02:00
Andreas Kling
c7f7c1f7f0 PixelPaint: Use move semantics around Layer construction and accessors 2021-06-12 11:19:29 +02:00
Andreas Kling
9c5de113b1 PixelPaint: Rename Layer::create_foo() => Layer::try_create_foo() 2021-06-11 23:06:46 +02:00