mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 06:17:35 +00:00
PixelPaint: Convert main UI to GML :^)
This commit is contained in:
parent
afc3ed228d
commit
8c044d4f52
10 changed files with 101 additions and 38 deletions
|
@ -1,3 +1,5 @@
|
||||||
|
compile_gml(PixelPaintWindow.gml PixelPaintWindowGML.h pixel_paint_window_gml)
|
||||||
|
|
||||||
set(SOURCES
|
set(SOURCES
|
||||||
BrushTool.cpp
|
BrushTool.cpp
|
||||||
BucketTool.cpp
|
BucketTool.cpp
|
||||||
|
@ -16,6 +18,7 @@ set(SOURCES
|
||||||
PaletteWidget.cpp
|
PaletteWidget.cpp
|
||||||
PenTool.cpp
|
PenTool.cpp
|
||||||
PickerTool.cpp
|
PickerTool.cpp
|
||||||
|
PixelPaintWindowGML.h
|
||||||
RectangleTool.cpp
|
RectangleTool.cpp
|
||||||
SprayTool.cpp
|
SprayTool.cpp
|
||||||
ToolboxWidget.cpp
|
ToolboxWidget.cpp
|
||||||
|
|
|
@ -14,6 +14,8 @@
|
||||||
#include <LibGfx/Palette.h>
|
#include <LibGfx/Palette.h>
|
||||||
#include <LibGfx/Rect.h>
|
#include <LibGfx/Rect.h>
|
||||||
|
|
||||||
|
REGISTER_WIDGET(PixelPaint, ImageEditor);
|
||||||
|
|
||||||
namespace PixelPaint {
|
namespace PixelPaint {
|
||||||
|
|
||||||
ImageEditor::ImageEditor()
|
ImageEditor::ImageEditor()
|
||||||
|
|
|
@ -11,6 +11,8 @@
|
||||||
#include <LibGUI/Painter.h>
|
#include <LibGUI/Painter.h>
|
||||||
#include <LibGfx/Palette.h>
|
#include <LibGfx/Palette.h>
|
||||||
|
|
||||||
|
REGISTER_WIDGET(PixelPaint, LayerListWidget);
|
||||||
|
|
||||||
namespace PixelPaint {
|
namespace PixelPaint {
|
||||||
|
|
||||||
LayerListWidget::LayerListWidget()
|
LayerListWidget::LayerListWidget()
|
||||||
|
|
|
@ -14,6 +14,8 @@
|
||||||
#include <LibGUI/TextBox.h>
|
#include <LibGUI/TextBox.h>
|
||||||
#include <LibGfx/Font.h>
|
#include <LibGfx/Font.h>
|
||||||
|
|
||||||
|
REGISTER_WIDGET(PixelPaint, LayerPropertiesWidget);
|
||||||
|
|
||||||
namespace PixelPaint {
|
namespace PixelPaint {
|
||||||
|
|
||||||
LayerPropertiesWidget::LayerPropertiesWidget()
|
LayerPropertiesWidget::LayerPropertiesWidget()
|
||||||
|
|
|
@ -10,6 +10,8 @@
|
||||||
#include <LibGUI/ColorPicker.h>
|
#include <LibGUI/ColorPicker.h>
|
||||||
#include <LibGfx/Palette.h>
|
#include <LibGfx/Palette.h>
|
||||||
|
|
||||||
|
REGISTER_WIDGET(PixelPaint, PaletteWidget);
|
||||||
|
|
||||||
namespace PixelPaint {
|
namespace PixelPaint {
|
||||||
|
|
||||||
class ColorWidget : public GUI::Frame {
|
class ColorWidget : public GUI::Frame {
|
||||||
|
@ -52,8 +54,7 @@ private:
|
||||||
Color m_color;
|
Color m_color;
|
||||||
};
|
};
|
||||||
|
|
||||||
PaletteWidget::PaletteWidget(ImageEditor& editor)
|
PaletteWidget::PaletteWidget()
|
||||||
: m_editor(editor)
|
|
||||||
{
|
{
|
||||||
set_frame_shape(Gfx::FrameShape::Panel);
|
set_frame_shape(Gfx::FrameShape::Panel);
|
||||||
set_frame_shadow(Gfx::FrameShadow::Raised);
|
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 = add<GUI::Frame>();
|
||||||
m_secondary_color_widget->set_relative_rect({ 2, 2, 60, 31 });
|
m_secondary_color_widget->set_relative_rect({ 2, 2, 60, 31 });
|
||||||
m_secondary_color_widget->set_fill_with_background_color(true);
|
m_secondary_color_widget->set_fill_with_background_color(true);
|
||||||
set_secondary_color(m_editor.secondary_color());
|
|
||||||
|
|
||||||
m_primary_color_widget = add<GUI::Frame>();
|
m_primary_color_widget = add<GUI::Frame>();
|
||||||
Gfx::IntRect rect { 0, 0, 38, 15 };
|
Gfx::IntRect rect { 0, 0, 38, 15 };
|
||||||
rect.center_within(m_secondary_color_widget->relative_rect());
|
rect.center_within(m_secondary_color_widget->relative_rect());
|
||||||
m_primary_color_widget->set_relative_rect(rect);
|
m_primary_color_widget->set_relative_rect(rect);
|
||||||
m_primary_color_widget->set_fill_with_background_color(true);
|
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>();
|
auto& color_container = add<GUI::Widget>();
|
||||||
color_container.set_relative_rect(m_secondary_color_widget->relative_rect().right() + 2, 2, 500, 32);
|
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));
|
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()
|
PaletteWidget::~PaletteWidget()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void PaletteWidget::set_primary_color(Color color)
|
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();
|
auto pal = m_primary_color_widget->palette();
|
||||||
pal.set_color(ColorRole::Background, color);
|
pal.set_color(ColorRole::Background, color);
|
||||||
m_primary_color_widget->set_palette(pal);
|
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)
|
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();
|
auto pal = m_secondary_color_widget->palette();
|
||||||
pal.set_color(ColorRole::Background, color);
|
pal.set_color(ColorRole::Background, color);
|
||||||
m_secondary_color_widget->set_palette(pal);
|
m_secondary_color_widget->set_palette(pal);
|
||||||
|
|
|
@ -21,10 +21,12 @@ public:
|
||||||
void set_primary_color(Color);
|
void set_primary_color(Color);
|
||||||
void set_secondary_color(Color);
|
void set_secondary_color(Color);
|
||||||
|
|
||||||
private:
|
void set_image_editor(ImageEditor&);
|
||||||
explicit PaletteWidget(ImageEditor&);
|
|
||||||
|
|
||||||
ImageEditor& m_editor;
|
private:
|
||||||
|
explicit PaletteWidget();
|
||||||
|
|
||||||
|
ImageEditor* m_editor { nullptr };
|
||||||
RefPtr<GUI::Frame> m_primary_color_widget;
|
RefPtr<GUI::Frame> m_primary_color_widget;
|
||||||
RefPtr<GUI::Frame> m_secondary_color_widget;
|
RefPtr<GUI::Frame> m_secondary_color_widget;
|
||||||
};
|
};
|
||||||
|
|
52
Userland/Applications/PixelPaint/PixelPaintWindow.gml
Normal file
52
Userland/Applications/PixelPaint/PixelPaintWindow.gml
Normal file
|
@ -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"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -9,6 +9,8 @@
|
||||||
#include <LibGUI/BoxLayout.h>
|
#include <LibGUI/BoxLayout.h>
|
||||||
#include <LibGUI/GroupBox.h>
|
#include <LibGUI/GroupBox.h>
|
||||||
|
|
||||||
|
REGISTER_WIDGET(PixelPaint, ToolPropertiesWidget);
|
||||||
|
|
||||||
namespace PixelPaint {
|
namespace PixelPaint {
|
||||||
|
|
||||||
ToolPropertiesWidget::ToolPropertiesWidget()
|
ToolPropertiesWidget::ToolPropertiesWidget()
|
||||||
|
|
|
@ -21,6 +21,8 @@
|
||||||
#include <LibGUI/Button.h>
|
#include <LibGUI/Button.h>
|
||||||
#include <LibGUI/Toolbar.h>
|
#include <LibGUI/Toolbar.h>
|
||||||
|
|
||||||
|
REGISTER_WIDGET(PixelPaint, ToolboxWidget);
|
||||||
|
|
||||||
namespace PixelPaint {
|
namespace PixelPaint {
|
||||||
|
|
||||||
ToolboxWidget::ToolboxWidget()
|
ToolboxWidget::ToolboxWidget()
|
||||||
|
|
|
@ -16,19 +16,19 @@
|
||||||
#include "Tool.h"
|
#include "Tool.h"
|
||||||
#include "ToolPropertiesWidget.h"
|
#include "ToolPropertiesWidget.h"
|
||||||
#include "ToolboxWidget.h"
|
#include "ToolboxWidget.h"
|
||||||
|
#include <Applications/PixelPaint/PixelPaintWindowGML.h>
|
||||||
#include <LibCore/ArgsParser.h>
|
#include <LibCore/ArgsParser.h>
|
||||||
#include <LibCore/File.h>
|
#include <LibCore/File.h>
|
||||||
#include <LibGUI/Action.h>
|
#include <LibGUI/Action.h>
|
||||||
#include <LibGUI/Application.h>
|
#include <LibGUI/Application.h>
|
||||||
#include <LibGUI/BoxLayout.h>
|
|
||||||
#include <LibGUI/Clipboard.h>
|
#include <LibGUI/Clipboard.h>
|
||||||
#include <LibGUI/FilePicker.h>
|
#include <LibGUI/FilePicker.h>
|
||||||
#include <LibGUI/Icon.h>
|
#include <LibGUI/Icon.h>
|
||||||
#include <LibGUI/Menubar.h>
|
#include <LibGUI/Menubar.h>
|
||||||
#include <LibGUI/MessageBox.h>
|
#include <LibGUI/MessageBox.h>
|
||||||
|
#include <LibGUI/Toolbar.h>
|
||||||
#include <LibGUI/Window.h>
|
#include <LibGUI/Window.h>
|
||||||
#include <LibGfx/Bitmap.h>
|
#include <LibGfx/Bitmap.h>
|
||||||
#include <LibGfx/Matrix4x4.h>
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
@ -58,34 +58,24 @@ int main(int argc, char** argv)
|
||||||
window->resize(950, 570);
|
window->resize(950, 570);
|
||||||
window->set_icon(app_icon.bitmap_for_size(16));
|
window->set_icon(app_icon.bitmap_for_size(16));
|
||||||
|
|
||||||
auto& horizontal_container = window->set_main_widget<GUI::Widget>();
|
auto& main_widget = window->set_main_widget<GUI::Widget>();
|
||||||
horizontal_container.set_layout<GUI::HorizontalBoxLayout>();
|
main_widget.load_from_gml(pixel_paint_window_gml);
|
||||||
horizontal_container.layout()->set_spacing(0);
|
|
||||||
|
|
||||||
auto& toolbox = horizontal_container.add<PixelPaint::ToolboxWidget>();
|
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");
|
||||||
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>();
|
|
||||||
image_editor.set_focus(true);
|
image_editor.set_focus(true);
|
||||||
|
|
||||||
vertical_container.add<PixelPaint::PaletteWidget>(image_editor);
|
auto& palette_widget = *main_widget.find_descendant_of_type_named<PixelPaint::PaletteWidget>("palette_widget");
|
||||||
|
palette_widget.set_image_editor(image_editor);
|
||||||
|
|
||||||
auto& right_panel = horizontal_container.add<GUI::Widget>();
|
auto& layer_list_widget = *main_widget.find_descendant_of_type_named<PixelPaint::LayerListWidget>("layer_list_widget");
|
||||||
right_panel.set_fill_with_background_color(true);
|
|
||||||
right_panel.set_fixed_width(230);
|
|
||||||
right_panel.set_layout<GUI::VerticalBoxLayout>();
|
|
||||||
|
|
||||||
auto& layer_list_widget = right_panel.add<PixelPaint::LayerListWidget>();
|
|
||||||
layer_list_widget.on_layer_select = [&](auto* layer) {
|
layer_list_widget.on_layer_select = [&](auto* layer) {
|
||||||
image_editor.set_active_layer(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) {
|
toolbox.on_tool_selection = [&](auto* tool) {
|
||||||
image_editor.set_active_tool(tool);
|
image_editor.set_active_tool(tool);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue