| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | |
| 15 | |
| 16 | |
| 17 | |
| 18 | |
| 19 | |
| 20 | |
| 21 | |
| 22 | |
| 23 | |
| 24 | |
| 25 | |
| 26 | |
| 27 | |
| 28 | |
| 29 | |
| 30 | |
| 31 | |
| 32 | |
| 33 | |
| 34 | |
| 35 | |
| 36 | |
| 37 | |
| 38 | |
| 39 | |
| 40 | |
| 41 | |
| 42 | |
| 43 | |
| 44 | |
| 45 | |
| 46 | |
| 47 | |
| 48 | #if defined(_WIN32) || defined(_WIN64) |
| 49 | #define BI_ALPHABITFIELDS 4 |
| 50 | #define LoadImage LoadImageA |
| 51 | |
| 52 | |
| 53 | #define CloseWindow CloseWindowWin32 |
| 54 | #define Rectangle RectangleWin32 |
| 55 | #define ShowCursor ShowCursorWin32 |
| 56 | |
| 57 | #define WIN32_LEAN_AND_MEAN |
| 58 | #include <windows.h> |
| 59 | |
| 60 | |
| 61 | #undef CloseWindow |
| 62 | #undef Rectangle |
| 63 | #undef ShowCursor |
| 64 | #undef LoadImage |
| 65 | |
| 66 | #include "../external/fix_win32_compatibility.h" |
| 67 | #endif |
| 68 | |
| 69 | #if defined(PLATFORM_WEB_RGFW) |
| 70 | #define RGFW_NO_GL_HEADER |
| 71 | #endif |
| 72 | |
| 73 | #if defined(GRAPHICS_API_OPENGL_ES2) && !defined(PLATFORM_WEB_RGFW) |
| 74 | #define RGFW_OPENGL_ES2 |
| 75 | #endif |
| 76 | |
| 77 | void ShowCursor(void); |
| 78 | void CloseWindow(void); |
| 79 | double get_time_seconds(void); |
| 80 | |
| 81 | #if defined(__unix__) || defined(__linux__) |
| 82 | #define _XTYPEDEF_FONT |
| 83 | #endif |
| 84 | |
| 85 | #define RGFW_OPENGL |
| 86 | #define RGFW_IMPLEMENTATION |
| 87 | |
| 88 | #if defined(_WIN32) || defined(_WIN64) |
| 89 | #define WIN32_LEAN_AND_MEAN |
| 90 | #define Rectangle rectangle_win32 |
| 91 | #define CloseWindow CloseWindow_win32 |
| 92 | #define ShowCursor __imp_ShowCursor |
| 93 | #define _APISETSTRING_ |
| 94 | |
| 95 | #if defined(__cplusplus) |
| 96 | extern "C" { |
| 97 | #endif |
| 98 | __declspec(dllimport) int __stdcall MultiByteToWideChar(unsigned int CodePage, unsigned long dwFlags, const char *lpMultiByteStr, int cbMultiByte, wchar_t *lpWideCharStr, int cchWideChar); |
| 99 | #if defined(__cplusplus) |
| 100 | } |
| 101 | #endif |
| 102 | |
| 103 | #endif |
| 104 | |
| 105 | #if defined(__APPLE__) |
| 106 | #define Point NSPOINT |
| 107 | #define Size NSSIZE |
| 108 | |
| 109 | #ifdef GetColor |
| 110 | #undef GetColor |
| 111 | #endif |
| 112 | #define GetColor GetColor_osx |
| 113 | #ifdef EventType |
| 114 | #undef EventType |
| 115 | #endif |
| 116 | #define EventType EventType_osx |
| 117 | #endif |
| 118 | |
| 119 | #if defined(__APPLE__) |
| 120 | |
| 121 | #include <IOKit/hid/IOHIDUsageTables.h> |
| 122 | #ifndef kHIDUsage_Button_5 |
| 123 | #define kHIDUsage_Button_5 0x05 |
| 124 | #endif |
| 125 | #ifndef kHIDUsage_Button_6 |
| 126 | #define kHIDUsage_Button_6 0x06 |
| 127 | #endif |
| 128 | #ifndef kHIDUsage_Button_7 |
| 129 | #define kHIDUsage_Button_7 0x07 |
| 130 | #endif |
| 131 | #ifndef kHIDUsage_Button_8 |
| 132 | #define kHIDUsage_Button_8 0x08 |
| 133 | #endif |
| 134 | #ifndef kHIDUsage_Button_9 |
| 135 | #define kHIDUsage_Button_9 0x09 |
| 136 | #endif |
| 137 | #ifndef kHIDUsage_Button_10 |
| 138 | #define kHIDUsage_Button_10 0x0A |
| 139 | #endif |
| 140 | #endif |
| 141 | |
| 142 | |
| 143 | #define MG_MAX_GAMEPADS MAX_GAMEPADS |
| 144 | #define MG_IMPLEMENTATION |
| 145 | #include "../external/RGFW/deps/minigamepad.h" |
| 146 | |
| 147 | #define RGFW_ALLOC RL_MALLOC |
| 148 | #define RGFW_FREE RL_FREE |
| 149 | #define RGFW_CALLOC RL_CALLOC |
| 150 | #define RGFW_INT_DEFINED 1 |
| 151 | |
| 152 | #include "../external/RGFW/RGFW.h" |
| 153 | |
| 154 | #if defined(_WIN32) || defined(_WIN64) |
| 155 | #undef DrawText |
| 156 | #undef ShowCursor |
| 157 | #undef CloseWindow |
| 158 | #undef Rectangle |
| 159 | |
| 160 | #ifdef MAX_PATH |
| 161 | #undef MAX_PATH |
| 162 | #endif |
| 163 | #define MAX_PATH 1025 |
| 164 | #endif |
| 165 | |
| 166 | #if defined(__APPLE__) |
| 167 | #undef Point |
| 168 | #undef Size |
| 169 | #endif |
| 170 | |
| 171 | #include <stdbool.h> |
| 172 | |
| 173 | |
| 174 | |
| 175 | |
| 176 | typedef struct { |
| 177 | RGFW_window *window; |
| 178 | RGFW_monitor *monitor; |
| 179 | mg_gamepads minigamepad; |
| 180 | |
| 181 | #if defined(GRAPHICS_API_OPENGL_SOFTWARE) |
| 182 | RGFW_surface *surface; |
| 183 | u8 *surfacePixels; |
| 184 | i32 surfaceWidth; |
| 185 | i32 surfaceHeight; |
| 186 | #endif |
| 187 | } PlatformData; |
| 188 | |
| 189 | |
| 190 | |
| 191 | |
| 192 | extern CoreData CORE; |
| 193 | |
| 194 | static PlatformData platform = { 0 }; |
| 195 | |
| 196 | #if defined(__linux__) |
| 197 | #undef KEY_NULL |
| 198 | |
| 199 | #undef KEY_APOSTROPHE |
| 200 | #undef KEY_COMMA |
| 201 | #undef KEY_MINUS |
| 202 | #undef KEY_PERIOD |
| 203 | #undef KEY_SLASH |
| 204 | #undef KEY_ZERO |
| 205 | #undef KEY_ONE |
| 206 | #undef KEY_TWO |
| 207 | #undef KEY_THREE |
| 208 | #undef KEY_FOUR |
| 209 | #undef KEY_FIVE |
| 210 | #undef KEY_SIX |
| 211 | #undef KEY_SEVEN |
| 212 | #undef KEY_EIGHT |
| 213 | #undef KEY_NINE |
| 214 | #undef KEY_SEMICOLON |
| 215 | #undef KEY_EQUAL |
| 216 | #undef KEY_A |
| 217 | #undef KEY_B |
| 218 | #undef KEY_C |
| 219 | #undef KEY_D |
| 220 | #undef KEY_E |
| 221 | #undef KEY_F |
| 222 | #undef KEY_G |
| 223 | #undef KEY_H |
| 224 | #undef KEY_I |
| 225 | #undef KEY_J |
| 226 | #undef KEY_K |
| 227 | #undef KEY_L |
| 228 | #undef KEY_M |
| 229 | #undef KEY_N |
| 230 | #undef KEY_O |
| 231 | #undef KEY_P |
| 232 | #undef KEY_Q |
| 233 | #undef KEY_R |
| 234 | #undef KEY_S |
| 235 | #undef KEY_T |
| 236 | #undef KEY_U |
| 237 | #undef KEY_V |
| 238 | #undef KEY_W |
| 239 | #undef KEY_X |
| 240 | #undef KEY_Y |
| 241 | #undef KEY_Z |
| 242 | #undef KEY_LEFT_BRACKET |
| 243 | #undef KEY_BACKSLASH |
| 244 | #undef KEY_RIGHT_BRACKET |
| 245 | #undef KEY_GRAVE |
| 246 | |
| 247 | #undef KEY_SPACE |
| 248 | #undef KEY_ESCAPE |
| 249 | #undef KEY_ENTER |
| 250 | #undef KEY_TAB |
| 251 | #undef KEY_BACKSPACE |
| 252 | #undef KEY_INSERT |
| 253 | #undef KEY_DELETE |
| 254 | #undef KEY_RIGHT |
| 255 | #undef KEY_LEFT |
| 256 | #undef KEY_DOWN |
| 257 | #undef KEY_UP |
| 258 | #undef KEY_PAGE_UP |
| 259 | #undef KEY_PAGE_DOWN |
| 260 | #undef KEY_HOME |
| 261 | #undef KEY_END |
| 262 | #undef KEY_CAPS_LOCK |
| 263 | #undef KEY_SCROLL_LOCK |
| 264 | #undef KEY_NUM_LOCK |
| 265 | #undef KEY_PRINT_SCREEN |
| 266 | #undef KEY_PAUSE |
| 267 | #undef KEY_F1 |
| 268 | #undef KEY_F2 |
| 269 | #undef KEY_F3 |
| 270 | #undef KEY_F4 |
| 271 | #undef KEY_F5 |
| 272 | #undef KEY_F6 |
| 273 | #undef KEY_F7 |
| 274 | #undef KEY_F8 |
| 275 | #undef KEY_F9 |
| 276 | #undef KEY_F10 |
| 277 | #undef KEY_F11 |
| 278 | #undef KEY_F12 |
| 279 | #undef KEY_LEFT_SHIFT |
| 280 | #undef KEY_LEFT_CONTROL |
| 281 | #undef KEY_LEFT_ALT |
| 282 | #undef KEY_LEFT_SUPER |
| 283 | #undef KEY_RIGHT_SHIFT |
| 284 | #undef KEY_RIGHT_CONTROL |
| 285 | #undef KEY_RIGHT_ALT |
| 286 | #undef KEY_RIGHT_SUPER |
| 287 | #undef KEY_KB_MENU |
| 288 | |
| 289 | #undef KEY_KP_0 |
| 290 | #undef KEY_KP_1 |
| 291 | #undef KEY_KP_2 |
| 292 | #undef KEY_KP_3 |
| 293 | #undef KEY_KP_4 |
| 294 | #undef KEY_KP_5 |
| 295 | #undef KEY_KP_6 |
| 296 | #undef KEY_KP_7 |
| 297 | #undef KEY_KP_8 |
| 298 | #undef KEY_KP_9 |
| 299 | #undef KEY_KP_DECIMAL |
| 300 | #undef KEY_KP_DIVIDE |
| 301 | #undef KEY_KP_MULTIPLY |
| 302 | #undef KEY_KP_SUBTRACT |
| 303 | #undef KEY_KP_ADD |
| 304 | #undef KEY_KP_ENTER |
| 305 | #undef KEY_KP_EQUAL |
| 306 | #endif |
| 307 | |
| 308 | static const unsigned short RGFW_keyConvertTable[] = { |
| 309 | [RGFW_keyNULL] = KEY_NULL, |
| 310 | [RGFW_apostrophe] = KEY_APOSTROPHE, |
| 311 | [RGFW_comma] = KEY_COMMA, |
| 312 | [RGFW_minus] = KEY_MINUS, |
| 313 | [RGFW_period] = KEY_PERIOD, |
| 314 | [RGFW_slash] = KEY_SLASH, |
| 315 | [RGFW_0] = KEY_ZERO, |
| 316 | [RGFW_1] = KEY_ONE, |
| 317 | [RGFW_2] = KEY_TWO, |
| 318 | [RGFW_3] = KEY_THREE, |
| 319 | [RGFW_4] = KEY_FOUR, |
| 320 | [RGFW_5] = KEY_FIVE, |
| 321 | [RGFW_6] = KEY_SIX, |
| 322 | [RGFW_7] = KEY_SEVEN, |
| 323 | [RGFW_8] = KEY_EIGHT, |
| 324 | [RGFW_9] = KEY_NINE, |
| 325 | [RGFW_semicolon] = KEY_SEMICOLON, |
| 326 | [RGFW_equals] = KEY_EQUAL, |
| 327 | [RGFW_a] = KEY_A, |
| 328 | [RGFW_b] = KEY_B, |
| 329 | [RGFW_c] = KEY_C, |
| 330 | [RGFW_d] = KEY_D, |
| 331 | [RGFW_e] = KEY_E, |
| 332 | [RGFW_f] = KEY_F, |
| 333 | [RGFW_g] = KEY_G, |
| 334 | [RGFW_h] = KEY_H, |
| 335 | [RGFW_i] = KEY_I, |
| 336 | [RGFW_j] = KEY_J, |
| 337 | [RGFW_k] = KEY_K, |
| 338 | [RGFW_l] = KEY_L, |
| 339 | [RGFW_m] = KEY_M, |
| 340 | [RGFW_n] = KEY_N, |
| 341 | [RGFW_o] = KEY_O, |
| 342 | [RGFW_p] = KEY_P, |
| 343 | [RGFW_q] = KEY_Q, |
| 344 | [RGFW_r] = KEY_R, |
| 345 | [RGFW_s] = KEY_S, |
| 346 | [RGFW_t] = KEY_T, |
| 347 | [RGFW_u] = KEY_U, |
| 348 | [RGFW_v] = KEY_V, |
| 349 | [RGFW_w] = KEY_W, |
| 350 | [RGFW_x] = KEY_X, |
| 351 | [RGFW_y] = KEY_Y, |
| 352 | [RGFW_z] = KEY_Z, |
| 353 | [RGFW_bracket] = KEY_LEFT_BRACKET, |
| 354 | [RGFW_backSlash] = KEY_BACKSLASH, |
| 355 | [RGFW_closeBracket] = KEY_RIGHT_BRACKET, |
| 356 | [RGFW_backtick] = KEY_GRAVE, |
| 357 | [RGFW_space] = KEY_SPACE, |
| 358 | [RGFW_escape] = KEY_ESCAPE, |
| 359 | [RGFW_return] = KEY_ENTER, |
| 360 | [RGFW_tab] = KEY_TAB, |
| 361 | [RGFW_backSpace] = KEY_BACKSPACE, |
| 362 | [RGFW_insert] = KEY_INSERT, |
| 363 | [RGFW_delete] = KEY_DELETE, |
| 364 | [RGFW_right] = KEY_RIGHT, |
| 365 | [RGFW_left] = KEY_LEFT, |
| 366 | [RGFW_down] = KEY_DOWN, |
| 367 | [RGFW_up] = KEY_UP, |
| 368 | [RGFW_pageUp] = KEY_PAGE_UP, |
| 369 | [RGFW_pageDown] = KEY_PAGE_DOWN, |
| 370 | [RGFW_home] = KEY_HOME, |
| 371 | [RGFW_end] = KEY_END, |
| 372 | [RGFW_capsLock] = KEY_CAPS_LOCK, |
| 373 | [RGFW_scrollLock] = KEY_SCROLL_LOCK, |
| 374 | [RGFW_numLock] = KEY_NUM_LOCK, |
| 375 | [RGFW_printScreen] = KEY_PRINT_SCREEN, |
| 376 | [RGFW_pause] = KEY_PAUSE, |
| 377 | [RGFW_F1] = KEY_F1, |
| 378 | [RGFW_F2] = KEY_F2, |
| 379 | [RGFW_F3] = KEY_F3, |
| 380 | [RGFW_F4] = KEY_F4, |
| 381 | [RGFW_F5] = KEY_F5, |
| 382 | [RGFW_F6] = KEY_F6, |
| 383 | [RGFW_F7] = KEY_F7, |
| 384 | [RGFW_F8] = KEY_F8, |
| 385 | [RGFW_F9] = KEY_F9, |
| 386 | [RGFW_F10] = KEY_F10, |
| 387 | [RGFW_F11] = KEY_F11, |
| 388 | [RGFW_F12] = KEY_F12, |
| 389 | [RGFW_shiftL] = KEY_LEFT_SHIFT, |
| 390 | [RGFW_controlL] = KEY_LEFT_CONTROL, |
| 391 | [RGFW_altL] = KEY_LEFT_ALT, |
| 392 | [RGFW_superL] = KEY_LEFT_SUPER, |
| 393 | |
| 394 | [RGFW_shiftR] = KEY_RIGHT_SHIFT, |
| 395 | [RGFW_controlR] = KEY_RIGHT_CONTROL, |
| 396 | [RGFW_altR] = KEY_RIGHT_ALT, |
| 397 | [RGFW_superR] = KEY_RIGHT_SUPER, |
| 398 | |
| 399 | [RGFW_menu] = KEY_KB_MENU, |
| 400 | [RGFW_kp0] = KEY_KP_0, |
| 401 | [RGFW_kp1] = KEY_KP_1, |
| 402 | [RGFW_kp2] = KEY_KP_2, |
| 403 | [RGFW_kp3] = KEY_KP_3, |
| 404 | [RGFW_kp4] = KEY_KP_4, |
| 405 | [RGFW_kp5] = KEY_KP_5, |
| 406 | [RGFW_kp6] = KEY_KP_6, |
| 407 | [RGFW_kp7] = KEY_KP_7, |
| 408 | [RGFW_kp8] = KEY_KP_8, |
| 409 | [RGFW_kp9] = KEY_KP_9, |
| 410 | [RGFW_kpPeriod] = KEY_KP_DECIMAL, |
| 411 | [RGFW_kpSlash] = KEY_KP_DIVIDE, |
| 412 | [RGFW_kpMultiply] = KEY_KP_MULTIPLY, |
| 413 | [RGFW_kpMinus] = KEY_KP_SUBTRACT, |
| 414 | [RGFW_kpPlus] = KEY_KP_ADD, |
| 415 | [RGFW_kpReturn] = KEY_KP_ENTER, |
| 416 | [RGFW_kpEqual] = KEY_KP_EQUAL, |
| 417 | }; |
| 418 | |
| 419 | static int mg_buttonConvertTable[] = { |
| 420 | [MG_BUTTON_NORTH] = GAMEPAD_BUTTON_RIGHT_FACE_UP, |
| 421 | [MG_BUTTON_EAST] = GAMEPAD_BUTTON_RIGHT_FACE_RIGHT, |
| 422 | [MG_BUTTON_SOUTH] = GAMEPAD_BUTTON_RIGHT_FACE_DOWN, |
| 423 | [MG_BUTTON_WEST] = GAMEPAD_BUTTON_RIGHT_FACE_LEFT, |
| 424 | [MG_BUTTON_LEFT_SHOULDER] = GAMEPAD_BUTTON_LEFT_TRIGGER_1, |
| 425 | [MG_BUTTON_RIGHT_SHOULDER] = GAMEPAD_BUTTON_RIGHT_TRIGGER_1, |
| 426 | [MG_BUTTON_LEFT_TRIGGER] = GAMEPAD_BUTTON_LEFT_TRIGGER_2, |
| 427 | [MG_BUTTON_RIGHT_TRIGGER] = GAMEPAD_BUTTON_RIGHT_TRIGGER_2, |
| 428 | [MG_BUTTON_BACK] = GAMEPAD_BUTTON_MIDDLE_LEFT, |
| 429 | [MG_BUTTON_GUIDE] = GAMEPAD_BUTTON_MIDDLE, |
| 430 | [MG_BUTTON_START] = GAMEPAD_BUTTON_MIDDLE_RIGHT, |
| 431 | [MG_BUTTON_DPAD_UP] = GAMEPAD_BUTTON_LEFT_FACE_UP, |
| 432 | [MG_BUTTON_DPAD_RIGHT] = GAMEPAD_BUTTON_LEFT_FACE_RIGHT, |
| 433 | [MG_BUTTON_DPAD_DOWN] = GAMEPAD_BUTTON_LEFT_FACE_DOWN, |
| 434 | [MG_BUTTON_DPAD_LEFT] = GAMEPAD_BUTTON_LEFT_FACE_LEFT, |
| 435 | [MG_BUTTON_LEFT_STICK] = GAMEPAD_BUTTON_LEFT_THUMB, |
| 436 | [MG_BUTTON_RIGHT_STICK] = GAMEPAD_BUTTON_RIGHT_THUMB, |
| 437 | }; |
| 438 | |
| 439 | static int mg_axisConvertTable[] = { |
| 440 | [MG_AXIS_LEFT_X] = GAMEPAD_AXIS_LEFT_X, |
| 441 | [MG_AXIS_LEFT_Y] = GAMEPAD_AXIS_LEFT_Y, |
| 442 | [MG_AXIS_RIGHT_X] = GAMEPAD_AXIS_RIGHT_X, |
| 443 | [MG_AXIS_RIGHT_Y] = GAMEPAD_AXIS_RIGHT_Y, |
| 444 | [MG_AXIS_LEFT_TRIGGER] = GAMEPAD_AXIS_LEFT_TRIGGER, |
| 445 | [MG_AXIS_RIGHT_TRIGGER] = GAMEPAD_AXIS_RIGHT_TRIGGER, |
| 446 | |
| 447 | |
| 448 | [MG_AXIS_HAT_DPAD_LEFT_RIGHT] = -1, |
| 449 | [MG_AXIS_HAT_DPAD_LEFT] = -1, |
| 450 | [MG_AXIS_HAT_DPAD_RIGHT] = -1, |
| 451 | [MG_AXIS_HAT_DPAD_UP_DOWN] = -1, |
| 452 | [MG_AXIS_HAT_DPAD_UP] = -1, |
| 453 | [MG_AXIS_HAT_DPAD_DOWN] = -1, |
| 454 | }; |
| 455 | |
| 456 | |
| 457 | |
| 458 | |
| 459 | int InitPlatform(void); |
| 460 | bool InitGraphicsDevice(void); |
| 461 | |
| 462 | static KeyboardKey ConvertScancodeToKey(u32 keycode); |
| 463 | |
| 464 | |
| 465 | |
| 466 | |
| 467 | |
| 468 | |
| 469 | |
| 470 | |
| 471 | |
| 472 | |
| 473 | |
| 474 | bool WindowShouldClose(void) |
| 475 | { |
| 476 | if (CORE.Window.shouldClose == false) |
| 477 | CORE.Window.shouldClose = RGFW_window_shouldClose(platform.window); |
| 478 | if (CORE.Window.ready) return CORE.Window.shouldClose; |
| 479 | else return true; |
| 480 | } |
| 481 | |
| 482 | |
| 483 | void ToggleFullscreen(void) |
| 484 | { |
| 485 | if (!FLAG_IS_SET(CORE.Window.flags, FLAG_FULLSCREEN_MODE)) |
| 486 | { |
| 487 | FLAG_SET(CORE.Window.flags, FLAG_FULLSCREEN_MODE); |
| 488 | |
| 489 | Vector2 currentPosition = GetWindowPosition(); |
| 490 | CORE.Window.previousPosition.x = currentPosition.x; |
| 491 | CORE.Window.previousPosition.y = currentPosition.y; |
| 492 | CORE.Window.previousScreen = CORE.Window.screen; |
| 493 | |
| 494 | RGFW_monitor* currentMonitor = RGFW_window_getMonitor(platform.window); |
| 495 | RGFW_monitor_scaleToWindow(currentMonitor, platform.window); |
| 496 | RGFW_window_setFullscreen(platform.window, 1); |
| 497 | } |
| 498 | else |
| 499 | { |
| 500 | FLAG_CLEAR(CORE.Window.flags, FLAG_FULLSCREEN_MODE); |
| 501 | |
| 502 | |
| 503 | CORE.Window.position = CORE.Window.previousPosition; |
| 504 | RGFW_window_setFullscreen(platform.window, 0); |
| 505 | RGFW_window_move(platform.window, CORE.Window.position.x, CORE.Window.position.y); |
| 506 | RGFW_window_resize(platform.window, CORE.Window.previousScreen.width, CORE.Window.previousScreen.height); |
| 507 | } |
| 508 | |
| 509 | |
| 510 | |
| 511 | if (FLAG_IS_SET(CORE.Window.flags, FLAG_VSYNC_HINT)) RGFW_window_swapInterval_OpenGL(platform.window, 1); |
| 512 | } |
| 513 | |
| 514 | |
| 515 | void ToggleBorderlessWindowed(void) |
| 516 | { |
| 517 | if (FLAG_IS_SET(CORE.Window.flags, FLAG_FULLSCREEN_MODE)) |
| 518 | { |
| 519 | ToggleFullscreen(); |
| 520 | |
| 521 | |
| 522 | return; |
| 523 | } |
| 524 | |
| 525 | if (!FLAG_IS_SET(CORE.Window.flags, FLAG_BORDERLESS_WINDOWED_MODE)) |
| 526 | { |
| 527 | FLAG_SET(CORE.Window.flags, FLAG_BORDERLESS_WINDOWED_MODE); |
| 528 | |
| 529 | Vector2 currentPosition = GetWindowPosition(); |
| 530 | CORE.Window.previousPosition.x = (int)currentPosition.x; |
| 531 | CORE.Window.previousPosition.y = (int)currentPosition.y; |
| 532 | CORE.Window.previousScreen = CORE.Window.screen; |
| 533 | |
| 534 | RGFW_monitor *currentMonitor = RGFW_window_getMonitor(platform.window); |
| 535 | RGFW_window_setBorder(platform.window, 0); |
| 536 | RGFW_window_move(platform.window, 0, 0); |
| 537 | RGFW_window_resize(platform.window, currentMonitor->mode.w, currentMonitor->mode.h); |
| 538 | } |
| 539 | else |
| 540 | { |
| 541 | FLAG_CLEAR(CORE.Window.flags, FLAG_BORDERLESS_WINDOWED_MODE); |
| 542 | RGFW_window_setBorder(platform.window, 1); |
| 543 | |
| 544 | CORE.Window.position = CORE.Window.previousPosition; |
| 545 | |
| 546 | RGFW_window_resize(platform.window, CORE.Window.previousScreen.width, CORE.Window.previousScreen.height); |
| 547 | RGFW_window_move(platform.window, CORE.Window.position.x, CORE.Window.position.y); |
| 548 | } |
| 549 | } |
| 550 | |
| 551 | |
| 552 | void MaximizeWindow(void) |
| 553 | { |
| 554 | RGFW_window_maximize(platform.window); |
| 555 | } |
| 556 | |
| 557 | |
| 558 | void MinimizeWindow(void) |
| 559 | { |
| 560 | RGFW_window_minimize(platform.window); |
| 561 | } |
| 562 | |
| 563 | |
| 564 | void RestoreWindow(void) |
| 565 | { |
| 566 | if (!FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_UNFOCUSED)) RGFW_window_focus(platform.window); |
| 567 | |
| 568 | RGFW_window_restore(platform.window); |
| 569 | } |
| 570 | |
| 571 | |
| 572 | void SetWindowState(unsigned int flags) |
| 573 | { |
| 574 | if (!CORE.Window.ready) TRACELOG(LOG_WARNING, "WINDOW: SetWindowState does nothing before window initialization, Use \"SetConfigFlags\" instead"); |
| 575 | |
| 576 | FLAG_SET(CORE.Window.flags, flags); |
| 577 | |
| 578 | if (FLAG_IS_SET(flags, FLAG_VSYNC_HINT)) |
| 579 | { |
| 580 | RGFW_window_swapInterval_OpenGL(platform.window, 1); |
| 581 | } |
| 582 | if (FLAG_IS_SET(flags, FLAG_FULLSCREEN_MODE)) |
| 583 | { |
| 584 | ToggleFullscreen(); |
| 585 | } |
| 586 | if (FLAG_IS_SET(flags, FLAG_WINDOW_RESIZABLE)) |
| 587 | { |
| 588 | RGFW_window_setMaxSize(platform.window, 0, 0); |
| 589 | RGFW_window_setMinSize(platform.window, 0, 0); |
| 590 | } |
| 591 | if (FLAG_IS_SET(flags, FLAG_WINDOW_UNDECORATED)) |
| 592 | { |
| 593 | RGFW_window_setBorder(platform.window, 0); |
| 594 | } |
| 595 | if (FLAG_IS_SET(flags, FLAG_WINDOW_HIDDEN)) |
| 596 | { |
| 597 | RGFW_window_hide(platform.window); |
| 598 | } |
| 599 | if (FLAG_IS_SET(flags, FLAG_WINDOW_MINIMIZED)) |
| 600 | { |
| 601 | RGFW_window_minimize(platform.window); |
| 602 | } |
| 603 | if (FLAG_IS_SET(flags, FLAG_WINDOW_MAXIMIZED)) |
| 604 | { |
| 605 | RGFW_window_maximize(platform.window); |
| 606 | } |
| 607 | if (FLAG_IS_SET(flags, FLAG_WINDOW_UNFOCUSED)) |
| 608 | { |
| 609 | FLAG_SET(CORE.Window.flags, FLAG_WINDOW_UNFOCUSED); |
| 610 | FLAG_CLEAR(platform.window->internal.flags, RGFW_windowFocusOnShow); |
| 611 | RGFW_window_setFlags(platform.window, platform.window->internal.flags); |
| 612 | } |
| 613 | if (FLAG_IS_SET(flags, FLAG_WINDOW_TOPMOST)) |
| 614 | { |
| 615 | RGFW_window_setFloating(platform.window, RGFW_TRUE); |
| 616 | } |
| 617 | if (FLAG_IS_SET(flags, FLAG_WINDOW_ALWAYS_RUN)) |
| 618 | { |
| 619 | FLAG_SET(CORE.Window.flags, FLAG_WINDOW_ALWAYS_RUN); |
| 620 | } |
| 621 | if (FLAG_IS_SET(flags, FLAG_WINDOW_TRANSPARENT)) |
| 622 | { |
| 623 | TRACELOG(LOG_WARNING, "WINDOW: Framebuffer transparency can only be configured before window initialization"); |
| 624 | } |
| 625 | if (FLAG_IS_SET(flags, FLAG_WINDOW_HIGHDPI)) |
| 626 | { |
| 627 | TRACELOG(LOG_WARNING, "WINDOW: High DPI can only be configured before window initialization"); |
| 628 | } |
| 629 | if (FLAG_IS_SET(flags, FLAG_WINDOW_MOUSE_PASSTHROUGH)) |
| 630 | { |
| 631 | RGFW_window_setMousePassthrough(platform.window, 1); |
| 632 | } |
| 633 | if (FLAG_IS_SET(flags, FLAG_BORDERLESS_WINDOWED_MODE)) |
| 634 | { |
| 635 | ToggleBorderlessWindowed(); |
| 636 | } |
| 637 | if (FLAG_IS_SET(flags, FLAG_MSAA_4X_HINT)) |
| 638 | { |
| 639 | RGFW_glHints* hints = RGFW_getGlobalHints_OpenGL(); |
| 640 | hints->samples = 4; |
| 641 | RGFW_setGlobalHints_OpenGL(hints); |
| 642 | } |
| 643 | if (FLAG_IS_SET(flags, FLAG_INTERLACED_HINT)) |
| 644 | { |
| 645 | TRACELOG(LOG_WARNING, "RPI: Interlaced mode can only be configured before window initialization"); |
| 646 | } |
| 647 | } |
| 648 | |
| 649 | |
| 650 | void ClearWindowState(unsigned int flags) |
| 651 | { |
| 652 | FLAG_CLEAR(CORE.Window.flags, flags); |
| 653 | |
| 654 | if (FLAG_IS_SET(flags, FLAG_VSYNC_HINT)) |
| 655 | { |
| 656 | RGFW_window_swapInterval_OpenGL(platform.window, 0); |
| 657 | } |
| 658 | if (FLAG_IS_SET(flags, FLAG_FULLSCREEN_MODE)) |
| 659 | { |
| 660 | ToggleFullscreen(); |
| 661 | } |
| 662 | if (FLAG_IS_SET(flags, FLAG_WINDOW_RESIZABLE)) |
| 663 | { |
| 664 | RGFW_window_setMaxSize(platform.window, platform.window->w, platform.window->h); |
| 665 | RGFW_window_setMinSize(platform.window, platform.window->w, platform.window->h); |
| 666 | } |
| 667 | if (FLAG_IS_SET(flags, FLAG_WINDOW_UNDECORATED)) |
| 668 | { |
| 669 | RGFW_window_setBorder(platform.window, 1); |
| 670 | } |
| 671 | if (FLAG_IS_SET(flags, FLAG_WINDOW_HIDDEN)) |
| 672 | { |
| 673 | if (!FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_UNFOCUSED)) RGFW_window_focus(platform.window); |
| 674 | |
| 675 | RGFW_window_show(platform.window); |
| 676 | } |
| 677 | if (FLAG_IS_SET(flags, FLAG_WINDOW_MINIMIZED)) |
| 678 | { |
| 679 | if (!FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_UNFOCUSED)) RGFW_window_focus(platform.window); |
| 680 | |
| 681 | RGFW_window_restore(platform.window); |
| 682 | } |
| 683 | if (FLAG_IS_SET(flags, FLAG_WINDOW_MAXIMIZED)) |
| 684 | { |
| 685 | if (!FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_UNFOCUSED)) RGFW_window_focus(platform.window); |
| 686 | |
| 687 | RGFW_window_restore(platform.window); |
| 688 | } |
| 689 | if (FLAG_IS_SET(flags, FLAG_WINDOW_UNFOCUSED)) |
| 690 | { |
| 691 | RGFW_window_setFlags(platform.window, platform.window->internal.flags | RGFW_windowFocusOnShow); |
| 692 | } |
| 693 | if (FLAG_IS_SET(flags, FLAG_WINDOW_TOPMOST)) |
| 694 | { |
| 695 | RGFW_window_setFloating(platform.window, RGFW_FALSE); |
| 696 | } |
| 697 | if (FLAG_IS_SET(flags, FLAG_WINDOW_TRANSPARENT)) |
| 698 | { |
| 699 | TRACELOG(LOG_WARNING, "WINDOW: Framebuffer transparency can only be configured before window initialization"); |
| 700 | } |
| 701 | if (FLAG_IS_SET(flags, FLAG_WINDOW_HIGHDPI)) |
| 702 | { |
| 703 | TRACELOG(LOG_WARNING, "WINDOW: High DPI can only be configured before window initialization"); |
| 704 | } |
| 705 | if (FLAG_IS_SET(flags, FLAG_WINDOW_MOUSE_PASSTHROUGH)) |
| 706 | { |
| 707 | RGFW_window_setMousePassthrough(platform.window, 0); |
| 708 | } |
| 709 | if (FLAG_IS_SET(flags, FLAG_BORDERLESS_WINDOWED_MODE)) |
| 710 | { |
| 711 | ToggleBorderlessWindowed(); |
| 712 | } |
| 713 | if (FLAG_IS_SET(flags, FLAG_MSAA_4X_HINT)) |
| 714 | { |
| 715 | RGFW_glHints* hints = RGFW_getGlobalHints_OpenGL(); |
| 716 | hints->samples = 0; |
| 717 | RGFW_setGlobalHints_OpenGL(hints); |
| 718 | } |
| 719 | if (FLAG_IS_SET(flags, FLAG_INTERLACED_HINT)) |
| 720 | { |
| 721 | TRACELOG(LOG_WARNING, "RPI: Interlaced mode can only be configured before window initialization"); |
| 722 | } |
| 723 | } |
| 724 | |
| 725 | |
| 726 | void SetWindowIcon(Image image) |
| 727 | { |
| 728 | if (image.format != PIXELFORMAT_UNCOMPRESSED_R8G8B8A8) |
| 729 | { |
| 730 | TRACELOG(LOG_WARNING, "RGFW: Window icon image must be in R8G8B8A8 pixel format"); |
| 731 | return; |
| 732 | } |
| 733 | RGFW_window_setIcon(platform.window, (u8 *)image.data, image.width, image.height, RGFW_formatRGBA8); |
| 734 | } |
| 735 | |
| 736 | |
| 737 | void SetWindowIcons(Image *images, int count) |
| 738 | { |
| 739 | if ((images == NULL) || (count <= 0)) |
| 740 | { |
| 741 | RGFW_window_setIcon(platform.window, NULL, 0, 0, 0); |
| 742 | } |
| 743 | else |
| 744 | { |
| 745 | Image *bigIcon = NULL; |
| 746 | Image *smallIcon = NULL; |
| 747 | |
| 748 | for (int i = 0; i < count; i++) |
| 749 | { |
| 750 | if (images[i].format != PIXELFORMAT_UNCOMPRESSED_R8G8B8A8) |
| 751 | { |
| 752 | TRACELOG(LOG_WARNING, "RGFW: Window icon image must be in R8G8B8A8 pixel format"); |
| 753 | continue; |
| 754 | } |
| 755 | if ((bigIcon == NULL) || ((images[i].width > bigIcon->width) && (images[i].height > bigIcon->height))) bigIcon = &images[i]; |
| 756 | if ((smallIcon == NULL) || ((images[i].width < smallIcon->width) && (images[i].height > smallIcon->height))) smallIcon = &images[i]; |
| 757 | } |
| 758 | |
| 759 | if (smallIcon != NULL) RGFW_window_setIconEx(platform.window, (u8 *)smallIcon->data, smallIcon->width, smallIcon->height, RGFW_formatRGBA8, RGFW_iconWindow); |
| 760 | if (bigIcon != NULL) RGFW_window_setIconEx(platform.window, (u8 *)bigIcon->data, bigIcon->width, bigIcon->height, RGFW_formatRGBA8, RGFW_iconTaskbar); |
| 761 | } |
| 762 | } |
| 763 | |
| 764 | |
| 765 | void SetWindowTitle(const char *title) |
| 766 | { |
| 767 | RGFW_window_setName(platform.window, (char *)title); |
| 768 | CORE.Window.title = title; |
| 769 | } |
| 770 | |
| 771 | |
| 772 | void SetWindowPosition(int x, int y) |
| 773 | { |
| 774 | RGFW_window_move(platform.window, x, y); |
| 775 | } |
| 776 | |
| 777 | |
| 778 | void SetWindowMonitor(int monitor) |
| 779 | { |
| 780 | RGFW_window_moveToMonitor(platform.window, RGFW_getMonitors(NULL)[monitor]); |
| 781 | } |
| 782 | |
| 783 | |
| 784 | void SetWindowMinSize(int width, int height) |
| 785 | { |
| 786 | RGFW_window_setMinSize(platform.window, width, height); |
| 787 | CORE.Window.screenMin.width = width; |
| 788 | CORE.Window.screenMin.height = height; |
| 789 | } |
| 790 | |
| 791 | |
| 792 | void SetWindowMaxSize(int width, int height) |
| 793 | { |
| 794 | RGFW_window_setMaxSize(platform.window, width, height); |
| 795 | CORE.Window.screenMax.width = width; |
| 796 | CORE.Window.screenMax.height = height; |
| 797 | } |
| 798 | |
| 799 | |
| 800 | void SetWindowSize(int width, int height) |
| 801 | { |
| 802 | if (FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_HIGHDPI)) |
| 803 | { |
| 804 | CORE.Window.screen.width = width; |
| 805 | CORE.Window.screen.height = height; |
| 806 | |
| 807 | Vector2 scaleDpi = GetWindowScaleDPI(); |
| 808 | |
| 809 | #if defined(__APPLE__) |
| 810 | RGFW_monitor* currentMonitor = RGFW_window_getMonitor(platform.window); |
| 811 | CORE.Window.screenScale = MatrixScale(currentMonitor->pixelRatio, currentMonitor->pixelRatio, 1.0f); |
| 812 | |
| 813 | CORE.Window.render.width = CORE.Window.screen.width * currentMonitor->pixelRatio; |
| 814 | CORE.Window.render.height = CORE.Window.screen.height * currentMonitor->pixelRatio; |
| 815 | CORE.Window.currentFbo.width = CORE.Window.render.width; |
| 816 | CORE.Window.currentFbo.height = CORE.Window.render.height; |
| 817 | #else |
| 818 | SetMouseScale(1.0f/scaleDpi.x, 1.0f/scaleDpi.y); |
| 819 | CORE.Window.screenScale = MatrixScale(scaleDpi.x, scaleDpi.y, 1.0f); |
| 820 | #endif |
| 821 | |
| 822 | CORE.Window.currentFbo.width = CORE.Window.render.width; |
| 823 | CORE.Window.currentFbo.height = CORE.Window.render.height; |
| 824 | } |
| 825 | else |
| 826 | { |
| 827 | CORE.Window.screen.width = width; |
| 828 | CORE.Window.screen.height = height; |
| 829 | } |
| 830 | |
| 831 | if (!CORE.Window.usingFbo) |
| 832 | { |
| 833 | SetupViewport(CORE.Window.screen.width, CORE.Window.screen.height); |
| 834 | } |
| 835 | |
| 836 | RGFW_window_resize(platform.window, CORE.Window.screen.width, CORE.Window.screen.height); |
| 837 | } |
| 838 | |
| 839 | |
| 840 | void SetWindowOpacity(float opacity) |
| 841 | { |
| 842 | RGFW_window_setOpacity(platform.window, opacity); |
| 843 | } |
| 844 | |
| 845 | |
| 846 | void SetWindowFocused(void) |
| 847 | { |
| 848 | RGFW_window_focus(platform.window); |
| 849 | } |
| 850 | |
| 851 | |
| 852 | void *GetWindowHandle(void) |
| 853 | { |
| 854 | if (platform.window == NULL) return NULL; |
| 855 | |
| 856 | #if defined(RGFW_WASM) |
| 857 | return (void *)&platform.window->src.ctx; |
| 858 | #elif defined(RGFW_WAYLAND) |
| 859 | return (void *)platform.window->src.surface; |
| 860 | #else |
| 861 | return (void *)platform.window->src.window; |
| 862 | #endif |
| 863 | } |
| 864 | |
| 865 | |
| 866 | int GetMonitorCount(void) |
| 867 | { |
| 868 | size_t count = 0; |
| 869 | RGFW_getMonitors(&count); |
| 870 | |
| 871 | return count; |
| 872 | } |
| 873 | |
| 874 | |
| 875 | int GetCurrentMonitor(void) |
| 876 | { |
| 877 | RGFW_monitor **mons = RGFW_getMonitors(NULL); |
| 878 | RGFW_monitor *mon = NULL; |
| 879 | |
| 880 | if (platform.window) mon = RGFW_window_getMonitor(platform.window); |
| 881 | else mon = RGFW_getPrimaryMonitor(); |
| 882 | |
| 883 | for (int i = 0; i < 6; i++) |
| 884 | { |
| 885 | if ((mons[i]->x == mon->x) && (mons[i]->y == mon->y)) return i; |
| 886 | } |
| 887 | |
| 888 | return 0; |
| 889 | } |
| 890 | |
| 891 | |
| 892 | Vector2 GetMonitorPosition(int monitor) |
| 893 | { |
| 894 | RGFW_monitor **mons = RGFW_getMonitors(NULL); |
| 895 | |
| 896 | return (Vector2){ (float)mons[monitor]->x, (float)mons[monitor]->y }; |
| 897 | } |
| 898 | |
| 899 | |
| 900 | int GetMonitorWidth(int monitor) |
| 901 | { |
| 902 | RGFW_monitor **mons = RGFW_getMonitors(NULL); |
| 903 | |
| 904 | return mons[monitor]->mode.w; |
| 905 | } |
| 906 | |
| 907 | |
| 908 | int GetMonitorHeight(int monitor) |
| 909 | { |
| 910 | RGFW_monitor **mons = RGFW_getMonitors(NULL); |
| 911 | |
| 912 | return mons[monitor]->mode.h; |
| 913 | } |
| 914 | |
| 915 | |
| 916 | int GetMonitorPhysicalWidth(int monitor) |
| 917 | { |
| 918 | RGFW_monitor **mons = RGFW_getMonitors(NULL); |
| 919 | |
| 920 | return mons[monitor]->physW; |
| 921 | } |
| 922 | |
| 923 | |
| 924 | int GetMonitorPhysicalHeight(int monitor) |
| 925 | { |
| 926 | RGFW_monitor **mons = RGFW_getMonitors(NULL); |
| 927 | |
| 928 | return (int)mons[monitor]->physH; |
| 929 | } |
| 930 | |
| 931 | |
| 932 | int GetMonitorRefreshRate(int monitor) |
| 933 | { |
| 934 | RGFW_monitor **mons = RGFW_getMonitors(NULL); |
| 935 | |
| 936 | return (int)mons[monitor]->mode.refreshRate; |
| 937 | } |
| 938 | |
| 939 | |
| 940 | const char *GetMonitorName(int monitor) |
| 941 | { |
| 942 | RGFW_monitor **mons = RGFW_getMonitors(NULL); |
| 943 | |
| 944 | return mons[monitor]->name; |
| 945 | } |
| 946 | |
| 947 | |
| 948 | Vector2 GetWindowPosition(void) |
| 949 | { |
| 950 | if (platform.window == NULL) |
| 951 | { |
| 952 | return (Vector2){ 0.0f, 0.0f }; |
| 953 | } |
| 954 | |
| 955 | if (RGFW_window_getPosition(platform.window, &platform.window->x, &platform.window->y)) { |
| 956 | return (Vector2){ (float)platform.window->x, (float)platform.window->y }; |
| 957 | } |
| 958 | |
| 959 | return (Vector2){ 0.0f, 0.0f }; |
| 960 | } |
| 961 | |
| 962 | |
| 963 | Vector2 GetWindowScaleDPI(void) |
| 964 | { |
| 965 | RGFW_monitor *monitor = NULL; |
| 966 | |
| 967 | if (platform.window) monitor = RGFW_window_getMonitor(platform.window); |
| 968 | else monitor = RGFW_getPrimaryMonitor(); |
| 969 | |
| 970 | #if defined(__APPLE__) |
| 971 | |
| 972 | |
| 973 | return (Vector2){ 1.0f/monitor->scaleX, 1.0f/monitor->scaleX }; |
| 974 | #else |
| 975 | |
| 976 | return (Vector2){ monitor->scaleX, monitor->scaleX }; |
| 977 | #endif |
| 978 | } |
| 979 | |
| 980 | |
| 981 | |
| 982 | float GetMonitorPixelRatio(void) |
| 983 | { |
| 984 | RGFW_monitor *monitor = NULL; |
| 985 | |
| 986 | if (platform.window) monitor = RGFW_window_getMonitor(platform.window); |
| 987 | else monitor = RGFW_getPrimaryMonitor(); |
| 988 | |
| 989 | return monitor->pixelRatio; |
| 990 | } |
| 991 | |
| 992 | |
| 993 | void SetClipboardText(const char *text) |
| 994 | { |
| 995 | |
| 996 | RGFW_writeClipboard(text, strlen(text)+1); |
| 997 | } |
| 998 | |
| 999 | |
| 1000 | |
| 1001 | const char *GetClipboardText(void) |
| 1002 | { |
| 1003 | return RGFW_readClipboard(NULL); |
| 1004 | } |
| 1005 | |
| 1006 | #if SUPPORT_CLIPBOARD_IMAGE |
| 1007 | #if defined(_WIN32) |
| 1008 | #define WIN32_CLIPBOARD_IMPLEMENTATION |
| 1009 | #define WINUSER_ALREADY_INCLUDED |
| 1010 | #define WINBASE_ALREADY_INCLUDED |
| 1011 | #define WINGDI_ALREADY_INCLUDED |
| 1012 | #include "../external/win32_clipboard.h" |
| 1013 | #elif defined(__linux__) && defined(DRGFW_X11) |
| 1014 | #include <X11/Xlib.h> |
| 1015 | #include <X11/Xatom.h> |
| 1016 | #endif |
| 1017 | #endif |
| 1018 | |
| 1019 | |
| 1020 | Image GetClipboardImage(void) |
| 1021 | { |
| 1022 | Image image = { 0 }; |
| 1023 | |
| 1024 | #if SUPPORT_CLIPBOARD_IMAGE && SUPPORT_MODULE_RTEXTURES |
| 1025 | #if defined(_WIN32) |
| 1026 | |
| 1027 | unsigned long long int dataSize = 0; |
| 1028 | void *fileData = NULL; |
| 1029 | |
| 1030 | int width = 0; |
| 1031 | int height = 0; |
| 1032 | fileData = (void *)Win32GetClipboardImageData(&width, &height, &dataSize); |
| 1033 | |
| 1034 | if (fileData == NULL) TRACELOG(LOG_WARNING, "Clipboard image: Couldn't get clipboard data"); |
| 1035 | else image = LoadImageFromMemory(".bmp", (const unsigned char *)fileData, dataSize); |
| 1036 | |
| 1037 | #elif defined(__linux__) && defined(DRGFW_X11) |
| 1038 | |
| 1039 | |
| 1040 | Display *dpy = XOpenDisplay(NULL); |
| 1041 | if (!dpy) return image; |
| 1042 | |
| 1043 | Window root = DefaultRootWindow(dpy); |
| 1044 | Window win = XCreateSimpleWindow( |
| 1045 | dpy, |
| 1046 | root, |
| 1047 | 0, 0, |
| 1048 | 1, 1, |
| 1049 | 0, |
| 1050 | 0, |
| 1051 | 0 |
| 1052 | ); |
| 1053 | |
| 1054 | Atom clipboard = XInternAtom(dpy, "CLIPBOARD", False); |
| 1055 | Atom targetType = XInternAtom(dpy, "image/png", False); |
| 1056 | Atom property = XInternAtom(dpy, "RAYLIB_CLIPBOARD_MANAGER", False); |
| 1057 | |
| 1058 | |
| 1059 | XConvertSelection(dpy, clipboard, targetType, property, win, CurrentTime); |
| 1060 | |
| 1061 | |
| 1062 | XEvent ev = { 0 }; |
| 1063 | XNextEvent(dpy, &ev); |
| 1064 | |
| 1065 | Atom actualType = { 0 }; |
| 1066 | int actualFormat = 0; |
| 1067 | unsigned long nitems = 0; |
| 1068 | unsigned long bytesAfter = 0; |
| 1069 | unsigned char *data = NULL; |
| 1070 | |
| 1071 | |
| 1072 | XGetWindowProperty(dpy, win, property, 0, ~0L, False, AnyPropertyType, |
| 1073 | &actualType, &actualFormat, &nitems, &bytesAfter, &data); |
| 1074 | |
| 1075 | if (data != NULL) |
| 1076 | { |
| 1077 | image = LoadImageFromMemory(".png", data, (int)nitems); |
| 1078 | XFree(data); |
| 1079 | } |
| 1080 | |
| 1081 | XDestroyWindow(dpy, win); |
| 1082 | XCloseDisplay(dpy); |
| 1083 | #else |
| 1084 | TRACELOG(LOG_WARNING, "Clipboard image: PLATFORM_DESKTOP_RGFW doesn't implement GetClipboardImage() for this OS"); |
| 1085 | #endif |
| 1086 | #else |
| 1087 | TRACELOG(LOG_WARNING, "Clipboard image: SUPPORT_CLIPBOARD_IMAGE requires SUPPORT_MODULE_RTEXTURES to work properly"); |
| 1088 | #endif |
| 1089 | |
| 1090 | return image; |
| 1091 | } |
| 1092 | |
| 1093 | |
| 1094 | void ShowCursor(void) |
| 1095 | { |
| 1096 | RGFW_window_showMouse(platform.window, true); |
| 1097 | CORE.Input.Mouse.cursorHidden = false; |
| 1098 | } |
| 1099 | |
| 1100 | |
| 1101 | void HideCursor(void) |
| 1102 | { |
| 1103 | RGFW_window_showMouse(platform.window, false); |
| 1104 | CORE.Input.Mouse.cursorHidden = true; |
| 1105 | } |
| 1106 | |
| 1107 | |
| 1108 | void EnableCursor(void) |
| 1109 | { |
| 1110 | RGFW_window_captureRawMouse(platform.window, false); |
| 1111 | |
| 1112 | |
| 1113 | SetMousePosition(CORE.Window.screen.width/2, CORE.Window.screen.height/2); |
| 1114 | ShowCursor(); |
| 1115 | |
| 1116 | CORE.Input.Mouse.cursorLocked = true; |
| 1117 | } |
| 1118 | |
| 1119 | |
| 1120 | void DisableCursor(void) |
| 1121 | { |
| 1122 | RGFW_window_captureRawMouse(platform.window, true); |
| 1123 | HideCursor(); |
| 1124 | |
| 1125 | CORE.Input.Mouse.cursorLocked = true; |
| 1126 | } |
| 1127 | |
| 1128 | |
| 1129 | void SwapScreenBuffer(void) |
| 1130 | { |
| 1131 | #if defined(GRAPHICS_API_OPENGL_SOFTWARE) |
| 1132 | { |
| 1133 | if (platform.surface) |
| 1134 | { |
| 1135 | |
| 1136 | swReadPixels(0, 0, platform.surfaceWidth, platform.surfaceHeight, SW_RGBA, SW_UNSIGNED_BYTE, platform.surfacePixels); |
| 1137 | |
| 1138 | |
| 1139 | #if defined(__APPLE__) |
| 1140 | unsigned char temp = 0; |
| 1141 | unsigned char *p = NULL; |
| 1142 | for (int i = 0; i < (platform.surfaceWidth * platform.surfaceHeight); i += 1) |
| 1143 | { |
| 1144 | p = platform.surfacePixels + (i * 4); |
| 1145 | temp = p[0]; |
| 1146 | p[0] = p[2]; |
| 1147 | p[2] = temp; |
| 1148 | } |
| 1149 | #endif |
| 1150 | |
| 1151 | |
| 1152 | RGFW_window_blitSurface(platform.window, platform.surface); |
| 1153 | } |
| 1154 | } |
| 1155 | #else |
| 1156 | { |
| 1157 | RGFW_window_swapBuffers_OpenGL(platform.window); |
| 1158 | } |
| 1159 | #endif |
| 1160 | } |
| 1161 | |
| 1162 | |
| 1163 | |
| 1164 | |
| 1165 | |
| 1166 | |
| 1167 | double GetTime(void) |
| 1168 | { |
| 1169 | |
| 1170 | double baseTime = (double)CORE.Time.base*1e-9; |
| 1171 | double time = get_time_seconds() - baseTime; |
| 1172 | |
| 1173 | return time; |
| 1174 | } |
| 1175 | |
| 1176 | |
| 1177 | |
| 1178 | |
| 1179 | void OpenURL(const char *url) |
| 1180 | { |
| 1181 | |
| 1182 | if (strchr(url, '\'') != NULL) TRACELOG(LOG_WARNING, "SYSTEM: Provided URL could be potentially malicious, avoid [\'] character"); |
| 1183 | else |
| 1184 | { |
| 1185 | char *cmd = (char *)RL_CALLOC(strlen(url) + 32, sizeof(char)); |
| 1186 | #if defined(_WIN32) |
| 1187 | sprintf(cmd, "explorer \"%s\"", url); |
| 1188 | #endif |
| 1189 | #if defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__) |
| 1190 | sprintf(cmd, "xdg-open '%s'", url); |
| 1191 | #endif |
| 1192 | #if defined(__APPLE__) |
| 1193 | sprintf(cmd, "open '%s'", url); |
| 1194 | #endif |
| 1195 | int result = system(cmd); |
| 1196 | if (result == -1) TRACELOG(LOG_WARNING, "OpenURL() child process could not be created"); |
| 1197 | RL_FREE(cmd); |
| 1198 | } |
| 1199 | } |
| 1200 | |
| 1201 | |
| 1202 | |
| 1203 | |
| 1204 | |
| 1205 | |
| 1206 | int SetGamepadMappings(const char *mappings) |
| 1207 | { |
| 1208 | return mg_update_gamepad_mappings(&platform.minigamepad, mappings); |
| 1209 | } |
| 1210 | |
| 1211 | |
| 1212 | void SetGamepadVibration(int gamepad, float leftMotor, float rightMotor, float duration) |
| 1213 | { |
| 1214 | TRACELOG(LOG_WARNING, "SetGamepadVibration() unsupported on target platform"); |
| 1215 | } |
| 1216 | |
| 1217 | |
| 1218 | void SetMousePosition(int x, int y) |
| 1219 | { |
| 1220 | RGFW_window_moveMouse(platform.window, x, y); |
| 1221 | CORE.Input.Mouse.currentPosition = (Vector2){ (float)x, (float)y }; |
| 1222 | CORE.Input.Mouse.previousPosition = CORE.Input.Mouse.currentPosition; |
| 1223 | } |
| 1224 | |
| 1225 | |
| 1226 | void SetMouseCursor(int cursor) |
| 1227 | { |
| 1228 | RGFW_window_setMouseStandard(platform.window, cursor); |
| 1229 | } |
| 1230 | |
| 1231 | |
| 1232 | const char *GetKeyName(int key) |
| 1233 | { |
| 1234 | TRACELOG(LOG_WARNING, "GetKeyName() unsupported on target platform"); |
| 1235 | |
| 1236 | return ""; |
| 1237 | } |
| 1238 | |
| 1239 | |
| 1240 | void PollInputEvents(void) |
| 1241 | { |
| 1242 | #if SUPPORT_GESTURES_SYSTEM |
| 1243 | |
| 1244 | |
| 1245 | UpdateGestures(); |
| 1246 | #endif |
| 1247 | |
| 1248 | |
| 1249 | CORE.Input.Keyboard.keyPressedQueueCount = 0; |
| 1250 | CORE.Input.Keyboard.charPressedQueueCount = 0; |
| 1251 | |
| 1252 | |
| 1253 | CORE.Input.Mouse.currentWheelMove.x = 0; |
| 1254 | CORE.Input.Mouse.currentWheelMove.y = 0; |
| 1255 | |
| 1256 | |
| 1257 | |
| 1258 | |
| 1259 | for (int i = 0; i < MAX_GAMEPADS; i++) |
| 1260 | { |
| 1261 | |
| 1262 | if (CORE.Input.Gamepad.ready[i]) |
| 1263 | { |
| 1264 | |
| 1265 | for (int k = 0; k < MAX_GAMEPAD_BUTTONS; k++) |
| 1266 | { |
| 1267 | CORE.Input.Gamepad.previousButtonState[i][k] = CORE.Input.Gamepad.currentButtonState[i][k]; |
| 1268 | } |
| 1269 | } |
| 1270 | } |
| 1271 | |
| 1272 | |
| 1273 | for (int i = 0; i < MAX_TOUCH_POINTS; i++) CORE.Input.Touch.previousTouchState[i] = CORE.Input.Touch.currentTouchState[i]; |
| 1274 | |
| 1275 | |
| 1276 | CORE.Input.Touch.position[0] = CORE.Input.Mouse.currentPosition; |
| 1277 | |
| 1278 | int touchAction = -1; |
| 1279 | bool realTouch = false; |
| 1280 | |
| 1281 | |
| 1282 | |
| 1283 | for (int i = 0; i < MAX_KEYBOARD_KEYS; i++) |
| 1284 | { |
| 1285 | CORE.Input.Keyboard.previousKeyState[i] = CORE.Input.Keyboard.currentKeyState[i]; |
| 1286 | CORE.Input.Keyboard.keyRepeatInFrame[i] = 0; |
| 1287 | } |
| 1288 | |
| 1289 | |
| 1290 | for (int i = 0; i < MAX_MOUSE_BUTTONS; i++) CORE.Input.Mouse.previousButtonState[i] = CORE.Input.Mouse.currentButtonState[i]; |
| 1291 | |
| 1292 | |
| 1293 | |
| 1294 | CORE.Window.resizedLastFrame = false; |
| 1295 | |
| 1296 | CORE.Input.Mouse.previousPosition = CORE.Input.Mouse.currentPosition; |
| 1297 | if (RGFW_window_isCaptured(platform.window)) |
| 1298 | { |
| 1299 | CORE.Input.Mouse.previousPosition = (Vector2){ 0.0f, 0.0f }; |
| 1300 | CORE.Input.Mouse.currentPosition = (Vector2){ 0.0f, 0.0f }; |
| 1301 | } |
| 1302 | else |
| 1303 | { |
| 1304 | CORE.Input.Mouse.previousPosition = CORE.Input.Mouse.currentPosition; |
| 1305 | } |
| 1306 | |
| 1307 | if ((CORE.Window.eventWaiting) || (IsWindowState(FLAG_WINDOW_MINIMIZED) && !IsWindowState(FLAG_WINDOW_ALWAYS_RUN))) |
| 1308 | { |
| 1309 | CORE.Time.previous = GetTime(); |
| 1310 | } |
| 1311 | |
| 1312 | RGFW_event rgfw_event; |
| 1313 | while (RGFW_window_checkEvent(platform.window, &rgfw_event)) |
| 1314 | { |
| 1315 | |
| 1316 | switch (rgfw_event.type) |
| 1317 | { |
| 1318 | case RGFW_mouseEnter: CORE.Input.Mouse.cursorOnScreen = true; break; |
| 1319 | case RGFW_mouseLeave: CORE.Input.Mouse.cursorOnScreen = false; break; |
| 1320 | case RGFW_quit: |
| 1321 | RGFW_window_setShouldClose(platform.window, true); |
| 1322 | return; |
| 1323 | case RGFW_dataDrop: |
| 1324 | { |
| 1325 | for (int i = 0; i < rgfw_event.drop.count; i++) |
| 1326 | { |
| 1327 | if (CORE.Window.dropFileCount == 0) |
| 1328 | { |
| 1329 | |
| 1330 | |
| 1331 | |
| 1332 | CORE.Window.dropFilepaths = (char **)RL_CALLOC(1024, sizeof(char *)); |
| 1333 | |
| 1334 | CORE.Window.dropFilepaths[CORE.Window.dropFileCount] = (char *)RL_CALLOC(MAX_FILEPATH_LENGTH, sizeof(char)); |
| 1335 | strcpy(CORE.Window.dropFilepaths[CORE.Window.dropFileCount], rgfw_event.drop.files[i]); |
| 1336 | |
| 1337 | CORE.Window.dropFileCount++; |
| 1338 | } |
| 1339 | else if (CORE.Window.dropFileCount < 1024) |
| 1340 | { |
| 1341 | CORE.Window.dropFilepaths[CORE.Window.dropFileCount] = (char *)RL_CALLOC(MAX_FILEPATH_LENGTH, sizeof(char)); |
| 1342 | strcpy(CORE.Window.dropFilepaths[CORE.Window.dropFileCount], rgfw_event.drop.files[i]); |
| 1343 | |
| 1344 | CORE.Window.dropFileCount++; |
| 1345 | } |
| 1346 | else TRACELOG(LOG_WARNING, "FILE: Maximum drag and drop files at once is limited to 1024 files!"); |
| 1347 | } |
| 1348 | } break; |
| 1349 | |
| 1350 | |
| 1351 | case RGFW_windowResized: |
| 1352 | { |
| 1353 | |
| 1354 | CORE.Window.resizedLastFrame = true; |
| 1355 | |
| 1356 | #if defined(__APPLE__) |
| 1357 | if (FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_HIGHDPI)) |
| 1358 | { |
| 1359 | RGFW_monitor* currentMonitor = RGFW_window_getMonitor(platform.window); |
| 1360 | SetupViewport(platform.window->w * currentMonitor->pixelRatio, platform.window->h * currentMonitor->pixelRatio); |
| 1361 | CORE.Window.screenScale = MatrixScale(currentMonitor->pixelRatio, currentMonitor->pixelRatio, 1.0f); |
| 1362 | |
| 1363 | CORE.Window.screen.width = platform.window->w; |
| 1364 | CORE.Window.screen.height = platform.window->h; |
| 1365 | CORE.Window.render.width = CORE.Window.screen.width * currentMonitor->pixelRatio; |
| 1366 | CORE.Window.render.height = CORE.Window.screen.height * currentMonitor->pixelRatio; |
| 1367 | } |
| 1368 | else |
| 1369 | { |
| 1370 | SetupViewport(platform.window->w, platform.window->h); |
| 1371 | CORE.Window.screen.width = platform.window->w; |
| 1372 | CORE.Window.screen.height = platform.window->h; |
| 1373 | CORE.Window.render.width = CORE.Window.screen.width; |
| 1374 | CORE.Window.render.height = CORE.Window.screen.height; |
| 1375 | } |
| 1376 | |
| 1377 | CORE.Window.currentFbo.width = CORE.Window.render.width; |
| 1378 | CORE.Window.currentFbo.height = CORE.Window.render.height; |
| 1379 | #elif defined(PLATFORM_WEB_RGFW) |
| 1380 | |
| 1381 | #else |
| 1382 | SetupViewport(platform.window->w, platform.window->h); |
| 1383 | |
| 1384 | |
| 1385 | if (FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_HIGHDPI)) |
| 1386 | { |
| 1387 | Vector2 scaleDpi = GetWindowScaleDPI(); |
| 1388 | CORE.Window.screen.width = (int)(platform.window->w/scaleDpi.x); |
| 1389 | CORE.Window.screen.height = (int)(platform.window->h/scaleDpi.y); |
| 1390 | CORE.Window.screenScale = MatrixScale(scaleDpi.x, scaleDpi.y, 1.0f); |
| 1391 | |
| 1392 | |
| 1393 | |
| 1394 | } |
| 1395 | else |
| 1396 | { |
| 1397 | CORE.Window.screen.width = platform.window->w; |
| 1398 | CORE.Window.screen.height = platform.window->h; |
| 1399 | } |
| 1400 | |
| 1401 | CORE.Window.currentFbo.width = CORE.Window.screen.width; |
| 1402 | CORE.Window.currentFbo.height = CORE.Window.screen.height; |
| 1403 | #endif |
| 1404 | |
| 1405 | #if defined(GRAPHICS_API_OPENGL_SOFTWARE) |
| 1406 | #if defined(__APPLE__) |
| 1407 | RGFW_monitor* currentMonitor = RGFW_window_getMonitor(platform.window); |
| 1408 | CORE.Window.screenScale = MatrixScale(currentMonitor->pixelRatio, currentMonitor->pixelRatio, 1.0f); |
| 1409 | SetupViewport(platform.window->w * currentMonitor->pixelRatio, platform.window->h * currentMonitor->pixelRatio); |
| 1410 | |
| 1411 | CORE.Window.render.width = CORE.Window.screen.width * currentMonitor->pixelRatio; |
| 1412 | CORE.Window.render.height = CORE.Window.screen.height * currentMonitor->pixelRatio; |
| 1413 | CORE.Window.currentFbo.width = CORE.Window.render.width; |
| 1414 | CORE.Window.currentFbo.height = CORE.Window.render.height; |
| 1415 | #endif |
| 1416 | platform.surfaceWidth = CORE.Window.currentFbo.width; |
| 1417 | platform.surfaceHeight = CORE.Window.currentFbo.height; |
| 1418 | |
| 1419 | |
| 1420 | if (FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_HIGHDPI)) |
| 1421 | { |
| 1422 | Vector2 scaleDpi = GetWindowScaleDPI(); |
| 1423 | platform.surfaceWidth *= scaleDpi.x; |
| 1424 | platform.surfaceHeight *= scaleDpi.y; |
| 1425 | } |
| 1426 | |
| 1427 | if (platform.surfacePixels != NULL) |
| 1428 | { |
| 1429 | RL_FREE(platform.surfacePixels); |
| 1430 | platform.surfacePixels = RL_MALLOC(platform.surfaceWidth * platform.surfaceHeight * 4); |
| 1431 | } |
| 1432 | |
| 1433 | if (platform.surface != NULL) |
| 1434 | { |
| 1435 | RGFW_surface_free(platform.surface); |
| 1436 | platform.surface = RGFW_window_createSurface(platform.window, platform.surfacePixels, platform.surfaceWidth, platform.surfaceHeight, RGFW_formatBGRA8); |
| 1437 | swResize(platform.surfaceWidth, platform.surfaceHeight); |
| 1438 | } |
| 1439 | #endif |
| 1440 | } break; |
| 1441 | case RGFW_windowMaximized: |
| 1442 | { |
| 1443 | FLAG_SET(CORE.Window.flags, FLAG_WINDOW_MAXIMIZED); |
| 1444 | } break; |
| 1445 | case RGFW_windowMinimized: |
| 1446 | { |
| 1447 | FLAG_SET(CORE.Window.flags, FLAG_WINDOW_MINIMIZED); |
| 1448 | } break; |
| 1449 | case RGFW_windowRestored: |
| 1450 | { |
| 1451 | if (RGFW_window_isMaximized(platform.window)) |
| 1452 | FLAG_CLEAR(CORE.Window.flags, FLAG_WINDOW_MAXIMIZED); |
| 1453 | if (RGFW_window_isMinimized(platform.window)) |
| 1454 | FLAG_CLEAR(CORE.Window.flags, FLAG_WINDOW_MINIMIZED); |
| 1455 | } break; |
| 1456 | case RGFW_windowMoved: |
| 1457 | { |
| 1458 | CORE.Window.position.x = platform.window->x; |
| 1459 | CORE.Window.position.y = platform.window->x; |
| 1460 | } break; |
| 1461 | |
| 1462 | |
| 1463 | case RGFW_keyPressed: |
| 1464 | { |
| 1465 | KeyboardKey key = ConvertScancodeToKey(rgfw_event.key.value); |
| 1466 | if (key != KEY_NULL) |
| 1467 | { |
| 1468 | |
| 1469 | if ((CORE.Input.Keyboard.currentKeyState[key] == 0) && (CORE.Input.Keyboard.keyPressedQueueCount < MAX_KEY_PRESSED_QUEUE)) |
| 1470 | { |
| 1471 | CORE.Input.Keyboard.keyPressedQueue[CORE.Input.Keyboard.keyPressedQueueCount] = key; |
| 1472 | CORE.Input.Keyboard.keyPressedQueueCount++; |
| 1473 | } |
| 1474 | |
| 1475 | CORE.Input.Keyboard.currentKeyState[key] = 1; |
| 1476 | |
| 1477 | if (CORE.Input.Keyboard.currentKeyState[CORE.Input.Keyboard.exitKey]) RGFW_window_setShouldClose(platform.window, true); |
| 1478 | } |
| 1479 | } break; |
| 1480 | case RGFW_keyReleased: |
| 1481 | { |
| 1482 | KeyboardKey key = ConvertScancodeToKey(rgfw_event.key.value); |
| 1483 | if (key != KEY_NULL) CORE.Input.Keyboard.currentKeyState[key] = 0; |
| 1484 | } break; |
| 1485 | |
| 1486 | case RGFW_keyChar: |
| 1487 | { |
| 1488 | |
| 1489 | |
| 1490 | if (CORE.Input.Keyboard.charPressedQueueCount < MAX_CHAR_PRESSED_QUEUE) |
| 1491 | { |
| 1492 | |
| 1493 | CORE.Input.Keyboard.charPressedQueue[CORE.Input.Keyboard.charPressedQueueCount] = rgfw_event.keyChar.value; |
| 1494 | CORE.Input.Keyboard.charPressedQueueCount++; |
| 1495 | } |
| 1496 | } break; |
| 1497 | |
| 1498 | |
| 1499 | case RGFW_mouseScroll: |
| 1500 | { |
| 1501 | CORE.Input.Mouse.currentWheelMove.x += rgfw_event.scroll.x; |
| 1502 | CORE.Input.Mouse.currentWheelMove.y += rgfw_event.scroll.y; |
| 1503 | } break; |
| 1504 | case RGFW_mouseButtonPressed: |
| 1505 | { |
| 1506 | int btn = rgfw_event.button.value; |
| 1507 | if (btn == RGFW_mouseLeft) btn = 1; |
| 1508 | else if (btn == RGFW_mouseRight) btn = 2; |
| 1509 | else if (btn == RGFW_mouseMiddle) btn = 3; |
| 1510 | |
| 1511 | CORE.Input.Mouse.currentButtonState[btn - 1] = 1; |
| 1512 | CORE.Input.Touch.currentTouchState[btn - 1] = 1; |
| 1513 | |
| 1514 | touchAction = 1; |
| 1515 | } break; |
| 1516 | case RGFW_mouseButtonReleased: |
| 1517 | { |
| 1518 | int btn = rgfw_event.button.value; |
| 1519 | if (btn == RGFW_mouseLeft) btn = 1; |
| 1520 | else if (btn == RGFW_mouseRight) btn = 2; |
| 1521 | else if (btn == RGFW_mouseMiddle) btn = 3; |
| 1522 | |
| 1523 | CORE.Input.Mouse.currentButtonState[btn - 1] = 0; |
| 1524 | CORE.Input.Touch.currentTouchState[btn - 1] = 0; |
| 1525 | |
| 1526 | touchAction = 0; |
| 1527 | } break; |
| 1528 | case RGFW_mousePosChanged: |
| 1529 | { |
| 1530 | float mouseX = 0.0f; |
| 1531 | float mouseY = 0.0f; |
| 1532 | if (RGFW_window_isCaptured(platform.window)) |
| 1533 | { |
| 1534 | mouseX = (float)rgfw_event.mouse.vecX; |
| 1535 | mouseY = (float)rgfw_event.mouse.vecY; |
| 1536 | } |
| 1537 | else |
| 1538 | { |
| 1539 | mouseX = (float)rgfw_event.mouse.x; |
| 1540 | mouseY = (float)rgfw_event.mouse.y; |
| 1541 | } |
| 1542 | |
| 1543 | #if defined(__EMSCRIPTEN__) |
| 1544 | double canvasWidth = 0.0; |
| 1545 | double canvasHeight = 0.0; |
| 1546 | emscripten_get_element_css_size("#canvas", &canvasWidth, &canvasHeight); |
| 1547 | mouseX *= ((float)GetScreenWidth()/(float)canvasWidth); |
| 1548 | mouseY *= ((float)GetScreenHeight()/(float)canvasHeight); |
| 1549 | #endif |
| 1550 | if (RGFW_window_isCaptured(platform.window)) |
| 1551 | { |
| 1552 | CORE.Input.Mouse.currentPosition.x += mouseX; |
| 1553 | CORE.Input.Mouse.currentPosition.y += mouseY; |
| 1554 | } |
| 1555 | else |
| 1556 | { |
| 1557 | CORE.Input.Mouse.currentPosition.x = mouseX; |
| 1558 | CORE.Input.Mouse.currentPosition.y = mouseY; |
| 1559 | } |
| 1560 | |
| 1561 | CORE.Input.Touch.position[0] = CORE.Input.Mouse.currentPosition; |
| 1562 | touchAction = 2; |
| 1563 | } break; |
| 1564 | default: break; |
| 1565 | } |
| 1566 | |
| 1567 | #if SUPPORT_GESTURES_SYSTEM |
| 1568 | if (touchAction > -1) |
| 1569 | { |
| 1570 | |
| 1571 | GestureEvent gestureEvent = { 0 }; |
| 1572 | |
| 1573 | |
| 1574 | gestureEvent.touchAction = touchAction; |
| 1575 | |
| 1576 | |
| 1577 | gestureEvent.pointId[0] = 0; |
| 1578 | |
| 1579 | |
| 1580 | gestureEvent.pointCount = 1; |
| 1581 | |
| 1582 | |
| 1583 | if (touchAction == 2 || realTouch) gestureEvent.position[0] = CORE.Input.Touch.position[0]; |
| 1584 | else gestureEvent.position[0] = GetMousePosition(); |
| 1585 | |
| 1586 | |
| 1587 | gestureEvent.position[0].x /= (float)GetScreenWidth(); |
| 1588 | gestureEvent.position[0].y /= (float)GetScreenHeight(); |
| 1589 | |
| 1590 | |
| 1591 | ProcessGestureEvent(gestureEvent); |
| 1592 | |
| 1593 | touchAction = -1; |
| 1594 | } |
| 1595 | #endif |
| 1596 | } |
| 1597 | |
| 1598 | |
| 1599 | mg_event gamepad_event; |
| 1600 | while (mg_gamepads_check_event(&platform.minigamepad, &gamepad_event)) { |
| 1601 | int gamepadIndex = gamepad_event.gamepad->index; |
| 1602 | switch (gamepad_event.type) { |
| 1603 | case MG_EVENT_BUTTON_PRESS: |
| 1604 | { |
| 1605 | int button = mg_buttonConvertTable[gamepad_event.button]; |
| 1606 | if (button >= 0) |
| 1607 | { |
| 1608 | CORE.Input.Gamepad.currentButtonState[gamepadIndex][button] = 1; |
| 1609 | CORE.Input.Gamepad.lastButtonPressed = button; |
| 1610 | } |
| 1611 | } break; |
| 1612 | case MG_EVENT_BUTTON_RELEASE: |
| 1613 | { |
| 1614 | int button = mg_buttonConvertTable[gamepad_event.button]; |
| 1615 | if (button >= 0) |
| 1616 | { |
| 1617 | CORE.Input.Gamepad.currentButtonState[gamepadIndex][button] = 0; |
| 1618 | if (CORE.Input.Gamepad.lastButtonPressed == button) CORE.Input.Gamepad.lastButtonPressed = 0; |
| 1619 | } |
| 1620 | } break; |
| 1621 | case MG_EVENT_AXIS_MOVE: |
| 1622 | { |
| 1623 | int axis = mg_axisConvertTable[gamepad_event.axis]; |
| 1624 | |
| 1625 | switch (axis) { |
| 1626 | case GAMEPAD_AXIS_LEFT_X: |
| 1627 | case GAMEPAD_AXIS_LEFT_Y: |
| 1628 | case GAMEPAD_AXIS_RIGHT_X: |
| 1629 | case GAMEPAD_AXIS_RIGHT_Y: |
| 1630 | CORE.Input.Gamepad.axisState[gamepadIndex][axis] = platform.minigamepad.gamepads[gamepadIndex].axes[gamepad_event.axis].value; |
| 1631 | break; |
| 1632 | case GAMEPAD_AXIS_LEFT_TRIGGER: |
| 1633 | case GAMEPAD_AXIS_RIGHT_TRIGGER: |
| 1634 | CORE.Input.Gamepad.axisState[gamepadIndex][axis] = platform.minigamepad.gamepads[gamepadIndex].axes[gamepad_event.axis].value; |
| 1635 | |
| 1636 | |
| 1637 | int button = (axis == GAMEPAD_AXIS_LEFT_TRIGGER) ? GAMEPAD_BUTTON_LEFT_TRIGGER_2 : GAMEPAD_BUTTON_RIGHT_TRIGGER_2; |
| 1638 | int pressed = (platform.minigamepad.gamepads[gamepadIndex].axes[gamepad_event.axis].value >= 1.0f); |
| 1639 | |
| 1640 | CORE.Input.Gamepad.currentButtonState[gamepadIndex][button] = pressed; |
| 1641 | if (pressed) CORE.Input.Gamepad.lastButtonPressed = button; |
| 1642 | else if (CORE.Input.Gamepad.lastButtonPressed == button) CORE.Input.Gamepad.lastButtonPressed = 0; |
| 1643 | break; |
| 1644 | } |
| 1645 | } break; |
| 1646 | case MG_EVENT_GAMEPAD_CONNECT: |
| 1647 | CORE.Input.Gamepad.ready[gamepadIndex] = true; |
| 1648 | CORE.Input.Gamepad.axisState[gamepadIndex][GAMEPAD_AXIS_LEFT_TRIGGER] = -1.0f; |
| 1649 | CORE.Input.Gamepad.axisState[gamepadIndex][GAMEPAD_AXIS_RIGHT_TRIGGER] = -1.0f; |
| 1650 | |
| 1651 | int axisCount = 0; |
| 1652 | for (int i = 0; i < MG_AXIS_COUNT; i += 1) { |
| 1653 | if (platform.minigamepad.gamepads[gamepadIndex].axes[i].supported) { |
| 1654 | axisCount += 1; |
| 1655 | } else { |
| 1656 | break; |
| 1657 | } |
| 1658 | } |
| 1659 | CORE.Input.Gamepad.axisCount[gamepadIndex] = axisCount; |
| 1660 | strcpy(CORE.Input.Gamepad.name[gamepadIndex], platform.minigamepad.gamepads[gamepadIndex].name); |
| 1661 | break; |
| 1662 | case MG_EVENT_GAMEPAD_DISCONNECT: |
| 1663 | CORE.Input.Gamepad.ready[gamepadIndex] = false; |
| 1664 | break; |
| 1665 | default: break; |
| 1666 | } |
| 1667 | } |
| 1668 | } |
| 1669 | |
| 1670 | |
| 1671 | |
| 1672 | |
| 1673 | |
| 1674 | |
| 1675 | int InitPlatform(void) |
| 1676 | { |
| 1677 | |
| 1678 | unsigned int flags = RGFW_windowCenter | RGFW_windowAllowDND; |
| 1679 | |
| 1680 | |
| 1681 | if (FLAG_IS_SET(CORE.Window.flags, FLAG_FULLSCREEN_MODE)) |
| 1682 | { |
| 1683 | FLAG_SET(flags, RGFW_windowFullscreen); |
| 1684 | } |
| 1685 | |
| 1686 | if (FLAG_IS_SET(CORE.Window.flags, FLAG_BORDERLESS_WINDOWED_MODE)) |
| 1687 | { |
| 1688 | FLAG_SET(flags, RGFW_windowedFullscreen); |
| 1689 | } |
| 1690 | |
| 1691 | if (FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_UNDECORATED)) FLAG_SET(flags, RGFW_windowNoBorder); |
| 1692 | if (!FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_RESIZABLE)) FLAG_SET(flags, RGFW_windowNoResize); |
| 1693 | if (FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_TRANSPARENT)) FLAG_SET(flags, RGFW_windowTransparent); |
| 1694 | if (FLAG_IS_SET(CORE.Window.flags, FLAG_FULLSCREEN_MODE)) FLAG_SET(flags, RGFW_windowFullscreen); |
| 1695 | if (FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_HIDDEN)) FLAG_SET(flags, RGFW_windowHide); |
| 1696 | if (FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_MAXIMIZED)) FLAG_SET(flags, RGFW_windowMaximize); |
| 1697 | |
| 1698 | |
| 1699 | |
| 1700 | |
| 1701 | RGFW_glHints* hints = RGFW_getGlobalHints_OpenGL(); |
| 1702 | if (rlGetVersion() == RL_OPENGL_21) |
| 1703 | { |
| 1704 | hints->major = 2; |
| 1705 | hints->minor = 1; |
| 1706 | } |
| 1707 | else if (rlGetVersion() == RL_OPENGL_33) |
| 1708 | { |
| 1709 | hints->major = 3; |
| 1710 | hints->minor = 3; |
| 1711 | } |
| 1712 | else if (rlGetVersion() == RL_OPENGL_43) |
| 1713 | { |
| 1714 | hints->major = 4; |
| 1715 | hints->minor = 3; |
| 1716 | } |
| 1717 | else if (rlGetVersion() == RL_OPENGL_SOFTWARE) |
| 1718 | { |
| 1719 | hints->major = 1; |
| 1720 | hints->minor = 1; |
| 1721 | hints->renderer = RGFW_glSoftware; |
| 1722 | } |
| 1723 | |
| 1724 | if (FLAG_IS_SET(CORE.Window.flags, FLAG_MSAA_4X_HINT)) hints->samples = 4; |
| 1725 | |
| 1726 | if (!FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_UNFOCUSED)) FLAG_SET(flags, RGFW_windowFocusOnShow | RGFW_windowFocus); |
| 1727 | |
| 1728 | if (FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_HIGHDPI)) |
| 1729 | { |
| 1730 | #if !defined(__APPLE__) |
| 1731 | CORE.Window.screen.width = CORE.Window.screen.width * GetWindowScaleDPI().x; |
| 1732 | CORE.Window.screen.height = CORE.Window.screen.height * GetWindowScaleDPI().y; |
| 1733 | #endif |
| 1734 | } |
| 1735 | |
| 1736 | RGFW_setGlobalHints_OpenGL(hints); |
| 1737 | platform.window = RGFW_createWindow((CORE.Window.title != 0)? CORE.Window.title : " ", 0, 0, CORE.Window.screen.width, CORE.Window.screen.height, flags | RGFW_windowOpenGL); |
| 1738 | |
| 1739 | #ifndef PLATFORM_WEB_RGFW |
| 1740 | i32 screenSizeWidth; |
| 1741 | i32 screenSizeHeight; |
| 1742 | RGFW_window_getSize(platform.window, &screenSizeWidth, &screenSizeHeight); |
| 1743 | CORE.Window.display.width = screenSizeWidth; |
| 1744 | CORE.Window.display.height = screenSizeHeight; |
| 1745 | #else |
| 1746 | CORE.Window.display.width = CORE.Window.screen.width; |
| 1747 | CORE.Window.display.height = CORE.Window.screen.height; |
| 1748 | #endif |
| 1749 | if (FLAG_IS_SET(CORE.Window.flags, FLAG_VSYNC_HINT)) RGFW_window_swapInterval_OpenGL(platform.window, 1); |
| 1750 | |
| 1751 | |
| 1752 | if (platform.window != NULL) |
| 1753 | { |
| 1754 | CORE.Window.ready = true; |
| 1755 | |
| 1756 | CORE.Window.render.width = CORE.Window.screen.width; |
| 1757 | CORE.Window.render.height = CORE.Window.screen.height; |
| 1758 | CORE.Window.currentFbo.width = CORE.Window.render.width; |
| 1759 | CORE.Window.currentFbo.height = CORE.Window.render.height; |
| 1760 | } |
| 1761 | else |
| 1762 | { |
| 1763 | TRACELOG(LOG_FATAL, "PLATFORM: Failed to initialize graphics device"); |
| 1764 | return -1; |
| 1765 | } |
| 1766 | |
| 1767 | |
| 1768 | |
| 1769 | RGFW_window_setExitKey(platform.window, RGFW_keyNULL); |
| 1770 | RGFW_window_makeCurrentWindow_OpenGL(platform.window); |
| 1771 | |
| 1772 | |
| 1773 | |
| 1774 | |
| 1775 | CORE.Window.position.x = platform.window->x; |
| 1776 | CORE.Window.position.y = platform.window->y; |
| 1777 | CORE.Window.render.width = CORE.Window.screen.width; |
| 1778 | CORE.Window.render.height = CORE.Window.screen.height; |
| 1779 | CORE.Window.currentFbo.width = CORE.Window.render.width; |
| 1780 | CORE.Window.currentFbo.height = CORE.Window.render.height; |
| 1781 | |
| 1782 | |
| 1783 | if (FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_HIGHDPI)) { |
| 1784 | Vector2 scaleDpi = GetWindowScaleDPI(); |
| 1785 | |
| 1786 | #if defined(__APPLE__) |
| 1787 | RGFW_monitor* currentMonitor = RGFW_window_getMonitor(platform.window); |
| 1788 | CORE.Window.screenScale = MatrixScale(currentMonitor->pixelRatio, currentMonitor->pixelRatio, 1.0f); |
| 1789 | |
| 1790 | CORE.Window.render.width = CORE.Window.screen.width * currentMonitor->pixelRatio; |
| 1791 | CORE.Window.render.height = CORE.Window.screen.height * currentMonitor->pixelRatio; |
| 1792 | CORE.Window.currentFbo.width = CORE.Window.render.width; |
| 1793 | CORE.Window.currentFbo.height = CORE.Window.render.height; |
| 1794 | #else |
| 1795 | SetMouseScale(1.0f/scaleDpi.x, 1.0f/scaleDpi.y); |
| 1796 | CORE.Window.screenScale = MatrixScale(scaleDpi.x, scaleDpi.y, 1.0f); |
| 1797 | CORE.Window.screen.width /= scaleDpi.x; |
| 1798 | CORE.Window.screen.height /= scaleDpi.y; |
| 1799 | #endif |
| 1800 | } |
| 1801 | |
| 1802 | #if defined(GRAPHICS_API_OPENGL_SOFTWARE) |
| 1803 | |
| 1804 | #if defined(__APPLE__) |
| 1805 | RGFW_monitor* currentMonitor = RGFW_window_getMonitor(platform.window); |
| 1806 | CORE.Window.screenScale = MatrixScale(currentMonitor->pixelRatio, currentMonitor->pixelRatio, 1.0f); |
| 1807 | |
| 1808 | CORE.Window.render.width = CORE.Window.screen.width * currentMonitor->pixelRatio; |
| 1809 | CORE.Window.render.height = CORE.Window.screen.height * currentMonitor->pixelRatio; |
| 1810 | CORE.Window.currentFbo.width = CORE.Window.render.width; |
| 1811 | CORE.Window.currentFbo.height = CORE.Window.render.height; |
| 1812 | #endif |
| 1813 | |
| 1814 | platform.surfaceWidth = CORE.Window.currentFbo.width; |
| 1815 | platform.surfaceHeight = CORE.Window.currentFbo.height; |
| 1816 | |
| 1817 | platform.surfacePixels = RL_MALLOC(platform.surfaceWidth * platform.surfaceHeight * 4); |
| 1818 | if (platform.surfacePixels == NULL) |
| 1819 | { |
| 1820 | TRACELOG(LOG_FATAL, "PLATFORM: Failed to initialize software pixel buffer"); |
| 1821 | return -1; |
| 1822 | } |
| 1823 | |
| 1824 | platform.surface = RGFW_window_createSurface(platform.window, platform.surfacePixels, platform.surfaceWidth, platform.surfaceHeight, RGFW_formatBGRA8); |
| 1825 | |
| 1826 | if (platform.surface == NULL) |
| 1827 | { |
| 1828 | RL_FREE(platform.surfacePixels); |
| 1829 | |
| 1830 | TRACELOG(LOG_FATAL, "PLATFORM: Failed to initialize software surface"); |
| 1831 | return -1; |
| 1832 | } |
| 1833 | #endif |
| 1834 | |
| 1835 | TRACELOG(LOG_INFO, "DISPLAY: Device initialized successfully %s", |
| 1836 | FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_HIGHDPI)? "(HighDPI)" : ""); |
| 1837 | TRACELOG(LOG_INFO, " > Display size: %i x %i", CORE.Window.display.width, CORE.Window.display.height); |
| 1838 | TRACELOG(LOG_INFO, " > Screen size: %i x %i", CORE.Window.screen.width, CORE.Window.screen.height); |
| 1839 | TRACELOG(LOG_INFO, " > Render size: %i x %i", CORE.Window.render.width, CORE.Window.render.height); |
| 1840 | TRACELOG(LOG_INFO, " > Viewport offsets: %i, %i", CORE.Window.renderOffset.x, CORE.Window.renderOffset.y); |
| 1841 | |
| 1842 | |
| 1843 | |
| 1844 | |
| 1845 | rlLoadExtensions((void *)RGFW_getProcAddress_OpenGL); |
| 1846 | |
| 1847 | |
| 1848 | |
| 1849 | |
| 1850 | InitTimer(); |
| 1851 | |
| 1852 | |
| 1853 | |
| 1854 | |
| 1855 | #if defined(__APPLE__) |
| 1856 | |
| 1857 | |
| 1858 | ChangeDirectory(GetApplicationDirectory()); |
| 1859 | #endif |
| 1860 | |
| 1861 | CORE.Storage.basePath = GetWorkingDirectory(); |
| 1862 | |
| 1863 | |
| 1864 | #if defined(RGFW_WAYLAND) |
| 1865 | if (rlGetVersion() == RL_OPENGL_SOFTWARE) |
| 1866 | { |
| 1867 | if (RGFW_usingWayland()) TRACELOG(LOG_INFO, "PLATFORM: DESKTOP (RGFW - Wayland, Software): Initialized successfully"); |
| 1868 | else TRACELOG(LOG_INFO, "PLATFORM: DESKTOP (RGFW - X11, Software (fallback)): Initialized successfully"); |
| 1869 | } |
| 1870 | else |
| 1871 | { |
| 1872 | if (RGFW_usingWayland()) TRACELOG(LOG_INFO, "PLATFORM: DESKTOP (RGFW - Wayland): Initialized successfully"); |
| 1873 | else TRACELOG(LOG_INFO, "PLATFORM: DESKTOP (RGFW - X11 (fallback)): Initialized successfully"); |
| 1874 | } |
| 1875 | #elif defined(RGFW_X11) |
| 1876 | #if defined(__APPLE__) |
| 1877 | if (rlGetVersion() == RL_OPENGL_SOFTWARE) |
| 1878 | { |
| 1879 | TRACELOG(LOG_INFO, "PLATFORM: DESKTOP (RGFW - X11, Software, (MacOS)): Initialized successfully"); |
| 1880 | } |
| 1881 | else |
| 1882 | { |
| 1883 | TRACELOG(LOG_INFO, "PLATFORM: DESKTOP (RGFW - X11, (MacOS)): Initialized successfully"); |
| 1884 | } |
| 1885 | #else |
| 1886 | if (rlGetVersion() == RL_OPENGL_SOFTWARE) |
| 1887 | { |
| 1888 | TRACELOG(LOG_INFO, "PLATFORM: DESKTOP (RGFW - X11, Software): Initialized successfully"); |
| 1889 | } |
| 1890 | else |
| 1891 | { |
| 1892 | TRACELOG(LOG_INFO, "PLATFORM: DESKTOP (RGFW - X11): Initialized successfully"); |
| 1893 | } |
| 1894 | #endif |
| 1895 | #elif defined (RGFW_WINDOWS) |
| 1896 | if (rlGetVersion() == RL_OPENGL_SOFTWARE) |
| 1897 | { |
| 1898 | TRACELOG(LOG_INFO, "PLATFORM: DESKTOP (RGFW - Win32, Software): Initialized successfully"); |
| 1899 | } |
| 1900 | else |
| 1901 | { |
| 1902 | TRACELOG(LOG_INFO, "PLATFORM: DESKTOP (RGFW - Win32): Initialized successfully"); |
| 1903 | } |
| 1904 | #elif defined(RGFW_WASM) |
| 1905 | if (rlGetVersion() == RL_OPENGL_SOFTWARE) |
| 1906 | { |
| 1907 | TRACELOG(LOG_INFO, "PLATFORM: DESKTOP (RGFW - WASMs, Software): Initialized successfully"); |
| 1908 | } |
| 1909 | else |
| 1910 | { |
| 1911 | TRACELOG(LOG_INFO, "PLATFORM: DESKTOP (RGFW - WASMs): Initialized successfully"); |
| 1912 | } |
| 1913 | #elif defined(RGFW_MACOS) |
| 1914 | if (rlGetVersion() == RL_OPENGL_SOFTWARE) |
| 1915 | { |
| 1916 | TRACELOG(LOG_INFO, "PLATFORM: DESKTOP (RGFW - MacOS, Software): Initialized successfully"); |
| 1917 | } |
| 1918 | else |
| 1919 | { |
| 1920 | TRACELOG(LOG_INFO, "PLATFORM: DESKTOP (RGFW - MacOS): Initialized successfully"); |
| 1921 | } |
| 1922 | #endif |
| 1923 | |
| 1924 | mg_gamepads_init(&platform.minigamepad); |
| 1925 | |
| 1926 | return 0; |
| 1927 | } |
| 1928 | |
| 1929 | |
| 1930 | void ClosePlatform(void) |
| 1931 | { |
| 1932 | mg_gamepads_free(&platform.minigamepad); |
| 1933 | RGFW_window_close(platform.window); |
| 1934 | |
| 1935 | #if defined(GRAPHICS_API_OPENGL_SOFTWARE) |
| 1936 | if (platform.surfacePixels != NULL) |
| 1937 | { |
| 1938 | RL_FREE(platform.surfacePixels); |
| 1939 | } |
| 1940 | |
| 1941 | if (platform.surface != NULL) |
| 1942 | { |
| 1943 | RGFW_surface_free(platform.surface); |
| 1944 | } |
| 1945 | #endif |
| 1946 | } |
| 1947 | |
| 1948 | |
| 1949 | static KeyboardKey ConvertScancodeToKey(u32 keycode) |
| 1950 | { |
| 1951 | if (keycode > sizeof(RGFW_keyConvertTable)/sizeof(unsigned short)) return KEY_NULL; |
| 1952 | |
| 1953 | return (KeyboardKey)RGFW_keyConvertTable[keycode]; |
| 1954 | } |
| 1955 | |
| 1956 | |
| 1957 | double get_time_seconds(void) |
| 1958 | { |
| 1959 | double currentTime = 0.0; |
| 1960 | |
| 1961 | #if defined(_WIN32) |
| 1962 | static LARGE_INTEGER freq = { 0 }; |
| 1963 | static bool freqInitialized = false; |
| 1964 | LARGE_INTEGER counter = { 0 }; |
| 1965 | if (!freqInitialized) |
| 1966 | { |
| 1967 | |
| 1968 | QueryPerformanceFrequency(&freq); |
| 1969 | freqInitialized = true; |
| 1970 | } |
| 1971 | QueryPerformanceCounter(&counter); |
| 1972 | currentTime = (double)counter.QuadPart/(double)freq.QuadPart; |
| 1973 | #elif defined(__EMSCRIPTEN__) |
| 1974 | currentTime = emscripten_get_now()/1000.0; |
| 1975 | #elif defined(__APPLE__) |
| 1976 | static mach_timebase_info_data_t tb = { 0 }; |
| 1977 | static bool tbInitialized = false; |
| 1978 | if (!tbInitialized) |
| 1979 | { |
| 1980 | mach_timebase_info(&tb); |
| 1981 | tbInitialized = true; |
| 1982 | } |
| 1983 | uint64_t ticks = mach_absolute_time(); |
| 1984 | |
| 1985 | currentTime = (double)ticks*(double)tb.numer/(double)tb.denom/1e9; |
| 1986 | #elif defined(__linux__) |
| 1987 | struct timespec ts = { 0 }; |
| 1988 | clock_gettime(CLOCK_MONOTONIC, &ts); |
| 1989 | currentTime = (double)ts.tv_sec + (double)ts.tv_nsec/1e9; |
| 1990 | #else |
| 1991 | |
| 1992 | currentTime = (double)clock()/(double)CLOCKS_PER_SEC; |
| 1993 | #endif |
| 1994 | |
| 1995 | return currentTime; |
| 1996 | } |