box.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. #include <stdint.h>
  2. #include <stdbool.h>
  3. #include "gfx/box.h"
  4. #include "gfx/shape.h"
  5. #include "gfx/text.h"
  6. #include "gfx/SDL_easy.h"
  7. box_t *create_box(int x, int y, int w, int h, _Bool is_on, const char *title)
  8. {
  9. box_t *box = malloc(sizeof(box_t));
  10. box->rect.x = x; box->rect.y = y; box->rect.w = w; box->rect.h = h;
  11. box->is_on = is_on;
  12. box->on_text = create_text(&FONT_TEXT[QFontSize_20], 1150, box->rect.y + 30, Colour_Nintendo_Cyan, "On");
  13. box->off_text = create_text(&FONT_TEXT[QFontSize_20], 1150, box->rect.y + 30, Colour_Nintendo_Grey, "Off");
  14. box->title = create_text(&FONT_TEXT[QFontSize_20], box->rect.x + 15, box->rect.y + 25, Colour_Nintendo_White, title);
  15. box->spacer_top = create_shape(Colour_Nintendo_Silver, box->rect.x, box->rect.y, box->rect.w, box->rect.h, true);
  16. box->spacer_bottom = create_shape(Colour_Nintendo_Silver, box->rect.x, box->rect.y + 75, box->rect.w, box->rect.h, true);
  17. return box;
  18. }
  19. void draw_box(box_t *box)
  20. {
  21. draw_shape(&box->spacer_top);
  22. draw_text(box->title);
  23. draw_text(box->is_on == true ? box->on_text : box->off_text);
  24. draw_shape(&box->spacer_bottom);
  25. }
  26. void free_box(box_t *box)
  27. {
  28. free_text(box->title);
  29. free_text(box->on_text);
  30. free_text(box->off_text);
  31. free(box);
  32. }