libultraship
Reimplementations of libultra (N64 SDK) functions for modern hardware
Loading...
Searching...
No Matches
gfx_sdl.h
Go to the documentation of this file.
1#pragma once
2
3#include <memory>
5
6namespace Ship {
7class ConsoleVariable;
8class Config;
9class FileDrop;
10} // namespace Ship
11
12namespace Fast {
13class Fast3dGui;
14
22 public:
24 GfxWindowBackendSDL2(std::shared_ptr<Ship::Config> config = nullptr,
25 std::shared_ptr<Ship::FileDrop> fileDrop = nullptr,
26 std::shared_ptr<Ship::ConsoleVariable> consoleVariable = nullptr,
27 std::shared_ptr<Fast::Fast3dGui> fast3dGui = nullptr);
29
32 void Init(const char* gameName, const char* apiName, bool startFullScreen, uint32_t width, uint32_t height,
33 int32_t posX, int32_t posY) override;
34 void Close() override;
35 void SetKeyboardCallbacks(bool (*onKeyDown)(int scancode), bool (*onKeyUp)(int scancode),
36 void (*onAllKeysUp)()) override;
37 void SetMouseCallbacks(bool (*onMouseButtonDown)(int btn), bool (*onMouseButtonUp)(int btn)) override;
38 void SetFullscreenChangedCallback(void (*onFullscreenChanged)(bool is_now_fullscreen)) override;
39 void SetFullscreen(bool fullscreen) override;
40 void GetActiveWindowRefreshRate(uint32_t* refreshRate) override;
41 void SetCursorVisibility(bool visability) override;
42 void SetMousePos(int32_t posX, int32_t posY) override;
43 void GetMousePos(int32_t* x, int32_t* y) override;
44 void GetMouseDelta(int32_t* x, int32_t* y) override;
45 void GetMouseWheel(float* x, float* y) override;
46 bool GetMouseState(uint32_t btn) override;
47 void SetMouseCapture(bool capture) override;
48 bool IsMouseCaptured() override;
49 void GetDimensions(uint32_t* width, uint32_t* height, int32_t* posX, int32_t* posY) override;
50 void SetDimensions(uint32_t width, uint32_t height, int32_t posX, int32_t posY) override;
52 void HandleEvents() override;
53 bool IsFrameReady() override;
54 void SwapBuffersBegin() override;
55 void SwapBuffersEnd() override;
56 double GetTime() override;
58 void SetTargetFps(int fps) override;
59 void SetMaxFrameLatency(int latency) override;
60 const char* GetKeyName(int scancode) override;
61 bool CanDisableVsync() override;
62 bool IsRunning() override;
63 void Destroy() override;
64 bool IsFullscreen() override;
66 private:
67 void SetFullscreenImpl(bool on, bool call_callback);
68 void HandleSingleEvent(SDL_Event& event);
69 int TranslateScancode(int scancode) const;
70 int UntranslateScancode(int translatedScancode) const;
71 void OnKeydown(int scancode) const;
72 void OnKeyup(int scancode) const;
73 void OnMouseButtonDown(int btn) const;
74 void OnMouseButtonUp(int btn) const;
75 void SyncFramerateWithTime() const;
76
77 SDL_Window* mWnd;
78 SDL_Rect mCursorClip;
79 SDL_GLContext mCtx;
80 SDL_Renderer* mRenderer;
81 int mSdlToLusTable[512];
82 float mMouseWheelX = 0.0f;
83 float mMouseWheelY = 0.0f;
84#ifdef __OpenBSD__
85 int mBsdTick; // store kern.clockrate's tick (microseconds) to adjust sleep timing
86#endif
87 // OTRTODO: These are redundant. Info can be queried from SDL.
88 int mWindowWidth = 640;
89 int mWindowHeight = 480;
90 void (*mOnAllKeysUp)();
91
92 std::shared_ptr<Ship::ConsoleVariable> mConsoleVariable;
93 std::shared_ptr<Ship::Config> mConfig;
94 std::shared_ptr<Ship::FileDrop> mFileDrop;
95 std::shared_ptr<Fast::Fast3dGui> mFast3dGui;
96};
97} // namespace Fast
SDL2 implementation of the Fast3D window/input backend.
Definition gfx_sdl.h:21
void SetKeyboardCallbacks(bool(*onKeyDown)(int scancode), bool(*onKeyUp)(int scancode), void(*onAllKeysUp)()) override
void GetActiveWindowRefreshRate(uint32_t *refreshRate) override
const char * GetKeyName(int scancode) override
void GetMousePos(int32_t *x, int32_t *y) override
void SwapBuffersBegin() override
bool CanDisableVsync() override
void SetTargetFps(int fps) override
bool IsRunning() override
void SetDimensions(uint32_t width, uint32_t height, int32_t posX, int32_t posY) override
void SetFullscreenChangedCallback(void(*onFullscreenChanged)(bool is_now_fullscreen)) override
void SetCursorVisibility(bool visability) override
void Init(const char *gameName, const char *apiName, bool startFullScreen, uint32_t width, uint32_t height, int32_t posX, int32_t posY) override
void SetMouseCallbacks(bool(*onMouseButtonDown)(int btn), bool(*onMouseButtonUp)(int btn)) override
void GetDimensions(uint32_t *width, uint32_t *height, int32_t *posX, int32_t *posY) override
void GetMouseDelta(int32_t *x, int32_t *y) override
Ship::WindowRect GetPrimaryMonitorRect() override
void SwapBuffersEnd() override
double GetTime() override
void SetMousePos(int32_t posX, int32_t posY) override
void SetFullscreen(bool fullscreen) override
GfxWindowBackendSDL2(std::shared_ptr< Ship::Config > config=nullptr, std::shared_ptr< Ship::FileDrop > fileDrop=nullptr, std::shared_ptr< Ship::ConsoleVariable > consoleVariable=nullptr, std::shared_ptr< Fast::Fast3dGui > fast3dGui=nullptr)
Constructs the backend with optional shared engine dependencies.
bool GetMouseState(uint32_t btn) override
void SetMouseCapture(bool capture) override
void HandleEvents() override
bool IsFrameReady() override
bool IsMouseCaptured() override
bool IsFullscreen() override
void SetMaxFrameLatency(int latency) override
void GetMouseWheel(float *x, float *y) override
Definition gfx_window_manager_api.h:7
Definition gfx_direct3d_common.h:19
Core namespace for the libultraship engine framework.
Definition gfx_direct3d_common.h:14
Screen-space rectangle in integer pixels.
Definition Window.h:38