2014-02-10 02:10:30 +01:00
|
|
|
/**************************************************************************/
|
|
|
|
/* theme.h */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* https://godotengine.org */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
|
|
|
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/**************************************************************************/
|
2018-01-05 00:50:27 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
#ifndef THEME_H
|
|
|
|
#define THEME_H
|
|
|
|
|
2020-11-07 23:33:38 +01:00
|
|
|
#include "core/io/resource.h"
|
2014-02-10 02:10:30 +01:00
|
|
|
#include "scene/resources/font.h"
|
|
|
|
#include "scene/resources/style_box.h"
|
|
|
|
#include "scene/resources/texture.h"
|
|
|
|
|
|
|
|
class Theme : public Resource {
|
2017-01-03 03:03:46 +01:00
|
|
|
GDCLASS(Theme, Resource);
|
2017-06-16 00:44:11 +02:00
|
|
|
RES_BASE_EXTENSION("theme");
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2021-05-31 16:28:02 +02:00
|
|
|
#ifdef TOOLS_ENABLED
|
|
|
|
friend class ThemeItemImportTree;
|
|
|
|
friend class ThemeItemEditorDialog;
|
2021-03-13 20:30:26 +01:00
|
|
|
friend class ThemeTypeEditor;
|
2021-05-31 16:28:02 +02:00
|
|
|
#endif
|
|
|
|
|
2021-03-22 12:35:58 +01:00
|
|
|
public:
|
2022-05-18 16:24:26 +02:00
|
|
|
using ThemeIconMap = HashMap<StringName, Ref<Texture2D>>;
|
|
|
|
using ThemeStyleMap = HashMap<StringName, Ref<StyleBox>>;
|
|
|
|
using ThemeFontMap = HashMap<StringName, Ref<Font>>;
|
|
|
|
using ThemeFontSizeMap = HashMap<StringName, int>;
|
|
|
|
using ThemeColorMap = HashMap<StringName, Color>;
|
|
|
|
using ThemeConstantMap = HashMap<StringName, int>;
|
|
|
|
|
2021-03-22 12:35:58 +01:00
|
|
|
enum DataType {
|
|
|
|
DATA_TYPE_COLOR,
|
|
|
|
DATA_TYPE_CONSTANT,
|
|
|
|
DATA_TYPE_FONT,
|
|
|
|
DATA_TYPE_FONT_SIZE,
|
|
|
|
DATA_TYPE_ICON,
|
|
|
|
DATA_TYPE_STYLEBOX,
|
|
|
|
DATA_TYPE_MAX
|
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
2021-05-31 16:28:02 +02:00
|
|
|
bool no_change_propagation = false;
|
|
|
|
|
2021-10-04 16:26:43 +02:00
|
|
|
void _emit_theme_changed(bool p_notify_list_changed = false);
|
2016-06-17 21:00:27 +02:00
|
|
|
|
2021-03-30 19:16:33 +02:00
|
|
|
Vector<String> _get_icon_list(const String &p_theme_type) const;
|
2020-04-10 16:50:28 +02:00
|
|
|
Vector<String> _get_icon_type_list() const;
|
2021-03-30 19:16:33 +02:00
|
|
|
Vector<String> _get_stylebox_list(const String &p_theme_type) const;
|
2020-04-10 16:50:28 +02:00
|
|
|
Vector<String> _get_stylebox_type_list() const;
|
2021-03-30 19:16:33 +02:00
|
|
|
Vector<String> _get_font_list(const String &p_theme_type) const;
|
2020-04-10 16:50:28 +02:00
|
|
|
Vector<String> _get_font_type_list() const;
|
2021-03-30 19:16:33 +02:00
|
|
|
Vector<String> _get_font_size_list(const String &p_theme_type) const;
|
2021-03-22 12:35:58 +01:00
|
|
|
Vector<String> _get_font_size_type_list() const;
|
2021-03-30 19:16:33 +02:00
|
|
|
Vector<String> _get_color_list(const String &p_theme_type) const;
|
2020-04-10 16:50:28 +02:00
|
|
|
Vector<String> _get_color_type_list() const;
|
2021-03-30 19:16:33 +02:00
|
|
|
Vector<String> _get_constant_list(const String &p_theme_type) const;
|
2020-04-10 16:50:28 +02:00
|
|
|
Vector<String> _get_constant_type_list() const;
|
2021-03-22 12:35:58 +01:00
|
|
|
|
2021-03-30 19:16:33 +02:00
|
|
|
Vector<String> _get_theme_item_list(DataType p_data_type, const String &p_theme_type) const;
|
2021-03-22 12:35:58 +01:00
|
|
|
Vector<String> _get_theme_item_type_list(DataType p_data_type) const;
|
2021-07-04 22:42:23 +02:00
|
|
|
|
|
|
|
Vector<String> _get_type_variation_list(const StringName &p_theme_type) const;
|
2020-04-10 16:50:28 +02:00
|
|
|
Vector<String> _get_type_list() const;
|
2019-10-23 04:08:23 +02:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
protected:
|
|
|
|
bool _set(const StringName &p_name, const Variant &p_value);
|
|
|
|
bool _get(const StringName &p_name, Variant &r_ret) const;
|
|
|
|
void _get_property_list(List<PropertyInfo> *p_list) const;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2021-10-02 18:26:20 +02:00
|
|
|
// Default values configurable for each individual theme.
|
2021-12-31 16:53:43 +01:00
|
|
|
float default_base_scale = 0.0;
|
|
|
|
Ref<Font> default_font;
|
|
|
|
int default_font_size = -1;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2023-09-13 13:14:06 +02:00
|
|
|
HashMap<StringName, ThemeIconMap> icon_map;
|
|
|
|
HashMap<StringName, ThemeStyleMap> style_map;
|
|
|
|
HashMap<StringName, ThemeFontMap> font_map;
|
|
|
|
HashMap<StringName, ThemeFontSizeMap> font_size_map;
|
|
|
|
HashMap<StringName, ThemeColorMap> color_map;
|
|
|
|
HashMap<StringName, ThemeConstantMap> constant_map;
|
|
|
|
HashMap<StringName, StringName> variation_map;
|
|
|
|
HashMap<StringName, List<StringName>> variation_base_map;
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
static void _bind_methods();
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2021-05-31 16:28:02 +02:00
|
|
|
void _freeze_change_propagation();
|
|
|
|
void _unfreeze_and_propagate_changes();
|
|
|
|
|
2021-02-11 18:18:45 +01:00
|
|
|
virtual void reset_state() override;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
public:
|
2022-04-26 12:21:34 +02:00
|
|
|
static bool is_valid_type_name(const String &p_name);
|
|
|
|
static bool is_valid_item_name(const String &p_name);
|
|
|
|
|
2021-12-31 16:53:43 +01:00
|
|
|
void set_default_base_scale(float p_base_scale);
|
|
|
|
float get_default_base_scale() const;
|
|
|
|
bool has_default_base_scale() const;
|
|
|
|
|
|
|
|
void set_default_font(const Ref<Font> &p_default_font);
|
|
|
|
Ref<Font> get_default_font() const;
|
|
|
|
bool has_default_font() const;
|
|
|
|
|
|
|
|
void set_default_font_size(int p_font_size);
|
|
|
|
int get_default_font_size() const;
|
|
|
|
bool has_default_font_size() const;
|
2020-09-03 13:22:16 +02:00
|
|
|
|
2021-03-30 19:16:33 +02:00
|
|
|
void set_icon(const StringName &p_name, const StringName &p_theme_type, const Ref<Texture2D> &p_icon);
|
2023-09-13 13:14:06 +02:00
|
|
|
virtual Ref<Texture2D> get_icon(const StringName &p_name, const StringName &p_theme_type) const;
|
2021-03-30 19:16:33 +02:00
|
|
|
bool has_icon(const StringName &p_name, const StringName &p_theme_type) const;
|
|
|
|
bool has_icon_nocheck(const StringName &p_name, const StringName &p_theme_type) const;
|
|
|
|
void rename_icon(const StringName &p_old_name, const StringName &p_name, const StringName &p_theme_type);
|
|
|
|
void clear_icon(const StringName &p_name, const StringName &p_theme_type);
|
2021-08-01 21:47:20 +02:00
|
|
|
void get_icon_list(const StringName &p_theme_type, List<StringName> *p_list) const;
|
2021-03-30 19:16:33 +02:00
|
|
|
void add_icon_type(const StringName &p_theme_type);
|
2022-02-11 15:53:58 +01:00
|
|
|
void remove_icon_type(const StringName &p_theme_type);
|
2020-04-10 16:50:28 +02:00
|
|
|
void get_icon_type_list(List<StringName> *p_list) const;
|
2020-09-12 18:20:11 +02:00
|
|
|
|
2021-03-30 19:16:33 +02:00
|
|
|
void set_stylebox(const StringName &p_name, const StringName &p_theme_type, const Ref<StyleBox> &p_style);
|
2023-09-13 13:14:06 +02:00
|
|
|
virtual Ref<StyleBox> get_stylebox(const StringName &p_name, const StringName &p_theme_type) const;
|
2021-03-30 19:16:33 +02:00
|
|
|
bool has_stylebox(const StringName &p_name, const StringName &p_theme_type) const;
|
|
|
|
bool has_stylebox_nocheck(const StringName &p_name, const StringName &p_theme_type) const;
|
|
|
|
void rename_stylebox(const StringName &p_old_name, const StringName &p_name, const StringName &p_theme_type);
|
|
|
|
void clear_stylebox(const StringName &p_name, const StringName &p_theme_type);
|
2021-08-01 21:47:20 +02:00
|
|
|
void get_stylebox_list(const StringName &p_theme_type, List<StringName> *p_list) const;
|
2021-03-30 19:16:33 +02:00
|
|
|
void add_stylebox_type(const StringName &p_theme_type);
|
2022-02-11 15:53:58 +01:00
|
|
|
void remove_stylebox_type(const StringName &p_theme_type);
|
2020-04-10 16:50:28 +02:00
|
|
|
void get_stylebox_type_list(List<StringName> *p_list) const;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2021-03-30 19:16:33 +02:00
|
|
|
void set_font(const StringName &p_name, const StringName &p_theme_type, const Ref<Font> &p_font);
|
2023-09-13 13:14:06 +02:00
|
|
|
virtual Ref<Font> get_font(const StringName &p_name, const StringName &p_theme_type) const;
|
2021-03-30 19:16:33 +02:00
|
|
|
bool has_font(const StringName &p_name, const StringName &p_theme_type) const;
|
|
|
|
bool has_font_nocheck(const StringName &p_name, const StringName &p_theme_type) const;
|
|
|
|
void rename_font(const StringName &p_old_name, const StringName &p_name, const StringName &p_theme_type);
|
|
|
|
void clear_font(const StringName &p_name, const StringName &p_theme_type);
|
2021-08-01 21:47:20 +02:00
|
|
|
void get_font_list(const StringName &p_theme_type, List<StringName> *p_list) const;
|
2021-03-30 19:16:33 +02:00
|
|
|
void add_font_type(const StringName &p_theme_type);
|
2022-02-11 15:53:58 +01:00
|
|
|
void remove_font_type(const StringName &p_theme_type);
|
2020-04-10 16:50:28 +02:00
|
|
|
void get_font_type_list(List<StringName> *p_list) const;
|
2020-09-03 13:22:16 +02:00
|
|
|
|
2021-03-30 19:16:33 +02:00
|
|
|
void set_font_size(const StringName &p_name, const StringName &p_theme_type, int p_font_size);
|
2023-09-13 13:14:06 +02:00
|
|
|
virtual int get_font_size(const StringName &p_name, const StringName &p_theme_type) const;
|
2021-03-30 19:16:33 +02:00
|
|
|
bool has_font_size(const StringName &p_name, const StringName &p_theme_type) const;
|
|
|
|
bool has_font_size_nocheck(const StringName &p_name, const StringName &p_theme_type) const;
|
|
|
|
void rename_font_size(const StringName &p_old_name, const StringName &p_name, const StringName &p_theme_type);
|
|
|
|
void clear_font_size(const StringName &p_name, const StringName &p_theme_type);
|
2021-08-01 21:47:20 +02:00
|
|
|
void get_font_size_list(const StringName &p_theme_type, List<StringName> *p_list) const;
|
2021-03-30 19:16:33 +02:00
|
|
|
void add_font_size_type(const StringName &p_theme_type);
|
2022-02-11 15:53:58 +01:00
|
|
|
void remove_font_size_type(const StringName &p_theme_type);
|
2021-03-22 12:35:58 +01:00
|
|
|
void get_font_size_type_list(List<StringName> *p_list) const;
|
2020-09-12 18:20:11 +02:00
|
|
|
|
2021-03-30 19:16:33 +02:00
|
|
|
void set_color(const StringName &p_name, const StringName &p_theme_type, const Color &p_color);
|
2023-09-13 13:14:06 +02:00
|
|
|
virtual Color get_color(const StringName &p_name, const StringName &p_theme_type) const;
|
2021-03-30 19:16:33 +02:00
|
|
|
bool has_color(const StringName &p_name, const StringName &p_theme_type) const;
|
|
|
|
bool has_color_nocheck(const StringName &p_name, const StringName &p_theme_type) const;
|
|
|
|
void rename_color(const StringName &p_old_name, const StringName &p_name, const StringName &p_theme_type);
|
|
|
|
void clear_color(const StringName &p_name, const StringName &p_theme_type);
|
2021-08-01 21:47:20 +02:00
|
|
|
void get_color_list(const StringName &p_theme_type, List<StringName> *p_list) const;
|
2021-03-30 19:16:33 +02:00
|
|
|
void add_color_type(const StringName &p_theme_type);
|
2022-02-11 15:53:58 +01:00
|
|
|
void remove_color_type(const StringName &p_theme_type);
|
2020-04-10 16:50:28 +02:00
|
|
|
void get_color_type_list(List<StringName> *p_list) const;
|
2020-09-12 18:20:11 +02:00
|
|
|
|
2021-03-30 19:16:33 +02:00
|
|
|
void set_constant(const StringName &p_name, const StringName &p_theme_type, int p_constant);
|
2023-09-13 13:14:06 +02:00
|
|
|
virtual int get_constant(const StringName &p_name, const StringName &p_theme_type) const;
|
2021-03-30 19:16:33 +02:00
|
|
|
bool has_constant(const StringName &p_name, const StringName &p_theme_type) const;
|
|
|
|
bool has_constant_nocheck(const StringName &p_name, const StringName &p_theme_type) const;
|
|
|
|
void rename_constant(const StringName &p_old_name, const StringName &p_name, const StringName &p_theme_type);
|
|
|
|
void clear_constant(const StringName &p_name, const StringName &p_theme_type);
|
2021-08-01 21:47:20 +02:00
|
|
|
void get_constant_list(const StringName &p_theme_type, List<StringName> *p_list) const;
|
2021-03-30 19:16:33 +02:00
|
|
|
void add_constant_type(const StringName &p_theme_type);
|
2022-02-11 15:53:58 +01:00
|
|
|
void remove_constant_type(const StringName &p_theme_type);
|
2020-04-10 16:50:28 +02:00
|
|
|
void get_constant_type_list(List<StringName> *p_list) const;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2021-03-30 19:16:33 +02:00
|
|
|
void set_theme_item(DataType p_data_type, const StringName &p_name, const StringName &p_theme_type, const Variant &p_value);
|
|
|
|
Variant get_theme_item(DataType p_data_type, const StringName &p_name, const StringName &p_theme_type) const;
|
|
|
|
bool has_theme_item(DataType p_data_type, const StringName &p_name, const StringName &p_theme_type) const;
|
|
|
|
bool has_theme_item_nocheck(DataType p_data_type, const StringName &p_name, const StringName &p_theme_type) const;
|
|
|
|
void rename_theme_item(DataType p_data_type, const StringName &p_old_name, const StringName &p_name, const StringName &p_theme_type);
|
|
|
|
void clear_theme_item(DataType p_data_type, const StringName &p_name, const StringName &p_theme_type);
|
2021-08-01 21:47:20 +02:00
|
|
|
void get_theme_item_list(DataType p_data_type, const StringName &p_theme_type, List<StringName> *p_list) const;
|
2021-03-30 19:16:33 +02:00
|
|
|
void add_theme_item_type(DataType p_data_type, const StringName &p_theme_type);
|
2022-02-11 15:53:58 +01:00
|
|
|
void remove_theme_item_type(DataType p_data_type, const StringName &p_theme_type);
|
2021-03-22 12:35:58 +01:00
|
|
|
void get_theme_item_type_list(DataType p_data_type, List<StringName> *p_list) const;
|
|
|
|
|
2021-07-04 22:42:23 +02:00
|
|
|
void set_type_variation(const StringName &p_theme_type, const StringName &p_base_type);
|
|
|
|
bool is_type_variation(const StringName &p_theme_type, const StringName &p_base_type) const;
|
|
|
|
void clear_type_variation(const StringName &p_theme_type);
|
|
|
|
StringName get_type_variation_base(const StringName &p_theme_type) const;
|
|
|
|
void get_type_variation_list(const StringName &p_base_type, List<StringName> *p_list) const;
|
|
|
|
|
2022-02-11 15:53:58 +01:00
|
|
|
void add_type(const StringName &p_theme_type);
|
|
|
|
void remove_type(const StringName &p_theme_type);
|
2014-02-10 02:10:30 +01:00
|
|
|
void get_type_list(List<StringName> *p_list) const;
|
2021-07-04 22:42:23 +02:00
|
|
|
void get_type_dependencies(const StringName &p_base_type, const StringName &p_type_variant, List<StringName> *p_list);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2021-08-14 01:01:15 +02:00
|
|
|
void merge_with(const Ref<Theme> &p_other);
|
2018-11-27 18:33:14 +01:00
|
|
|
void clear();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
Theme();
|
|
|
|
~Theme();
|
|
|
|
};
|
|
|
|
|
2021-03-22 12:35:58 +01:00
|
|
|
VARIANT_ENUM_CAST(Theme::DataType);
|
|
|
|
|
2022-07-23 23:41:51 +02:00
|
|
|
#endif // THEME_H
|