Skip to content

Commit

Permalink
Bind remaining theme properties to their respective classes
Browse files Browse the repository at this point in the history
This adds binds for GraphEdit/GraphElement/GraphNode, which were
skipped before due to a rework. This also adds binds for Window,
which was skipped before due to a complicated code organization.

Also adds theme cache entries/direct cache access to a few places
that previously missed it. Some theme properties are now exposed
to other classes via friendships or public getters for convenience.

This removes all string-based theme access from scene/ classes.
  • Loading branch information
YuriSizov committed Sep 13, 2023
1 parent 98b50eb commit fe00027
Show file tree
Hide file tree
Showing 26 changed files with 356 additions and 189 deletions.
17 changes: 16 additions & 1 deletion scene/gui/code_edit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2399,6 +2399,19 @@ void CodeEdit::set_symbol_lookup_word_as_valid(bool p_valid) {
}
}

/* Visual */
Color CodeEdit::_get_brace_mismatch_color() const {
return theme_cache.brace_mismatch_color;
}

Color CodeEdit::_get_code_folding_color() const {
return theme_cache.code_folding_color;
}

Ref<Texture2D> CodeEdit::_get_folded_eol_icon() const {
return theme_cache.folded_eol_icon;
}

void CodeEdit::_bind_methods() {
/* Indent management */
ClassDB::bind_method(D_METHOD("set_indent_size", "size"), &CodeEdit::set_indent_size);
Expand Down Expand Up @@ -2644,7 +2657,7 @@ void CodeEdit::_bind_methods() {
BIND_THEME_ITEM(Theme::DATA_TYPE_ICON, CodeEdit, folded_eol_icon);

BIND_THEME_ITEM(Theme::DATA_TYPE_COLOR, CodeEdit, breakpoint_color);
BIND_THEME_ITEM_CUSTOM(Theme::DATA_TYPE_COLOR, CodeEdit, breakpoint_icon, "breakpoint");
BIND_THEME_ITEM_CUSTOM(Theme::DATA_TYPE_ICON, CodeEdit, breakpoint_icon, "breakpoint");

BIND_THEME_ITEM(Theme::DATA_TYPE_COLOR, CodeEdit, bookmark_color);
BIND_THEME_ITEM_CUSTOM(Theme::DATA_TYPE_ICON, CodeEdit, bookmark_icon, "bookmark");
Expand Down Expand Up @@ -2677,6 +2690,8 @@ void CodeEdit::_bind_methods() {
/* Other visuals */
BIND_THEME_ITEM_CUSTOM(Theme::DATA_TYPE_STYLEBOX, CodeEdit, style_normal, "normal");

BIND_THEME_ITEM(Theme::DATA_TYPE_COLOR, CodeEdit, brace_mismatch_color);

BIND_THEME_ITEM(Theme::DATA_TYPE_FONT, CodeEdit, font);
BIND_THEME_ITEM(Theme::DATA_TYPE_FONT_SIZE, CodeEdit, font_size);

Expand Down
6 changes: 6 additions & 0 deletions scene/gui/code_edit.h
Original file line number Diff line number Diff line change
Expand Up @@ -278,11 +278,17 @@ class CodeEdit : public TextEdit {
/* Other visuals */
Ref<StyleBox> style_normal;

Color brace_mismatch_color;

Ref<Font> font;
int font_size = 16;
int line_spacing = 1;
} theme_cache;

virtual Color _get_brace_mismatch_color() const override;
virtual Color _get_code_folding_color() const override;
virtual Ref<Texture2D> _get_folded_eol_icon() const override;

/* Callbacks */
int lines_edited_changed = 0;
int lines_edited_from = -1;
Expand Down
20 changes: 10 additions & 10 deletions scene/gui/color_mode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ void ColorModeRGB::slider_draw(int p_which) {
Color left_color;
Color right_color;
Color color = color_picker->get_pick_color();
const real_t margin = 16 * color_picker->get_theme_default_base_scale();
const real_t margin = 16 * color_picker->theme_cache.base_scale;

if (p_which == ColorPicker::SLIDER_COUNT) {
slider->draw_texture_rect(color_picker->get_theme_icon(SNAME("sample_bg"), SNAME("ColorPicker")), Rect2(Point2(0, 0), Size2(size.x, margin)), true);
slider->draw_texture_rect(color_picker->theme_cache.sample_bg, Rect2(Point2(0, 0), Size2(size.x, margin)), true);

left_color = color;
left_color.a = 0;
Expand Down Expand Up @@ -168,10 +168,10 @@ void ColorModeHSV::slider_draw(int p_which) {
Color left_color;
Color right_color;
Color color = color_picker->get_pick_color();
const real_t margin = 16 * color_picker->get_theme_default_base_scale();
const real_t margin = 16 * color_picker->theme_cache.base_scale;

if (p_which == ColorPicker::SLIDER_COUNT) {
slider->draw_texture_rect(color_picker->get_theme_icon(SNAME("sample_bg"), SNAME("ColorPicker")), Rect2(Point2(0, 0), Size2(size.x, margin)), true);
slider->draw_texture_rect(color_picker->theme_cache.sample_bg, Rect2(Point2(0, 0), Size2(size.x, margin)), true);

left_color = color;
left_color.a = 0;
Expand Down Expand Up @@ -204,7 +204,7 @@ void ColorModeHSV::slider_draw(int p_which) {
slider->draw_polygon(pos, col);

if (p_which == 0) { // H
Ref<Texture2D> hue = color_picker->get_theme_icon(SNAME("color_hue"), SNAME("ColorPicker"));
Ref<Texture2D> hue = color_picker->theme_cache.color_hue;
slider->draw_texture_rect(hue, Rect2(Vector2(), Vector2(size.x, margin)), false, Color::from_hsv(0, 0, color.get_v(), color.get_s()));
}
}
Expand Down Expand Up @@ -243,10 +243,10 @@ void ColorModeRAW::slider_draw(int p_which) {
Color left_color;
Color right_color;
Color color = color_picker->get_pick_color();
const real_t margin = 16 * color_picker->get_theme_default_base_scale();
const real_t margin = 16 * color_picker->theme_cache.base_scale;

if (p_which == ColorPicker::SLIDER_COUNT) {
slider->draw_texture_rect(color_picker->get_theme_icon(SNAME("sample_bg"), SNAME("ColorPicker")), Rect2(Point2(0, 0), Size2(size.x, margin)), true);
slider->draw_texture_rect(color_picker->theme_cache.sample_bg, Rect2(Point2(0, 0), Size2(size.x, margin)), true);

left_color = color;
left_color.a = 0;
Expand Down Expand Up @@ -334,7 +334,7 @@ Color ColorModeOKHSL::get_color() const {
void ColorModeOKHSL::slider_draw(int p_which) {
HSlider *slider = color_picker->get_slider(p_which);
Size2 size = slider->get_size();
const real_t margin = 16 * color_picker->get_theme_default_base_scale();
const real_t margin = 16 * color_picker->theme_cache.base_scale;

Vector<Vector2> pos;
Vector<Color> col;
Expand Down Expand Up @@ -370,7 +370,7 @@ void ColorModeOKHSL::slider_draw(int p_which) {
col.resize(4);

if (p_which == ColorPicker::SLIDER_COUNT) {
slider->draw_texture_rect(color_picker->get_theme_icon(SNAME("sample_bg"), SNAME("ColorPicker")), Rect2(Point2(0, 0), Size2(size.x, margin)), true);
slider->draw_texture_rect(color_picker->theme_cache.sample_bg, Rect2(Point2(0, 0), Size2(size.x, margin)), true);

left_color = color;
left_color.a = 0;
Expand Down Expand Up @@ -399,7 +399,7 @@ void ColorModeOKHSL::slider_draw(int p_which) {
slider->draw_polygon(pos, col);

if (p_which == 0) { // H
Ref<Texture2D> hue = color_picker->get_theme_icon(SNAME("color_okhsl_hue"), SNAME("ColorPicker"));
Ref<Texture2D> hue = color_picker->theme_cache.color_okhsl_hue;
slider->draw_texture_rect(hue, Rect2(Vector2(), Vector2(size.x, margin)), false, Color::from_hsv(0, 0, color.get_ok_hsl_l() * 2.0, color.get_ok_hsl_s()));
return;
}
Expand Down
13 changes: 7 additions & 6 deletions scene/gui/color_picker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,7 @@ ColorPicker::PickerShapeType ColorPicker::get_picker_shape() const {
}

inline int ColorPicker::_get_preset_size() {
return (int(get_minimum_size().width) - (preset_container->get_theme_constant(SNAME("h_separation")) * (PRESET_COLUMN_COUNT - 1))) / PRESET_COLUMN_COUNT;
return (int(get_minimum_size().width) - (preset_container->get_h_separation() * (PRESET_COLUMN_COUNT - 1))) / PRESET_COLUMN_COUNT;
}

void ColorPicker::_add_preset_button(int p_size, const Color &p_color) {
Expand Down Expand Up @@ -997,7 +997,7 @@ void ColorPicker::_sample_draw() {
const Rect2 rect_old = Rect2(Point2(), Size2(sample->get_size().width * 0.5, sample->get_size().height * 0.95));

if (old_color.a < 1.0) {
sample->draw_texture_rect(theme_cache.sample_background_icon, rect_old, true);
sample->draw_texture_rect(theme_cache.sample_bg, rect_old, true);
}

sample->draw_rect(rect_old, old_color);
Expand All @@ -1011,7 +1011,7 @@ void ColorPicker::_sample_draw() {
}

if (color.a < 1.0) {
sample->draw_texture_rect(theme_cache.sample_background_icon, rect_new, true);
sample->draw_texture_rect(theme_cache.sample_bg, rect_new, true);
}

sample->draw_rect(rect_new, color);
Expand Down Expand Up @@ -1125,7 +1125,7 @@ void ColorPicker::_hsv_draw(int p_which, Control *c) {
} else if (p_which == 1) {
if (actual_shape == SHAPE_HSV_RECTANGLE) {
c->draw_set_transform(Point2(), -Math_PI / 2, Size2(c->get_size().x, -c->get_size().y));
c->draw_texture_rect(theme_cache.color_hue_icon, Rect2(Point2(), Size2(1, 1)));
c->draw_texture_rect(theme_cache.color_hue, Rect2(Point2(), Size2(1, 1)));
c->draw_set_transform(Point2(), 0, Size2(1, 1));
int y = c->get_size().y - c->get_size().y * (1.0 - h);
Color col;
Expand Down Expand Up @@ -1703,10 +1703,11 @@ void ColorPicker::_bind_methods() {
BIND_THEME_ITEM(Theme::DATA_TYPE_ICON, ColorPicker, shape_circle);

BIND_THEME_ITEM(Theme::DATA_TYPE_ICON, ColorPicker, bar_arrow);
BIND_THEME_ITEM_CUSTOM(Theme::DATA_TYPE_ICON, ColorPicker, sample_background_icon, "sample_bg");
BIND_THEME_ITEM(Theme::DATA_TYPE_ICON, ColorPicker, sample_bg);
BIND_THEME_ITEM(Theme::DATA_TYPE_ICON, ColorPicker, overbright_indicator);
BIND_THEME_ITEM(Theme::DATA_TYPE_ICON, ColorPicker, picker_cursor);
BIND_THEME_ITEM_CUSTOM(Theme::DATA_TYPE_ICON, ColorPicker, color_hue_icon, "color_hue");
BIND_THEME_ITEM(Theme::DATA_TYPE_ICON, ColorPicker, color_hue);
BIND_THEME_ITEM(Theme::DATA_TYPE_ICON, ColorPicker, color_okhsl_hue);

BIND_THEME_ITEM_EXT(Theme::DATA_TYPE_STYLEBOX, ColorPicker, mode_button_normal, "tab_unselected", "TabContainer");
BIND_THEME_ITEM_EXT(Theme::DATA_TYPE_STYLEBOX, ColorPicker, mode_button_pressed, "tab_selected", "TabContainer");
Expand Down
11 changes: 9 additions & 2 deletions scene/gui/color_picker.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ class ColorPresetButton : public BaseButton {
class ColorPicker : public VBoxContainer {
GDCLASS(ColorPicker, VBoxContainer);

// These classes poke into theme items for their internal logic.
friend class ColorModeRGB;
friend class ColorModeHSV;
friend class ColorModeRAW;
friend class ColorModeOKHSL;

public:
enum ColorModeType {
MODE_RGB,
Expand Down Expand Up @@ -229,10 +235,11 @@ class ColorPicker : public VBoxContainer {
Ref<Texture2D> shape_circle;

Ref<Texture2D> bar_arrow;
Ref<Texture2D> sample_background_icon;
Ref<Texture2D> sample_bg;
Ref<Texture2D> overbright_indicator;
Ref<Texture2D> picker_cursor;
Ref<Texture2D> color_hue_icon;
Ref<Texture2D> color_hue;
Ref<Texture2D> color_okhsl_hue;

/* Mode buttons */
Ref<StyleBox> mode_button_normal;
Expand Down
Loading

0 comments on commit fe00027

Please sign in to comment.