playground-sdk/platform/display.h

38 lines
895 B
C++

#pragma once
#include <SDL3/SDL.h>
#include <string>
namespace playground {
struct Event {
enum class Type { Quit, MouseMove, MouseDown, MouseUp, KeyDown, KeyUp, TextInput } type;
float x = 0;
float y = 0;
Uint8 button = 0;
SDL_Keycode key = SDLK_UNKNOWN;
std::string text;
};
class Display {
public:
Display() = default;
~Display();
Display(const Display&) = delete;
Display& operator=(const Display&) = delete;
bool open(const char* title, int width = 800, int height = 600,
std::string* error = nullptr);
bool poll(Event& out);
void beginFrame();
void endFrame();
SDL_Renderer* renderer() const { return renderer_; }
SDL_Window* window() const { return window_; }
private:
SDL_Window* window_ = nullptr;
SDL_Renderer* renderer_ = nullptr;
bool videoReady_ = false;
};
} // namespace playground