summaryrefslogtreecommitdiff
path: root/scene/gui
diff options
context:
space:
mode:
Diffstat (limited to 'scene/gui')
-rw-r--r--scene/gui/color_picker.cpp33
-rw-r--r--scene/gui/color_picker.h3
-rw-r--r--scene/gui/control.cpp4
-rw-r--r--scene/gui/tree.cpp26
-rw-r--r--scene/gui/tree.h6
5 files changed, 62 insertions, 10 deletions
diff --git a/scene/gui/color_picker.cpp b/scene/gui/color_picker.cpp
index 862a5d6bcb..7b553543b6 100644
--- a/scene/gui/color_picker.cpp
+++ b/scene/gui/color_picker.cpp
@@ -64,7 +64,18 @@ void ColorPicker::_notification(int p_what) {
case NOTIFICATION_ENTER_TREE: {
btn_pick->set_icon(get_icon("screen_picker", "ColorPicker"));
+ update_material(uv_material, color);
+ update_material(w_material, color);
+
+ uv_edit->get_child(0)->cast_to<Control>()->update();
+ w_edit->get_child(0)->cast_to<Control>()->update();
+ _update_color();
}
+
+ case NOTIFICATION_VISIBILITY_CHANGED: {
+ c_text->call_deferred("grab_focus");
+ c_text->call_deferred("select");
+ } break;
}
}
@@ -88,8 +99,13 @@ void ColorPicker::set_color(const Color& p_color) {
h=color.get_h();
s=color.get_s();
v=color.get_v();
+
+ if (!is_inside_tree())
+ return;
+
update_material(uv_material, color);
update_material(w_material, color);
+
uv_edit->get_child(0)->cast_to<Control>()->update();
w_edit->get_child(0)->cast_to<Control>()->update();
_update_color();
@@ -100,6 +116,10 @@ void ColorPicker::set_edit_alpha(bool p_show) {
edit_alpha=p_show;
_update_controls();
+
+ if (!is_inside_tree())
+ return;
+
_update_color();
sample->update();
}
@@ -136,6 +156,10 @@ void ColorPicker::_html_entered(const String& p_html) {
return;
color = Color::html(p_html);
+
+ if (!is_inside_tree())
+ return;
+
_update_color();
emit_signal("color_changed",color);
}
@@ -163,8 +187,6 @@ void ColorPicker::_update_color() {
} else {
c_text->set_text(color.to_html(edit_alpha && color.a<1));
}
- c_text->grab_focus();
- c_text->select();
sample->update();
updating=false;
@@ -225,6 +247,9 @@ void ColorPicker::set_raw_mode(bool p_enabled) {
if (btn_mode->is_pressed()!=p_enabled)
btn_mode->set_pressed(p_enabled);
+ if (!is_inside_tree())
+ return;
+
_update_controls();
_update_color();
}
@@ -531,7 +556,7 @@ ColorPicker::ColorPicker() :
_update_controls();
- _update_color();
+ //_update_color();
updating=false;
uv_material.instance();
@@ -594,6 +619,8 @@ void ColorPickerButton::pressed() {
popup->set_pos(get_global_pos()-Size2(0,ms.height));
popup->set_size(ms);
popup->popup();
+
+
}
void ColorPickerButton::_notification(int p_what) {
diff --git a/scene/gui/color_picker.h b/scene/gui/color_picker.h
index 59668ebac1..35f4ae7a99 100644
--- a/scene/gui/color_picker.h
+++ b/scene/gui/color_picker.h
@@ -89,6 +89,9 @@ private:
void _screen_input(const InputEvent& p_input);
void _add_preset_pressed();
void _screen_pick_pressed();
+
+friend class ColorPicker;
+
protected:
void _notification(int);
diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp
index 71a0f50240..c319e306e0 100644
--- a/scene/gui/control.cpp
+++ b/scene/gui/control.cpp
@@ -1597,7 +1597,9 @@ bool Control::has_focus() const {
void Control::grab_focus() {
- ERR_FAIL_COND(!is_inside_tree());
+ if (!is_inside_tree()){
+ ERR_FAIL_COND(!is_inside_tree());
+ }
if (data.focus_mode==FOCUS_NONE)
return;
diff --git a/scene/gui/tree.cpp b/scene/gui/tree.cpp
index 3b25701944..05b1e8bcea 100644
--- a/scene/gui/tree.cpp
+++ b/scene/gui/tree.cpp
@@ -482,7 +482,7 @@ void TreeItem::deselect(int p_column) {
_cell_deselected(p_column);
}
-void TreeItem::add_button(int p_column,const Ref<Texture>& p_button,int p_id) {
+void TreeItem::add_button(int p_column, const Ref<Texture>& p_button, int p_id, bool p_disabled) {
ERR_FAIL_INDEX( p_column, cells.size() );
@@ -492,6 +492,7 @@ void TreeItem::add_button(int p_column,const Ref<Texture>& p_button,int p_id) {
if (p_id<0)
p_id=cells[p_column].buttons.size();
button.id=p_id;
+ button.disabled=p_disabled;
cells[p_column].buttons.push_back(button);
_changed_notify(p_column);
}
@@ -533,6 +534,15 @@ int TreeItem::get_button_by_id(int p_column,int p_id) const {
return -1;
}
+
+bool TreeItem::is_button_disabled(int p_column, int p_idx) const {
+
+ ERR_FAIL_INDEX_V( p_column, cells.size(), false );
+ ERR_FAIL_INDEX_V( p_idx, cells[p_column].buttons.size(), false );
+
+ return cells[p_column].buttons[p_idx].disabled;
+
+}
void TreeItem::set_button(int p_column,int p_idx,const Ref<Texture>& p_button){
ERR_FAIL_COND( p_button.is_null() );
@@ -672,10 +682,11 @@ void TreeItem::_bind_methods() {
ObjectTypeDB::bind_method(_MD("clear_custom_bg_color","column"),&TreeItem::clear_custom_bg_color);
ObjectTypeDB::bind_method(_MD("get_custom_bg_color","column"),&TreeItem::get_custom_bg_color);
- ObjectTypeDB::bind_method(_MD("add_button","column","button:Texture","button_idx"),&TreeItem::add_button);
+ ObjectTypeDB::bind_method(_MD("add_button","column","button:Texture","button_idx","disabled"),&TreeItem::add_button,DEFVAL(-1),DEFVAL(false));
ObjectTypeDB::bind_method(_MD("get_button_count","column"),&TreeItem::get_button_count);
ObjectTypeDB::bind_method(_MD("get_button:Texture","column","button_idx"),&TreeItem::get_button);
ObjectTypeDB::bind_method(_MD("erase_button","column","button_idx"),&TreeItem::erase_button);
+ ObjectTypeDB::bind_method(_MD("is_button_disabled","column","button_idx"),&TreeItem::is_button_disabled);
ObjectTypeDB::bind_method(_MD("set_tooltip","column","tooltip"),&TreeItem::set_tooltip);
ObjectTypeDB::bind_method(_MD("get_tooltip","column"),&TreeItem::get_tooltip);
@@ -1015,14 +1026,15 @@ int Tree::draw_item(const Point2i& p_pos,const Point2& p_draw_ofs, const Size2&
Point2i o = Point2i( ofs+w-s.width, p_pos.y )-cache.offset+p_draw_ofs;
- if (cache.click_type==Cache::CLICK_BUTTON && cache.click_item==p_item && cache.click_column==i) {
+ if (cache.click_type==Cache::CLICK_BUTTON && cache.click_item==p_item && cache.click_column==i && !p_item->cells[i].buttons[j].disabled) {
//being pressed
cache.button_pressed->draw(get_canvas_item(),Rect2(o,s));
}
o.y+=(label_h-s.height)/2;
o+=cache.button_pressed->get_offset();
- b->draw(ci,o);
+
+ b->draw(ci,o,p_item->cells[i].buttons[j].disabled?Color(1,1,1,0.5):Color(1,1,1,1));
w-=s.width+cache.button_margin;
bw+=s.width+cache.button_margin;
}
@@ -1472,7 +1484,13 @@ int Tree::propagate_mouse_event(const Point2i &p_pos,int x_ofs,int y_ofs,bool p_
for(int j=c.buttons.size()-1;j>=0;j--) {
Ref<Texture> b=c.buttons[j].texture;
int w = b->get_size().width + cache.button_pressed->get_minimum_size().width;
+
if (x>col_width-w) {
+ if (c.buttons[j].disabled) {
+ pressed_button=-1;
+ cache.click_type=Cache::CLICK_NONE;
+ return -1;
+ }
pressed_button=j;
cache.click_type=Cache::CLICK_BUTTON;
cache.click_index=j;
diff --git a/scene/gui/tree.h b/scene/gui/tree.h
index e4d349978c..e5c95b4d66 100644
--- a/scene/gui/tree.h
+++ b/scene/gui/tree.h
@@ -86,8 +86,9 @@ friend class Tree;
struct Button {
int id;
+ bool disabled;
Ref<Texture> texture;
- Button() { id=0; }
+ Button() { id=0; disabled=false; }
};
Vector< Button > buttons;
@@ -172,12 +173,13 @@ public:
void set_icon_max_width(int p_column,int p_max);
int get_icon_max_width(int p_column) const;
- void add_button(int p_column,const Ref<Texture>& p_button,int p_id=-1);
+ void add_button(int p_column,const Ref<Texture>& p_button,int p_id=-1,bool p_disabled=false);
int get_button_count(int p_column) const;
Ref<Texture> get_button(int p_column,int p_idx) const;
int get_button_id(int p_column,int p_idx) const;
void erase_button(int p_column,int p_idx);
int get_button_by_id(int p_column,int p_id) const;
+ bool is_button_disabled(int p_column,int p_idx) const;
void set_button(int p_column,int p_idx,const Ref<Texture>& p_button);
/* range works for mode number or mode combo */