renamed structs and functions to better fit packages and added a test program
This commit is contained in:
parent
9783251f41
commit
f3ac5a48d5
50
frame.go
Normal file
50
frame.go
Normal file
|
@ -0,0 +1,50 @@
|
|||
package pinwindows
|
||||
|
||||
import (
|
||||
// "fmt"
|
||||
|
||||
rl "github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
// frame struct - used for grouping elements together. Will eventually be drawable and autodraw a
|
||||
// list of elements that will be autoreized and managed by the frame
|
||||
type Frame struct {
|
||||
Texture *rl.RenderTexture2D
|
||||
Size rl.Vector2
|
||||
ScrollH bool
|
||||
ScrollW bool
|
||||
ScrollOffsetH float32
|
||||
ScrollOffsetW float32
|
||||
}
|
||||
|
||||
func NewFrame(w, h int) Frame {
|
||||
texture := rl.LoadRenderTexture(int32(w), int32(h))
|
||||
rframe := Frame{}
|
||||
rframe.Texture = &texture
|
||||
rframe.Size = rl.Vector2{X: float32(w), Y: float32(h)}
|
||||
return Frame{Texture: &texture, Size: rl.Vector2{X: float32(w), Y: float32(h)}, ScrollW: false, ScrollH: false}
|
||||
|
||||
}
|
||||
|
||||
func (f *Frame) Resize(w, h int) {
|
||||
rl.UnloadRenderTexture(*f.Texture)
|
||||
f.Size.X += float32(w)
|
||||
f.Size.Y += float32(h)
|
||||
*f.Texture = rl.LoadRenderTexture(int32(f.Size.X), int32(f.Size.Y))
|
||||
}
|
||||
|
||||
func (f *Frame) BeginDrawMode() {
|
||||
rl.BeginTextureMode(*f.Texture)
|
||||
var startposH int32 = int32(0 + f.ScrollOffsetH)
|
||||
var startposW int32 = int32(0 + f.ScrollOffsetW)
|
||||
rl.BeginScissorMode(startposW, startposH, int32(f.Size.X-float32(startposW)), int32(f.Size.Y-float32(startposH)))
|
||||
}
|
||||
|
||||
func (f *Frame) EndDrawMode() {
|
||||
rl.EndScissorMode()
|
||||
rl.EndTextureMode()
|
||||
}
|
||||
|
||||
func (f *Frame) Draw() {
|
||||
DrawTextureFlipped(&f.Texture.Texture, 0, 0)
|
||||
}
|
7
go.mod
7
go.mod
|
@ -2,9 +2,12 @@ module git.dummkopf.live/InventorX/pinwindows
|
|||
|
||||
go 1.22.2
|
||||
|
||||
require github.com/gen2brain/raylib-go/raylib v0.0.0-20240421191056-278df68f40bb
|
||||
require (
|
||||
github.com/gen2brain/raylib-go/raygui v0.0.0-20240522200953-b7c9eeec1b29
|
||||
github.com/gen2brain/raylib-go/raylib v0.0.0-20240522200953-b7c9eeec1b29
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/ebitengine/purego v0.7.1 // indirect
|
||||
golang.org/x/sys v0.19.0 // indirect
|
||||
golang.org/x/sys v0.20.0 // indirect
|
||||
)
|
||||
|
|
6
go.sum
6
go.sum
|
@ -2,11 +2,17 @@ github.com/ebitengine/purego v0.6.0-alpha.1.0.20231122024802-192c5e846faa h1:Ik7
|
|||
github.com/ebitengine/purego v0.6.0-alpha.1.0.20231122024802-192c5e846faa/go.mod h1:ah1In8AOtksoNK6yk5z1HTJeUkC1Ez4Wk2idgGslMwQ=
|
||||
github.com/ebitengine/purego v0.7.1 h1:6/55d26lG3o9VCZX8lping+bZcmShseiqlh2bnUDiPA=
|
||||
github.com/ebitengine/purego v0.7.1/go.mod h1:ah1In8AOtksoNK6yk5z1HTJeUkC1Ez4Wk2idgGslMwQ=
|
||||
github.com/gen2brain/raylib-go/raygui v0.0.0-20240522200953-b7c9eeec1b29 h1:9bC6G+GJcebNe4y7AQTASzbq/35uCAZpna5Yaxh5fY8=
|
||||
github.com/gen2brain/raylib-go/raygui v0.0.0-20240522200953-b7c9eeec1b29/go.mod h1:Ra1zgJP7vnGst+STvzPPiVJhjicklFWONCz5nu6MnOM=
|
||||
github.com/gen2brain/raylib-go/raylib v0.0.0-20240418150228-9548fadb54e6 h1:mNKFgLZIU0eEHKHjb7Uk9ZuSy65DdgmEf2xxum0Tof4=
|
||||
github.com/gen2brain/raylib-go/raylib v0.0.0-20240418150228-9548fadb54e6/go.mod h1:P/hDjVwz/9fhR0ww3+umzDpDA7Bf7Tce4xNChHIEFqE=
|
||||
github.com/gen2brain/raylib-go/raylib v0.0.0-20240421191056-278df68f40bb h1:2CdDr/LfDc9uLOW/+3ffSM5Ia7xZZMgjC6UmP7KTjRw=
|
||||
github.com/gen2brain/raylib-go/raylib v0.0.0-20240421191056-278df68f40bb/go.mod h1:P/hDjVwz/9fhR0ww3+umzDpDA7Bf7Tce4xNChHIEFqE=
|
||||
github.com/gen2brain/raylib-go/raylib v0.0.0-20240522200953-b7c9eeec1b29 h1:PcZhEzXyuccb+d27B2txaUsD3/cBlGKiS8BE8qgBC6c=
|
||||
github.com/gen2brain/raylib-go/raylib v0.0.0-20240522200953-b7c9eeec1b29/go.mod h1:76svhwieyfOFogKyYbDwqjPSTaWFDp1aDk0sLsQoO5k=
|
||||
golang.org/x/sys v0.14.0 h1:Vz7Qs629MkJkGyHxUlRHizWJRG2j8fbQKjELVSNhy7Q=
|
||||
golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o=
|
||||
golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y=
|
||||
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
|
|
82
maintest/main.go
Normal file
82
maintest/main.go
Normal file
|
@ -0,0 +1,82 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
gui "github.com/gen2brain/raylib-go/raygui"
|
||||
rl "github.com/gen2brain/raylib-go/raylib"
|
||||
|
||||
"git.dummkopf.live/InventorX/pinwindows"
|
||||
)
|
||||
|
||||
const RENDERWIDTH = 1920
|
||||
const RENDERHEIGHT = 1080
|
||||
|
||||
const SCREENWIDTH = 1280
|
||||
const SCREENHEIGHT = 720
|
||||
|
||||
func DrawButtonAt00(window *pinwindows.Window) {
|
||||
//fmt.Println(window)
|
||||
window.BeginDrawMode()
|
||||
rl.ClearBackground(rl.White)
|
||||
close := gui.Button(rl.NewRectangle(0, 0, 20, 20), "Ha")
|
||||
if close {
|
||||
window.ManageFunc = pinwindows.CloseWindow
|
||||
}
|
||||
window.EndDrawMode()
|
||||
}
|
||||
|
||||
func main() {
|
||||
rl.InitWindow(SCREENWIDTH, SCREENHEIGHT, "raylib [core] example - basic window")
|
||||
rl.SetWindowState(rl.FlagWindowResizable)
|
||||
defer rl.CloseWindow()
|
||||
|
||||
rl.SetTargetFPS(int32(rl.GetMonitorRefreshRate(0)))
|
||||
a := rl.GetMonitorPosition(0)
|
||||
mh := rl.GetMonitorHeight(0)
|
||||
mw := rl.GetMonitorWidth(0)
|
||||
rl.SetWindowPosition(int(a.X)+int(0.5*float32(mw))-(SCREENWIDTH/2), int(a.Y)+int(0.5*float32(mh))-(0.5*SCREENHEIGHT))
|
||||
|
||||
wm := pinwindows.NewWindowManager()
|
||||
|
||||
rendertexture := rl.LoadRenderTexture(SCREENWIDTH, SCREENHEIGHT)
|
||||
|
||||
raywin := pinwindows.NewWindow(100, 100, 200, 200)
|
||||
|
||||
wm.AddWindow(&raywin)
|
||||
|
||||
for !rl.WindowShouldClose() {
|
||||
wm.ManageWindowlist()
|
||||
wm.ProcessUserWindowMovement()
|
||||
|
||||
raywin.BeginDrawMode()
|
||||
rl.ClearBackground(rl.White)
|
||||
ispressed := gui.Button(rl.NewRectangle(0, 0, 50, 50), "new")
|
||||
raywin.EndDrawMode()
|
||||
|
||||
if ispressed {
|
||||
newwindow := pinwindows.NewWindow(50, 50, 200, 200)
|
||||
newwindow.DrawBorder = true
|
||||
newwindow.DrawFunc = DrawButtonAt00
|
||||
wm.AddWindow(&newwindow)
|
||||
}
|
||||
|
||||
pinwindows.UpdateRenderTexture(&rendertexture)
|
||||
|
||||
wm.DrawInternalWindowList()
|
||||
rl.BeginTextureMode(rendertexture)
|
||||
rl.ClearBackground(rl.Black)
|
||||
|
||||
wm.DrawWindowlist()
|
||||
|
||||
rl.EndTextureMode()
|
||||
|
||||
rl.BeginDrawing()
|
||||
pinwindows.DrawTextureFlipped(&rendertexture.Texture, 0, 0)
|
||||
rl.EndDrawing()
|
||||
|
||||
}
|
||||
|
||||
fmt.Println("test")
|
||||
pinwindows.Testfunc()
|
||||
}
|
6
other.go
6
other.go
|
@ -6,3 +6,9 @@ func DrawTextureFlipped(rentex *rl.Texture2D, posx, posy int32) {
|
|||
rl.DrawTexturePro(*rentex, rl.NewRectangle(0, 0, float32(rentex.Width), -float32(rentex.Height)), rl.NewRectangle(float32(posx), float32(posy), float32(rentex.Width), float32(rentex.Height)), rl.NewVector2(0, 0), 0, rl.White)
|
||||
}
|
||||
|
||||
func UpdateRenderTexture(texture *rl.RenderTexture2D) {
|
||||
if rl.IsWindowResized() {
|
||||
rl.UnloadRenderTexture(*texture)
|
||||
*texture = rl.LoadRenderTexture(int32(rl.GetScreenWidth()), int32(rl.GetScreenHeight()))
|
||||
}
|
||||
}
|
||||
|
|
36
window.go
36
window.go
|
@ -6,7 +6,7 @@ import (
|
|||
rl "github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
type RayGuiWindow struct {
|
||||
type Window struct {
|
||||
Texture *rl.RenderTexture2D
|
||||
Pos rl.Vector2
|
||||
Size rl.Vector2
|
||||
|
@ -24,15 +24,19 @@ const (
|
|||
WINDOW_NO_EVENT = -1
|
||||
)
|
||||
|
||||
type windowdrawfunc func(*RayGuiWindow)
|
||||
type windowdrawfunc func(*Window)
|
||||
|
||||
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 Testfunc() {
|
||||
fmt.Println("erm")
|
||||
}
|
||||
|
||||
func (win *RayGuiWindow) GetBorderRect() rl.Rectangle {
|
||||
func NewWindow(x, y, w, h int) Window {
|
||||
texture := rl.LoadRenderTexture(int32(w), int32(h))
|
||||
|
||||
return Window{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 *Window) GetBorderRect() rl.Rectangle {
|
||||
if win.DrawBorder {
|
||||
return rl.NewRectangle(0, 0, win.Size.X, 20)
|
||||
} else {
|
||||
|
@ -40,14 +44,14 @@ func (win *RayGuiWindow) GetBorderRect() rl.Rectangle {
|
|||
}
|
||||
}
|
||||
|
||||
func (win *RayGuiWindow) Resize(x, y int) {
|
||||
func (win *Window) ResizeDelta(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 {
|
||||
func (win *Window) DidStartMoveDrag() bool {
|
||||
if win.IsTouchingRegion(rl.GetMousePosition(), rl.NewRectangle(0, -win.GetBorderRect().Height, float32(win.Size.X), win.GetBorderRect().Height)) {
|
||||
if rl.IsMouseButtonPressed(rl.MouseButtonLeft) {
|
||||
return true
|
||||
|
@ -56,7 +60,7 @@ func (win *RayGuiWindow) DidStartMoveDrag() bool {
|
|||
return false
|
||||
}
|
||||
|
||||
func (win *RayGuiWindow) DidStartResizeDrag() bool {
|
||||
func (win *Window) 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
|
||||
|
@ -65,11 +69,11 @@ func (win *RayGuiWindow) DidStartResizeDrag() bool {
|
|||
return false
|
||||
}
|
||||
|
||||
func (window *RayGuiWindow) isLeftClicked() bool {
|
||||
func (window *Window) isLeftClicked() bool {
|
||||
return rl.IsMouseButtonPressed(rl.MouseButtonLeft) && rl.CheckCollisionPointRec(rl.GetMousePosition(), rl.NewRectangle(float32(window.Pos.X), float32(window.Pos.Y-window.GetBorderRect().Height), float32(window.Size.X), float32(window.Size.Y+window.GetBorderRect().Height)))
|
||||
}
|
||||
|
||||
func (window *RayGuiWindow) BeginDrawMode() {
|
||||
func (window *Window) BeginDrawMode() {
|
||||
rl.BeginTextureMode(*window.Texture)
|
||||
if window.AcceptingInput {
|
||||
rl.SetMouseOffset(int(-window.Pos.X), int(-window.Pos.Y))
|
||||
|
@ -78,12 +82,12 @@ func (window *RayGuiWindow) BeginDrawMode() {
|
|||
}
|
||||
}
|
||||
|
||||
func (window *RayGuiWindow) EndDrawMode() {
|
||||
func (window *Window) EndDrawMode() {
|
||||
rl.SetMouseOffset(0, 0)
|
||||
rl.EndTextureMode()
|
||||
}
|
||||
|
||||
func (window RayGuiWindow) IsTouchingRegion(posvec rl.Vector2, rect rl.Rectangle) bool {
|
||||
func (window Window) 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
|
||||
|
@ -91,7 +95,7 @@ func (window RayGuiWindow) IsTouchingRegion(posvec rl.Vector2, rect rl.Rectangle
|
|||
return false
|
||||
}
|
||||
|
||||
func (window *RayGuiWindow) Draw() {
|
||||
func (window *Window) Draw() {
|
||||
rl.DrawRectangle(int32(window.Pos.X), int32(window.Pos.Y)-int32(window.GetBorderRect().Height), int32(window.Size.X), int32(window.GetBorderRect().Height), rl.Gray)
|
||||
|
||||
rl.DrawText(fmt.Sprint(window.AcceptingInput), int32(window.Pos.X-20), int32(window.Pos.Y)-20, 12, rl.Blue)
|
||||
|
@ -99,7 +103,7 @@ func (window *RayGuiWindow) Draw() {
|
|||
DrawTextureFlipped(&window.Texture.Texture, int32(window.Pos.X), int32(window.Pos.Y))
|
||||
}
|
||||
|
||||
func (window *RayGuiWindow) DrawInternals() {
|
||||
func (window *Window) DrawInternals() {
|
||||
if window.DrawFunc != nil {
|
||||
window.DrawFunc(window)
|
||||
}
|
||||
|
|
|
@ -4,21 +4,21 @@ import (
|
|||
rl "github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
type managewindowfunc func(*RayGuiWindowManager, *RayGuiWindow)
|
||||
type managewindowfunc func(*WindowManager, *Window)
|
||||
|
||||
type RayGuiWindowManager struct {
|
||||
Winlist []*RayGuiWindow
|
||||
Movingwindow *RayGuiWindow // the currently moving (resize, drag, etc...)
|
||||
type WindowManager struct {
|
||||
Winlist []*Window
|
||||
Movingwindow *Window // the currently moving (resize, drag, etc...)
|
||||
Movingwindowmode int
|
||||
}
|
||||
|
||||
func NewRayGuiWindowManager() RayGuiWindowManager {
|
||||
var windowlist []*RayGuiWindow
|
||||
return RayGuiWindowManager{Winlist: windowlist, Movingwindow: nil}
|
||||
func NewWindowManager() WindowManager {
|
||||
var windowlist []*Window
|
||||
return WindowManager{Winlist: windowlist, Movingwindow: nil}
|
||||
}
|
||||
|
||||
func (winman *RayGuiWindowManager) ManageWindowlist() {
|
||||
var windowtomovetofront *RayGuiWindow = nil
|
||||
func (winman *WindowManager) ManageWindowlist() {
|
||||
var windowtomovetofront *Window = nil
|
||||
for i := 0; i < len(winman.Winlist); i++ {
|
||||
if winman.Winlist[i].isLeftClicked() {
|
||||
windowtomovetofront = winman.Winlist[i]
|
||||
|
@ -34,7 +34,7 @@ func (winman *RayGuiWindowManager) ManageWindowlist() {
|
|||
}
|
||||
}
|
||||
|
||||
func (winman *RayGuiWindowManager) ProcessUserWindowMovement() {
|
||||
func (winman *WindowManager) ProcessUserWindowMovement() {
|
||||
currentmovingwindow := winman.Movingwindow
|
||||
|
||||
for i := 0; i < len(winman.Winlist); i++ {
|
||||
|
@ -57,24 +57,24 @@ func (winman *RayGuiWindowManager) ProcessUserWindowMovement() {
|
|||
winman.Movingwindow.Pos.Y += (rl.GetMouseDelta().Y)
|
||||
}
|
||||
if winman.Movingwindowmode == WINDOW_MODE_RESZIE {
|
||||
winman.Movingwindow.Resize(int(rl.GetMouseDelta().X), int(rl.GetMouseDelta().Y))
|
||||
winman.Movingwindow.ResizeDelta(int(rl.GetMouseDelta().X), int(rl.GetMouseDelta().Y))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (winman RayGuiWindowManager) DrawInternalWindowList() {
|
||||
func (winman WindowManager) DrawInternalWindowList() {
|
||||
for i := 0; i < len(winman.Winlist); i++ {
|
||||
winman.Winlist[i].DrawInternals()
|
||||
}
|
||||
}
|
||||
|
||||
func (winman RayGuiWindowManager) DrawWindowlist() {
|
||||
func (winman WindowManager) DrawWindowlist() {
|
||||
for i := 0; i < len(winman.Winlist); i++ {
|
||||
winman.Winlist[i].Draw()
|
||||
}
|
||||
}
|
||||
|
||||
func (winman *RayGuiWindowManager) WinlistUnlistWindow(windowtoremove *RayGuiWindow) {
|
||||
func (winman *WindowManager) WinlistUnlistWindow(windowtoremove *Window) {
|
||||
indextoremove := -1
|
||||
for i := 0; i < len(winman.Winlist); i++ {
|
||||
if winman.Winlist[i] == windowtoremove {
|
||||
|
@ -91,7 +91,7 @@ func (winman *RayGuiWindowManager) WinlistUnlistWindow(windowtoremove *RayGuiWin
|
|||
return
|
||||
}
|
||||
|
||||
func CloseWindow(winman *RayGuiWindowManager, windowtoremove *RayGuiWindow) {
|
||||
func CloseWindow(winman *WindowManager, windowtoremove *Window) {
|
||||
winman.WinlistUnlistWindow(windowtoremove)
|
||||
rl.UnloadRenderTexture(*windowtoremove.Texture)
|
||||
if winman.Movingwindow == windowtoremove {
|
||||
|
@ -100,7 +100,7 @@ func CloseWindow(winman *RayGuiWindowManager, windowtoremove *RayGuiWindow) {
|
|||
return
|
||||
}
|
||||
|
||||
func (winman *RayGuiWindowManager) AddWindow(windowtoadd *RayGuiWindow) {
|
||||
func (winman *WindowManager) AddWindow(windowtoadd *Window) {
|
||||
if len(winman.Winlist) > 0 {
|
||||
winman.Winlist[len(winman.Winlist)-1].AcceptingInput = false
|
||||
}
|
||||
|
@ -108,7 +108,7 @@ func (winman *RayGuiWindowManager) AddWindow(windowtoadd *RayGuiWindow) {
|
|||
winman.Winlist[len(winman.Winlist)-1].AcceptingInput = true
|
||||
}
|
||||
|
||||
func MoveToTopOfWindowlist(winman *RayGuiWindowManager, windowtomove *RayGuiWindow) {
|
||||
func MoveToTopOfWindowlist(winman *WindowManager, windowtomove *Window) {
|
||||
winman.Winlist[len(winman.Winlist)-1].AcceptingInput = false
|
||||
winman.WinlistUnlistWindow(windowtomove)
|
||||
winman.AddWindow(windowtomove)
|
||||
|
|
Loading…
Reference in a new issue