Advertisement
Guest User

Untitled

a guest
Feb 19th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.23 KB | None | 0 0
  1. bool ImGui::Checkbox(const char* label, bool* v)
  2. {
  3. ImGuiWindow* window = GetCurrentWindow();
  4. if (window->SkipItems)
  5. return false;
  6. ImGuiContext& g = *GImGui;
  7. const ImGuiStyle& style = ImGuiStyle::ImGuiStyle();
  8. const ImGuiID id = window->GetID(label);
  9. const ImVec2 label_size = CalcTextSize(label, NULL, true);
  10. const ImVec2 pading = ImVec2(2, 2);
  11. 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));
  12. ItemSize(check_bb, style.FramePadding.y);
  13. ImRect total_bb = check_bb;
  14. if (label_size.x > 0)
  15. SameLine(0, style.ItemInnerSpacing.x);
  16. const ImRect text_bb(window->DC.CursorPos + ImVec2(0, style.FramePadding.y), window->DC.CursorPos + ImVec2(0, style.FramePadding.y) + label_size);
  17. if (label_size.x > 0)
  18. {
  19. ItemSize(ImVec2(text_bb.GetWidth(), check_bb.GetHeight()), style.FramePadding.y);
  20. total_bb = ImRect(ImMin(check_bb.Min, text_bb.Min), ImMax(check_bb.Max, text_bb.Max));
  21. }
  22. if (!ItemAdd(total_bb, &id))
  23. return false;
  24. bool hovered, held;
  25. bool pressed = ButtonBehavior(total_bb, id, &hovered, &held);
  26. if (pressed)
  27. *v = !(*v);
  28. const float check_sz = ImMin(check_bb.GetWidth(), check_bb.GetHeight());
  29. const float check_sz2 = check_sz / 2;
  30. const float pad = ImMax(1.0f, (float)(int)(check_sz / 4.f));
  31. if (*v)//отрисовка галочки
  32. {
  33. /*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)));
  34. 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)));
  35. 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)));*/
  36.  
  37.  
  38. 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)));
  39. 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)));
  40. 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)));;
  41. }
  42. else
  43. {
  44. 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)));
  45. 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)));
  46. 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)));
  47. }
  48. if (label_size.x > 0.0f)
  49. RenderText(text_bb.GetTL(), label);
  50. return pressed;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement