1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 02:47:35 +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:
Andreas Kling 2019-12-29 00:47:49 +01:00
parent 19d4f4c7b5
commit 7b2dd7e116
18 changed files with 98 additions and 40 deletions

View file

@ -1,13 +1,33 @@
#pragma once
#include <AK/Badge.h>
#include <AK/Noncopyable.h>
#include <LibDraw/SystemTheme.h>
class GApplication;
class Palette : public RefCounted<Palette> {
class PaletteImpl : public RefCounted<PaletteImpl> {
AK_MAKE_NONCOPYABLE(PaletteImpl)
AK_MAKE_NONMOVABLE(PaletteImpl)
public:
static NonnullRefPtr<Palette> create_with_shared_buffer(SharedBuffer&);
static NonnullRefPtr<PaletteImpl> create_with_shared_buffer(SharedBuffer&);
NonnullRefPtr<PaletteImpl> clone() const;
Color color(ColorRole) const;
const SystemTheme& theme() const;
void replace_internal_buffer(Badge<GApplication>, SharedBuffer& buffer) { m_theme_buffer = buffer; }
private:
explicit PaletteImpl(SharedBuffer&);
RefPtr<SharedBuffer> m_theme_buffer;
};
class Palette {
public:
explicit Palette(const PaletteImpl&);
~Palette();
Color window() const { return color(ColorRole::Window); }
@ -41,14 +61,14 @@ public:
Color threed_shadow2() const { return color(ColorRole::ThreedShadow2); }
Color hover_highlight() const { return color(ColorRole::ThreedHighlight); }
Color color(ColorRole) const;
Color color(ColorRole role) const { return m_impl->color(role); }
void set_color(ColorRole, Color);
const SystemTheme& theme() const;
const SystemTheme& theme() const { return m_impl->theme(); }
void replace_internal_buffer(Badge<GApplication>, SharedBuffer& buffer) { m_theme_buffer = buffer; }
PaletteImpl& impl() { return *m_impl; }
const PaletteImpl& impl() const { return *m_impl; }
private:
explicit Palette(SharedBuffer&);
RefPtr<SharedBuffer> m_theme_buffer;
NonnullRefPtr<PaletteImpl> m_impl;
};