LineInput.hxx 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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_visible(bool visible);
  22. [[nodiscard]] bool is_visible() const;
  23. void set_value(std::string value);
  24. [[nodiscard]]char const* value() const;
  25. private:
  26. std::string value_;
  27. int x_, y_, w_, h_;
  28. bool focus_;
  29. bool visible_;
  30. Asset<SDL_Texture*> texture_;
  31. Asset<TTF_Font*> font_;
  32. std::chrono::milliseconds blink_timer_{0};
  33. };
  34. #endif // SNAKE_LINEINPUT_HXX