Guest User

Untitled

a guest
Mar 15th, 2021
1,482
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.67 KB | None | 0 0
  1. enum AnimationTypes { STATIC, DYNAMIC, INTERP };
  2.  
  3. std::string pChar(std::string first_, std::string second_) {
  4. return (std::stringstream{} << first_ << second_).str();
  5. }
  6.  
  7. float Animate(const char* label, const char* second_label, bool if_, float Maximal_, float Speed_, int type) {
  8.  
  9. auto ID = ImGui::GetID(pChar(label, second_label).c_str());
  10.  
  11. static std::map<ImGuiID, float> pValue;
  12.  
  13. auto this_e = pValue.find(ID);
  14.  
  15. if (this_e == pValue.end()) {
  16. pValue.insert({ ID, 0.f });
  17. this_e = pValue.find(ID);
  18. }
  19.  
  20. switch (type) {
  21.  
  22. case DYNAMIC: {
  23. if (if_) //do
  24. this_e->second += abs(Maximal_ - this_e->second) / Speed_;
  25. else
  26. this_e->second -= (0 + this_e->second) / Speed_;
  27. }
  28. break;
  29.  
  30. case INTERP: {
  31. this_e->second += (Maximal_ - this_e->second) / Speed_;
  32. }
  33. break;
  34.  
  35. case STATIC: {
  36. if (if_) //do
  37. this_e->second += Speed_;
  38. else
  39. this_e->second -= Speed_;
  40. }
  41. break;
  42. }
  43.  
  44. if (type != INTERP) {
  45. if (this_e->second < 0.f)
  46. this_e->second = 0.f;
  47. else if (this_e->second > Maximal_)
  48. this_e->second = Maximal_;
  49. }
  50.  
  51. return this_e->second;
  52.  
  53. }
  54.  
  55. void DrawShapeAnimated(const char* label, ImVec2 min, ImVec2 max, ImVec2 pos, ImColor color) {
  56.  
  57. int hovered_delta = Animate(label, "hovered_rect", ImGui::IsMouseHoveringRect(min, max, false), 255.f, 15.f, STATIC);
  58.  
  59. ImGui::SetCursorPos(pos - ImGui::GetWindowPos());
  60.  
  61. auto clicked = ImGui::GetIO().MouseClicked[0] && ImGui::IsMouseHoveringRect(min, max, false);
  62. auto ID = ImGui::GetID(pChar(label, "b_animation").c_str());
  63.  
  64. static std::map<ImGuiID, bool> pValue;
  65. auto ItPLibrary = pValue.find(ID);
  66. if (ItPLibrary == pValue.end()) {
  67. pValue.insert({ ID, false });
  68. ItPLibrary = pValue.find(ID);
  69. }
  70.  
  71. float radius = Animate(label, "circle_radius", ItPLibrary->second, 100.f, 10.f, DYNAMIC);
  72.  
  73. static std::map<ImGuiID, int> pValue2;
  74.  
  75. static POINT MousePoint;
  76. GetCursorPos(&MousePoint);
  77.  
  78. static std::map<ImGuiID, ImVec2> CirclePosMap;
  79. auto CirclePos = CirclePosMap.find(ID);
  80. if (CirclePos == CirclePosMap.end()) {
  81. CirclePosMap.insert({ ID, ImVec2(MousePoint.x, MousePoint.y) });
  82. CirclePos = CirclePosMap.find(ID);
  83. }
  84.  
  85. if (clicked) {
  86. CirclePos->second = ImVec2(MousePoint.x, MousePoint.y);
  87. ItPLibrary->second = true;
  88. }
  89.  
  90. if (ItPLibrary->second) {
  91.  
  92. if (radius >= 95.f) {
  93. ItPLibrary->second = false;
  94. radius = 0.f;
  95. }
  96. }
  97. ImRect bb = ImRect(min, max);
  98. auto size = bb.GetSize();
  99. //calc circle start radius and scale radius
  100. float StartRad = sqrt((size.x + size.y) / 2);
  101. //scale :::
  102. float ScaleRad = ((StartRad + radius) + (sqrt(size.x * size.y) / ((size.x - size.y) / StartRad))) * 0.5;
  103.  
  104. ImGui::BeginChild(pChar("drawlist_zone", label).c_str(), size, false); {
  105. if (ItPLibrary->second)
  106. ImGui::GetWindowDrawList()->AddCircleFilled(CirclePos->second, StartRad + ScaleRad, ImColor(int(255.f * color.Value.x), int(255.f * color.Value.y), int(255.f * color.Value.z), 95 - (int)(radius)), (StartRad + ScaleRad) * 15.f);
  107. }
  108. ImGui::EndChild();
  109. }
  110.  
  111. void create_window(const char* name, std::vector <std::string> vec ) {
  112.  
  113. ImGui::SetNextWindowSize(ImVec2(170, 30));
  114. //draw
  115.  
  116. //flags -
  117. static const WORD dw_window_flags{
  118. ImGuiWindowFlags_NoBackground
  119. | ImGuiWindowFlags_NoTitleBar
  120. | ImGuiWindowFlags_NoCollapse
  121. | ImGuiWindowFlags_NoResize
  122. | ImGuiWindowFlags_NoScrollbar
  123. | ImGuiWindowFlags_NoScrollWithMouse
  124. };
  125.  
  126. if (ImGui::Begin(name, nullptr, dw_window_flags))
  127. {
  128. //get vars :::
  129. ImColor theme = ImColor(45, 130, 242, 255);
  130. ImColor theme_zero = ImColor(45, 130, 242, 0);
  131. ImColor black = ImColor(0, 0, 0, 210);
  132. ImColor black_zero = ImColor(0, 0, 0, 0);
  133. ImColor black_half = ImColor(0, 0, 0, 60);
  134.  
  135. const auto draw = ImGui::GetBackgroundDrawList();
  136. const auto p = ImGui::GetWindowPos();
  137. const auto s = ImGui::GetWindowSize();
  138.  
  139. //background
  140. draw->AddRectFilledMultiColor(p + ImVec2(10, 0), p + ImVec2(s.x / 2, s.y), black_half, black_half, black_half, black_half);
  141. draw->AddRectFilledMultiColor(p + ImVec2(s.x / 2, 0), p + ImVec2(s.x, s.y) - ImVec2(10, 0), black_half, black_half, black_half, black_half);
  142.  
  143. //up
  144. draw->AddRectFilledMultiColor(p + ImVec2(10, 0), p + ImVec2(s.x / 2, 2), theme_zero, theme, theme, theme_zero);
  145. draw->AddRectFilledMultiColor(p + ImVec2(s.x / 2, 0), p + ImVec2(s.x, 2) - ImVec2(10, 0), theme, theme_zero, theme_zero, theme);
  146.  
  147. auto spec_sz = ImGui::CalcTextSize(name);
  148. draw->AddText(p + ImVec2(s.x / 2 - spec_sz.x / 2, s.y / 2 - spec_sz.y / 2), ImColor(255, 255, 255), name);
  149.  
  150. ImVec2 shape_pos = p + ImVec2(10, 0);
  151. ImVec2 shape_sz = s - ImVec2(20, -2);
  152.  
  153. DrawShapeAnimated(name, shape_pos, shape_pos + shape_sz, shape_pos, theme);
  154.  
  155. for (auto i = 0; i < vec.size(); i++) {
  156. int alpha_of_this = Animate("Spectators", vec[i].c_str(), true, 255, 15, STATIC);
  157. auto first_circle_pos = ImVec2(p.x + 20, p.y + s.y + 15 + 25 * i);
  158. draw->AddCircleFilled(first_circle_pos, 2.3f, ImColor(45, 130, 242, alpha_of_this), 5.f * 15.f);
  159. draw->AddCircleFilled(first_circle_pos, 2.f, ImColor(45, 130, 242, alpha_of_this), 5.f * 15.f);
  160. draw->AddText(first_circle_pos + ImVec2(10, -9), ImColor(255, 255, 255, alpha_of_this), vec[i].c_str());
  161. }
  162.  
  163. draw->AddRectFilled(p + ImVec2(10, s.y), p + ImVec2(s.x - 10, 4 + s.y + 25 * vec.size()), ImColor(0, 0, 0, 100), 0, 15);
  164. }
  165. ImGui::End();
  166.  
  167.  
  168. }
  169. void init() {
  170.  
  171. static std::vector <std::string> binds {"Rapidfire", "Hideshots", "Force-body"};
  172. create_window("Keys state", binds);
  173.  
  174. static std::vector <std::string> spec {"Bot Maxim"};
  175. create_window("Spectators", spec);
  176.  
  177.  
  178. }
Advertisement
Add Comment
Please, Sign In to add comment