summaryrefslogtreecommitdiff
path: root/scene/gui
diff options
context:
space:
mode:
Diffstat (limited to 'scene/gui')
-rw-r--r--scene/gui/dialogs.cpp2
-rw-r--r--scene/gui/graph_edit.cpp20
-rw-r--r--scene/gui/graph_edit.h1
-rw-r--r--scene/gui/graph_node.cpp31
-rw-r--r--scene/gui/graph_node.h3
-rw-r--r--scene/gui/item_list.cpp18
-rw-r--r--scene/gui/item_list.h4
-rw-r--r--scene/gui/line_edit.cpp79
-rw-r--r--scene/gui/line_edit.h8
-rw-r--r--scene/gui/texture_progress.cpp1
10 files changed, 128 insertions, 39 deletions
diff --git a/scene/gui/dialogs.cpp b/scene/gui/dialogs.cpp
index 4dbc106834..93e46da82b 100644
--- a/scene/gui/dialogs.cpp
+++ b/scene/gui/dialogs.cpp
@@ -399,8 +399,6 @@ AcceptDialog::AcceptDialog() {
add_child(label);
hbc = memnew( HBoxContainer );
- hbc->set_area_as_parent_rect(margin);
- hbc->set_anchor_and_margin(MARGIN_TOP,ANCHOR_END,button_margin);
add_child(hbc);
hbc->add_spacer();
diff --git a/scene/gui/graph_edit.cpp b/scene/gui/graph_edit.cpp
index 2307b33345..0de6add8cb 100644
--- a/scene/gui/graph_edit.cpp
+++ b/scene/gui/graph_edit.cpp
@@ -360,7 +360,8 @@ bool GraphEdit::_filter_input(const Point2& p_point) {
Ref<Texture> port =get_icon("port","GraphNode");
- float grab_r=port->get_width()*0.5;
+ float grab_r_extend = 2.0;
+ float grab_r=port->get_width()*0.5*grab_r_extend;
for(int i=get_child_count()-1;i>=0;i--) {
GraphNode *gn=get_child(i)->cast_to<GraphNode>();
@@ -379,8 +380,9 @@ bool GraphEdit::_filter_input(const Point2& p_point) {
for(int j=0;j<gn->get_connection_input_count();j++) {
Vector2 pos = gn->get_connection_input_pos(j)+gn->get_pos();
- if (pos.distance_to(p_point)<grab_r)
+ if (pos.distance_to(p_point)<grab_r) {
return true;
+ }
}
@@ -392,11 +394,13 @@ bool GraphEdit::_filter_input(const Point2& p_point) {
void GraphEdit::_top_layer_input(const InputEvent& p_ev) {
+
+ float grab_r_extend = 2.0;
if (p_ev.type==InputEvent::MOUSE_BUTTON && p_ev.mouse_button.button_index==BUTTON_LEFT && p_ev.mouse_button.pressed) {
Ref<Texture> port =get_icon("port","GraphNode");
Vector2 mpos(p_ev.mouse_button.x,p_ev.mouse_button.y);
- float grab_r=port->get_width()*0.5;
+ float grab_r=port->get_width()*0.5*grab_r_extend;
for(int i=get_child_count()-1;i>=0;i--) {
GraphNode *gn=get_child(i)->cast_to<GraphNode>();
@@ -425,6 +429,7 @@ void GraphEdit::_top_layer_input(const InputEvent& p_ev) {
connecting_color=to->cast_to<GraphNode>()->get_connection_input_color(E->get().to_port);
connecting_target=false;
connecting_to=pos;
+ just_disconected=true;
emit_signal("disconnection_request",E->get().from,E->get().from_port,E->get().to,E->get().to_port);
to = get_node(String(connecting_from)); //maybe it was erased
@@ -446,6 +451,7 @@ void GraphEdit::_top_layer_input(const InputEvent& p_ev) {
connecting_color=gn->get_connection_output_color(j);
connecting_target=false;
connecting_to=pos;
+ just_disconected=false;
return;
}
@@ -474,6 +480,7 @@ void GraphEdit::_top_layer_input(const InputEvent& p_ev) {
connecting_color=fr->cast_to<GraphNode>()->get_connection_output_color(E->get().from_port);
connecting_target=false;
connecting_to=pos;
+ just_disconected=true;
emit_signal("disconnection_request",E->get().from,E->get().from_port,E->get().to,E->get().to_port);
fr = get_node(String(connecting_from)); //maybe it was erased
@@ -496,6 +503,8 @@ void GraphEdit::_top_layer_input(const InputEvent& p_ev) {
connecting_color=gn->get_connection_input_color(j);
connecting_target=false;
connecting_to=pos;
+ just_disconected=true;
+
return;
}
@@ -512,7 +521,7 @@ void GraphEdit::_top_layer_input(const InputEvent& p_ev) {
Ref<Texture> port =get_icon("port","GraphNode");
Vector2 mpos(p_ev.mouse_button.x,p_ev.mouse_button.y);
- float grab_r=port->get_width()*0.5;
+ float grab_r=port->get_width()*0.5*grab_r_extend;
for(int i=get_child_count()-1;i>=0;i--) {
GraphNode *gn=get_child(i)->cast_to<GraphNode>();
@@ -568,7 +577,7 @@ void GraphEdit::_top_layer_input(const InputEvent& p_ev) {
}
emit_signal("connection_request",from,from_slot,to,to_slot);
- } else {
+ } else if (!just_disconected) {
String from = connecting_from;
int from_slot = connecting_index;
Vector2 ofs = Vector2(p_ev.mouse_button.x,p_ev.mouse_button.y);
@@ -1323,6 +1332,7 @@ GraphEdit::GraphEdit() {
zoom_hb->add_child(snap_amount);
setting_scroll_ofs=false;
+ just_disconected=false;
diff --git a/scene/gui/graph_edit.h b/scene/gui/graph_edit.h
index ed6e4ef6ac..c5174f6699 100644
--- a/scene/gui/graph_edit.h
+++ b/scene/gui/graph_edit.h
@@ -92,6 +92,7 @@ private:
Vector2 connecting_to;
String connecting_target_to;
int connecting_target_index;
+ bool just_disconected;
bool dragging;
bool just_selected;
diff --git a/scene/gui/graph_node.cpp b/scene/gui/graph_node.cpp
index 5ece970936..da298a795a 100644
--- a/scene/gui/graph_node.cpp
+++ b/scene/gui/graph_node.cpp
@@ -183,12 +183,39 @@ void GraphNode::_resort() {
}
+bool GraphNode::has_point(const Point2& p_point) const {
+
+ if (comment) {
+ Ref<StyleBox> comment = get_stylebox("comment");
+ Ref<Texture> resizer =get_icon("resizer");
+
+ if (Rect2(get_size()-resizer->get_size(), resizer->get_size()).has_point(p_point)) {
+ return true;
+ }
+ if (Rect2(0,0,get_size().width,comment->get_margin(MARGIN_TOP)).has_point(p_point)) {
+ return true;
+ }
+
+ return false;
+
+ } else {
+ return Control::has_point(p_point);
+ }
+}
void GraphNode::_notification(int p_what) {
if (p_what==NOTIFICATION_DRAW) {
- Ref<StyleBox> sb=get_stylebox(comment? "comment": (selected ? "selectedframe" : "frame"));
+ Ref<StyleBox> sb;
+
+ if (comment) {
+ sb = get_stylebox( selected? "commentfocus" : "comment");
+
+ } else {
+
+ sb = get_stylebox( selected ? "selectedframe" : "frame");
+ }
sb=sb->duplicate();
sb->call("set_modulate",modulate);
@@ -601,6 +628,8 @@ void GraphNode::_input_event(const InputEvent& p_ev) {
ERR_EXPLAIN("GraphNode must be the child of a GraphEdit node.");
ERR_FAIL_COND(get_parent_control() == NULL);
+ print_line("INPUT EVENT BUTTON");
+
if(p_ev.mouse_button.pressed && p_ev.mouse_button.button_index==BUTTON_LEFT) {
Vector2 mpos = Vector2(p_ev.mouse_button.x,p_ev.mouse_button.y);
diff --git a/scene/gui/graph_node.h b/scene/gui/graph_node.h
index 7357ab5a45..cbfd34f556 100644
--- a/scene/gui/graph_node.h
+++ b/scene/gui/graph_node.h
@@ -93,6 +93,9 @@ private:
Overlay overlay;
Color modulate;
+
+ bool has_point(const Point2& p_point) const;
+
protected:
diff --git a/scene/gui/item_list.cpp b/scene/gui/item_list.cpp
index 105d919338..63902ef815 100644
--- a/scene/gui/item_list.cpp
+++ b/scene/gui/item_list.cpp
@@ -40,6 +40,7 @@ void ItemList::add_item(const String& p_item,const Ref<Texture>& p_texture,bool
item.selectable=p_selectable;
item.selected=false;
item.disabled=false;
+ item.tooltip_enabled=true;
item.custom_bg=Color(0,0,0,0);
items.push_back(item);
@@ -57,6 +58,7 @@ void ItemList::add_icon_item(const Ref<Texture>& p_item,bool p_selectable){
item.selectable=p_selectable;
item.selected=false;
item.disabled=false;
+ item.tooltip_enabled=true;
item.custom_bg=Color(0,0,0,0);
items.push_back(item);
@@ -82,6 +84,16 @@ String ItemList::get_item_text(int p_idx) const{
}
+void ItemList::set_item_tooltip_enabled(int p_idx, const bool p_enabled) {
+ ERR_FAIL_INDEX(p_idx,items.size());
+ items[p_idx].tooltip_enabled = p_enabled;
+}
+
+bool ItemList::is_item_tooltip_enabled(int p_idx) const {
+ ERR_FAIL_INDEX_V(p_idx,items.size(), false);
+ return items[p_idx].tooltip_enabled;
+}
+
void ItemList::set_item_tooltip(int p_idx,const String& p_tooltip){
ERR_FAIL_INDEX(p_idx,items.size());
@@ -1198,6 +1210,9 @@ String ItemList::get_tooltip(const Point2& p_pos) const {
int closest = get_item_at_pos(p_pos);
if (closest!=-1) {
+ if (!items[closest].tooltip_enabled) {
+ return "";
+ }
if (items[closest].tooltip!="") {
return items[closest].tooltip;
}
@@ -1294,6 +1309,9 @@ void ItemList::_bind_methods(){
ObjectTypeDB::bind_method(_MD("set_item_custom_bg_color","idx","custom_bg_color"),&ItemList::set_item_custom_bg_color);
ObjectTypeDB::bind_method(_MD("get_item_custom_bg_color","idx"),&ItemList::get_item_custom_bg_color);
+ ObjectTypeDB::bind_method(_MD("set_item_tooltip_enabled","idx","enable"),&ItemList::set_item_tooltip_enabled);
+ ObjectTypeDB::bind_method(_MD("is_item_tooltip_enabled","idx"),&ItemList::is_item_tooltip_enabled);
+
ObjectTypeDB::bind_method(_MD("set_item_tooltip","idx","tooltip"),&ItemList::set_item_tooltip);
ObjectTypeDB::bind_method(_MD("get_item_tooltip","idx"),&ItemList::get_item_tooltip);
diff --git a/scene/gui/item_list.h b/scene/gui/item_list.h
index e1902d1c1f..91c74b5291 100644
--- a/scene/gui/item_list.h
+++ b/scene/gui/item_list.h
@@ -56,6 +56,7 @@ private:
bool selectable;
bool selected;
bool disabled;
+ bool tooltip_enabled;
Variant metadata;
String tooltip;
Color custom_bg;
@@ -135,6 +136,9 @@ public:
void set_item_tag_icon(int p_idx,const Ref<Texture>& p_tag_icon);
Ref<Texture> get_item_tag_icon(int p_idx) const;
+ void set_item_tooltip_enabled(int p_idx, const bool p_enabled);
+ bool is_item_tooltip_enabled(int p_idx) const;
+
void set_item_tooltip(int p_idx,const String& p_tooltip);
String get_item_tooltip(int p_idx) const;
diff --git a/scene/gui/line_edit.cpp b/scene/gui/line_edit.cpp
index fcea12fd6b..90a8af9238 100644
--- a/scene/gui/line_edit.cpp
+++ b/scene/gui/line_edit.cpp
@@ -193,8 +193,8 @@ void LineEdit::_input_event(InputEvent p_event) {
}
set_cursor_pos(0);
- emit_signal("text_changed",text);
- _change_notify("text");
+ _text_changed();
+
}
@@ -215,8 +215,7 @@ void LineEdit::_input_event(InputEvent p_event) {
selection_clear();
undo_text = text;
text = text.substr(0,cursor_pos);
- emit_signal("text_changed",text);
- _change_notify("text");
+ _text_changed();
}
} break;
@@ -475,9 +474,7 @@ void LineEdit::_input_event(InputEvent p_event) {
selection_delete();
CharType ucodestr[2]={(CharType)k.unicode,0};
append_at_cursor(ucodestr);
- emit_signal("text_changed",text);
- _change_notify("text");
-
+ _text_changed();
accept_event();
}
@@ -725,8 +722,7 @@ void LineEdit::paste_text() {
if(selection.enabled) selection_delete();
append_at_cursor(paste_buffer);
- emit_signal("text_changed",text);
- _change_notify("text");
+ _text_changed();
}
@@ -750,9 +746,7 @@ void LineEdit::undo() {
set_cursor_pos(old_cursor_pos);
}
- emit_signal("text_changed",text);
- _change_notify("text");
-
+ _text_changed();
}
void LineEdit::shift_selection_check_pre(bool p_shift) {
@@ -806,16 +800,6 @@ void LineEdit::set_cursor_at_pixel_pos(int p_x) {
pixel_ofs+=char_w;
if (pixel_ofs > p_x) { //found what we look for
-
-
- if ( (pixel_ofs-p_x) < (char_w >> 1 ) ) {
-
- ofs+=1;
- } else if ( (pixel_ofs-p_x) > (char_w >> 1 ) ) {
-
- ofs-=1;
- }
-
break;
}
@@ -891,8 +875,7 @@ void LineEdit::delete_char() {
// set_window_pos(cursor_pos-get_window_length());
}
- emit_signal("text_changed",text);
- _change_notify("text");
+ _text_changed();
}
void LineEdit::delete_text(int p_from_column, int p_to_column) {
@@ -924,8 +907,7 @@ void LineEdit::delete_text(int p_from_column, int p_to_column) {
window_pos=cursor_pos;
}
- emit_signal("text_changed",text);
- _change_notify("text");
+ _text_changed();
}
void LineEdit::set_text(String p_text) {
@@ -940,8 +922,7 @@ void LineEdit::set_text(String p_text) {
void LineEdit::clear() {
clear_internal();
- emit_signal("text_changed",text);
- _change_notify("text");
+ _text_changed();
}
String LineEdit::get_text() const {
@@ -1080,7 +1061,17 @@ Size2 LineEdit::get_minimum_size() const {
Size2 min=style->get_minimum_size();
min.height+=font->get_height();
- min.width+=get_constant("minimum_spaces")*font->get_char_size(' ').x;
+
+ //minimum size of text
+ int space_size = font->get_char_size(' ').x;
+ int mstext = get_constant("minimum_spaces")*space_size;
+
+ if (expand_to_text_length) {
+ mstext=MAX(mstext,font->get_string_size(text).x+space_size); //add a spce because some fonts are too exact
+ }
+
+ min.width+=mstext;
+
return min;
}
@@ -1236,6 +1227,29 @@ PopupMenu *LineEdit::get_menu() const {
}
#endif
+
+void LineEdit::set_expand_to_text_length(bool p_enabled) {
+
+ expand_to_text_length = p_enabled;
+ minimum_size_changed();
+}
+
+bool LineEdit::get_expand_to_text_length() const{
+
+ return expand_to_text_length;
+}
+
+
+void LineEdit::_text_changed() {
+
+ if (expand_to_text_length)
+ minimum_size_changed();
+
+ emit_signal("text_changed",text);
+ _change_notify("text");
+
+}
+
void LineEdit::_bind_methods() {
ObjectTypeDB::bind_method(_MD("_toggle_draw_caret"),&LineEdit::_toggle_draw_caret);
@@ -1258,7 +1272,9 @@ void LineEdit::_bind_methods() {
ObjectTypeDB::bind_method(_MD("get_placeholder_alpha"),&LineEdit::get_placeholder_alpha);
ObjectTypeDB::bind_method(_MD("set_cursor_pos","pos"),&LineEdit::set_cursor_pos);
ObjectTypeDB::bind_method(_MD("get_cursor_pos"),&LineEdit::get_cursor_pos);
- ObjectTypeDB::bind_method(_MD("cursor_set_blink_enabled", "enable"),&LineEdit::cursor_set_blink_enabled);
+ ObjectTypeDB::bind_method(_MD("set_expand_to_text_length","enabled"),&LineEdit::set_expand_to_text_length);
+ ObjectTypeDB::bind_method(_MD("get_expand_to_text_length"),&LineEdit::get_expand_to_text_length);
+ ObjectTypeDB::bind_method(_MD("cursor_set_blink_enabled", "enabled"),&LineEdit::cursor_set_blink_enabled);
ObjectTypeDB::bind_method(_MD("cursor_get_blink_enabled"),&LineEdit::cursor_get_blink_enabled);
ObjectTypeDB::bind_method(_MD("cursor_set_blink_speed", "blink_speed"),&LineEdit::cursor_set_blink_speed);
ObjectTypeDB::bind_method(_MD("cursor_get_blink_speed"),&LineEdit::cursor_get_blink_speed);
@@ -1296,6 +1312,7 @@ void LineEdit::_bind_methods() {
ADD_PROPERTYNZ( PropertyInfo( Variant::INT, "max_length" ), _SCS("set_max_length"),_SCS("get_max_length") );
ADD_PROPERTYNO( PropertyInfo( Variant::BOOL, "editable" ), _SCS("set_editable"),_SCS("is_editable") );
ADD_PROPERTYNZ( PropertyInfo( Variant::BOOL, "secret" ), _SCS("set_secret"),_SCS("is_secret") );
+ ADD_PROPERTYNO( PropertyInfo( Variant::BOOL, "expand_to_len" ), _SCS("set_expand_to_text_length"),_SCS("get_expand_to_text_length") );
ADD_PROPERTY( PropertyInfo( Variant::INT,"focus_mode", PROPERTY_HINT_ENUM, "None,Click,All" ), _SCS("set_focus_mode"), _SCS("get_focus_mode") );
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "caret/caret_blink"), _SCS("cursor_set_blink_enabled"), _SCS("cursor_get_blink_enabled"));;
ADD_PROPERTYNZ(PropertyInfo(Variant::REAL, "caret/caret_blink_speed",PROPERTY_HINT_RANGE,"0.1,10,0.1"), _SCS("cursor_set_blink_speed"),_SCS("cursor_get_blink_speed") );
@@ -1337,7 +1354,7 @@ LineEdit::LineEdit() {
menu->add_separator();
menu->add_item(TTR("Undo"),MENU_UNDO,KEY_MASK_CMD|KEY_Z);
menu->connect("item_pressed",this,"menu_option");
-
+ expand_to_text_length=false;
}
diff --git a/scene/gui/line_edit.h b/scene/gui/line_edit.h
index 112e4ad55e..47d5706bbe 100644
--- a/scene/gui/line_edit.h
+++ b/scene/gui/line_edit.h
@@ -90,6 +90,11 @@ private:
} selection;
Timer *caret_blink_timer;
+
+
+ void _text_changed();
+ bool expand_to_text_length;
+
bool caret_blink_enabled;
bool draw_caret;
bool window_has_focus;
@@ -169,6 +174,9 @@ public:
virtual Size2 get_minimum_size() const;
+ void set_expand_to_text_length(bool p_len);
+ bool get_expand_to_text_length() const;
+
virtual bool is_text_field() const;
LineEdit();
~LineEdit();
diff --git a/scene/gui/texture_progress.cpp b/scene/gui/texture_progress.cpp
index 923a35031c..2c576b6ba5 100644
--- a/scene/gui/texture_progress.cpp
+++ b/scene/gui/texture_progress.cpp
@@ -297,6 +297,7 @@ void TextureProgress::_bind_methods() {
TextureProgress::TextureProgress()
{
mode=FILL_LEFT_TO_RIGHT;
+ rad_init_angle=0;
rad_center_off=Point2();
rad_max_degrees=360;
}