99 lines
2.8 KiB
Go
99 lines
2.8 KiB
Go
package pinwindows
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
rl "github.com/gen2brain/raylib-go/raylib"
|
|
)
|
|
|
|
type RayGuiWindow struct {
|
|
Texture *rl.RenderTexture2D
|
|
Pos rl.Vector2
|
|
Size rl.Vector2
|
|
DrawBorder bool
|
|
DrawFunc windowdrawfunc
|
|
ManageFunc managewindowfunc
|
|
AcceptingInput bool
|
|
}
|
|
|
|
const (
|
|
WINDOW_MODE_DRAG = 0
|
|
WINDOW_MODE_RESZIE = 1
|
|
WINDOW_MODE_NORMAL = 2
|
|
|
|
WINDOW_NO_EVENT = -1
|
|
)
|
|
|
|
type windowdrawfunc func(*RayGuiWindow)
|
|
|
|
func NewRayGuiWindow(x, y, w, h int) RayGuiWindow {
|
|
texture := rl.LoadRenderTexture(int32(w), int32(h))
|
|
|
|
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.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.Size.X), 20)) {
|
|
if rl.IsMouseButtonPressed(rl.MouseButtonLeft) {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
func (win *RayGuiWindow) DidStartResizeDrag() bool {
|
|
if win.IsTouchingRegion(rl.GetMousePosition(), rl.NewRectangle(0, 0, float32(win.Size.X), float32(win.Size.Y))) {
|
|
if rl.IsMouseButtonPressed(rl.MouseButtonRight) {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
func (window *RayGuiWindow) isLeftClicked() bool {
|
|
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.Pos.X), int(-window.Pos.Y))
|
|
} else {
|
|
rl.SetMouseOffset(-1000000, -1000000)
|
|
}
|
|
}
|
|
|
|
func (window *RayGuiWindow) EndDrawMode() {
|
|
rl.SetMouseOffset(0, 0)
|
|
rl.EndTextureMode()
|
|
}
|
|
|
|
func (window RayGuiWindow) IsTouchingRegion(posvec rl.Vector2, rect rl.Rectangle) bool {
|
|
|
|
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(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, int32(window.Pos.X), int32(window.Pos.Y))
|
|
}
|
|
|
|
func (window *RayGuiWindow) DrawInternals() {
|
|
if window.DrawFunc != nil {
|
|
window.DrawFunc(window)
|
|
}
|
|
|
|
}
|