Add experimental screen refresh

This commit is contained in:
Michał Gdula 2024-03-22 10:44:31 +00:00
parent 106ac0c797
commit 26fb4bb574
5 changed files with 80 additions and 34 deletions

4
go.mod
View file

@ -1,15 +1,13 @@
module ColouringApp module github.com/Fluffy-Bean/ColouringApp
go 1.21.5 go 1.21.5
require ( require (
github.com/gen2brain/raylib-go/raygui v0.0.0-20240110102818-483e94e4d92e github.com/gen2brain/raylib-go/raygui v0.0.0-20240110102818-483e94e4d92e
github.com/gen2brain/raylib-go/raylib v0.0.0-20240110102818-483e94e4d92e github.com/gen2brain/raylib-go/raylib v0.0.0-20240110102818-483e94e4d92e
github.com/huandu/go-sqlbuilder v1.25.0
) )
require ( require (
github.com/ebitengine/purego v0.6.0-alpha.1.0.20231122024802-192c5e846faa // indirect github.com/ebitengine/purego v0.6.0-alpha.1.0.20231122024802-192c5e846faa // indirect
github.com/huandu/xstrings v1.3.2 // indirect
golang.org/x/sys v0.14.0 // indirect golang.org/x/sys v0.14.0 // indirect
) )

14
go.sum
View file

@ -1,22 +1,8 @@
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/ebitengine/purego v0.6.0-alpha.1.0.20231122024802-192c5e846faa h1:Ik7QikRgeH+bFOfAcMpttCbs6XxWXxCLXMm4awxtOXk= github.com/ebitengine/purego v0.6.0-alpha.1.0.20231122024802-192c5e846faa h1:Ik7QikRgeH+bFOfAcMpttCbs6XxWXxCLXMm4awxtOXk=
github.com/ebitengine/purego v0.6.0-alpha.1.0.20231122024802-192c5e846faa/go.mod h1:ah1In8AOtksoNK6yk5z1HTJeUkC1Ez4Wk2idgGslMwQ= github.com/ebitengine/purego v0.6.0-alpha.1.0.20231122024802-192c5e846faa/go.mod h1:ah1In8AOtksoNK6yk5z1HTJeUkC1Ez4Wk2idgGslMwQ=
github.com/gen2brain/raylib-go/raygui v0.0.0-20240110102818-483e94e4d92e h1:rbZ3Fy7hRHL/GLcm9sCt3N2tjTPGT9EwGwvVHTuVnJQ= github.com/gen2brain/raylib-go/raygui v0.0.0-20240110102818-483e94e4d92e h1:rbZ3Fy7hRHL/GLcm9sCt3N2tjTPGT9EwGwvVHTuVnJQ=
github.com/gen2brain/raylib-go/raygui v0.0.0-20240110102818-483e94e4d92e/go.mod h1:Ra1zgJP7vnGst+STvzPPiVJhjicklFWONCz5nu6MnOM= github.com/gen2brain/raylib-go/raygui v0.0.0-20240110102818-483e94e4d92e/go.mod h1:Ra1zgJP7vnGst+STvzPPiVJhjicklFWONCz5nu6MnOM=
github.com/gen2brain/raylib-go/raylib v0.0.0-20240110102818-483e94e4d92e h1:t/kVA/quBlzLB+43QzIsHkFQrZs2ii79rk9NOofbQxs= github.com/gen2brain/raylib-go/raylib v0.0.0-20240110102818-483e94e4d92e h1:t/kVA/quBlzLB+43QzIsHkFQrZs2ii79rk9NOofbQxs=
github.com/gen2brain/raylib-go/raylib v0.0.0-20240110102818-483e94e4d92e/go.mod h1:P/hDjVwz/9fhR0ww3+umzDpDA7Bf7Tce4xNChHIEFqE= github.com/gen2brain/raylib-go/raylib v0.0.0-20240110102818-483e94e4d92e/go.mod h1:P/hDjVwz/9fhR0ww3+umzDpDA7Bf7Tce4xNChHIEFqE=
github.com/huandu/go-assert v1.1.5 h1:fjemmA7sSfYHJD7CUqs9qTwwfdNAx7/j2/ZlHXzNB3c=
github.com/huandu/go-assert v1.1.5/go.mod h1:yOLvuqZwmcHIC5rIzrBhT7D3Q9c3GFnd0JrPVhn/06U=
github.com/huandu/go-sqlbuilder v1.25.0 h1:h1l+6CqeCviPJCnkEZoRGNdfZ5RO9BKMvG3A+1VuKNM=
github.com/huandu/go-sqlbuilder v1.25.0/go.mod h1:nUVmMitjOmn/zacMLXT0d3Yd3RHoO2K+vy906JzqxMI=
github.com/huandu/xstrings v1.3.2 h1:L18LIDzqlW6xN2rEkpdV8+oL/IXWJ1APd+vsdYy4Wdw=
github.com/huandu/xstrings v1.3.2/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
golang.org/x/sys v0.14.0 h1:Vz7Qs629MkJkGyHxUlRHizWJRG2j8fbQKjELVSNhy7Q= 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.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=

71
main.go
View file

@ -14,14 +14,15 @@ import (
func main() { func main() {
// Initialize raylib // Initialize raylib
raylib.SetConfigFlags(raylib.FlagWindowResizable) // | raylib.FlagWindowHighdpi | raylib.FlagMsaa4xHint) raylib.SetConfigFlags(raylib.FlagWindowResizable | raylib.FlagWindowHighdpi | raylib.FlagMsaa4xHint)
raylib.InitWindow(applicationWindowWidth, applicationWindowHeight, applicationTitle) raylib.InitWindow(applicationWindowWidth, applicationWindowHeight, applicationTitle)
raylib.SetWindowMinSize(int(applicationMinWindowWidth), int(applicationMinWindowHeight)) raylib.SetWindowMinSize(int(applicationMinWindowWidth), int(applicationMinWindowHeight))
// raylib.SetTargetFPS(int32(raylib.GetMonitorRefreshRate(raylib.GetCurrentMonitor()))) raylib.SetTargetFPS(int32(raylib.GetMonitorRefreshRate(raylib.GetCurrentMonitor())))
raylib.SetTargetFPS(60)
raylib.SetExitKey(raylib.KeyNull) raylib.SetExitKey(raylib.KeyNull)
raylib.HideCursor() raylib.HideCursor()
defer raylib.CloseWindow()
// Make sure both assets and userData directories exist // Make sure both assets and userData directories exist
if _, err := os.Stat(dirAssets); os.IsNotExist(err) { if _, err := os.Stat(dirAssets); os.IsNotExist(err) {
panic("Assets directory not found") panic("Assets directory not found")
@ -96,6 +97,10 @@ func main() {
if raylib.IsKeyPressed(raylib.KeyF8) { if raylib.IsKeyPressed(raylib.KeyF8) {
applicationShowDebugValues = !applicationShowDebugValues applicationShowDebugValues = !applicationShowDebugValues
} }
if raylib.IsKeyPressed(raylib.KeyF9) {
applicationExperimentalUpdates = !applicationExperimentalUpdates
addToast("Experimental Updates: " + strconv.FormatBool(applicationExperimentalUpdates))
}
if raylib.IsKeyPressed(raylib.KeyF12) { if raylib.IsKeyPressed(raylib.KeyF12) {
addToast("Screenshot saved!") addToast("Screenshot saved!")
} }
@ -134,7 +139,7 @@ func main() {
newRectangleStroke = rectangleTool{ newRectangleStroke = rectangleTool{
StartPos: raylib.GetMousePosition(), StartPos: raylib.GetMousePosition(),
EndPos: raylib.GetMousePosition(), EndPos: raylib.GetMousePosition(),
Rounded: false, Rounded: true,
Color: toolPanelColourPicker, Color: toolPanelColourPicker,
Size: toolPanelBrushSize, Size: toolPanelBrushSize,
} }
@ -151,7 +156,6 @@ func main() {
applicationState = StateNormal applicationState = StateNormal
} }
case toolPointer: case toolPointer:
fallthrough
default: default:
// yyeeeeet // yyeeeeet
} }
@ -177,11 +181,56 @@ func main() {
canvas.Update() canvas.Update()
updateToasts() updateToasts()
if !applicationExperimentalUpdates {
applicationShouldDraw = true
} else {
if applicationRuntime > 1 {
applicationShouldDraw = false
}
if raylib.IsWindowResized() {
applicationShouldDraw = true
fmt.Println("Updating render: Window Resized")
}
if applicationLastMousePos != raylib.GetMousePosition() {
applicationShouldDraw = true
applicationLastMousePos = raylib.GetMousePosition()
fmt.Println("Updating render: Mouse moved")
}
if toastShouldUpdate {
applicationShouldDraw = true
fmt.Println("Updating render: Toasts")
}
if applicationState != applicationLastState {
applicationShouldDraw = true
applicationLastState = applicationState
fmt.Println("Updating render: State")
}
if raylib.GetKeyPressed() != 0 {
applicationShouldDraw = true
fmt.Println("Updating render: GUI")
}
if raylib.IsMouseButtonDown(raylib.MouseLeftButton) || raylib.IsMouseButtonDown(raylib.MouseRightButton) {
applicationShouldDraw = true
fmt.Println("Updating render: Mouse Button")
}
if raylib.IsMouseButtonReleased(raylib.MouseLeftButton) || raylib.IsMouseButtonReleased(raylib.MouseRightButton) {
applicationShouldDraw = true
fmt.Println("Updating render: Mouse Button Released")
}
if raylib.IsMouseButtonPressed(raylib.MouseLeftButton) || raylib.IsMouseButtonPressed(raylib.MouseRightButton) {
applicationShouldDraw = true
fmt.Println("Updating render: Mouse Button Pressed")
}
}
} }
// DRAW // DRAW
// check if gui changes are needed
raylib.BeginDrawing() raylib.BeginDrawing()
{ if applicationShouldDraw {
raylib.ClearBackground(raylib.White) raylib.ClearBackground(raylib.White)
gui.Grid(raylib.NewRectangle(0, 0, float32(applicationWindowWidth), float32(applicationWindowHeight)), "", 30, 1, &raylib.Vector2{}) gui.Grid(raylib.NewRectangle(0, 0, float32(applicationWindowWidth), float32(applicationWindowHeight)), "", 30, 1, &raylib.Vector2{})
@ -504,10 +553,14 @@ func main() {
} }
drawToasts() drawToasts()
if applicationShowDebugValues && applicationExperimentalUpdates {
if applicationShowdebugUpdate {
raylib.DrawRectangle(0, 0, 200, 20, raylib.Fade(raylib.Black, 0.5))
}
applicationShowdebugUpdate = !applicationShowdebugUpdate
}
} }
raylib.EndDrawing() raylib.EndDrawing()
} }
// GOODBYE
raylib.CloseWindow()
} }

View file

@ -14,6 +14,7 @@ type toast struct {
var ( var (
toasts []toast toasts []toast
toastShouldUpdate = true
toastDimHeight = float32(0) toastDimHeight = float32(0)
) )
@ -36,6 +37,8 @@ func updateToasts() {
} }
} }
toasts = t toasts = t
toastShouldUpdate = int(toastDimHeight) != 0
} }
func drawToasts() { func drawToasts() {

10
vars.go
View file

@ -35,11 +35,17 @@ const (
var ( var (
applicationState = StateNormal applicationState = StateNormal
applicationLastState = StateNormal
applicationShouldQuit = false applicationShouldQuit = false
applicationShowDebugValues = false applicationShouldDraw = true
applicationLastMousePos = raylib.Vector2{}
applicationWindowWidth = applicationMinWindowWidth applicationWindowWidth = applicationMinWindowWidth
applicationWindowHeight = applicationMinWindowHeight applicationWindowHeight = applicationMinWindowHeight
applicationRuntime = float32(0) applicationRuntime = 0
applicationExperimentalUpdates = false
applicationShowDebugValues = false
applicationShowdebugUpdate = false
) )
var ( var (