Advertisement
Guest User

imgui

a guest
Dec 12th, 2019
382
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 37.87 KB | None | 0 0
  1. #include "Gui.h"
  2.  
  3. // Data
  4. static INT64 g_Time = 0;
  5. static INT64 g_TicksPerSecond = 0;
  6.  
  7. static GuiContext GDefaultContext;
  8. GuiContext* GGui = &GDefaultContext;
  9.  
  10. GuiIO::GuiIO()
  11. {
  12. DisplaySize = Vector2(-1.0f, -1.0f);
  13. DeltaTime = 1.0f / 60.0f;
  14. MousePos = Vector2(-1, -1);
  15. MousePosPrev = Vector2(-1, -1);
  16. MouseDoubleClickTime = 0.30f;
  17. MouseDoubleClickMaxDist = 6.0f;
  18. MouseDragThreshold = 6.0f;
  19. for (int i = 0; i < ARRAYSIZE(MouseDownDuration); i++)
  20. MouseDownDuration[i] = MouseDownDurationPrev[i] = -1.0f;
  21. for (int i = 0; i < ARRAYSIZE(KeysDownDuration); i++)
  22. KeysDownDuration[i] = KeysDownDurationPrev[i] = -1.0f;
  23. KeyRepeatDelay = 0.250f;
  24. KeyRepeatRate = 0.050f;
  25. MouseDragging = false;
  26. MouseDraggingTo = Vector2(0.0f, 0.0f);
  27. }
  28.  
  29. GuiIO& Gui::GetIO()
  30. {
  31. return GGui->IO;
  32. }
  33.  
  34. float Gui::GetTime()
  35. {
  36. return GGui->Time;
  37. }
  38.  
  39. int Gui::GetFrameCount()
  40. {
  41. return GGui->FrameCount;
  42. }
  43.  
  44. void Gui::NewFrame()
  45. {
  46. GuiContext& g = *GGui;
  47.  
  48. ASSERT(g.IO.DeltaTime >= 0.0f);
  49. ASSERT(g.IO.DisplaySize.x >= 0.0f && g.IO.DisplaySize.y >= 0.0f);
  50.  
  51. if (!g.Initialized)
  52. {
  53. g.Initialized = true;
  54. }
  55.  
  56. g.Time += g.IO.DeltaTime;
  57. g.FrameCount += 1;
  58.  
  59. // Update inputs state
  60. if (g.IO.MousePos.x < 0 && g.IO.MousePos.y < 0)
  61. g.IO.MousePos = Vector2(-9999.0f, -9999.0f);
  62. if ((g.IO.MousePos.x < 0 && g.IO.MousePos.y < 0) || (g.IO.MousePos.x < 0 && g.IO.MousePosPrev.y < 0))
  63. g.IO.MouseDelta = Vector2(0.0f, 0.0f);
  64. else
  65. g.IO.MouseDelta = g.IO.MousePos - g.IO.MousePosPrev;
  66. g.IO.MousePosPrev = g.IO.MousePos;
  67. for (int i = 0; i < ARRAYSIZE(g.IO.MouseDown); i++)
  68. {
  69. g.IO.MouseClicked[i] = g.IO.MouseDown[i] && g.IO.MouseDownDuration[i] < 0.0f;
  70. g.IO.MouseReleased[i] = !g.IO.MouseDown[i] && g.IO.MouseDownDuration[i] >= 0.0f;
  71. g.IO.MouseDownDurationPrev[i] = g.IO.MouseDownDuration[i];
  72. g.IO.MouseDownDuration[i] = g.IO.MouseDown[i] ? (g.IO.MouseDownDuration[i] < 0.0f ? 0.0f : g.IO.MouseDownDuration[i] + g.IO.DeltaTime) : -1.0f;
  73. g.IO.MouseDoubleClicked[i] = false;
  74. if (g.IO.MouseClicked[i])
  75. {
  76. if (g.Time - g.IO.MouseClickedTime[i] < g.IO.MouseDoubleClickTime)
  77. {
  78. if (LengthSqr(g.IO.MousePos - g.IO.MouseClickedPos[i]) < g.IO.MouseDoubleClickMaxDist * g.IO.MouseDoubleClickMaxDist)
  79. g.IO.MouseDoubleClicked[i] = true;
  80. g.IO.MouseClickedTime[i] = -FLT_MAX;
  81. }
  82. else
  83. {
  84. g.IO.MouseClickedTime[i] = g.Time;
  85. }
  86. g.IO.MouseClickedPos[i] = g.IO.MousePos;
  87. }
  88. else if (g.IO.MouseDown[i])
  89. {
  90. //Drag
  91. }
  92. }
  93.  
  94. // Calculate frame-rate for the user, as a feature
  95. g.FramerateSecPerFrameAccum += g.IO.DeltaTime - g.FramerateSecPerFrame[g.FramerateSecPerFrameIdx];
  96. g.FramerateSecPerFrame[g.FramerateSecPerFrameIdx] = g.IO.DeltaTime;
  97. g.FramerateSecPerFrameIdx = (g.FramerateSecPerFrameIdx + 1) % ARRAYSIZE(g.FramerateSecPerFrame);
  98. g.IO.Framerate = 1.0f / (g.FramerateSecPerFrameAccum / (float)ARRAYSIZE(g.FramerateSecPerFrame));
  99. }
  100.  
  101. bool GUI_DX11_Init()
  102. {
  103. if (!QueryPerformanceFrequency((LARGE_INTEGER *)&g_TicksPerSecond))
  104. return false;
  105. if (!QueryPerformanceCounter((LARGE_INTEGER *)&g_Time))
  106. return false;
  107.  
  108. return true;
  109. }
  110.  
  111. void GUI_DX11_NewFrame(HWND hWnd)
  112. {
  113. GuiIO& io = Gui::GetIO();
  114.  
  115. // Setup display size (every frame to accommodate for window resizing)
  116. //RECT rect;
  117. //GetClientRect(hWnd, &rect);
  118. io.DisplaySize = Vector2(1920, 1080);//= Vector2((float)(rect.right - rect.left), (float)(rect.bottom - rect.top));
  119.  
  120. // Setup time step
  121. INT64 current_time;
  122. QueryPerformanceCounter((LARGE_INTEGER *)&current_time);
  123. io.DeltaTime = (float)(current_time - g_Time) / g_TicksPerSecond;
  124. g_Time = current_time;
  125.  
  126. //Start the frame
  127. Gui::NewFrame();
  128. }
  129.  
  130. GUI_API LRESULT Gui_WndProcHandler(HWND, UINT msg, WPARAM wParam, LPARAM lParam)
  131. {
  132. GuiIO& io = Gui::GetIO();
  133. switch (msg)
  134. {
  135. case WM_LBUTTONDOWN:
  136. io.MouseDown[0] = true;
  137. return true;
  138. case WM_LBUTTONUP:
  139. io.MouseDown[0] = false;
  140. return true;
  141. case WM_RBUTTONDOWN:
  142. io.MouseDown[1] = true;
  143. return true;
  144. case WM_RBUTTONUP:
  145. io.MouseDown[1] = false;
  146. return true;
  147. case WM_MBUTTONDOWN:
  148. io.MouseDown[2] = true;
  149. return true;
  150. case WM_MBUTTONUP:
  151. io.MouseDown[2] = false;
  152. return true;
  153. case WM_MOUSEWHEEL:
  154. io.MouseWheel += GET_WHEEL_DELTA_WPARAM(wParam) > 0 ? +1.0f : -1.0f;
  155. return true;
  156. case WM_MOUSEMOVE:
  157. io.MousePos.x = (signed short)(lParam);
  158. io.MousePos.y = (signed short)(lParam >> 16);
  159. return true;
  160. case WM_KEYDOWN:
  161. if (wParam < 256)
  162. io.KeysDown[wParam] = 1;
  163. return true;
  164. case WM_KEYUP:
  165. if (wParam < 256)
  166. io.KeysDown[wParam] = 0;
  167. return true;
  168. case WM_CHAR:
  169. // TODO: Create AddInputCharacter
  170. return true;
  171. }
  172. return 0;
  173. }
  174.  
  175. GuiWindow::GuiWindow()
  176. {
  177. HubPos = Vector2(80.0f, 60.0f);
  178. HubSize = Vector2(0.0f, 0.0f);
  179. BarWidth = 0.0f;
  180. BarWidthMaximumEverGet = 0.0f;
  181. HubActive = true;
  182. HubWasActive = true;
  183.  
  184. Pos = Vector2(0.0f, 0.0f);
  185. Size = Vector2(0.0f, 0.0f);
  186. MinX = 0;
  187. MinY = 12;
  188. MaxX = 12;
  189. MaxY = 12;
  190. Active = false;
  191. WasActive = false;
  192. ItemsLastPos = Vector2(0.0f, 0.0f);
  193. ItemsCurrentPos = Vector2(0.0f, 0.0f);
  194. ItemsCount = 0;
  195. ItemsCountDisplay = 0;
  196. ItemsCreatedCount = 0;
  197. ExpansionActive = false;
  198. ExpansionWasActive = false;
  199. ExpansionPop = false;
  200.  
  201. //Tabs
  202. TabsItemsCount = 0;
  203. TabsItemsCountLast = 0;
  204. TabsLastPosBeforePop = Vector2(0.0f, 0.0f);
  205. TabsActive = false;
  206. TabsArrayState;
  207.  
  208. //Scroll
  209. ScrollNeeded = false;
  210. ScrollWasActive = false;
  211. ScrollPos = Vector2(0, 0);
  212. //ScrollPos = Vector2(Pos.x - 22.0f, (Pos.y + Size.x) - 17.0f);
  213. ScrollSize = Vector2(4, 0);
  214. ScrollState = 0;
  215. ScrollStateCount = Vector2(0,0);
  216. ScrollIsDragging = false;
  217. DragWidth = 0.0f;
  218. //DragRect = Rect(HubPos.x + 40.0f, HubPos.y, 0.0f, 40.0f);
  219.  
  220. }
  221.  
  222. GuiWindow& Gui::GetWindow()
  223. {
  224. return GGui->Window;
  225. }
  226.  
  227. GuiStyle::GuiStyle()
  228. {
  229. HubPadding = Vector2(11.0f, 11.f);
  230. HubItemsSpacing = 5.0f;
  231. TabsItemsOffset = 24.0f;
  232. ItemsOffset = 24.0f;
  233. ItemsMaximum = 7;
  234. TabsX = 105.0f;
  235. OffsetFromScrollbar = 15.0f;
  236. }
  237.  
  238. GuiStyle& Gui::GetStyle()
  239. {
  240. return GGui->Style;
  241. }
  242.  
  243. bool Gui::Begin()
  244. {
  245. GuiContext& g = *GGui;
  246. GuiWindow& window = GetWindow();
  247. GuiStyle& style = GetStyle();
  248.  
  249. const int current_frame = GetFrameCount();
  250.  
  251. window.ExpansionPop = true;
  252.  
  253. // Initialize Hub
  254. std::string connectionStatus = XorStrA("Online");
  255. //char ConnectionStatus[7] = "Online";
  256. char hubText[256];
  257. sprintf(hubText, "FPS %.f", GetIO().Framerate);
  258. float Text_Hub_Length = g_pDrawManager->GetTextLength(0, hubText);
  259. Text_Hub_Length += g_pDrawManager->GetTextLength(0, connectionStatus.c_str());
  260.  
  261. if(window.BarWidthMaximumEverGet <= Text_Hub_Length + style.HubItemsSpacing + (style.HubPadding.y * 2) - 5.0f || current_frame <= 300)
  262. window.BarWidthMaximumEverGet = Text_Hub_Length + style.HubItemsSpacing + (style.HubPadding.y * 2) - 5.0f;
  263. window.BarWidth = window.BarWidthMaximumEverGet;
  264.  
  265. window.ItemsLastPos = window.HubPos;
  266. window.ItemsCurrentPos = window.HubPos;
  267.  
  268. /*-----------------*/
  269. /* DRAWING */
  270. /*-----------------*/
  271.  
  272. //Draw Hub red rect
  273. g_pDrawManager->AddFillRect(window.HubPos.x, window.HubPos.y, 40.0f, 40.0f, 0xB80000D9);
  274. window.HubSize = Vector2(40.0f, 40.0f);
  275. window.ItemsCurrentPos.x += window.HubSize.x;
  276.  
  277. if (window.HubActive)
  278. {
  279. g_pDrawManager->AddFillRect(window.HubPos.x + 9, window.HubPos.y + 14, 9, 2, 0xFFFFFFFF);
  280. g_pDrawManager->AddFillRect(window.HubPos.x + 12, window.HubPos.y + 19, 16, 2, 0xFFFFFFFF);
  281. g_pDrawManager->AddFillRect(window.HubPos.x + 19, window.HubPos.y + 24, 9, 2, 0xFFFFFFFF);
  282. window.Active = false;
  283. }
  284. else
  285. {
  286. g_pDrawManager->AddLine(window.HubPos.x + 14, window.HubPos.y + 22, window.HubPos.x + 21, window.HubPos.y + 29, 0xFFFFFFFF, 2);
  287. g_pDrawManager->AddLine(window.HubPos.x + 27, window.HubPos.y + 22, window.HubPos.x + 20, window.HubPos.y + 28, 0xFFFFFFFF, 2);
  288. g_pDrawManager->AddFillRect(window.HubPos.x + 19, window.HubPos.y + 12, 2, 16, 0xFFFFFFFF);
  289. window.Active = true;
  290. }
  291.  
  292. std::string hackVersion = XorStrA("Dune v1.0");
  293. // Initialize Window
  294. //const char HackVersion[256] = "Dune v1.0";
  295.  
  296. if (window.Active)
  297. window.BarWidth += g_pDrawManager->GetTextLength(0, hackVersion.c_str()) + 168.0f;
  298.  
  299. //Draw Hub background text
  300. g_pDrawManager->AddFillRect(window.ItemsCurrentPos.x, window.ItemsCurrentPos.y, window.BarWidth, window.HubSize.y, 0x131313D9);
  301. window.ItemsLastPos = window.ItemsCurrentPos;
  302. window.ItemsCurrentPos = Vector2(window.ItemsCurrentPos.x + style.HubPadding.x, window.ItemsCurrentPos.y + style.HubPadding.y);
  303.  
  304. if (window.Active)
  305. {
  306. g_pDrawManager->AddText(window.ItemsCurrentPos.x, window.ItemsCurrentPos.y, 0xFFFFFFFF, 0, notting, hackVersion.c_str());
  307. window.ItemsLastPos = window.ItemsCurrentPos;
  308. window.ItemsCurrentPos.x += g_pDrawManager->GetTextLength(0, hackVersion.c_str()) + 168.0f;
  309. }
  310.  
  311. //Draw Text for fps
  312. g_pDrawManager->AddText(window.ItemsCurrentPos.x, window.ItemsCurrentPos.y, 0xFFFFFFFF, 0, notting, hubText);
  313. window.ItemsLastPos = window.ItemsCurrentPos;
  314. window.ItemsCurrentPos.x += g_pDrawManager->GetTextLength(0, hubText);
  315.  
  316. //Draw Text for status
  317. g_pDrawManager->AddText(window.ItemsCurrentPos.x, window.ItemsCurrentPos.y, 0xFFFFFFFF, 0, notting, connectionStatus.c_str());
  318. window.ItemsLastPos = window.ItemsCurrentPos;
  319. window.ItemsCurrentPos = Vector2(window.ItemsCurrentPos.x + g_pDrawManager->GetTextLength(0, connectionStatus.c_str()) - 7.0f, window.ItemsCurrentPos.y + 8.0f);
  320.  
  321. //Draw cercle status
  322. g_pDrawManager->AddFillCircle(window.ItemsCurrentPos.x, window.ItemsCurrentPos.y, 3.0f, 0x00D000FF);
  323. window.ItemsLastPos = window.ItemsCurrentPos;
  324. window.ItemsCurrentPos = window.Pos;
  325.  
  326. //Setting the final menu size
  327. window.HubSize = Vector2(40.0f + window.BarWidth, 40.0f);
  328.  
  329. if (window.Active)
  330. {
  331. window.Pos.x = window.HubPos.x;
  332. window.Pos.y = window.HubPos.y + 40.0f;
  333. window.Size = Vector2(window.HubSize.x, 192.0f);
  334.  
  335. window.ItemsLastPos = window.ItemsCurrentPos;
  336. window.ItemsCurrentPos = window.Pos;
  337.  
  338. if (window.TabsActive)
  339. {
  340. window.Pos.x += style.TabsX;
  341. window.Size.x -= style.TabsX;
  342. }
  343. //Draw window
  344. g_pDrawManager->AddFillRect(window.Pos.x, window.Pos.y, window.Size.x, window.Size.y, 0xF9F9F9D9);
  345. }
  346.  
  347.  
  348. //Dragging & moving the Window/Hub
  349. if (IsMouseHoveringRect(Vector2(window.HubPos.x + 40.0f, window.HubPos.y), Vector2(window.BarWidth, 40.0f)))
  350. {
  351. if (IsMouseDown(0) && !IsMouseReleased(0))
  352. g.IO.MouseDragging = true;
  353. else
  354. g.IO.MouseDragging = false;
  355. }
  356.  
  357. if (g.IO.MouseDragging)
  358. {
  359. window.HubPos.x = g.IO.MousePos.x - g.IO.MouseDraggingTo.x;
  360. window.HubPos.y = g.IO.MousePos.y - g.IO.MouseDraggingTo.y;
  361. }
  362. else
  363. {
  364. g.IO.MouseDraggingTo.x = g.IO.MousePos.x - window.HubPos.x;
  365. g.IO.MouseDraggingTo.y = g.IO.MousePos.y - window.HubPos.y;
  366. }
  367.  
  368.  
  369. //Opening window
  370. if (IsMouseHoveringRect(Vector2(window.HubPos.x, window.HubPos.y), Vector2(40.0f, 40.0f)) && IsMouseClicked(0, true) && !g.IO.MouseDragging)
  371. window.HubActive = !(window.HubActive);
  372.  
  373.  
  374. //Scrolling & Items disposition in window
  375. if (window.ItemsCreatedCount >= style.ItemsMaximum)
  376. window.ScrollNeeded = true;
  377. else
  378. window.ScrollNeeded = false;
  379.  
  380. if (window.ScrollNeeded && window.Active)
  381. {
  382. if (0 - g.IO.MouseWheel > window.ItemsCreatedCount - style.ItemsMaximum)
  383. g.IO.MouseWheel = -(window.ItemsCreatedCount - style.ItemsMaximum);
  384. else
  385. {
  386. if (0 - g.IO.MouseWheel < 0)
  387. {
  388. g.IO.MouseWheel = 0.f;
  389. }
  390. else
  391. window.ScrollState = 0 - g.IO.MouseWheel;
  392. }
  393. window.ScrollPos = Vector2(window.Pos.x + window.Size.x - window.MaxX - window.ScrollSize.x, window.Pos.y + 12.0f);
  394. window.ScrollSize.y = window.Size.y - 24.0f;
  395. g_pDrawManager->AddFillRect(window.ScrollPos.x, window.ScrollPos.y, window.ScrollSize.x, window.ScrollSize.y, 0xD9D9D9D9, 2.0f);
  396. if (window.ScrollState > 0)
  397. window.ScrollPos.y += ((window.Size.y - 24.0f) / ((window.ItemsCreatedCount - style.ItemsMaximum) + 1) ) * window.ScrollState;
  398. window.ScrollSize.y = (window.Size.y - 24.0f) / ((window.ItemsCreatedCount - style.ItemsMaximum) + 1);
  399. g_pDrawManager->AddFillRect(window.ScrollPos.x, window.ScrollPos.y, window.ScrollSize.x, window.ScrollSize.y, 0xF1F1F1FF, 2.0f);
  400. }
  401.  
  402. return true;
  403. }
  404.  
  405. void Gui::End()
  406. {
  407. GuiWindow& window = GetWindow();
  408.  
  409. if(window.TabsItemsCount > 0)
  410. window.TabsItemsCount = 0;
  411.  
  412. if (window.ItemsCreatedCount != window.ItemsCountDisplay)
  413. window.ItemsCreatedCount = window.ItemsCountDisplay;
  414.  
  415. if (window.ItemsCountDisplay > 0)
  416. window.ItemsCountDisplay = 0;
  417.  
  418. window.ExpansionPop = true;
  419. }
  420.  
  421. bool Gui::Tab(const char* label, bool* p_state)
  422. {
  423. GuiContext& g = *GGui;
  424. GuiWindow& window = GetWindow();
  425. GuiStyle& style = GetStyle();
  426.  
  427. if (!window.Active)
  428. return false;
  429.  
  430. if(!window.TabsActive)
  431. window.TabsActive = true;
  432.  
  433. //Adding a new items in the list
  434. window.TabsItemsCountLast = window.TabsItemsCount;
  435. window.TabsItemsCount += 1;
  436.  
  437. //Add state in Array
  438. if (window.TabsArrayState.size() == window.TabsItemsCountLast)
  439. window.TabsArrayState.push_back(*p_state);
  440.  
  441. //Set the p_state at the same value of the array
  442. *p_state = window.TabsArrayState[window.TabsItemsCountLast];
  443.  
  444. //printf("TabsItemsCount: %d\nArraySize: %i \n", window.TabsItemsCount, window.TabsArrayState.size());
  445. if (window.TabsItemsCountLast == 0)
  446. {
  447. //TopOffset
  448. g_pDrawManager->AddFillRect(window.ItemsCurrentPos.x, window.ItemsCurrentPos.y, style.TabsX, window.MinY, 0xFFFFFFD9);
  449.  
  450. //DownOffset
  451. g_pDrawManager->AddFillRect(window.ItemsCurrentPos.x, (window.ItemsCurrentPos.y + window.Size.y) - window.MaxY, style.TabsX, window.MaxY, 0xFFFFFFD9);
  452. window.ItemsLastPos = window.ItemsCurrentPos;
  453. window.ItemsCurrentPos.y += window.MinY;
  454. }
  455.  
  456. if (window.TabsItemsCountLast >= 1 )
  457. window.ItemsCurrentPos.y += style.TabsItemsOffset;
  458.  
  459. if (!window.ScrollIsDragging && IsMouseHoveringRect(Vector2(window.ItemsCurrentPos.x, window.ItemsCurrentPos.y), Vector2(style.TabsX, style.TabsItemsOffset))
  460. && IsMouseClicked(0, true)
  461. && !g.IO.MouseDragging)
  462. {
  463. if (window.ScrollWasActive)
  464. {
  465. window.ScrollState = 0;
  466. g.IO.MouseWheel = 0.f;
  467. }
  468.  
  469. for (int i = 0; i <= window.TabsArrayState.size(); i++)
  470. {
  471. if (window.TabsArrayState[i] && i != window.TabsItemsCountLast)
  472. {
  473. window.TabsArrayState[i] = false;
  474. }
  475.  
  476. if (i == window.TabsItemsCountLast)
  477. {
  478. window.TabsArrayState[i] = true;
  479. }
  480. }
  481. //*p_state = !(*p_state);
  482. }
  483.  
  484. if (window.TabsArrayState[window.TabsItemsCountLast])
  485. {
  486. g_pDrawManager->AddFillRect(window.ItemsCurrentPos.x, window.ItemsCurrentPos.y, 4.0f, style.TabsItemsOffset, 0xB80000D9);
  487. g_pDrawManager->AddFillRect(window.ItemsCurrentPos.x + 4.0f, window.ItemsCurrentPos.y, style.TabsX - 4.0f, style.TabsItemsOffset, 0xF0F0F0D9);
  488. g_pDrawManager->AddText(window.ItemsCurrentPos.x + 23.0f, window.ItemsCurrentPos.y + 4.0f, 0xB80000FF, 1, notting, label);
  489.  
  490. window.ItemsLastPos = window.ItemsCurrentPos;
  491. //Adding LastPos for TabPop() function to reset the position of the tab
  492. window.TabsLastPosBeforePop = window.ItemsCurrentPos;
  493. window.ItemsCurrentPos = Vector2(window.Pos.x + 23.0f, window.Pos.y + window.MinY);
  494.  
  495. }
  496. else
  497. {
  498. if(IsMouseHoveringRect(Vector2(window.ItemsCurrentPos.x, window.ItemsCurrentPos.y), Vector2(style.TabsX, style.TabsItemsOffset)))
  499. g_pDrawManager->AddFillRect(window.ItemsCurrentPos.x, window.ItemsCurrentPos.y, style.TabsX, style.TabsItemsOffset, 0xF0F0F0D9);
  500. else
  501. g_pDrawManager->AddFillRect(window.ItemsCurrentPos.x, window.ItemsCurrentPos.y, style.TabsX, style.TabsItemsOffset, 0xFFFFFFD9);
  502.  
  503. g_pDrawManager->AddText(window.ItemsCurrentPos.x + 23.0f, window.ItemsCurrentPos.y + 4.0f, Colors::Black, 1, notting, label);
  504. return false;
  505. }
  506.  
  507. return true;
  508. }
  509.  
  510. void Gui::TabPop()
  511. {
  512. GuiWindow& window = GetWindow();
  513. GuiStyle& style = GetStyle();
  514. //printf("Pop: %i\n", window.TabsItemsCountLast);
  515. window.ItemsCurrentPos = window.TabsLastPosBeforePop;
  516.  
  517. if (window.ScrollNeeded)
  518. window.ScrollWasActive = true;
  519. else
  520. window.ScrollWasActive = false;
  521. }
  522.  
  523. bool Gui::Button(const char* label)
  524. {
  525. //Todo
  526. }
  527.  
  528. bool Gui::SwitchCheck(const char* label, bool* p_state)
  529. {
  530. GuiContext& g = *GGui;
  531. GuiWindow& window = GetWindow();
  532. GuiStyle& style = GetStyle();
  533.  
  534. window.ItemsCount = window.ItemsCountDisplay;
  535. window.ItemsCountDisplay += 1;
  536.  
  537. //Check if the this item is max the maximum of item can be display
  538. if (window.ScrollNeeded && window.ItemsCount < window.ScrollState || window.ItemsCountDisplay > style.ItemsMaximum + window.ScrollState)
  539. return *p_state;
  540.  
  541. float rightWinOffset = window.Size.x - 23.0f - window.MaxX - window.ScrollSize.x - style.OffsetFromScrollbar;
  542.  
  543. window.ItemsLastPos = window.ItemsCurrentPos;
  544.  
  545. if (!window.ScrollIsDragging && IsMouseHoveringRect(Vector2(window.ItemsCurrentPos.x, window.ItemsCurrentPos.y), Vector2(rightWinOffset, style.ItemsOffset))
  546. && !g.IO.MouseDragging)
  547. {
  548. g_pDrawManager->AddFillRect(window.ItemsCurrentPos.x, window.ItemsCurrentPos.y, rightWinOffset, style.ItemsOffset, 0xF1F1F1A0);
  549. if (IsMouseClicked(0, true))
  550. {
  551. *p_state = !(*p_state);
  552. }
  553. }
  554.  
  555. if (!window.ExpansionPop && window.ExpansionWasActive)
  556. g_pDrawManager->AddText(window.ItemsCurrentPos.x + 23.0f, window.ItemsCurrentPos.y + 4.0f, Colors::Black, 1, notting, label);
  557. else
  558. g_pDrawManager->AddText(window.ItemsCurrentPos.x, window.ItemsCurrentPos.y + 4.0f, Colors::Black, 1, notting, label);
  559.  
  560. if (window.TabsActive)
  561. window.ItemsCurrentPos.x = (window.Pos.x + window.Size.x) - window.MaxX - window.ScrollSize.x - style.OffsetFromScrollbar - 23.0f;
  562. //Todo: Ajouter un mode de positionnement normal dependament la longeur du text
  563.  
  564.  
  565. //Debug
  566. //g_pDrawManager->AddRect(window.ItemsCurrentPos.x, window.ItemsCurrentPos.y, rightWinOffset, style.ItemsOffset, Colors::DarkViolet, 0.0f);
  567.  
  568. if (*p_state)
  569. {
  570. window.ItemsCurrentPos.y += 9.0f;
  571. g_pDrawManager->AddFillRect(window.ItemsCurrentPos.x, window.ItemsCurrentPos.y, 23.0f, 8.0f, 0xD06F71FF, 4.0f);
  572. window.ItemsCurrentPos.x += 10.0f;
  573. window.ItemsCurrentPos.y -= 2.0f;
  574.  
  575. g_pDrawManager->AddFillCircle(window.ItemsCurrentPos.x, window.ItemsCurrentPos.y, 6.0f, 0xB80000FF);
  576. window.ItemsCurrentPos = window.ItemsLastPos;
  577. window.ItemsCurrentPos.y += style.ItemsOffset;
  578. return true;
  579. }
  580. else
  581. {
  582. window.ItemsCurrentPos.y += 7.0f;
  583. g_pDrawManager->AddFillRect(window.ItemsCurrentPos.x, window.ItemsCurrentPos.y, 23.0f, 8.0f, 0xD9D9D9FF, 4.0f);
  584. window.ItemsCurrentPos.y -= 2.0f;
  585.  
  586. g_pDrawManager->AddFillCircle(window.ItemsCurrentPos.x, window.ItemsCurrentPos.y, 6.0f, 0xF1F1F1FF);
  587. window.ItemsCurrentPos = window.ItemsLastPos;
  588. window.ItemsCurrentPos.y += style.ItemsOffset;
  589. return false;
  590. }
  591. }
  592.  
  593. bool Gui::ExpansionPanel(const char* label, bool* p_state)
  594. {
  595. GuiContext& g = *GGui;
  596. GuiWindow& window = GetWindow();
  597. GuiStyle& style = GetStyle();
  598.  
  599. //Setting the ExpansionPush
  600. window.ExpansionPop = false;
  601.  
  602. float rightWinOffset = window.Size.x - 23.0f - window.MaxX - window.ScrollSize.x - style.OffsetFromScrollbar;
  603.  
  604. window.ItemsCount = window.ItemsCountDisplay;
  605. window.ItemsCountDisplay += 1;
  606.  
  607. if(*p_state)
  608. window.ExpansionWasActive = true;
  609. else
  610. window.ExpansionPop = true;
  611.  
  612. if (window.ScrollNeeded && window.ItemsCount < window.ScrollState || window.ItemsCountDisplay > style.ItemsMaximum + window.ScrollState)
  613. return *p_state;
  614.  
  615. window.ItemsLastPos = window.ItemsCurrentPos;
  616.  
  617. if (!window.ScrollIsDragging && IsMouseHoveringRect(Vector2(window.ItemsCurrentPos.x, window.ItemsCurrentPos.y), Vector2(rightWinOffset, style.ItemsOffset))
  618. && !g.IO.MouseDragging)
  619. {
  620. g_pDrawManager->AddFillRect(window.ItemsCurrentPos.x, window.ItemsCurrentPos.y, rightWinOffset, style.ItemsOffset, 0xF1F1F1A0);
  621. if (IsMouseClicked(0, true))
  622. {
  623. *p_state = !(*p_state);
  624. }
  625. }
  626.  
  627. g_pDrawManager->AddText(window.ItemsCurrentPos.x, window.ItemsCurrentPos.y + 4.0f, Colors::Black, 1, notting, label);
  628.  
  629. if (*p_state)
  630. {
  631. g_pDrawManager->AddFillCircle(window.ItemsCurrentPos.x + rightWinOffset - 14.0f, window.ItemsCurrentPos.y + 11.0f, 1.5f, 0x0000004D);
  632. g_pDrawManager->AddFillCircle(window.ItemsCurrentPos.x + rightWinOffset - 15.0f, window.ItemsCurrentPos.y + 12.0f, 1.5f, 0x0000004D);
  633. g_pDrawManager->AddFillCircle(window.ItemsCurrentPos.x + rightWinOffset - 16.0f, window.ItemsCurrentPos.y + 13.0f, 1.5f, 0x0000004D);
  634. g_pDrawManager->AddFillCircle(window.ItemsCurrentPos.x + rightWinOffset - 17.0f, window.ItemsCurrentPos.y + 14.0f, 1.5f, 0x0000004D);
  635. g_pDrawManager->AddFillCircle(window.ItemsCurrentPos.x + rightWinOffset - 18.0f, window.ItemsCurrentPos.y + 15.0f, 1.5f, 0x0000004D);
  636.  
  637. g_pDrawManager->AddFillCircle(window.ItemsCurrentPos.x + rightWinOffset - 13.0f, window.ItemsCurrentPos.y + 11.0f, 1.5f, 0x0000004D);
  638. g_pDrawManager->AddFillCircle(window.ItemsCurrentPos.x + rightWinOffset - 12.0f, window.ItemsCurrentPos.y + 12.0f, 1.5f, 0x0000004D);
  639. g_pDrawManager->AddFillCircle(window.ItemsCurrentPos.x + rightWinOffset - 11.0f, window.ItemsCurrentPos.y + 13.0f, 1.5f, 0x0000004D);
  640. g_pDrawManager->AddFillCircle(window.ItemsCurrentPos.x + rightWinOffset - 10.0f, window.ItemsCurrentPos.y + 14.0f, 1.5f, 0x0000004D);
  641. g_pDrawManager->AddFillCircle(window.ItemsCurrentPos.x + rightWinOffset - 9.0f, window.ItemsCurrentPos.y + 15.0f, 1.5f, 0x0000004D);
  642.  
  643.  
  644. window.ExpansionActive = true;
  645. window.ItemsCurrentPos = window.ItemsLastPos;
  646. window.ItemsCurrentPos.y += style.ItemsOffset;
  647. return true;
  648. }
  649. else
  650. {
  651. g_pDrawManager->AddFillCircle(window.ItemsCurrentPos.x + rightWinOffset - 14.0f, window.ItemsCurrentPos.y + 15.0f, 1.5f, 0x0000004D);
  652. g_pDrawManager->AddFillCircle(window.ItemsCurrentPos.x + rightWinOffset - 15.0f, window.ItemsCurrentPos.y + 14.0f, 1.5f, 0x0000004D);
  653. g_pDrawManager->AddFillCircle(window.ItemsCurrentPos.x + rightWinOffset - 16.0f, window.ItemsCurrentPos.y + 13.0f, 1.5f, 0x0000004D);
  654. g_pDrawManager->AddFillCircle(window.ItemsCurrentPos.x + rightWinOffset - 17.0f, window.ItemsCurrentPos.y + 12.0f, 1.5f, 0x0000004D);
  655. g_pDrawManager->AddFillCircle(window.ItemsCurrentPos.x + rightWinOffset - 18.0f, window.ItemsCurrentPos.y + 11.0f, 1.5f, 0x0000004D);
  656.  
  657. g_pDrawManager->AddFillCircle(window.ItemsCurrentPos.x + rightWinOffset - 13.0f, window.ItemsCurrentPos.y + 15.0f, 1.5f, 0x0000004D);
  658. g_pDrawManager->AddFillCircle(window.ItemsCurrentPos.x + rightWinOffset - 12.0f, window.ItemsCurrentPos.y + 14.0f, 1.5f, 0x0000004D);
  659. g_pDrawManager->AddFillCircle(window.ItemsCurrentPos.x + rightWinOffset - 11.0f, window.ItemsCurrentPos.y + 13.0f, 1.5f, 0x0000004D);
  660. g_pDrawManager->AddFillCircle(window.ItemsCurrentPos.x + rightWinOffset - 10.0f, window.ItemsCurrentPos.y + 12.0f, 1.5f, 0x0000004D);
  661. g_pDrawManager->AddFillCircle(window.ItemsCurrentPos.x + rightWinOffset - 9.0f, window.ItemsCurrentPos.y + 11.0f, 1.5f, 0x0000004D);
  662.  
  663. window.ExpansionActive = false;
  664. window.ItemsCurrentPos = window.ItemsLastPos;
  665. window.ItemsCurrentPos.y += style.ItemsOffset;
  666. return false;
  667. }
  668. //window.ExpansionPop = true;
  669. return true;
  670. }
  671.  
  672. void Gui::ExpansionPanelPop()
  673. {
  674. GuiWindow& window = GetWindow();
  675. window.ExpansionPop = true;
  676. }
  677.  
  678. void Gui::Divider()
  679. {
  680.  
  681. }
  682.  
  683. bool Gui::SliderFloat(const char* label, float* v, float v_min, float v_max, int precision, const char* display_format)
  684. {
  685. GuiContext& g = *GGui;
  686. GuiWindow& window = GetWindow();
  687. GuiStyle& style = GetStyle();
  688.  
  689. window.ItemsCount = window.ItemsCountDisplay;
  690. window.ItemsCountDisplay += 1;
  691.  
  692. //Check if the this item is max the maximum of item can be display
  693. if (window.ScrollNeeded && window.ItemsCount < window.ScrollState || window.ItemsCountDisplay > style.ItemsMaximum + window.ScrollState)
  694. return false;
  695.  
  696. window.ItemsLastPos = window.ItemsCurrentPos;
  697.  
  698. bool slideActive = false;
  699. bool Hovering = false;
  700. window.ScrollIsDragging = false;
  701.  
  702. std::stringstream ss;
  703. ss << std::fixed << std::setprecision(precision) << *v << display_format;
  704. std::string text = ss.str();
  705. if (!window.ExpansionPop && window.ExpansionWasActive)
  706. {
  707. window.ItemsCurrentPos.x += 23.0f;
  708. g_pDrawManager->AddText(window.ItemsCurrentPos.x, window.ItemsCurrentPos.y + 4.0f, Colors::Black, 1, notting, label);
  709. //window.ItemsCurrentPos.x += 23.0f;
  710. }
  711. else
  712. g_pDrawManager->AddText(window.ItemsCurrentPos.x, window.ItemsCurrentPos.y + 4.0f, Colors::Black, 1, notting, label);
  713.  
  714. window.ItemsCurrentPos.x += 84.0f;
  715. window.ItemsCurrentPos.y += 12.0f;
  716.  
  717. float SliderLenght = 170;
  718. if (!window.ExpansionPop && window.ExpansionWasActive)
  719. SliderLenght -= 23.0f;
  720.  
  721. g_pDrawManager->AddFillRect(window.ItemsCurrentPos.x, window.ItemsCurrentPos.y, SliderLenght, 2.0f, 0xD9D9D9FF);
  722. g_pDrawManager->AddText(window.ItemsCurrentPos.x + SliderLenght + 10.0f, window.ItemsCurrentPos.y - 8.0f, Colors::Black, 1, notting, text.c_str());
  723.  
  724. g_pDrawManager->AddFillRect(window.ItemsCurrentPos.x + SliderLenght + 8.0f, window.ItemsCurrentPos.y + 8.0f, g_pDrawManager->GetTextLength(1, text.c_str()) - 6.0f, 1, 0xD9D9D9FF);
  725.  
  726. if (IsMouseHoveringRect(Vector2(window.ItemsCurrentPos.x - 50.0f, window.ItemsCurrentPos.y - 12.0f), Vector2(SliderLenght + 100.0f, style.ItemsOffset))
  727. && !g.IO.MouseDragging)
  728. {
  729. if (IsMouseClicked(0, true) && !IsMouseReleased(0))
  730. slideActive = true;
  731. else
  732. slideActive = false;
  733. Hovering = true;
  734. }
  735.  
  736. //Debug
  737. //g_pDrawManager->AddRect(window.ItemsCurrentPos.x - 50.0f, window.ItemsCurrentPos.y - 12.0f, SliderLenght + 100.0f, style.ItemsOffset, Colors::DarkViolet, 0.0f);
  738.  
  739. if (v)
  740. {
  741. float vm = ((*v) - v_min) * SliderLenght / ((v_max)-v_min);
  742. g_pDrawManager->AddFillRect(window.ItemsCurrentPos.x, window.ItemsCurrentPos.y, vm, 2.0f, 0xB80000FF);
  743. if (!slideActive && !Hovering)
  744. g_pDrawManager->AddFillCircle(window.ItemsCurrentPos.x + vm - 5.0f, window.ItemsCurrentPos.y - 3.0f, 4.0f, 0xB80000FF);
  745. if (Hovering && g.IO.MouseDownDuration[0] == -1.0f)
  746. {
  747. g_pDrawManager->AddFillCircle(window.ItemsCurrentPos.x + vm - 9.0f, window.ItemsCurrentPos.y - 7.0f, 8.0f, 0xB8000033);
  748. g_pDrawManager->AddFillCircle(window.ItemsCurrentPos.x + vm - 5.0f, window.ItemsCurrentPos.y - 3.0f, 4.0f, 0xB80000FF);
  749. }
  750. if (Hovering && g.IO.MouseDownDuration[0] >= 0)
  751. {
  752. window.ScrollIsDragging = true;
  753. g_pDrawManager->AddFillCircle(window.ItemsCurrentPos.x + vm - 7.0f, window.ItemsCurrentPos.y - 5.0f, 6.0f, 0xB80000FF);
  754. }
  755. }
  756.  
  757. if (v && slideActive)
  758. {
  759. *v = (g.IO.MousePos.x - window.ItemsCurrentPos.x) * (v_max - v_min) / SliderLenght;
  760. if (*v > v_max)
  761. *v = v_max;
  762. if (*v < v_min)
  763. *v = v_min;
  764. }
  765. //Set the offset for next item position
  766. window.ItemsCurrentPos = window.ItemsLastPos;
  767. window.ItemsCurrentPos.y += style.ItemsOffset;
  768. return true;
  769. }
  770.  
  771. bool Gui::SliderInt(const char* label, int* v, int v_min, int v_max, const char* display_format)
  772. {
  773. GuiContext& g = *GGui;
  774. GuiWindow& window = GetWindow();
  775. GuiStyle& style = GetStyle();
  776.  
  777. window.ItemsCount = window.ItemsCountDisplay;
  778. window.ItemsCountDisplay += 1;
  779.  
  780. //Check if the this item is max the maximum of item can be display
  781. if (window.ScrollNeeded && window.ItemsCount < window.ScrollState || window.ItemsCountDisplay > style.ItemsMaximum + window.ScrollState)
  782. return false;
  783.  
  784. window.ItemsLastPos = window.ItemsCurrentPos;
  785.  
  786. bool slideActive = false;
  787. bool Hovering = false;
  788. window.ScrollIsDragging = false;
  789.  
  790. std::stringstream ss;
  791. ss << std::fixed << std::setprecision(0) << *v << display_format;
  792. std::string text = ss.str();
  793. if (!window.ExpansionPop && window.ExpansionWasActive)
  794. {
  795. window.ItemsCurrentPos.x += 23.0f;
  796. g_pDrawManager->AddText(window.ItemsCurrentPos.x, window.ItemsCurrentPos.y + 4.0f, Colors::Black, 1, notting, label);
  797. //window.ItemsCurrentPos.x += 23.0f;
  798. }
  799. else
  800. g_pDrawManager->AddText(window.ItemsCurrentPos.x, window.ItemsCurrentPos.y + 4.0f, Colors::Black, 1, notting, label);
  801.  
  802. window.ItemsCurrentPos.x += 84.0f;
  803. window.ItemsCurrentPos.y += 12.0f;
  804.  
  805. float SliderLenght = 170;
  806. if (!window.ExpansionPop && window.ExpansionWasActive)
  807. SliderLenght -= 23.0f;
  808.  
  809. g_pDrawManager->AddFillRect(window.ItemsCurrentPos.x, window.ItemsCurrentPos.y, SliderLenght, 2.0f, 0xD9D9D9FF);
  810. g_pDrawManager->AddText(window.ItemsCurrentPos.x + SliderLenght + 10.0f, window.ItemsCurrentPos.y - 8.0f, Colors::Black, 1, notting,text.c_str());
  811.  
  812. g_pDrawManager->AddFillRect(window.ItemsCurrentPos.x + SliderLenght + 8.0f, window.ItemsCurrentPos.y + 8.0f, g_pDrawManager->GetTextLength(1, text.c_str()) - 6.0f, 1, 0xD9D9D9FF);
  813.  
  814. if (IsMouseHoveringRect(Vector2(window.ItemsCurrentPos.x - 50.0f, window.ItemsCurrentPos.y - 12.0f), Vector2(SliderLenght + 100.0f, style.ItemsOffset))
  815. && !g.IO.MouseDragging)
  816. {
  817. if (IsMouseClicked(0, true) && !IsMouseReleased(0))
  818. slideActive = true;
  819. else
  820. slideActive = false;
  821. Hovering = true;
  822. }
  823.  
  824. //Debug
  825. //g_pDrawManager->AddRect(window.ItemsCurrentPos.x - 50.0f, window.ItemsCurrentPos.y - 12.0f, SliderLenght + 100.0f, style.ItemsOffset, Colors::DarkViolet, 0.0f);
  826.  
  827. if (v)
  828. {
  829. float vm = ((*v) - v_min) * SliderLenght / ((v_max) - v_min);
  830. g_pDrawManager->AddFillRect(window.ItemsCurrentPos.x, window.ItemsCurrentPos.y, vm, 2.0f, 0xB80000FF);
  831. if (!slideActive && !Hovering)
  832. g_pDrawManager->AddFillCircle(window.ItemsCurrentPos.x + vm - 5.0f, window.ItemsCurrentPos.y - 3.0f, 4.0f, 0xB80000FF);
  833. if (Hovering && g.IO.MouseDownDuration[0] == -1.0f)
  834. {
  835. g_pDrawManager->AddFillCircle(window.ItemsCurrentPos.x + vm - 9.0f, window.ItemsCurrentPos.y - 7.0f, 8.0f, 0xB8000033);
  836. g_pDrawManager->AddFillCircle(window.ItemsCurrentPos.x + vm - 5.0f, window.ItemsCurrentPos.y - 3.0f, 4.0f, 0xB80000FF);
  837. }
  838. if (Hovering && g.IO.MouseDownDuration[0] >= 0)
  839. {
  840. window.ScrollIsDragging = true;
  841. g_pDrawManager->AddFillCircle(window.ItemsCurrentPos.x + vm - 7.0f, window.ItemsCurrentPos.y - 5.0f, 6.0f, 0xB80000FF);
  842. }
  843. }
  844.  
  845. if (v && slideActive)
  846. {
  847. *v = (g.IO.MousePos.x - window.ItemsCurrentPos.x) * (v_max - v_min) / SliderLenght;
  848. if (*v > v_max)
  849. *v = v_max;
  850. if (*v < v_min)
  851. *v = v_min;
  852. }
  853. //Set the offset for next item position
  854. window.ItemsCurrentPos = window.ItemsLastPos;
  855. window.ItemsCurrentPos.y += style.ItemsOffset;
  856. return true;
  857. }
  858.  
  859. bool Gui::SliderDegree(const char* label, int* v, int v_min, int v_max, const char* display_format)
  860. {
  861. GuiContext& g = *GGui;
  862. GuiWindow& window = GetWindow();
  863. GuiStyle& style = GetStyle();
  864.  
  865. window.ItemsCount = window.ItemsCountDisplay;
  866. window.ItemsCountDisplay += 1;
  867.  
  868. //Check if the this item is max the maximum of item can be display
  869. if (window.ScrollNeeded && window.ItemsCount < window.ScrollState || window.ItemsCountDisplay > style.ItemsMaximum + window.ScrollState)
  870. return false;
  871.  
  872. window.ItemsLastPos = window.ItemsCurrentPos;
  873.  
  874. bool slideActive = false;
  875. bool Hovering = false;
  876. window.ScrollIsDragging = false;
  877.  
  878. std::stringstream ss;
  879. ss << std::fixed << std::setprecision(0) << *v << display_format;
  880. std::string text = ss.str();
  881. if (!window.ExpansionPop && window.ExpansionWasActive)
  882. {
  883. window.ItemsCurrentPos.x += 23.0f;
  884. g_pDrawManager->AddText(window.ItemsCurrentPos.x, window.ItemsCurrentPos.y + 4.0f, Colors::Black, 1, notting, label);
  885. //window.ItemsCurrentPos.x += 23.0f;
  886. }
  887. else
  888. g_pDrawManager->AddText(window.ItemsCurrentPos.x, window.ItemsCurrentPos.y + 4.0f, Colors::Black, 1, notting, label);
  889.  
  890. window.ItemsCurrentPos.x += 84.0f;
  891. window.ItemsCurrentPos.y += 12.0f;
  892.  
  893. float SliderLenght = 170;
  894. if (!window.ExpansionPop && window.ExpansionActive)
  895. SliderLenght -= 23.0f;
  896.  
  897. g_pDrawManager->AddFillRect(window.ItemsCurrentPos.x, window.ItemsCurrentPos.y, SliderLenght, 2.0f, 0xD9D9D9FF);
  898. g_pDrawManager->AddText(window.ItemsCurrentPos.x + SliderLenght + 10.0f, window.ItemsCurrentPos.y - 8.0f, Colors::Black, 1, notting, text.c_str());
  899.  
  900. g_pDrawManager->AddFillRect(window.ItemsCurrentPos.x + SliderLenght + 8.0f, window.ItemsCurrentPos.y + 8.0f, g_pDrawManager->GetTextLength(1, text.c_str()) - 6.0f, 1, 0xD9D9D9FF);
  901.  
  902. if (IsMouseHoveringRect(Vector2(window.ItemsCurrentPos.x - 50.0f, window.ItemsCurrentPos.y - 12.0f), Vector2(SliderLenght + 100.0f, style.ItemsOffset))
  903. && !g.IO.MouseDragging)
  904. {
  905. if (IsMouseClicked(0, true) && !IsMouseReleased(0))
  906. slideActive = true;
  907. else
  908. slideActive = false;
  909. Hovering = true;
  910. }
  911.  
  912. //Debug
  913. //g_pDrawManager->AddRect(window.ItemsCurrentPos.x - 50.0f, window.ItemsCurrentPos.y - 12.0f, SliderLenght + 100.0f, style.ItemsOffset, Colors::DarkViolet, 0.0f);
  914.  
  915. if (v)
  916. {
  917. float vm = ((*v) - v_min) * SliderLenght / ((v_max)-v_min);
  918. g_pDrawManager->AddFillRect(window.ItemsCurrentPos.x, window.ItemsCurrentPos.y, vm, 2.0f, 0xB80000FF);
  919. if (!slideActive && !Hovering)
  920. g_pDrawManager->AddFillCircle(window.ItemsCurrentPos.x + vm - 5.0f, window.ItemsCurrentPos.y - 3.0f, 4.0f, 0xB80000FF);
  921. if (Hovering && g.IO.MouseDownDuration[0] == -1.0f)
  922. {
  923. g_pDrawManager->AddFillCircle(window.ItemsCurrentPos.x + vm - 9.0f, window.ItemsCurrentPos.y - 7.0f, 8.0f, 0xB8000033);
  924. g_pDrawManager->AddFillCircle(window.ItemsCurrentPos.x + vm - 5.0f, window.ItemsCurrentPos.y - 3.0f, 4.0f, 0xB80000FF);
  925. }
  926. if (Hovering && g.IO.MouseDownDuration[0] >= 0)
  927. {
  928. window.ScrollIsDragging = true;
  929. g_pDrawManager->AddFillCircle(window.ItemsCurrentPos.x + vm - 7.0f, window.ItemsCurrentPos.y - 5.0f, 6.0f, 0xB80000FF);
  930. }
  931. }
  932.  
  933. if (v && slideActive)
  934. {
  935. *v = (g.IO.MousePos.x - window.ItemsCurrentPos.x) * (v_max - v_min) / SliderLenght;
  936. if (*v > v_max)
  937. *v = v_max;
  938. if (*v < v_min)
  939. *v = v_min;
  940. }
  941. //Set the offset for next item position
  942. window.ItemsCurrentPos = window.ItemsLastPos;
  943. window.ItemsCurrentPos.y += style.ItemsOffset;
  944. return true;
  945. }
  946.  
  947. bool Gui::IsKeyDown(int key_index)
  948. {
  949. if (key_index < 0) return false;
  950. ASSERT(key_index > = 0 && hey_index < ARRAYSIZE(GGui->IO.KeysDown));
  951. return GGui->IO.KeysDown[key_index];
  952. }
  953.  
  954. bool Gui::IsKeyPressed(int key_index, bool repeat)
  955. {
  956. GuiContext& g = *GGui;
  957. if (key_index < 0) return false;
  958. ASSERT(key_index >= 0 && key_index < ARRAYSIZE(g.IO.KeysDown));
  959. const float t = g.IO.KeysDownDuration[key_index];
  960. if (t == 0.0f)
  961. return true;
  962.  
  963. if (repeat && t > g.IO.KeyRepeatDelay)
  964. {
  965. float delay = g.IO.KeyRepeatDelay, rate = g.IO.KeyRepeatRate;
  966. if ((fmodf(t - delay, rate) > rate*0.5f) != (fmodf(t - delay - g.IO.DeltaTime, rate) > rate*0.5f))
  967. return true;
  968. }
  969.  
  970. return false;
  971. }
  972.  
  973. bool Gui::IsKeyReleased(int key_index)
  974. {
  975. GuiContext& g = *GGui;
  976. if (key_index < 0) return false;
  977. ASSERT(key_index >= 0 && key_index < ARRAYSIZE(g.IO.KeysDown));
  978. if (g.IO.KeysDownDurationPrev[key_index] >= 0.0f && !g.IO.KeysDown[key_index])
  979. return true;
  980. return false;
  981. }
  982.  
  983. bool Gui::IsMouseDown(int button)
  984. {
  985. GuiContext& g = *GGui;
  986. ASSERT(button >= 0 && button < ARRAYSIZE(g.IO.MouseDown));
  987. return g.IO.MouseDown[button];
  988. }
  989.  
  990. bool Gui::IsMouseClicked(int button, bool repeat)
  991. {
  992. GuiContext& g = *GGui;
  993. ASSERT(button >= 0 && button < ARRAYSIZE(g.IO.MouseDown));
  994. const float t = g.IO.MouseDownDuration[button];
  995. if (t == 0.0f)
  996. return true;
  997.  
  998. if (repeat && t > g.IO.KeyRepeatDelay)
  999. {
  1000. float delay = g.IO.KeyRepeatDelay, rate = g.IO.KeyRepeatRate;
  1001. if ((fmodf(t - delay, rate) > rate - 0.5f) != (fmodf(t - delay - g.IO.DeltaTime, rate) > rate*0.5f))
  1002. return true;
  1003. }
  1004.  
  1005. return false;
  1006. }
  1007.  
  1008. bool Gui::IsMouseDoubleClicked(int button)
  1009. {
  1010. GuiContext& g = *GGui;
  1011. ASSERT(button >= 0 && button < ARRAYSIZE(g.IO.MouseDown));
  1012. return g.IO.MouseDoubleClicked[button];
  1013. }
  1014.  
  1015. bool Gui::IsMouseReleased(int button)
  1016. {
  1017. GuiContext& g = *GGui;
  1018. ASSERT(button >= 0 && button < ARRAYSIZE(g.IO.MouseDown));
  1019. return g.IO.MouseReleased[button];
  1020. }
  1021.  
  1022. bool Gui::IsMouseHoveringRect(const Vector2& r_min, const Vector2& r_max, bool clip)
  1023. {
  1024. GuiContext& g = *GGui;
  1025.  
  1026. //clip
  1027. Rect rect_clipped(r_min, r_max);
  1028. if (clip)
  1029. rect_clipped.Add(Vector4(r_min.x, r_min.y, r_min.x + r_max.x, r_min.y + r_max.y));
  1030. //rect_clipped.Clip(Vector4(r_min.x, r_min.y, r_min.x + r_max.x, r_min.y + r_max.y));
  1031.  
  1032. //rect_clipped.Add(Vector4(0,0,0,0));
  1033. return rect_clipped.Contains(g.IO.MousePos);
  1034. }
  1035.  
  1036. Vector2 Gui::GetMousePos()
  1037. {
  1038. return GGui->IO.MousePos;
  1039. }
  1040.  
  1041. U32 Hash(const void* data, int data_size, U32 seed)
  1042. {
  1043. static U32 crc32_lut[256] = { 0 };
  1044. if (!crc32_lut[1])
  1045. {
  1046. const U32 polynomial = 0xEDB88320;
  1047. for (U32 i = 0; i < 256; i++)
  1048. {
  1049. U32 crc = i;
  1050. for (U32 j = 0; j < 8; j++)
  1051. crc = (crc >> 1) ^ (U32(-int(crc & 1)) & polynomial);
  1052. crc32_lut[i] = crc;
  1053. }
  1054. }
  1055.  
  1056. seed = ~seed;
  1057. U32 crc = seed;
  1058. const unsigned char* current = (const unsigned char*)data;
  1059.  
  1060. if (data_size > 0)
  1061. {
  1062. // Known size
  1063. while (data_size--)
  1064. crc = (crc >> 8) ^ crc32_lut[(crc & 0xFF) ^ *current++];
  1065. }
  1066. else
  1067. {
  1068. // Zero-terminated string
  1069. while (unsigned char c = *current++)
  1070. {
  1071. // We support a syntax of "label###id" where only "###id" is included in the hash, and only "label" gets displayed.
  1072. // Because this syntax is rarely used we are optimizing for the common case.
  1073. // - If we reach ### in the string we discard the hash so far and reset to the seed.
  1074. // - We don't do 'current += 2; continue;' after handling ### to keep the code smaller.
  1075. if (c == '#' && current[0] == '#' && current[1] == '#')
  1076. crc = seed;
  1077. crc = (crc >> 8) ^ crc32_lut[(crc & 0xFF) ^ c];
  1078. }
  1079. }
  1080. return ~crc;
  1081. }
  1082.  
  1083. int Gui::FormatString(char* buf, int buf_size, const char* fmt, ...)
  1084. {
  1085. va_list args;
  1086. va_start(args, fmt);
  1087. int w = vsnprintf(buf, buf_size, fmt, args);
  1088.  
  1089. va_end(args);
  1090. if (buf == NULL)
  1091. return w;
  1092. if (w == -1 || w >= buf_size)
  1093. w = buf_size - 1;
  1094. buf[w] = 0;
  1095. return w;
  1096. }
  1097.  
  1098. const char* Gui::FindRenderedTextEnd(const char* text, const char* text_end)
  1099. {
  1100. const char* text_display_end = text;
  1101. if (!text_end)
  1102. text_end = (const char*)-1;
  1103. while (text_display_end < text_end && *text_display_end != '\0' && (text_display_end[0] != '#' || text_display_end[1] != '#'))
  1104. text_display_end++;
  1105. return text_display_end;
  1106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement