raygui/examples/portable_window/portable_window.c

97 lines
3.3 KiB
C
Raw Normal View History

/*******************************************************************************************
*
2019-07-05 20:47:15 +02:00
* raygui - portable window
2018-11-08 10:41:31 +01:00
*
* DEPENDENCIES:
* raylib 4.0 - Windowing/input management and drawing.
* raygui 3.0 - Immediate-mode GUI controls.
2018-11-08 10:41:31 +01:00
*
* COMPILATION (Windows - MinGW):
* gcc -o $(NAME_PART).exe $(FILE_NAME) -I../../src -lraylib -lopengl32 -lgdi32 -std=c99
*
* LICENSE: zlib/libpng
*
* Copyright (c) 2016-2021 Ramon Santamaria (@raysan5)
*
**********************************************************************************************/
#include "raylib.h"
#define RAYGUI_IMPLEMENTATION
2019-08-16 16:07:07 +02:00
#include "../../src/raygui.h"
//------------------------------------------------------------------------------------
// Program main entry point
//------------------------------------------------------------------------------------
int main()
{
// Initialization
//---------------------------------------------------------------------------------------
const int screenWidth = 800;
const int screenHeight = 600;
SetConfigFlags(FLAG_WINDOW_UNDECORATED);
2019-07-05 20:47:15 +02:00
InitWindow(screenWidth, screenHeight, "raygui - portable window");
// General variables
2019-07-05 20:47:15 +02:00
Vector2 mousePosition = { 0 };
Vector2 windowPosition = { 500, 200 };
Vector2 panOffset = mousePosition;
bool dragWindow = false;
2018-11-14 12:15:45 +01:00
2019-07-05 20:47:15 +02:00
SetWindowPosition(windowPosition.x, windowPosition.y);
bool exitWindow = false;
2018-11-14 12:15:45 +01:00
SetTargetFPS(60);
//--------------------------------------------------------------------------------------
// Main game loop
while (!exitWindow && !WindowShouldClose()) // Detect window close button or ESC key
{
// Update
//----------------------------------------------------------------------------------
2019-07-05 20:47:15 +02:00
mousePosition = GetMousePosition();
2018-11-14 12:15:45 +01:00
if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON))
{
2019-07-05 20:47:15 +02:00
if (CheckCollisionPointRec(mousePosition, (Rectangle){ 0, 0, screenWidth, 20 }))
{
2018-11-14 12:15:45 +01:00
dragWindow = true;
2019-07-05 20:47:15 +02:00
panOffset = mousePosition;
}
}
2018-11-14 12:15:45 +01:00
if (dragWindow)
{
2019-07-05 20:47:15 +02:00
windowPosition.x += (mousePosition.x - panOffset.x);
windowPosition.y += (mousePosition.y - panOffset.y);
2018-11-14 12:15:45 +01:00
if (IsMouseButtonReleased(MOUSE_LEFT_BUTTON)) dragWindow = false;
2019-07-05 20:47:15 +02:00
SetWindowPosition(windowPosition.x, windowPosition.y);
2018-11-14 12:15:45 +01:00
}
2018-11-08 10:41:31 +01:00
//----------------------------------------------------------------------------------
// Draw
//----------------------------------------------------------------------------------
BeginDrawing();
2018-11-14 11:20:53 +01:00
ClearBackground(RAYWHITE);
2021-04-02 16:32:14 +02:00
exitWindow = GuiWindowBox((Rectangle){ 0, 0, screenWidth, screenHeight }, "#198# PORTABLE WINDOW");
2019-07-05 20:47:15 +02:00
2021-03-12 18:01:14 +01:00
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;
}