From 34b3c75bf99a5bcf71fea20df28ac9d04deb918e Mon Sep 17 00:00:00 2001 From: InventorXtreme Date: Sun, 21 Apr 2024 01:30:49 -0400 Subject: [PATCH] erm --- window.go | 31 ++++++++++++++----------------- windowmanager.go | 6 +++--- 2 files changed, 17 insertions(+), 20 deletions(-) diff --git a/window.go b/window.go index f8e6b1b..17196ef 100644 --- a/window.go +++ b/window.go @@ -8,10 +8,8 @@ import ( type RayGuiWindow struct { Texture *rl.RenderTexture2D - X int32 - Y int32 - W int32 - H int32 + Pos rl.Vector2 + Size rl.Vector2 DrawBorder bool DrawFunc windowdrawfunc ManageFunc managewindowfunc @@ -31,18 +29,18 @@ type windowdrawfunc func(*RayGuiWindow) func NewRayGuiWindow(x, y, w, h int) RayGuiWindow { texture := rl.LoadRenderTexture(int32(w), int32(h)) - return RayGuiWindow{Texture: &texture, X: int32(x), Y: int32(y), W: int32(w), H: int32(h), DrawBorder: true, AcceptingInput: false} + return RayGuiWindow{Texture: &texture, Pos: rl.Vector2{X: float32(x), Y: float32(y)}, Size: rl.Vector2{X: float32(w), Y: float32(h)}, DrawBorder: true, AcceptingInput: false} } func (win *RayGuiWindow) Resize(x, y int) { rl.UnloadRenderTexture(*win.Texture) - win.W += int32(x) - win.H += int32(y) - *win.Texture = rl.LoadRenderTexture(int32(win.W), int32(win.H)) + win.Size.X += float32(x) + win.Size.Y += float32(y) + *win.Texture = rl.LoadRenderTexture(int32(win.Size.X), int32(win.Size.Y)) } func (win *RayGuiWindow) DidStartMoveDrag() bool { - if win.IsTouchingRegion(rl.GetMousePosition(), rl.NewRectangle(0, -20, float32(win.W), 20)) { + if win.IsTouchingRegion(rl.GetMousePosition(), rl.NewRectangle(0, -20, float32(win.Size.X), 20)) { if rl.IsMouseButtonPressed(rl.MouseButtonLeft) { return true } @@ -51,7 +49,7 @@ func (win *RayGuiWindow) DidStartMoveDrag() bool { } func (win *RayGuiWindow) DidStartResizeDrag() bool { - if win.IsTouchingRegion(rl.GetMousePosition(), rl.NewRectangle(0, 0, float32(win.W), float32(win.H))) { + if win.IsTouchingRegion(rl.GetMousePosition(), rl.NewRectangle(0, 0, float32(win.Size.X), float32(win.Size.Y))) { if rl.IsMouseButtonPressed(rl.MouseButtonRight) { return true } @@ -60,13 +58,13 @@ func (win *RayGuiWindow) DidStartResizeDrag() bool { } func (window *RayGuiWindow) isLeftClicked() bool { - return rl.IsMouseButtonPressed(rl.MouseButtonLeft) && rl.CheckCollisionPointRec(rl.GetMousePosition(), rl.NewRectangle(float32(window.X), float32(window.Y-20), float32(window.W), float32(window.H+20))) + return rl.IsMouseButtonPressed(rl.MouseButtonLeft) && rl.CheckCollisionPointRec(rl.GetMousePosition(), rl.NewRectangle(float32(window.Pos.X), float32(window.Pos.Y-20), float32(window.Size.X), float32(window.Size.Y+20))) } func (window *RayGuiWindow) BeginDrawMode() { rl.BeginTextureMode(*window.Texture) if window.AcceptingInput { - rl.SetMouseOffset(int(-window.X), int(-window.Y)) + rl.SetMouseOffset(int(-window.Pos.X), int(-window.Pos.Y)) } else { rl.SetMouseOffset(-1000000, -1000000) } @@ -79,18 +77,17 @@ func (window *RayGuiWindow) EndDrawMode() { func (window RayGuiWindow) IsTouchingRegion(posvec rl.Vector2, rect rl.Rectangle) bool { - if rl.CheckCollisionPointRec(posvec, rl.Rectangle{X: rect.X + float32(window.X), Y: rect.Y + float32(window.Y), Width: rect.Width, Height: rect.Height}) { + if rl.CheckCollisionPointRec(posvec, rl.Rectangle{X: rect.X + float32(window.Pos.X), Y: rect.Y + float32(window.Pos.Y), Width: rect.Width, Height: rect.Height}) { return true } return false } func (window *RayGuiWindow) Draw() { - rl.DrawRectangle(window.X, window.Y-20, window.W, 20, rl.Gray) - rl.DrawText(fmt.Sprint(window.AcceptingInput), window.X-20, window.Y-20, 12, rl.Blue) + rl.DrawRectangle(int32(window.Pos.X), int32(window.Pos.Y)-20, int32(window.Size.X), 20, rl.Gray) + rl.DrawText(fmt.Sprint(window.AcceptingInput), int32(window.Pos.X-20), int32(window.Pos.Y)-20, 12, rl.Blue) //fmt.Printf("WindowDraw at %i, %i\n", window.X, window.Y) - - DrawTextureFlipped(&window.Texture.Texture, window.X, window.Y) + DrawTextureFlipped(&window.Texture.Texture, int32(window.Pos.X), int32(window.Pos.Y)) } func (window *RayGuiWindow) DrawInternals() { diff --git a/windowmanager.go b/windowmanager.go index b45eb42..799a54a 100644 --- a/windowmanager.go +++ b/windowmanager.go @@ -1,4 +1,4 @@ -package pinwindows +package pinwindows import rl "github.com/gen2brain/raylib-go/raylib" @@ -52,8 +52,8 @@ func (winman *RayGuiWindowManager) ProcessUserWindowMovement() { if winman.movingwindow != nil { if winman.movingwindowmode == WINDOW_MODE_DRAG { - winman.movingwindow.X += int32(rl.GetMouseDelta().X) - winman.movingwindow.Y += int32(rl.GetMouseDelta().Y) + winman.movingwindow.Pos.X += (rl.GetMouseDelta().X) + winman.movingwindow.Pos.Y += (rl.GetMouseDelta().Y) } if winman.movingwindowmode == WINDOW_MODE_RESZIE { winman.movingwindow.Resize(int(rl.GetMouseDelta().X), int(rl.GetMouseDelta().Y))