mirror of
https://github.com/raysan5/raygui.git
synced 2025-12-25 10:22:33 -05:00
...the bar. This example never expected it and was caching Window Position, which means that position was outdated at the moment you moved the window via other means than dragging the bar. Fixes: https://github.com/raysan5/raygui/issues/468
99 lines
3.5 KiB
C
99 lines
3.5 KiB
C
/*******************************************************************************************
|
|
*
|
|
* raygui - portable window
|
|
*
|
|
* DEPENDENCIES:
|
|
* raylib 4.0 - Windowing/input management and drawing.
|
|
* raygui 3.0 - Immediate-mode GUI controls.
|
|
*
|
|
* COMPILATION (Windows - MinGW):
|
|
* gcc -o $(NAME_PART).exe $(FILE_NAME) -I../../src -lraylib -lopengl32 -lgdi32 -std=c99
|
|
*
|
|
* LICENSE: zlib/libpng
|
|
*
|
|
* Copyright (c) 2016-2024 Ramon Santamaria (@raysan5)
|
|
*
|
|
**********************************************************************************************/
|
|
|
|
#include "raylib.h"
|
|
|
|
#define RAYGUI_IMPLEMENTATION
|
|
#include "../../src/raygui.h"
|
|
|
|
//------------------------------------------------------------------------------------
|
|
// Program main entry point
|
|
//------------------------------------------------------------------------------------
|
|
int main()
|
|
{
|
|
// Initialization
|
|
//---------------------------------------------------------------------------------------
|
|
const int screenWidth = 800;
|
|
const int screenHeight = 600;
|
|
|
|
SetConfigFlags(FLAG_WINDOW_UNDECORATED);
|
|
InitWindow(screenWidth, screenHeight, "raygui - portable window");
|
|
|
|
// General variables
|
|
Vector2 mousePosition = { 0 };
|
|
Vector2 windowPosition = { 500, 200 };
|
|
Vector2 panOffset = mousePosition;
|
|
bool dragWindow = false;
|
|
|
|
SetWindowPosition(windowPosition.x, windowPosition.y);
|
|
|
|
bool exitWindow = false;
|
|
|
|
SetTargetFPS(60);
|
|
//--------------------------------------------------------------------------------------
|
|
|
|
// Main game loop
|
|
while (!exitWindow && !WindowShouldClose()) // Detect window close button or ESC key
|
|
{
|
|
// Update
|
|
//----------------------------------------------------------------------------------
|
|
mousePosition = GetMousePosition();
|
|
|
|
if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON) && !dragWindow)
|
|
{
|
|
if (CheckCollisionPointRec(mousePosition, (Rectangle){ 0, 0, screenWidth, 20 }))
|
|
{
|
|
windowPosition = GetWindowPosition();
|
|
dragWindow = true;
|
|
panOffset = mousePosition;
|
|
}
|
|
}
|
|
|
|
if (dragWindow)
|
|
{
|
|
windowPosition.x += (mousePosition.x - panOffset.x);
|
|
windowPosition.y += (mousePosition.y - panOffset.y);
|
|
|
|
SetWindowPosition((int)windowPosition.x, (int)windowPosition.y);
|
|
|
|
if (IsMouseButtonReleased(MOUSE_LEFT_BUTTON)) dragWindow = false;
|
|
}
|
|
//----------------------------------------------------------------------------------
|
|
|
|
// Draw
|
|
//----------------------------------------------------------------------------------
|
|
BeginDrawing();
|
|
|
|
ClearBackground(RAYWHITE);
|
|
|
|
exitWindow = GuiWindowBox((Rectangle){ 0, 0, screenWidth, screenHeight }, "#198# PORTABLE WINDOW");
|
|
|
|
DrawText(TextFormat("Mouse Position: [ %.0f, %.0f ]", mousePosition.x, mousePosition.y), 10, 40, 10, DARKGRAY);
|
|
DrawText(TextFormat("Window Position: [ %.0f, %.0f ]", windowPosition.x, windowPosition.y), 10, 60, 10, DARKGRAY);
|
|
|
|
EndDrawing();
|
|
//----------------------------------------------------------------------------------
|
|
}
|
|
|
|
// De-Initialization
|
|
//--------------------------------------------------------------------------------------
|
|
CloseWindow(); // Close window and OpenGL context
|
|
//--------------------------------------------------------------------------------------
|
|
|
|
return 0;
|
|
}
|