property_editor.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. /*************************************************************************/
  2. /* property_editor.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* http://www.godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  9. /* */
  10. /* Permission is hereby granted, free of charge, to any person obtaining */
  11. /* a copy of this software and associated documentation files (the */
  12. /* "Software"), to deal in the Software without restriction, including */
  13. /* without limitation the rights to use, copy, modify, merge, publish, */
  14. /* distribute, sublicense, and/or sell copies of the Software, and to */
  15. /* permit persons to whom the Software is furnished to do so, subject to */
  16. /* the following conditions: */
  17. /* */
  18. /* The above copyright notice and this permission notice shall be */
  19. /* included in all copies or substantial portions of the Software. */
  20. /* */
  21. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  22. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  23. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  24. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  25. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  26. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  27. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  28. /*************************************************************************/
  29. #ifndef PROPERTY_EDITOR_H
  30. #define PROPERTY_EDITOR_H
  31. #include "scene/gui/tree.h"
  32. #include "scene/gui/button.h"
  33. #include "scene/gui/label.h"
  34. #include "scene/gui/file_dialog.h"
  35. #include "scene/gui/dialogs.h"
  36. #include "scene/gui/color_picker.h"
  37. #include "scene/gui/menu_button.h"
  38. #include "scene/gui/texture_frame.h"
  39. #include "scene/gui/text_edit.h"
  40. #include "scene/gui/check_button.h"
  41. #include "scene_tree_editor.h"
  42. /**
  43. @author Juan Linietsky <[email protected]>
  44. */
  45. class CustomPropertyEditor : public Popup {
  46. OBJ_TYPE( CustomPropertyEditor, Popup );
  47. enum {
  48. MAX_VALUE_EDITORS=12,
  49. MAX_ACTION_BUTTONS=5,
  50. OBJ_MENU_LOAD=0,
  51. OBJ_MENU_EDIT=1,
  52. OBJ_MENU_CLEAR=2,
  53. OBJ_MENU_MAKE_UNIQUE=3,
  54. OBJ_MENU_COPY=4,
  55. OBJ_MENU_PASTE=5,
  56. OBJ_MENU_REIMPORT=6,
  57. TYPE_BASE_ID=100
  58. };
  59. enum {
  60. EASING_LINEAR,
  61. EASING_EASE_IN,
  62. EASING_EASE_OUT,
  63. EASING_ZERO,
  64. EASING_IN_OUT,
  65. EASING_OUT_IN
  66. };
  67. PopupMenu *menu;
  68. SceneTreeDialog *scene_tree;
  69. FileDialog *file;
  70. ConfirmationDialog *error;
  71. String name;
  72. Variant::Type type;
  73. Variant v;
  74. int hint;
  75. String hint_text;
  76. LineEdit *value_editor[MAX_VALUE_EDITORS];
  77. Label *value_label[MAX_VALUE_EDITORS];
  78. HScrollBar *scroll[4];
  79. Button *action_buttons[MAX_ACTION_BUTTONS];
  80. MenuButton *type_button;
  81. Vector<String> inheritors_array;
  82. TextureFrame *texture_preview;
  83. ColorPicker *color_picker;
  84. TextEdit *text_edit;
  85. bool read_only;
  86. Button *checks20[20];
  87. Control *easing_draw;
  88. Object* owner;
  89. bool updating;
  90. void _text_edit_changed();
  91. void _file_selected(String p_file);
  92. void _scroll_modified(double p_value);
  93. void _modified(String p_string);
  94. void _focus_enter();
  95. void _focus_exit();
  96. void _action_pressed(int p_which);
  97. void _type_create_selected(int p_idx);
  98. void _color_changed(const Color& p_color);
  99. void _draw_easing();
  100. void _menu_option(int p_which);
  101. void _drag_easing(const InputEvent& p_ev);
  102. void _node_path_selected(NodePath p_path);
  103. void show_value_editors(int p_amount);
  104. void config_value_editors(int p_amount, int p_columns,int p_label_w,const List<String>& p_strings);
  105. void config_action_buttons(const List<String>& p_strings);
  106. protected:
  107. void _notification(int p_what);
  108. static void _bind_methods();
  109. public:
  110. Variant get_variant() const;
  111. String get_name() const;
  112. void set_read_only(bool p_read_only) { read_only=p_read_only; }
  113. bool edit(Object* p_owner,const String& p_name,Variant::Type p_type, const Variant& p_variant,int p_hint,String p_hint_text);
  114. CustomPropertyEditor();
  115. };
  116. class PropertyEditor : public Control {
  117. OBJ_TYPE( PropertyEditor, Control );
  118. Tree *tree;
  119. Label *top_label;
  120. //Object *object;
  121. Object* obj;
  122. Array _prop_edited_name;
  123. StringName _prop_edited;
  124. bool capitalize_paths;
  125. bool changing;
  126. bool update_tree_pending;
  127. bool autoclear;
  128. bool keying;
  129. bool read_only;
  130. bool show_categories;
  131. HashMap<String,String> pending;
  132. String selected_property;
  133. CustomPropertyEditor *custom_editor;
  134. void _resource_edit_request();
  135. void _custom_editor_edited();
  136. void _custom_editor_request(bool p_arrow);
  137. void _item_selected();
  138. void _item_edited();
  139. TreeItem *get_parent_node(String p_path,HashMap<String,TreeItem*>& item_paths,TreeItem *root);
  140. void set_item_text(TreeItem *p_item, int p_type, const String& p_name, int p_hint=PROPERTY_HINT_NONE, const String& p_hint_text="");
  141. TreeItem *find_item(TreeItem *p_item,const String& p_name);
  142. virtual void _changed_callback(Object *p_changed,const char * p_what);
  143. virtual void _changed_callbacks(Object *p_changed,const String& p_callback);
  144. void _edit_button(Object *p_item, int p_column, int p_button);
  145. void _node_removed(Node *p_node);
  146. void _edit_set(const String& p_name, const Variant& p_value);
  147. void _draw_flags(Object *ti,const Rect2& p_rect);
  148. Node *get_instanced_node();
  149. UndoRedo *undo_redo;
  150. protected:
  151. void _notification(int p_what);
  152. static void _bind_methods();
  153. public:
  154. void set_undo_redo(UndoRedo *p_undo_redo) { undo_redo=p_undo_redo; }
  155. String get_selected_path() const;
  156. Tree *get_tree();
  157. Label* get_top_label();
  158. void hide_top_label();
  159. void update_tree();
  160. void update_property(const String& p_prop);
  161. void edit(Object* p_object);
  162. void set_keying(bool p_active);
  163. void set_read_only(bool p_read_only) { read_only=p_read_only; custom_editor->set_read_only(p_read_only);}
  164. void set_capitalize_paths(bool p_capitalize);
  165. void set_autoclear(bool p_enable);
  166. void set_show_categories(bool p_show);
  167. PropertyEditor();
  168. ~PropertyEditor();
  169. };
  170. #endif