diff options
Diffstat (limited to 'scene/gui/patch_9_rect.cpp')
-rw-r--r-- | scene/gui/patch_9_rect.cpp | 88 |
1 files changed, 40 insertions, 48 deletions
diff --git a/scene/gui/patch_9_rect.cpp b/scene/gui/patch_9_rect.cpp index 6fb35f72e5..d0bd45e435 100644 --- a/scene/gui/patch_9_rect.cpp +++ b/scene/gui/patch_9_rect.cpp @@ -32,17 +32,17 @@ void NinePatchRect::_notification(int p_what) { - if (p_what==NOTIFICATION_DRAW) { + if (p_what == NOTIFICATION_DRAW) { if (texture.is_null()) return; - Size2 s=get_size(); + Size2 s = get_size(); RID ci = get_canvas_item(); - VS::get_singleton()->canvas_item_add_nine_patch(ci,Rect2(Point2(),s),region_rect,texture->get_rid(),Vector2(margin[MARGIN_LEFT],margin[MARGIN_TOP]),Vector2(margin[MARGIN_RIGHT],margin[MARGIN_BOTTOM]),VS::NINE_PATCH_STRETCH,VS::NINE_PATCH_STRETCH,draw_center); + VS::get_singleton()->canvas_item_add_nine_patch(ci, Rect2(Point2(), s), region_rect, texture->get_rid(), Vector2(margin[MARGIN_LEFT], margin[MARGIN_TOP]), Vector2(margin[MARGIN_RIGHT], margin[MARGIN_BOTTOM]), VS::NINE_PATCH_STRETCH, VS::NINE_PATCH_STRETCH, draw_center); //draw_texture_rect(texture,Rect2(Point2(),s),false,modulate); -/* + /* Vector<Point2> points; points.resize(4); points[0]=Point2(0,0); @@ -63,40 +63,37 @@ void NinePatchRect::_notification(int p_what) { Size2 NinePatchRect::get_minimum_size() const { - return Size2(margin[MARGIN_LEFT]+margin[MARGIN_RIGHT],margin[MARGIN_TOP]+margin[MARGIN_BOTTOM]); + return Size2(margin[MARGIN_LEFT] + margin[MARGIN_RIGHT], margin[MARGIN_TOP] + margin[MARGIN_BOTTOM]); } void NinePatchRect::_bind_methods() { - - ClassDB::bind_method(D_METHOD("set_texture","texture"), & NinePatchRect::set_texture ); - ClassDB::bind_method(D_METHOD("get_texture"), & NinePatchRect::get_texture ); - ClassDB::bind_method(D_METHOD("set_patch_margin","margin","value"), & NinePatchRect::set_patch_margin ); - ClassDB::bind_method(D_METHOD("get_patch_margin","margin"), & NinePatchRect::get_patch_margin ); - ClassDB::bind_method(D_METHOD("set_region_rect","rect"),&NinePatchRect::set_region_rect); - ClassDB::bind_method(D_METHOD("get_region_rect"),&NinePatchRect::get_region_rect); - ClassDB::bind_method(D_METHOD("set_draw_center","draw_center"), & NinePatchRect::set_draw_center ); - ClassDB::bind_method(D_METHOD("get_draw_center"), & NinePatchRect::get_draw_center ); + ClassDB::bind_method(D_METHOD("set_texture", "texture"), &NinePatchRect::set_texture); + ClassDB::bind_method(D_METHOD("get_texture"), &NinePatchRect::get_texture); + ClassDB::bind_method(D_METHOD("set_patch_margin", "margin", "value"), &NinePatchRect::set_patch_margin); + ClassDB::bind_method(D_METHOD("get_patch_margin", "margin"), &NinePatchRect::get_patch_margin); + ClassDB::bind_method(D_METHOD("set_region_rect", "rect"), &NinePatchRect::set_region_rect); + ClassDB::bind_method(D_METHOD("get_region_rect"), &NinePatchRect::get_region_rect); + ClassDB::bind_method(D_METHOD("set_draw_center", "draw_center"), &NinePatchRect::set_draw_center); + ClassDB::bind_method(D_METHOD("get_draw_center"), &NinePatchRect::get_draw_center); ADD_SIGNAL(MethodInfo("texture_changed")); - ADD_PROPERTYNZ( PropertyInfo( Variant::OBJECT, "texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture"), "set_texture","get_texture") ; - ADD_PROPERTYNO( PropertyInfo( Variant::BOOL, "draw_center"), "set_draw_center","get_draw_center") ; - ADD_PROPERTYNZ( PropertyInfo( Variant::RECT2, "region_rect"), "set_region_rect","get_region_rect"); - - ADD_GROUP("Patch Margin","patch_margin_"); - ADD_PROPERTYINZ( PropertyInfo( Variant::INT, "patch_margin_left",PROPERTY_HINT_RANGE,"0,16384,1"), "set_patch_margin","get_patch_margin",MARGIN_LEFT ); - ADD_PROPERTYINZ( PropertyInfo( Variant::INT, "patch_margin_top",PROPERTY_HINT_RANGE,"0,16384,1"), "set_patch_margin","get_patch_margin",MARGIN_TOP ); - ADD_PROPERTYINZ( PropertyInfo( Variant::INT, "patch_margin_right",PROPERTY_HINT_RANGE,"0,16384,1"), "set_patch_margin","get_patch_margin",MARGIN_RIGHT ); - ADD_PROPERTYINZ( PropertyInfo( Variant::INT, "patch_margin_bottom",PROPERTY_HINT_RANGE,"0,16384,1"), "set_patch_margin","get_patch_margin",MARGIN_BOTTOM ); + ADD_PROPERTYNZ(PropertyInfo(Variant::OBJECT, "texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture"), "set_texture", "get_texture"); + ADD_PROPERTYNO(PropertyInfo(Variant::BOOL, "draw_center"), "set_draw_center", "get_draw_center"); + ADD_PROPERTYNZ(PropertyInfo(Variant::RECT2, "region_rect"), "set_region_rect", "get_region_rect"); + ADD_GROUP("Patch Margin", "patch_margin_"); + ADD_PROPERTYINZ(PropertyInfo(Variant::INT, "patch_margin_left", PROPERTY_HINT_RANGE, "0,16384,1"), "set_patch_margin", "get_patch_margin", MARGIN_LEFT); + ADD_PROPERTYINZ(PropertyInfo(Variant::INT, "patch_margin_top", PROPERTY_HINT_RANGE, "0,16384,1"), "set_patch_margin", "get_patch_margin", MARGIN_TOP); + ADD_PROPERTYINZ(PropertyInfo(Variant::INT, "patch_margin_right", PROPERTY_HINT_RANGE, "0,16384,1"), "set_patch_margin", "get_patch_margin", MARGIN_RIGHT); + ADD_PROPERTYINZ(PropertyInfo(Variant::INT, "patch_margin_bottom", PROPERTY_HINT_RANGE, "0,16384,1"), "set_patch_margin", "get_patch_margin", MARGIN_BOTTOM); } +void NinePatchRect::set_texture(const Ref<Texture> &p_tex) { -void NinePatchRect::set_texture(const Ref<Texture>& p_tex) { - - if (texture==p_tex) + if (texture == p_tex) return; - texture=p_tex; + texture = p_tex; update(); /* if (texture.is_valid()) @@ -111,12 +108,10 @@ Ref<Texture> NinePatchRect::get_texture() const { return texture; } +void NinePatchRect::set_patch_margin(Margin p_margin, int p_size) { - -void NinePatchRect::set_patch_margin(Margin p_margin,int p_size) { - - ERR_FAIL_INDEX(p_margin,4); - margin[p_margin]=p_size; + ERR_FAIL_INDEX(p_margin, 4); + margin[p_margin] = p_size; update(); minimum_size_changed(); switch (p_margin) { @@ -135,18 +130,18 @@ void NinePatchRect::set_patch_margin(Margin p_margin,int p_size) { } } -int NinePatchRect::get_patch_margin(Margin p_margin) const{ +int NinePatchRect::get_patch_margin(Margin p_margin) const { - ERR_FAIL_INDEX_V(p_margin,4,0); + ERR_FAIL_INDEX_V(p_margin, 4, 0); return margin[p_margin]; } -void NinePatchRect::set_region_rect(const Rect2& p_region_rect) { +void NinePatchRect::set_region_rect(const Rect2 &p_region_rect) { - if (region_rect==p_region_rect) + if (region_rect == p_region_rect) return; - region_rect=p_region_rect; + region_rect = p_region_rect; item_rect_changed(); _change_notify("region_rect"); @@ -159,28 +154,25 @@ Rect2 NinePatchRect::get_region_rect() const { void NinePatchRect::set_draw_center(bool p_draw) { - draw_center=p_draw; + draw_center = p_draw; update(); } -bool NinePatchRect::get_draw_center() const{ +bool NinePatchRect::get_draw_center() const { return draw_center; } NinePatchRect::NinePatchRect() { - - margin[MARGIN_LEFT]=0; - margin[MARGIN_RIGHT]=0; - margin[MARGIN_BOTTOM]=0; - margin[MARGIN_TOP]=0; + margin[MARGIN_LEFT] = 0; + margin[MARGIN_RIGHT] = 0; + margin[MARGIN_BOTTOM] = 0; + margin[MARGIN_TOP] = 0; set_mouse_filter(MOUSE_FILTER_IGNORE); - draw_center=true; + draw_center = true; } - -NinePatchRect::~NinePatchRect() -{ +NinePatchRect::~NinePatchRect() { } |