summaryrefslogtreecommitdiff
path: root/scene
diff options
context:
space:
mode:
authorJuan Linietsky <reduzio@gmail.com>2016-06-06 20:15:33 -0300
committerJuan Linietsky <reduzio@gmail.com>2016-06-06 20:15:33 -0300
commitbe830d10c25e0699d516cbb0a4e8124754e5ff51 (patch)
tree2a9eb86c55957ce9c236a2939ae5544ce6e9e8d0 /scene
parent7499fa4507919eb0f1802f01d012d9b88fe714c7 (diff)
parent5894060abb35713d744b6a79e7112d38926ba767 (diff)
Merge pull request #5026 from Geequlim/patch9frame-extension
Enhanced Patch9Frame
Diffstat (limited to 'scene')
-rw-r--r--scene/gui/patch_9_frame.cpp38
-rw-r--r--scene/gui/patch_9_frame.h4
-rw-r--r--scene/resources/style_box.cpp21
-rw-r--r--scene/resources/style_box.h4
4 files changed, 61 insertions, 6 deletions
diff --git a/scene/gui/patch_9_frame.cpp b/scene/gui/patch_9_frame.cpp
index b6e261714c..3ecee7328b 100644
--- a/scene/gui/patch_9_frame.cpp
+++ b/scene/gui/patch_9_frame.cpp
@@ -9,10 +9,9 @@ void Patch9Frame::_notification(int p_what) {
if (texture.is_null())
return;
-
Size2 s=get_size();
RID ci = get_canvas_item();
- VS::get_singleton()->canvas_item_add_style_box(ci,Rect2(Point2(),s),texture->get_rid(),Vector2(margin[MARGIN_LEFT],margin[MARGIN_TOP]),Vector2(margin[MARGIN_RIGHT],margin[MARGIN_BOTTOM]),draw_center,modulate);
+ VS::get_singleton()->canvas_item_add_style_box(ci,Rect2(Point2(),s),region_rect,texture->get_rid(),Vector2(margin[MARGIN_LEFT],margin[MARGIN_TOP]),Vector2(margin[MARGIN_RIGHT],margin[MARGIN_BOTTOM]),draw_center,modulate);
// draw_texture_rect(texture,Rect2(Point2(),s),false,modulate);
/*
@@ -47,12 +46,15 @@ void Patch9Frame::_bind_methods() {
ObjectTypeDB::bind_method(_MD("get_modulate"), & Patch9Frame::get_modulate );
ObjectTypeDB::bind_method(_MD("set_patch_margin","margin","value"), & Patch9Frame::set_patch_margin );
ObjectTypeDB::bind_method(_MD("get_patch_margin","margin"), & Patch9Frame::get_patch_margin );
+ ObjectTypeDB::bind_method(_MD("set_region_rect","rect"),&Patch9Frame::set_region_rect);
+ ObjectTypeDB::bind_method(_MD("get_region_rect"),&Patch9Frame::get_region_rect);
ObjectTypeDB::bind_method(_MD("set_draw_center","draw_center"), & Patch9Frame::set_draw_center );
ObjectTypeDB::bind_method(_MD("get_draw_center"), & Patch9Frame::get_draw_center );
ADD_PROPERTYNZ( PropertyInfo( Variant::OBJECT, "texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture"), _SCS("set_texture"),_SCS("get_texture") );
ADD_PROPERTYNO( PropertyInfo( Variant::COLOR, "modulate"), _SCS("set_modulate"),_SCS("get_modulate") );
ADD_PROPERTYNO( PropertyInfo( Variant::BOOL, "draw_center"), _SCS("set_draw_center"),_SCS("get_draw_center") );
+ ADD_PROPERTYNZ( PropertyInfo( Variant::RECT2, "region_rect"), _SCS("set_region_rect"),_SCS("get_region_rect"));
ADD_PROPERTYINZ( PropertyInfo( Variant::INT, "patch_margin/left",PROPERTY_HINT_RANGE,"0,16384,1"), _SCS("set_patch_margin"),_SCS("get_patch_margin"),MARGIN_LEFT );
ADD_PROPERTYINZ( PropertyInfo( Variant::INT, "patch_margin/top",PROPERTY_HINT_RANGE,"0,16384,1"), _SCS("set_patch_margin"),_SCS("get_patch_margin"),MARGIN_TOP );
ADD_PROPERTYINZ( PropertyInfo( Variant::INT, "patch_margin/right",PROPERTY_HINT_RANGE,"0,16384,1"), _SCS("set_patch_margin"),_SCS("get_patch_margin"),MARGIN_RIGHT );
@@ -93,6 +95,20 @@ void Patch9Frame::set_patch_margin(Margin p_margin,int p_size) {
margin[p_margin]=p_size;
update();
minimum_size_changed();
+ switch (p_margin) {
+ case MARGIN_LEFT:
+ _change_notify("patch_margin/left");
+ break;
+ case MARGIN_TOP:
+ _change_notify("patch_margin/top");
+ break;
+ case MARGIN_RIGHT:
+ _change_notify("patch_margin/right");
+ break;
+ case MARGIN_BOTTOM:
+ _change_notify("patch_margin/bottom");
+ break;
+ }
}
int Patch9Frame::get_patch_margin(Margin p_margin) const{
@@ -101,6 +117,22 @@ int Patch9Frame::get_patch_margin(Margin p_margin) const{
return margin[p_margin];
}
+void Patch9Frame::set_region_rect(const Rect2& p_region_rect) {
+
+ if (region_rect==p_region_rect)
+ return;
+
+ region_rect=p_region_rect;
+
+ item_rect_changed();
+ _change_notify("region_rect");
+}
+
+Rect2 Patch9Frame::get_region_rect() const {
+
+ return region_rect;
+}
+
void Patch9Frame::set_draw_center(bool p_draw) {
draw_center=p_draw;
@@ -128,5 +160,3 @@ Patch9Frame::Patch9Frame() {
Patch9Frame::~Patch9Frame()
{
}
-
-
diff --git a/scene/gui/patch_9_frame.h b/scene/gui/patch_9_frame.h
index 562a5b1d77..52e2324c3d 100644
--- a/scene/gui/patch_9_frame.h
+++ b/scene/gui/patch_9_frame.h
@@ -11,6 +11,7 @@ class Patch9Frame : public Control {
bool draw_center;
int margin[4];
+ Rect2 region_rect;
Color modulate;
Ref<Texture> texture;
protected:
@@ -30,6 +31,9 @@ public:
void set_patch_margin(Margin p_margin,int p_size);
int get_patch_margin(Margin p_margin) const;
+ void set_region_rect(const Rect2& p_region_rect);
+ Rect2 get_region_rect() const;
+
void set_draw_center(bool p_enable);
bool get_draw_center() const;
diff --git a/scene/resources/style_box.cpp b/scene/resources/style_box.cpp
index 75e38f9701..a61ffe8e97 100644
--- a/scene/resources/style_box.cpp
+++ b/scene/resources/style_box.cpp
@@ -138,7 +138,7 @@ void StyleBoxTexture::draw(RID p_canvas_item,const Rect2& p_rect) const {
r.pos.y-=expand_margin[MARGIN_TOP];
r.size.x+=expand_margin[MARGIN_LEFT]+expand_margin[MARGIN_RIGHT];
r.size.y+=expand_margin[MARGIN_TOP]+expand_margin[MARGIN_BOTTOM];
- VisualServer::get_singleton()->canvas_item_add_style_box( p_canvas_item,r,texture->get_rid(),Vector2(margin[MARGIN_LEFT],margin[MARGIN_TOP]),Vector2(margin[MARGIN_RIGHT],margin[MARGIN_BOTTOM]),draw_center);
+ VisualServer::get_singleton()->canvas_item_add_style_box( p_canvas_item,r,region_rect,texture->get_rid(),Vector2(margin[MARGIN_LEFT],margin[MARGIN_TOP]),Vector2(margin[MARGIN_RIGHT],margin[MARGIN_BOTTOM]),draw_center);
}
void StyleBoxTexture::set_draw_center(bool p_draw) {
@@ -175,6 +175,20 @@ float StyleBoxTexture::get_expand_margin_size(Margin p_expand_margin) const {
return expand_margin[p_expand_margin];
}
+void StyleBoxTexture::set_region_rect(const Rect2& p_region_rect) {
+
+ if (region_rect==p_region_rect)
+ return;
+
+ region_rect=p_region_rect;
+ emit_changed();
+}
+
+Rect2 StyleBoxTexture::get_region_rect() const {
+
+ return region_rect;
+}
+
void StyleBoxTexture::_bind_methods() {
@@ -187,10 +201,14 @@ void StyleBoxTexture::_bind_methods() {
ObjectTypeDB::bind_method(_MD("set_expand_margin_size","margin","size"),&StyleBoxTexture::set_expand_margin_size);
ObjectTypeDB::bind_method(_MD("get_expand_margin_size","margin"),&StyleBoxTexture::get_expand_margin_size);
+ ObjectTypeDB::bind_method(_MD("set_region_rect","region"),&StyleBoxTexture::set_region_rect);
+ ObjectTypeDB::bind_method(_MD("get_region_rect"),&StyleBoxTexture::get_region_rect);
+
ObjectTypeDB::bind_method(_MD("set_draw_center","enable"),&StyleBoxTexture::set_draw_center);
ObjectTypeDB::bind_method(_MD("get_draw_center"),&StyleBoxTexture::get_draw_center);
ADD_PROPERTY( PropertyInfo( Variant::OBJECT, "texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture" ), _SCS("set_texture"),_SCS("get_texture") );
+ ADD_PROPERTYNZ( PropertyInfo( Variant::RECT2, "region_rect"), _SCS("set_region_rect"),_SCS("get_region_rect"));
ADD_PROPERTYI( PropertyInfo( Variant::REAL, "margin/left", PROPERTY_HINT_RANGE,"0,2048,1" ), _SCS("set_margin_size"),_SCS("get_margin_size"), MARGIN_LEFT );
ADD_PROPERTYI( PropertyInfo( Variant::REAL, "margin/right", PROPERTY_HINT_RANGE,"0,2048,1" ), _SCS("set_margin_size"),_SCS("get_margin_size"), MARGIN_RIGHT );
ADD_PROPERTYI( PropertyInfo( Variant::REAL, "margin/top", PROPERTY_HINT_RANGE,"0,2048,1" ), _SCS("set_margin_size"),_SCS("get_margin_size"), MARGIN_TOP);
@@ -505,4 +523,3 @@ StyleBoxImageMask::StyleBoxImageMask() {
}
expand=true;
}
-
diff --git a/scene/resources/style_box.h b/scene/resources/style_box.h
index 02d79bc2ac..98aaee754b 100644
--- a/scene/resources/style_box.h
+++ b/scene/resources/style_box.h
@@ -81,6 +81,7 @@ class StyleBoxTexture : public StyleBox {
float expand_margin[4];
float margin[4];
+ Rect2 region_rect;
Ref<Texture> texture;
bool draw_center;
@@ -98,6 +99,9 @@ public:
void set_margin_size(Margin p_margin,float p_size);
float get_margin_size(Margin p_margin) const;
+ void set_region_rect(const Rect2& p_region_rect);
+ Rect2 get_region_rect() const;
+
void set_texture(RES p_texture);
RES get_texture() const;