summaryrefslogtreecommitdiff
path: root/scene/gui
diff options
context:
space:
mode:
Diffstat (limited to 'scene/gui')
-rw-r--r--scene/gui/item_list.cpp140
-rw-r--r--scene/gui/item_list.h12
-rw-r--r--scene/gui/line_edit.cpp117
-rw-r--r--scene/gui/line_edit.h28
-rw-r--r--scene/gui/text_edit.cpp66
-rw-r--r--scene/gui/text_edit.h18
-rw-r--r--scene/gui/tree.cpp69
-rw-r--r--scene/gui/tree.h9
8 files changed, 401 insertions, 58 deletions
diff --git a/scene/gui/item_list.cpp b/scene/gui/item_list.cpp
index bf66a770d3..c1a0e43e49 100644
--- a/scene/gui/item_list.cpp
+++ b/scene/gui/item_list.cpp
@@ -383,6 +383,17 @@ Size2 ItemList::get_min_icon_size() const {
return min_icon_size;
}
+
+void ItemList::set_max_icon_size(const Size2& p_size) {
+
+ max_icon_size=p_size;
+ update();
+}
+
+Size2 ItemList::get_max_icon_size() const {
+
+ return max_icon_size;
+}
Size2 ItemList::Item::get_icon_size() const {
if (icon.is_null())
@@ -399,16 +410,18 @@ void ItemList::_input_event(const InputEvent& p_event) {
defer_select_single=-1;
return;
}
+
if (defer_select_single>=0 && p_event.type==InputEvent::MOUSE_BUTTON && p_event.mouse_button.button_index==BUTTON_LEFT && !p_event.mouse_button.pressed) {
select(defer_select_single,true);
+
emit_signal("multi_selected",defer_select_single,true);
defer_select_single=-1;
return;
}
- if (p_event.type==InputEvent::MOUSE_BUTTON && p_event.mouse_button.button_index==BUTTON_LEFT && p_event.mouse_button.pressed) {
+ if (p_event.type==InputEvent::MOUSE_BUTTON && (p_event.mouse_button.button_index==BUTTON_LEFT || (allow_rmb_select && p_event.mouse_button.button_index==BUTTON_RIGHT)) && p_event.mouse_button.pressed) {
const InputEventMouseButton &mb = p_event.mouse_button;
@@ -447,6 +460,7 @@ void ItemList::_input_event(const InputEvent& p_event) {
if (select_mode==SELECT_MULTI && items[i].selected && mb.mod.command) {
unselect(i);
emit_signal("multi_selected",i,false);
+
} else if (select_mode==SELECT_MULTI && mb.mod.shift && current>=0 && current<items.size() && current!=i) {
int from = current;
@@ -460,29 +474,45 @@ void ItemList::_input_event(const InputEvent& p_event) {
if (selected)
emit_signal("multi_selected",i,true);
}
+
+ if (p_event.mouse_button.button_index==BUTTON_RIGHT) {
+
+ emit_signal("item_rmb_selected",i,Vector2(mb.x,mb.y));
+ }
} else {
- if (!mb.doubleclick && !mb.mod.command && select_mode==SELECT_MULTI && items[i].selectable && items[i].selected) {
+ if (!mb.doubleclick && !mb.mod.command && select_mode==SELECT_MULTI && items[i].selectable && items[i].selected && p_event.mouse_button.button_index==BUTTON_LEFT) {
defer_select_single=i;
return;
}
- bool selected = !items[i].selected;
- select(i,select_mode==SELECT_SINGLE || !mb.mod.command);
- if (selected) {
- if (select_mode==SELECT_SINGLE) {
- emit_signal("item_selected",i);
- } else
- emit_signal("multi_selected",i,true);
- }
+ if (items[i].selected && p_event.mouse_button.button_index==BUTTON_RIGHT) {
- if (/*select_mode==SELECT_SINGLE &&*/ mb.doubleclick) {
+ emit_signal("item_rmb_selected",i,Vector2(mb.x,mb.y));
+ } else {
+ bool selected = !items[i].selected;
- emit_signal("item_activated",i);
- }
+ select(i,select_mode==SELECT_SINGLE || !mb.mod.command);
+
+ if (selected) {
+ if (select_mode==SELECT_SINGLE) {
+ emit_signal("item_selected",i);
+ } else
+ emit_signal("multi_selected",i,true);
+
+
+ }
+
+ if (p_event.mouse_button.button_index==BUTTON_RIGHT) {
+ emit_signal("item_rmb_selected",i,Vector2(mb.x,mb.y));
+ } else if (/*select_mode==SELECT_SINGLE &&*/ mb.doubleclick) {
+ emit_signal("item_activated",i);
+
+ }
+ }
}
@@ -690,6 +720,55 @@ void ItemList::ensure_current_is_visible() {
update();
}
+static Size2 _adjust_to_max_size(Size2 p_size, Size2 p_max_size) {
+
+ if (p_max_size.x<=0)
+ p_max_size.x=1e20;
+ if (p_max_size.y<=0)
+ p_max_size.y=1e20;
+
+
+ Size2 new_size;
+
+ if (p_size.x > p_max_size.x) {
+
+ new_size.width=p_max_size.x;
+ new_size.height=p_size.height * p_max_size.width / p_size.width;
+
+ if (new_size.height > p_max_size.height) {
+ new_size=Size2(); //invalid
+ }
+ }
+
+
+ if (p_size.y > p_max_size.y) {
+
+ Size2 new_size2;
+ new_size2.height=p_max_size.y;
+ new_size2.width=p_size.width * p_max_size.height / p_size.height;
+
+ if (new_size2.width < p_max_size.width) {
+
+ if (new_size!=Size2()) {
+
+ if (new_size2.x*new_size2.y > new_size.x*new_size.y) {
+ new_size=new_size2;
+ }
+ } else {
+ new_size=new_size2;
+ }
+ }
+
+ }
+
+ if (new_size==Size2())
+ return p_size;
+ else
+ return new_size;
+
+
+}
+
void ItemList::_notification(int p_what) {
if (p_what==NOTIFICATION_RESIZED) {
@@ -752,12 +831,7 @@ void ItemList::_notification(int p_what) {
Size2 minsize;
if (items[i].icon.is_valid()) {
- minsize=items[i].get_icon_size();
-
- if (min_icon_size.x!=0)
- minsize.x = MAX(minsize.x,min_icon_size.x);
- if (min_icon_size.y!=0)
- minsize.y = MAX(minsize.y,min_icon_size.y);
+ minsize=_adjust_to_max_size(items[i].get_icon_size(),max_icon_size);
if (items[i].text!="") {
if (icon_mode==ICON_MODE_TOP) {
@@ -902,7 +976,7 @@ void ItemList::_notification(int p_what) {
Vector2 text_ofs;
if (items[i].icon.is_valid()) {
- Size2 icon_size = items[i].get_icon_size();
+ Size2 icon_size = _adjust_to_max_size(items[i].get_icon_size(),max_icon_size);
Vector2 icon_ofs;
if (min_icon_size!=Vector2()) {
@@ -922,7 +996,7 @@ void ItemList::_notification(int p_what) {
}
if (items[i].icon_region.has_no_area())
- draw_texture(items[i].icon, pos);
+ draw_texture_rect(items[i].icon, Rect2(pos,icon_size) );
else
draw_texture_rect_region(items[i].icon, Rect2(pos, icon_size), items[i].icon_region);
@@ -1044,7 +1118,7 @@ void ItemList::_scroll_changed(double) {
update();
}
-int ItemList::get_item_at_pos(const Point2& p_pos) const {
+int ItemList::get_item_at_pos(const Point2& p_pos, bool p_exact) const {
Vector2 pos=p_pos;
Ref<StyleBox> bg = get_stylebox("bg");
@@ -1067,7 +1141,7 @@ int ItemList::get_item_at_pos(const Point2& p_pos) const {
}
float dist = rc.distance_to(pos);
- if (dist<closest_dist) {
+ if (!p_exact && dist<closest_dist) {
closest=i;
closest_dist=dist;
}
@@ -1117,6 +1191,16 @@ int ItemList::find_metadata(const Variant& p_metadata) const {
}
+
+void ItemList::set_allow_rmb_select(bool p_allow) {
+ allow_rmb_select=p_allow;
+}
+
+bool ItemList::get_allow_rmb_select() const {
+
+ return allow_rmb_select;
+}
+
void ItemList::_bind_methods(){
ObjectTypeDB::bind_method(_MD("add_item","text","icon:Texture","selectable"),&ItemList::add_item,DEFVAL(Variant()),DEFVAL(true));
@@ -1174,7 +1258,13 @@ void ItemList::_bind_methods(){
ObjectTypeDB::bind_method(_MD("set_min_icon_size","size"),&ItemList::set_min_icon_size);
ObjectTypeDB::bind_method(_MD("get_min_icon_size"),&ItemList::get_min_icon_size);
- ObjectTypeDB::bind_method(_MD("get_item_at_pos","pos"),&ItemList::get_item_at_pos);
+ ObjectTypeDB::bind_method(_MD("set_max_icon_size","size"),&ItemList::set_max_icon_size);
+ ObjectTypeDB::bind_method(_MD("get_max_icon_size"),&ItemList::get_max_icon_size);
+
+ ObjectTypeDB::bind_method(_MD("set_allow_rmb_select","allow"),&ItemList::set_allow_rmb_select);
+ ObjectTypeDB::bind_method(_MD("get_allow_rmb_select"),&ItemList::get_allow_rmb_select);
+
+ ObjectTypeDB::bind_method(_MD("get_item_at_pos","pos","exact"),&ItemList::get_item_at_pos,DEFVAL(false));
ObjectTypeDB::bind_method(_MD("ensure_current_is_visible"),&ItemList::ensure_current_is_visible);
@@ -1187,6 +1277,7 @@ void ItemList::_bind_methods(){
BIND_CONSTANT( SELECT_MULTI );
ADD_SIGNAL( MethodInfo("item_selected",PropertyInfo(Variant::INT,"index")));
+ ADD_SIGNAL( MethodInfo("item_rmb_selected",PropertyInfo(Variant::INT,"index"),PropertyInfo(Variant::VECTOR2,"atpos")));
ADD_SIGNAL( MethodInfo("multi_selected",PropertyInfo(Variant::INT,"index"),PropertyInfo(Variant::BOOL,"selected")));
ADD_SIGNAL( MethodInfo("item_activated",PropertyInfo(Variant::INT,"index")));
}
@@ -1215,6 +1306,7 @@ ItemList::ItemList() {
search_time_msec=0;
ensure_selected_visible=false;
defer_select_single=-1;
+ allow_rmb_select=false;
}
diff --git a/scene/gui/item_list.h b/scene/gui/item_list.h
index fcb4dfae5a..59fa1d8270 100644
--- a/scene/gui/item_list.h
+++ b/scene/gui/item_list.h
@@ -60,9 +60,11 @@ private:
int max_text_lines;
int max_columns;
Size2 min_icon_size;
-
+ Size2 max_icon_size;
int defer_select_single;
+ bool allow_rmb_select;
+
void _scroll_changed(double);
void _input_event(const InputEvent& p_event);
protected:
@@ -134,13 +136,19 @@ public:
void set_min_icon_size(const Size2& p_size);
Size2 get_min_icon_size() const;
+ void set_max_icon_size(const Size2& p_size);
+ Size2 get_max_icon_size() const;
+
+ void set_allow_rmb_select(bool p_allow);
+ bool get_allow_rmb_select() const;
+
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;
- int get_item_at_pos(const Point2& p_pos) const;
+ int get_item_at_pos(const Point2& p_pos,bool p_exact=false) const;
ItemList();
~ItemList();
diff --git a/scene/gui/line_edit.cpp b/scene/gui/line_edit.cpp
index 21dee62b38..14dac454bd 100644
--- a/scene/gui/line_edit.cpp
+++ b/scene/gui/line_edit.cpp
@@ -41,7 +41,15 @@ void LineEdit::_input_event(InputEvent p_event) {
const InputEventMouseButton &b = p_event.mouse_button;
- if (b.button_index!=1)
+ if (b.pressed && b.button_index==BUTTON_RIGHT) {
+ menu->set_pos(get_global_transform().xform(get_local_mouse_pos()));
+ menu->set_size(Vector2(1,1));
+ menu->popup();
+ grab_focus();
+ return;
+ }
+
+ if (b.button_index!=BUTTON_LEFT)
break;
if (b.pressed) {
@@ -143,24 +151,10 @@ void LineEdit::_input_event(InputEvent p_event) {
if( k.mod.command && editable) {
- int old_cursor_pos = cursor_pos;
- text = undo_text;
-
- Ref<Font> font = get_font("font");
-
- cached_width = 0;
- for (int i = 0; i<text.length(); i++)
- cached_width += font->get_char_size(text[i]).width;
+ undo();
- if(old_cursor_pos > text.length()) {
- set_cursor_pos(text.length());
- } else {
- set_cursor_pos(old_cursor_pos);
- }
}
- emit_signal("text_changed",text);
- _change_notify("text");
} break;
@@ -559,6 +553,28 @@ void LineEdit::paste_text() {
}
+void LineEdit::undo() {
+
+ int old_cursor_pos = cursor_pos;
+ text = undo_text;
+
+ Ref<Font> font = get_font("font");
+
+ cached_width = 0;
+ for (int i = 0; i<text.length(); i++)
+ cached_width += font->get_char_size(text[i]).width;
+
+ if(old_cursor_pos > text.length()) {
+ set_cursor_pos(text.length());
+ } else {
+ set_cursor_pos(old_cursor_pos);
+ }
+
+ emit_signal("text_changed",text);
+ _change_notify("text");
+
+}
+
void LineEdit::shift_selection_check_pre(bool p_shift) {
if (!selection.old_shift && p_shift) {
@@ -669,6 +685,8 @@ void LineEdit::set_text(String p_text) {
void LineEdit::clear() {
clear_internal();
+ emit_signal("text_changed",text);
+ _change_notify("text");
}
String LineEdit::get_text() const {
@@ -932,6 +950,39 @@ bool LineEdit::is_text_field() const {
return true;
}
+void LineEdit::menu_option(int p_option) {
+
+ switch(p_option) {
+ case MENU_CUT: {
+ cut_text();
+ } break;
+ case MENU_COPY: {
+
+ copy_text();
+ } break;
+ case MENU_PASTE: {
+
+ paste_text();
+ } break;
+ case MENU_CLEAR: {
+ clear();
+ } break;
+ case MENU_SELECT_ALL: {
+ select_all();
+ } break;
+ case MENU_UNDO: {
+
+ undo();
+ } break;
+
+ }
+
+}
+
+PopupMenu *LineEdit::get_menu() const {
+ return menu;
+}
+
void LineEdit::_bind_methods() {
ObjectTypeDB::bind_method(_MD("set_align", "align"), &LineEdit::set_align);
@@ -952,6 +1003,8 @@ void LineEdit::_bind_methods() {
ObjectTypeDB::bind_method(_MD("set_secret","enabled"),&LineEdit::set_secret);
ObjectTypeDB::bind_method(_MD("is_secret"),&LineEdit::is_secret);
ObjectTypeDB::bind_method(_MD("select","from","to"),&LineEdit::select,DEFVAL(0),DEFVAL(-1));
+ ObjectTypeDB::bind_method(_MD("menu_option","option"),&LineEdit::menu_option);
+ ObjectTypeDB::bind_method(_MD("get_menu:PopupMenu"),&LineEdit::get_menu);
ADD_SIGNAL( MethodInfo("text_changed", PropertyInfo( Variant::STRING, "text" )) );
ADD_SIGNAL( MethodInfo("text_entered", PropertyInfo( Variant::STRING, "text" )) );
@@ -961,11 +1014,21 @@ void LineEdit::_bind_methods() {
BIND_CONSTANT(ALIGN_RIGHT);
BIND_CONSTANT(ALIGN_FILL);
- ADD_PROPERTY( PropertyInfo( Variant::STRING, "text" ), _SCS("set_text"),_SCS("get_text") );
+ BIND_CONSTANT( MENU_CUT );
+ BIND_CONSTANT( MENU_COPY );
+ BIND_CONSTANT( MENU_PASTE );
+ BIND_CONSTANT( MENU_CLEAR );
+ BIND_CONSTANT( MENU_SELECT_ALL );
+ BIND_CONSTANT( MENU_UNDO );
+ BIND_CONSTANT( MENU_MAX );
+
+ ADD_PROPERTYNZ( PropertyInfo( Variant::STRING, "text" ), _SCS("set_text"),_SCS("get_text") );
ADD_PROPERTYNZ(PropertyInfo(Variant::INT, "align", PROPERTY_HINT_ENUM, "Left,Center,Right,Fill"), _SCS("set_align"), _SCS("get_align"));
- ADD_PROPERTY( PropertyInfo( Variant::INT, "max_length" ), _SCS("set_max_length"),_SCS("get_max_length") );
- ADD_PROPERTY( PropertyInfo( Variant::BOOL, "editable" ), _SCS("set_editable"),_SCS("is_editable") );
- ADD_PROPERTY( PropertyInfo( Variant::BOOL, "secret" ), _SCS("set_secret"),_SCS("is_secret") );
+ 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") );
+
+
}
LineEdit::LineEdit() {
@@ -984,6 +1047,20 @@ LineEdit::LineEdit() {
set_stop_mouse(true);
+ menu = memnew( PopupMenu );
+ add_child(menu);
+ menu->add_item(TTR("Cut"),MENU_CUT,KEY_MASK_CMD|KEY_X);
+ menu->add_item(TTR("Copy"),MENU_COPY,KEY_MASK_CMD|KEY_C);
+ menu->add_item(TTR("Paste"),MENU_PASTE,KEY_MASK_CMD|KEY_V);
+ menu->add_separator();
+ menu->add_item(TTR("Select All"),MENU_SELECT_ALL,KEY_MASK_CMD|KEY_A);
+ menu->add_item(TTR("Clear"),MENU_CLEAR);
+ menu->add_separator();
+ menu->add_item(TTR("Undo"),MENU_UNDO,KEY_MASK_CMD|KEY_Z);
+ menu->connect("item_pressed",this,"menu_option");
+
+
+
}
LineEdit::~LineEdit() {
diff --git a/scene/gui/line_edit.h b/scene/gui/line_edit.h
index 207c6b115b..586a54e950 100644
--- a/scene/gui/line_edit.h
+++ b/scene/gui/line_edit.h
@@ -30,6 +30,8 @@
#define LINE_EDIT_H
#include "scene/gui/control.h"
+#include "scene/gui/popup_menu.h"
+
/**
@author Juan Linietsky <reduzio@gmail.com>
*/
@@ -45,6 +47,18 @@ public:
ALIGN_RIGHT,
ALIGN_FILL
};
+
+ enum MenuItems {
+ MENU_CUT,
+ MENU_COPY,
+ MENU_PASTE,
+ MENU_CLEAR,
+ MENU_SELECT_ALL,
+ MENU_UNDO,
+ MENU_MAX
+
+ };
+
private:
Align align;
@@ -54,6 +68,8 @@ private:
String undo_text;
String text;
+ PopupMenu *menu;
+
int cursor_pos;
int window_pos;
int max_length; // 0 for no maximum
@@ -85,14 +101,12 @@ private:
void clear_internal();
void changed_internal();
- void copy_text();
- void cut_text();
- void paste_text();
void _input_event(InputEvent p_event);
void _notification(int p_what);
+
protected:
static void _bind_methods();
public:
@@ -103,6 +117,8 @@ public:
virtual bool can_drop_data(const Point2& p_point,const Variant& p_data) const;
virtual void drop_data(const Point2& p_point,const Variant& p_data);
+ void menu_option(int p_option);
+ PopupMenu *get_menu() const;
void select_all();
@@ -116,6 +132,10 @@ public:
void append_at_cursor(String p_text);
void clear();
+ void copy_text();
+ void cut_text();
+ void paste_text();
+ void undo();
void set_editable(bool p_editable);
bool is_editable() const;
@@ -127,7 +147,7 @@ public:
virtual Size2 get_minimum_size() const;
- virtual bool is_text_field() const;
+ virtual bool is_text_field() const;
LineEdit();
~LineEdit();
diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp
index 7bbdc38d50..03024daff5 100644
--- a/scene/gui/text_edit.cpp
+++ b/scene/gui/text_edit.cpp
@@ -1534,6 +1534,15 @@ void TextEdit::_input_event(const InputEvent& p_input_event) {
update();
}
+
+ if (mb.button_index==BUTTON_RIGHT) {
+
+ menu->set_pos(get_global_transform().xform(get_local_mouse_pos()));
+ menu->set_size(Vector2(1,1));
+ menu->popup();
+ grab_focus();
+
+ }
} else {
if (mb.button_index==BUTTON_LEFT)
@@ -4162,6 +4171,38 @@ bool TextEdit::is_text_field() const {
return true;
}
+
+void TextEdit::menu_option(int p_option) {
+
+ switch( p_option ) {
+ case MENU_CUT: {
+
+ cut();
+ } break;
+ case MENU_COPY: {
+ copy();
+ } break;
+ case MENU_PASTE: {
+
+ paste();
+ } break;
+ case MENU_CLEAR: {
+ clear();
+ } break;
+ case MENU_SELECT_ALL: {
+ select_all();
+ } break;
+ case MENU_UNDO: {
+ undo();
+ } break;
+
+ };
+}
+
+PopupMenu *TextEdit::get_menu() const {
+ return menu;
+}
+
void TextEdit::_bind_methods() {
@@ -4231,6 +4272,8 @@ void TextEdit::_bind_methods() {
ObjectTypeDB::bind_method(_MD("set_symbol_color","color"),&TextEdit::set_symbol_color);
ObjectTypeDB::bind_method(_MD("set_custom_bg_color","color"),&TextEdit::set_custom_bg_color);
ObjectTypeDB::bind_method(_MD("clear_colors"),&TextEdit::clear_colors);
+ ObjectTypeDB::bind_method(_MD("menu_option"),&TextEdit::menu_option);
+ ObjectTypeDB::bind_method(_MD("get_menu:PopupMenu"),&TextEdit::get_menu);
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") );
@@ -4239,6 +4282,15 @@ void TextEdit::_bind_methods() {
ADD_SIGNAL(MethodInfo("text_changed"));
ADD_SIGNAL(MethodInfo("request_completion"));
+ BIND_CONSTANT( MENU_CUT );
+ BIND_CONSTANT( MENU_COPY );
+ BIND_CONSTANT( MENU_PASTE );
+ BIND_CONSTANT( MENU_CLEAR );
+ BIND_CONSTANT( MENU_SELECT_ALL );
+ BIND_CONSTANT( MENU_UNDO );
+ BIND_CONSTANT( MENU_MAX );
+
+
}
TextEdit::TextEdit() {
@@ -4343,6 +4395,20 @@ TextEdit::TextEdit() {
brace_matching_enabled=false;
auto_indent=false;
insert_mode = false;
+
+ menu = memnew( PopupMenu );
+ add_child(menu);
+ menu->add_item(TTR("Cut"),MENU_CUT,KEY_MASK_CMD|KEY_X);
+ menu->add_item(TTR("Copy"),MENU_COPY,KEY_MASK_CMD|KEY_C);
+ menu->add_item(TTR("Paste"),MENU_PASTE,KEY_MASK_CMD|KEY_V);
+ menu->add_separator();
+ menu->add_item(TTR("Select All"),MENU_SELECT_ALL,KEY_MASK_CMD|KEY_A);
+ menu->add_item(TTR("Clear"),MENU_CLEAR);
+ menu->add_separator();
+ menu->add_item(TTR("Undo"),MENU_UNDO,KEY_MASK_CMD|KEY_Z);
+ menu->connect("item_pressed",this,"menu_option");
+
+
}
TextEdit::~TextEdit()
diff --git a/scene/gui/text_edit.h b/scene/gui/text_edit.h
index ea4f148e91..dbe6293240 100644
--- a/scene/gui/text_edit.h
+++ b/scene/gui/text_edit.h
@@ -31,6 +31,7 @@
#include "scene/gui/control.h"
#include "scene/gui/scroll_bar.h"
+#include "scene/gui/popup_menu.h"
#include "scene/main/timer.h"
@@ -290,6 +291,8 @@ class TextEdit : public Control {
DVector<int> _search_bind(const String &p_key,uint32_t p_search_flags, int p_from_line,int p_from_column) const;
+ PopupMenu *menu;
+
void _clear();
void _cancel_completion();
void _cancel_code_hint();
@@ -317,6 +320,17 @@ protected:
public:
+ enum MenuItems {
+ MENU_CUT,
+ MENU_COPY,
+ MENU_PASTE,
+ MENU_CLEAR,
+ MENU_SELECT_ALL,
+ MENU_UNDO,
+ MENU_MAX
+
+ };
+
enum SearchFlags {
SEARCH_MATCH_CASE=1,
@@ -433,6 +447,8 @@ public:
uint32_t get_saved_version() const;
void tag_saved_version();
+ void menu_option(int p_option);
+
void set_show_line_numbers(bool p_show);
void set_tooltip_request_func(Object *p_obj, const StringName& p_function, const Variant& p_udata);
@@ -442,6 +458,8 @@ public:
void set_code_hint(const String& p_hint);
void query_code_comple();
+ PopupMenu *get_menu() const;
+
String get_text_for_completion();
virtual bool is_text_field() const;
diff --git a/scene/gui/tree.cpp b/scene/gui/tree.cpp
index 062a377cee..2c39aea08c 100644
--- a/scene/gui/tree.cpp
+++ b/scene/gui/tree.cpp
@@ -1563,10 +1563,10 @@ int Tree::propagate_mouse_event(const Point2i &p_pos,int x_ofs,int y_ofs,bool p_
col_width-=w+cache.button_margin;
}
- if (p_button==BUTTON_LEFT) {
+ if (p_button==BUTTON_LEFT || (p_button==BUTTON_RIGHT && allow_rmb_select)) {
/* process selection */
- if (p_doubleclick && (!c.editable || c.mode==TreeItem::CELL_MODE_CUSTOM || c.mode==TreeItem::CELL_MODE_ICON || c.mode==TreeItem::CELL_MODE_CHECK)) {
+ if (p_doubleclick && (!c.editable || c.mode==TreeItem::CELL_MODE_CUSTOM || c.mode==TreeItem::CELL_MODE_ICON /*|| c.mode==TreeItem::CELL_MODE_CHECK*/)) { //it' s confusing for check
emit_signal("item_activated");
return -1;
@@ -1574,10 +1574,13 @@ int Tree::propagate_mouse_event(const Point2i &p_pos,int x_ofs,int y_ofs,bool p_
if (select_mode==SELECT_MULTI && p_mod.command && c.selectable) {
- if (!c.selected) {
+ if (!c.selected || p_button==BUTTON_RIGHT) {
p_item->select(col);
emit_signal("multi_selected",p_item,col,true);
+ if (p_button==BUTTON_RIGHT) {
+ emit_signal("item_rmb_selected",get_local_mouse_pos());
+ }
//p_item->selected_signal.call(col);
@@ -1597,15 +1600,25 @@ int Tree::propagate_mouse_event(const Point2i &p_pos,int x_ofs,int y_ofs,bool p_
bool inrange=false;
select_single_item( p_item, root, col,selected_item,&inrange );
+ if (p_button==BUTTON_RIGHT) {
+ emit_signal("item_rmb_selected",get_local_mouse_pos());
+ }
} else {
int icount = _count_selected_items(root);
- if (select_mode==SELECT_MULTI && icount>1) {
+ if (select_mode==SELECT_MULTI && icount>1 && p_button!=BUTTON_RIGHT) {
single_select_defer=p_item;
single_select_defer_column=col;
} else {
- select_single_item( p_item, root, col );
+
+ if (p_button!=BUTTON_RIGHT || !c.selected) {
+ select_single_item( p_item, root, col );
+ }
+
+ if (p_button==BUTTON_RIGHT) {
+ emit_signal("item_rmb_selected",get_local_mouse_pos());
+ }
}
}
@@ -1626,7 +1639,7 @@ int Tree::propagate_mouse_event(const Point2i &p_pos,int x_ofs,int y_ofs,bool p_
/* editing */
- bool bring_up_editor=c.selected;// && already_selected;
+ bool bring_up_editor=force_select_on_already_selected ? (c.selected && already_selected) : c.selected;
bool bring_up_value_editor=false;
String editor_text=c.text;
@@ -2348,12 +2361,13 @@ void Tree::_input_event(InputEvent p_event) {
}
switch(b.button_index) {
+ case BUTTON_RIGHT:
case BUTTON_LEFT: {
Ref<StyleBox> bg = cache.bg;
Point2 pos = Point2(b.x,b.y) - bg->get_offset();
cache.click_type=Cache::CLICK_NONE;
- if (show_column_titles) {
+ if (show_column_titles && b.button_index==BUTTON_LEFT) {
pos.y-=_get_title_button_height();
if (pos.y<0) {
@@ -2375,8 +2389,12 @@ void Tree::_input_event(InputEvent p_event) {
}
}
- if (!root)
+ if (!root || (!root->get_children() && hide_root)) {
+ if (b.button_index==BUTTON_RIGHT && allow_rmb_select) {
+ emit_signal("empty_tree_rmb_selected",get_local_mouse_pos());
+ }
break;
+ }
click_handled=false;
pressing_for_editor=false;
@@ -2390,6 +2408,9 @@ void Tree::_input_event(InputEvent p_event) {
}
+ if (b.button_index==BUTTON_RIGHT)
+ break;
+
if (drag_touching) {
set_fixed_process(false);
drag_touching_deaccel=false;
@@ -3455,6 +3476,27 @@ int Tree::get_drop_mode_flags() const {
return drop_mode_flags;
}
+void Tree::set_single_select_cell_editing_only_when_already_selected(bool p_enable) {
+
+ force_select_on_already_selected=p_enable;
+}
+
+bool Tree::get_single_select_cell_editing_only_when_already_selected() const {
+
+ return force_select_on_already_selected;
+}
+
+
+void Tree::set_allow_rmb_select(bool p_allow) {
+
+ allow_rmb_select=p_allow;
+}
+
+bool Tree::get_allow_rmb_select() const{
+
+ return allow_rmb_select;
+}
+
void Tree::_bind_methods() {
ObjectTypeDB::bind_method(_MD("_range_click_timeout"),&Tree::_range_click_timeout);
@@ -3505,10 +3547,18 @@ void Tree::_bind_methods() {
ObjectTypeDB::bind_method(_MD("set_drop_mode_flags","flags"),&Tree::set_drop_mode_flags);
ObjectTypeDB::bind_method(_MD("get_drop_mode_flags"),&Tree::get_drop_mode_flags);
+ ObjectTypeDB::bind_method(_MD("set_allow_rmb_select","allow"),&Tree::set_allow_rmb_select);
+ ObjectTypeDB::bind_method(_MD("get_allow_rmb_select"),&Tree::get_allow_rmb_select);
+
+
+ ObjectTypeDB::bind_method(_MD("set_single_select_cell_editing_only_when_already_selected","enable"),&Tree::set_single_select_cell_editing_only_when_already_selected);
+ ObjectTypeDB::bind_method(_MD("get_single_select_cell_editing_only_when_already_selected"),&Tree::get_single_select_cell_editing_only_when_already_selected);
ADD_SIGNAL( MethodInfo("item_selected"));
ADD_SIGNAL( MethodInfo("cell_selected"));
ADD_SIGNAL( MethodInfo("multi_selected",PropertyInfo(Variant::OBJECT,"item"),PropertyInfo(Variant::INT,"column"),PropertyInfo(Variant::BOOL,"selected")) );
+ ADD_SIGNAL( MethodInfo("item_rmb_selected",PropertyInfo(Variant::VECTOR2,"pos")));
+ ADD_SIGNAL( MethodInfo("empty_tree_rmb_selected",PropertyInfo(Variant::VECTOR2,"pos")));
ADD_SIGNAL( MethodInfo("item_edited"));
ADD_SIGNAL( MethodInfo("item_collapsed",PropertyInfo(Variant::OBJECT,"item")));
//ADD_SIGNAL( MethodInfo("item_doubleclicked" ) );
@@ -3610,6 +3660,9 @@ Tree::Tree() {
drop_mode_over=NULL;
drop_mode_section=0;
single_select_defer=NULL;
+ force_select_on_already_selected=false;
+
+ allow_rmb_select=false;
}
diff --git a/scene/gui/tree.h b/scene/gui/tree.h
index 43a913392e..1dad26dffe 100644
--- a/scene/gui/tree.h
+++ b/scene/gui/tree.h
@@ -438,6 +438,9 @@ friend class TreeItem;
bool drag_touching;
bool drag_touching_deaccel;
bool click_handled;
+ bool allow_rmb_select;
+
+ bool force_select_on_already_selected;
bool hide_folding;
@@ -514,6 +517,12 @@ public:
void set_drop_mode_flags(int p_flags);
int get_drop_mode_flags() const;
+ void set_single_select_cell_editing_only_when_already_selected(bool p_enable);
+ bool get_single_select_cell_editing_only_when_already_selected() const;
+
+ void set_allow_rmb_select(bool p_allow);
+ bool get_allow_rmb_select() const;
+
void set_value_evaluator(ValueEvaluator *p_evaluator);
Tree();