Button.hxx 819 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #pragma once
  2. #ifndef SNAKE_BUTTON_HXX
  3. #define SNAKE_BUTTON_HXX
  4. #include <SDL.h>
  5. #include <SDL_ttf.h>
  6. #include <functional>
  7. #include <string>
  8. #include "../AssetManager.hxx"
  9. class SDLRenderer;
  10. class Button final {
  11. public:
  12. Button(std::string title, int x, int y, int w, int h);
  13. void set_pressed(bool pressed);
  14. [[nodiscard]] bool is_pressed() const;
  15. void update();
  16. void render(SDLRenderer& renderer);
  17. void trigger();
  18. void set_on_click(std::function<void()> handler);
  19. void move(int x, int y);
  20. void resize(int w, int h);
  21. [[nodiscard]] SDL_Rect get_bounding_box() const;
  22. private:
  23. std::string title_;
  24. int x_, y_, w_, h_;
  25. bool pressed_;
  26. std::function<void()> on_click_;
  27. Asset<SDL_Texture*> up_;
  28. Asset<SDL_Texture*> down_;
  29. Asset<TTF_Font*> font_;
  30. };
  31. #endif // SNAKE_BUTTON_HXX