2018-06-07 14:02:16 +02:00
|
|
|
/*******************************************************************************************
|
|
|
|
*
|
2019-07-05 20:47:15 +02:00
|
|
|
* raygui - portable window
|
2018-11-08 10:41:31 +01:00
|
|
|
*
|
|
|
|
* DEPENDENCIES:
|
2021-10-05 14:10:35 +02:00
|
|
|
* 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
|
2018-06-07 14:02:16 +02:00
|
|
|
*
|
|
|
|
* LICENSE: zlib/libpng
|
|
|
|
*
|
2021-10-05 14:10:35 +02:00
|
|
|
* Copyright (c) 2016-2021 Ramon Santamaria (@raysan5)
|
2018-06-07 14:02:16 +02:00
|
|
|
*
|
|
|
|
**********************************************************************************************/
|
|
|
|
|
|
|
|
#include "raylib.h"
|
|
|
|
|
|
|
|
#define RAYGUI_IMPLEMENTATION
|
2019-08-16 16:07:07 +02:00
|
|
|
#include "../../src/raygui.h"
|
2018-06-07 14:02:16 +02:00
|
|
|
|
|
|
|
//------------------------------------------------------------------------------------
|
|
|
|
// Program main entry point
|
|
|
|
//------------------------------------------------------------------------------------
|
|
|
|
int main()
|
|
|
|
{
|
|
|
|
// Initialization
|
|
|
|
//---------------------------------------------------------------------------------------
|
2021-10-05 14:10:35 +02:00
|
|
|
const int screenWidth = 800;
|
|
|
|
const int screenHeight = 600;
|
2018-06-07 14:02:16 +02:00
|
|
|
|
|
|
|
SetConfigFlags(FLAG_WINDOW_UNDECORATED);
|
2019-07-05 20:47:15 +02:00
|
|
|
InitWindow(screenWidth, screenHeight, "raygui - portable window");
|
2018-06-07 14:02:16 +02:00
|
|
|
|
|
|
|
// General variables
|
2019-07-05 20:47:15 +02:00
|
|
|
Vector2 mousePosition = { 0 };
|
|
|
|
Vector2 windowPosition = { 500, 200 };
|
|
|
|
Vector2 panOffset = mousePosition;
|
2018-06-07 14:02:16 +02:00
|
|
|
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);
|
2018-06-07 14:02:16 +02:00
|
|
|
//--------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// 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-06-07 14:02:16 +02:00
|
|
|
|
2018-11-14 12:15:45 +01:00
|
|
|
if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON))
|
2018-06-07 14:02:16 +02:00
|
|
|
{
|
2019-07-05 20:47:15 +02:00
|
|
|
if (CheckCollisionPointRec(mousePosition, (Rectangle){ 0, 0, screenWidth, 20 }))
|
2018-06-07 14:02:16 +02:00
|
|
|
{
|
2018-11-14 12:15:45 +01:00
|
|
|
dragWindow = true;
|
2019-07-05 20:47:15 +02:00
|
|
|
panOffset = mousePosition;
|
2018-06-07 14:02:16 +02:00
|
|
|
}
|
|
|
|
}
|
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
|
|
|
//----------------------------------------------------------------------------------
|
2018-06-07 14:02:16 +02:00
|
|
|
|
|
|
|
// Draw
|
|
|
|
//----------------------------------------------------------------------------------
|
|
|
|
BeginDrawing();
|
|
|
|
|
2018-11-14 11:20:53 +01:00
|
|
|
ClearBackground(RAYWHITE);
|
2018-06-07 14:02:16 +02:00
|
|
|
|
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);
|
2018-06-07 14:02:16 +02:00
|
|
|
|
|
|
|
EndDrawing();
|
|
|
|
//----------------------------------------------------------------------------------
|
|
|
|
}
|
|
|
|
|
|
|
|
// De-Initialization
|
|
|
|
//--------------------------------------------------------------------------------------
|
|
|
|
CloseWindow(); // Close window and OpenGL context
|
|
|
|
//--------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|