summaryrefslogtreecommitdiff
path: root/scene/gui
diff options
context:
space:
mode:
Diffstat (limited to 'scene/gui')
-rw-r--r--scene/gui/color_picker.cpp81
-rw-r--r--scene/gui/color_picker.h2
-rw-r--r--scene/gui/control.cpp4
-rw-r--r--scene/gui/line_edit.cpp9
-rw-r--r--scene/gui/text_edit.cpp6
-rw-r--r--scene/gui/tree.cpp26
-rw-r--r--scene/gui/tree.h6
7 files changed, 99 insertions, 35 deletions
diff --git a/scene/gui/color_picker.cpp b/scene/gui/color_picker.cpp
index 862a5d6bcb..f1b910d23f 100644
--- a/scene/gui/color_picker.cpp
+++ b/scene/gui/color_picker.cpp
@@ -34,7 +34,7 @@
#include "os/input.h"
#include "os/keyboard.h"
-void update_material(Ref<CanvasItemMaterial>mat,const Color& p_color) {
+void update_material(Ref<CanvasItemMaterial>mat,const Color& p_color,float h,float s,float v) {
if (!mat.is_valid())
return;
Ref<Shader> sdr = mat->get_shader();
@@ -44,9 +44,9 @@ void update_material(Ref<CanvasItemMaterial>mat,const Color& p_color) {
mat->set_shader_param("R",p_color.r);
mat->set_shader_param("G",p_color.g);
mat->set_shader_param("B",p_color.b);
- mat->set_shader_param("H",p_color.get_h());
- mat->set_shader_param("S",p_color.get_s());
- mat->set_shader_param("V",p_color.get_v());
+ mat->set_shader_param("H",h);
+ mat->set_shader_param("S",s);
+ mat->set_shader_param("V",v);
mat->set_shader_param("A",p_color.a);
}
@@ -57,14 +57,25 @@ void ColorPicker::_notification(int p_what) {
case NOTIFICATION_THEME_CHANGED: {
uv_material->set_shader(get_shader("uv_editor"));
w_material->set_shader(get_shader("w_editor"));
- update_material(uv_material,color);
- update_material(w_material,color);
+ update_material(uv_material,color,h,s,v);
+ update_material(w_material,color,h,s,v);
_update_controls();
} break;
case NOTIFICATION_ENTER_TREE: {
btn_pick->set_icon(get_icon("screen_picker", "ColorPicker"));
+ update_material(uv_material, color,h,s,v);
+ update_material(w_material, color,h,s,v);
+
+ 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;
}
}
@@ -85,11 +96,19 @@ void ColorPicker::_update_controls() {
void ColorPicker::set_color(const Color& p_color) {
color=p_color;
- h=color.get_h();
- s=color.get_s();
- v=color.get_v();
- update_material(uv_material, color);
- update_material(w_material, color);
+ if (color != last_hsv) {
+ h=color.get_h();
+ s=color.get_s();
+ v=color.get_v();
+ last_hsv = color;
+ }
+
+ if (!is_inside_tree())
+ return;
+
+ update_material(uv_material, color,h,s,v);
+ update_material(w_material, color,h,s,v);
+
uv_edit->get_child(0)->cast_to<Control>()->update();
w_edit->get_child(0)->cast_to<Control>()->update();
_update_color();
@@ -100,6 +119,10 @@ void ColorPicker::set_edit_alpha(bool p_show) {
edit_alpha=p_show;
_update_controls();
+
+ if (!is_inside_tree())
+ return;
+
_update_color();
sample->update();
}
@@ -119,13 +142,10 @@ void ColorPicker::_value_changed(double) {
}
color.components[3] = scroll[3]->get_val()/255.0;
- update_material(uv_material,color);
- update_material(w_material,color);
+ set_color(color);
c_text->set_text(color.to_html(edit_alpha && color.a<1));
- sample->update();
-
emit_signal("color_changed",color);
}
@@ -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();
}
@@ -243,15 +268,17 @@ void ColorPicker::_hsv_draw(int p_wich,Control* c)
if (!c)
return;
if (p_wich==0) {
- int x=c->get_size().x*color.get_s();
- int y=c->get_size().y-c->get_size().y*color.get_v();
- c->draw_line(Point2(x,0),Point2(x,c->get_size().y),color.inverted());
- c->draw_line(Point2(0,y),Point2(c->get_size().x,y),color.inverted());
+ int x=c->get_size().x*s;
+ int y=c->get_size().y-c->get_size().y*v;
+ Color col = color;
+ col.a=1;
+ c->draw_line(Point2(x,0),Point2(x,c->get_size().y),col.inverted());
+ c->draw_line(Point2(0,y),Point2(c->get_size().x,y),col.inverted());
c->draw_line(Point2(x,y),Point2(x,y),Color(1,1,1),2);
} else if (p_wich==1) {
- int y=c->get_size().y-c->get_size().y*color.get_h();
+ int y=c->get_size().y-c->get_size().y*h;
Color col=Color();
- col.set_hsv(color.get_h(),1,1);
+ col.set_hsv(h,1,1);
c->draw_line(Point2(0,y),Point2(c->get_size().x,y),col.inverted());
}
}
@@ -266,6 +293,7 @@ void ColorPicker::_uv_input(const InputEvent &ev) {
s=x/256;
v=1.0-y/256.0;
color.set_hsv(h,s,v,color.a);
+ last_hsv = color;
set_color(color);
_update_color();
emit_signal("color_changed", color);
@@ -281,6 +309,7 @@ void ColorPicker::_uv_input(const InputEvent &ev) {
s=x/256;
v=1.0-y/256.0;
color.set_hsv(h,s,v,color.a);
+ last_hsv = color;
set_color(color);
_update_color();
emit_signal("color_changed", color);
@@ -298,6 +327,7 @@ void ColorPicker::_w_input(const InputEvent &ev) {
changing_color = false;
}
color.set_hsv(h,s,v,color.a);
+ last_hsv = color;
set_color(color);
_update_color();
emit_signal("color_changed", color);
@@ -308,6 +338,7 @@ void ColorPicker::_w_input(const InputEvent &ev) {
float y = CLAMP((float)bev.y,0,256);
h=1.0-y/256.0;
color.set_hsv(h,s,v,color.a);
+ last_hsv = color;
set_color(color);
_update_color();
emit_signal("color_changed", color);
@@ -531,7 +562,7 @@ ColorPicker::ColorPicker() :
_update_controls();
- _update_color();
+ //_update_color();
updating=false;
uv_material.instance();
@@ -594,6 +625,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..4559bc7391 100644
--- a/scene/gui/color_picker.h
+++ b/scene/gui/color_picker.h
@@ -73,6 +73,7 @@ private:
bool updating;
bool changing_color;
float h,s,v;
+ Color last_hsv;
void _html_entered(const String& p_html);
void _value_changed(double);
@@ -89,6 +90,7 @@ private:
void _screen_input(const InputEvent& p_input);
void _add_preset_pressed();
void _screen_pick_pressed();
+
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/line_edit.cpp b/scene/gui/line_edit.cpp
index fdced3f62f..2a62ab30fc 100644
--- a/scene/gui/line_edit.cpp
+++ b/scene/gui/line_edit.cpp
@@ -80,8 +80,8 @@ void LineEdit::_input_event(InputEvent p_event) {
selection.creating=false;
selection.doubleclick=false;
- // notify to show soft keyboard
- notification(NOTIFICATION_FOCUS_ENTER);
+ if (OS::get_singleton()->has_virtual_keyboard())
+ OS::get_singleton()->show_virtual_keyboard(get_text(),get_global_rect());
}
update();
@@ -230,8 +230,9 @@ void LineEdit::_input_event(InputEvent p_event) {
case KEY_RETURN: {
emit_signal( "text_entered",text );
- // notify to hide soft keyboard
- notification(NOTIFICATION_FOCUS_EXIT);
+ if (OS::get_singleton()->has_virtual_keyboard())
+ OS::get_singleton()->hide_virtual_keyboard();
+
return;
} break;
diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp
index 7f7c8c023c..bf012b7a03 100644
--- a/scene/gui/text_edit.cpp
+++ b/scene/gui/text_edit.cpp
@@ -1197,6 +1197,12 @@ void TextEdit::_input_event(const InputEvent& p_input_event) {
if (mb.button_index==BUTTON_WHEEL_DOWN) {
v_scroll->set_val( v_scroll->get_val() +3 );
}
+ if (mb.button_index==BUTTON_WHEEL_LEFT) {
+ h_scroll->set_val( h_scroll->get_val() -3 );
+ }
+ if (mb.button_index==BUTTON_WHEEL_RIGHT) {
+ h_scroll->set_val( h_scroll->get_val() +3 );
+ }
if (mb.button_index==BUTTON_LEFT) {
int row,col;
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 */