@GuiView.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. /******************************************************************************/
  2. /******************************************************************************/
  3. class GuiView : Region
  4. {
  5. static const flt MinSize;
  6. static Color TextRectColor;
  7. static void ViewportDraw(Viewport &viewport);
  8. static bool IgnoreSelected;
  9. class Button2 : GuiObjs::ObjName<Button > {~Button2 (); Button2 ();virtual GuiObj*test(C GuiPC &gpc, C Vec2 &pos, GuiObj* &mouse_wheel)override; };
  10. class CheckBox2 : GuiObjs::ObjName<CheckBox > {~CheckBox2 (); CheckBox2 ();virtual GuiObj*test(C GuiPC &gpc, C Vec2 &pos, GuiObj* &mouse_wheel)override; virtual void update(C GuiPC &gpc)override; };
  11. class ComboBox2 : GuiObjs::ObjName<ComboBox > {~ComboBox2 (); ComboBox2 (); virtual GuiObj* test(C GuiPC &gpc, C Vec2 &pos, GuiObj* &mouse_wheel)override; virtual void update(C GuiPC &gpc)override; };
  12. class GuiCustom2 : GuiObjs::ObjName<GuiCustom> {~GuiCustom2(); GuiCustom2(); virtual GuiObj* test(C GuiPC &gpc, C Vec2 &pos, GuiObj* &mouse_wheel)override; virtual void draw(C GuiPC &gpc)override; };
  13. class Desktop2 : GuiObjs::ObjName<Desktop > {~Desktop2 (); Desktop2 (); /*virtual GuiObj* test(C Vec2 &pos, GuiObj* &mouse_wheel)override {return (IgnoreSelected && GuiEdit.sel.has(this)) ? null : super.test(pos, mouse_wheel);}*/ };
  14. class GuiImage2 : GuiObjs::ObjName<GuiImage > {~GuiImage2 (); GuiImage2 ();virtual GuiObj*test(C GuiPC &gpc, C Vec2 &pos, GuiObj* &mouse_wheel)override; };
  15. class List2 : GuiObjs::ObjName<_List > {~List2 (); List2 ();virtual GuiObj*test(C GuiPC &gpc, C Vec2 &pos, GuiObj* &mouse_wheel)override; };
  16. class Menu2 : GuiObjs::ObjName<Menu > {~Menu2 (); Menu2 ();virtual GuiObj*test(C GuiPC &gpc, C Vec2 &pos, GuiObj* &mouse_wheel)override; };
  17. class MenuBar2 : GuiObjs::ObjName<MenuBar > {~MenuBar2 (); MenuBar2 ();virtual GuiObj*test(C GuiPC &gpc, C Vec2 &pos, GuiObj* &mouse_wheel)override; };
  18. class Progress2 : GuiObjs::ObjName<Progress > {~Progress2 (); Progress2 ();virtual GuiObj*test(C GuiPC &gpc, C Vec2 &pos, GuiObj* &mouse_wheel)override; };
  19. class Region2 : GuiObjs::ObjName<Region > {~Region2 (); Region2 (); virtual GuiObj* test(C GuiPC &gpc, C Vec2 &pos, GuiObj* &mouse_wheel)override; };
  20. class SlideBar2 : GuiObjs::ObjName<SlideBar > {~SlideBar2 (); SlideBar2 (); virtual GuiObj* test(C GuiPC &gpc, C Vec2 &pos, GuiObj* &mouse_wheel)override; };
  21. class Slider2 : GuiObjs::ObjName<Slider > {~Slider2 (); Slider2 ();virtual GuiObj*test(C GuiPC &gpc, C Vec2 &pos, GuiObj* &mouse_wheel)override; };
  22. class Tabs2 : GuiObjs::ObjName<Tabs > {~Tabs2 (); Tabs2 (); virtual GuiObj* test(C GuiPC&gpc, C Vec2&pos, GuiObj*&mouse_wheel)override; };
  23. class Text2 : GuiObjs::ObjName<Text > {~Text2 (); Text2 (); virtual GuiObj* test(C GuiPC &gpc, C Vec2 &pos, GuiObj* &mouse_wheel)override; virtual void draw(C GuiPC &gpc)override; };
  24. class TextBox2 : GuiObjs::ObjName<TextBox > {~TextBox2 (); TextBox2 ();virtual GuiObj*test(C GuiPC &gpc, C Vec2 &pos, GuiObj* &mouse_wheel)override; virtual void update(C GuiPC &gpc)override; virtual void draw(C GuiPC&gpc)override; };
  25. class TextLine2 : GuiObjs::ObjName<TextLine > {~TextLine2 (); TextLine2 ();virtual GuiObj*test(C GuiPC &gpc, C Vec2 &pos, GuiObj* &mouse_wheel)override; virtual void update(C GuiPC &gpc)override; virtual void draw(C GuiPC&gpc)override; };
  26. class Viewport2 : GuiObjs::ObjName<Viewport > {~Viewport2 (); Viewport2 ();virtual GuiObj*test(C GuiPC &gpc, C Vec2 &pos, GuiObj* &mouse_wheel)override; virtual void draw(C GuiPC &gpc)override; };
  27. class Window2 : GuiObjs::ObjName<Window > {~Window2 (); Window2 (); virtual GuiObj* test(C GuiPC &gpc, C Vec2 &pos, GuiObj* &mouse_wheel)override; virtual void update(C GuiPC &gpc)override; };
  28. class Objects
  29. {
  30. GuiObj *parent;
  31. Memx<Button2 > button ;
  32. Memx<CheckBox2 > checkbox;
  33. Memx<ComboBox2 > combobox;
  34. Memx<GuiCustom2> custom ;
  35. Memx<Desktop2 > desktop ;
  36. Memx<GuiImage2 > image ;
  37. Memx<List2 > list ;
  38. Memx<Menu2 > menu ;
  39. Memx<MenuBar2 > menubar ;
  40. Memx<Progress2 > progress;
  41. Memx<Region2 > region ;
  42. Memx<SlideBar2 > slidebar;
  43. Memx<Slider2 > slider ;
  44. Memx<Tabs2 > tabs ;
  45. Memx<Text2 > text ;
  46. Memx<TextBox2 > textbox ;
  47. Memx<TextLine2 > textline;
  48. Memx<Viewport2 > viewport;
  49. Memx<Window2 > window ;
  50. // get
  51. Memx<GuiObj>* container(GUI_OBJ_TYPE type);
  52. bool containsMain(GuiObj *go); // if 'go' is stored in this objects
  53. bool contains (GuiObj *go); // if 'go' is stored in this objects
  54. // manage
  55. void del();
  56. void create(C GuiObjs &objs); // create from
  57. void copyTo(GuiObjs &objs)C;
  58. // operations
  59. GuiObj* New(GUI_OBJ_TYPE type);
  60. void remove(GuiObj *go);
  61. // io
  62. bool save(File &f, cchar *path)C;
  63. bool load(File &f, cchar *path);
  64. bool save(C Str &name)C;
  65. bool load(C Str &name);
  66. public:
  67. Objects();
  68. };
  69. static void PosX ( GuiObj &go, C Str &t);
  70. static Str PosX (C GuiObj &go );
  71. static void PosY ( GuiObj &go, C Str &t);
  72. static Str PosY (C GuiObj &go );
  73. static void SizeX( GuiObj &go, C Str &t);
  74. static Str SizeX(C GuiObj &go );
  75. static void SizeY( GuiObj &go, C Str &t);
  76. static Str SizeY(C GuiObj &go );
  77. static void Desc ( GuiObj &go, C Str &t);
  78. static Str Desc (C GuiObj &go );
  79. static void CheckBoxOn ( CheckBox &checkbox, C Str &t);
  80. static Str CheckBoxOn (C CheckBox &checkbox );
  81. static void ProgressValue( Progress &progress, C Str &t);
  82. static Str ProgressValue(C Progress &progress );
  83. static void RegionSbc ( Region &region , C Str &t);
  84. static Str RegionSbc (C Region &region );
  85. static void SlideBarLength ( SlideBar &slidebar, C Str &t);
  86. static Str SlideBarLength (C SlideBar &slidebar );
  87. static void SlideBarLengthTotal( SlideBar &slidebar, C Str &t);
  88. static Str SlideBarLengthTotal(C SlideBar &slidebar );
  89. static void SlideBarFrac ( SlideBar &slidebar, C Str &t);
  90. static Str SlideBarFrac (C SlideBar &slidebar );
  91. static void SliderValue( Slider &slider, C Str &t);
  92. static Str SliderValue(C Slider &slider );
  93. static Str TabsValid (C Tabs &tabs );
  94. static void TabsValid ( Tabs &tabs, C Str &t);
  95. static Str TabsLayout (C Tabs &tabs );
  96. static void TabsLayout ( Tabs &tabs, C Str &t);
  97. static Str TabsSpace (C Tabs &tabs );
  98. static void TabsSpace ( Tabs &tabs, C Str &t);
  99. static Str TabsAutoSize(C Tabs &tabs );
  100. static void TabsAutoSize( Tabs &tabs, C Str &t);
  101. template<int i> static Str TabsTabText (C Tabs &tabs );
  102. template<int i> static void TabsTabText ( Tabs &tabs, C Str &t);
  103. static void TextCodeFunc( Text &text, C Str &t);
  104. static Str TextCodeFunc(C Text &text );
  105. static Str TextLineText (C TextLine &textline );
  106. static void TextLineText ( TextLine &textline, C Str &t);
  107. static Str TextLinePassword (C TextLine &textline );
  108. static void TextLinePassword ( TextLine &textline, C Str &t);
  109. static Str TextLineMaxLength(C TextLine &textline );
  110. static void TextLineMaxLength( TextLine &textline, C Str &t);
  111. static Str TextBoxText (C TextBox &textbox );
  112. static void TextBoxText ( TextBox &textbox, C Str &t);
  113. static Str TextBoxMaxLength(C TextBox &textbox );
  114. static void TextBoxMaxLength( TextBox &textbox, C Str &t);
  115. static void WindowLevel ( Window &window, C Str &t);
  116. static Str WindowLevel (C Window &window );
  117. static void WindowMovable ( Window &window, C Str &t);
  118. static Str WindowMovable (C Window &window );
  119. static void WindowResizable ( Window &window, C Str &t);
  120. static Str WindowResizable (C Window &window );
  121. static void WindowBarVisible( Window &window, C Str &t);
  122. static Str WindowBarVisible(C Window &window );
  123. //static void WindowBarHeight ( Window &window, C Str &t) { window.barHeight (TextFlt (t));}
  124. //static Str WindowBarHeight (C Window &window ) {return window.barHeight ();}
  125. static void ButtonImage (Button &button , C Str &t);
  126. static void ButtonSkin (Button &button , C Str &t);
  127. static void CheckBoxSkin (CheckBox &checkbox, C Str &t);
  128. static void ComboBoxSkin (ComboBox &combobox, C Str &t);
  129. static void ImageImage (GuiImage &image , C Str &t);
  130. static void ProgressSkin (Progress &progress, C Str &t);
  131. static void SlideBarSkin (SlideBar &slidebar, C Str &t);
  132. static void SliderSkin (Slider &slider , C Str &t);
  133. static void RegionSkin (Region &region , C Str &t);
  134. static void TabsSkin (Tabs &tabs , C Str &t);
  135. static void TextSkin (Text &text , C Str &t);
  136. static void TextLineSkin (TextLine &textline, C Str &t);
  137. static void TextBoxSkin (TextBox &textbox , C Str &t);
  138. static void WindowSkin (Window &window , C Str &t);
  139. static void TextTextStyle(Text &text , C Str &t);
  140. static Str ButtonImage (C Button &button );
  141. static Str ButtonSkin (C Button &button );
  142. static Str CheckBoxSkin (C CheckBox &checkbox);
  143. static Str ComboBoxSkin (C ComboBox &combobox);
  144. static Str ImageImage (C GuiImage &image );
  145. static Str ProgressSkin (C Progress &progress);
  146. static Str SlideBarSkin (C SlideBar &slidebar);
  147. static Str SliderSkin (C Slider &slider );
  148. static Str RegionSkin (C Region &region );
  149. static Str TabsSkin (C Tabs &tabs );
  150. static Str TextSkin (C Text &text );
  151. static Str TextLineSkin (C TextLine &textline);
  152. static Str TextBoxSkin (C TextBox &textbox );
  153. static Str WindowSkin (C Window &window );
  154. static Str TextTextStyle(C Text &text );
  155. class ObjEdit : PropWin
  156. {
  157. static GuiSkinPtr Skin;
  158. static void PreChanged(C Property &prop); // set skin because that may affect object properties (for example slidebar button visibility, window client rectangle)
  159. static void Changed(C Property &prop);
  160. Rect create(GUI_OBJ_TYPE type, int level);
  161. virtual void draw(C GuiPC &gpc)override;
  162. };
  163. static GuiObj* MainObject(GuiObj *go);
  164. static GuiObj* MainParent(GuiObj *parent, bool allow_tabs);
  165. static GuiObj* FirstContainer(GuiObj *go, bool allow_tabs);
  166. enum OP
  167. {
  168. OP_NEW ,
  169. OP_DEL ,
  170. OP_MOVE ,
  171. OP_SIZE ,
  172. OP_COPY ,
  173. OP_SEPARATE,
  174. OP_SCALE ,
  175. OP_PARENT ,
  176. OP_NUM ,
  177. };
  178. static GUI_OBJ_TYPE obj_new[]
  179. ; static int obj_new_elms;
  180. class Panel : Window
  181. {
  182. flt grid_size;
  183. Button draw_proportions, grid_align, undo, redo, locate, align_sel, aspect, move_up, move_down;
  184. Tabs op, obj_type;
  185. Memx<Property> props;
  186. static void AlignSel(Panel &panel);
  187. static void MoveUp (Panel &panel);
  188. static void MoveDown(Panel &panel);
  189. static void Aspect (Panel &panel);
  190. static void Undo (Panel &panel);
  191. static void Redo (Panel &panel);
  192. static void Locate (Panel &panel);
  193. GUI_OBJ_TYPE objType()C;
  194. void align(Vec2 &pos, bool force=false);
  195. void alignTrunc(Vec2 &pos);
  196. Panel& create();
  197. public:
  198. Panel();
  199. };
  200. class Change : Edit::_Undo::Change
  201. {
  202. GuiObjs objs;
  203. virtual void create(ptr user)override;
  204. virtual void apply(ptr user)override;
  205. };
  206. bool changed, selecting, disable_selection;
  207. Vec2 sel_pos, helper;
  208. UID elm_id;
  209. Elm *elm;
  210. Objects objs;
  211. Panel panel;
  212. ObjEdit obj_edit[GO_NUM];
  213. Button new_tab;
  214. int op;
  215. GuiObj *sel_parent, *last;
  216. Memc<GuiObj*> sel, lit, temp;
  217. Edit::Undo<Change> undo; void undoVis();
  218. bool selected()C;
  219. void selectedChanged();
  220. void flush();
  221. void set(Elm *elm);
  222. void activate(Elm *elm);
  223. void toggle (Elm *elm);
  224. void erasing(C UID &elm_id);
  225. static void DelTab(ptr user);
  226. static void NewTab(GuiView &gv);
  227. GuiView& createPropsTabs(Tabs *tabs);
  228. void createProps();
  229. GuiView& create(GuiObj &parent);
  230. void resize();
  231. virtual GuiObj* test(C GuiPC &gpc, C Vec2 &pos, GuiObj* &mouse_wheel)override;
  232. void elmChanged(C UID &elm_id);
  233. void setChanged(bool to_gui=false);
  234. // get
  235. GuiObj* cur( );
  236. GuiObj* cur(GUI_OBJ_TYPE type);
  237. bool selectedParents(GuiObj *obj); // if object or its parents are selected
  238. bool editable(GuiObj *obj);
  239. Rect selRect( );
  240. bool hasKbFocus( );
  241. // operations
  242. void removed(GuiObj*obj);
  243. void sort(); static int CompareOrder(GuiObj*C &a, GuiObj*C &b);
  244. void alignSel();
  245. void moveUpSel (); // process from end , but keep selection order
  246. void moveDownSel(); // process from start, but keep selection order
  247. void resetAspect();
  248. void processSel();
  249. GuiView& toGui();
  250. GuiObj* copy(GuiObj &obj, GuiObj *parent, C Vec2 *screen_pos, C Vec2 *offset);
  251. void clean(); // clean all references which point to invalid files
  252. virtual void update(C GuiPC &gpc)override;
  253. static void Highlight(GuiObj &go, C Color &color, flt a);
  254. void drawPreview(GuiObj &obj, C GuiPC &gpc, GuiObj &parent);
  255. virtual void draw(C GuiPC &gpc)override;
  256. void drawPre();
  257. void draw();
  258. // drag
  259. void drag(Memc<UID> &elms, GuiObj* &obj, C Vec2 &screen_pos);
  260. public:
  261. GuiView();
  262. };
  263. /******************************************************************************/
  264. /******************************************************************************/
  265. extern GuiView GuiEdit;
  266. /******************************************************************************/