LineInput.hxx 1021 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #pragma once
  2. #ifndef SNAKE_LINEINPUT_HXX
  3. #define SNAKE_LINEINPUT_HXX
  4. #include <chrono>
  5. #include <boost/noncopyable.hpp>
  6. #include "../AssetManager.hxx"
  7. class LineInput final : private boost::noncopyable {
  8. public:
  9. static int constexpr MIN_WIDTH = 16;
  10. static int constexpr MIN_HEIGHT = 15;
  11. LineInput(int x, int y, int w, int h, std::string value = "");
  12. void on_event(SDL_Event const& evt);
  13. void update(std::chrono::milliseconds delta_time);
  14. void render(SDLRenderer& renderer);
  15. void move(int x, int y);
  16. void resize(int w, int h);
  17. [[nodiscard]] SDL_Rect get_bounding_box() const;
  18. // this does not remove the focus from other inputs!
  19. void set_focus(bool focus);
  20. [[nodiscard]] bool has_focus() const;
  21. void set_value(std::string value);
  22. [[nodiscard]]char const* value() const;
  23. private:
  24. std::string value_;
  25. int x_, y_, w_, h_;
  26. bool focus_;
  27. Asset<SDL_Texture*> texture_;
  28. Asset<TTF_Font*> font_;
  29. std::chrono::milliseconds blink_timer_{0};
  30. };
  31. #endif // SNAKE_LINEINPUT_HXX