From 7c407ab6a1a92a59a0fd6e200d8b7b52a5b8c0c0 Mon Sep 17 00:00:00 2001 From: maiconpintoabreu Date: Mon, 29 Sep 2025 16:57:28 +0100 Subject: [PATCH] Add core monitor change example --- examples/core/core_monitor_change.c | 84 ++++++++++++++++++++++++++ examples/core/core_monitor_change.png | Bin 0 -> 6062 bytes 2 files changed, 84 insertions(+) create mode 100644 examples/core/core_monitor_change.c create mode 100644 examples/core/core_monitor_change.png diff --git a/examples/core/core_monitor_change.c b/examples/core/core_monitor_change.c new file mode 100644 index 000000000..f9c9e3040 --- /dev/null +++ b/examples/core/core_monitor_change.c @@ -0,0 +1,84 @@ +/******************************************************************************************* +* +* raylib [core] example - monitor change +* +* Example complexity rating: [★☆☆☆] 1/4 +* +* Example originally created with raylib 5.5, last time updated with raylib 5.6 +* +* Example contributed by Maicon Santana (@maiconpintoabreu) and reviewed by Ramon Santamaria (@raysan5) +* +* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified, +* BSD-like license that allows static linking with closed source software +* +* Copyright (c) 2025-2025 Maicon Santana (@maiconpintoabreu) +* +********************************************************************************************/ + +#include "raylib.h" + +//------------------------------------------------------------------------------------ +// Program main entry point +//------------------------------------------------------------------------------------ +int main(void) +{ + // Initialization + //-------------------------------------------------------------------------------------- + const int screenWidth = 800; + const int screenHeight = 450; + + InitWindow(screenWidth, screenHeight, "raylib [core] example - monitor change"); + + int currentMonitor = GetCurrentMonitor(); + + SetTargetFPS(60); // Set our game to run at 60 frames-per-second + //-------------------------------------------------------------------------------------- + + // Main game loop + while (!WindowShouldClose()) // Detect window close button or ESC key + { + // Update + //---------------------------------------------------------------------------------- + + if (IsKeyPressed(KEY_ENTER)) { + currentMonitor += 1; + if(currentMonitor == GetMonitorCount()) { + currentMonitor = 0; + } + SetWindowMonitor(currentMonitor); + } else { + currentMonitor = GetCurrentMonitor(); + } + + const Vector2 resolution = (Vector2){(float)GetMonitorWidth(currentMonitor), (float)GetMonitorHeight(currentMonitor)}; + const int refreshRate = GetMonitorRefreshRate(currentMonitor); + + // Draw + //---------------------------------------------------------------------------------- + BeginDrawing(); + + ClearBackground(RAYWHITE); + + DrawText("[Enter] Move to the next monitor available", 20, 20, 20, DARKGRAY); + + DrawText( + TextFormat("%3.0f x %3.0f [%ihz]", + resolution.x, + resolution.y, + refreshRate + ), 20, 70, 20, GRAY); + DrawText(TextFormat("%i", currentMonitor), screenWidth * 0.5, screenHeight * 0.5, 70, GRAY); + DrawRectangleLines(20, 100, screenWidth - 40, screenHeight - 120, DARKGRAY); + + + EndDrawing(); + //---------------------------------------------------------------------------------- + } + + // De-Initialization + //-------------------------------------------------------------------------------------- + CloseWindow(); // Close window and OpenGL context + //-------------------------------------------------------------------------------------- + + return 0; +} \ No newline at end of file diff --git a/examples/core/core_monitor_change.png b/examples/core/core_monitor_change.png new file mode 100644 index 0000000000000000000000000000000000000000..ceb984ccb10910ff48681ad568e058f339d6eb32 GIT binary patch literal 6062 zcmeAS@N?(olHy`uVBq!ia0y~yU{+vYU_8XZ#=yWJp1k%10|Sp+YJ_K+r>7PJ2LlN3 zF)%Q2GW=s;VPIrn0AmJ52phy;wi|Hl6Z3<6$mo^A|`j3CPy85sWGW^iWUU}IxvW949H zXXoVP;NlVC<>BV$krWc<7m<~cmy?x}kx@|5Q&&*ZQI?U>FxS*EFf=hSkyp30wJ@^L zGd3{-8N$fP$;rdbBf-lnVWcRdXhbsje}F-dgJA+A12dx%1Ct;lvmoRDBMkBk42-Od zU;yz70|O%yGYcylI|nBh_x~ddTLnNN#mvOQ%*x8b!oa{-%gDscz#_;hq-f~KCLEZ^ zu2d*u)Hrb=hqBYggQ7tfKd2Zd6*X~kiHS={N~x-;YiMejn3|beSXw!|xVpJ}czOkg zgocGjL`Eg2q^6~3WM&nYl$MoOR8}>&w6?W(baqXeJZ0*%=`&`|TC{k{(q+q6tX#Ee z^OmjKw(r=v>(JpNM~@vpaq`rq%U7;myME*5t%r{uKY9A>`HPpYK7RWA8K@SeRMZLH=T7DhGL7k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