diff options
Diffstat (limited to 'scene/gui/tree.h')
-rw-r--r-- | scene/gui/tree.h | 223 |
1 files changed, 107 insertions, 116 deletions
diff --git a/scene/gui/tree.h b/scene/gui/tree.h index 14bd2efbaa..68d4453156 100644 --- a/scene/gui/tree.h +++ b/scene/gui/tree.h @@ -29,25 +29,24 @@ #ifndef TREE_H #define TREE_H +#include "core/helper/value_evaluator.h" #include "scene/gui/control.h" -#include "scene/gui/popup_menu.h" #include "scene/gui/line_edit.h" +#include "scene/gui/popup_menu.h" #include "scene/gui/scroll_bar.h" #include "scene/gui/slider.h" -#include "core/helper/value_evaluator.h" /** @author Juan Linietsky <reduzio@gmail.com> */ - class Tree; class TreeItem : public Object { - GDCLASS(TreeItem,Object); -public: + GDCLASS(TreeItem, Object); +public: enum TreeCellMode { CELL_MODE_STRING, ///< just a string @@ -59,8 +58,7 @@ public: }; private: -friend class Tree; - + friend class Tree; struct Cell { @@ -70,7 +68,7 @@ friend class Tree; Rect2i icon_region; String text; String suffix; - double min,max,step,val; + double min, max, step, val; int icon_max_w; bool expr; bool checked; @@ -94,33 +92,35 @@ friend class Tree; bool disabled; Ref<Texture> texture; Color color; - Button() { id=0; disabled=false; color=Color(1,1,1,1); } + Button() { + id = 0; + disabled = false; + color = Color(1, 1, 1, 1); + } }; - Vector< Button > buttons; + Vector<Button> buttons; Cell() { - custom_draw_obj=0; - mode=TreeItem::CELL_MODE_STRING; - min=0; - max=100; - step=1; - val=0; - checked=false; - editable=false; - selected=false; - selectable=true; - custom_color=false; - custom_bg_color=false; - expr=false; - icon_max_w=0; + custom_draw_obj = 0; + mode = TreeItem::CELL_MODE_STRING; + min = 0; + max = 100; + step = 1; + val = 0; + checked = false; + editable = false; + selected = false; + selectable = true; + custom_color = false; + custom_bg_color = false; + expr = false; + icon_max_w = 0; } - Size2 get_icon_size() const; - void draw_icon(const RID& p_where, const Point2& p_pos, const Size2& p_size=Size2()) const; - + void draw_icon(const RID &p_where, const Point2 &p_pos, const Size2 &p_size = Size2()) const; }; Vector<Cell> cells; @@ -132,79 +132,76 @@ friend class Tree; TreeItem *childs; //child items Tree *tree; //tree (for reference) - - TreeItem(Tree *p_tree); - void _changed_notify(int p_cell); void _changed_notify(); void _cell_selected(int p_cell); void _cell_deselected(int p_cell); -protected: +protected: static void _bind_methods(); //bind helpers - Dictionary _get_range_config( int p_column ) { + Dictionary _get_range_config(int p_column) { Dictionary d; - double min,max,step; - get_range_config(p_column,min,max,step); - d["min"]=min; - d["max"]=max; - d["step"]=step; - d["expr"]=false; + double min, max, step; + get_range_config(p_column, min, max, step); + d["min"] = min; + d["max"] = max; + d["step"] = step; + d["expr"] = false; return d; } - void _remove_child(Object *p_child) { remove_child( p_child->cast_to<TreeItem>() ); } -public: + void _remove_child(Object *p_child) { remove_child(p_child->cast_to<TreeItem>()); } +public: /* cell mode */ - void set_cell_mode( int p_column, TreeCellMode p_mode ); - TreeCellMode get_cell_mode( int p_column ) const; + void set_cell_mode(int p_column, TreeCellMode p_mode); + TreeCellMode get_cell_mode(int p_column) const; /* check mode */ - void set_checked(int p_column,bool p_checked); + void set_checked(int p_column, bool p_checked); bool is_checked(int p_column) const; - void set_text(int p_column,String p_text); + void set_text(int p_column, String p_text); String get_text(int p_column) const; - void set_suffix(int p_column,String p_suffix); + void set_suffix(int p_column, String p_suffix); String get_suffix(int p_column) const; - void set_icon(int p_column,const Ref<Texture>& p_icon); + void set_icon(int p_column, const Ref<Texture> &p_icon); Ref<Texture> get_icon(int p_column) const; - void set_icon_region(int p_column,const Rect2& p_icon_region); + void set_icon_region(int p_column, const Rect2 &p_icon_region); Rect2 get_icon_region(int p_column) const; - void set_icon_max_width(int p_column,int p_max); + 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,bool p_disabled=false); + 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); - void set_button_color(int p_column,int p_idx,const Color& p_color); + 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); + void set_button_color(int p_column, int p_idx, const Color &p_color); /* range works for mode number or mode combo */ - void set_range(int p_column,double p_value); + void set_range(int p_column, double p_value); double get_range(int p_column) const; - void set_range_config(int p_column,double p_min,double p_max,double p_step,bool p_exp=false); - void get_range_config(int p_column,double& r_min,double& r_max,double &r_step) const; + void set_range_config(int p_column, double p_min, double p_max, double p_step, bool p_exp = false); + void get_range_config(int p_column, double &r_min, double &r_max, double &r_step) const; bool is_range_exponential(int p_column) const; - void set_metadata(int p_column,const Variant& p_meta); + void set_metadata(int p_column, const Variant &p_meta); Variant get_metadata(int p_column) const; - void set_custom_draw(int p_column,Object *p_object,const StringName& p_callback); + void set_custom_draw(int p_column, Object *p_object, const StringName &p_callback); void set_collapsed(bool p_collapsed); bool is_collapsed(); @@ -219,7 +216,7 @@ public: void remove_child(TreeItem *p_item); - void set_selectable(int p_column,bool p_selectable); + void set_selectable(int p_column, bool p_selectable); bool is_selectable(int p_column) const; bool is_selected(int p_column); @@ -227,52 +224,49 @@ public: void deselect(int p_column); void set_as_cursor(int p_column); - void set_editable(int p_column,bool p_editable); + void set_editable(int p_column, bool p_editable); bool is_editable(int p_column); - void set_custom_color(int p_column,const Color& p_color); + void set_custom_color(int p_column, const Color &p_color); Color get_custom_color(int p_column) const; void clear_custom_color(int p_column); - void set_custom_bg_color(int p_column, const Color& p_color, bool p_bg_outline=false); + void set_custom_bg_color(int p_column, const Color &p_color, bool p_bg_outline = false); void clear_custom_bg_color(int p_column); Color get_custom_bg_color(int p_column) const; - void set_tooltip(int p_column, const String& p_tooltip); + void set_tooltip(int p_column, const String &p_tooltip); String get_tooltip(int p_column) const; - void clear_children(); void move_to_top(); void move_to_bottom(); ~TreeItem(); - }; - -VARIANT_ENUM_CAST( TreeItem::TreeCellMode ); - +VARIANT_ENUM_CAST(TreeItem::TreeCellMode); class Tree : public Control { - GDCLASS( Tree, Control ); + GDCLASS(Tree, Control); + public: enum SelectMode { - SELECT_SINGLE, - SELECT_ROW, - SELECT_MULTI + SELECT_SINGLE, + SELECT_ROW, + SELECT_MULTI }; enum DropModeFlags { - DROP_MODE_DISABLED=0, - DROP_MODE_ON_ITEM=1, - DROP_MODE_INBETWEEN=2 + DROP_MODE_DISABLED = 0, + DROP_MODE_ON_ITEM = 1, + DROP_MODE_INBETWEEN = 2 }; private: -friend class TreeItem; + friend class TreeItem; TreeItem *root; TreeItem *popup_edited_item; @@ -295,7 +289,6 @@ friend class TreeItem; bool range_drag_enabled; Vector2 range_drag_capture_pos; - //TreeItem *cursor_item; //int cursor_column; @@ -315,7 +308,10 @@ friend class TreeItem; int min_width; bool expand; String title; - ColumnInfo() { min_width=1; expand=true; } + ColumnInfo() { + min_width = 1; + expand = true; + } }; bool show_column_titles; @@ -335,10 +331,10 @@ friend class TreeItem; int compute_item_height(TreeItem *p_item) const; int get_item_height(TreeItem *p_item) const; //void draw_item_text(String p_text,const Ref<Texture>& p_icon,int p_icon_max_w,bool p_tool,Rect2i p_rect,const Color& p_color); - void draw_item_rect(const TreeItem::Cell& p_cell,const Rect2i& p_rect,const Color& p_color); - int draw_item(const Point2i& p_pos,const Point2& p_draw_ofs, const Size2& p_draw_size,TreeItem *p_item); - void select_single_item(TreeItem *p_selected,TreeItem *p_current,int p_col,TreeItem *p_prev=NULL,bool *r_in_range=NULL,bool p_force_deselect=false); - int propagate_mouse_event(const Point2i &p_pos,int x_ofs,int y_ofs,bool p_doubleclick,TreeItem *p_item,int p_button,const InputModifierState& p_mod); + void draw_item_rect(const TreeItem::Cell &p_cell, const Rect2i &p_rect, const Color &p_color); + int draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2 &p_draw_size, TreeItem *p_item); + void select_single_item(TreeItem *p_selected, TreeItem *p_current, int p_col, TreeItem *p_prev = NULL, bool *r_in_range = NULL, bool p_force_deselect = false); + int propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, bool p_doubleclick, TreeItem *p_item, int p_button, const InputModifierState &p_mod); void text_editor_enter(String p_text); void _text_editor_modal_close(); void value_editor_changed(double p_value); @@ -350,10 +346,10 @@ friend class TreeItem; Size2 get_minimum_size() const; - void item_edited(int p_column,TreeItem *p_item); - void item_changed(int p_column,TreeItem *p_item); - void item_selected(int p_column,TreeItem *p_item); - void item_deselected(int p_column,TreeItem *p_item); + void item_edited(int p_column, TreeItem *p_item); + void item_changed(int p_column, TreeItem *p_item); + void item_selected(int p_column, TreeItem *p_item); + void item_deselected(int p_column, TreeItem *p_item); void propagate_set_columns(TreeItem *p_item); @@ -413,7 +409,6 @@ friend class TreeItem; } cache; - int _get_title_button_height() const; void _scroll_moved(float p_value); @@ -429,13 +424,13 @@ friend class TreeItem; uint64_t last_keypress; String incr_search; bool cursor_can_exit_tree; - void _do_incr_search(const String& p_add); + void _do_incr_search(const String &p_add); - TreeItem* _search_item_text(TreeItem *p_at, const String& p_find,int *r_col,bool p_selectable,bool p_backwards=false); + TreeItem *_search_item_text(TreeItem *p_at, const String &p_find, int *r_col, bool p_selectable, bool p_backwards = false); - TreeItem* _find_item_at_pos(TreeItem *p_current, const Point2& p_pos, int& r_column, int &h, int §ion) const; + TreeItem *_find_item_at_pos(TreeItem *p_current, const Point2 &p_pos, int &r_column, int &h, int §ion) const; -/* float drag_speed; + /* float drag_speed; float drag_accum; float last_drag_accum; @@ -459,37 +454,35 @@ friend class TreeItem; ValueEvaluator *evaluator; - int _count_selected_items(TreeItem* p_from) const; + int _count_selected_items(TreeItem *p_from) const; protected: static void _bind_methods(); //bind helpers - Object* _create_item(Object *p_parent) { return create_item(p_parent->cast_to<TreeItem>() ); } - TreeItem *_get_next_selected(Object *p_item) { return get_next_selected(p_item->cast_to<TreeItem>() ); } - Rect2 _get_item_rect(Object *p_item,int p_column) const { return get_item_rect(p_item->cast_to<TreeItem>(),p_column ); } - + Object *_create_item(Object *p_parent) { return create_item(p_parent->cast_to<TreeItem>()); } + TreeItem *_get_next_selected(Object *p_item) { return get_next_selected(p_item->cast_to<TreeItem>()); } + Rect2 _get_item_rect(Object *p_item, int p_column) const { return get_item_rect(p_item->cast_to<TreeItem>(), p_column); } public: + virtual String get_tooltip(const Point2 &p_pos) const; - virtual String get_tooltip(const Point2& p_pos) const; - - TreeItem* get_item_at_pos(const Point2& p_pos) const; - int get_column_at_pos(const Point2& p_pos) const; - int get_drop_section_at_pos(const Point2& p_pos) const; + TreeItem *get_item_at_pos(const Point2 &p_pos) const; + int get_column_at_pos(const Point2 &p_pos) const; + int get_drop_section_at_pos(const Point2 &p_pos) const; void clear(); - TreeItem* create_item(TreeItem *p_parent=0); - TreeItem* get_root(); - TreeItem* get_last_item(); + TreeItem *create_item(TreeItem *p_parent = 0); + TreeItem *get_root(); + TreeItem *get_last_item(); - void set_column_min_width(int p_column,int p_min_width); - void set_column_expand(int p_column,bool p_expand); + void set_column_min_width(int p_column, int p_min_width); + void set_column_expand(int p_column, bool p_expand); int get_column_width(int p_column) const; void set_hide_root(bool p_eanbled); - TreeItem *get_next_selected( TreeItem* p_item); + TreeItem *get_next_selected(TreeItem *p_item); TreeItem *get_selected() const; int get_selected_column() const; int get_pressed_button() const; @@ -498,7 +491,7 @@ public: void set_columns(int p_columns); int get_columns() const; - void set_column_title(int p_column,const String& p_title); + void set_column_title(int p_column, const String &p_title); String get_column_title(int p_column) const; void set_column_titles_visible(bool p_show); @@ -512,10 +505,10 @@ public: Rect2 get_custom_popup_rect() const; int get_item_offset(TreeItem *p_item) const; - Rect2 get_item_rect(TreeItem *p_item,int p_column=-1) const; + Rect2 get_item_rect(TreeItem *p_item, int p_column = -1) const; bool edit_selected(); - TreeItem* search_item_text(const String& p_find,int *r_col=NULL,bool p_selectable=false); + TreeItem *search_item_text(const String &p_find, int *r_col = NULL, bool p_selectable = false); Point2 get_scroll() const; @@ -536,7 +529,6 @@ public: void set_edit_checkbox_cell_only_when_checkbox_is_pressed(bool p_enable); bool get_edit_checkbox_cell_only_when_checkbox_is_pressed() const; - void set_allow_rmb_select(bool p_allow); bool get_allow_rmb_select() const; @@ -544,8 +536,7 @@ public: Tree(); ~Tree(); - }; -VARIANT_ENUM_CAST( Tree::SelectMode ); +VARIANT_ENUM_CAST(Tree::SelectMode); #endif |