-ability to scale and modulate texturebutton, closes #818

-fixed bug in ordering of modal subwindows, closes #1001
This commit is contained in:
Juan Linietsky 2015-01-03 00:23:14 -03:00
parent d722537154
commit 0df45672e7
3 changed files with 77 additions and 16 deletions

View File

@ -768,6 +768,12 @@ Control* Control::_find_control_at_pos(CanvasItem* p_node,const Point2& p_global
c->_window_sort_subwindows(); // sort them
int idx=0;
for (List<Control*>::Element *E=c->window->subwindows.front();E;E=E->next()) {
if (!E->get()->is_visible())
continue;
}
for (List<Control*>::Element *E=c->window->subwindows.back();E;E=E->prev()) {
Control *sw = E->get();
@ -1126,6 +1132,7 @@ void Control::_window_input_event(InputEvent p_event) {
over = _find_control_at_pos(this,pos,parent_xform,window->focus_inv_xform);
}
if (window->drag_data.get_type()==Variant::NIL && over && !window->modal_stack.empty()) {
Control *top = window->modal_stack.back()->get();
@ -2267,6 +2274,7 @@ void Control::_window_sort_subwindows() {
return;
window->modal_stack.sort_custom<CComparator>();
window->subwindows.sort_custom<CComparator>();
window->subwindow_order_dirty=false;
}

View File

@ -31,28 +31,33 @@
Size2 TextureButton::get_minimum_size() const {
Size2 rscale;
if (normal.is_null()) {
if (pressed.is_null()) {
if (hover.is_null())
if (click_mask.is_null())
return Size2();
rscale= Size2();
else
return click_mask->get_size();
rscale= click_mask->get_size();
else
return hover->get_size();
rscale= hover->get_size();
} else
return pressed->get_size();
rscale= pressed->get_size()*scale;
} else
return normal->get_size();
rscale= normal->get_size();
return rscale*scale;
}
bool TextureButton::has_point(const Point2& p_point) const {
Point2 ppos = p_point/scale;
if (click_mask.is_valid()) {
Point2i p =p_point;
Point2i p =ppos;
if (p.x<0 || p.x>=click_mask->get_size().width || p.y<0 || p.y>=click_mask->get_size().height)
return false;
@ -71,46 +76,57 @@ void TextureButton::_notification(int p_what) {
DrawMode draw_mode = get_draw_mode();
// if (normal.is_null())
// break;
Ref<Texture> texdraw;
switch (draw_mode) {
case DRAW_NORMAL: {
if (normal.is_valid())
normal->draw(canvas_item,Point2());
texdraw=normal;
} break;
case DRAW_PRESSED: {
if (pressed.is_null()) {
if (hover.is_null()) {
if (normal.is_valid())
normal->draw(canvas_item,Point2());
texdraw=normal;
} else
hover->draw(canvas_item,Point2());
texdraw=hover;
} else
pressed->draw(canvas_item,Point2());
texdraw=pressed;
} break;
case DRAW_HOVER: {
if (hover.is_null()) {
if (pressed.is_valid() && is_pressed())
pressed->draw(canvas_item,Point2());
texdraw=pressed;
else if (normal.is_valid())
normal->draw(canvas_item,Point2());
texdraw=normal;
} else
hover->draw(canvas_item,Point2());
texdraw=hover;
} break;
case DRAW_DISABLED: {
if (disabled.is_null()) {
if (normal.is_valid())
normal->draw(canvas_item,Point2());
texdraw=normal;
} else
disabled->draw(canvas_item,Point2());
texdraw=disabled;
} break;
}
if (texdraw.is_valid()) {
Rect2 drect(Point2(),texdraw->get_size()*scale);
draw_texture_rect(texdraw,drect,false,modulate);
}
if (has_focus() && focused.is_valid()) {
focused->draw(canvas_item, Point2());
Rect2 drect(Point2(),focused->get_size()*scale);
draw_texture_rect(focused,drect,false,modulate);
};
} break;
@ -125,6 +141,8 @@ void TextureButton::_bind_methods() {
ObjectTypeDB::bind_method(_MD("set_disabled_texture","texture:Texture"),&TextureButton::set_disabled_texture);
ObjectTypeDB::bind_method(_MD("set_focused_texture","texture:Texture"),&TextureButton::set_focused_texture);
ObjectTypeDB::bind_method(_MD("set_click_mask","mask:BitMap"),&TextureButton::set_click_mask);
ObjectTypeDB::bind_method(_MD("set_scale","scale"),&TextureButton::set_scale);
ObjectTypeDB::bind_method(_MD("set_modulate","color"),&TextureButton::set_modulate);
ObjectTypeDB::bind_method(_MD("get_normal_texture:Texture"),&TextureButton::get_normal_texture);
ObjectTypeDB::bind_method(_MD("get_pressed_texture:Texture"),&TextureButton::get_pressed_texture);
@ -132,6 +150,8 @@ void TextureButton::_bind_methods() {
ObjectTypeDB::bind_method(_MD("get_disabled_texture:Texture"),&TextureButton::get_disabled_texture);
ObjectTypeDB::bind_method(_MD("get_focused_texture:Texture"),&TextureButton::get_focused_texture);
ObjectTypeDB::bind_method(_MD("get_click_mask:BitMap"),&TextureButton::get_click_mask);
ObjectTypeDB::bind_method(_MD("get_scale"),&TextureButton::get_scale);
ObjectTypeDB::bind_method(_MD("get_modulate"),&TextureButton::get_modulate);
ADD_PROPERTY(PropertyInfo(Variant::OBJECT,"textures/normal",PROPERTY_HINT_RESOURCE_TYPE,"Texture"), _SCS("set_normal_texture"), _SCS("get_normal_texture"));
ADD_PROPERTY(PropertyInfo(Variant::OBJECT,"textures/pressed",PROPERTY_HINT_RESOURCE_TYPE,"Texture"), _SCS("set_pressed_texture"), _SCS("get_pressed_texture"));
@ -139,6 +159,8 @@ void TextureButton::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::OBJECT,"textures/disabled",PROPERTY_HINT_RESOURCE_TYPE,"Texture"), _SCS("set_disabled_texture"), _SCS("get_disabled_texture"));
ADD_PROPERTY(PropertyInfo(Variant::OBJECT,"textures/focused",PROPERTY_HINT_RESOURCE_TYPE,"Texture"), _SCS("set_focused_texture"), _SCS("get_focused_texture"));
ADD_PROPERTY(PropertyInfo(Variant::OBJECT,"textures/click_mask",PROPERTY_HINT_RESOURCE_TYPE,"BitMap"), _SCS("set_click_mask"), _SCS("get_click_mask")) ;
ADD_PROPERTY(PropertyInfo(Variant::REAL,"params/scale",PROPERTY_HINT_RANGE,"0.01,1024,0.01"), _SCS("set_scale"), _SCS("get_scale"));
ADD_PROPERTY(PropertyInfo(Variant::COLOR,"params/modulate"), _SCS("set_modulate"), _SCS("get_modulate"));
}
@ -206,6 +228,30 @@ void TextureButton::set_focused_texture(const Ref<Texture>& p_focused) {
focused = p_focused;
};
void TextureButton::set_scale(float p_scale) {
ERR_FAIL_COND(p_scale<=0);
scale=p_scale;
minimum_size_changed();
update();
}
float TextureButton::get_scale() const{
return scale;
}
void TextureButton::set_modulate(const Color& p_modulate) {
modulate=p_modulate;
update();
}
Color TextureButton::get_modulate() const {
return modulate;
}
TextureButton::TextureButton() {
scale=1.0;
modulate=Color(1,1,1);
}

View File

@ -41,6 +41,8 @@ class TextureButton : public BaseButton {
Ref<Texture> disabled;
Ref<Texture> focused;
Ref<BitMap> click_mask;
float scale;
Color modulate;
protected:
@ -66,6 +68,11 @@ public:
Ref<Texture> get_focused_texture() const;
Ref<BitMap> get_click_mask() const;
void set_scale(float p_scale);
float get_scale() const;
void set_modulate(const Color& p_modulate);
Color get_modulate() const;
TextureButton();
};