Add a helper scene_base & inherit app from it
This commit is contained in:
parent
e42c5dc054
commit
517f964ce7
2 changed files with 38 additions and 2 deletions
|
|
@ -10,7 +10,7 @@ namespace psemek::app
|
||||||
{
|
{
|
||||||
|
|
||||||
struct app
|
struct app
|
||||||
: scene
|
: scene_base
|
||||||
{
|
{
|
||||||
app(std::string const & name);
|
app(std::string const & name);
|
||||||
app(std::string const & name, int multisampling);
|
app(std::string const & name, int multisampling);
|
||||||
|
|
@ -18,9 +18,9 @@ namespace psemek::app
|
||||||
|
|
||||||
virtual bool running() const;
|
virtual bool running() const;
|
||||||
virtual void stop();
|
virtual void stop();
|
||||||
|
virtual void on_quit();
|
||||||
|
|
||||||
void on_resize(int width, int height) override;
|
void on_resize(int width, int height) override;
|
||||||
virtual void on_quit();
|
|
||||||
|
|
||||||
void render() override;
|
void render() override;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,12 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <psemek/geom/point.hpp>
|
||||||
|
|
||||||
#include <SDL2/SDL_keycode.h>
|
#include <SDL2/SDL_keycode.h>
|
||||||
|
|
||||||
|
#include <optional>
|
||||||
|
#include <set>
|
||||||
|
|
||||||
namespace psemek::app
|
namespace psemek::app
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
@ -34,4 +39,35 @@ namespace psemek::app
|
||||||
|
|
||||||
inline scene::~scene() = default;
|
inline scene::~scene() = default;
|
||||||
|
|
||||||
|
struct scene_base
|
||||||
|
: scene
|
||||||
|
{
|
||||||
|
void on_mouse_move(int x, int y, int, int) override { mouse_ = geom::point{x, y}; }
|
||||||
|
void on_left_button_down() override { left_button_down_ = true; }
|
||||||
|
void on_left_button_up() override { left_button_down_ = false; }
|
||||||
|
void on_middle_button_down() override { middle_button_down_ = true; }
|
||||||
|
void on_middle_button_up() override { middle_button_down_ = false; }
|
||||||
|
void on_right_button_down() override { right_button_down_ = true; }
|
||||||
|
void on_right_button_up() override { right_button_down_ = false; }
|
||||||
|
void on_key_down(SDL_Keycode key) override { keys_.insert(key); }
|
||||||
|
void on_key_up(SDL_Keycode key) override { keys_.erase(key); }
|
||||||
|
|
||||||
|
bool is_left_button_down() const { return left_button_down_; }
|
||||||
|
bool is_middle_button_down() const { return middle_button_down_; }
|
||||||
|
bool is_right_button_down() const { return right_button_down_; }
|
||||||
|
|
||||||
|
std::optional<geom::point<int, 2>> mouse() const { return mouse_; }
|
||||||
|
|
||||||
|
bool is_key_down(SDL_Keycode key) const { return keys_.count(key) > 0; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool left_button_down_ = false;
|
||||||
|
bool middle_button_down_ = false;
|
||||||
|
bool right_button_down_ = false;
|
||||||
|
|
||||||
|
std::optional<geom::point<int, 2>> mouse_;
|
||||||
|
|
||||||
|
std::set<SDL_Keycode> keys_;
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue