diff options
author | Andreas Kling <kling@serenityos.org> | 2021-05-16 00:03:13 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-05-16 01:11:56 +0200 |
commit | 8c044d4f527dc97f7fc9d8b4bc8d61df69eb2bea (patch) | |
tree | 5bbfaa6cb1e2a368b176aea25e3d2441db05baae /Userland/Applications | |
parent | afc3ed228d1a560171d785e73a4afbf860cdbfc2 (diff) | |
download | serenity-8c044d4f527dc97f7fc9d8b4bc8d61df69eb2bea.zip |
PixelPaint: Convert main UI to GML :^)
Diffstat (limited to 'Userland/Applications')
10 files changed, 100 insertions, 37 deletions
diff --git a/Userland/Applications/PixelPaint/CMakeLists.txt b/Userland/Applications/PixelPaint/CMakeLists.txt index c462c8405c..fae25a2267 100644 --- a/Userland/Applications/PixelPaint/CMakeLists.txt +++ b/Userland/Applications/PixelPaint/CMakeLists.txt @@ -1,3 +1,5 @@ +compile_gml(PixelPaintWindow.gml PixelPaintWindowGML.h pixel_paint_window_gml) + set(SOURCES BrushTool.cpp BucketTool.cpp @@ -16,6 +18,7 @@ set(SOURCES PaletteWidget.cpp PenTool.cpp PickerTool.cpp + PixelPaintWindowGML.h RectangleTool.cpp SprayTool.cpp ToolboxWidget.cpp diff --git a/Userland/Applications/PixelPaint/ImageEditor.cpp b/Userland/Applications/PixelPaint/ImageEditor.cpp index 07408ea3e6..9871fd8335 100644 --- a/Userland/Applications/PixelPaint/ImageEditor.cpp +++ b/Userland/Applications/PixelPaint/ImageEditor.cpp @@ -14,6 +14,8 @@ #include <LibGfx/Palette.h> #include <LibGfx/Rect.h> +REGISTER_WIDGET(PixelPaint, ImageEditor); + namespace PixelPaint { ImageEditor::ImageEditor() diff --git a/Userland/Applications/PixelPaint/LayerListWidget.cpp b/Userland/Applications/PixelPaint/LayerListWidget.cpp index 4bc1b019bf..a627dccb42 100644 --- a/Userland/Applications/PixelPaint/LayerListWidget.cpp +++ b/Userland/Applications/PixelPaint/LayerListWidget.cpp @@ -11,6 +11,8 @@ #include <LibGUI/Painter.h> #include <LibGfx/Palette.h> +REGISTER_WIDGET(PixelPaint, LayerListWidget); + namespace PixelPaint { LayerListWidget::LayerListWidget() diff --git a/Userland/Applications/PixelPaint/LayerPropertiesWidget.cpp b/Userland/Applications/PixelPaint/LayerPropertiesWidget.cpp index cb53b54a95..44ef335626 100644 --- a/Userland/Applications/PixelPaint/LayerPropertiesWidget.cpp +++ b/Userland/Applications/PixelPaint/LayerPropertiesWidget.cpp @@ -14,6 +14,8 @@ #include <LibGUI/TextBox.h> #include <LibGfx/Font.h> +REGISTER_WIDGET(PixelPaint, LayerPropertiesWidget); + namespace PixelPaint { LayerPropertiesWidget::LayerPropertiesWidget() diff --git a/Userland/Applications/PixelPaint/PaletteWidget.cpp b/Userland/Applications/PixelPaint/PaletteWidget.cpp index 504ba63f40..74d0b94c08 100644 --- a/Userland/Applications/PixelPaint/PaletteWidget.cpp +++ b/Userland/Applications/PixelPaint/PaletteWidget.cpp @@ -10,6 +10,8 @@ #include <LibGUI/ColorPicker.h> #include <LibGfx/Palette.h> +REGISTER_WIDGET(PixelPaint, PaletteWidget); + namespace PixelPaint { class ColorWidget : public GUI::Frame { @@ -52,8 +54,7 @@ private: Color m_color; }; -PaletteWidget::PaletteWidget(ImageEditor& editor) - : m_editor(editor) +PaletteWidget::PaletteWidget() { set_frame_shape(Gfx::FrameShape::Panel); set_frame_shadow(Gfx::FrameShadow::Raised); @@ -65,22 +66,12 @@ PaletteWidget::PaletteWidget(ImageEditor& editor) m_secondary_color_widget = add<GUI::Frame>(); m_secondary_color_widget->set_relative_rect({ 2, 2, 60, 31 }); m_secondary_color_widget->set_fill_with_background_color(true); - set_secondary_color(m_editor.secondary_color()); m_primary_color_widget = add<GUI::Frame>(); Gfx::IntRect rect { 0, 0, 38, 15 }; rect.center_within(m_secondary_color_widget->relative_rect()); m_primary_color_widget->set_relative_rect(rect); m_primary_color_widget->set_fill_with_background_color(true); - set_primary_color(m_editor.primary_color()); - - m_editor.on_primary_color_change = [this](Color color) { - set_primary_color(color); - }; - - m_editor.on_secondary_color_change = [this](Color color) { - set_secondary_color(color); - }; auto& color_container = add<GUI::Widget>(); color_container.set_relative_rect(m_secondary_color_widget->relative_rect().right() + 2, 2, 500, 32); @@ -134,13 +125,28 @@ PaletteWidget::PaletteWidget(ImageEditor& editor) add_color_widget(bottom_color_container, Color::from_rgb(0xff8040)); } +void PaletteWidget::set_image_editor(ImageEditor& editor) +{ + m_editor = &editor; + set_primary_color(editor.primary_color()); + set_secondary_color(editor.secondary_color()); + + editor.on_primary_color_change = [this](Color color) { + set_primary_color(color); + }; + + editor.on_secondary_color_change = [this](Color color) { + set_secondary_color(color); + }; +} + PaletteWidget::~PaletteWidget() { } void PaletteWidget::set_primary_color(Color color) { - m_editor.set_primary_color(color); + m_editor->set_primary_color(color); auto pal = m_primary_color_widget->palette(); pal.set_color(ColorRole::Background, color); m_primary_color_widget->set_palette(pal); @@ -149,7 +155,7 @@ void PaletteWidget::set_primary_color(Color color) void PaletteWidget::set_secondary_color(Color color) { - m_editor.set_secondary_color(color); + m_editor->set_secondary_color(color); auto pal = m_secondary_color_widget->palette(); pal.set_color(ColorRole::Background, color); m_secondary_color_widget->set_palette(pal); diff --git a/Userland/Applications/PixelPaint/PaletteWidget.h b/Userland/Applications/PixelPaint/PaletteWidget.h index 7c8815a617..2a52627577 100644 --- a/Userland/Applications/PixelPaint/PaletteWidget.h +++ b/Userland/Applications/PixelPaint/PaletteWidget.h @@ -21,10 +21,12 @@ public: void set_primary_color(Color); void set_secondary_color(Color); + void set_image_editor(ImageEditor&); + private: - explicit PaletteWidget(ImageEditor&); + explicit PaletteWidget(); - ImageEditor& m_editor; + ImageEditor* m_editor { nullptr }; RefPtr<GUI::Frame> m_primary_color_widget; RefPtr<GUI::Frame> m_secondary_color_widget; }; diff --git a/Userland/Applications/PixelPaint/PixelPaintWindow.gml b/Userland/Applications/PixelPaint/PixelPaintWindow.gml new file mode 100644 index 0000000000..1a6a935b5a --- /dev/null +++ b/Userland/Applications/PixelPaint/PixelPaintWindow.gml @@ -0,0 +1,52 @@ +@GUI::Widget { + name: "main" + fill_with_background_color: true + + layout: @GUI::VerticalBoxLayout { + spacing: 2 + } + + @GUI::Widget { + layout: @GUI::HorizontalBoxLayout { + spacing: 0 + } + + @PixelPaint::ToolboxWidget { + name: "toolbox" + } + + @GUI::Widget { + layout: @GUI::VerticalBoxLayout { + spacing: 0 + } + + @PixelPaint::ImageEditor { + name: "image_editor" + } + + @PixelPaint::PaletteWidget { + name: "palette_widget" + } + } + + @GUI::Widget { + fill_with_background_color: true + fixed_width: 230 + + layout: @GUI::VerticalBoxLayout { + } + + @PixelPaint::LayerListWidget { + name: "layer_list_widget" + } + + @PixelPaint::LayerPropertiesWidget { + name: "layer_properties_widget" + } + + @PixelPaint::ToolPropertiesWidget { + name: "tool_properties_widget" + } + } + } +} diff --git a/Userland/Applications/PixelPaint/ToolPropertiesWidget.cpp b/Userland/Applications/PixelPaint/ToolPropertiesWidget.cpp index 5fe9bac4aa..f0468d257d 100644 --- a/Userland/Applications/PixelPaint/ToolPropertiesWidget.cpp +++ b/Userland/Applications/PixelPaint/ToolPropertiesWidget.cpp @@ -9,6 +9,8 @@ #include <LibGUI/BoxLayout.h> #include <LibGUI/GroupBox.h> +REGISTER_WIDGET(PixelPaint, ToolPropertiesWidget); + namespace PixelPaint { ToolPropertiesWidget::ToolPropertiesWidget() diff --git a/Userland/Applications/PixelPaint/ToolboxWidget.cpp b/Userland/Applications/PixelPaint/ToolboxWidget.cpp index 69f403eb03..0a1d2f5279 100644 --- a/Userland/Applications/PixelPaint/ToolboxWidget.cpp +++ b/Userland/Applications/PixelPaint/ToolboxWidget.cpp @@ -21,6 +21,8 @@ #include <LibGUI/Button.h> #include <LibGUI/Toolbar.h> +REGISTER_WIDGET(PixelPaint, ToolboxWidget); + namespace PixelPaint { ToolboxWidget::ToolboxWidget() diff --git a/Userland/Applications/PixelPaint/main.cpp b/Userland/Applications/PixelPaint/main.cpp index 4a77c35f4f..307e8a48fc 100644 --- a/Userland/Applications/PixelPaint/main.cpp +++ b/Userland/Applications/PixelPaint/main.cpp @@ -16,19 +16,19 @@ #include "Tool.h" #include "ToolPropertiesWidget.h" #include "ToolboxWidget.h" +#include <Applications/PixelPaint/PixelPaintWindowGML.h> #include <LibCore/ArgsParser.h> #include <LibCore/File.h> #include <LibGUI/Action.h> #include <LibGUI/Application.h> -#include <LibGUI/BoxLayout.h> #include <LibGUI/Clipboard.h> #include <LibGUI/FilePicker.h> #include <LibGUI/Icon.h> #include <LibGUI/Menubar.h> #include <LibGUI/MessageBox.h> +#include <LibGUI/Toolbar.h> #include <LibGUI/Window.h> #include <LibGfx/Bitmap.h> -#include <LibGfx/Matrix4x4.h> #include <stdio.h> #include <unistd.h> @@ -58,34 +58,24 @@ int main(int argc, char** argv) window->resize(950, 570); window->set_icon(app_icon.bitmap_for_size(16)); - auto& horizontal_container = window->set_main_widget<GUI::Widget>(); - horizontal_container.set_layout<GUI::HorizontalBoxLayout>(); - horizontal_container.layout()->set_spacing(0); + auto& main_widget = window->set_main_widget<GUI::Widget>(); + main_widget.load_from_gml(pixel_paint_window_gml); - auto& toolbox = horizontal_container.add<PixelPaint::ToolboxWidget>(); - - auto& vertical_container = horizontal_container.add<GUI::Widget>(); - vertical_container.set_layout<GUI::VerticalBoxLayout>(); - vertical_container.layout()->set_spacing(0); - - auto& image_editor = vertical_container.add<PixelPaint::ImageEditor>(); + auto& toolbox = *main_widget.find_descendant_of_type_named<PixelPaint::ToolboxWidget>("toolbox"); + auto& image_editor = *main_widget.find_descendant_of_type_named<PixelPaint::ImageEditor>("image_editor"); image_editor.set_focus(true); - vertical_container.add<PixelPaint::PaletteWidget>(image_editor); - - auto& right_panel = horizontal_container.add<GUI::Widget>(); - right_panel.set_fill_with_background_color(true); - right_panel.set_fixed_width(230); - right_panel.set_layout<GUI::VerticalBoxLayout>(); + auto& palette_widget = *main_widget.find_descendant_of_type_named<PixelPaint::PaletteWidget>("palette_widget"); + palette_widget.set_image_editor(image_editor); - auto& layer_list_widget = right_panel.add<PixelPaint::LayerListWidget>(); + auto& layer_list_widget = *main_widget.find_descendant_of_type_named<PixelPaint::LayerListWidget>("layer_list_widget"); layer_list_widget.on_layer_select = [&](auto* layer) { image_editor.set_active_layer(layer); }; - auto& layer_properties_widget = right_panel.add<PixelPaint::LayerPropertiesWidget>(); + auto& layer_properties_widget = *main_widget.find_descendant_of_type_named<PixelPaint::LayerPropertiesWidget>("layer_properties_widget"); - auto& tool_properties_widget = right_panel.add<PixelPaint::ToolPropertiesWidget>(); + auto& tool_properties_widget = *main_widget.find_descendant_of_type_named<PixelPaint::ToolPropertiesWidget>("tool_properties_widget"); toolbox.on_tool_selection = [&](auto* tool) { image_editor.set_active_tool(tool); |