Advertisement
Guest User

Untitled

a guest
May 20th, 2018
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.76 KB | None | 0 0
  1. // чекбокс первый
  2.  
  3. bool ImGui::Checkbox(const char* label, bool* v)
  4. {
  5. ImGuiWindow* window = GetCurrentWindow();
  6. if (window->SkipItems)
  7. return false;
  8. ImGuiContext& g = *GImGui;
  9. const ImGuiStyle& style = ImGuiStyle::ImGuiStyle();
  10. const ImGuiID id = window->GetID(label);
  11. const ImVec2 label_size = CalcTextSize(label, NULL, true);
  12. const ImVec2 pading = ImVec2(2, 2);
  13. const ImRect check_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(label_size.y + style.FramePadding.x * 6, label_size.y + style.FramePadding.y / 2));
  14. ItemSize(check_bb, style.FramePadding.y);
  15. ImRect total_bb = check_bb;
  16. if (label_size.x > 0)
  17. SameLine(0, style.ItemInnerSpacing.x);
  18. const ImRect text_bb(window->DC.CursorPos + ImVec2(0, style.FramePadding.y), window->DC.CursorPos + ImVec2(0, style.FramePadding.y) + label_size);
  19. if (label_size.x > 0)
  20. {
  21. ItemSize(ImVec2(text_bb.GetWidth(), check_bb.GetHeight()), style.FramePadding.y);
  22. total_bb = ImRect(ImMin(check_bb.Min, text_bb.Min), ImMax(check_bb.Max, text_bb.Max));
  23. }
  24. if (!ItemAdd(total_bb, &id))
  25. return false;
  26. bool hovered, held;
  27. bool pressed = ButtonBehavior(total_bb, id, &hovered, &held);
  28. if (pressed)
  29. *v = !(*v);
  30. const float check_sz = ImMin(check_bb.GetWidth(), check_bb.GetHeight());
  31. const float check_sz2 = check_sz / 2;
  32. const float pad = ImMax(1.0f, (float)(int)(check_sz / 4.f));
  33. if (*v)//от исовка галочки
  34. {
  35. window->DrawList->AddRectFilled(ImVec2(check_bb.Min.x, check_bb.Min.y), ImVec2(check_bb.Min.x + 40, check_bb.Min.y + 20), GetColorU32(ImVec4(0.40f, 0.40f, 0.40f, 1.00f)));
  36. window->DrawList->AddRectFilled(ImVec2(check_bb.Min.x + 2, check_bb.Min.y + 2), ImVec2(check_bb.Min.x + 38, check_bb.Min.y + 18), GetColorU32(ImVec4(0, 0, 0, 1.00f)));
  37. window->DrawList->AddRectFilled(ImVec2(check_bb.Max.x - 3, check_bb.Max.y - 1), ImVec2(check_bb.Max.x - 21, check_bb.Max.y - 15), GetColorU32(ImVec4(0.0f, 0.5f, 0.0f, 1.0f)));
  38. }
  39. else
  40. {
  41. window->DrawList->AddRectFilled(ImVec2(check_bb.Min.x, check_bb.Min.y), ImVec2(check_bb.Min.x + 40, check_bb.Min.y + 20), GetColorU32(ImVec4(0.20f, 0.20f, 0.20f, 1.00f)));
  42. window->DrawList->AddRectFilled(ImVec2(check_bb.Min.x + 2, check_bb.Min.y + 2), ImVec2(check_bb.Min.x + 38, check_bb.Min.y + 18), GetColorU32(ImVec4(0, 0, 0, 1.00f)));
  43. window->DrawList->AddRectFilled(ImVec2(check_bb.Min.x + 3, check_bb.Min.y + 3), ImVec2(check_bb.Min.x + 21, check_bb.Min.y + 17), GetColorU32(ImVec4(0.20f, 0.20f, 0.20f, 1.00f)));
  44. }
  45. if (label_size.x > 0.0f)
  46. RenderText(text_bb.GetTL(), label);
  47. return pressed;
  48. }
  49.  
  50. // чекбокс для индиго
  51.  
  52.  
  53. bool ImGui::Checkbox(const char* label, bool* v)
  54. {
  55.     ImGuiWindow* window = GetCurrentWindow();
  56.     if (window->SkipItems)
  57.         return false;
  58.     ImGuiContext& g = *GImGui;
  59.     const ImGuiStyle& style = ImGuiStyle::ImGuiStyle();
  60.     const ImGuiID id = window->GetID(label);
  61.     const ImVec2 label_size = CalcTextSize(label, NULL, true);
  62.     const ImVec2 pading = ImVec2(2, 2);
  63.     const ImRect check_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(label_size.y + style.FramePadding.x * 6, label_size.y + style.FramePadding.y / 2));
  64.     ItemSize(check_bb, style.FramePadding.y);
  65.     ImRect total_bb = check_bb;
  66.     if (label_size.x > 0)
  67.         SameLine(0, style.ItemInnerSpacing.x);
  68.     const ImRect text_bb(window->DC.CursorPos + ImVec2(0, style.FramePadding.y), window->DC.CursorPos + ImVec2(0, style.FramePadding.y) + label_size);
  69.     if (label_size.x > 0)
  70.     {
  71.         ItemSize(ImVec2(text_bb.GetWidth(), check_bb.GetHeight()), style.FramePadding.y);
  72.         total_bb = ImRect(ImMin(check_bb.Min, text_bb.Min), ImMax(check_bb.Max, text_bb.Max));
  73.     }
  74.     if (!ItemAdd(total_bb, &id))
  75.         return false;
  76.     bool hovered, held;
  77.     bool pressed = ButtonBehavior(total_bb, id, &hovered, &held);
  78.     if (pressed)
  79.         *v = !(*v);
  80.     const float check_sz = ImMin(check_bb.GetWidth(), check_bb.GetHeight());
  81.     const float check_sz2 = check_sz / 2;
  82.     const float pad = ImMax(1.0f, (float)(int)(check_sz / 4.f));
  83.     if (*v)//отрисовка галочки
  84.     {
  85.         /*window->DrawList->AddRectFilled(ImVec2(check_bb.Min.x, check_bb.Min.y), ImVec2(check_bb.Min.x + 40, check_bb.Min.y + 20), GetColorU32(ImVec4(0.40f, 0.40f, 0.40f, 1.00f)));
  86.         window->DrawList->AddRectFilled(ImVec2(check_bb.Min.x + 2, check_bb.Min.y + 2), ImVec2(check_bb.Min.x + 38, check_bb.Min.y + 18), GetColorU32(ImVec4(0, 0, 0, 1.00f)));
  87.         window->DrawList->AddRectFilled(ImVec2(check_bb.Max.x - 3, check_bb.Max.y - 1), ImVec2(check_bb.Max.x - 21, check_bb.Max.y - 15), GetColorU32(ImVec4(0.0f, 0.5f, 0.0f, 1.0f)));*/
  88.  
  89.  
  90.         window->DrawList->AddRectFilled(ImVec2(check_bb.Min.x, check_bb.Min.y),         ImVec2(check_bb.Min.x + 40, check_bb.Min.y + 20), GetColorU32(ImVec4(0.40f, 0.40f, 0.40f, 1.00f)));
  91.         window->DrawList->AddRectFilled(ImVec2(check_bb.Min.x + 2, check_bb.Min.y + 2), ImVec2(check_bb.Min.x + 38, check_bb.Min.y + 18), GetColorU32(ImVec4(0, 0, 0, 1.00f)));
  92.         window->DrawList->AddRectFilled(ImVec2(check_bb.Max.x - 1, check_bb.Max.y + 2), ImVec2(check_bb.Max.x - 19, check_bb.Max.y - 12), GetColorU32(ImVec4(0.0f, 0.5f, 0.0f, 1.0f)));;
  93.     }
  94.     else
  95.     {
  96.         window->DrawList->AddRectFilled(ImVec2(check_bb.Min.x, check_bb.Min.y),         ImVec2(check_bb.Min.x + 40, check_bb.Min.y + 20), GetColorU32(ImVec4(0.20f, 0.20f, 0.20f, 1.00f)));
  97.         window->DrawList->AddRectFilled(ImVec2(check_bb.Min.x + 2, check_bb.Min.y + 2), ImVec2(check_bb.Min.x + 38, check_bb.Min.y + 18), GetColorU32(ImVec4(0, 0, 0, 1.00f)));
  98.         window->DrawList->AddRectFilled(ImVec2(check_bb.Min.x + 3, check_bb.Min.y + 3), ImVec2(check_bb.Min.x + 21, check_bb.Min.y + 17), GetColorU32(ImVec4(0.20f, 0.20f, 0.20f, 1.00f)));
  99.     }
  100.     if (label_size.x > 0.0f)
  101.         RenderText(text_bb.GetTL(), label);
  102.     return pressed;
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement