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