mirror of
https://github.com/raysan5/raygui.git
synced 2025-12-25 10:22:33 -05:00
Review examples
This commit is contained in:
96
examples/portable_window/portable_window.c
Normal file
96
examples/portable_window/portable_window.c
Normal file
@ -0,0 +1,96 @@
|
||||
/*******************************************************************************************
|
||||
*
|
||||
* raygui - portable window
|
||||
*
|
||||
* DEPENDENCIES:
|
||||
* raylib 2.1 - Windowing/input management and drawing.
|
||||
* raygui 2.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) 2018 raylib technologies (@raylibtech)
|
||||
*
|
||||
**********************************************************************************************/
|
||||
|
||||
#include "raylib.h"
|
||||
|
||||
#define RAYGUI_IMPLEMENTATION
|
||||
#include "raygui.h"
|
||||
|
||||
//------------------------------------------------------------------------------------
|
||||
// Program main entry point
|
||||
//------------------------------------------------------------------------------------
|
||||
int main()
|
||||
{
|
||||
// Initialization
|
||||
//---------------------------------------------------------------------------------------
|
||||
int screenWidth = 800;
|
||||
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))
|
||||
{
|
||||
if (CheckCollisionPointRec(mousePosition, (Rectangle){ 0, 0, screenWidth, 20 }))
|
||||
{
|
||||
dragWindow = true;
|
||||
panOffset = mousePosition;
|
||||
}
|
||||
}
|
||||
|
||||
if (dragWindow)
|
||||
{
|
||||
windowPosition.x += (mousePosition.x - panOffset.x);
|
||||
windowPosition.y += (mousePosition.y - panOffset.y);
|
||||
|
||||
if (IsMouseButtonReleased(MOUSE_LEFT_BUTTON)) dragWindow = false;
|
||||
|
||||
SetWindowPosition(windowPosition.x, windowPosition.y);
|
||||
}
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
exitWindow = GuiWindowBox((Rectangle){ 0, 0, screenWidth, screenHeight }, "PORTABLE WINDOW");
|
||||
|
||||
DrawText(FormatText("Mouse Position: [ %.0f, %.0f ]", mousePosition.x, mousePosition.y), 10, 40, 10, DARKGRAY);
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user