gg/event.go

89 lines
1.5 KiB
Go
Raw Permalink Normal View History

2023-11-23 22:05:22 +03:00
package gg
import (
//"github.com/hajimehoshi/ebiten/v2"
2023-11-23 22:05:22 +03:00
)
2024-05-28 11:24:12 +03:00
import "surdeus.su/core/gg/mx"
2023-12-24 15:05:34 +03:00
func diffEm[V comparable](s1, s2 []V) []V {
2023-11-23 22:05:22 +03:00
combinedSlice := append(s1, s2...)
2023-12-24 15:05:34 +03:00
dm := make(map[V]int)
2023-11-23 22:05:22 +03:00
for _, v := range combinedSlice {
if _, ok := dm[v]; ok {
// remove element later as it exist in both slice.
dm[v] += 1
continue
}
// new entry, add in map!
dm[v] = 1
}
2023-12-24 15:05:34 +03:00
var retSlice []V
2023-11-23 22:05:22 +03:00
for k, v := range dm {
if v == 1 {
retSlice = append(retSlice, k)
}
}
return retSlice
}
2024-05-28 11:24:12 +03:00
// The type represents event of a
// key getting pressed down.
2023-11-23 22:05:22 +03:00
type KeyDown struct {
Key
}
2024-05-28 11:24:12 +03:00
// The type represents event of a
// key getting pressed up.
2023-11-23 22:05:22 +03:00
type KeyUp struct {
Key
}
2024-05-28 11:24:12 +03:00
// The type represents event of a
// mouse button being pressed down.
2023-11-23 22:05:22 +03:00
type MouseButtonDown struct {
MouseButton
2024-05-28 11:24:12 +03:00
Position mx.Vector
2023-11-23 22:05:22 +03:00
}
2024-05-28 11:24:12 +03:00
// The type represents event of a
// mouse button being pressed up.
2023-11-23 22:05:22 +03:00
type MouseButtonUp struct {
MouseButton
2024-05-28 11:24:12 +03:00
Positon mx.Vector
2023-11-23 22:05:22 +03:00
}
2024-05-28 11:24:12 +03:00
// The type represents
// event of moving the mouse.
2023-11-23 22:05:22 +03:00
type MouseMove struct {
2024-05-28 11:24:12 +03:00
// Real and absolute deltas
// for the mouse movement.
RealDelta, AbsDelta mx.Vector
2023-12-24 15:05:34 +03:00
}
2024-05-28 11:24:12 +03:00
// The type represents event
// of a wheel change.
2023-12-24 15:05:34 +03:00
type WheelChange struct {
2024-05-28 11:24:12 +03:00
Offset mx.Vector
2023-11-23 22:05:22 +03:00
}
2024-06-01 16:07:28 +03:00
type KeyboardEvents struct {
2024-06-03 11:04:42 +03:00
Downs []KeyDown
Ups []KeyUp
2024-06-01 16:07:28 +03:00
}
type MouseEvents struct {
2024-06-03 11:04:42 +03:00
Downs []MouseButtonDown
Ups []MouseButtonUp
2024-06-01 16:07:28 +03:00
Move *MouseMove
2024-06-03 11:04:42 +03:00
Wheel *WheelChange
2024-06-01 16:07:28 +03:00
}
type Events struct {
Keyboard KeyboardEvents
Mouse MouseEvents
}
2023-11-23 22:05:22 +03:00
type EventChan chan any