chainreaction/board_widget.hpp

63 lines
2.2 KiB
C++

#ifndef SDL_UI_HPP
#define SDL_UI_HPP
#include <SDL2/SDL_rect.h>
#include <SDL2/SDL_stdinc.h>
#include <basic_widgets/w/feat/mouse_handler.hpp>
#include <basic_widgets/w/feat/texture_handler.hpp>
#include <basic_widgets/w/base/widget.hpp>
extern "C" { Uint32 SDL_RegisterEvents(int); }
namespace game::data
{
struct Board;
}
namespace game::ui
{
class BoardWidget : public bwidgets::widget::Widget,
public bwidgets::widget::MouseHandler,
public bwidgets::widget::TextureHandler
{
protected:
static const
int _border_ratio {30};
SDL_Rect _border_area;
bwidgets::core::Texture* _circle_blue {nullptr};
bwidgets::core::Texture* _circle_red {nullptr};
virtual void _draw_atoms(const SDL_Rect&, int, bwidgets::core::Texture*);
virtual void _handle_focus_change(bool) override {}
virtual void _handle_geometry_change(const SDL_Rect&) noexcept override;
virtual void _handle_renderer_change(bwidgets::core::Renderer*) override;
virtual void _handle_rendering() override;
virtual void _handle_texture_update() override;
virtual void _render_empty_board();
virtual void _render_square_content();
public:
enum struct event_code : Sint32 {
PLAY
};
const Uint32 event_type {SDL_RegisterEvents(1)};
const data::Board* board {nullptr};
SDL_Color color_bg {50, 50, 50, SDL_ALPHA_OPAQUE};
SDL_Color color_hl1 {255, 0, 0, SDL_ALPHA_OPAQUE/16};
SDL_Color color_hl2 {255, 255, 0, SDL_ALPHA_OPAQUE/16};
SDL_Color color_outline {175, 175, 175, SDL_ALPHA_OPAQUE};
SDL_Color color_p1 {255, 0, 0, SDL_ALPHA_OPAQUE};
SDL_Color color_p2 {0, 0, 255, SDL_ALPHA_OPAQUE};
BoardWidget(Widget* parent=nullptr);
virtual ~BoardWidget();
SDL_Point board_coord_from_input(const SDL_Point&) const;
};
}
#endif