LineInput.hxx 900 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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 update(std::chrono::milliseconds delta_time);
  13. void render(SDLRenderer& renderer);
  14. void move(int x, int y);
  15. void resize(int w, int h);
  16. [[nodiscard]] SDL_Rect get_bounding_box() const;
  17. // this does not remove the focus from other inputs!
  18. void set_focus(bool focus);
  19. [[nodiscard]] bool has_focus() const;
  20. private:
  21. std::string value_;
  22. int x_, y_, w_, h_;
  23. bool focus_;
  24. Asset<SDL_Texture*> texture_;
  25. Asset<TTF_Font*> font_;
  26. std::chrono::milliseconds blink_timer_{0};
  27. };
  28. #endif // SNAKE_LINEINPUT_HXX