examples
This commit is contained in:
parent
f19f61b778
commit
ff8baa4ce7
34 changed files with 5219 additions and 3 deletions
96
examples/gui/portable_window/portable_window.c
Normal file
96
examples/gui/portable_window/portable_window.c
Normal file
|
@ -0,0 +1,96 @@
|
|||
/*******************************************************************************************
|
||||
*
|
||||
* 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-2022 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))
|
||||
{
|
||||
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 }, "#198# PORTABLE WINDOW");
|
||||
|
||||
DrawText(TextFormat("Mouse Position: [ %.0f, %.0f ]", mousePosition.x, mousePosition.y), 10, 40, 10, DARKGRAY);
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue