BaseGUI.h 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #ifndef BASE_GUI_H
  2. #define BASE_GUI_H
  3. #include "math/Vector.h"
  4. #include "utils/List.h"
  5. #include "utils/Size.h"
  6. struct BaseGUI final {
  7. static const Vector2 FIXED_SIZE;
  8. float scale;
  9. Vector2 scaledSize;
  10. struct Base {
  11. Vector2 pos;
  12. Vector2 size;
  13. bool hovered;
  14. bool pressed;
  15. Base();
  16. };
  17. struct Label {
  18. Base base;
  19. StringBuffer<50> text;
  20. };
  21. List<Label> labels;
  22. struct Input {
  23. Base base;
  24. StringBuffer<50> text;
  25. };
  26. List<Input> inputs;
  27. int activeInput = -1;
  28. struct Button {
  29. Base base;
  30. StringBuffer<20> text;
  31. };
  32. List<Button> buttons;
  33. void tick();
  34. void updateScale();
  35. void render();
  36. Vector2 round(const Vector2& v) const;
  37. void renderString(const Vector2& pos, const char* s);
  38. Label& addLabel(const char* text);
  39. Input& addInput();
  40. Button& addButton(const char* text);
  41. bool isIn(const Vector2& pos, const Vector2& size,
  42. const Vector2& point) const;
  43. private:
  44. void tickBase(Base& b);
  45. Vector2 renderCenteredString(const Base& b, const char* text);
  46. void renderBase(const Base& b);
  47. void renderLabels();
  48. void renderInputs();
  49. void renderButtons();
  50. };
  51. #endif