|
@@ -0,0 +1,582 @@
|
|
|
+package al
|
|
|
+
|
|
|
+
|
|
|
+#cgo pkg-config: allegro-5
|
|
|
+#cgo CFLAGS: -I/usr/local/include
|
|
|
+#cgo linux LDFLAGS: -lc_nonshared
|
|
|
+#include <stdlib.h>
|
|
|
+#include <allegro5/allegro.h>
|
|
|
+#include <allegro5/events.h>
|
|
|
+#include "helpers.h"
|
|
|
+#include "callbacks.h"
|
|
|
+*/
|
|
|
+import "C"
|
|
|
+
|
|
|
+import "unsafe"
|
|
|
+import "runtime"
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+const (
|
|
|
+ EVENT_JOYSTICK_AXIS = C.ALLEGRO_EVENT_JOYSTICK_AXIS
|
|
|
+ EVENT_JOYSTICK_BUTTON_DOWN = C.ALLEGRO_EVENT_JOYSTICK_BUTTON_DOWN
|
|
|
+ EVENT_JOYSTICK_BUTTON_UP = C.ALLEGRO_EVENT_JOYSTICK_BUTTON_UP
|
|
|
+ EVENT_JOYSTICK_CONFIGURATION = C.ALLEGRO_EVENT_JOYSTICK_CONFIGURATION
|
|
|
+ EVENT_KEY_DOWN = C.ALLEGRO_EVENT_KEY_DOWN
|
|
|
+ EVENT_KEY_CHAR = C.ALLEGRO_EVENT_KEY_CHAR
|
|
|
+ EVENT_KEY_UP = C.ALLEGRO_EVENT_KEY_UP
|
|
|
+ EVENT_MOUSE_AXES = C.ALLEGRO_EVENT_MOUSE_AXES
|
|
|
+ EVENT_MOUSE_BUTTON_DOWN = C.ALLEGRO_EVENT_MOUSE_BUTTON_DOWN
|
|
|
+ EVENT_MOUSE_BUTTON_UP = C.ALLEGRO_EVENT_MOUSE_BUTTON_UP
|
|
|
+ EVENT_MOUSE_ENTER_DISPLAY = C.ALLEGRO_EVENT_MOUSE_ENTER_DISPLAY
|
|
|
+ EVENT_MOUSE_LEAVE_DISPLAY = C.ALLEGRO_EVENT_MOUSE_LEAVE_DISPLAY
|
|
|
+ EVENT_MOUSE_WARPED = C.ALLEGRO_EVENT_MOUSE_WARPED
|
|
|
+ EVENT_TIMER = C.ALLEGRO_EVENT_TIMER
|
|
|
+ EVENT_DISPLAY_EXPOSE = C.ALLEGRO_EVENT_DISPLAY_EXPOSE
|
|
|
+ EVENT_DISPLAY_RESIZE = C.ALLEGRO_EVENT_DISPLAY_RESIZE
|
|
|
+ EVENT_DISPLAY_CLOSE = C.ALLEGRO_EVENT_DISPLAY_CLOSE
|
|
|
+ EVENT_DISPLAY_LOST = C.ALLEGRO_EVENT_DISPLAY_LOST
|
|
|
+ EVENT_DISPLAY_FOUND = C.ALLEGRO_EVENT_DISPLAY_FOUND
|
|
|
+ EVENT_DISPLAY_SWITCH_IN = C.ALLEGRO_EVENT_DISPLAY_SWITCH_IN
|
|
|
+ EVENT_DISPLAY_SWITCH_OUT = C.ALLEGRO_EVENT_DISPLAY_SWITCH_OUT
|
|
|
+ EVENT_DISPLAY_ORIENTATION = C.ALLEGRO_EVENT_DISPLAY_ORIENTATION
|
|
|
+ EVENT_TOUCH_BEGIN = C.ALLEGRO_EVENT_TOUCH_BEGIN
|
|
|
+ EVENT_TOUCH_END = C.ALLEGRO_EVENT_TOUCH_END
|
|
|
+ EVENT_TOUCH_MOVE = C.ALLEGRO_EVENT_TOUCH_MOVE
|
|
|
+ EVENT_TOUCH_CANCEL = C.ALLEGRO_EVENT_TOUCH_CANCEL
|
|
|
+ EVENT_DISPLAY_CONNECTED = C.ALLEGRO_EVENT_DISPLAY_CONNECTED
|
|
|
+ EVENT_DISPLAY_DISCONNECTED = C.ALLEGRO_EVENT_DISPLAY_DISCONNECTED
|
|
|
+)
|
|
|
+
|
|
|
+func EVENT_TYPE_IS_USER(t int) bool {
|
|
|
+ return ((t) >= 512)
|
|
|
+}
|
|
|
+
|
|
|
+func GET_EVENT_TYPE(a, b, c, d int) int {
|
|
|
+ return AL_ID(a, b, c, d)
|
|
|
+}
|
|
|
+
|
|
|
+func getAnyEvenTimestamp(any *C.ALLEGRO_ANY_EVENT) float64 {
|
|
|
+ return float64(any.timestamp)
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+type EventSourcer interface {
|
|
|
+ EventSource() * EventSource
|
|
|
+}
|
|
|
+
|
|
|
+func (disp * Display) EventSource() * EventSource {
|
|
|
+ return (*EventSource)(unsafe.Pointer(disp))
|
|
|
+}
|
|
|
+
|
|
|
+func (joy * Joystick) EventSource() * EventSource {
|
|
|
+ return (*EventSource)(unsafe.Pointer(joy))
|
|
|
+}
|
|
|
+
|
|
|
+func (key * Keyboard) EventSource() * EventSource {
|
|
|
+ return (*EventSource)(unsafe.Pointer(key))
|
|
|
+}
|
|
|
+
|
|
|
+func (mouse * Mouse) EventSource() * EventSource {
|
|
|
+ return (*EventSource)(unsafe.Pointer(mouse))
|
|
|
+}
|
|
|
+
|
|
|
+func (touch * TouchInput) EventSource() * EventSource {
|
|
|
+ return (*EventSource)(unsafe.Pointer(touch))
|
|
|
+}
|
|
|
+
|
|
|
+func (timer * Timer) EventSource() * EventSource {
|
|
|
+ return (*EventSource)(unsafe.Pointer(timer))
|
|
|
+}
|
|
|
+
|
|
|
+func (es * EventSource) EventSource() * EventSource {
|
|
|
+ return es
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+type EventSource C.ALLEGRO_EVENT_SOURCE
|
|
|
+
|
|
|
+
|
|
|
+func wrapEventSourceRaw(ptr *C.ALLEGRO_EVENT_SOURCE) *EventSource {
|
|
|
+ return (*EventSource)(ptr)
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (self *EventSource) toC() *C.ALLEGRO_EVENT_SOURCE {
|
|
|
+ return (*C.ALLEGRO_EVENT_SOURCE)(self)
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+type EventUnion C.ALLEGRO_EVENT
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+type Event interface {
|
|
|
+ Type() int
|
|
|
+ Source() EventSourcer
|
|
|
+ Timestamp() float64
|
|
|
+}
|
|
|
+
|
|
|
+type AnyEvent C.ALLEGRO_ANY_EVENT
|
|
|
+type DisplayEvent C.ALLEGRO_DISPLAY_EVENT
|
|
|
+type JoystickEvent C.ALLEGRO_JOYSTICK_EVENT
|
|
|
+type KeyboardEvent C.ALLEGRO_KEYBOARD_EVENT
|
|
|
+type MouseEvent C.ALLEGRO_MOUSE_EVENT
|
|
|
+type TimerEvent C.ALLEGRO_TIMER_EVENT
|
|
|
+type TouchEvent C.ALLEGRO_TOUCH_EVENT
|
|
|
+type UserEvent C.ALLEGRO_USER_EVENT
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+func (self *EventUnion) toC() *C.ALLEGRO_EVENT {
|
|
|
+ return (*C.ALLEGRO_EVENT)(self)
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (self *EventUnion) toPointer() unsafe.Pointer {
|
|
|
+ return unsafe.Pointer(self.toC())
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+func (evun *EventUnion) Event() Event {
|
|
|
+ ae := (*C.ALLEGRO_ANY_EVENT)(evun.toPointer())
|
|
|
+ switch (C.int(ae._type)) {
|
|
|
+ case EVENT_JOYSTICK_AXIS : fallthrough
|
|
|
+ case EVENT_JOYSTICK_BUTTON_DOWN : fallthrough
|
|
|
+ case EVENT_JOYSTICK_BUTTON_UP : fallthrough
|
|
|
+ case EVENT_JOYSTICK_CONFIGURATION :
|
|
|
+ return (*JoystickEvent)(evun.toPointer())
|
|
|
+ case EVENT_KEY_CHAR : fallthrough
|
|
|
+ case EVENT_KEY_DOWN : fallthrough
|
|
|
+ case EVENT_KEY_UP :
|
|
|
+ return (*KeyboardEvent)(evun.toPointer())
|
|
|
+
|
|
|
+ case EVENT_MOUSE_AXES : fallthrough
|
|
|
+ case EVENT_MOUSE_BUTTON_DOWN : fallthrough
|
|
|
+ case EVENT_MOUSE_BUTTON_UP : fallthrough
|
|
|
+ case EVENT_MOUSE_ENTER_DISPLAY : fallthrough
|
|
|
+ case EVENT_MOUSE_LEAVE_DISPLAY : fallthrough
|
|
|
+ case EVENT_MOUSE_WARPED :
|
|
|
+ return (*MouseEvent)(evun.toPointer())
|
|
|
+
|
|
|
+ case EVENT_TIMER :
|
|
|
+ return (*TimerEvent)(evun.toPointer())
|
|
|
+
|
|
|
+ case EVENT_DISPLAY_EXPOSE : fallthrough
|
|
|
+ case EVENT_DISPLAY_RESIZE : fallthrough
|
|
|
+ case EVENT_DISPLAY_CLOSE : fallthrough
|
|
|
+ case EVENT_DISPLAY_LOST : fallthrough
|
|
|
+ case EVENT_DISPLAY_FOUND : fallthrough
|
|
|
+ case EVENT_DISPLAY_SWITCH_IN : fallthrough
|
|
|
+ case EVENT_DISPLAY_SWITCH_OUT : fallthrough
|
|
|
+ case EVENT_DISPLAY_ORIENTATION :
|
|
|
+ return (*DisplayEvent)(evun.toPointer())
|
|
|
+ default: break
|
|
|
+ }
|
|
|
+
|
|
|
+ if EVENT_TYPE_IS_USER(int(ae._type)) {
|
|
|
+ return (*UserEvent)(evun.toPointer())
|
|
|
+ }
|
|
|
+
|
|
|
+ return (*AnyEvent)(evun.toPointer())
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+func (ev AnyEvent ) Type() int { return int(ev._type); }
|
|
|
+func (ev DisplayEvent ) Type() int { return int(ev._type); }
|
|
|
+func (ev JoystickEvent) Type() int { return int(ev._type); }
|
|
|
+func (ev KeyboardEvent) Type() int { return int(ev._type); }
|
|
|
+func (ev MouseEvent ) Type() int { return int(ev._type); }
|
|
|
+func (ev TimerEvent ) Type() int { return int(ev._type); }
|
|
|
+func (ev TouchEvent ) Type() int { return int(ev._type); }
|
|
|
+func (ev UserEvent ) Type() int { return int(ev._type); }
|
|
|
+
|
|
|
+func (ev AnyEvent ) Source() EventSourcer { return wrapEventSourceRaw (ev.source); }
|
|
|
+func (ev DisplayEvent ) Source() EventSourcer { return wrapDisplayRaw (ev.source); }
|
|
|
+func (ev JoystickEvent) Source() EventSourcer { return wrapJoystickRaw (ev.source); }
|
|
|
+func (ev KeyboardEvent) Source() EventSourcer { return wrapKeyboardRaw (ev.source); }
|
|
|
+func (ev MouseEvent ) Source() EventSourcer { return wrapMouseRaw (ev.source); }
|
|
|
+func (ev TimerEvent ) Source() EventSourcer { return wrapTimerRaw (ev.source); }
|
|
|
+func (ev TouchEvent ) Source() EventSourcer { return wrapTouchInputRaw (ev.source); }
|
|
|
+func (ev UserEvent ) Source() EventSourcer { return wrapEventSourceRaw (ev.source); }
|
|
|
+
|
|
|
+func (ev AnyEvent ) Timestamp() float64 { return float64(ev.timestamp); }
|
|
|
+func (ev DisplayEvent ) Timestamp() float64 { return float64(ev.timestamp); }
|
|
|
+func (ev JoystickEvent) Timestamp() float64 { return float64(ev.timestamp); }
|
|
|
+func (ev KeyboardEvent) Timestamp() float64 { return float64(ev.timestamp); }
|
|
|
+func (ev MouseEvent ) Timestamp() float64 { return float64(ev.timestamp); }
|
|
|
+func (ev TimerEvent ) Timestamp() float64 { return float64(ev.timestamp); }
|
|
|
+func (ev TouchEvent ) Timestamp() float64 { return float64(ev.timestamp); }
|
|
|
+func (ev UserEvent ) Timestamp() float64 { return float64(ev.timestamp); }
|
|
|
+
|
|
|
+
|
|
|
+func (eu * EventUnion) AnyEvent () *AnyEvent { return (*AnyEvent )(eu.toPointer()); }
|
|
|
+func (eu * EventUnion) DisplayEvent () *DisplayEvent { if !eu.IsDisplayEvent () { return nil; } else { return (*DisplayEvent )(eu.toPointer());}; }
|
|
|
+func (eu * EventUnion) JoystickEvent() *JoystickEvent { if !eu.IsJoystickEvent() { return nil; } else { return (*JoystickEvent)(eu.toPointer());}; }
|
|
|
+func (eu * EventUnion) KeyboardEvent() *KeyboardEvent { if !eu.IsKeyboardEvent() { return nil; } else { return (*KeyboardEvent)(eu.toPointer());}; }
|
|
|
+func (eu * EventUnion) MouseEvent () *MouseEvent { if !eu.IsMouseEvent () { return nil; } else { return (*MouseEvent )(eu.toPointer());}; }
|
|
|
+func (eu * EventUnion) TimerEvent () *TimerEvent { if !eu.IsTimerEvent () { return nil; } else { return (*TimerEvent )(eu.toPointer());}; }
|
|
|
+func (eu * EventUnion) TouchEvent () *TouchEvent { if !eu.IsTouchEvent () { return nil; } else { return (*TouchEvent )(eu.toPointer());}; }
|
|
|
+func (eu * EventUnion) UserEvent () *UserEvent { if !eu.IsUserEvent () { return nil; } else { return (*UserEvent )(eu.toPointer());}; }
|
|
|
+
|
|
|
+
|
|
|
+func (self *EventUnion) Type() int {
|
|
|
+ return self.AnyEvent().Type()
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (self *EventUnion) Timestamp() float64 {
|
|
|
+ return self.AnyEvent().Timestamp()
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (self *EventUnion) Source() EventSourcer {
|
|
|
+ return self.AnyEvent().Source()
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (self *EventUnion) IsDisplayEvent() bool {
|
|
|
+ t := self.Type()
|
|
|
+ return ((t >= EVENT_DISPLAY_EXPOSE) && (t <= EVENT_DISPLAY_ORIENTATION) || ((t>= EVENT_DISPLAY_CONNECTED) && (t<= EVENT_DISPLAY_DISCONNECTED) ))
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (self *EventUnion) IsMouseEvent() bool {
|
|
|
+ t := self.Type()
|
|
|
+ return (t >= EVENT_MOUSE_AXES) && (t <= EVENT_MOUSE_WARPED)
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (self *EventUnion) IsJoystickEvent() bool {
|
|
|
+ t := self.Type()
|
|
|
+ return (t >= EVENT_JOYSTICK_AXIS) && (t <= EVENT_JOYSTICK_CONFIGURATION)
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (self *EventUnion) IsKeyboardEvent() bool {
|
|
|
+ t := self.Type()
|
|
|
+ return (t >= EVENT_KEY_DOWN) && (t <= EVENT_KEY_UP)
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (self *EventUnion) IsTouchEvent() bool {
|
|
|
+ t := self.Type()
|
|
|
+ return (t >= EVENT_TOUCH_BEGIN) && (t <= EVENT_TOUCH_CANCEL)
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (self *EventUnion) IsTimerEvent() bool {
|
|
|
+ t := self.Type()
|
|
|
+ return (t == EVENT_TIMER)
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (self *EventUnion) IsUserEvent() bool {
|
|
|
+ t := self.Type()
|
|
|
+ return EVENT_TYPE_IS_USER(t)
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (de DisplayEvent) X() int {
|
|
|
+ return int(de.x)
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (de DisplayEvent) Y() int {
|
|
|
+ return int(de.y)
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (de DisplayEvent) Width() int {
|
|
|
+ return int(de.width)
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (de DisplayEvent) Height() int {
|
|
|
+ return int(de.height)
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (de DisplayEvent) Orientation() int {
|
|
|
+ return int(de.orientation)
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (je JoystickEvent) Stick() int {
|
|
|
+ return int(je.stick)
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (je JoystickEvent) Axis() int {
|
|
|
+ return int(je.axis)
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (je JoystickEvent) Button() int {
|
|
|
+ return int(je.button)
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (je JoystickEvent) Pos() int {
|
|
|
+ return int(je.pos)
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (ke KeyboardEvent) Display() *Display {
|
|
|
+ return wrapDisplayRaw(ke.display)
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (ke KeyboardEvent) Keycode() int {
|
|
|
+ return int(ke.keycode)
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (ke KeyboardEvent) Unichar() rune {
|
|
|
+ return rune(ke.unichar)
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (ke KeyboardEvent) Modifiers() int {
|
|
|
+ return int(ke.modifiers)
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (ke KeyboardEvent) Repeat() bool {
|
|
|
+ return bool(ke.repeat)
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (me MouseEvent) X() int {
|
|
|
+ return int(me.x)
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (me MouseEvent) Y() int {
|
|
|
+ return int(me.y)
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (me MouseEvent) Z() int {
|
|
|
+ return int(me.z)
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (me MouseEvent) W() int {
|
|
|
+ return int(me.w)
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (me MouseEvent) DX() int {
|
|
|
+ return int(me.dx)
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (me MouseEvent) DY() int {
|
|
|
+ return int(me.dy)
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (me MouseEvent) DZ() int {
|
|
|
+ return int(me.dz)
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (me MouseEvent) DW() int {
|
|
|
+ return int(me.dw)
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (me MouseEvent) Button() int {
|
|
|
+ return int(me.button)
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (me MouseEvent) Pressure() float32 {
|
|
|
+ return float32(me.pressure)
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (me MouseEvent) Display() *Display {
|
|
|
+ return wrapDisplayRaw(me.display)
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+func (te TimerEvent) Error() float64 {
|
|
|
+ return float64(te.error)
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (te TimerEvent) Count() int64 {
|
|
|
+ return int64(te.count)
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+func (te TouchEvent) X() int {
|
|
|
+ return int(te.x)
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (te TouchEvent) Y() int {
|
|
|
+ return int(te.y)
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (te TouchEvent) ID() int {
|
|
|
+ return int(te.id)
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (te TouchEvent) Primary() bool {
|
|
|
+ return bool(te.primary)
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (te TouchEvent) DX() int {
|
|
|
+ return int(te.dx)
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (te TouchEvent) DY() int {
|
|
|
+ return int(te.dy)
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+ * as offsets into a GO-allocated map. */
|
|
|
+
|
|
|
+func (ue UserEvent) Data1Pointer() unsafe.Pointer { return unsafe.Pointer(uintptr(ue.data1));}
|
|
|
+func (ue UserEvent) Data1Integer() int64 { return int64(ue.data1); }
|
|
|
+func (ue UserEvent) Data2Pointer() unsafe.Pointer { return unsafe.Pointer(uintptr(ue.data2));}
|
|
|
+func (ue UserEvent) Data2Integer() int64 { return int64(ue.data2); }
|
|
|
+func (ue UserEvent) Data3Pointer() unsafe.Pointer { return unsafe.Pointer(uintptr(ue.data3));}
|
|
|
+func (ue UserEvent) Data3Integer() int64 { return int64(ue.data3); }
|
|
|
+func (ue UserEvent) Data4Pointer() unsafe.Pointer { return unsafe.Pointer(uintptr(ue.data4));}
|
|
|
+func (ue UserEvent) Data4Integer() int64 { return int64(ue.data4); }
|
|
|
+
|
|
|
+func (ue UserEvent) SetData1Integer(v int64) { ue.data1 = C.intptr_t(v); }
|
|
|
+func (ue UserEvent) SetData2Integer(v int64) { ue.data2 = C.intptr_t(v); }
|
|
|
+func (ue UserEvent) SetData3Integer(v int64) { ue.data3 = C.intptr_t(v); }
|
|
|
+func (ue UserEvent) SetData4Integer(v int64) { ue.data4 = C.intptr_t(v); }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+The compiler accept this, but it's unlikely to work correctly.
|
|
|
+func (ue UserEvent) Data1() interface{} { return (interface{})(ue.Data1Pointer());}
|
|
|
+func (ue UserEvent) Data2() interface{} { return (interface{})(ue.Data2Pointer());}
|
|
|
+func (ue UserEvent) Data3() interface{} { return (interface{})(ue.Data3Pointer());}
|
|
|
+func (ue UserEvent) Data4() interface{} { return (interface{})(ue.Data4Pointer());}
|
|
|
+*/
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+type EventQueue struct {
|
|
|
+ handle *C.ALLEGRO_EVENT_QUEUE
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (self *EventQueue) Destroy() {
|
|
|
+ if self.handle != nil {
|
|
|
+ C.al_destroy_event_queue(self.handle)
|
|
|
+ }
|
|
|
+ self.handle = nil
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func wrapEventQueueRaw(handle *C.ALLEGRO_EVENT_QUEUE) *EventQueue {
|
|
|
+ if handle == nil {
|
|
|
+ return nil
|
|
|
+ }
|
|
|
+ return &EventQueue{handle}
|
|
|
+}
|
|
|
+
|
|
|
+func (eq * EventQueue) toC() (handle *C.ALLEGRO_EVENT_QUEUE) {
|
|
|
+ return eq.handle
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func wrapEventQueue(handle *C.ALLEGRO_EVENT_QUEUE) *EventQueue {
|
|
|
+ result := wrapEventQueueRaw(handle)
|
|
|
+ if result != nil {
|
|
|
+ runtime.SetFinalizer(result, func(me *EventQueue) { me.Destroy() })
|
|
|
+ }
|
|
|
+ return result
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func CreateEventQueue() *EventQueue {
|
|
|
+ return wrapEventQueue(C.al_create_event_queue())
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (self *EventQueue) RegisterEventSource(src *EventSource) {
|
|
|
+ C.al_register_event_source(self.handle, src.toC())
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (self *EventQueue) UnregisterEventSource(src *EventSource) {
|
|
|
+ C.al_unregister_event_source(self.handle, src.toC())
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (self *EventQueue) IsEmpty() bool {
|
|
|
+ return bool(C.al_is_event_queue_empty(self.handle))
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+func (self *EventQueue) GetNextEvent() (event *EventUnion, ok bool) {
|
|
|
+ event = &EventUnion{}
|
|
|
+ ok = bool(C.al_get_next_event(self.handle, event.toC()))
|
|
|
+ return event, ok
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+func (self *EventQueue) PeekNextEvent() (event *EventUnion, ok bool) {
|
|
|
+ event = &EventUnion{}
|
|
|
+ ok = bool(C.al_peek_next_event(self.handle, event.toC()))
|
|
|
+ return event, ok
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (self *EventQueue) DropNextEvent() bool {
|
|
|
+ return bool(C.al_drop_next_event(self.handle))
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (self *EventQueue) Flush() {
|
|
|
+ C.al_flush_event_queue(self.handle)
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (self *EventQueue) WaitForEvent() (event *EventUnion) {
|
|
|
+ event = &EventUnion{}
|
|
|
+ C.al_wait_for_event(self.handle, event.toC())
|
|
|
+ return event
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (self *EventQueue) WaitForEventTimed(secs float32) (event *EventUnion, ok bool) {
|
|
|
+ event = &EventUnion{}
|
|
|
+ ok = bool(C.al_wait_for_event_timed(self.handle, event.toC(), C.float(secs)))
|
|
|
+ return event, ok
|
|
|
+}
|
|
|
+
|
|
|
+func (queue *EventQueue) WaitForEventUntil(timeout * Timeout) (event *EventUnion, ok bool) {
|
|
|
+ event = &EventUnion{}
|
|
|
+ ok = bool(C.al_wait_for_event_until(queue.toC(), event.toC(), timeout.toC()))
|
|
|
+ return event, ok
|
|
|
+}
|
|
|
+
|