mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-01-07 19:57:45 +03:00
PixelPaint: Add mouse indicators to the rulers
This commit is contained in:
parent
242acfcbae
commit
a5ff941c86
Notes:
sideshowbarker
2024-07-18 04:15:20 +09:00
Author: https://github.com/Granddave Commit: https://github.com/SerenityOS/serenity/commit/a5ff941c86d Pull-request: https://github.com/SerenityOS/serenity/pull/9835 Issue: https://github.com/SerenityOS/serenity/issues/9827 Reviewed-by: https://github.com/TobyAsE Reviewed-by: https://github.com/mustafaquraish ✅
@ -2,6 +2,7 @@
|
||||
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
|
||||
* Copyright (c) 2021, Tobias Christiansen <tobyase@serenityos.org>
|
||||
* Copyright (c) 2021, Mustafa Quraish <mustafa@cs.toronto.edu>
|
||||
* Copyright (c) 2021, David Isaksson <davidisaksson93@gmail.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
@ -122,6 +123,7 @@ void ImageEditor::paint_event(GUI::PaintEvent& event)
|
||||
const auto ruler_bg_color = palette().color(Gfx::ColorRole::InactiveSelection);
|
||||
const auto ruler_fg_color = palette().color(Gfx::ColorRole::Ruler);
|
||||
const auto ruler_text_color = palette().color(Gfx::ColorRole::InactiveSelectionText);
|
||||
const auto mouse_indicator_color = Color::White;
|
||||
|
||||
// Ruler background
|
||||
painter.fill_rect({ { 0, 0 }, { m_ruler_thickness, rect().height() } }, ruler_bg_color);
|
||||
@ -165,6 +167,12 @@ void ImageEditor::paint_event(GUI::PaintEvent& event)
|
||||
painter.draw_text({ { 0, editor_y - m_ruler_thickness }, { m_ruler_thickness, m_ruler_thickness } }, String::formatted("{}", y), painter.font(), Gfx::TextAlignment::BottomRight, ruler_text_color);
|
||||
}
|
||||
|
||||
// Mouse position indicator
|
||||
const Gfx::IntPoint indicator_x({ m_mouse_position.x(), m_ruler_thickness });
|
||||
const Gfx::IntPoint indicator_y({ m_ruler_thickness, m_mouse_position.y() });
|
||||
painter.draw_triangle(indicator_x, indicator_x + Gfx::IntPoint(-m_mouse_indicator_triangle_size, -m_mouse_indicator_triangle_size), indicator_x + Gfx::IntPoint(m_mouse_indicator_triangle_size, -m_mouse_indicator_triangle_size), mouse_indicator_color);
|
||||
painter.draw_triangle(indicator_y, indicator_y + Gfx::IntPoint(-m_mouse_indicator_triangle_size, -m_mouse_indicator_triangle_size), indicator_y + Gfx::IntPoint(-m_mouse_indicator_triangle_size, m_mouse_indicator_triangle_size), mouse_indicator_color);
|
||||
|
||||
// Top left square
|
||||
painter.fill_rect({ { 0, 0 }, { m_ruler_thickness, m_ruler_thickness } }, ruler_bg_color);
|
||||
}
|
||||
@ -185,6 +193,20 @@ int ImageEditor::calculate_ruler_step_size() const
|
||||
return 1 * pow(10, max_factor);
|
||||
}
|
||||
|
||||
Gfx::IntRect ImageEditor::mouse_indicator_rect_x() const
|
||||
{
|
||||
const Gfx::IntPoint top_left({ m_ruler_thickness, m_ruler_thickness - m_mouse_indicator_triangle_size });
|
||||
const Gfx::IntSize size({ width() + 1, m_mouse_indicator_triangle_size + 1 });
|
||||
return Gfx::IntRect(top_left, size);
|
||||
}
|
||||
|
||||
Gfx::IntRect ImageEditor::mouse_indicator_rect_y() const
|
||||
{
|
||||
const Gfx::IntPoint top_left({ m_ruler_thickness - m_mouse_indicator_triangle_size, m_ruler_thickness });
|
||||
const Gfx::IntSize size({ m_mouse_indicator_triangle_size + 1, height() + 1 });
|
||||
return Gfx::IntRect(top_left, size);
|
||||
}
|
||||
|
||||
Gfx::FloatRect ImageEditor::layer_rect_to_editor_rect(Layer const& layer, Gfx::IntRect const& layer_rect) const
|
||||
{
|
||||
return image_rect_to_editor_rect(layer_rect.translated(layer.location()));
|
||||
@ -288,6 +310,12 @@ void ImageEditor::mousedown_event(GUI::MouseEvent& event)
|
||||
|
||||
void ImageEditor::mousemove_event(GUI::MouseEvent& event)
|
||||
{
|
||||
m_mouse_position = event.position();
|
||||
if (m_show_rulers) {
|
||||
update(mouse_indicator_rect_x());
|
||||
update(mouse_indicator_rect_y());
|
||||
}
|
||||
|
||||
if (event.buttons() & GUI::MouseButton::Middle) {
|
||||
auto delta = event.position() - m_click_position;
|
||||
m_pan_origin = m_saved_pan_origin.translated(
|
||||
|
@ -130,6 +130,8 @@ private:
|
||||
void relayout();
|
||||
|
||||
int calculate_ruler_step_size() const;
|
||||
Gfx::IntRect mouse_indicator_rect_x() const;
|
||||
Gfx::IntRect mouse_indicator_rect_y() const;
|
||||
|
||||
NonnullRefPtr<Image> m_image;
|
||||
RefPtr<Layer> m_active_layer;
|
||||
@ -150,8 +152,10 @@ private:
|
||||
Gfx::FloatPoint m_pan_origin;
|
||||
Gfx::FloatPoint m_saved_pan_origin;
|
||||
Gfx::IntPoint m_click_position;
|
||||
Gfx::IntPoint m_mouse_position;
|
||||
|
||||
int m_ruler_thickness { 20 };
|
||||
int m_mouse_indicator_triangle_size { 5 };
|
||||
|
||||
Gfx::StandardCursor m_active_cursor { Gfx::StandardCursor::None };
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user