raygui/examples/portable_window/portable_window.c
Winter e81fd89b6d
Modify custom_file_dialog, portable_window, propertly_list, and text_editor examples to be compatible with the newest raylib and raygui (#156)
Modify gui_textbox_extended.h to contain DrawTextRec and DrawTextRecEx since they were cut from raylib, also add DrawTextBoxedSelectable as an alias for DrawTextRecEx for compatibility/name consistency
Modify gui_textbox_extended.h to be compatible with the latest raylib
2021-09-19 20:15:24 +02:00

98 lines
3.3 KiB
C

/*******************************************************************************************
*
* 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) 2020 Ramon Santamaria (@raysan5)
*
**********************************************************************************************/
#include "raylib.h"
#define RAYGUI_IMPLEMENTATION
#define RAYGUI_SUPPORT_RICONS
#include "../../src/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 }, "#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;
}