From 5fbb9b35459318d3f435ea8e5ae82e3614a43fb3 Mon Sep 17 00:00:00 2001 From: squishy Date: Sat, 23 Mar 2024 09:12:55 +0000 Subject: [PATCH] added mouse cursor --- cursor.png | Bin 0 -> 240 bytes run.go | 20 +++++++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 cursor.png diff --git a/cursor.png b/cursor.png new file mode 100644 index 0000000000000000000000000000000000000000..fcb13c23e646ac5215e892cc91316ad841708c4e GIT binary patch literal 240 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`jKx9jP7LeL$-D$|R(ZNOhFJ7Y zon*^*Sb?YYe)kTCcCKl13eLyw{AYN3&Fk&C772@{-6n!22OCsXaw_Kkac5{MOs*50 zXvlU_HfdV|$3pKn$yznRKbLp4G1#fCIsHfeUiAf*KS$Q=_18V{_b1yFPgBP2uU%VZ zfU*|P6V|?M5@}eIsB)9_qSuS2EmapB4d)NV-)RAghgo_g-J)oe@8t`3>7I_<`r lfyN&VMQ>&`%@Vy?$7rDMwwNj3Fbe2u22WQ%mvv4FO#ssfTq6Jg literal 0 HcmV?d00001 diff --git a/run.go b/run.go index bcc6dec..0050430 100644 --- a/run.go +++ b/run.go @@ -1,6 +1,7 @@ package bloob import ( + _ "embed" "fmt" "github.com/veandco/go-sdl2/sdl" "time" @@ -21,8 +22,14 @@ type Settings struct { type Bloob struct { MousePos Vec2i + Cursor *Image } +var DefaultCursor *Image + +//go:embed "cursor.png" +var defaultCursorBytes []byte + func Run(game Runnable) { _ = sdl.Init(sdl.INIT_EVERYTHING) defer sdl.Quit() @@ -34,7 +41,13 @@ func Run(game Runnable) { Title: "Blooblib", } - bloob := Bloob{} + if DefaultCursor == nil { + DefaultCursor = LoadImageBytes(defaultCursorBytes) + } + + bloob := Bloob{ + Cursor: DefaultCursor, + } game.Init(&settings) @@ -51,6 +64,8 @@ func Run(game Runnable) { screen := NewImage(settings.WindowSize) screen.Alpha = false + sdl.ShowCursor(sdl.DISABLE) + _ = window.UpdateSurface() lastSecond := time.Now() @@ -85,6 +100,9 @@ func Run(game Runnable) { if delta2 >= frameDuration { game.Update(&bloob) game.Render(screen) + if bloob.Cursor != nil { + screen.Draw(bloob.Cursor, bloob.MousePos) + } windowImage.DrawUpscale(screen) framesSinceLastSecond += 1 lastFrame = lastFrame.Add(frameDuration)