summaryrefslogtreecommitdiff
path: root/scene
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <rverschelde@gmail.com>2019-11-25 14:25:39 +0100
committerGitHub <noreply@github.com>2019-11-25 14:25:39 +0100
commitf6e57517679d05d8ac43eee51ddf0b4f1de3859c (patch)
tree89230ced99f6c41cebb3da8539b8158f85567634 /scene
parent397fc4b9a65ca21419ab2e9395260cf4699b3dcb (diff)
parent1120de862d131160cf43e2fdb7f736b47bc77550 (diff)
Merge pull request #33860 from nekomatata/stylebox-preview-shadow
StyleBox preview adjusted to fit all drawn content
Diffstat (limited to 'scene')
-rw-r--r--scene/resources/style_box.cpp21
-rw-r--r--scene/resources/style_box.h3
2 files changed, 24 insertions, 0 deletions
diff --git a/scene/resources/style_box.cpp b/scene/resources/style_box.cpp
index d56360f918..f26b57b572 100644
--- a/scene/resources/style_box.cpp
+++ b/scene/resources/style_box.cpp
@@ -81,6 +81,10 @@ Size2 StyleBox::get_center_size() const {
return Size2();
}
+Rect2 StyleBox::get_draw_rect(const Rect2 &p_rect) const {
+ return p_rect;
+}
+
void StyleBox::_bind_methods() {
ClassDB::bind_method(D_METHOD("test_mask", "point", "rect"), &StyleBox::test_mask);
@@ -175,6 +179,10 @@ float StyleBoxTexture::get_style_margin(Margin p_margin) const {
return margin[p_margin];
}
+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]);
+}
+
void StyleBoxTexture::draw(RID p_canvas_item, const Rect2 &p_rect) const {
if (texture.is_null())
return;
@@ -685,6 +693,19 @@ inline void adapt_values(int p_index_a, int p_index_b, int *adapted_values, cons
adapted_values[p_index_a] = MIN(p_max_a, adapted_values[p_index_a]);
adapted_values[p_index_b] = MIN(p_max_b, adapted_values[p_index_b]);
}
+
+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]);
+
+ if (shadow_size > 0) {
+ Rect2 shadow_rect = draw_rect.grow(shadow_size);
+ shadow_rect.position += shadow_offset;
+ draw_rect = draw_rect.merge(shadow_rect);
+ }
+
+ return draw_rect;
+}
+
void StyleBoxFlat::draw(RID p_canvas_item, const Rect2 &p_rect) const {
//PREPARATIONS
diff --git a/scene/resources/style_box.h b/scene/resources/style_box.h
index d02e107480..ec07b5e885 100644
--- a/scene/resources/style_box.h
+++ b/scene/resources/style_box.h
@@ -56,6 +56,7 @@ public:
float get_margin(Margin p_margin) const;
virtual Size2 get_center_size() const;
+ virtual Rect2 get_draw_rect(const Rect2 &p_rect) const;
virtual void draw(RID p_canvas_item, const Rect2 &p_rect) const = 0;
CanvasItem *get_current_item_drawn() const;
@@ -133,6 +134,7 @@ public:
void set_modulate(const Color &p_modulate);
Color get_modulate() const;
+ virtual Rect2 get_draw_rect(const Rect2 &p_rect) const;
virtual void draw(RID p_canvas_item, const Rect2 &p_rect) const;
StyleBoxTexture();
@@ -227,6 +229,7 @@ public:
virtual Size2 get_center_size() const;
+ virtual Rect2 get_draw_rect(const Rect2 &p_rect) const;
virtual void draw(RID p_canvas_item, const Rect2 &p_rect) const;
StyleBoxFlat();