mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 16:37:47 +00:00
LibDraw+LibGUI: Allow changing individual colors in a Palette
Palette is now a value wrapper around a NonnullRefPtr<PaletteImpl>. A new function, set_color(ColorRole, Color) implements a simple copy-on-write mechanism so that we're sharing the PaletteImpl in the common case, but allowing you to create custom palettes if you like, by getting a GWidget's palette, modifying it, and then assigning the modified palette to the widget via GWidget::set_palette(). Use this to make PaintBrush show its palette colors once again. Fixes #943.
This commit is contained in:
parent
19d4f4c7b5
commit
7b2dd7e116
18 changed files with 98 additions and 40 deletions
|
@ -36,8 +36,10 @@ void ColorDialog::build()
|
|||
};
|
||||
|
||||
m_preview_widget = GFrame::construct(right_vertical_container);
|
||||
m_preview_widget->set_background_color(m_color);
|
||||
auto pal = m_preview_widget->palette();
|
||||
pal.set_color(ColorRole::Background, m_color);
|
||||
m_preview_widget->set_fill_with_background_color(true);
|
||||
m_preview_widget->set_palette(pal);
|
||||
right_vertical_container->layout()->add_spacer();
|
||||
auto cancel_button = GButton::construct("Cancel", right_vertical_container);
|
||||
cancel_button->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed);
|
||||
|
@ -68,7 +70,9 @@ void ColorDialog::build()
|
|||
if (component == Blue)
|
||||
m_color.set_blue(value);
|
||||
|
||||
m_preview_widget->set_background_color(m_color);
|
||||
auto pal = m_preview_widget->palette();
|
||||
pal.set_color(ColorRole::Background, m_color);
|
||||
m_preview_widget->set_palette(pal);
|
||||
m_preview_widget->update();
|
||||
};
|
||||
return spinbox;
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include "PaintableWidget.h"
|
||||
#include "Tool.h"
|
||||
#include <LibDraw/GraphicsBitmap.h>
|
||||
#include <LibDraw/Palette.h>
|
||||
#include <LibGUI/GPainter.h>
|
||||
|
||||
static PaintableWidget* s_the;
|
||||
|
@ -16,6 +17,9 @@ PaintableWidget::PaintableWidget(GWidget* parent)
|
|||
ASSERT(!s_the);
|
||||
s_the = this;
|
||||
set_fill_with_background_color(true);
|
||||
auto pal = palette();
|
||||
pal.set_color(ColorRole::Window, Color::MidGray);
|
||||
set_palette(pal);
|
||||
set_background_color(Color::MidGray);
|
||||
m_bitmap = GraphicsBitmap::create(GraphicsBitmap::Format::RGB32, { 600, 400 });
|
||||
m_bitmap->fill(Color::White);
|
||||
|
|
|
@ -26,7 +26,9 @@ public:
|
|||
auto dialog = ColorDialog::construct(m_color, window());
|
||||
if (dialog->exec() == GDialog::ExecOK) {
|
||||
m_color = dialog->color();
|
||||
set_background_color(m_color);
|
||||
auto pal = palette();
|
||||
pal.set_color(ColorRole::Background, m_color);
|
||||
set_palette(pal);
|
||||
update();
|
||||
}
|
||||
return;
|
||||
|
@ -97,7 +99,9 @@ PaletteWidget::PaletteWidget(PaintableWidget& paintable_widget, GWidget* parent)
|
|||
auto add_color_widget = [&](GWidget* container, Color color) {
|
||||
auto color_widget = ColorWidget::construct(color, *this, container);
|
||||
color_widget->set_fill_with_background_color(true);
|
||||
color_widget->set_background_color(color);
|
||||
auto pal = color_widget->palette();
|
||||
pal.set_color(ColorRole::Background, color);
|
||||
color_widget->set_palette(pal);
|
||||
};
|
||||
|
||||
add_color_widget(top_color_container, Color::from_rgb(0x000000));
|
||||
|
@ -138,13 +142,17 @@ PaletteWidget::~PaletteWidget()
|
|||
void PaletteWidget::set_primary_color(Color color)
|
||||
{
|
||||
m_paintable_widget.set_primary_color(color);
|
||||
m_primary_color_widget->set_background_color(color);
|
||||
auto pal = m_primary_color_widget->palette();
|
||||
pal.set_color(ColorRole::Background, color);
|
||||
m_primary_color_widget->set_palette(pal);
|
||||
m_primary_color_widget->update();
|
||||
}
|
||||
|
||||
void PaletteWidget::set_secondary_color(Color color)
|
||||
{
|
||||
m_paintable_widget.set_secondary_color(color);
|
||||
m_secondary_color_widget->set_background_color(color);
|
||||
auto pal = m_secondary_color_widget->palette();
|
||||
pal.set_color(ColorRole::Background, color);
|
||||
m_secondary_color_widget->set_palette(pal);
|
||||
m_secondary_color_widget->update();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue