summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorthankyouverycool <66646555+thankyouverycool@users.noreply.github.com>2020-07-29 16:09:04 -0400
committerAndreas Kling <kling@serenityos.org>2020-08-01 07:56:48 +0200
commit41aacdf8158ff23c0105dae3defd1ab57ac9f2f5 (patch)
tree79c47e876c38a0d897fc0774219c53073f0ad026
parent044b4cc09066466d5a7c1455116a2c7644d17965 (diff)
downloadserenity-41aacdf8158ff23c0105dae3defd1ab57ac9f2f5.zip
LibGfx: Add Paths to themes
Paths allows themes to specify directories/files where custom resources are located.
-rw-r--r--Libraries/LibGfx/Palette.cpp14
-rw-r--r--Libraries/LibGfx/Palette.h5
-rw-r--r--Libraries/LibGfx/SystemTheme.cpp18
-rw-r--r--Libraries/LibGfx/SystemTheme.h8
4 files changed, 45 insertions, 0 deletions
diff --git a/Libraries/LibGfx/Palette.cpp b/Libraries/LibGfx/Palette.cpp
index de86256771..84d1990344 100644
--- a/Libraries/LibGfx/Palette.cpp
+++ b/Libraries/LibGfx/Palette.cpp
@@ -67,6 +67,12 @@ int PaletteImpl::metric(MetricRole role) const
return theme().metric[(int)role];
}
+String PaletteImpl::path(PathRole role) const
+{
+ ASSERT((int)role < (int)PathRole::__Count);
+ return theme().path[(int)role];
+}
+
NonnullRefPtr<PaletteImpl> PaletteImpl::clone() const
{
auto new_theme_buffer = SharedBuffer::create_with_size(m_theme_buffer->size());
@@ -90,6 +96,14 @@ void Palette::set_metric(MetricRole role, int value)
theme.metric[(int)role] = value;
}
+void Palette::set_path(PathRole role, String path)
+{
+ if (m_impl->ref_count() != 1)
+ m_impl = m_impl->clone();
+ auto& theme = const_cast<SystemTheme&>(impl().theme());
+ theme.path[(int)role] = path;
+}
+
PaletteImpl::~PaletteImpl()
{
}
diff --git a/Libraries/LibGfx/Palette.h b/Libraries/LibGfx/Palette.h
index e23d12dde2..6dc43e431d 100644
--- a/Libraries/LibGfx/Palette.h
+++ b/Libraries/LibGfx/Palette.h
@@ -45,6 +45,7 @@ public:
Color color(ColorRole) const;
int metric(MetricRole) const;
+ String path(PathRole) const;
const SystemTheme& theme() const;
void replace_internal_buffer(Badge<GUI::Application>, SharedBuffer& buffer);
@@ -124,11 +125,15 @@ public:
int window_title_button_width() const { return metric(MetricRole::TitleButtonWidth); }
int window_title_button_height() const { return metric(MetricRole::TitleButtonHeight); }
+ String title_button_icons_path() const { return path(PathRole::TitleButtonIcons); }
+
Color color(ColorRole role) const { return m_impl->color(role); }
int metric(MetricRole role) const { return m_impl->metric(role); }
+ String path(PathRole role) const { return m_impl->path(role); }
void set_color(ColorRole, Color);
void set_metric(MetricRole, int);
+ void set_path(PathRole, String);
const SystemTheme& theme() const { return m_impl->theme(); }
diff --git a/Libraries/LibGfx/SystemTheme.cpp b/Libraries/LibGfx/SystemTheme.cpp
index f52010bef8..35ccf43c0e 100644
--- a/Libraries/LibGfx/SystemTheme.cpp
+++ b/Libraries/LibGfx/SystemTheme.cpp
@@ -85,6 +85,19 @@ RefPtr<SharedBuffer> load_system_theme(const String& path)
return metric;
};
+ auto get_path = [&](auto& name, auto role) {
+ auto path = file->read_entry("Paths", name);
+ if (path.is_empty()) {
+ switch (role) {
+ case (int)PathRole::TitleButtonIcons:
+ return "/res/icons/16x16/";
+ default:
+ return "/res/";
+ }
+ }
+ return &path[0];
+ };
+
#define DO_COLOR(x) \
data->color[(int)ColorRole::x] = get_color(#x)
@@ -153,6 +166,11 @@ RefPtr<SharedBuffer> load_system_theme(const String& path)
DO_METRIC(TitleButtonWidth);
DO_METRIC(TitleButtonHeight);
+#define DO_PATH(x) \
+ data->path[(int)PathRole::x] = get_path(#x, (int)PathRole::x)
+
+ DO_PATH(TitleButtonIcons);
+
buffer->seal();
buffer->share_globally();
diff --git a/Libraries/LibGfx/SystemTheme.h b/Libraries/LibGfx/SystemTheme.h
index a2fa7ea4ea..244de1a54d 100644
--- a/Libraries/LibGfx/SystemTheme.h
+++ b/Libraries/LibGfx/SystemTheme.h
@@ -27,6 +27,7 @@
#pragma once
#include <AK/Forward.h>
+#include <AK/String.h>
#include <AK/Types.h>
#include <LibGfx/Color.h>
@@ -105,9 +106,16 @@ enum class MetricRole {
__Count,
};
+enum class PathRole {
+ NoRole,
+ TitleButtonIcons,
+ __Count,
+};
+
struct SystemTheme {
Color color[(int)ColorRole::__Count];
int metric[(int)MetricRole::__Count];
+ String path[(int)PathRole::__Count];
};
const SystemTheme& current_system_theme();