Advertisement
Guest User

Untitled

a guest
Oct 21st, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.93 KB | None | 0 0
  1. #define UI_COL_SHADOW Color(56, 58, 61, 255)
  2. #define UI_COL_TABTEXT Color(145, 145, 145, 255)
  3. #define UI_CHK_SIZE 16
  4. #include "Controls.h"
  5. #include "RenderManager.h"
  6.  
  7. #pragma region Base Control
  8. void CControl::SetPosition(int x, int y)
  9. {
  10. m_x = x;
  11. m_y = y;
  12. }
  13.  
  14. void CControl::SetSize(int w, int h)
  15. {
  16. m_iWidth = w;
  17. m_iHeight = h;
  18. }
  19.  
  20. void CControl::GetSize(int &w, int &h)
  21. {
  22. w = m_iWidth;
  23. h = m_iHeight;
  24. }
  25.  
  26. bool CControl::Flag(int f)
  27. {
  28. if (m_Flags & f)
  29. return true;
  30. else
  31. return false;
  32. }
  33.  
  34. POINT CControl::GetAbsolutePos()
  35. {
  36. POINT p;
  37. RECT client = parent->GetClientArea();
  38. if (parent)
  39. {
  40. p.x = m_x + client.left;
  41. p.y = m_y + client.top + 29;
  42. }
  43.  
  44. return p;
  45. }
  46.  
  47. void CControl::SetFileId(std::string fid)
  48. {
  49. FileIdentifier = fid;
  50. }
  51. #pragma endregion Implementations of the Base control functions
  52.  
  53. #pragma region CheckBox
  54. CCheckBox::CCheckBox()
  55. {
  56. Checked = false;
  57.  
  58. m_Flags = UIFlags::UI_Clickable | UIFlags::UI_Drawable | UIFlags::UI_SaveFile;
  59. m_iWidth = 13;
  60. m_iHeight = 13;
  61.  
  62. FileControlType = UIControlTypes::UIC_CheckBox;
  63. }
  64.  
  65. void CCheckBox::SetState(bool s)
  66. {
  67. Checked = s;
  68. }
  69.  
  70. bool CCheckBox::GetState()
  71. {
  72. return Checked;
  73. }
  74.  
  75. void CCheckBox::Draw(bool hover)
  76. {
  77. POINT a = GetAbsolutePos();
  78.  
  79. Color outline = Color(0, 0, 0, 255);
  80.  
  81. if (hover)
  82. {
  83. if (Checked)
  84. {
  85. outline = Color(65, 65, 65, 255);
  86. }
  87. else
  88. {
  89. outline = Color(31, 232, 233, 255);
  90. }
  91. }
  92. else if (Checked)
  93. {
  94. outline = Color(0, 0, 0, 255);
  95. }
  96.  
  97. if (Checked)
  98. Render::Clear(a.x + 150, a.y, UI_CHK_SIZE, UI_CHK_SIZE, Color(31, 232, 233, 255));
  99. Render::Outline(a.x + 150, a.y, UI_CHK_SIZE, UI_CHK_SIZE, outline);
  100.  
  101. }
  102.  
  103. void CCheckBox::OnUpdate() { m_iWidth = UI_CHK_SIZE + 150; m_iHeight = UI_CHK_SIZE; }
  104.  
  105. void CCheckBox::OnClick()
  106. {
  107. Checked = !Checked;
  108. }
  109. #pragma endregion Implementations of the Check Box functions
  110.  
  111. #pragma region Label
  112. CLabel::CLabel()
  113. {
  114. m_Flags = UIFlags::UI_Drawable;
  115. Text = "Default";
  116. FileIdentifier = "Default";
  117. }
  118.  
  119. void CLabel::Draw(bool hover)
  120. {
  121. POINT a = GetAbsolutePos();
  122. Render::Text(a.x, a.y, Color(245, 245, 245, 255), Render::Fonts::Menu, Text.c_str());
  123. }
  124.  
  125. void CLabel::SetText(std::string text)
  126. {
  127. Text = text;
  128. }
  129.  
  130. void CLabel::OnUpdate() {}
  131. void CLabel::OnClick() {}
  132. #pragma endregion Implementations of the Label functions
  133.  
  134. #pragma region GroupBox
  135. CGroupBox::CGroupBox()
  136. {
  137. Items = 1;
  138. m_Flags = UIFlags::UI_Drawable | UIFlags::UI_RenderFirst;
  139. Text = "Default";
  140. FileIdentifier = "Default";
  141. }
  142.  
  143. void CGroupBox::Draw(bool hover)
  144. {
  145. POINT a = GetAbsolutePos();
  146. RECT txtSize = Render::GetTextSize(Render::Fonts::Menu, Text.c_str());
  147. Render::Clear(a.x + 2, a.y + 2, m_iWidth - 4, m_iHeight - 4, Color(8, 8, 8, 10)); // menu mini box color
  148. Render::Text(a.x + 15, a.y - (txtSize.bottom / 2), Color(255, 255, 255, 255), Render::Fonts::Menu, Text.c_str());
  149.  
  150. Render::Line(a.x, a.y, a.x + 12, a.y, Color(129, 129, 129, 255));
  151. Render::Line(a.x + 15 + txtSize.right + 5, a.y, a.x + m_iWidth, a.y, Color(129, 129, 129, 255));
  152. Render::Line(a.x, a.y, a.x, a.y + m_iHeight, Color(129, 129, 129, 255));
  153. Render::Line(a.x, a.y + m_iHeight, a.x + m_iWidth, a.y + m_iHeight, Color(129, 129, 129, 255));
  154. Render::Line(a.x + m_iWidth, a.y, a.x + m_iWidth, a.y + m_iHeight, Color(129, 129, 129, 255));
  155. }
  156.  
  157. void CGroupBox::SetText(std::string text)
  158. {
  159. Text = text;
  160. }
  161.  
  162. void CGroupBox::PlaceLabledControl(std::string Label, CTab *Tab, CControl* control)
  163. {
  164. int x = m_x + 12;
  165. int y = m_y + Items * 24;
  166.  
  167. CLabel* label = new CLabel;
  168. label->SetPosition(x, y);
  169. label->SetText(Label);
  170. Tab->RegisterControl(label);
  171.  
  172. x += m_iWidth / 2;
  173.  
  174. int cw, ch;
  175. control->SetPosition(x, y);
  176. control->GetSize(cw, ch);
  177. control->SetSize((m_iWidth / 2) - 20, ch);
  178. Tab->RegisterControl(control);
  179. Items++;
  180. }
  181.  
  182. void CGroupBox::OnUpdate() {}
  183. void CGroupBox::OnClick() {}
  184. #pragma endregion Implementations of the Group Box functions
  185.  
  186. #pragma region Sliders
  187. CSlider::CSlider()
  188. {
  189. m_Flags = UIFlags::UI_Drawable | UIFlags::UI_Clickable | UIFlags::UI_SaveFile;
  190.  
  191. FileControlType = UIControlTypes::UIC_Slider;
  192. }
  193.  
  194. void CSlider::Draw(bool hover)
  195. {
  196. POINT a = GetAbsolutePos();
  197.  
  198. Render::Clear(a.x, a.y + 5, m_iWidth, 5, Color(40, 40, 40, 255));
  199. Render::Outline(a.x - 1, a.y + 4, m_iWidth + 2, 7, UI_COL_SHADOW);
  200. Render::GradientV(a.x, a.y + 5, m_iWidth, 3, Color(93, 93, 93, 255), Color(30, 30, 30, 255));
  201.  
  202. float Ratio = Value / (Max - Min);
  203. float Location = Ratio*m_iWidth;
  204.  
  205. Render::Clear(a.x, a.y + 5, Location, 5, Color(31, 232, 233, 255)); /*Slider Color*/
  206. Render::Clear(a.x, a.y + 9, Location, 1, Color(50, 50, 50, 50));
  207.  
  208. char buffer[24];
  209. sprintf_s(buffer, "%.f", Value);
  210. RECT txtSize = Render::GetTextSize(Render::Fonts::Menu, buffer);
  211. if (Location == 0)
  212. Render::Text(a.x + (Location)-txtSize.right / 2 - 2 + 3, a.y + 10, Color(200, 200, 200, 255), Render::Fonts::Menu, buffer);
  213. else
  214. Render::Text(a.x + (Location)-txtSize.right / 2 - 2, a.y + 10, Color(200, 200, 200, 255), Render::Fonts::Menu, buffer);
  215. }
  216.  
  217. void CSlider::OnUpdate() {
  218. POINT a = GetAbsolutePos();
  219. m_iHeight = 11;
  220.  
  221. if (DoDrag)
  222. {
  223. if (GUI.GetKeyState(VK_LBUTTON))
  224. {
  225. POINT m = GUI.GetMouse();
  226. float NewX;
  227. float Ratio;
  228. NewX = m.x - a.x - 1;
  229. if (NewX < 0) NewX = 0;
  230. if (NewX > m_iWidth) NewX = m_iWidth;
  231. Ratio = NewX / float(m_iWidth);
  232. Value = Min + (Max - Min)*Ratio;
  233. }
  234. else
  235. {
  236. DoDrag = false;
  237. }
  238. }
  239. }
  240.  
  241. void CSlider::OnClick() {
  242. POINT a = GetAbsolutePos();
  243. RECT SliderRegion = { a.x, a.y, m_iWidth, 11 };
  244. if (GUI.IsMouseInRegion(SliderRegion))
  245. {
  246. DoDrag = true;
  247. }
  248. }
  249.  
  250. float CSlider::GetValue()
  251. {
  252. return Value;
  253. }
  254.  
  255. void CSlider::SetValue(float v)
  256. {
  257. Value = v;
  258. }
  259.  
  260. void CSlider::SetBoundaries(float min, float max)
  261. {
  262. Min = min; Max = max;
  263. }
  264. #pragma endregion Implementations of the Slider functions
  265.  
  266. #pragma region KeyBinders
  267.  
  268. char* KeyStrings[254] = { nullptr, "Left Mouse", "Right Mouse", "Control+Break", "Middle Mouse", "Mouse 4", "Mouse 5",
  269. nullptr, "Backspace", "TAB", nullptr, nullptr, nullptr, "ENTER", nullptr, nullptr, "SHIFT", "CTRL", "ALT", "PAUSE",
  270. "CAPS LOCK", nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, "ESC", nullptr, nullptr, nullptr, nullptr, "SPACEBAR",
  271. "PG UP", "PG DOWN", "END", "HOME", "Left", "Up", "Right", "Down", nullptr, "Print", nullptr, "Print Screen", "Insert",
  272. "Delete", nullptr, "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
  273. nullptr, "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X",
  274. "Y", "Z", "Left Windows", "Right Windows", nullptr, nullptr, nullptr, "NUM 0", "NUM 1", "NUM 2", "NUM 3", "NUM 4", "NUM 5", "NUM 6",
  275. "NUM 7", "NUM 8", "NUM 9", "*", "+", "_", "-", ".", "/", "F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8", "F9", "F10", "F11", "F12",
  276. "F13", "F14", "F15", "F16", "F17", "F18", "F19", "F20", "F21", "F22", "F23", "F24", nullptr, nullptr, nullptr, nullptr, nullptr,
  277. nullptr, nullptr, nullptr, "NUM LOCK", "SCROLL LOCK", nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
  278. nullptr, nullptr, nullptr, nullptr, nullptr, "LSHIFT", "RSHIFT", "LCONTROL", "RCONTROL", "LMENU", "RMENU", nullptr, nullptr, nullptr,
  279. nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, "Next Track", "Previous Track", "Stop", "Play/Pause", nullptr, nullptr,
  280. nullptr, nullptr, nullptr, nullptr, ";", "+", ",", "-", ".", "/?", "~", nullptr, nullptr, nullptr, nullptr,
  281. nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
  282. nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, "[{", "\\|", "}]", "'\"", nullptr, nullptr, nullptr, nullptr,
  283. nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
  284. nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr };
  285.  
  286. CKeyBind::CKeyBind()
  287. {
  288. m_Flags = UIFlags::UI_Drawable | UIFlags::UI_Clickable | UIFlags::UI_SaveFile;
  289. FileControlType = UIControlTypes::UIC_KeyBind;
  290. }
  291.  
  292. void CKeyBind::Draw(bool hover)
  293. {
  294. POINT a = GetAbsolutePos();
  295.  
  296. Render::Outline(a.x, a.y, m_iWidth, m_iHeight, Color(129, 129, 129, 255));
  297. if (hover)
  298. Render::Clear(a.x + 2, a.y + 2, m_iWidth - 4, m_iHeight - 4, Color(255, 255, 255, 80));
  299. bool GoodKeyName = false;
  300. char NameBuffer[128];
  301. char* KeyName = "Not Bound";
  302.  
  303. if (IsGettingKey)
  304. {
  305. KeyName = "<Press A Key>";
  306. }
  307. else
  308. {
  309. if (Key >= 0)
  310. {
  311. KeyName = KeyStrings[Key];
  312. if (KeyName)
  313. {
  314. GoodKeyName = true;
  315. }
  316. else
  317. {
  318. if (GetKeyNameText(Key << 16, NameBuffer, 127))
  319. {
  320. KeyName = NameBuffer;
  321. GoodKeyName = true;
  322. }
  323. }
  324. }
  325.  
  326. if (!GoodKeyName)
  327. {
  328. KeyName = "No Key Bound";
  329. }
  330. }
  331.  
  332.  
  333. Render::Text(a.x + 2, a.y + 2, Color(255, 255, 255, 255), Render::Fonts::Menu, KeyName);
  334. }
  335.  
  336. void CKeyBind::OnUpdate() {
  337. m_iHeight = 16;
  338. POINT a = GetAbsolutePos();
  339. if (IsGettingKey)
  340. {
  341. for (int i = 0; i < 255; i++)
  342. {
  343. if (GUI.GetKeyPress(i))
  344. {
  345. if (i == VK_ESCAPE)
  346. {
  347. IsGettingKey = false;
  348. Key = -1;
  349. return;
  350. }
  351.  
  352. Key = i;
  353. IsGettingKey = false;
  354. return;
  355. }
  356. }
  357. }
  358. }
  359.  
  360. void CKeyBind::OnClick() {
  361. POINT a = GetAbsolutePos();
  362. if (!IsGettingKey)
  363. {
  364. IsGettingKey = true;
  365. }
  366. }
  367.  
  368. int CKeyBind::GetKey()
  369. {
  370. return Key;
  371. }
  372.  
  373. void CKeyBind::SetKey(int key)
  374. {
  375. Key = key;
  376. }
  377.  
  378. #pragma endregion Implementations of the KeyBind Control functions
  379.  
  380. #pragma region Button
  381. CButton::CButton()
  382. {
  383. m_iWidth = 177;
  384. m_Flags = UIFlags::UI_Drawable | UIFlags::UI_Clickable;
  385. Text = "Default";
  386. CallBack = nullptr;
  387. FileIdentifier = "Default";
  388. }
  389.  
  390. void CButton::Draw(bool hover)
  391. {
  392. POINT a = GetAbsolutePos();
  393. if (hover)
  394. Render::GradientV(a.x + 2, a.y + 2, m_iWidth - 4, m_iHeight - 6, Color(50, 50, 50, 200), Color(50, 50, 50, 255));
  395. else
  396. Render::GradientV(a.x + 2, a.y + 2, m_iWidth - 4, m_iHeight - 6, Color(30, 30, 30, 200), Color(30, 30, 30, 30));
  397.  
  398. RECT TextSize = Render::GetTextSize(Render::Fonts::MenuBold, Text.c_str());
  399. int TextX = a.x + (m_iWidth / 2) - (TextSize.left / 2);
  400. int TextY = a.y + (m_iHeight / 2) - (TextSize.bottom / 2);
  401.  
  402. Render::Text(TextX, TextY, Color(31, 232, 233, 255), Render::Fonts::MenuBold, Text.c_str());
  403. }
  404.  
  405. void CButton::SetText(std::string text)
  406. {
  407. Text = text;
  408. }
  409.  
  410. void CButton::SetCallback(CButton::ButtonCallback_t callback)
  411. {
  412. CallBack = callback;
  413. }
  414.  
  415. void CButton::OnUpdate()
  416. {
  417. m_iHeight = 26;
  418. }
  419.  
  420. void CButton::OnClick()
  421. {
  422. if (CallBack)
  423. CallBack();
  424. }
  425. #pragma endregion Implementations of the Button functions
  426.  
  427. #pragma region ComboBox
  428. CComboBox::CComboBox()
  429. {
  430. m_Flags = UIFlags::UI_Drawable | UIFlags::UI_Clickable | UIFlags::UI_Focusable | UIFlags::UI_SaveFile;
  431. FileControlType = UIControlTypes::UIC_ComboBox;
  432. }
  433.  
  434. void CComboBox::Draw(bool hover)
  435. {
  436. POINT a = GetAbsolutePos();
  437. RECT Region = { a.x, a.y, m_iWidth, 16 };
  438. Render::Outline(a.x, a.y, m_iWidth, 16, Color(129, 129, 129, 255));
  439.  
  440. // Hover for the Top Box
  441. if (GUI.IsMouseInRegion(Region))
  442. Render::Clear(a.x + 2, a.y + 2, m_iWidth - 4, 12, Color(80, 80, 80, 255));
  443.  
  444. // If we have some items
  445. if (Items.size() > 0)
  446. {
  447. // The current item
  448. Render::Text(a.x + 2, a.y + 2, Color(255, 255, 255, 255), Render::Fonts::Menu, GetItem().c_str());
  449.  
  450. // If the drop down part is open
  451. if (IsOpen)
  452. {
  453. Render::Clear(a.x, a.y + 17, m_iWidth, Items.size() * 16, Color(80, 80, 80, 255));
  454.  
  455. // Draw the items
  456. for (int i = 0; i < Items.size(); i++)
  457. {
  458. RECT ItemRegion = { a.x, a.y + 17 + i * 16, m_iWidth, 16 };
  459.  
  460. // Hover
  461. if (GUI.IsMouseInRegion(ItemRegion))
  462. {
  463. Render::Clear(a.x, a.y + 17 + i * 16, m_iWidth, 16, Color(207, 207, 207, 255));
  464. }
  465.  
  466. Render::Text(a.x + 2, a.y + 19 + i * 16, Color(255, 255, 255, 255), Render::Fonts::Menu, Items[i].c_str());
  467. }
  468. }
  469. }
  470. }
  471.  
  472. void CComboBox::AddItem(std::string text)
  473. {
  474. Items.push_back(text);
  475. SelectedIndex = 0;
  476. }
  477.  
  478. void CComboBox::OnUpdate()
  479. {
  480. if (IsOpen)
  481. {
  482. m_iHeight = 16 + 16 * Items.size();
  483.  
  484. if (parent->GetFocus() != this)
  485. IsOpen = false;
  486. }
  487. else
  488. {
  489. m_iHeight = 16;
  490. }
  491.  
  492. }
  493.  
  494. void CComboBox::OnClick()
  495. {
  496. POINT a = GetAbsolutePos();
  497. RECT Region = { a.x, a.y, m_iWidth, 16 };
  498.  
  499. if (IsOpen)
  500. {
  501. // If we clicked one of the items(Not in the top bar)
  502. if (!GUI.IsMouseInRegion(Region))
  503. {
  504. // Draw the items
  505. for (int i = 0; i < Items.size(); i++)
  506. {
  507. RECT ItemRegion = { a.x, a.y + 16 + i * 16, m_iWidth, 16 };
  508.  
  509. // Hover
  510. if (GUI.IsMouseInRegion(ItemRegion))
  511. {
  512. SelectedIndex = i;
  513. }
  514. }
  515. }
  516.  
  517. // Close the drop down
  518. IsOpen = false;
  519. }
  520. else
  521. {
  522. IsOpen = true;
  523. }
  524. }
  525.  
  526. int CComboBox::GetIndex()
  527. {
  528. return SelectedIndex;
  529. }
  530.  
  531. std::string CComboBox::GetItem()
  532. {
  533. if (SelectedIndex >= 0 && SelectedIndex < Items.size())
  534. {
  535. return Items[SelectedIndex];
  536. }
  537.  
  538. return "Error";
  539. }
  540.  
  541. void CComboBox::SelectIndex(int idx)
  542. {
  543. if (idx >= 0 && idx < Items.size())
  544. {
  545. SelectedIndex = idx;
  546. }
  547. }
  548.  
  549. #pragma endregion Implementations of the ComboBox functions
  550.  
  551. char* KeyDigits[254] = { nullptr, "Left Mouse", "Right Mouse", "Control+Break", "Middle Mouse", "Mouse 4", "Mouse 5",
  552. nullptr, "Backspace", "TAB", nullptr, nullptr, nullptr, "ENTER", nullptr, nullptr, "SHIFT", "CTRL", "ALT", "PAUSE",
  553. "CAPS LOCK", nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, "ESC", nullptr, nullptr, nullptr, nullptr, "SPACEBAR",
  554. "PG UP", "PG DOWN", "END", "HOME", "Left", "Up", "Right", "Down", nullptr, "Print", nullptr, "Print Screen", "Insert",
  555. "Delete", nullptr, "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
  556. nullptr, "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X",
  557. "Y", "Z", "Left Windows", "Right Windows", nullptr, nullptr, nullptr, "0", "1", "2", "3", "4", "5", "6",
  558. "7", "8", "9", "*", "+", "_", "-", ".", "/", "F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8", "F9", "F10", "F11", "F12",
  559. "F13", "F14", "F15", "F16", "F17", "F18", "F19", "F20", "F21", "F22", "F23", "F24", nullptr, nullptr, nullptr, nullptr, nullptr,
  560. nullptr, nullptr, nullptr, "NUM LOCK", "SCROLL LOCK", nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
  561. nullptr, nullptr, nullptr, nullptr, nullptr, "LSHIFT", "RSHIFT", "LCONTROL", "RCONTROL", "LMENU", "RMENU", nullptr, nullptr, nullptr,
  562. nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, "Next Track", "Previous Track", "Stop", "Play/Pause", nullptr, nullptr,
  563. nullptr, nullptr, nullptr, nullptr, ";", "+", ",", "-", ".", "/?", "~", nullptr, nullptr, nullptr, nullptr,
  564. nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
  565. nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, "[{", "\\|", "}]", "'\"", nullptr, nullptr, nullptr, nullptr,
  566. nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
  567. nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr };
  568.  
  569.  
  570. CTextField::CTextField()
  571. {
  572. m_Flags = UIFlags::UI_Drawable | UIFlags::UI_Clickable | UIFlags::UI_SaveFile;
  573. FileControlType = UIControlTypes::UIC_KeyBind;
  574. }
  575.  
  576. std::string CTextField::getText()
  577. {
  578. return text;
  579. }
  580.  
  581. void CTextField::SetText(std::string stext)
  582. {
  583. text = stext;
  584. }
  585.  
  586. void CTextField::Draw(bool hover)
  587. {
  588. POINT a = GetAbsolutePos();
  589.  
  590. Render::Outline(a.x, a.y, m_iWidth, m_iHeight, Color(255, 255, 255, 255));
  591. if (hover || IsGettingKey)
  592. Render::Clear(a.x + 2, a.y + 2, m_iWidth - 4, m_iHeight - 4, Color(255, 255, 255, 255));
  593.  
  594. const char *cstr = text.c_str();
  595.  
  596. Render::Text(a.x + 2, a.y + 2, Color(255, 255, 255, 255), Render::Fonts::Menu, cstr);
  597. }
  598.  
  599. void CTextField::OnUpdate()
  600. {
  601. m_iHeight = 16;
  602. POINT a = GetAbsolutePos();
  603. POINT b;
  604. const char *strg = text.c_str();
  605.  
  606. if (IsGettingKey)
  607. {
  608. b = GetAbsolutePos();
  609. for (int i = 0; i < 255; i++)
  610. {
  611. if (GUI.GetKeyPress(i))
  612. {
  613. if (i == VK_ESCAPE || i == VK_RETURN || i == VK_INSERT)
  614. {
  615. IsGettingKey = false;
  616. return;
  617. }
  618.  
  619. if (i == VK_BACK && strlen(strg) != 0)
  620. {
  621. text = text.substr(0, strlen(strg) - 1);
  622. }
  623.  
  624. if (strlen(strg) < 6 && (i == 0x30 || i == 0x31 || i == 0x32 || i == 0x33 || i == 0x34 || i == 0x35 || i == 0x36 || i == 0x37 || i == 0x38 || i == 0x39 || i == VK_NUMPAD0 || i == VK_NUMPAD1 || i == VK_NUMPAD2 || i == VK_NUMPAD3 || i == VK_NUMPAD4 || i == VK_NUMPAD5 || i == VK_NUMPAD6 || i == VK_NUMPAD7 || i == VK_NUMPAD8 || i == VK_NUMPAD9))
  625. {
  626. text = text + KeyDigits[i];
  627. return;
  628. }
  629. }
  630. }
  631. }
  632. }
  633.  
  634. void CTextField::OnClick()
  635. {
  636. POINT a = GetAbsolutePos();
  637. if (!IsGettingKey)
  638. {
  639. IsGettingKey = true;
  640. }
  641. }
  642.  
  643. #pragma endregion Implementation of the Textfield
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement