aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSam Anthony <sam@samanthony.xyz>2024-08-24 14:49:13 -0400
committerSam Anthony <sam@samanthony.xyz>2024-08-24 14:49:13 -0400
commiteac0b4b31a1ae323222076dcb31dc7cd4d9402d5 (patch)
tree37736bf9cdf1452ec7629a86d3fad072cc8b94df
parent050f26f34a64689e16fc9d20c9a9dc3f7e43b1d0 (diff)
downloadgui-eac0b4b31a1ae323222076dcb31dc7cd4d9402d5.zip
move win to gui package
-rw-r--r--event.go83
-rw-r--r--win.go (renamed from win/win.go)15
-rw-r--r--win/events.go89
3 files changed, 90 insertions, 97 deletions
diff --git a/event.go b/event.go
index 3b88c00..eff095b 100644
--- a/event.go
+++ b/event.go
@@ -68,3 +68,86 @@ func makeEventsChan() (<-chan Event, chan<- Event) {
return out, in
}
+
+// Button indicates a mouse button in an event.
+type Button string
+
+// List of all mouse buttons.
+const (
+ ButtonLeft Button = "left"
+ ButtonRight Button = "right"
+ ButtonMiddle Button = "middle"
+)
+
+// Key indicates a keyboard key in an event.
+type Key string
+
+// List of all keyboard keys.
+const (
+ KeyLeft Key = "left"
+ KeyRight Key = "right"
+ KeyUp Key = "up"
+ KeyDown Key = "down"
+ KeyEscape Key = "escape"
+ KeySpace Key = "space"
+ KeyBackspace Key = "backspace"
+ KeyDelete Key = "delete"
+ KeyEnter Key = "enter"
+ KeyTab Key = "tab"
+ KeyHome Key = "home"
+ KeyEnd Key = "end"
+ KeyPageUp Key = "pageup"
+ KeyPageDown Key = "pagedown"
+ KeyShift Key = "shift"
+ KeyCtrl Key = "ctrl"
+ KeyAlt Key = "alt"
+)
+
+type (
+ // WiClose is an event that happens when the user presses the close button on the window.
+ WiClose struct{}
+
+ // MoMove is an event that happens when the mouse gets moved across the window.
+ MoMove struct{ image.Point }
+
+ // MoDown is an event that happens when a mouse button gets pressed.
+ MoDown struct {
+ image.Point
+ Button Button
+ }
+
+ // MoUp is an event that happens when a mouse button gets released.
+ MoUp struct {
+ image.Point
+ Button Button
+ }
+
+ // MoScroll is an event that happens on scrolling the mouse.
+ //
+ // The Point field tells the amount scrolled in each direction.
+ MoScroll struct{ image.Point }
+
+ // KbType is an event that happens when a Unicode character gets typed on the keyboard.
+ KbType struct{ Rune rune }
+
+ // KbDown is an event that happens when a key on the keyboard gets pressed.
+ KbDown struct{ Key Key }
+
+ // KbUp is an event that happens when a key on the keyboard gets released.
+ KbUp struct{ Key Key }
+
+ // KbRepeat is an event that happens when a key on the keyboard gets repeated.
+ //
+ // This happens when its held down for some time.
+ KbRepeat struct{ Key Key }
+)
+
+func (wc WiClose) String() string { return "wi/close" }
+func (mm MoMove) String() string { return fmt.Sprintf("mo/move/%d/%d", mm.X, mm.Y) }
+func (md MoDown) String() string { return fmt.Sprintf("mo/down/%d/%d/%s", md.X, md.Y, md.Button) }
+func (mu MoUp) String() string { return fmt.Sprintf("mo/up/%d/%d/%s", mu.X, mu.Y, mu.Button) }
+func (ms MoScroll) String() string { return fmt.Sprintf("mo/scroll/%d/%d", ms.X, ms.Y) }
+func (kt KbType) String() string { return fmt.Sprintf("kb/type/%d", kt.Rune) }
+func (kd KbDown) String() string { return fmt.Sprintf("kb/down/%s", kd.Key) }
+func (ku KbUp) String() string { return fmt.Sprintf("kb/up/%s", ku.Key) }
+func (kr KbRepeat) String() string { return fmt.Sprintf("kb/repeat/%s", kr.Key) }
diff --git a/win/win.go b/win.go
index 1741549..41c68a3 100644
--- a/win/win.go
+++ b/win.go
@@ -1,4 +1,4 @@
-package win
+package gui
import (
"image"
@@ -7,7 +7,6 @@ import (
"time"
"unsafe"
- "github.com/faiface/gui"
"github.com/faiface/mainthread"
"github.com/go-gl/gl/v2.1/gl"
"github.com/go-gl/glfw/v3.2/glfw"
@@ -76,7 +75,7 @@ func New(opts ...Option) (*Win, error) {
opt(&o)
}
- eventsOut, eventsIn := gui.MakeEventsChan()
+ eventsOut, eventsIn := makeEventsChan()
w := &Win{
eventsOut: eventsOut,
@@ -158,8 +157,8 @@ func makeGLFWWin(o *options) (*glfw.Window, error) {
//
// Warning: only one window can be open at a time. This will be fixed.
type Win struct {
- eventsOut <-chan gui.Event
- eventsIn chan<- gui.Event
+ eventsOut <-chan Event
+ eventsIn chan<- Event
draw chan func(draw.Image) image.Rectangle
newSize chan image.Rectangle
@@ -171,7 +170,7 @@ type Win struct {
}
// Events returns the events channel of the window.
-func (w *Win) Events() <-chan gui.Event { return w.eventsOut }
+func (w *Win) Events() <-chan Event { return w.eventsOut }
// Draw returns the draw channel of the window.
func (w *Win) Draw() chan<- func(draw.Image) image.Rectangle { return w.draw }
@@ -252,7 +251,7 @@ func (w *Win) eventThread() {
w.w.SetFramebufferSizeCallback(func(_ *glfw.Window, width, height int) {
r := image.Rect(0, 0, width, height)
w.newSize <- r
- w.eventsIn <- gui.Resize{Rectangle: r}
+ w.eventsIn <- Resize{Rectangle: r}
})
w.w.SetCloseCallback(func(_ *glfw.Window) {
@@ -260,7 +259,7 @@ func (w *Win) eventThread() {
})
r := w.img.Bounds()
- w.eventsIn <- gui.Resize{Rectangle: r}
+ w.eventsIn <- Resize{Rectangle: r}
for {
select {
diff --git a/win/events.go b/win/events.go
deleted file mode 100644
index 90fab52..0000000
--- a/win/events.go
+++ /dev/null
@@ -1,89 +0,0 @@
-package win
-
-import (
- "fmt"
- "image"
-)
-
-// Button indicates a mouse button in an event.
-type Button string
-
-// List of all mouse buttons.
-const (
- ButtonLeft Button = "left"
- ButtonRight Button = "right"
- ButtonMiddle Button = "middle"
-)
-
-// Key indicates a keyboard key in an event.
-type Key string
-
-// List of all keyboard keys.
-const (
- KeyLeft Key = "left"
- KeyRight Key = "right"
- KeyUp Key = "up"
- KeyDown Key = "down"
- KeyEscape Key = "escape"
- KeySpace Key = "space"
- KeyBackspace Key = "backspace"
- KeyDelete Key = "delete"
- KeyEnter Key = "enter"
- KeyTab Key = "tab"
- KeyHome Key = "home"
- KeyEnd Key = "end"
- KeyPageUp Key = "pageup"
- KeyPageDown Key = "pagedown"
- KeyShift Key = "shift"
- KeyCtrl Key = "ctrl"
- KeyAlt Key = "alt"
-)
-
-type (
- // WiClose is an event that happens when the user presses the close button on the window.
- WiClose struct{}
-
- // MoMove is an event that happens when the mouse gets moved across the window.
- MoMove struct{ image.Point }
-
- // MoDown is an event that happens when a mouse button gets pressed.
- MoDown struct {
- image.Point
- Button Button
- }
-
- // MoUp is an event that happens when a mouse button gets released.
- MoUp struct {
- image.Point
- Button Button
- }
-
- // MoScroll is an event that happens on scrolling the mouse.
- //
- // The Point field tells the amount scrolled in each direction.
- MoScroll struct{ image.Point }
-
- // KbType is an event that happens when a Unicode character gets typed on the keyboard.
- KbType struct{ Rune rune }
-
- // KbDown is an event that happens when a key on the keyboard gets pressed.
- KbDown struct{ Key Key }
-
- // KbUp is an event that happens when a key on the keyboard gets released.
- KbUp struct{ Key Key }
-
- // KbRepeat is an event that happens when a key on the keyboard gets repeated.
- //
- // This happens when its held down for some time.
- KbRepeat struct{ Key Key }
-)
-
-func (wc WiClose) String() string { return "wi/close" }
-func (mm MoMove) String() string { return fmt.Sprintf("mo/move/%d/%d", mm.X, mm.Y) }
-func (md MoDown) String() string { return fmt.Sprintf("mo/down/%d/%d/%s", md.X, md.Y, md.Button) }
-func (mu MoUp) String() string { return fmt.Sprintf("mo/up/%d/%d/%s", mu.X, mu.Y, mu.Button) }
-func (ms MoScroll) String() string { return fmt.Sprintf("mo/scroll/%d/%d", ms.X, ms.Y) }
-func (kt KbType) String() string { return fmt.Sprintf("kb/type/%d", kt.Rune) }
-func (kd KbDown) String() string { return fmt.Sprintf("kb/down/%s", kd.Key) }
-func (ku KbUp) String() string { return fmt.Sprintf("kb/up/%s", ku.Key) }
-func (kr KbRepeat) String() string { return fmt.Sprintf("kb/repeat/%s", kr.Key) }