diff options
author | Juan Linietsky <reduzio@gmail.com> | 2019-01-24 10:21:56 -0300 |
---|---|---|
committer | Juan Linietsky <reduzio@gmail.com> | 2019-01-24 10:22:41 -0300 |
commit | d0b736f7e54cb487db25ab39346ee0fc4b565aee (patch) | |
tree | bcf15f2e4829f9debd799668b51599663641b10d /scene | |
parent | 95bd60f71c5ab0fcd2aed69a1aaa88b3235e93e4 (diff) |
Ability to get the current canvas item being drawn from stylebox.
Diffstat (limited to 'scene')
-rw-r--r-- | scene/2d/canvas_item.cpp | 7 | ||||
-rw-r--r-- | scene/2d/canvas_item.h | 4 | ||||
-rw-r--r-- | scene/resources/style_box.cpp | 7 | ||||
-rw-r--r-- | scene/resources/style_box.h | 4 |
4 files changed, 22 insertions, 0 deletions
diff --git a/scene/2d/canvas_item.cpp b/scene/2d/canvas_item.cpp index 6ed008cf9c..dced688899 100644 --- a/scene/2d/canvas_item.cpp +++ b/scene/2d/canvas_item.cpp @@ -434,6 +434,11 @@ void CanvasItem::hide() { _change_notify("visible"); } +CanvasItem *CanvasItem::current_item_drawn = NULL; +CanvasItem *CanvasItem::get_current_item_drawn() { + return current_item_drawn; +} + void CanvasItem::_update_callback() { if (!is_inside_tree()) { @@ -449,11 +454,13 @@ void CanvasItem::_update_callback() { first_draw = false; } drawing = true; + current_item_drawn = this; notification(NOTIFICATION_DRAW); emit_signal(SceneStringNames::get_singleton()->draw); if (get_script_instance()) { get_script_instance()->call_multilevel_reversed(SceneStringNames::get_singleton()->_draw, NULL, 0); } + current_item_drawn = NULL; drawing = false; } //todo updating = false diff --git a/scene/2d/canvas_item.h b/scene/2d/canvas_item.h index a02e792cf2..bf7cfa8e75 100644 --- a/scene/2d/canvas_item.h +++ b/scene/2d/canvas_item.h @@ -222,6 +222,8 @@ private: void _set_on_top(bool p_on_top) { set_draw_behind_parent(!p_on_top); } bool _is_on_top() const { return !is_draw_behind_parent_enabled(); } + static CanvasItem *current_item_drawn; + protected: _FORCE_INLINE_ void _notify_transform() { if (!is_inside_tree()) return; @@ -324,6 +326,8 @@ public: void draw_set_transform(const Point2 &p_offset, float p_rot, const Size2 &p_scale); void draw_set_transform_matrix(const Transform2D &p_matrix); + static CanvasItem *get_current_item_drawn(); + /* RECT / TRANSFORM */ void set_as_toplevel(bool p_toplevel); diff --git a/scene/resources/style_box.cpp b/scene/resources/style_box.cpp index db7153e9ad..affe9a3e24 100644 --- a/scene/resources/style_box.cpp +++ b/scene/resources/style_box.cpp @@ -29,6 +29,8 @@ /*************************************************************************/ #include "style_box.h" +#include "scene/2d/canvas_item.h" + #include <limits.h> bool StyleBox::test_mask(const Point2 &p_point, const Rect2 &p_rect) const { @@ -54,6 +56,10 @@ float StyleBox::get_margin(Margin p_margin) const { return margin[p_margin]; } +CanvasItem *StyleBox::get_current_item_drawn() const { + return CanvasItem::get_current_item_drawn(); +} + Size2 StyleBox::get_minimum_size() const { return Size2(get_margin(MARGIN_LEFT) + get_margin(MARGIN_RIGHT), get_margin(MARGIN_TOP) + get_margin(MARGIN_BOTTOM)); @@ -83,6 +89,7 @@ void StyleBox::_bind_methods() { ClassDB::bind_method(D_METHOD("get_minimum_size"), &StyleBox::get_minimum_size); ClassDB::bind_method(D_METHOD("get_center_size"), &StyleBox::get_center_size); ClassDB::bind_method(D_METHOD("get_offset"), &StyleBox::get_offset); + ClassDB::bind_method(D_METHOD("get_current_item_drawn"), &StyleBox::get_current_item_drawn); ClassDB::bind_method(D_METHOD("draw", "canvas_item", "rect"), &StyleBox::draw); diff --git a/scene/resources/style_box.h b/scene/resources/style_box.h index 911a457990..9062270765 100644 --- a/scene/resources/style_box.h +++ b/scene/resources/style_box.h @@ -37,6 +37,8 @@ /** @author Juan Linietsky <reduzio@gmail.com> */ +class CanvasItem; + class StyleBox : public Resource { GDCLASS(StyleBox, Resource); @@ -58,6 +60,8 @@ public: virtual void draw(RID p_canvas_item, const Rect2 &p_rect) const = 0; + CanvasItem *get_current_item_drawn() const; + Size2 get_minimum_size() const; Point2 get_offset() const; |