Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2020
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.27 KB | None | 0 0
  1.  
  2.  
  3. #pragma once
  4.  
  5. #include "CommonIncludes.h"
  6.  
  7. #include <map>
  8.  
  9. class CControl;
  10. class CTab;
  11. class CWindow;
  12. class CGUI;
  13.  
  14. extern CGUI GUI;
  15.  
  16. enum UIFlags
  17. {
  18. UI_None = 0x00,
  19. UI_Drawable = 0x01,
  20. UI_Clickable = 0x02,
  21. UI_Focusable = 0x04,
  22. UI_RenderFirst = 0x08,
  23. UI_SaveFile = 0x10
  24. };
  25.  
  26. enum UIControlTypes
  27. {
  28. UIC_CheckBox = 1,
  29. UIC_Slider,
  30. UIC_KeyBind,
  31. UIC_ComboBox,
  32. UIC_ItemSelector,
  33. UIC_Button,
  34. UIC_MultiBox,
  35. UIC_GroupBox,
  36. UIC_ListBox,
  37. UIC_ColorSelector,
  38. UIC_Label,
  39. UIC_TextField
  40. };
  41.  
  42. // Base class for GUI controls
  43. class CControl
  44. {
  45. friend class CGUI;
  46. friend class CTab;
  47. friend class CWindow;
  48. public:
  49. void SetPosition(int x, int y);
  50. void SetSize(int w, int h);
  51. void GetSize(int &w, int &h);
  52. void SetFileId(std::string fid);
  53. int FileControlType;
  54. int m_iWidth, m_iHeight;
  55.  
  56.  
  57. POINT GetAbsolutePos();
  58. bool Flag(int f);
  59. int m_x, m_y;
  60.  
  61. CControl* parent_group;
  62. int g_tab = 0;
  63.  
  64. bool should_function = true;
  65. protected:
  66. int m_Flags;
  67. CWindow* parent;
  68.  
  69. std::string FileIdentifier;
  70.  
  71. virtual void Draw(bool) = 0;
  72. virtual void OnUpdate() = 0;
  73. virtual void OnClick() = 0;
  74. };
  75.  
  76. // A GUI Control Container
  77. class CTab
  78. {
  79. friend class CControl;
  80. friend class CGUI;
  81. friend class CWindow;
  82. public:
  83. void SetTitle(std::string name);
  84. void RegisterControl(CControl* control);
  85. std::vector<CControl*> Controls;
  86. private:
  87. std::string Title;
  88. CWindow* parent;
  89. };
  90.  
  91. // Base class for a simple GUI window
  92. class CWindow
  93. {
  94. friend class CControl;
  95. friend class CGUI;
  96. public:
  97. void SetPosition(int x, int y);
  98. void SetSize(int w, int h);
  99. void SetTitle(std::string title);
  100. void Open();
  101. void Close();
  102. void Toggle();
  103. bool isOpen();
  104. int get_iWidth()
  105. {
  106. return m_iWidth;
  107. }
  108. int get_iHeight()
  109. {
  110. return m_iHeight;
  111. }
  112. int get_x()
  113. {
  114. return m_x;
  115. }
  116. int get_y()
  117. {
  118. return m_y;
  119. }
  120. CControl* GetFocus();
  121.  
  122. void RegisterTab(CTab* Tab);
  123.  
  124. RECT GetClientArea();
  125. RECT GetTabArea();
  126. RECT GetDragArea();
  127. CControl* FocusedControl;
  128.  
  129. private:
  130. void DrawControls();
  131.  
  132. bool m_bIsOpen = false;
  133.  
  134. std::vector<CTab*> Tabs;
  135. CTab* SelectedTab;
  136.  
  137. bool IsFocusingControl;
  138.  
  139. std::string Title;
  140. int m_x;
  141. int m_y;
  142. int m_iWidth;
  143. int m_iHeight;
  144.  
  145. };
  146.  
  147. // User interface manager
  148. class CGUI
  149. {
  150. public:
  151. CGUI();
  152.  
  153. // Draws all windows
  154. void Draw();
  155.  
  156. // Handle all input etc
  157. void Update();
  158.  
  159. // Draws a single window
  160. bool DrawWindow(CWindow* window, int menu);
  161.  
  162. // Registers a window
  163. void RegisterWindow(CWindow* window);
  164.  
  165. // Config saving/loading
  166. void SaveWindowState(CWindow* window, std::string Filename);
  167. void LoadWindowState(CWindow* window, std::string Filename);
  168.  
  169. // Window Binds
  170. void BindWindow(unsigned char Key, CWindow* window);
  171.  
  172. // Input
  173. bool GetKeyPress(unsigned int key);
  174. bool GetKeyState(unsigned int key);
  175. bool IsMouseInRegion(int x, int y, int x2, int y2);
  176. bool IsMouseInRegion(RECT region);
  177. POINT GetMouse();
  178.  
  179. private:
  180. // Input
  181. // keyboard
  182. bool keys[256];
  183. bool oldKeys[256];
  184. // Mouse
  185. POINT Mouse;
  186. bool MenuOpen;
  187.  
  188. // Window Dragging
  189. bool IsDraggingWindow;
  190. CWindow* DraggingWindow;
  191. int DragOffsetX; int DragOffsetY;
  192.  
  193. // Windows
  194. std::vector<CWindow*> Windows;
  195.  
  196. // KeyBinds -> Windows Map
  197. std::map<int, CWindow*> WindowBinds;
  198. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement