Ability to get the current canvas item being drawn from stylebox.

This commit is contained in:
Juan Linietsky 2019-01-24 10:21:56 -03:00
parent 95bd60f71c
commit d0b736f7e5
4 changed files with 22 additions and 0 deletions

View File

@ -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

View File

@ -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);

View File

@ -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);

View File

@ -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;