summaryrefslogtreecommitdiff
path: root/scene/resources/style_box.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'scene/resources/style_box.cpp')
-rw-r--r--scene/resources/style_box.cpp63
1 files changed, 51 insertions, 12 deletions
diff --git a/scene/resources/style_box.cpp b/scene/resources/style_box.cpp
index 48efa242e9..f646e3667d 100644
--- a/scene/resources/style_box.cpp
+++ b/scene/resources/style_box.cpp
@@ -3,7 +3,7 @@
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
-/* http://www.godotengine.org */
+/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
@@ -191,6 +191,22 @@ void StyleBoxTexture::set_expand_margin_size(Margin p_expand_margin, float p_siz
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;
+ emit_changed();
+}
+
+void StyleBoxTexture::set_expand_margin_size_all(float p_expand_margin_size) {
+ for (int i = 0; i < 4; i++) {
+
+ expand_margin[i] = p_expand_margin_size;
+ }
+ emit_changed();
+}
+
float StyleBoxTexture::get_expand_margin_size(Margin p_expand_margin) const {
ERR_FAIL_INDEX_V(p_expand_margin, 4, 0);
@@ -257,6 +273,8 @@ void StyleBoxTexture::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_margin_size", "margin"), &StyleBoxTexture::get_margin_size);
ClassDB::bind_method(D_METHOD("set_expand_margin_size", "margin", "size"), &StyleBoxTexture::set_expand_margin_size);
+ ClassDB::bind_method(D_METHOD("set_expand_margin_all", "size"), &StyleBoxTexture::set_expand_margin_size_all);
+ ClassDB::bind_method(D_METHOD("set_expand_margin_individual", "size_left", "size_top", "size_right", "size_bottom"), &StyleBoxTexture::set_expand_margin_size_individual);
ClassDB::bind_method(D_METHOD("get_expand_margin_size", "margin"), &StyleBoxTexture::get_expand_margin_size);
ClassDB::bind_method(D_METHOD("set_region_rect", "region"), &StyleBoxTexture::set_region_rect);
@@ -296,9 +314,9 @@ void StyleBoxTexture::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::COLOR, "modulate_color"), "set_modulate", "get_modulate");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "draw_center"), "set_draw_center", "get_draw_center");
- BIND_CONSTANT(AXIS_STRETCH_MODE_STRETCH);
- BIND_CONSTANT(AXIS_STRETCH_MODE_TILE);
- BIND_CONSTANT(AXIS_STRETCH_MODE_TILE_FIT);
+ BIND_ENUM_CONSTANT(AXIS_STRETCH_MODE_STRETCH);
+ BIND_ENUM_CONSTANT(AXIS_STRETCH_MODE_TILE);
+ BIND_ENUM_CONSTANT(AXIS_STRETCH_MODE_TILE_FIT);
}
StyleBoxTexture::StyleBoxTexture() {
@@ -421,7 +439,25 @@ void StyleBoxFlat::set_expand_margin_size(Margin p_expand_margin, float p_size)
expand_margin[p_expand_margin] = 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;
+ emit_changed();
+}
+
+void StyleBoxFlat::set_expand_margin_size_all(float p_expand_margin_size) {
+ for (int i = 0; i < 4; i++) {
+
+ expand_margin[i] = p_expand_margin_size;
+ }
+ emit_changed();
+}
+
float StyleBoxFlat::get_expand_margin_size(Margin p_expand_margin) const {
+
return expand_margin[p_expand_margin];
}
void StyleBoxFlat::set_filled(bool p_filled) {
@@ -463,7 +499,7 @@ bool StyleBoxFlat::is_anti_aliased() const {
}
void StyleBoxFlat::set_aa_size(const int &p_aa_size) {
- aa_size = p_aa_size;
+ aa_size = CLAMP(p_aa_size, 1, 5);
emit_changed();
}
int StyleBoxFlat::get_aa_size() const {
@@ -471,7 +507,7 @@ int StyleBoxFlat::get_aa_size() const {
}
void StyleBoxFlat::set_corner_detail(const int &p_corner_detail) {
- corner_detail = p_corner_detail;
+ corner_detail = CLAMP(p_corner_detail, 1, 128);
emit_changed();
}
int StyleBoxFlat::get_corner_detail() const {
@@ -514,6 +550,7 @@ inline void draw_ring(Vector<Vector2> &verts, Vector<int> &indices, Vector<Color
if (!vert_offset) {
vert_offset = 0;
}
+ int adapted_corner_detail = (corner_radius[0] == 0 && corner_radius[1] == 0 && corner_radius[2] == 0 && corner_radius[3] == 0) ? 1 : corner_detail;
int rings = (border_width[0] == 0 && border_width[1] == 0 && border_width[2] == 0 && border_width[3] == 0) ? 1 : 2;
rings = 2;
@@ -540,7 +577,7 @@ inline void draw_ring(Vector<Vector2> &verts, Vector<int> &indices, Vector<Color
//calculate the vert array
for (int corner_index = 0; corner_index < 4; corner_index++) {
- for (int detail = 0; detail <= corner_detail; detail++) {
+ for (int detail = 0; detail <= adapted_corner_detail; detail++) {
for (int inner_outer = (2 - rings); inner_outer < 2; inner_outer++) {
float radius;
Color color;
@@ -554,8 +591,8 @@ inline void draw_ring(Vector<Vector2> &verts, Vector<int> &indices, Vector<Color
color = *outer_color;
corner_point = outer_points[corner_index];
}
- float x = radius * (float)cos((double)corner_index * Math_PI / 2.0 + (double)detail / (double)corner_detail * Math_PI / 2.0 + Math_PI) + corner_point.x;
- float y = radius * (float)sin((double)corner_index * Math_PI / 2.0 + (double)detail / (double)corner_detail * Math_PI / 2.0 + Math_PI) + corner_point.y;
+ float x = radius * (float)cos((double)corner_index * Math_PI / 2.0 + (double)detail / (double)adapted_corner_detail * Math_PI / 2.0 + Math_PI) + corner_point.x;
+ float y = radius * (float)sin((double)corner_index * Math_PI / 2.0 + (double)detail / (double)adapted_corner_detail * Math_PI / 2.0 + Math_PI) + corner_point.y;
verts.push_back(Vector2(x, y));
colors.push_back(color);
}
@@ -563,7 +600,7 @@ inline void draw_ring(Vector<Vector2> &verts, Vector<int> &indices, Vector<Color
}
if (rings == 2) {
- int vert_count = (corner_detail + 1) * 4 * rings;
+ int vert_count = (adapted_corner_detail + 1) * 4 * rings;
//fill the indices and the colors for the border
for (int i = 0; i < vert_count; i++) {
//poly 1
@@ -717,7 +754,7 @@ void StyleBoxFlat::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_bg_color"), &StyleBoxFlat::get_bg_color);
ClassDB::bind_method(D_METHOD("set_border_color", "color"), &StyleBoxFlat::set_border_color_all);
- ClassDB::bind_method(D_METHOD("get_border_color", "color"), &StyleBoxFlat::get_border_color_all);
+ ClassDB::bind_method(D_METHOD("get_border_color"), &StyleBoxFlat::get_border_color_all);
ClassDB::bind_method(D_METHOD("set_border_width_all", "width"), &StyleBoxFlat::set_border_width_all);
ClassDB::bind_method(D_METHOD("get_border_width_min"), &StyleBoxFlat::get_border_width_min);
@@ -735,6 +772,8 @@ void StyleBoxFlat::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_corner_radius", "corner"), &StyleBoxFlat::get_corner_radius);
ClassDB::bind_method(D_METHOD("set_expand_margin", "margin", "size"), &StyleBoxFlat::set_expand_margin_size);
+ ClassDB::bind_method(D_METHOD("set_expand_margin_all", "size"), &StyleBoxFlat::set_expand_margin_size_all);
+ ClassDB::bind_method(D_METHOD("set_expand_margin_individual", "size_left", "size_top", "size_right", "size_bottom"), &StyleBoxFlat::set_expand_margin_size_individual);
ClassDB::bind_method(D_METHOD("get_expand_margin", "margin"), &StyleBoxFlat::get_expand_margin_size);
ClassDB::bind_method(D_METHOD("set_filled", "filled"), &StyleBoxFlat::set_filled);
@@ -776,7 +815,7 @@ void StyleBoxFlat::_bind_methods() {
ADD_PROPERTYI(PropertyInfo(Variant::INT, "corner_radius_bottom_right", PROPERTY_HINT_RANGE, "0,1024,1"), "set_corner_radius", "get_corner_radius", CORNER_BOTTOM_RIGHT);
ADD_PROPERTYI(PropertyInfo(Variant::INT, "corner_radius_bottom_left", PROPERTY_HINT_RANGE, "0,1024,1"), "set_corner_radius", "get_corner_radius", CORNER_BOTTOM_LEFT);
- ADD_PROPERTY(PropertyInfo(Variant::INT, "corner_detail"), "set_corner_detail", "get_corner_detail");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "corner_detail", PROPERTY_HINT_RANGE, "1,128,1"), "set_corner_detail", "get_corner_detail");
ADD_GROUP("Expand Margin", "expand_margin_");
ADD_PROPERTYI(PropertyInfo(Variant::REAL, "expand_margin_left", PROPERTY_HINT_RANGE, "0,2048,1"), "set_expand_margin", "get_expand_margin", MARGIN_LEFT);