mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 10:57:35 +00:00
PixelPaint: Display color information on mousemove with the PickerTool
Per-channel values of the pixel color are now displayed in the status bar when the PickerTool is selected. This information obviously updates on mousemove.
This commit is contained in:
parent
c587ada084
commit
b5594bf9a2
3 changed files with 28 additions and 9 deletions
|
@ -337,29 +337,44 @@ GUI::MouseEvent ImageEditor::event_adjusted_for_layer(GUI::MouseEvent const& eve
|
|||
};
|
||||
}
|
||||
|
||||
void ImageEditor::set_editor_color_to_color_at_mouse_position(GUI::MouseEvent const& event, bool sample_all_layers = false)
|
||||
Optional<Color> ImageEditor::color_from_position(Gfx::IntPoint position, bool sample_all_layers)
|
||||
{
|
||||
auto position = event.position();
|
||||
Color color;
|
||||
auto layer = active_layer();
|
||||
auto* layer = active_layer();
|
||||
if (sample_all_layers) {
|
||||
color = image().color_at(position);
|
||||
} else {
|
||||
if (!layer || !layer->rect().contains(position))
|
||||
return;
|
||||
return {};
|
||||
color = layer->currently_edited_bitmap().get_pixel(position);
|
||||
}
|
||||
return color;
|
||||
}
|
||||
|
||||
set_appended_status_info(DeprecatedString::formatted("R:{}, G:{}, B:{}, A:{} [{}]", color.red(), color.green(), color.blue(), color.alpha(), color.to_deprecated_string()));
|
||||
void ImageEditor::set_status_info_to_color_at_mouse_position(Gfx::IntPoint position, bool sample_all_layers)
|
||||
{
|
||||
auto const color = color_from_position(position, sample_all_layers);
|
||||
if (!color.has_value())
|
||||
return;
|
||||
|
||||
set_appended_status_info(DeprecatedString::formatted("R:{}, G:{}, B:{}, A:{} [{}]", color->red(), color->green(), color->blue(), color->alpha(), color->to_deprecated_string()));
|
||||
}
|
||||
|
||||
void ImageEditor::set_editor_color_to_color_at_mouse_position(GUI::MouseEvent const& event, bool sample_all_layers = false)
|
||||
{
|
||||
auto const color = color_from_position(event.position(), sample_all_layers);
|
||||
|
||||
if (!color.has_value())
|
||||
return;
|
||||
|
||||
// We picked a transparent pixel, do nothing.
|
||||
if (!color.alpha())
|
||||
if (!color->alpha())
|
||||
return;
|
||||
|
||||
if (event.buttons() & GUI::MouseButton::Primary)
|
||||
set_primary_color(color);
|
||||
set_primary_color(*color);
|
||||
if (event.buttons() & GUI::MouseButton::Secondary)
|
||||
set_secondary_color(color);
|
||||
set_secondary_color(*color);
|
||||
}
|
||||
|
||||
void ImageEditor::mousedown_event(GUI::MouseEvent& event)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue