button.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #ifndef IC_EXPLORER_BUTTON_H
  2. #define IC_EXPLORER_BUTTON_H
  3. #include "window.h"
  4. #include <SDL_mixer.h>
  5. #include <SDL_ttf.h>
  6. #define BUTTON_PADDING 0.005f
  7. typedef struct {
  8. Mix_Chunk *down;
  9. Mix_Chunk *up;
  10. Mix_Chunk *hover;
  11. } ButtonSoundSet;
  12. struct Button;
  13. typedef void (*ButtonAction)(struct Button *button, Window *window, float x,
  14. float y);
  15. typedef struct Button {
  16. float x;
  17. float y;
  18. float w;
  19. float h;
  20. char *text;
  21. SDL_Texture *current;
  22. SDL_Texture *inactive;
  23. SDL_Texture *active;
  24. SDL_Color textColor;
  25. TTF_Font *font;
  26. SDL_Texture *renderedText;
  27. ButtonSoundSet sounds;
  28. int textW;
  29. int textH;
  30. ButtonAction action;
  31. int down;
  32. } Button;
  33. Button *buttonNew(const char *text, float x, float y, float w, float h,
  34. SDL_Texture *inactive, SDL_Texture *active,
  35. SDL_Color textColor, TTF_Font *font, ButtonSoundSet sounds,
  36. const Window *window);
  37. void buttonDelete(Button *button);
  38. void buttonDraw(const Button *button, const Window *window);
  39. void buttonUpdate(Button *button, const Window *window);
  40. void buttonProcessInput(Button *button, Window *window, const SDL_Event *event);
  41. void buttonGetCenter(const Button *button, Point *point);
  42. #endif /* IC_EXPLORER_BUTTON_H */