erm
This commit is contained in:
parent
1fd13fa66f
commit
34b3c75bf9
31
window.go
31
window.go
|
@ -8,10 +8,8 @@ import (
|
||||||
|
|
||||||
type RayGuiWindow struct {
|
type RayGuiWindow struct {
|
||||||
Texture *rl.RenderTexture2D
|
Texture *rl.RenderTexture2D
|
||||||
X int32
|
Pos rl.Vector2
|
||||||
Y int32
|
Size rl.Vector2
|
||||||
W int32
|
|
||||||
H int32
|
|
||||||
DrawBorder bool
|
DrawBorder bool
|
||||||
DrawFunc windowdrawfunc
|
DrawFunc windowdrawfunc
|
||||||
ManageFunc managewindowfunc
|
ManageFunc managewindowfunc
|
||||||
|
@ -31,18 +29,18 @@ type windowdrawfunc func(*RayGuiWindow)
|
||||||
func NewRayGuiWindow(x, y, w, h int) RayGuiWindow {
|
func NewRayGuiWindow(x, y, w, h int) RayGuiWindow {
|
||||||
texture := rl.LoadRenderTexture(int32(w), int32(h))
|
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) {
|
func (win *RayGuiWindow) Resize(x, y int) {
|
||||||
rl.UnloadRenderTexture(*win.Texture)
|
rl.UnloadRenderTexture(*win.Texture)
|
||||||
win.W += int32(x)
|
win.Size.X += float32(x)
|
||||||
win.H += int32(y)
|
win.Size.Y += float32(y)
|
||||||
*win.Texture = rl.LoadRenderTexture(int32(win.W), int32(win.H))
|
*win.Texture = rl.LoadRenderTexture(int32(win.Size.X), int32(win.Size.Y))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (win *RayGuiWindow) DidStartMoveDrag() bool {
|
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) {
|
if rl.IsMouseButtonPressed(rl.MouseButtonLeft) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
@ -51,7 +49,7 @@ func (win *RayGuiWindow) DidStartMoveDrag() bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (win *RayGuiWindow) DidStartResizeDrag() 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) {
|
if rl.IsMouseButtonPressed(rl.MouseButtonRight) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
@ -60,13 +58,13 @@ func (win *RayGuiWindow) DidStartResizeDrag() bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (window *RayGuiWindow) isLeftClicked() 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() {
|
func (window *RayGuiWindow) BeginDrawMode() {
|
||||||
rl.BeginTextureMode(*window.Texture)
|
rl.BeginTextureMode(*window.Texture)
|
||||||
if window.AcceptingInput {
|
if window.AcceptingInput {
|
||||||
rl.SetMouseOffset(int(-window.X), int(-window.Y))
|
rl.SetMouseOffset(int(-window.Pos.X), int(-window.Pos.Y))
|
||||||
} else {
|
} else {
|
||||||
rl.SetMouseOffset(-1000000, -1000000)
|
rl.SetMouseOffset(-1000000, -1000000)
|
||||||
}
|
}
|
||||||
|
@ -79,18 +77,17 @@ func (window *RayGuiWindow) EndDrawMode() {
|
||||||
|
|
||||||
func (window RayGuiWindow) IsTouchingRegion(posvec rl.Vector2, rect rl.Rectangle) bool {
|
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 true
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (window *RayGuiWindow) Draw() {
|
func (window *RayGuiWindow) Draw() {
|
||||||
rl.DrawRectangle(window.X, window.Y-20, window.W, 20, rl.Gray)
|
rl.DrawRectangle(int32(window.Pos.X), int32(window.Pos.Y)-20, int32(window.Size.X), 20, rl.Gray)
|
||||||
rl.DrawText(fmt.Sprint(window.AcceptingInput), window.X-20, window.Y-20, 12, rl.Blue)
|
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)
|
//fmt.Printf("WindowDraw at %i, %i\n", window.X, window.Y)
|
||||||
|
DrawTextureFlipped(&window.Texture.Texture, int32(window.Pos.X), int32(window.Pos.Y))
|
||||||
DrawTextureFlipped(&window.Texture.Texture, window.X, window.Y)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (window *RayGuiWindow) DrawInternals() {
|
func (window *RayGuiWindow) DrawInternals() {
|
||||||
|
|
|
@ -52,8 +52,8 @@ func (winman *RayGuiWindowManager) ProcessUserWindowMovement() {
|
||||||
|
|
||||||
if winman.movingwindow != nil {
|
if winman.movingwindow != nil {
|
||||||
if winman.movingwindowmode == WINDOW_MODE_DRAG {
|
if winman.movingwindowmode == WINDOW_MODE_DRAG {
|
||||||
winman.movingwindow.X += int32(rl.GetMouseDelta().X)
|
winman.movingwindow.Pos.X += (rl.GetMouseDelta().X)
|
||||||
winman.movingwindow.Y += int32(rl.GetMouseDelta().Y)
|
winman.movingwindow.Pos.Y += (rl.GetMouseDelta().Y)
|
||||||
}
|
}
|
||||||
if winman.movingwindowmode == WINDOW_MODE_RESZIE {
|
if winman.movingwindowmode == WINDOW_MODE_RESZIE {
|
||||||
winman.movingwindow.Resize(int(rl.GetMouseDelta().X), int(rl.GetMouseDelta().Y))
|
winman.movingwindow.Resize(int(rl.GetMouseDelta().X), int(rl.GetMouseDelta().Y))
|
||||||
|
|
Loading…
Reference in a new issue