diff options
Diffstat (limited to 'scene/resources')
-rw-r--r-- | scene/resources/default_theme/default_theme.cpp | 78 | ||||
-rw-r--r-- | scene/resources/style_box.cpp | 188 | ||||
-rw-r--r-- | scene/resources/style_box.h | 32 |
3 files changed, 149 insertions, 149 deletions
diff --git a/scene/resources/default_theme/default_theme.cpp b/scene/resources/default_theme/default_theme.cpp index 2de28b5e5c..7dbf53a43c 100644 --- a/scene/resources/default_theme/default_theme.cpp +++ b/scene/resources/default_theme/default_theme.cpp @@ -64,14 +64,14 @@ static Ref<StyleBoxTexture> make_stylebox(T p_src, float p_left, float p_top, fl Ref<StyleBoxTexture> style(memnew(StyleBoxTexture)); style->set_texture(texture); - style->set_margin_size(MARGIN_LEFT, p_left * scale); - style->set_margin_size(MARGIN_RIGHT, p_right * scale); - style->set_margin_size(MARGIN_BOTTOM, p_botton * scale); - style->set_margin_size(MARGIN_TOP, p_top * scale); - style->set_default_margin(MARGIN_LEFT, p_margin_left * scale); - style->set_default_margin(MARGIN_RIGHT, p_margin_right * scale); - style->set_default_margin(MARGIN_BOTTOM, p_margin_botton * scale); - style->set_default_margin(MARGIN_TOP, p_margin_top * scale); + style->set_margin_size(SIDE_LEFT, p_left * scale); + style->set_margin_size(SIDE_RIGHT, p_right * scale); + style->set_margin_size(SIDE_BOTTOM, p_botton * scale); + style->set_margin_size(SIDE_TOP, p_top * scale); + style->set_default_margin(SIDE_LEFT, p_margin_left * scale); + style->set_default_margin(SIDE_RIGHT, p_margin_right * scale); + style->set_default_margin(SIDE_BOTTOM, p_margin_botton * scale); + style->set_default_margin(SIDE_TOP, p_margin_top * scale); style->set_draw_center(p_draw_center); return style; @@ -80,19 +80,19 @@ static Ref<StyleBoxTexture> make_stylebox(T p_src, float p_left, float p_top, fl static Ref<StyleBoxFlat> make_flat_stylebox(Color p_color, float p_margin_left = -1, float p_margin_top = -1, float p_margin_right = -1, float p_margin_bottom = -1) { Ref<StyleBoxFlat> style(memnew(StyleBoxFlat)); style->set_bg_color(p_color); - style->set_default_margin(MARGIN_LEFT, p_margin_left * scale); - style->set_default_margin(MARGIN_RIGHT, p_margin_right * scale); - style->set_default_margin(MARGIN_BOTTOM, p_margin_bottom * scale); - style->set_default_margin(MARGIN_TOP, p_margin_top * scale); + style->set_default_margin(SIDE_LEFT, p_margin_left * scale); + style->set_default_margin(SIDE_RIGHT, p_margin_right * scale); + style->set_default_margin(SIDE_BOTTOM, p_margin_bottom * scale); + style->set_default_margin(SIDE_TOP, p_margin_top * scale); return style; } static Ref<StyleBoxTexture> sb_expand(Ref<StyleBoxTexture> p_sbox, float p_left, float p_top, float p_right, float p_botton) { - p_sbox->set_expand_margin_size(MARGIN_LEFT, p_left * scale); - p_sbox->set_expand_margin_size(MARGIN_TOP, p_top * scale); - p_sbox->set_expand_margin_size(MARGIN_RIGHT, p_right * scale); - p_sbox->set_expand_margin_size(MARGIN_BOTTOM, p_botton * scale); + p_sbox->set_expand_margin_size(SIDE_LEFT, p_left * scale); + p_sbox->set_expand_margin_size(SIDE_TOP, p_top * scale); + p_sbox->set_expand_margin_size(SIDE_RIGHT, p_right * scale); + p_sbox->set_expand_margin_size(SIDE_BOTTOM, p_botton * scale); return p_sbox; } @@ -130,10 +130,10 @@ static Ref<Texture2D> flip_icon(Ref<Texture2D> p_texture, bool p_flip_y = false, static Ref<StyleBox> make_empty_stylebox(float p_margin_left = -1, float p_margin_top = -1, float p_margin_right = -1, float p_margin_botton = -1) { Ref<StyleBox> style(memnew(StyleBoxEmpty)); - style->set_default_margin(MARGIN_LEFT, p_margin_left * scale); - style->set_default_margin(MARGIN_RIGHT, p_margin_right * scale); - style->set_default_margin(MARGIN_BOTTOM, p_margin_botton * scale); - style->set_default_margin(MARGIN_TOP, p_margin_top * scale); + style->set_default_margin(SIDE_LEFT, p_margin_left * scale); + style->set_default_margin(SIDE_RIGHT, p_margin_right * scale); + style->set_default_margin(SIDE_BOTTOM, p_margin_botton * scale); + style->set_default_margin(SIDE_TOP, p_margin_top * scale); return style; } @@ -162,7 +162,7 @@ void fill_default_theme(Ref<Theme> &theme, const Ref<Font> &default_font, const Ref<StyleBoxTexture> focus = make_stylebox(focus_png, 5, 5, 5, 5); for (int i = 0; i < 4; i++) { - focus->set_expand_margin_size(Margin(i), 1 * scale); + focus->set_expand_margin_size(Side(i), 1 * scale); } // Button @@ -281,15 +281,15 @@ void fill_default_theme(Ref<Theme> &theme, const Ref<Font> &default_font, const // CheckBox Ref<StyleBox> cbx_empty = memnew(StyleBoxEmpty); - cbx_empty->set_default_margin(MARGIN_LEFT, 4 * scale); - cbx_empty->set_default_margin(MARGIN_RIGHT, 4 * scale); - cbx_empty->set_default_margin(MARGIN_TOP, 4 * scale); - cbx_empty->set_default_margin(MARGIN_BOTTOM, 4 * scale); + cbx_empty->set_default_margin(SIDE_LEFT, 4 * scale); + cbx_empty->set_default_margin(SIDE_RIGHT, 4 * scale); + cbx_empty->set_default_margin(SIDE_TOP, 4 * scale); + cbx_empty->set_default_margin(SIDE_BOTTOM, 4 * scale); Ref<StyleBox> cbx_focus = focus; - cbx_focus->set_default_margin(MARGIN_LEFT, 4 * scale); - cbx_focus->set_default_margin(MARGIN_RIGHT, 4 * scale); - cbx_focus->set_default_margin(MARGIN_TOP, 4 * scale); - cbx_focus->set_default_margin(MARGIN_BOTTOM, 4 * scale); + cbx_focus->set_default_margin(SIDE_LEFT, 4 * scale); + cbx_focus->set_default_margin(SIDE_RIGHT, 4 * scale); + cbx_focus->set_default_margin(SIDE_TOP, 4 * scale); + cbx_focus->set_default_margin(SIDE_BOTTOM, 4 * scale); theme->set_stylebox("normal", "CheckBox", cbx_empty); theme->set_stylebox("pressed", "CheckBox", cbx_empty); @@ -318,10 +318,10 @@ void fill_default_theme(Ref<Theme> &theme, const Ref<Font> &default_font, const // CheckButton Ref<StyleBox> cb_empty = memnew(StyleBoxEmpty); - cb_empty->set_default_margin(MARGIN_LEFT, 6 * scale); - cb_empty->set_default_margin(MARGIN_RIGHT, 6 * scale); - cb_empty->set_default_margin(MARGIN_TOP, 4 * scale); - cb_empty->set_default_margin(MARGIN_BOTTOM, 4 * scale); + cb_empty->set_default_margin(SIDE_LEFT, 6 * scale); + cb_empty->set_default_margin(SIDE_RIGHT, 6 * scale); + cb_empty->set_default_margin(SIDE_TOP, 4 * scale); + cb_empty->set_default_margin(SIDE_BOTTOM, 4 * scale); theme->set_stylebox("normal", "CheckButton", cb_empty); theme->set_stylebox("pressed", "CheckButton", cb_empty); @@ -568,7 +568,7 @@ void fill_default_theme(Ref<Theme> &theme, const Ref<Font> &default_font, const Ref<StyleBoxTexture> selected = make_stylebox(selection_png, 6, 6, 6, 6); for (int i = 0; i < 4; i++) { - selected->set_expand_margin_size(Margin(i), 2 * scale); + selected->set_expand_margin_size(Side(i), 2 * scale); } theme->set_stylebox("panel", "PopupPanel", style_pp); @@ -617,8 +617,8 @@ void fill_default_theme(Ref<Theme> &theme, const Ref<Font> &default_font, const Ref<StyleBoxTexture> graph_bpoint = make_stylebox(graph_node_breakpoint_png, 6, 24, 6, 5, 16, 24, 16, 6); Ref<StyleBoxTexture> graph_position = make_stylebox(graph_node_position_png, 6, 24, 6, 5, 16, 24, 16, 6); - //graphsb->set_expand_margin_size(MARGIN_LEFT,10); - //graphsb->set_expand_margin_size(MARGIN_RIGHT,10); + //graphsb->set_expand_margin_size(SIDE_LEFT,10); + //graphsb->set_expand_margin_size(SIDE_RIGHT,10); theme->set_stylebox("frame", "GraphNode", graphsb); theme->set_stylebox("selectedframe", "GraphNode", graphsbselected); theme->set_stylebox("defaultframe", "GraphNode", graphsbdefault); @@ -713,8 +713,8 @@ void fill_default_theme(Ref<Theme> &theme, const Ref<Font> &default_font, const Ref<StyleBoxTexture> tc_sb = sb_expand(make_stylebox(tab_container_bg_png, 4, 4, 4, 4, 4, 4, 4, 4), 3, 3, 3, 3); - tc_sb->set_expand_margin_size(MARGIN_TOP, 2 * scale); - tc_sb->set_default_margin(MARGIN_TOP, 8 * scale); + tc_sb->set_expand_margin_size(SIDE_TOP, 2 * scale); + tc_sb->set_default_margin(SIDE_TOP, 8 * scale); theme->set_stylebox("tab_fg", "TabContainer", sb_expand(make_stylebox(tab_current_png, 4, 4, 4, 1, 16, 4, 16, 4), 2, 2, 2, 2)); theme->set_stylebox("tab_bg", "TabContainer", sb_expand(make_stylebox(tab_behind_png, 5, 5, 5, 1, 16, 6, 16, 4), 3, 0, 3, 3)); @@ -808,7 +808,7 @@ void fill_default_theme(Ref<Theme> &theme, const Ref<Font> &default_font, const Ref<StyleBoxTexture> style_tt = make_stylebox(tooltip_bg_png, 4, 4, 4, 4); for (int i = 0; i < 4; i++) { - style_tt->set_expand_margin_size((Margin)i, 4 * scale); + style_tt->set_expand_margin_size((Side)i, 4 * scale); } theme->set_stylebox("panel", "TooltipPanel", style_tt); diff --git a/scene/resources/style_box.cpp b/scene/resources/style_box.cpp index 14197c6c68..0271edaff0 100644 --- a/scene/resources/style_box.cpp +++ b/scene/resources/style_box.cpp @@ -38,26 +38,26 @@ bool StyleBox::test_mask(const Point2 &p_point, const Rect2 &p_rect) const { return true; } -void StyleBox::set_default_margin(Margin p_margin, float p_value) { - ERR_FAIL_INDEX((int)p_margin, 4); +void StyleBox::set_default_margin(Side p_side, float p_value) { + ERR_FAIL_INDEX((int)p_side, 4); - margin[p_margin] = p_value; + margin[p_side] = p_value; emit_changed(); } -float StyleBox::get_default_margin(Margin p_margin) const { - ERR_FAIL_INDEX_V((int)p_margin, 4, 0.0); +float StyleBox::get_default_margin(Side p_side) const { + ERR_FAIL_INDEX_V((int)p_side, 4, 0.0); - return margin[p_margin]; + return margin[p_side]; } -float StyleBox::get_margin(Margin p_margin) const { - ERR_FAIL_INDEX_V((int)p_margin, 4, 0.0); +float StyleBox::get_margin(Side p_side) const { + ERR_FAIL_INDEX_V((int)p_side, 4, 0.0); - if (margin[p_margin] < 0) { - return get_style_margin(p_margin); + if (margin[p_side] < 0) { + return get_style_margin(p_side); } else { - return margin[p_margin]; + return margin[p_side]; } } @@ -66,11 +66,11 @@ CanvasItem *StyleBox::get_current_item_drawn() const { } Size2 StyleBox::get_minimum_size() const { - return Size2(get_margin(MARGIN_LEFT) + get_margin(MARGIN_RIGHT), get_margin(MARGIN_TOP) + get_margin(MARGIN_BOTTOM)); + return Size2(get_margin(SIDE_LEFT) + get_margin(SIDE_RIGHT), get_margin(SIDE_TOP) + get_margin(SIDE_BOTTOM)); } Point2 StyleBox::get_offset() const { - return Point2(get_margin(MARGIN_LEFT), get_margin(MARGIN_TOP)); + return Point2(get_margin(SIDE_LEFT), get_margin(SIDE_TOP)); } Size2 StyleBox::get_center_size() const { @@ -99,10 +99,10 @@ void StyleBox::_bind_methods() { ClassDB::bind_method(D_METHOD("draw", "canvas_item", "rect"), &StyleBox::draw); ADD_GROUP("Content Margin", "content_margin_"); - ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "content_margin_left", PROPERTY_HINT_RANGE, "-1,2048,1"), "set_default_margin", "get_default_margin", MARGIN_LEFT); - ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "content_margin_right", PROPERTY_HINT_RANGE, "-1,2048,1"), "set_default_margin", "get_default_margin", MARGIN_RIGHT); - ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "content_margin_top", PROPERTY_HINT_RANGE, "-1,2048,1"), "set_default_margin", "get_default_margin", MARGIN_TOP); - ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "content_margin_bottom", PROPERTY_HINT_RANGE, "-1,2048,1"), "set_default_margin", "get_default_margin", MARGIN_BOTTOM); + ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "content_margin_left", PROPERTY_HINT_RANGE, "-1,2048,1"), "set_default_margin", "get_default_margin", SIDE_LEFT); + ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "content_margin_right", PROPERTY_HINT_RANGE, "-1,2048,1"), "set_default_margin", "get_default_margin", SIDE_RIGHT); + ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "content_margin_top", PROPERTY_HINT_RANGE, "-1,2048,1"), "set_default_margin", "get_default_margin", SIDE_TOP); + ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "content_margin_bottom", PROPERTY_HINT_RANGE, "-1,2048,1"), "set_default_margin", "get_default_margin", SIDE_BOTTOM); } StyleBox::StyleBox() { @@ -130,10 +130,10 @@ Ref<Texture2D> StyleBoxTexture::get_texture() const { return texture; } -void StyleBoxTexture::set_margin_size(Margin p_margin, float p_size) { - ERR_FAIL_INDEX((int)p_margin, 4); +void StyleBoxTexture::set_margin_size(Side p_side, float p_size) { + ERR_FAIL_INDEX((int)p_side, 4); - margin[p_margin] = p_size; + margin[p_side] = p_size; emit_changed(); static const char *margin_prop[4] = { "content_margin_left", @@ -141,23 +141,23 @@ void StyleBoxTexture::set_margin_size(Margin p_margin, float p_size) { "content_margin_right", "content_margin_bottom", }; - _change_notify(margin_prop[p_margin]); + _change_notify(margin_prop[p_side]); } -float StyleBoxTexture::get_margin_size(Margin p_margin) const { - ERR_FAIL_INDEX_V((int)p_margin, 4, 0.0); +float StyleBoxTexture::get_margin_size(Side p_side) const { + ERR_FAIL_INDEX_V((int)p_side, 4, 0.0); - return margin[p_margin]; + return margin[p_side]; } -float StyleBoxTexture::get_style_margin(Margin p_margin) const { - ERR_FAIL_INDEX_V((int)p_margin, 4, 0.0); +float StyleBoxTexture::get_style_margin(Side p_side) const { + ERR_FAIL_INDEX_V((int)p_side, 4, 0.0); - return margin[p_margin]; + return margin[p_side]; } Rect2 StyleBoxTexture::get_draw_rect(const Rect2 &p_rect) const { - return p_rect.grow_individual(expand_margin[MARGIN_LEFT], expand_margin[MARGIN_TOP], expand_margin[MARGIN_RIGHT], expand_margin[MARGIN_BOTTOM]); + return p_rect.grow_individual(expand_margin[SIDE_LEFT], expand_margin[SIDE_TOP], expand_margin[SIDE_RIGHT], expand_margin[SIDE_BOTTOM]); } void StyleBoxTexture::draw(RID p_canvas_item, const Rect2 &p_rect) const { @@ -170,12 +170,12 @@ void StyleBoxTexture::draw(RID p_canvas_item, const Rect2 &p_rect) const { texture->get_rect_region(rect, src_rect, rect, src_rect); - rect.position.x -= expand_margin[MARGIN_LEFT]; - rect.position.y -= expand_margin[MARGIN_TOP]; - rect.size.x += expand_margin[MARGIN_LEFT] + expand_margin[MARGIN_RIGHT]; - rect.size.y += expand_margin[MARGIN_TOP] + expand_margin[MARGIN_BOTTOM]; + rect.position.x -= expand_margin[SIDE_LEFT]; + rect.position.y -= expand_margin[SIDE_TOP]; + rect.size.x += expand_margin[SIDE_LEFT] + expand_margin[SIDE_RIGHT]; + rect.size.y += expand_margin[SIDE_TOP] + expand_margin[SIDE_BOTTOM]; - RenderingServer::get_singleton()->canvas_item_add_nine_patch(p_canvas_item, rect, src_rect, texture->get_rid(), Vector2(margin[MARGIN_LEFT], margin[MARGIN_TOP]), Vector2(margin[MARGIN_RIGHT], margin[MARGIN_BOTTOM]), RS::NinePatchAxisMode(axis_h), RS::NinePatchAxisMode(axis_v), draw_center, modulate); + RenderingServer::get_singleton()->canvas_item_add_nine_patch(p_canvas_item, rect, src_rect, texture->get_rid(), Vector2(margin[SIDE_LEFT], margin[SIDE_TOP]), Vector2(margin[SIDE_RIGHT], margin[SIDE_BOTTOM]), RS::NinePatchAxisMode(axis_h), RS::NinePatchAxisMode(axis_v), draw_center, modulate); } void StyleBoxTexture::set_draw_center(bool p_enabled) { @@ -195,17 +195,17 @@ Size2 StyleBoxTexture::get_center_size() const { return region_rect.size - get_minimum_size(); } -void StyleBoxTexture::set_expand_margin_size(Margin p_expand_margin, float p_size) { - ERR_FAIL_INDEX((int)p_expand_margin, 4); - expand_margin[p_expand_margin] = p_size; +void StyleBoxTexture::set_expand_margin_size(Side p_side, float p_size) { + ERR_FAIL_INDEX((int)p_side, 4); + expand_margin[p_side] = p_size; emit_changed(); } void StyleBoxTexture::set_expand_margin_size_individual(float p_left, float p_top, float p_right, float p_bottom) { - expand_margin[MARGIN_LEFT] = p_left; - expand_margin[MARGIN_TOP] = p_top; - expand_margin[MARGIN_RIGHT] = p_right; - expand_margin[MARGIN_BOTTOM] = p_bottom; + expand_margin[SIDE_LEFT] = p_left; + expand_margin[SIDE_TOP] = p_top; + expand_margin[SIDE_RIGHT] = p_right; + expand_margin[SIDE_BOTTOM] = p_bottom; emit_changed(); } @@ -216,9 +216,9 @@ void StyleBoxTexture::set_expand_margin_size_all(float p_expand_margin_size) { emit_changed(); } -float StyleBoxTexture::get_expand_margin_size(Margin p_expand_margin) const { - ERR_FAIL_INDEX_V((int)p_expand_margin, 4, 0); - return expand_margin[p_expand_margin]; +float StyleBoxTexture::get_expand_margin_size(Side p_side) const { + ERR_FAIL_INDEX_V((int)p_side, 4, 0); + return expand_margin[p_side]; } void StyleBoxTexture::set_region_rect(const Rect2 &p_region_rect) { @@ -299,15 +299,15 @@ void StyleBoxTexture::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture2D"), "set_texture", "get_texture"); ADD_PROPERTY(PropertyInfo(Variant::RECT2, "region_rect"), "set_region_rect", "get_region_rect"); ADD_GROUP("Margin", "margin_"); - ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "margin_left", PROPERTY_HINT_RANGE, "0,2048,1"), "set_margin_size", "get_margin_size", MARGIN_LEFT); - ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "margin_right", PROPERTY_HINT_RANGE, "0,2048,1"), "set_margin_size", "get_margin_size", MARGIN_RIGHT); - ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "margin_top", PROPERTY_HINT_RANGE, "0,2048,1"), "set_margin_size", "get_margin_size", MARGIN_TOP); - ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "margin_bottom", PROPERTY_HINT_RANGE, "0,2048,1"), "set_margin_size", "get_margin_size", MARGIN_BOTTOM); + ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "margin_left", PROPERTY_HINT_RANGE, "0,2048,1"), "set_margin_size", "get_margin_size", SIDE_LEFT); + ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "margin_right", PROPERTY_HINT_RANGE, "0,2048,1"), "set_margin_size", "get_margin_size", SIDE_RIGHT); + ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "margin_top", PROPERTY_HINT_RANGE, "0,2048,1"), "set_margin_size", "get_margin_size", SIDE_TOP); + ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "margin_bottom", PROPERTY_HINT_RANGE, "0,2048,1"), "set_margin_size", "get_margin_size", SIDE_BOTTOM); ADD_GROUP("Expand Margin", "expand_margin_"); - ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "expand_margin_left", PROPERTY_HINT_RANGE, "0,2048,1"), "set_expand_margin_size", "get_expand_margin_size", MARGIN_LEFT); - ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "expand_margin_right", PROPERTY_HINT_RANGE, "0,2048,1"), "set_expand_margin_size", "get_expand_margin_size", MARGIN_RIGHT); - ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "expand_margin_top", PROPERTY_HINT_RANGE, "0,2048,1"), "set_expand_margin_size", "get_expand_margin_size", MARGIN_TOP); - ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "expand_margin_bottom", PROPERTY_HINT_RANGE, "0,2048,1"), "set_expand_margin_size", "get_expand_margin_size", MARGIN_BOTTOM); + ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "expand_margin_left", PROPERTY_HINT_RANGE, "0,2048,1"), "set_expand_margin_size", "get_expand_margin_size", SIDE_LEFT); + ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "expand_margin_right", PROPERTY_HINT_RANGE, "0,2048,1"), "set_expand_margin_size", "get_expand_margin_size", SIDE_RIGHT); + ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "expand_margin_top", PROPERTY_HINT_RANGE, "0,2048,1"), "set_expand_margin_size", "get_expand_margin_size", SIDE_TOP); + ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "expand_margin_bottom", PROPERTY_HINT_RANGE, "0,2048,1"), "set_expand_margin_size", "get_expand_margin_size", SIDE_BOTTOM); ADD_GROUP("Axis Stretch", "axis_stretch_"); ADD_PROPERTY(PropertyInfo(Variant::INT, "axis_stretch_horizontal", PROPERTY_HINT_ENUM, "Stretch,Tile,Tile Fit"), "set_h_axis_stretch_mode", "get_h_axis_stretch_mode"); ADD_PROPERTY(PropertyInfo(Variant::INT, "axis_stretch_vertical", PROPERTY_HINT_ENUM, "Stretch,Tile,Tile Fit"), "set_v_axis_stretch_mode", "get_v_axis_stretch_mode"); @@ -367,15 +367,15 @@ int StyleBoxFlat::get_border_width_min() const { return MIN(MIN(border_width[0], border_width[1]), MIN(border_width[2], border_width[3])); } -void StyleBoxFlat::set_border_width(Margin p_margin, int p_width) { - ERR_FAIL_INDEX((int)p_margin, 4); - border_width[p_margin] = p_width; +void StyleBoxFlat::set_border_width(Side p_side, int p_width) { + ERR_FAIL_INDEX((int)p_side, 4); + border_width[p_side] = p_width; emit_changed(); } -int StyleBoxFlat::get_border_width(Margin p_margin) const { - ERR_FAIL_INDEX_V((int)p_margin, 4, 0); - return border_width[p_margin]; +int StyleBoxFlat::get_border_width(Side p_side) const { + ERR_FAIL_INDEX_V((int)p_side, 4, 0); + return border_width[p_side]; } void StyleBoxFlat::set_border_blend(bool p_blend) { @@ -415,17 +415,17 @@ int StyleBoxFlat::get_corner_radius(const Corner p_corner) const { return corner_radius[p_corner]; } -void StyleBoxFlat::set_expand_margin_size(Margin p_expand_margin, float p_size) { - ERR_FAIL_INDEX((int)p_expand_margin, 4); - expand_margin[p_expand_margin] = p_size; +void StyleBoxFlat::set_expand_margin_size(Side p_side, float p_size) { + ERR_FAIL_INDEX((int)p_side, 4); + expand_margin[p_side] = p_size; emit_changed(); } void StyleBoxFlat::set_expand_margin_size_individual(float p_left, float p_top, float p_right, float p_bottom) { - expand_margin[MARGIN_LEFT] = p_left; - expand_margin[MARGIN_TOP] = p_top; - expand_margin[MARGIN_RIGHT] = p_right; - expand_margin[MARGIN_BOTTOM] = p_bottom; + expand_margin[SIDE_LEFT] = p_left; + expand_margin[SIDE_TOP] = p_top; + expand_margin[SIDE_RIGHT] = p_right; + expand_margin[SIDE_BOTTOM] = p_bottom; emit_changed(); } @@ -436,9 +436,9 @@ void StyleBoxFlat::set_expand_margin_size_all(float p_expand_margin_size) { emit_changed(); } -float StyleBoxFlat::get_expand_margin_size(Margin p_expand_margin) const { - ERR_FAIL_INDEX_V((int)p_expand_margin, 4, 0.0); - return expand_margin[p_expand_margin]; +float StyleBoxFlat::get_expand_margin_size(Side p_side) const { + ERR_FAIL_INDEX_V((int)p_side, 4, 0.0); + return expand_margin[p_side]; } void StyleBoxFlat::set_draw_center(bool p_enabled) { @@ -633,7 +633,7 @@ inline void adapt_values(int p_index_a, int p_index_b, int *adapted_values, cons } Rect2 StyleBoxFlat::get_draw_rect(const Rect2 &p_rect) const { - Rect2 draw_rect = p_rect.grow_individual(expand_margin[MARGIN_LEFT], expand_margin[MARGIN_TOP], expand_margin[MARGIN_RIGHT], expand_margin[MARGIN_BOTTOM]); + Rect2 draw_rect = p_rect.grow_individual(expand_margin[SIDE_LEFT], expand_margin[SIDE_TOP], expand_margin[SIDE_RIGHT], expand_margin[SIDE_BOTTOM]); if (shadow_size > 0) { Rect2 shadow_rect = draw_rect.grow(shadow_size); @@ -652,7 +652,7 @@ void StyleBoxFlat::draw(RID p_canvas_item, const Rect2 &p_rect) const { return; } - Rect2 style_rect = p_rect.grow_individual(expand_margin[MARGIN_LEFT], expand_margin[MARGIN_TOP], expand_margin[MARGIN_RIGHT], expand_margin[MARGIN_BOTTOM]); + Rect2 style_rect = p_rect.grow_individual(expand_margin[SIDE_LEFT], expand_margin[SIDE_TOP], expand_margin[SIDE_RIGHT], expand_margin[SIDE_BOTTOM]); if (Math::is_zero_approx(style_rect.size.width) || Math::is_zero_approx(style_rect.size.height)) { return; } @@ -671,23 +671,23 @@ void StyleBoxFlat::draw(RID p_canvas_item, const Rect2 &p_rect) const { int width = MAX(style_rect.size.width, 0); int height = MAX(style_rect.size.height, 0); int adapted_border[4] = { INT_MAX, INT_MAX, INT_MAX, INT_MAX }; - adapt_values(MARGIN_TOP, MARGIN_BOTTOM, adapted_border, border_width, height, height, height); - adapt_values(MARGIN_LEFT, MARGIN_RIGHT, adapted_border, border_width, width, width, width); + adapt_values(SIDE_TOP, SIDE_BOTTOM, adapted_border, border_width, height, height, height); + adapt_values(SIDE_LEFT, SIDE_RIGHT, adapted_border, border_width, width, width, width); //adapt corners (prevent weird overlapping/glitchy drawings) int adapted_corner[4] = { INT_MAX, INT_MAX, INT_MAX, INT_MAX }; - adapt_values(CORNER_TOP_RIGHT, CORNER_BOTTOM_RIGHT, adapted_corner, corner_radius, height, height - adapted_border[MARGIN_BOTTOM], height - adapted_border[MARGIN_TOP]); - adapt_values(CORNER_TOP_LEFT, CORNER_BOTTOM_LEFT, adapted_corner, corner_radius, height, height - adapted_border[MARGIN_BOTTOM], height - adapted_border[MARGIN_TOP]); - adapt_values(CORNER_TOP_LEFT, CORNER_TOP_RIGHT, adapted_corner, corner_radius, width, width - adapted_border[MARGIN_RIGHT], width - adapted_border[MARGIN_LEFT]); - adapt_values(CORNER_BOTTOM_LEFT, CORNER_BOTTOM_RIGHT, adapted_corner, corner_radius, width, width - adapted_border[MARGIN_RIGHT], width - adapted_border[MARGIN_LEFT]); + adapt_values(CORNER_TOP_RIGHT, CORNER_BOTTOM_RIGHT, adapted_corner, corner_radius, height, height - adapted_border[SIDE_BOTTOM], height - adapted_border[SIDE_TOP]); + adapt_values(CORNER_TOP_LEFT, CORNER_BOTTOM_LEFT, adapted_corner, corner_radius, height, height - adapted_border[SIDE_BOTTOM], height - adapted_border[SIDE_TOP]); + adapt_values(CORNER_TOP_LEFT, CORNER_TOP_RIGHT, adapted_corner, corner_radius, width, width - adapted_border[SIDE_RIGHT], width - adapted_border[SIDE_LEFT]); + adapt_values(CORNER_BOTTOM_LEFT, CORNER_BOTTOM_RIGHT, adapted_corner, corner_radius, width, width - adapted_border[SIDE_RIGHT], width - adapted_border[SIDE_LEFT]); - Rect2 infill_rect = style_rect.grow_individual(-adapted_border[MARGIN_LEFT], -adapted_border[MARGIN_TOP], -adapted_border[MARGIN_RIGHT], -adapted_border[MARGIN_BOTTOM]); + Rect2 infill_rect = style_rect.grow_individual(-adapted_border[SIDE_LEFT], -adapted_border[SIDE_TOP], -adapted_border[SIDE_RIGHT], -adapted_border[SIDE_BOTTOM]); Rect2 border_style_rect = style_rect; if (aa_on) { for (int i = 0; i < 4; i++) { if (border_width[i] > 0) { - border_style_rect = border_style_rect.grow_margin((Margin)i, -aa_size_grow); + border_style_rect = border_style_rect.grow_margin((Side)i, -aa_size_grow); } } } @@ -748,8 +748,8 @@ void StyleBoxFlat::draw(RID p_canvas_item, const Rect2 &p_rect) const { } } - Rect2 infill_inner_rect = infill_rect.grow_individual(-aa_border_width[MARGIN_LEFT], -aa_border_width[MARGIN_TOP], - -aa_border_width[MARGIN_RIGHT], -aa_border_width[MARGIN_BOTTOM]); + Rect2 infill_inner_rect = infill_rect.grow_individual(-aa_border_width[SIDE_LEFT], -aa_border_width[SIDE_TOP], + -aa_border_width[SIDE_RIGHT], -aa_border_width[SIDE_BOTTOM]); if (draw_center) { if (!blend_on && draw_border) { @@ -759,8 +759,8 @@ void StyleBoxFlat::draw(RID p_canvas_item, const Rect2 &p_rect) const { } if (!blend_on || !draw_border) { - Rect2 infill_aa_rect = infill_rect.grow_individual(aa_fill_width[MARGIN_LEFT], aa_fill_width[MARGIN_TOP], - aa_fill_width[MARGIN_RIGHT], aa_fill_width[MARGIN_BOTTOM]); + Rect2 infill_aa_rect = infill_rect.grow_individual(aa_fill_width[SIDE_LEFT], aa_fill_width[SIDE_TOP], + aa_fill_width[SIDE_RIGHT], aa_fill_width[SIDE_BOTTOM]); Color alpha_bg = Color(bg_color.r, bg_color.g, bg_color.b, 0); @@ -796,9 +796,9 @@ void StyleBoxFlat::draw(RID p_canvas_item, const Rect2 &p_rect) const { vs->canvas_item_add_triangle_array(p_canvas_item, indices, verts, colors, uvs); } -float StyleBoxFlat::get_style_margin(Margin p_margin) const { - ERR_FAIL_INDEX_V((int)p_margin, 4, 0.0); - return border_width[p_margin]; +float StyleBoxFlat::get_style_margin(Side p_side) const { + ERR_FAIL_INDEX_V((int)p_side, 4, 0.0); + return border_width[p_side]; } void StyleBoxFlat::_bind_methods() { @@ -854,10 +854,10 @@ void StyleBoxFlat::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::BOOL, "draw_center"), "set_draw_center", "is_draw_center_enabled"); ADD_GROUP("Border Width", "border_width_"); - ADD_PROPERTYI(PropertyInfo(Variant::INT, "border_width_left", PROPERTY_HINT_RANGE, "0,1024,1"), "set_border_width", "get_border_width", MARGIN_LEFT); - ADD_PROPERTYI(PropertyInfo(Variant::INT, "border_width_top", PROPERTY_HINT_RANGE, "0,1024,1"), "set_border_width", "get_border_width", MARGIN_TOP); - ADD_PROPERTYI(PropertyInfo(Variant::INT, "border_width_right", PROPERTY_HINT_RANGE, "0,1024,1"), "set_border_width", "get_border_width", MARGIN_RIGHT); - ADD_PROPERTYI(PropertyInfo(Variant::INT, "border_width_bottom", PROPERTY_HINT_RANGE, "0,1024,1"), "set_border_width", "get_border_width", MARGIN_BOTTOM); + ADD_PROPERTYI(PropertyInfo(Variant::INT, "border_width_left", PROPERTY_HINT_RANGE, "0,1024,1"), "set_border_width", "get_border_width", SIDE_LEFT); + ADD_PROPERTYI(PropertyInfo(Variant::INT, "border_width_top", PROPERTY_HINT_RANGE, "0,1024,1"), "set_border_width", "get_border_width", SIDE_TOP); + ADD_PROPERTYI(PropertyInfo(Variant::INT, "border_width_right", PROPERTY_HINT_RANGE, "0,1024,1"), "set_border_width", "get_border_width", SIDE_RIGHT); + ADD_PROPERTYI(PropertyInfo(Variant::INT, "border_width_bottom", PROPERTY_HINT_RANGE, "0,1024,1"), "set_border_width", "get_border_width", SIDE_BOTTOM); ADD_GROUP("Border", "border_"); ADD_PROPERTY(PropertyInfo(Variant::COLOR, "border_color"), "set_border_color", "get_border_color"); @@ -873,10 +873,10 @@ void StyleBoxFlat::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::INT, "corner_detail", PROPERTY_HINT_RANGE, "1,20,1"), "set_corner_detail", "get_corner_detail"); ADD_GROUP("Expand Margin", "expand_margin_"); - ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "expand_margin_left", PROPERTY_HINT_RANGE, "0,2048,1"), "set_expand_margin", "get_expand_margin", MARGIN_LEFT); - ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "expand_margin_right", PROPERTY_HINT_RANGE, "0,2048,1"), "set_expand_margin", "get_expand_margin", MARGIN_RIGHT); - ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "expand_margin_top", PROPERTY_HINT_RANGE, "0,2048,1"), "set_expand_margin", "get_expand_margin", MARGIN_TOP); - ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "expand_margin_bottom", PROPERTY_HINT_RANGE, "0,2048,1"), "set_expand_margin", "get_expand_margin", MARGIN_BOTTOM); + ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "expand_margin_left", PROPERTY_HINT_RANGE, "0,2048,1"), "set_expand_margin", "get_expand_margin", SIDE_LEFT); + ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "expand_margin_right", PROPERTY_HINT_RANGE, "0,2048,1"), "set_expand_margin", "get_expand_margin", SIDE_RIGHT); + ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "expand_margin_top", PROPERTY_HINT_RANGE, "0,2048,1"), "set_expand_margin", "get_expand_margin", SIDE_TOP); + ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "expand_margin_bottom", PROPERTY_HINT_RANGE, "0,2048,1"), "set_expand_margin", "get_expand_margin", SIDE_BOTTOM); ADD_GROUP("Shadow", "shadow_"); ADD_PROPERTY(PropertyInfo(Variant::COLOR, "shadow_color"), "set_shadow_color", "get_shadow_color"); @@ -985,8 +985,8 @@ void StyleBoxLine::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::BOOL, "vertical"), "set_vertical", "is_vertical"); } -float StyleBoxLine::get_style_margin(Margin p_margin) const { - ERR_FAIL_INDEX_V((int)p_margin, 4, thickness); +float StyleBoxLine::get_style_margin(Side p_side) const { + ERR_FAIL_INDEX_V((int)p_side, 4, thickness); return thickness; } diff --git a/scene/resources/style_box.h b/scene/resources/style_box.h index 7dd806e840..52d3160d36 100644 --- a/scene/resources/style_box.h +++ b/scene/resources/style_box.h @@ -44,15 +44,15 @@ class StyleBox : public Resource { float margin[4]; protected: - virtual float get_style_margin(Margin p_margin) const = 0; + virtual float get_style_margin(Side p_side) const = 0; static void _bind_methods(); public: virtual bool test_mask(const Point2 &p_point, const Rect2 &p_rect) const; - void set_default_margin(Margin p_margin, float p_value); - float get_default_margin(Margin p_margin) const; - float get_margin(Margin p_margin) const; + void set_default_margin(Side p_side, float p_value); + float get_default_margin(Side p_side) const; + float get_margin(Side p_side) const; virtual Size2 get_center_size() const; virtual Rect2 get_draw_rect(const Rect2 &p_rect) const; @@ -68,7 +68,7 @@ public: class StyleBoxEmpty : public StyleBox { GDCLASS(StyleBoxEmpty, StyleBox); - virtual float get_style_margin(Margin p_margin) const override { return 0; } + virtual float get_style_margin(Side p_side) const override { return 0; } public: virtual void draw(RID p_canvas_item, const Rect2 &p_rect) const override {} @@ -96,17 +96,17 @@ private: AxisStretchMode axis_v; protected: - virtual float get_style_margin(Margin p_margin) const override; + virtual float get_style_margin(Side p_side) const override; static void _bind_methods(); public: - void set_expand_margin_size(Margin p_expand_margin, float p_size); + void set_expand_margin_size(Side p_expand_side, float p_size); void set_expand_margin_size_all(float p_expand_margin_size); void set_expand_margin_size_individual(float p_left, float p_top, float p_right, float p_bottom); - float get_expand_margin_size(Margin p_expand_margin) const; + float get_expand_margin_size(Side p_expand_side) const; - void set_margin_size(Margin p_margin, float p_size); - float get_margin_size(Margin p_margin) const; + void set_margin_size(Side p_side, float p_size); + float get_margin_size(Side p_side) const; void set_region_rect(const Rect2 &p_region_rect); Rect2 get_region_rect() const; @@ -157,7 +157,7 @@ class StyleBoxFlat : public StyleBox { int aa_size; protected: - virtual float get_style_margin(Margin p_margin) const override; + virtual float get_style_margin(Side p_side) const override; static void _bind_methods(); public: @@ -174,8 +174,8 @@ public: void set_border_width_all(int p_size); int get_border_width_min() const; - void set_border_width(Margin p_margin, int p_width); - int get_border_width(Margin p_margin) const; + void set_border_width(Side p_side, int p_width); + int get_border_width(Side p_side) const; //blend void set_border_blend(bool p_blend); @@ -192,10 +192,10 @@ public: int get_corner_detail() const; //EXPANDS - void set_expand_margin_size(Margin p_expand_margin, float p_size); + void set_expand_margin_size(Side p_expand_side, float p_size); void set_expand_margin_size_all(float p_expand_margin_size); void set_expand_margin_size_individual(float p_left, float p_top, float p_right, float p_bottom); - float get_expand_margin_size(Margin p_expand_margin) const; + float get_expand_margin_size(Side p_expand_side) const; //DRAW CENTER void set_draw_center(bool p_enabled); @@ -237,7 +237,7 @@ class StyleBoxLine : public StyleBox { float grow_end; protected: - virtual float get_style_margin(Margin p_margin) const override; + virtual float get_style_margin(Side p_side) const override; static void _bind_methods(); public: |