Gui.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /******************************************************************************/
  2. struct GUI // Graphical User Interface
  3. {
  4. Bool allow_window_fade , // if allow Window fading (smooth transparency), default=true
  5. window_fade ; // if use fade when closing windows or displaying message boxes, default=false
  6. Flt window_fade_in_speed , // speed of Window fading in , 0..Inf, default=9
  7. window_fade_out_speed, // speed of Window fading out , 0..Inf, default=6
  8. window_fade_scale , // scale of Window when faded out, 0..2 , default=0.85
  9. dialog_padd , // Dialog Window padding , 0..Inf, default=0.03
  10. dialog_button_height , // Dialog Window Button height , 0..Inf, default=0.06
  11. dialog_button_padd , // Dialog Window Button padding , 0..Inf, default=dialog_button_height*2
  12. dialog_button_margin , // Dialog Window Button margin , 0..Inf, default=dialog_button_height
  13. resize_radius , // radius used for detection of resizing windows, 0..Inf, default=0.022
  14. desc_delay ; // time after which gui object descriptions should be displayed, default=0.3
  15. UID click_sound_id ; // click sound id, default=UIDZero, if specified then it will be always played when a Button, CheckBox or a Tab is clicked
  16. ImagePtr image_shadow , // shadow image, default=ImagePtr().get("Gui/shadow.img" )
  17. image_drag , // drag image, default=ImagePtr().get("Gui/drag.img" )
  18. image_resize_x , // resize horizontal image, default=ImagePtr().get("Gui/resize_x.img" )
  19. image_resize_y , // resize vertical image, default=ImagePtr().get("Gui/resize_y.img" )
  20. image_resize_ld, // resize left down image, default=ImagePtr().get("Gui/resize_ru.img")
  21. image_resize_lu, // resize left up image, default=ImagePtr().get("Gui/resize_rd.img")
  22. image_resize_ru, // resize right up image, default=ImagePtr().get("Gui/resize_ru.img")
  23. image_resize_rd; // resize right down image, default=ImagePtr().get("Gui/resize_rd.img")
  24. GuiSkinPtr skin ; // active Gui Skin
  25. UID default_skin; // ID of the Gui Skin to be loaded during engine initialization, this can be modified in 'InitPre'
  26. void (*draw_keyboard_highlight)(GuiObj *obj, C Rect &rect, C GuiSkin *skin ); // pointer to custom function responsible for drawing keyboard highlight , 'obj'=pointer to gui object for the highlight , 'rect'=screen rectangle of the object, 'skin'=Gui Skin of the object, default='DrawKeyboardHighlight'
  27. void (*draw_description )(GuiObj *obj, C Vec2 &pos, CChar *text, Bool mouse); // pointer to custom function responsible for drawing gui object description, 'obj'=pointer to gui object of the desctiption, 'pos' =screen position where the description should be drawn, 'text'=text of the description, 'mouse'=if description drawing was triggered by mouse, default='DrawDescription'
  28. void (*draw_imm )(GuiObj *obj ); // pointer to custom function responsible for drawing the IMM data , 'obj'=pointer to gui object responsible for IMM text, default='DrawIMM'
  29. // get
  30. GuiObj * kb ()C {return _kb ;} // current object with keyboard focus
  31. GuiObj * ms ()C {return _ms ;} // current object with mouse focus (this is not always the object under mouse cursor, for example if you push the mouse button on a gui object, and move the cursor away without releasing the button, this method will still return the object on which the button was pushed, however as soon as the object gets deactivated, this will get cleared to null)
  32. GuiObj * msSrc ()C {return _ms_src ;} // current object with mouse focus (this is not always the object under mouse cursor, for example if you push the mouse button on a gui object, and move the cursor away without releasing the button, this method will still return the object on which the button was pushed, however as soon as the object gets deleted , this will get cleared to null)
  33. GuiObj * msLit ()C {return _ms_lit ;} // current object under mouse cursor (this is always the object under mouse cursor)
  34. GuiObj * wheel ()C {return _wheel ;} // current object with mouse wheel focus
  35. Desktop* desktop()C {return _desktop;} // current desktop
  36. Window * window ()C {return _window ;} // current window with focus
  37. Menu * menu ()C {return _menu ;} // current menu
  38. #if EE_PRIVATE
  39. Window * windowLit()C {return _window_lit;} // current window under mouse cursor
  40. #endif
  41. GuiObj* objAtPos(C Vec2 &pos)C; // get gui object at 'pos' screen position
  42. Flt updateTime()C {return _update_time;} // get CPU time needed to perform last 'update' method
  43. Color backgroundColor()C; // get background color of the current skin, this is 'Gui.skin.background_color'
  44. Color borderColor ()C; // get border color of the current skin, this is 'Gui.skin.border_color'
  45. // operations
  46. T1(TYPE) void operator+=(TYPE &child) {if(_desktop)*_desktop+=child;} // add gui object to active desktop
  47. T1(TYPE) void operator-=(TYPE &child) {if(_desktop)*_desktop-=child;} // remove gui object from active desktop
  48. void msgBox(C Str &title, C Str &text, C TextStylePtr &text_style=null); // create and display a gui based message box, 'title'=window title, 'text'=text message, 'text_style'=style of 'text'
  49. Dialog& getMsgBox(CPtr id); // get message box by its 'id', if 'id' is null then this method always creates a new message box, otherwise it first tries to find an existing message box with a matching id, if none was found then a new one is created
  50. Dialog* findMsgBox(CPtr id); // find message box by its 'id', if 'id' is null then this method does nothing, returns null when not found
  51. void delMsgBox(CPtr id); // delete message box by its 'id', if 'id' is null then this method does nothing
  52. void fadeOutMsgBox(CPtr id); // fade out message box by its 'id', if 'id' is null then this method does nothing
  53. void closeMsgBox(CPtr id); // close message box by its 'id', if 'id' is null then this method does nothing, closing means that either 'fadeOut' or 'del' will be called depending on 'Gui.msg_box_fade'
  54. GUI& passwordChar(Char c); // set character used for TextLine's when in password mode (default='*')
  55. GUI& windowButtonsRight(Bool right); Bool windowButtonsRight()C {return _window_buttons_right;} // set/get if Window Buttons (minimise, maximise, close) should appear on the right side of the Window, default=false for Mac and true otherwise
  56. void playClickSound()C; // play click sound based on 'click_sound_*' members
  57. // dragging
  58. Bool dragging ()C {return _dragging;} // if currently dragging an element
  59. Vec2 dragPos ()C; // get screen position of the input that triggered dragging (this is valid if 'dragging' returns true)
  60. void (*dragFinish()C)(Ptr user, GuiObj *obj, C Vec2 &screen_pos) {return _drag_finish;} // get function that was specified as 'finish' parameter for 'drag' method
  61. void dragCancel(); // cancel any current dragging
  62. void drag(C Str &name , Touch *touch=null ); // start dragging 'name' element, 'touch'=touch used to initiate the dragging (null for mouse)
  63. void drag(void finish(Ptr user, GuiObj *obj, C Vec2 &screen_pos), Ptr user=null, Touch *touch=null, void start(Ptr user)=null, void cancel(Ptr user)=null); // start dragging and call 'finish' function when finished, 'start' when started, 'cancel' when canceled, 'touch'=touch used to initiate the dragging (null for mouse)
  64. T1(TYPE) void drag(void finish(TYPE *user, GuiObj *obj, C Vec2 &screen_pos), TYPE *user , Touch *touch=null, void start(TYPE *user)=null, void cancel(TYPE *user)=null) {drag((void(*)(Ptr, GuiObj*, C Vec2&))finish, user, touch, (void(*)(Ptr))start, (void(*)(Ptr))cancel);} // start dragging and call 'finish' function when finished, 'start' when started, 'cancel' when canceled, 'touch'=touch used to initiate the dragging (null for mouse)
  65. T1(TYPE) void drag(void finish(TYPE &user, GuiObj *obj, C Vec2 &screen_pos), TYPE &user , Touch *touch=null, void start(TYPE &user)=null, void cancel(TYPE &user)=null) {drag((void(*)(Ptr, GuiObj*, C Vec2&))finish, &user, touch, (void(*)(Ptr))start, (void(*)(Ptr))cancel);} // start dragging and call 'finish' function when finished, 'start' when started, 'cancel' when canceled, 'touch'=touch used to initiate the dragging (null for mouse)
  66. #if EE_PRIVATE
  67. Bool dragWant()C {return _drag_want;} // if dragging is possible
  68. void dragDraw();
  69. #endif
  70. // function callbacks
  71. void addFuncCall(void func( ) ); // add custom function to the gui function callback list to be automatically called at the end of the 'Gui.update'
  72. void addFuncCall(void func(Ptr user), Ptr user); // add custom function to the gui function callback list to be automatically called at the end of the 'Gui.update'
  73. T1(TYPE) void addFuncCall(void func(TYPE *user), TYPE *user) {addFuncCall((void(*)(Ptr))func, user);} // add custom function to the gui function callback list to be automatically called at the end of the 'Gui.update'
  74. T1(TYPE) void addFuncCall(void func(TYPE &user), TYPE &user) {addFuncCall((void(*)(Ptr))func, &user);} // add custom function to the gui function callback list to be automatically called at the end of the 'Gui.update'
  75. // update / draw
  76. void update(); // update gui
  77. void draw (); // draw gui
  78. #if !EE_PRIVATE
  79. private:
  80. #endif
  81. Bool _drag_want, _dragging, _window_buttons_right;
  82. Char _pass_char;
  83. GuiObj *_kb, *_ms, *_ms_src, *_ms_lit, *_wheel, *_desc, *_touch_desc, *_overlay_textline;
  84. Menu *_menu;
  85. Window *_window, *_window_lit;
  86. Desktop *_desktop;
  87. Flt _update_time, _time_d_fade_out;
  88. Dbl _desc_time, _touch_desc_time;
  89. UInt _drag_touch_id;
  90. Vec2 _drag_pos, _overlay_textline_offset;
  91. Str _drag_name, _pass_temp;
  92. Ptr _drag_user;
  93. void (*_drag_start )(Ptr user),
  94. (*_drag_cancel)(Ptr user),
  95. (*_drag_finish)(Ptr user, GuiObj *obj, C Vec2 &screen_pos);
  96. Callbacks _callbacks;
  97. SyncLock _lock;
  98. Memx<Desktop> _desktops;
  99. #if EE_PRIVATE
  100. void del ();
  101. void create();
  102. void screenChanged(Flt old_width, Flt old_height);
  103. Bool Switch ( );
  104. void kbLit (GuiObj *obj, C Rect &rect, C GuiSkin *skin) {if(draw_keyboard_highlight)draw_keyboard_highlight(obj, rect, skin);}
  105. void setText ();
  106. C Str& passTemp(Int length); // Warning: this is not thread-safe
  107. TextLine* overlayTextLine(Vec2 &offset);
  108. friend struct Display;
  109. #endif
  110. GUI();
  111. }extern
  112. Gui; // Main GUI
  113. /******************************************************************************/
  114. void DrawKeyboardHighlight(GuiObj *obj, C Rect &rect, C GuiSkin *skin ); // default Keyboard Highlight drawing function
  115. void DrawDescription (GuiObj *obj, C Vec2 &pos, CChar *text, Bool mouse); // default Gui Object Description drawing function
  116. void DrawIMM (GuiObj *obj ); // default IMM (Windows Input Method Manager) drawing function
  117. /******************************************************************************/