summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorCody Hein <skmagiik@gmail.com>2022-12-13 22:22:03 -0700
committerAndrew Kaster <andrewdkaster@gmail.com>2022-12-31 04:49:19 -0700
commit29665668b6bf803b5587c490a86d4b0e83f92988 (patch)
tree27821c0c16454052aa51c4ef64fbb8e21da1f009 /Userland
parentbf06f494174e1af1aed09e2f9250fbc2b30db671 (diff)
downloadserenity-29665668b6bf803b5587c490a86d4b0e83f92988.zip
PixelPaint: Allow ImageEditor event to append info to the statusbar
This provides an event on ImageEditor for other functions to activate functions when appended_status_info is updated
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Applications/PixelPaint/ImageEditor.cpp9
-rw-r--r--Userland/Applications/PixelPaint/ImageEditor.h4
-rw-r--r--Userland/Applications/PixelPaint/MainWidget.cpp18
-rw-r--r--Userland/Applications/PixelPaint/MainWidget.h3
4 files changed, 33 insertions, 1 deletions
diff --git a/Userland/Applications/PixelPaint/ImageEditor.cpp b/Userland/Applications/PixelPaint/ImageEditor.cpp
index 149bed3aa7..bc206c3621 100644
--- a/Userland/Applications/PixelPaint/ImageEditor.cpp
+++ b/Userland/Applications/PixelPaint/ImageEditor.cpp
@@ -344,6 +344,8 @@ void ImageEditor::set_editor_color_to_color_at_mouse_position(GUI::MouseEvent co
color = layer->currently_edited_bitmap().get_pixel(position);
}
+ set_appended_status_info(DeprecatedString::formatted("R:{}, G:{}, B:{}, A:{} [{}]", color.red(), color.green(), color.blue(), color.alpha(), color.to_deprecated_string()));
+
// We picked a transparent pixel, do nothing.
if (!color.alpha())
return;
@@ -868,4 +870,11 @@ void ImageEditor::selection_did_change()
update();
}
+void ImageEditor::set_appended_status_info(DeprecatedString new_status_info)
+{
+ m_appended_status_info = new_status_info;
+ if (on_appended_status_info_change)
+ on_appended_status_info_change(m_appended_status_info);
+}
+
}
diff --git a/Userland/Applications/PixelPaint/ImageEditor.h b/Userland/Applications/PixelPaint/ImageEditor.h
index 92480d283a..694a068c84 100644
--- a/Userland/Applications/PixelPaint/ImageEditor.h
+++ b/Userland/Applications/PixelPaint/ImageEditor.h
@@ -123,6 +123,9 @@ public:
void set_modified(DeprecatedString action_text);
void set_unmodified();
void update_modified();
+ Function<void(DeprecatedString)> on_appended_status_info_change;
+ DeprecatedString appended_status_info() { return m_appended_status_info; };
+ void set_appended_status_info(DeprecatedString);
private:
explicit ImageEditor(NonnullRefPtr<Image>);
@@ -192,6 +195,7 @@ private:
void draw_marching_ants_pixel(Gfx::Painter&, int x, int y) const;
Core::EventLoop& m_gui_event_loop;
+ DeprecatedString m_appended_status_info;
};
}
diff --git a/Userland/Applications/PixelPaint/MainWidget.cpp b/Userland/Applications/PixelPaint/MainWidget.cpp
index 8b8630b717..d5394ee513 100644
--- a/Userland/Applications/PixelPaint/MainWidget.cpp
+++ b/Userland/Applications/PixelPaint/MainWidget.cpp
@@ -1117,7 +1117,7 @@ ImageEditor& MainWidget::create_new_editor(NonnullRefPtr<Image> image)
auto const& image_size = current_image_editor()->image().size();
auto image_rectangle = Gfx::IntRect { 0, 0, image_size.width(), image_size.height() };
if (image_rectangle.contains(mouse_position)) {
- m_statusbar->set_override_text(mouse_position.to_deprecated_string());
+ update_status_bar(current_image_editor()->appended_status_info());
m_histogram_widget->set_color_at_mouseposition(current_image_editor()->image().color_at(mouse_position));
m_vectorscope_widget->set_color_at_mouseposition(current_image_editor()->image().color_at(mouse_position));
} else {
@@ -1125,6 +1125,11 @@ ImageEditor& MainWidget::create_new_editor(NonnullRefPtr<Image> image)
m_histogram_widget->set_color_at_mouseposition(Color::Transparent);
m_vectorscope_widget->set_color_at_mouseposition(Color::Transparent);
}
+ m_last_image_editor_mouse_position = mouse_position;
+ };
+
+ image_editor.on_appended_status_info_change = [&](auto const& appended_status_info) {
+ update_status_bar(appended_status_info);
};
image_editor.on_leave = [&]() {
@@ -1217,4 +1222,15 @@ void MainWidget::update_window_modified()
{
window()->set_modified(m_tab_widget->is_any_tab_modified());
}
+void MainWidget::update_status_bar(DeprecatedString appended_text)
+{
+ StringBuilder builder = StringBuilder();
+ builder.append(m_last_image_editor_mouse_position.to_deprecated_string());
+ if (!appended_text.is_empty()) {
+ builder.append(" "sv);
+ builder.append(appended_text);
+ }
+ m_statusbar->set_override_text(builder.to_deprecated_string());
+}
+
}
diff --git a/Userland/Applications/PixelPaint/MainWidget.h b/Userland/Applications/PixelPaint/MainWidget.h
index 0053671d1b..8ffb548da3 100644
--- a/Userland/Applications/PixelPaint/MainWidget.h
+++ b/Userland/Applications/PixelPaint/MainWidget.h
@@ -60,6 +60,7 @@ private:
virtual void drop_event(GUI::DropEvent&) override;
void update_window_modified();
+ void update_status_bar(DeprecatedString appended_text = DeprecatedString::empty());
ProjectLoader m_loader;
@@ -107,6 +108,8 @@ private:
RefPtr<GUI::Action> m_layer_via_copy;
RefPtr<GUI::Action> m_layer_via_cut;
+
+ Gfx::IntPoint m_last_image_editor_mouse_position;
};
}