diff --git a/examples/gui/portable_window/go.mod b/examples/gui/portable_window/go.mod new file mode 100644 index 0000000..38805c6 --- /dev/null +++ b/examples/gui/portable_window/go.mod @@ -0,0 +1,11 @@ +module example + +go 1.19 + +require ( + github.com/Konstantin8105/raylib-go/raygui v0.0.0-20221122151443-e8a384ed1346 + github.com/Konstantin8105/raylib-go/raylib v0.0.0-20221122155035-fe6d2c0ed32a +) + +replace github.com/Konstantin8105/raylib-go/raylib => ../../../raylib +replace github.com/Konstantin8105/raylib-go/raygui => ../../../raygui3_5 diff --git a/examples/gui/portable_window/portable_window.go b/examples/gui/portable_window/portable_window.go new file mode 100644 index 0000000..bfc8a8f --- /dev/null +++ b/examples/gui/portable_window/portable_window.go @@ -0,0 +1,99 @@ +package main + +import ( + "fmt" + + gui "github.com/Konstantin8105/raylib-go/raygui" + rl "github.com/Konstantin8105/raylib-go/raylib" +) + +/******************************************************************************************* +* +* 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) +* +**********************************************************************************************/ + +//------------------------------------------------------------------------------------ +// Program main entry point +//------------------------------------------------------------------------------------ +func main() { + // Initialization + //--------------------------------------------------------------------------------------- + const ( + screenWidth = 800 + screenHeight = 600 + ) + + rl.SetConfigFlags(rl.FlagWindowUndecorated) + rl.InitWindow(screenWidth, screenHeight, "raygui - portable window") + + // General variables + var ( + mousePosition = rl.Vector2{0, 0} + windowPosition = rl.Vector2{500, 200} + panOffset = mousePosition + dragWindow = false + ) + + rl.SetWindowPosition(int(windowPosition.X), int(windowPosition.Y)) + + exitWindow := false + + rl.SetTargetFPS(60) + //-------------------------------------------------------------------------------------- + + // Main game loop + for !exitWindow && !rl.WindowShouldClose() { // Detect window close button or ESC key + // Update + //---------------------------------------------------------------------------------- + mousePosition = rl.GetMousePosition() + + if rl.IsMouseButtonPressed(rl.MouseLeftButton) { + if (rl.CheckCollisionPointRec(mousePosition, rl.Rectangle{0, 0, screenWidth, 20})) { + dragWindow = true + panOffset = mousePosition + } + } + + if dragWindow { + windowPosition.X += (mousePosition.X - panOffset.X) + windowPosition.Y += (mousePosition.Y - panOffset.Y) + + if rl.IsMouseButtonReleased(rl.MouseLeftButton) { + dragWindow = false + } + + rl.SetWindowPosition(int(windowPosition.X), int(windowPosition.Y)) + } + //---------------------------------------------------------------------------------- + + // Draw + //---------------------------------------------------------------------------------- + rl.BeginDrawing() + + rl.ClearBackground(rl.RayWhite) + + exitWindow = gui.WindowBox(rl.Rectangle{0, 0, screenWidth, screenHeight}, "#198# PORTABLE WINDOW") + + rl.DrawText(fmt.Sprintf("Mouse Position: [ %.0f, %.0f ]", mousePosition.X, mousePosition.Y), 10, 40, 10, rl.DarkGray) + + rl.EndDrawing() + //---------------------------------------------------------------------------------- + } + + // De-Initialization + //-------------------------------------------------------------------------------------- + rl.CloseWindow() // Close window and OpenGL context + //-------------------------------------------------------------------------------------- +} diff --git a/examples/gui/portable_window/portable_window.png b/examples/gui/portable_window/portable_window.png new file mode 100644 index 0000000..bc6e34e Binary files /dev/null and b/examples/gui/portable_window/portable_window.png differ diff --git a/examples/gui/scroll_panel/scroll_panel.png b/examples/gui/scroll_panel/scroll_panel.png new file mode 100644 index 0000000..fe2e095 Binary files /dev/null and b/examples/gui/scroll_panel/scroll_panel.png differ