Button.hxx 720 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  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 <future>
  8. #include <string>
  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. 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. private:
  20. std::string title_;
  21. int x_, y_, w_, h_;
  22. bool pressed_;
  23. std::function<void()> on_click_;
  24. std::shared_future<SDL_Texture*> up_;
  25. std::shared_future<SDL_Texture*> down_;
  26. std::shared_future<TTF_Font*> font_;
  27. };
  28. #endif // SNAKE_BUTTON_HXX