mirror of
https://github.com/Fluffy-Bean/ColouringApp.git
synced 2025-02-17 23:50:05 +00:00
Add experimental screen refresh
This commit is contained in:
parent
106ac0c797
commit
26fb4bb574
4
go.mod
4
go.mod
|
@ -1,15 +1,13 @@
|
|||
module ColouringApp
|
||||
module github.com/Fluffy-Bean/ColouringApp
|
||||
|
||||
go 1.21.5
|
||||
|
||||
require (
|
||||
github.com/gen2brain/raylib-go/raygui 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 (
|
||||
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
|
||||
)
|
||||
|
|
14
go.sum
14
go.sum
|
@ -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/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/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/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/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
71
main.go
|
@ -14,14 +14,15 @@ import (
|
|||
|
||||
func main() {
|
||||
// Initialize raylib
|
||||
raylib.SetConfigFlags(raylib.FlagWindowResizable) // | raylib.FlagWindowHighdpi | raylib.FlagMsaa4xHint)
|
||||
raylib.SetConfigFlags(raylib.FlagWindowResizable | raylib.FlagWindowHighdpi | raylib.FlagMsaa4xHint)
|
||||
raylib.InitWindow(applicationWindowWidth, applicationWindowHeight, applicationTitle)
|
||||
raylib.SetWindowMinSize(int(applicationMinWindowWidth), int(applicationMinWindowHeight))
|
||||
// raylib.SetTargetFPS(int32(raylib.GetMonitorRefreshRate(raylib.GetCurrentMonitor())))
|
||||
raylib.SetTargetFPS(60)
|
||||
raylib.SetTargetFPS(int32(raylib.GetMonitorRefreshRate(raylib.GetCurrentMonitor())))
|
||||
raylib.SetExitKey(raylib.KeyNull)
|
||||
raylib.HideCursor()
|
||||
|
||||
defer raylib.CloseWindow()
|
||||
|
||||
// Make sure both assets and userData directories exist
|
||||
if _, err := os.Stat(dirAssets); os.IsNotExist(err) {
|
||||
panic("Assets directory not found")
|
||||
|
@ -96,6 +97,10 @@ func main() {
|
|||
if raylib.IsKeyPressed(raylib.KeyF8) {
|
||||
applicationShowDebugValues = !applicationShowDebugValues
|
||||
}
|
||||
if raylib.IsKeyPressed(raylib.KeyF9) {
|
||||
applicationExperimentalUpdates = !applicationExperimentalUpdates
|
||||
addToast("Experimental Updates: " + strconv.FormatBool(applicationExperimentalUpdates))
|
||||
}
|
||||
if raylib.IsKeyPressed(raylib.KeyF12) {
|
||||
addToast("Screenshot saved!")
|
||||
}
|
||||
|
@ -134,7 +139,7 @@ func main() {
|
|||
newRectangleStroke = rectangleTool{
|
||||
StartPos: raylib.GetMousePosition(),
|
||||
EndPos: raylib.GetMousePosition(),
|
||||
Rounded: false,
|
||||
Rounded: true,
|
||||
Color: toolPanelColourPicker,
|
||||
Size: toolPanelBrushSize,
|
||||
}
|
||||
|
@ -151,7 +156,6 @@ func main() {
|
|||
applicationState = StateNormal
|
||||
}
|
||||
case toolPointer:
|
||||
fallthrough
|
||||
default:
|
||||
// yyeeeeet
|
||||
}
|
||||
|
@ -177,11 +181,56 @@ func main() {
|
|||
|
||||
canvas.Update()
|
||||
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
|
||||
// check if gui changes are needed
|
||||
raylib.BeginDrawing()
|
||||
{
|
||||
if applicationShouldDraw {
|
||||
|
||||
raylib.ClearBackground(raylib.White)
|
||||
gui.Grid(raylib.NewRectangle(0, 0, float32(applicationWindowWidth), float32(applicationWindowHeight)), "", 30, 1, &raylib.Vector2{})
|
||||
|
||||
|
@ -504,10 +553,14 @@ func main() {
|
|||
}
|
||||
|
||||
drawToasts()
|
||||
|
||||
if applicationShowDebugValues && applicationExperimentalUpdates {
|
||||
if applicationShowdebugUpdate {
|
||||
raylib.DrawRectangle(0, 0, 200, 20, raylib.Fade(raylib.Black, 0.5))
|
||||
}
|
||||
applicationShowdebugUpdate = !applicationShowdebugUpdate
|
||||
}
|
||||
}
|
||||
raylib.EndDrawing()
|
||||
}
|
||||
|
||||
// GOODBYE
|
||||
raylib.CloseWindow()
|
||||
}
|
||||
|
|
7
toast.go
7
toast.go
|
@ -13,8 +13,9 @@ type toast struct {
|
|||
}
|
||||
|
||||
var (
|
||||
toasts []toast
|
||||
toastDimHeight = float32(0)
|
||||
toasts []toast
|
||||
toastShouldUpdate = true
|
||||
toastDimHeight = float32(0)
|
||||
)
|
||||
|
||||
func addToast(text string) {
|
||||
|
@ -36,6 +37,8 @@ func updateToasts() {
|
|||
}
|
||||
}
|
||||
toasts = t
|
||||
|
||||
toastShouldUpdate = int(toastDimHeight) != 0
|
||||
}
|
||||
|
||||
func drawToasts() {
|
||||
|
|
18
vars.go
18
vars.go
|
@ -34,12 +34,18 @@ const (
|
|||
)
|
||||
|
||||
var (
|
||||
applicationState = StateNormal
|
||||
applicationShouldQuit = false
|
||||
applicationShowDebugValues = false
|
||||
applicationWindowWidth = applicationMinWindowWidth
|
||||
applicationWindowHeight = applicationMinWindowHeight
|
||||
applicationRuntime = float32(0)
|
||||
applicationState = StateNormal
|
||||
applicationLastState = StateNormal
|
||||
applicationShouldQuit = false
|
||||
applicationShouldDraw = true
|
||||
applicationLastMousePos = raylib.Vector2{}
|
||||
applicationWindowWidth = applicationMinWindowWidth
|
||||
applicationWindowHeight = applicationMinWindowHeight
|
||||
applicationRuntime = 0
|
||||
|
||||
applicationExperimentalUpdates = false
|
||||
applicationShowDebugValues = false
|
||||
applicationShowdebugUpdate = false
|
||||
)
|
||||
|
||||
var (
|
||||
|
|
Loading…
Reference in a new issue