diff options
Diffstat (limited to 'scene/resources/style_box.cpp')
-rw-r--r-- | scene/resources/style_box.cpp | 126 |
1 files changed, 1 insertions, 125 deletions
diff --git a/scene/resources/style_box.cpp b/scene/resources/style_box.cpp index 1c708f9c11..cdb663b8f1 100644 --- a/scene/resources/style_box.cpp +++ b/scene/resources/style_box.cpp @@ -141,7 +141,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,region_rect,texture->get_rid(),Vector2(margin[MARGIN_LEFT],margin[MARGIN_TOP]),Vector2(margin[MARGIN_RIGHT],margin[MARGIN_BOTTOM]),draw_center,modulate); + VisualServer::get_singleton()->canvas_item_add_nine_patch( p_canvas_item,r,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,modulate); } void StyleBoxTexture::set_draw_center(bool p_draw) { @@ -423,127 +423,3 @@ StyleBoxFlat::~StyleBoxFlat() { } -//////////////// - - - -void StyleBoxImageMask::_bind_methods() { - - ObjectTypeDB::bind_method(_MD("set_image","image"),&StyleBoxImageMask::set_image); - ObjectTypeDB::bind_method(_MD("get_image"),&StyleBoxImageMask::get_image); - ObjectTypeDB::bind_method(_MD("set_expand","expand"),&StyleBoxImageMask::set_expand); - ObjectTypeDB::bind_method(_MD("get_expand"),&StyleBoxImageMask::get_expand); - ObjectTypeDB::bind_method(_MD("set_expand_margin_size","margin","size"),&StyleBoxImageMask::set_expand_margin_size); - ObjectTypeDB::bind_method(_MD("get_expand_margin_size","margin"),&StyleBoxImageMask::get_expand_margin_size); - - ADD_PROPERTY( PropertyInfo(Variant::IMAGE, "image"), _SCS("set_image"), _SCS("get_image")); - ADD_PROPERTY( PropertyInfo(Variant::BOOL, "expand"), _SCS("set_expand"), _SCS("get_expand")); - ADD_PROPERTYI( PropertyInfo( Variant::REAL, "expand_margin/left", PROPERTY_HINT_RANGE,"0,2048,1" ), _SCS("set_expand_margin_size"),_SCS("get_expand_margin_size"), MARGIN_LEFT ); - ADD_PROPERTYI( PropertyInfo( Variant::REAL, "expand_margin/right", PROPERTY_HINT_RANGE,"0,2048,1" ), _SCS("set_expand_margin_size"),_SCS("get_expand_margin_size"), MARGIN_RIGHT ); - ADD_PROPERTYI( PropertyInfo( Variant::REAL, "expand_margin/top", PROPERTY_HINT_RANGE,"0,2048,1" ), _SCS("set_expand_margin_size"),_SCS("get_expand_margin_size"), MARGIN_TOP ); - ADD_PROPERTYI( PropertyInfo( Variant::REAL, "expand_margin/bottom", PROPERTY_HINT_RANGE,"0,2048,1" ), _SCS("set_expand_margin_size"),_SCS("get_expand_margin_size"), MARGIN_BOTTOM ); - -} - - -bool StyleBoxImageMask::test_mask(const Point2& p_point, const Rect2& p_rect) const { - - if (image.empty()) - return false; - if (p_rect.size.x<1) - return false; - if (p_rect.size.y<1) - return false; - - Size2i imgsize(image.get_width(),image.get_height()); - if (imgsize.x<=0 || imgsize.y<=0) - return false; - - Point2i img_expand_size( imgsize.x - expand_margin[MARGIN_LEFT] - expand_margin[MARGIN_RIGHT], imgsize.y - expand_margin[MARGIN_TOP] - expand_margin[MARGIN_BOTTOM]); - Point2i rect_expand_size( p_rect.size.x - expand_margin[MARGIN_LEFT] - expand_margin[MARGIN_RIGHT], p_rect.size.y - expand_margin[MARGIN_TOP] - expand_margin[MARGIN_BOTTOM]); - if (rect_expand_size.x<1) - rect_expand_size.x=1; - if (rect_expand_size.y<1) - rect_expand_size.y=1; - - - Point2i click_pos; - - - //treat x - - if (p_point.x<p_rect.pos.x) - click_pos.x=0; - else if (expand) { - - if (p_point.x>=p_rect.pos.x+p_rect.size.x) - click_pos.x=imgsize.x-1; - else if ((p_point.x-p_rect.pos.x)<expand_margin[MARGIN_LEFT]) - click_pos.x=p_point.x; - else if ((p_point.x-(p_rect.pos.x+p_rect.size.x))<expand_margin[MARGIN_RIGHT]) - click_pos.x=imgsize.x-(p_point.x-(p_rect.pos.x+p_rect.size.x)); - else //expand - click_pos.x=(p_point.x-p_rect.pos.x-expand_margin[MARGIN_LEFT])*img_expand_size.x/rect_expand_size.x; - } else if ((p_point.x-p_rect.pos.x) > imgsize.x) - click_pos.x=imgsize.x; - - //treat y - - if (p_point.y<p_rect.pos.y) - click_pos.y=0; - else if (expand) { - - if (p_point.y>=p_rect.pos.y+p_rect.size.y) - click_pos.y=imgsize.y-1; - else if ((p_point.y-p_rect.pos.y)<expand_margin[MARGIN_TOP]) - click_pos.y=p_point.y; - else if ((p_point.y-(p_rect.pos.y+p_rect.size.y))<expand_margin[MARGIN_BOTTOM]) - click_pos.y=imgsize.y-(p_point.y-(p_rect.pos.y+p_rect.size.y)); - else //expand - click_pos.y=(p_point.y-p_rect.pos.y-expand_margin[MARGIN_TOP])*img_expand_size.y/rect_expand_size.y; - } else if ((p_point.y-p_rect.pos.y) > imgsize.y) - click_pos.y=imgsize.y; - - return image.get_pixel(click_pos.x,click_pos.y).gray()>0.5; - -} - - -void StyleBoxImageMask::set_image(const Image& p_image) { - - image=p_image; -} -Image StyleBoxImageMask::get_image() const { - - return image; -} - - -void StyleBoxImageMask::set_expand(bool p_expand) { - - expand=p_expand; -} -bool StyleBoxImageMask::get_expand() const { - - return expand; -} -void StyleBoxImageMask::set_expand_margin_size(Margin p_expand_margin,float p_size) { - - ERR_FAIL_INDEX(p_expand_margin,4); - expand_margin[p_expand_margin]=p_size; -} - - -float StyleBoxImageMask::get_expand_margin_size(Margin p_expand_margin) const { - - ERR_FAIL_INDEX_V(p_expand_margin,4,0); - return expand_margin[p_expand_margin]; -} - -StyleBoxImageMask::StyleBoxImageMask() { - - for (int i=0;i<4;i++) { - expand_margin[i]=0; - } - expand=true; -} |