GUIButton.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. #pragma once
  2. #include "BaseGUIElement.h"
  3. #include "render/QuadRender.h"
  4. class GUIWidget;
  5. class BaseGUICursor;
  6. class GUIButton : public BaseGUIElement
  7. {
  8. public:
  9. struct Params
  10. {
  11. Params() :
  12. links (_FL_),
  13. hotKeys(_FL_)
  14. {
  15. }
  16. // float w,h;
  17. const char *description; // описание кнопки
  18. ConstString descObject; // имя объекта выводящего описание
  19. ConstString staticWidget; // общая графика (видна всегда)
  20. ConstString selectedButtonWidget; // графика состояния "mouse over"
  21. ConstString normalButtonWidget; // графика состояния "normal"
  22. ConstString focusButtonWidget; // графика состояния "focused"
  23. ConstString pressedButtonWidget; // графика состояния "pressed"
  24. ConstString disabledButtonWidget; // графика состояния "disabled"
  25. float pressXoffset;
  26. float pressYoffset;
  27. struct NavigationLink
  28. {
  29. const char *control; // имя контрола
  30. ConstString object; // имя объекта для перехода
  31. float activeTime;
  32. };
  33. struct HotKey
  34. {
  35. const char *hotKey;
  36. bool onlyInFocus;
  37. };
  38. array<NavigationLink> links;
  39. array<HotKey> hotKeys;
  40. bool initiallyFocused;
  41. MissionTrigger buttonEvent; // Событие нажатия на активную кнопку
  42. // MissionTrigger inactiEvent; // Событие нажатия на неактивную кнопку
  43. };
  44. MissionTrigger onGetFocus;
  45. MissionTrigger onLosFocus;
  46. private:
  47. BaseGUICursor *m_cursor; long m_cursorHash;
  48. long m_validateHash;
  49. bool m_wasPressed; // флаг нажатия
  50. bool m_wasReleased; // флаг отпускания
  51. bool m_doNotCheckFocusChange; // не проверять переход фокуса в текущем кадре.
  52. float m_focusTime;
  53. Params m_params;
  54. bool m_autorepeat; // признак возможности автоповтора
  55. bool m_autofocus; // автоматический переход фокуса
  56. GUIWidget *m_staticWidget;
  57. GUIWidget *m_selectedWidget;
  58. GUIWidget *m_normalWidget;
  59. GUIWidget *m_focusedWidget;
  60. GUIWidget *m_pressedWidget;
  61. GUIWidget *m_disabledWidget;
  62. GUIWidget *m_activeWidget;
  63. enum State {stStatic,stNormal,stFocused,stPressed,stDisabled};
  64. State m_state;
  65. bool m_release; // срабатывать при отжатии
  66. bool m_focusByPress;
  67. float m_pressTime; // время анимации нажатия/отжатиия кнопки
  68. float m_pressDelay; // время до автоповтора нажатия кнопки
  69. bool m_repeat; // признак состояния автоповтора
  70. bool m_pressed; // была ли нажата кнопка
  71. bool m_mouseOver;
  72. void SetState(State val)
  73. {
  74. m_state = val;
  75. }
  76. long drawPriority;
  77. GUIWidget* m_tooltipWidget;
  78. QuadRender m_helperQuad;
  79. bool m_restart; // выполняется рестарт объекта
  80. bool m_initComplete; // была выполнена инициализация функцией InitFunc()
  81. virtual void OnParentNotify(BaseGUIElement::Notification);
  82. public:
  83. virtual void OnLooseFocus();
  84. virtual void OnAcquireFocus();
  85. private:
  86. void OnHotKey();
  87. void ReadMOPs(MOPReader& reader);
  88. void SkipMOPs(MOPReader& reader);
  89. void _cdecl Work(float deltaTime, long level);
  90. void _cdecl InitFunc(float, long);
  91. void Restart(); // сбросить состояние
  92. bool RestartObject(MOPReader &reader);
  93. virtual void UnRegister(BaseGUIElement* object);
  94. void SetDisabled();
  95. void SetFocused();
  96. void SetNormal(bool reset = false);
  97. void SetPressed();
  98. void SetSelected();
  99. bool ProcessKeyboard();
  100. void ProcessMouse();
  101. MissionObject *FindObject(const ConstString & id)
  102. {
  103. MOSafePointer sp;
  104. Mission().FindObject(id,sp);
  105. return sp.Ptr();
  106. }
  107. public:
  108. bool GoToLink(const char *control);
  109. public:
  110. virtual void SetDrawUpdate() { SetUpdate(&GUIButton::Work,drawLevel); }
  111. virtual void DelDrawUpdate() { DelUpdate(&GUIButton::Work); }
  112. GUIButton(void);
  113. virtual ~GUIButton(void);
  114. virtual bool Create (MOPReader & reader);
  115. virtual bool EditMode_Update(MOPReader & reader);
  116. virtual void Show (bool isShow);
  117. virtual void Activate(bool isActive);
  118. virtual void Command(const char *id, dword numParams, const char **params);
  119. MO_IS_FUNCTION(GUIButton, BaseGUIElement);
  120. public:
  121. virtual void SetFocus()
  122. {
  123. SetFocused();
  124. }
  125. public:
  126. virtual void Draw();
  127. virtual void Update(float dltTime);
  128. };