diff --git a/src/rcore.c b/src/rcore.c index 253436e51..3efa67b2c 100644 --- a/src/rcore.c +++ b/src/rcore.c @@ -322,18 +322,15 @@ const char *TextFormat(const char *text, ...); // Formatting of text with //void InitWindow(int width, int height, const char *title) //void CloseWindow(void) //bool WindowShouldClose(void) -//bool IsWindowHidden(void) -//bool IsWindowMinimized(void) -//bool IsWindowMaximized(void) -//bool IsWindowFocused(void) -//bool IsWindowResized(void) //void ToggleFullscreen(void) +//void ToggleBorderlessWindowed(void) //void MaximizeWindow(void) //void MinimizeWindow(void) //void RestoreWindow(void) -//void ToggleBorderlessWindowed(void) + //void SetWindowState(unsigned int flags) //void ClearWindowState(unsigned int flags) + //void SetWindowIcon(Image image) //void SetWindowIcons(Image *images, int count) //void SetWindowTitle(const char *title) @@ -345,25 +342,27 @@ const char *TextFormat(const char *text, ...); // Formatting of text with //void SetWindowOpacity(float opacity) //void SetWindowFocused(void) //void *GetWindowHandle(void) +//Vector2 GetWindowPosition(void) +//Vector2 GetWindowScaleDPI(void) + //int GetMonitorCount(void) //int GetCurrentMonitor(void) -//Vector2 GetMonitorPosition(int monitor) //int GetMonitorWidth(int monitor) //int GetMonitorHeight(int monitor) //int GetMonitorPhysicalWidth(int monitor) //int GetMonitorPhysicalHeight(int monitor) //int GetMonitorRefreshRate(int monitor) +//Vector2 GetMonitorPosition(int monitor) //const char *GetMonitorName(int monitor) -//Vector2 GetWindowPosition(void) -//Vector2 GetWindowScaleDPI(void) + //void SetClipboardText(const char *text) //const char *GetClipboardText(void) + //void ShowCursor(void) //void HideCursor(void) //void EnableCursor(void) //void DisableCursor(void) - // Check if window has been initialized successfully bool IsWindowReady(void) { @@ -376,6 +375,36 @@ bool IsWindowFullscreen(void) return CORE.Window.fullscreen; } +// Check if window is currently hidden +bool IsWindowHidden(void) +{ + return ((CORE.Window.flags & FLAG_WINDOW_HIDDEN) > 0); +} + +// Check if window has been minimized +bool IsWindowMinimized(void) +{ + return ((CORE.Window.flags & FLAG_WINDOW_MINIMIZED) > 0); +} + +// Check if window has been maximized +bool IsWindowMaximized(void) +{ + return ((CORE.Window.flags & FLAG_WINDOW_MAXIMIZED) > 0); +} + +// Check if window has the focus +bool IsWindowFocused(void) +{ + return ((CORE.Window.flags & FLAG_WINDOW_UNFOCUSED) == 0); +} + +// Check if window has been resizedLastFrame +bool IsWindowResized(void) +{ + return CORE.Window.resizedLastFrame; +} + // Check if one specific window flag is enabled bool IsWindowState(unsigned int flag) { @@ -394,13 +423,13 @@ int GetScreenHeight(void) return CORE.Window.screen.height; } -// Get current render width which is equal to screen width * dpi scale +// Get current render width which is equal to screen width*dpi scale int GetRenderWidth(void) { return CORE.Window.render.width; } -// Get current screen height which is equal to screen height * dpi scale +// Get current screen height which is equal to screen height*dpi scale int GetRenderHeight(void) { return CORE.Window.render.height; diff --git a/src/rcore_android.c b/src/rcore_android.c index bfb57fedf..7cc71bbca 100644 --- a/src/rcore_android.c +++ b/src/rcore_android.c @@ -183,13 +183,14 @@ void InitWindow(int width, int height, const char *title) CORE.Input.Gamepad.lastButtonPressed = 0; // GAMEPAD_BUTTON_UNKNOWN CORE.Window.eventWaiting = false; + + // Platform specific init window + //-------------------------------------------------------------- CORE.Window.screen.width = width; CORE.Window.screen.height = height; CORE.Window.currentFbo.width = width; CORE.Window.currentFbo.height = height; - - // Platform specific init window - //-------------------------------------------------------------- + // Set desired windows flags before initializing anything ANativeActivity_setWindowFlags(platform.app->activity, AWINDOW_FLAG_FULLSCREEN, 0); //AWINDOW_FLAG_SCALED, AWINDOW_FLAG_DITHER @@ -227,6 +228,12 @@ void InitWindow(int width, int height, const char *title) // Initialize base path for storage CORE.Storage.basePath = platform.app->activity->internalDataPath; + + // Set some default window flags + CORE.Window.flags &= ~FLAG_WINDOW_HIDDEN; // false + CORE.Window.flags &= ~FLAG_WINDOW_MINIMIZED); // false + CORE.Window.flags |= FLAG_WINDOW_MAXIMIZED); // true + CORE.Window.flags &= ~FLAG_WINDOW_UNFOCUSED); // false TRACELOG(LOG_INFO, "PLATFORM: ANDROID: Application initialized successfully"); @@ -311,36 +318,6 @@ bool WindowShouldClose(void) else return true; } -// Check if window is currently hidden -bool IsWindowHidden(void) -{ - return false; -} - -// Check if window has been minimized -bool IsWindowMinimized(void) -{ - return false; -} - -// Check if window has been maximized -bool IsWindowMaximized(void) -{ - return false; -} - -// Check if window has the focus -bool IsWindowFocused(void) -{ - return platform.appEnabled; -} - -// Check if window has been resizedLastFrame -bool IsWindowResized(void) -{ - return false; -} - // Toggle fullscreen mode void ToggleFullscreen(void) { @@ -936,12 +913,14 @@ static void AndroidCommandCallback(struct android_app *app, int32_t cmd) case APP_CMD_GAINED_FOCUS: { platform.appEnabled = true; + CORE.Window.flags &= ~FLAG_WINDOW_UNFOCUSED; //ResumeMusicStream(); } break; case APP_CMD_PAUSE: break; case APP_CMD_LOST_FOCUS: { platform.appEnabled = false; + CORE.Window.flags |= FLAG_WINDOW_UNFOCUSED; //PauseMusicStream(); } break; case APP_CMD_TERM_WINDOW: diff --git a/src/rcore_desktop.c b/src/rcore_desktop.c index 54b684a0c..c2e5b23f1 100644 --- a/src/rcore_desktop.c +++ b/src/rcore_desktop.c @@ -2,7 +2,7 @@ * * rcore_desktop - Functions to manage window, graphics device and inputs * -* PLATFORM: DESKTOP +* PLATFORM: DESKTOP: GLFW * - Windows (Win32, Win64) * - Linux (X11/Wayland desktop mode) * - FreeBSD, OpenBSD, NetBSD, DragonFly (X11 desktop) @@ -187,8 +187,26 @@ void InitWindow(int width, int height, const char *title) CORE.Input.Gamepad.lastButtonPressed = 0; // GAMEPAD_BUTTON_UNKNOWN CORE.Window.eventWaiting = false; + + // Platform specific init window + //-------------------------------------------------------------- + glfwSetErrorCallback(ErrorCallback); +/* + // TODO: Setup GLFW custom allocators to match raylib ones + const GLFWallocator allocator = { + .allocate = MemAlloc, + .deallocate = MemFree, + .reallocate = MemRealloc, + .user = NULL + }; + + glfwInitAllocator(&allocator); +*/ + // Initialize graphics device // NOTE: returns true if window and graphic device has been initialized successfully + // WARNING: Actually, all window initialization and input callbacks initialization is + // done inside InitGraphicsDevice(), this functionality should be changed! CORE.Window.ready = InitGraphicsDevice(width, height); // If graphic device is no properly initialized, we end program @@ -197,13 +215,15 @@ void InitWindow(int width, int height, const char *title) // Initialize hi-res timer InitTimer(); + + // Initialize base path for storage + CORE.Storage.basePath = GetWorkingDirectory(); + //-------------------------------------------------------------- + // Initialize random seed SetRandomSeed((unsigned int)time(NULL)); - // Initialize base path for storage - CORE.Storage.basePath = GetWorkingDirectory(); - #if defined(SUPPORT_MODULE_RTEXT) && defined(SUPPORT_DEFAULT_FONT) // Load default font // WARNING: External function: Module required: rtext @@ -304,36 +324,6 @@ bool WindowShouldClose(void) else return true; } -// Check if window is currently hidden -bool IsWindowHidden(void) -{ - return ((CORE.Window.flags & FLAG_WINDOW_HIDDEN) > 0); -} - -// Check if window has been minimized -bool IsWindowMinimized(void) -{ - return ((CORE.Window.flags & FLAG_WINDOW_MINIMIZED) > 0); -} - -// Check if window has been maximized -bool IsWindowMaximized(void) -{ - return ((CORE.Window.flags & FLAG_WINDOW_MAXIMIZED) > 0); -} - -// Check if window has the focus -bool IsWindowFocused(void) -{ - return ((CORE.Window.flags & FLAG_WINDOW_UNFOCUSED) == 0); -} - -// Check if window has been resizedLastFrame -bool IsWindowResized(void) -{ - return CORE.Window.resizedLastFrame; -} - // Toggle fullscreen mode void ToggleFullscreen(void) { @@ -1408,18 +1398,6 @@ static bool InitGraphicsDevice(int width, int height) // NOTE: Framebuffer (render area - CORE.Window.render.width, CORE.Window.render.height) could include black bars... // ...in top-down or left-right to match display aspect ratio (no weird scaling) - glfwSetErrorCallback(ErrorCallback); -/* - // TODO: Setup GLFW custom allocators to match raylib ones - const GLFWallocator allocator = { - .allocate = MemAlloc, - .deallocate = MemFree, - .reallocate = MemRealloc, - .user = NULL - }; - - glfwInitAllocator(&allocator); -*/ #if defined(__APPLE__) glfwInitHint(GLFW_COCOA_CHDIR_RESOURCES, GLFW_FALSE); #endif diff --git a/src/rcore_drm.c b/src/rcore_drm.c index 2f0eab682..c0e88c723 100644 --- a/src/rcore_drm.c +++ b/src/rcore_drm.c @@ -215,6 +215,9 @@ void InitWindow(int width, int height, const char *title) CORE.Input.Gamepad.lastButtonPressed = 0; // GAMEPAD_BUTTON_UNKNOWN CORE.Window.eventWaiting = false; + + // Platform specific init window + //-------------------------------------------------------------- // Initialize graphics device (display device and OpenGL context) // NOTE: returns true if window and graphic device has been initialized successfully CORE.Window.ready = InitGraphicsDevice(width, height); @@ -223,15 +226,28 @@ void InitWindow(int width, int height, const char *title) if (!CORE.Window.ready) { TRACELOG(LOG_FATAL, "PLATFORM: Failed to initialize graphic device"); return; } else SetWindowPosition(GetMonitorWidth(GetCurrentMonitor()) / 2 - CORE.Window.screen.width / 2, GetMonitorHeight(GetCurrentMonitor()) / 2 - CORE.Window.screen.height / 2); + // Set some default window flags + CORE.Window.flags &= ~FLAG_WINDOW_HIDDEN; // false + CORE.Window.flags &= ~FLAG_WINDOW_MINIMIZED); // false + CORE.Window.flags |= FLAG_WINDOW_MAXIMIZED); // true + CORE.Window.flags &= ~FLAG_WINDOW_UNFOCUSED); // false + // Initialize hi-res timer InitTimer(); + + // Initialize base path for storage + CORE.Storage.basePath = GetWorkingDirectory(); + + // Initialize raw input system + InitEvdevInput(); // Evdev inputs initialization + InitGamepad(); // Gamepad init + InitKeyboard(); // Keyboard init (stdin) + //-------------------------------------------------------------- + // Initialize random seed SetRandomSeed((unsigned int)time(NULL)); - // Initialize base path for storage - CORE.Storage.basePath = GetWorkingDirectory(); - #if defined(SUPPORT_MODULE_RTEXT) && defined(SUPPORT_DEFAULT_FONT) // Load default font // WARNING: External function: Module required: rtext @@ -274,14 +290,6 @@ void InitWindow(int width, int height, const char *title) CORE.Time.frameCounter = 0; #endif - // Platform specific init window - //-------------------------------------------------------------- - // Initialize raw input system - InitEvdevInput(); // Evdev inputs initialization - InitGamepad(); // Gamepad init - InitKeyboard(); // Keyboard init (stdin) - //-------------------------------------------------------------- - TRACELOG(LOG_INFO, "PLATFORM: DRM: Application initialized successfully"); } @@ -412,36 +420,6 @@ bool WindowShouldClose(void) else return true; } -// Check if window is currently hidden -bool IsWindowHidden(void) -{ - return false; -} - -// Check if window has been minimized -bool IsWindowMinimized(void) -{ - return false; -} - -// Check if window has been maximized -bool IsWindowMaximized(void) -{ - return false; -} - -// Check if window has the focus -bool IsWindowFocused(void) -{ - return true; -} - -// Check if window has been resizedLastFrame -bool IsWindowResized(void) -{ - return false; -} - // Toggle fullscreen mode void ToggleFullscreen(void) { diff --git a/src/rcore_template.c b/src/rcore_template.c index ea5af40d9..88b3c4a7e 100644 --- a/src/rcore_template.c +++ b/src/rcore_template.c @@ -128,8 +128,11 @@ void InitWindow(int width, int height, const char *title) CORE.Input.Mouse.scale = (Vector2){ 1.0f, 1.0f }; CORE.Input.Mouse.cursor = MOUSE_CURSOR_ARROW; CORE.Input.Gamepad.lastButtonPressed = 0; // GAMEPAD_BUTTON_UNKNOWN - CORE.Window.eventWaiting = false; + + + // TODO: Platform specific init window + //-------------------------------------------------------------- CORE.Window.screen.width = width; CORE.Window.screen.height = height; CORE.Window.currentFbo.width = width; @@ -144,13 +147,15 @@ void InitWindow(int width, int height, const char *title) // Initialize hi-res timer InitTimer(); + + // Initialize base path for storage + CORE.Storage.basePath = GetWorkingDirectory(); + //-------------------------------------------------------------- + // Initialize random seed SetRandomSeed((unsigned int)time(NULL)); - // Initialize base path for storage - CORE.Storage.basePath = GetWorkingDirectory(); - #if defined(SUPPORT_MODULE_RTEXT) && defined(SUPPORT_DEFAULT_FONT) // Load default font // WARNING: External function: Module required: rtext @@ -193,11 +198,6 @@ void InitWindow(int width, int height, const char *title) CORE.Time.frameCounter = 0; #endif - // TODO: Platform specific init window - //-------------------------------------------------------------- - // ... - //-------------------------------------------------------------- - TRACELOG(LOG_INFO, "PLATFORM: CUSTOM: Application initialized successfully"); } @@ -239,36 +239,6 @@ bool WindowShouldClose(void) else return true; } -// Check if window is currently hidden -bool IsWindowHidden(void) -{ - return false; -} - -// Check if window has been minimized -bool IsWindowMinimized(void) -{ - return false; -} - -// Check if window has been maximized -bool IsWindowMaximized(void) -{ - return false; -} - -// Check if window has the focus -bool IsWindowFocused(void) -{ - return platform.appEnabled; -} - -// Check if window has been resizedLastFrame -bool IsWindowResized(void) -{ - return false; -} - // Toggle fullscreen mode void ToggleFullscreen(void) { diff --git a/src/rcore_web.c b/src/rcore_web.c index d24ef1214..261498a5b 100644 --- a/src/rcore_web.c +++ b/src/rcore_web.c @@ -171,6 +171,9 @@ void InitWindow(int width, int height, const char *title) CORE.Input.Gamepad.lastButtonPressed = 0; // GAMEPAD_BUTTON_UNKNOWN CORE.Window.eventWaiting = false; + + // Platform specific init window + //-------------------------------------------------------------- // Initialize graphics device (display device and OpenGL context) // NOTE: returns true if window and graphic device has been initialized successfully CORE.Window.ready = InitGraphicsDevice(width, height); @@ -181,13 +184,44 @@ void InitWindow(int width, int height, const char *title) // Initialize hi-res timer InitTimer(); + + // Initialize base path for storage + CORE.Storage.basePath = GetWorkingDirectory(); + + // Setup callback functions for the DOM events + emscripten_set_fullscreenchange_callback("#canvas", NULL, 1, EmscriptenFullscreenChangeCallback); + + // WARNING: Below resize code was breaking fullscreen mode for sample games and examples, it needs review + // Check fullscreen change events(note this is done on the window since most browsers don't support this on #canvas) + // emscripten_set_fullscreenchange_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW, NULL, 1, EmscriptenResizeCallback); + // Check Resize event (note this is done on the window since most browsers don't support this on #canvas) + emscripten_set_resize_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW, NULL, 1, EmscriptenResizeCallback); + + // Trigger this once to get initial window sizing + EmscriptenResizeCallback(EMSCRIPTEN_EVENT_RESIZE, NULL, NULL); + + // Support keyboard events -> Not used, GLFW.JS takes care of that + // emscripten_set_keypress_callback("#canvas", NULL, 1, EmscriptenKeyboardCallback); + // emscripten_set_keydown_callback("#canvas", NULL, 1, EmscriptenKeyboardCallback); + + // Support mouse events + emscripten_set_click_callback("#canvas", NULL, 1, EmscriptenMouseCallback); + + // Support touch events + emscripten_set_touchstart_callback("#canvas", NULL, 1, EmscriptenTouchCallback); + emscripten_set_touchend_callback("#canvas", NULL, 1, EmscriptenTouchCallback); + emscripten_set_touchmove_callback("#canvas", NULL, 1, EmscriptenTouchCallback); + emscripten_set_touchcancel_callback("#canvas", NULL, 1, EmscriptenTouchCallback); + + // Support gamepad events (not provided by GLFW3 on emscripten) + emscripten_set_gamepadconnected_callback(NULL, 1, EmscriptenGamepadCallback); + emscripten_set_gamepaddisconnected_callback(NULL, 1, EmscriptenGamepadCallback); + //-------------------------------------------------------------- + // Initialize random seed SetRandomSeed((unsigned int)time(NULL)); - // Initialize base path for storage - CORE.Storage.basePath = GetWorkingDirectory(); - #if defined(SUPPORT_MODULE_RTEXT) && defined(SUPPORT_DEFAULT_FONT) // Load default font // WARNING: External function: Module required: rtext @@ -230,38 +264,6 @@ void InitWindow(int width, int height, const char *title) CORE.Time.frameCounter = 0; #endif - // Platform specific init window - //-------------------------------------------------------------- - // Setup callback functions for the DOM events - emscripten_set_fullscreenchange_callback("#canvas", NULL, 1, EmscriptenFullscreenChangeCallback); - - // WARNING: Below resize code was breaking fullscreen mode for sample games and examples, it needs review - // Check fullscreen change events(note this is done on the window since most browsers don't support this on #canvas) - // emscripten_set_fullscreenchange_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW, NULL, 1, EmscriptenResizeCallback); - // Check Resize event (note this is done on the window since most browsers don't support this on #canvas) - emscripten_set_resize_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW, NULL, 1, EmscriptenResizeCallback); - - // Trigger this once to get initial window sizing - EmscriptenResizeCallback(EMSCRIPTEN_EVENT_RESIZE, NULL, NULL); - - // Support keyboard events -> Not used, GLFW.JS takes care of that - // emscripten_set_keypress_callback("#canvas", NULL, 1, EmscriptenKeyboardCallback); - // emscripten_set_keydown_callback("#canvas", NULL, 1, EmscriptenKeyboardCallback); - - // Support mouse events - emscripten_set_click_callback("#canvas", NULL, 1, EmscriptenMouseCallback); - - // Support touch events - emscripten_set_touchstart_callback("#canvas", NULL, 1, EmscriptenTouchCallback); - emscripten_set_touchend_callback("#canvas", NULL, 1, EmscriptenTouchCallback); - emscripten_set_touchmove_callback("#canvas", NULL, 1, EmscriptenTouchCallback); - emscripten_set_touchcancel_callback("#canvas", NULL, 1, EmscriptenTouchCallback); - - // Support gamepad events (not provided by GLFW3 on emscripten) - emscripten_set_gamepadconnected_callback(NULL, 1, EmscriptenGamepadCallback); - emscripten_set_gamepaddisconnected_callback(NULL, 1, EmscriptenGamepadCallback); - //-------------------------------------------------------------- - TRACELOG(LOG_INFO, "PLATFORM: WEB: Application initialized successfully"); } @@ -309,36 +311,6 @@ bool WindowShouldClose(void) return false; } -// Check if window is currently hidden -bool IsWindowHidden(void) -{ - return false; -} - -// Check if window has been minimized -bool IsWindowMinimized(void) -{ - return false; -} - -// Check if window has been maximized -bool IsWindowMaximized(void) -{ - return false; -} - -// Check if window has the focus -bool IsWindowFocused(void) -{ - return ((CORE.Window.flags & FLAG_WINDOW_UNFOCUSED) == 0); -} - -// Check if window has been resizedLastFrame -bool IsWindowResized(void) -{ - return CORE.Window.resizedLastFrame; -} - // Toggle fullscreen mode void ToggleFullscreen(void) {