summaryrefslogtreecommitdiff
path: root/scene/gui
diff options
context:
space:
mode:
Diffstat (limited to 'scene/gui')
-rw-r--r--scene/gui/color_ramp_edit.cpp54
-rw-r--r--scene/gui/file_dialog.cpp2
-rw-r--r--scene/gui/item_list.cpp60
-rw-r--r--scene/gui/item_list.h9
-rw-r--r--scene/gui/tabs.cpp48
-rw-r--r--scene/gui/tabs.h16
-rw-r--r--scene/gui/text_edit.cpp42
-rw-r--r--scene/gui/tree.h2
8 files changed, 220 insertions, 13 deletions
diff --git a/scene/gui/color_ramp_edit.cpp b/scene/gui/color_ramp_edit.cpp
index 382c0dc103..14a48fe3d3 100644
--- a/scene/gui/color_ramp_edit.cpp
+++ b/scene/gui/color_ramp_edit.cpp
@@ -48,6 +48,7 @@ void ColorRampEdit::_input_event(const InputEvent& p_event) {
points.remove(grabbed);
grabbed=-1;
+ grabbing=false;
update();
emit_signal("ramp_changed");
accept_event();
@@ -67,12 +68,38 @@ void ColorRampEdit::_input_event(const InputEvent& p_event) {
{
points.remove(grabbed);
grabbed=-1;
+ grabbing=false;
update();
emit_signal("ramp_changed");
accept_event();
}
}
+ //Hold alt key to duplicate selected color
+ if (p_event.type==InputEvent::MOUSE_BUTTON && p_event.mouse_button.button_index==1 && p_event.mouse_button.pressed && p_event.key.mod.alt ) {
+
+ int x = p_event.mouse_button.x;
+ grabbed=_get_point_from_pos(x);
+
+ if( grabbed != -1 ) {
+ int total_w = get_size().width-get_size().height-3;
+ ColorRamp::Point newPoint = points[grabbed];
+ newPoint.offset=CLAMP(x/float(total_w),0,1);
+
+ points.push_back(newPoint);
+ points.sort();
+ for(int i=0;i<points.size();++i) {
+ if (points[i].offset==newPoint.offset) {
+ grabbed=i;
+ break;
+ }
+ }
+
+ emit_signal("ramp_changed");
+ update();
+ }
+ }
+
if (p_event.type==InputEvent::MOUSE_BUTTON && p_event.mouse_button.button_index==1 && p_event.mouse_button.pressed) {
update();
@@ -158,6 +185,33 @@ void ColorRampEdit::_input_event(const InputEvent& p_event) {
int x = p_event.mouse_motion.x;
float newofs = CLAMP(x/float(total_w),0,1);
+
+ //Snap to nearest point if holding shift
+ if (p_event.key.mod.shift) {
+ float snap_treshhold = 0.03;
+ float smallest_ofs = snap_treshhold;
+ bool founded = false;
+ int nearest_point;
+ for(int i=0;i<points.size();++i) {
+ if (i != grabbed) {
+ float temp_ofs = ABS(points[i].offset - newofs);
+ if (temp_ofs < smallest_ofs) {
+ smallest_ofs = temp_ofs;
+ nearest_point = i;
+ if (founded)
+ break;
+ founded = true;
+ }
+ }
+ }
+ if (founded) {
+ if (points[nearest_point].offset < newofs)
+ newofs = points[nearest_point].offset+0.00001;
+ else
+ newofs = points[nearest_point].offset-0.00001;
+ newofs = CLAMP(newofs,0,1);
+ }
+ }
bool valid=true;
for(int i=0;i<points.size();i++) {
diff --git a/scene/gui/file_dialog.cpp b/scene/gui/file_dialog.cpp
index c53de6568a..8e428fd71c 100644
--- a/scene/gui/file_dialog.cpp
+++ b/scene/gui/file_dialog.cpp
@@ -686,7 +686,7 @@ void FileDialog::set_default_show_hidden_files(bool p_show) {
FileDialog::FileDialog() {
- show_hidden_files=true;
+ show_hidden_files=default_show_hidden_files;
VBoxContainer *vbc = memnew( VBoxContainer );
add_child(vbc);
diff --git a/scene/gui/item_list.cpp b/scene/gui/item_list.cpp
index 2fd4d810de..c29f6625d3 100644
--- a/scene/gui/item_list.cpp
+++ b/scene/gui/item_list.cpp
@@ -11,6 +11,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.custom_bg=Color(0,0,0,0);
items.push_back(item);
update();
@@ -26,6 +27,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.custom_bg=Color(0,0,0,0);
items.push_back(item);
update();
@@ -85,6 +87,23 @@ Ref<Texture> ItemList::get_item_icon(int p_idx) const{
}
+void ItemList::set_item_custom_bg_color(int p_idx,const Color& p_custom_bg_color) {
+
+ ERR_FAIL_INDEX(p_idx,items.size());
+
+ items[p_idx].custom_bg=p_custom_bg_color;
+
+}
+
+Color ItemList::get_item_custom_bg_color(int p_idx) const {
+
+ ERR_FAIL_INDEX_V(p_idx,items.size(),Color());
+
+ return items[p_idx].custom_bg;
+
+}
+
+
void ItemList::set_item_tag_icon(int p_idx,const Ref<Texture>& p_tag_icon){
@@ -635,6 +654,7 @@ void ItemList::_notification(int p_what) {
Ref<Font> font = get_font("font");
Color guide_color = get_color("guide_color");
Color font_color = get_color("font_color");
+ Color font_color_selected = get_color("font_color_selected");
int font_height = font->get_height();
Vector<int> line_size_cache;
Vector<int> line_limit_cache;
@@ -781,6 +801,11 @@ void ItemList::_notification(int p_what) {
if (current_columns==1) {
rcache.size.width = width-rcache.pos.x;
}
+ if (items[i].custom_bg.a>0.001) {
+ Rect2 r=rcache;
+ r.pos+=base_ofs;
+ draw_rect(r,items[i].custom_bg);
+ }
if (items[i].selected) {
Rect2 r=rcache;
r.pos+=base_ofs;
@@ -864,7 +889,7 @@ void ItemList::_notification(int p_what) {
if (line>=max_text_lines)
break;
}
- ofs+=font->draw_char(get_canvas_item(),text_ofs+Vector2(ofs+(max_len-line_size_cache[line])/2,line*(font_height+line_separation)).floor(),items[i].text[j],items[i].text[j+1],font_color);
+ ofs+=font->draw_char(get_canvas_item(),text_ofs+Vector2(ofs+(max_len-line_size_cache[line])/2,line*(font_height+line_separation)).floor(),items[i].text[j],items[i].text[j+1],items[i].selected?font_color_selected:font_color);
}
//special multiline mode
@@ -884,7 +909,7 @@ void ItemList::_notification(int p_what) {
text_ofs+=base_ofs;
text_ofs+=items[i].rect_cache.pos;
- draw_string(font,text_ofs,items[i].text,font_color,max_len+1);
+ draw_string(font,text_ofs,items[i].text,items[i].selected?font_color_selected:font_color,max_len+1);
}
@@ -954,6 +979,30 @@ String ItemList::get_tooltip(const Point2& p_pos) const {
}
+void ItemList::sort_items_by_text() {
+ items.sort();
+ update();
+ if (select_mode==SELECT_SINGLE) {
+ for(int i=0;i<items.size();i++) {
+ if (items[i].selected) {
+ select(i);
+ return;
+ }
+ }
+ }
+}
+
+int ItemList::find_metadata(const Variant& p_metadata) const {
+
+ for(int i=0;i<items.size();i++) {
+ if (items[i].metadata==p_metadata) {
+ return i;
+ }
+ }
+
+ return -1;
+
+}
void ItemList::_bind_methods(){
@@ -972,6 +1021,12 @@ void ItemList::_bind_methods(){
ObjectTypeDB::bind_method(_MD("set_item_disabled","idx","disabled"),&ItemList::set_item_disabled);
ObjectTypeDB::bind_method(_MD("is_item_disabled","idx"),&ItemList::is_item_disabled);
+ ObjectTypeDB::bind_method(_MD("set_item_metadata","idx","metadata"),&ItemList::set_item_metadata);
+ ObjectTypeDB::bind_method(_MD("get_item_metadata","idx"),&ItemList::get_item_metadata);
+
+ 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","idx","tooltip"),&ItemList::set_item_tooltip);
ObjectTypeDB::bind_method(_MD("get_item_tooltip","idx"),&ItemList::get_item_tooltip);
@@ -983,6 +1038,7 @@ void ItemList::_bind_methods(){
ObjectTypeDB::bind_method(_MD("remove_item","idx"),&ItemList::remove_item);
ObjectTypeDB::bind_method(_MD("clear"),&ItemList::clear);
+ ObjectTypeDB::bind_method(_MD("sort_items_by_text"),&ItemList::clear);
ObjectTypeDB::bind_method(_MD("set_fixed_column_width","width"),&ItemList::set_fixed_column_width);
ObjectTypeDB::bind_method(_MD("get_fixed_column_width"),&ItemList::get_fixed_column_width);
diff --git a/scene/gui/item_list.h b/scene/gui/item_list.h
index 6bbb416970..237079c428 100644
--- a/scene/gui/item_list.h
+++ b/scene/gui/item_list.h
@@ -29,8 +29,12 @@ private:
bool disabled;
Variant metadata;
String tooltip;
+ Color custom_bg;
+
Rect2 rect_cache;
+
+ bool operator<(const Item& p_another) const { return text<p_another.text; }
};
int current;
@@ -85,6 +89,9 @@ public:
void set_item_tooltip(int p_idx,const String& p_tooltip);
String get_item_tooltip(int p_idx) const;
+ void set_item_custom_bg_color(int p_idx,const Color& p_custom_bg_color);
+ Color get_item_custom_bg_color(int p_idx) const;
+
void select(int p_idx,bool p_single=true);
void unselect(int p_idx);
bool is_selected(int p_idx) const;
@@ -118,6 +125,8 @@ public:
void ensure_current_is_visible();
+ void sort_items_by_text();
+ int find_metadata(const Variant& p_metadata) const;
virtual String get_tooltip(const Point2& p_pos) const;
diff --git a/scene/gui/tabs.cpp b/scene/gui/tabs.cpp
index 37369a7e6c..40a6e20c37 100644
--- a/scene/gui/tabs.cpp
+++ b/scene/gui/tabs.cpp
@@ -77,8 +77,8 @@ void Tabs::_input_event(const InputEvent& p_event) {
for(int i=0;i<tabs.size();i++) {
int ofs=tabs[i].ofs_cache;
-
- if (pos.x < ofs) {
+ int size = tabs[i].ofs_cache;
+ if (pos.x >=tabs[i].ofs_cache && pos.x<tabs[i].ofs_cache+tabs[i].size_cache) {
found=i;
break;
@@ -89,6 +89,7 @@ void Tabs::_input_event(const InputEvent& p_event) {
if (found!=-1) {
set_current_tab(found);
+ emit_signal("tab_changed",found);
}
}
@@ -117,8 +118,22 @@ void Tabs::_notification(int p_what) {
int w=0;
+ int mw = get_minimum_size().width;
+
+ if (tab_align==ALIGN_CENTER) {
+ w=(get_size().width-mw)/2;
+ } else if (tab_align==ALIGN_RIGHT) {
+ w=get_size().width-mw;
+
+ }
+
+ if (w<0) {
+ w=0;
+ }
+
for(int i=0;i<tabs.size();i++) {
+ tabs[i].ofs_cache=w;
String s = tabs[i].text;
int lsize=0;
@@ -171,7 +186,7 @@ void Tabs::_notification(int p_what) {
w+=slen+sb->get_margin(MARGIN_RIGHT);
- tabs[i].ofs_cache=w;
+ tabs[i].size_cache=w-tabs[i].ofs_cache;
}
@@ -195,7 +210,7 @@ void Tabs::set_current_tab(int p_current) {
current=p_current;
_change_notify("current_tab");
- emit_signal("tab_changed",current);
+ //emit_signal("tab_changed",current);
update();
}
@@ -249,6 +264,12 @@ void Tabs::add_tab(const String& p_str,const Ref<Texture>& p_icon) {
}
+void Tabs::clear_tabs() {
+ tabs.clear();
+ current=0;
+ update();
+}
+
void Tabs::remove_tab(int p_idx) {
ERR_FAIL_INDEX(p_idx,tabs.size());
@@ -263,8 +284,19 @@ void Tabs::remove_tab(int p_idx) {
if (current>=tabs.size())
current=tabs.size()-1;
- emit_signal("tab_changed",current);
+ //emit_signal("tab_changed",current);
+
+}
+
+void Tabs::set_tab_align(TabAlign p_align) {
+
+ tab_align=p_align;
+ update();
+}
+
+Tabs::TabAlign Tabs::get_tab_align() const {
+ return tab_align;
}
@@ -280,15 +312,21 @@ void Tabs::_bind_methods() {
ObjectTypeDB::bind_method(_MD("get_tab_icon:Texture","tab_idx"),&Tabs::get_tab_icon);
ObjectTypeDB::bind_method(_MD("remove_tab","tab_idx"),&Tabs::remove_tab);
ObjectTypeDB::bind_method(_MD("add_tab","title","icon:Texture"),&Tabs::add_tab);
+ ObjectTypeDB::bind_method(_MD("set_tab_align","align"),&Tabs::set_tab_align);
+ ObjectTypeDB::bind_method(_MD("get_tab_align"),&Tabs::get_tab_align);
ADD_SIGNAL(MethodInfo("tab_changed",PropertyInfo(Variant::INT,"tab")));
ADD_PROPERTY( PropertyInfo(Variant::INT, "current_tab", PROPERTY_HINT_RANGE,"-1,4096,1",PROPERTY_USAGE_EDITOR), _SCS("set_current_tab"), _SCS("get_current_tab") );
+ BIND_CONSTANT( ALIGN_LEFT );
+ BIND_CONSTANT( ALIGN_CENTER );
+ BIND_CONSTANT( ALIGN_RIGHT );
}
Tabs::Tabs() {
current=0;
+ tab_align=ALIGN_CENTER;
}
diff --git a/scene/gui/tabs.h b/scene/gui/tabs.h
index 4a969928ff..8d4d0123f8 100644
--- a/scene/gui/tabs.h
+++ b/scene/gui/tabs.h
@@ -34,6 +34,14 @@
class Tabs : public Control {
OBJ_TYPE( Tabs, Control );
+public:
+
+ enum TabAlign {
+
+ ALIGN_LEFT,
+ ALIGN_CENTER,
+ ALIGN_RIGHT
+ };
private:
@@ -42,12 +50,14 @@ private:
String text;
Ref<Texture> icon;
int ofs_cache;
+ int size_cache;
};
Vector<Tab> tabs;
int current;
Control *_get_tab(int idx) const;
int _get_top_margin() const;
+ TabAlign tab_align;
protected:
@@ -65,16 +75,22 @@ public:
void set_tab_icon(int p_tab,const Ref<Texture>& p_icon);
Ref<Texture> get_tab_icon(int p_tab) const;
+ void set_tab_align(TabAlign p_align);
+ TabAlign get_tab_align() const;
+
int get_tab_count() const;
void set_current_tab(int p_current);
int get_current_tab() const;
void remove_tab(int p_idx);
+ void clear_tabs();
+
Size2 get_minimum_size() const;
Tabs();
};
+VARIANT_ENUM_CAST(Tabs::TabAlign);
#endif // TABS_H
diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp
index c497bc5363..44e97b5889 100644
--- a/scene/gui/text_edit.cpp
+++ b/scene/gui/text_edit.cpp
@@ -3323,9 +3323,32 @@ void TextEdit::_update_completion_candidates() {
//look for keywords first
- bool pre_keyword=false;
+ bool inquote=false;
+ int first_quote=-1;
+
+ int c=cofs-1;
+ while(c>=0) {
+ if (l[c]=='"' || l[c]=='\'') {
+ inquote=!inquote;
+ if (first_quote==-1)
+ first_quote=c;
+ }
+ c--;
+ }
- if (cofs>0 && l[cofs-1]==' ') {
+ bool pre_keyword=false;
+ bool cancel=false;
+
+ //print_line("inquote: "+itos(inquote)+"first quote "+itos(first_quote)+" cofs-1 "+itos(cofs-1));
+ if (!inquote && first_quote==cofs-1) {
+ //no completion here
+ //print_line("cancel!");
+ cancel=true;
+ } if (inquote && first_quote!=-1) {
+
+ s=l.substr(first_quote,cofs-first_quote);
+ //print_line("s: 1"+s);
+ } else if (cofs>0 && l[cofs-1]==' ') {
int kofs=cofs-1;
String kw;
while (kofs>=0 && l[kofs]==' ')
@@ -3337,7 +3360,7 @@ void TextEdit::_update_completion_candidates() {
}
pre_keyword=keywords.has(kw);
- print_line("KW "+kw+"? "+itos(pre_keyword));
+ //print_line("KW "+kw+"? "+itos(pre_keyword));
} else {
@@ -3354,7 +3377,7 @@ void TextEdit::_update_completion_candidates() {
update();
- if (!pre_keyword && s=="" && (cofs==0 || !completion_prefixes.has(String::chr(l[cofs-1])))) {
+ if (cancel || (!pre_keyword && s=="" && (cofs==0 || !completion_prefixes.has(String::chr(l[cofs-1]))))) {
//none to complete, cancel
_cancel_completion();
return;
@@ -3421,7 +3444,16 @@ void TextEdit::query_code_comple() {
String l = text[cursor.line];
int ofs = CLAMP(cursor.column,0,l.length());
- if (ofs>0 && (_is_completable(l[ofs-1]) || completion_prefixes.has(String::chr(l[ofs-1]))))
+ bool inquote=false;
+
+ int c=ofs-1;
+ while(c>=0) {
+ if (l[c]=='"' || l[c]=='\'')
+ inquote=!inquote;
+ c--;
+ }
+
+ if (ofs>0 && (inquote || _is_completable(l[ofs-1]) || completion_prefixes.has(String::chr(l[ofs-1]))))
emit_signal("request_completion");
}
diff --git a/scene/gui/tree.h b/scene/gui/tree.h
index f03827f542..8ddddd0630 100644
--- a/scene/gui/tree.h
+++ b/scene/gui/tree.h
@@ -454,6 +454,8 @@ public:
void set_cursor_can_exit_tree(bool p_enable);
bool can_cursor_exit_tree() const;
+ VScrollBar *get_vscroll_bar() { return v_scroll; }
+
Tree();
~Tree();