| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | |
| 15 | |
| 16 | |
| 17 | |
| 18 | |
| 19 | |
| 20 | |
| 21 | |
| 22 | |
| 23 | |
| 24 | #ifndef GLFWPP_HH |
| 25 | #define GLFWPP_HH |
| 26 | |
| 27 | #include <glfw/glfw3.h> |
| 28 | #include "types.hh" |
| 29 | #include <span> |
| 30 | |
| 31 | namespace glfwpp { |
| 32 | enum ErrorCodes { |
| 33 | NotInitialized = 0x00010001, |
| 34 | NoCurrentContext = 0x00010002, |
| 35 | InvalidEnum = 0x00010003, |
| 36 | InvalidValue = 0x00010004, |
| 37 | OutOfMemory = 0x00010005, |
| 38 | ApiUnavailable = 0x00010006, |
| 39 | VersionUnavailable = 0x00010007, |
| 40 | PlatformError = 0x00010008, |
| 41 | FormatUnavailable = 0x00010009, |
| 42 | NoWindowContent = 0x0001000A, |
| 43 | }; |
| 44 | |
| 45 | enum Attributes { |
| 46 | Focused = 0x00020001, |
| 47 | Iconified = 0x00020002, |
| 48 | Resizable = 0x00020003, |
| 49 | visible = 0x00020004, |
| 50 | Decorated = 0x00020005, |
| 51 | AutoNotify = 0x00020006, |
| 52 | Floating = 0x00020007, |
| 53 | Maximized = 0x00020008, |
| 54 | |
| 55 | RedBits = 0x00021001, |
| 56 | GreenBits = 0x00021002, |
| 57 | BlueBits = 0x00021003, |
| 58 | AlphaBits = 0x00021004, |
| 59 | DepthBits = 0x00021005, |
| 60 | StencilBits = 0x00021006, |
| 61 | AccumRedBits = 0x00021007, |
| 62 | AccumGreenBits = 0x00021008, |
| 63 | AccumBlueBits = 0x00021009, |
| 64 | AccumAlphaBits = 0x0002100A, |
| 65 | AuxBuffers = 0x0002100B, |
| 66 | Stereo = 0x0002100C, |
| 67 | Samples = 0x0002100D, |
| 68 | SrgbCapable = 0x0002100E, |
| 69 | RefreshRate = 0x0002100F, |
| 70 | Doublebuffer = 0x00021010, |
| 71 | |
| 72 | ClientApi = 0x00022001, |
| 73 | ContextVersionMajor = 0x00022002, |
| 74 | ContextVersionMinor = 0x00022003, |
| 75 | ContextRevision = 0x00022004, |
| 76 | ContextRobustness = 0x00022005, |
| 77 | OpenGLForwardCompatable = 0x00022006, |
| 78 | OpenGLDebugContext = 0x00022007, |
| 79 | OpenGLProfile = 0x00022008, |
| 80 | ContextReleaseBehavior = 0x00022009, |
| 81 | ContextNoError = 0x0002200A, |
| 82 | |
| 83 | NoApi = 0, |
| 84 | OpenGLApi = 0x00030001, |
| 85 | OpenGLESApi = 0x00030002, |
| 86 | |
| 87 | NoRobustness = 0, |
| 88 | NoResetNotification = 0x00031001, |
| 89 | LoseContextOnReset = 0x00031002, |
| 90 | |
| 91 | AnyOpenGLProfile = 0, |
| 92 | OpenGLCore = 0x00032001, |
| 93 | OpenGLCompat = 0x00032002, |
| 94 | |
| 95 | Cursor = 0x00033001, |
| 96 | StickyKeys = 0x00033002, |
| 97 | StickyMouseButtons = 0x00033003, |
| 98 | |
| 99 | CursorNormal = 0x00034001, |
| 100 | CursorHidden = 0x00034002, |
| 101 | CursorDisabled = 0x00034003, |
| 102 | |
| 103 | AnyReleaseBehavior = 0, |
| 104 | ReleaseBehaviorFlush = 0x00035001, |
| 105 | ReleaseBehaviorNone = 0x00035002, |
| 106 | }; |
| 107 | |
| 108 | enum CursorShapes { |
| 109 | ArrowCursor = 0x00036001, |
| 110 | IbeamCursor = 0x00036002, |
| 111 | CrosshairCursor = 0x00036003, |
| 112 | HandCursor = 0x00036004, |
| 113 | HResizeCursor = 0x00036005, |
| 114 | VResizeCursor = 0x00036006, |
| 115 | }; |
| 116 | |
| 117 | enum Connection { |
| 118 | Connected = 0x00040001, |
| 119 | Disconnected = 0x00040002, |
| 120 | DontCare = -1, |
| 121 | }; |
| 122 | |
| 123 | enum ButtonMode { |
| 124 | LockKeyMods = 0x00032004, |
| 125 | RawMouseMotion = 0x00032005, |
| 126 | }; |
| 127 | |
| 128 | enum ContextApi { |
| 129 | Native = 0x00032001, |
| 130 | EGL = 0x00032002, |
| 131 | OSMESA = 0x00032003, |
| 132 | }; |
| 133 | |
| 134 | class Instance { |
| 135 | public: |
| 136 | Instance(); |
| 137 | ~Instance(); |
| 138 | |
| 139 | GLFWerrorfun SetErrorCallback(); |
| 140 | |
| 141 | void SetContextMajorVersion(int major); |
| 142 | void SetContextMinorVersion(int minor); |
| 143 | void SetOpenGLProfile(int profile); |
| 144 | void SetForwardCompatibility(bool fc); |
| 145 | void SetMaximized(bool fc); |
| 146 | |
| 147 | void CreateWindowHints(); |
| 148 | void PollEvents(); |
| 149 | |
| 150 | void SwapInterval(int interval); |
| 151 | double GetTime(); |
| 152 | void SetTime(double time); |
| 153 | u64 GetTimerValue(); |
| 154 | u64 GetTimerFrequency(); |
| 155 | |
| 156 | void InitHint(int hint, int value); |
| 157 | void GetVersion(int *major, int *minor, int *rev); |
| 158 | cstr GetVersionString(void); |
| 159 | |
| 160 | int GetError(cstr *description); |
| 161 | GLFWerrorfun SetErrorCallback(GLFWerrorfun cbfun); |
| 162 | |
| 163 | private: |
| 164 | int m_Major = 0; |
| 165 | int m_Minor = 0; |
| 166 | int m_Profile = 0; |
| 167 | bool m_ForwardCompat = false; |
| 168 | bool m_IsMaximized = false; |
| 169 | }; |
| 170 | |
| 171 | class Window { |
| 172 | public: |
| 173 | Window(int width, int height, string title); |
| 174 | ~Window(); |
| 175 | |
| 176 | GLFWwindow *Get() const { return m_Window; } |
| 177 | GLFWframebuffersizefun SetFramebufferSizeCallback(); |
| 178 | |
| 179 | bool ShouldClose() const; |
| 180 | void SwapBuffers(); |
| 181 | |
| 182 | void GetSize(int *w, int *h); |
| 183 | void Maximize(); |
| 184 | void SetClipboardString(string str); |
| 185 | string GetClipboardString(); |
| 186 | void MakeContextCurrent(); |
| 187 | int GetAttrib(int attrib); |
| 188 | int GetInputMode(int mode); |
| 189 | void SetInputMode(int mode, int value); |
| 190 | int RawMouseMotionSupported(); |
| 191 | cstr GetKeyName(int key, int scancode); |
| 192 | int GetKeyScancode(int key); |
| 193 | int GetKey(int key); |
| 194 | int GetMouseButton(int button); |
| 195 | void GetCursorPos(double *xpos, double *ypos); |
| 196 | void SetCursorPos(double xpos, double ypos); |
| 197 | |
| 198 | GLFWwindow *GetCurrentContext(); |
| 199 | bool IsExtensionSupported(cstr ext); |
| 200 | GLFWglproc GetProcAddress(cstr procname); |
| 201 | |
| 202 | GLFWkeyfun SetKeyCallback(GLFWkeyfun cbfun); |
| 203 | GLFWcharfun SetCharCallback(GLFWcharfun cbfun); |
| 204 | GLFWcharmodsfun SetCharModsCallback(GLFWcharmodsfun cbfun); |
| 205 | GLFWmousebuttonfun SetMouseButtonCallback(GLFWmousebuttonfun cbfun); |
| 206 | GLFWcursorposfun SetCursorPosCallback(GLFWcursorposfun cbfun); |
| 207 | GLFWcursorenterfun SetCursorEnterCallback(GLFWcursorenterfun cbfun); |
| 208 | GLFWscrollfun SetScrollCallback(GLFWscrollfun cbfun); |
| 209 | GLFWdropfun SetDropCallback(GLFWdropfun cbfun); |
| 210 | |
| 211 | int JoystickPresent(int jid); |
| 212 | const f32 *GetJoystickAxes(int jid, int *count); |
| 213 | const unsigned char *GetJoystickButtons(int jid, int *count); |
| 214 | const unsigned char *GetJoystickHats(int jid, int *count); |
| 215 | cstr GetJoystickName(int jid); |
| 216 | cstr GetJoystickGUID(int jid); |
| 217 | void SetJoystickUserPointer(int jid, any ptr); |
| 218 | any GetJoystickUserPointer(int jid); |
| 219 | GLFWjoystickfun SetJoystickCallback(GLFWjoystickfun cbfun); |
| 220 | int UpdateGamepadMappings(string str); |
| 221 | int JoystickIsGamepad(int jid); |
| 222 | cstr GetGamepadName(int jid); |
| 223 | int GetGamepadState(int jid, GLFWgamepadstate *state); |
| 224 | |
| 225 | private: |
| 226 | GLFWwindow *m_Window = {}; |
| 227 | int m_Width = 0; |
| 228 | int m_Height = 0; |
| 229 | }; |
| 230 | |
| 231 | class Monitor { |
| 232 | public: |
| 233 | Monitor(); |
| 234 | ~Monitor(); |
| 235 | |
| 236 | GLFWmonitor *Get() const { return m_Monitor; } |
| 237 | std::span<GLFWmonitor *> GetMonitors(int *count); |
| 238 | GLFWmonitor *GetPrimary(); |
| 239 | void GetPos(int *xpos, int *ypos); |
| 240 | void GetWorkarea(int *xpos, int *ypos, int *width, int *height); |
| 241 | void GetPhysicalSize(int *width, int *height); |
| 242 | void GetContentScale(float *xscale, float *yscale); |
| 243 | cstr GetName(); |
| 244 | void SetUserPointer(any ptr); |
| 245 | any GetUserPointer(); |
| 246 | GLFWmonitorfun SetCallback(GLFWmonitorfun cbfun); |
| 247 | const GLFWvidmode *GetVideoModes(int *count); |
| 248 | const GLFWvidmode *GetVideoMode(); |
| 249 | void SetGamma(float gamma); |
| 250 | const GLFWgammaramp *GetGammaRamp(); |
| 251 | void SetGammaRamp(const GLFWgammaramp *ramp); |
| 252 | |
| 253 | private: |
| 254 | GLFWmonitor *m_Monitor = {}; |
| 255 | }; |
| 256 | |
| 257 | class Cursor { |
| 258 | public: |
| 259 | Cursor(GLFWimage *img, int xhot, int yhot); |
| 260 | ~Cursor(); |
| 261 | |
| 262 | GLFWcursor *Get() const { return m_Cursor; } |
| 263 | GLFWcursor *CreateStandardCursor(int shape); |
| 264 | void Set(Window window); |
| 265 | |
| 266 | private: |
| 267 | GLFWimage *m_Image; |
| 268 | GLFWcursor *m_Cursor; |
| 269 | }; |
| 270 | } |
| 271 | |
| 272 | #endif |