diff --git a/event.go b/event.go index 5261c44..708ed05 100644 --- a/event.go +++ b/event.go @@ -21,7 +21,8 @@ import ( ) type EventQueue struct { - queue *C.ALLEGRO_EVENT_QUEUE + queue *C.ALLEGRO_EVENT_QUEUE + displays map[*C.ALLEGRO_DISPLAY]*Display } type Event interface { @@ -37,16 +38,33 @@ func (eb EventBase) Stamp() float64 { } type DisplayCloseEvent struct { - EventBase + DisplayEvent } -type DisplayResizeEvent struct { - EventBase - X, Y int - Width int - Height int +type DisplayConnectedEvent struct { + DisplayEvent } +type DisplayDisconnectedEvent struct { + DisplayEvent +} + +type DisplayEvent struct { + EventBase + Display *Display +} + +type DisplayFoundEvent struct { + DisplayEvent +} + +type DisplayHaltDrawingEvent struct { + DisplayEvent +} + +type DisplayLostEvent struct { + DisplayEvent +} type DisplayOrientation int const ( @@ -78,10 +96,29 @@ func toDisplayOrientation(o C.int) DisplayOrientation { } type DisplayOrientationEvent struct { - EventBase + DisplayEvent Orientation DisplayOrientation } +type DisplayResizeEvent struct { + DisplayEvent + X, Y int + Width int + Height int +} + +type DisplayResumeDrawingEvent struct { + DisplayEvent +} + +type DisplaySwitchInEvent struct { + DisplayEvent +} + +type DisplaySwitchOutEvent struct { + DisplayEvent +} + type KeyEvent struct { EventBase KeyCode Key @@ -125,6 +162,7 @@ type MouseEvent struct { Z, W int Display *Display } + type MouseLeaveEvent struct { MouseEvent } @@ -155,7 +193,7 @@ func NewEventQueue() (*EventQueue, error) { if q == nil { return nil, errors.New("unable to create event queue") } - return &EventQueue{q}, nil + return &EventQueue{q, map[*C.ALLEGRO_DISPLAY]*Display{}}, nil } func (eq *EventQueue) register(source *C.ALLEGRO_EVENT_SOURCE) { @@ -164,6 +202,7 @@ func (eq *EventQueue) register(source *C.ALLEGRO_EVENT_SOURCE) { func (eq *EventQueue) RegisterDisplay(d *Display) { eq.register(C.al_get_display_event_source(d.display)) + eq.displays[d.display] = d } func (eq *EventQueue) RegisterMouse() { @@ -189,15 +228,40 @@ func (eq *EventQueue) mapEvent(e *C.ALLEGRO_EVENT) Event { case C.ALLEGRO_EVENT_AUDIO_RECORDER_FRAGMENT: recorder := (*C.ALLEGRO_AUDIO_RECORDER_EVENT)(unsafe.Pointer(e)) return &RecorderFragmentEvent{eb, unsafe.Pointer(recorder.buffer), int(recorder.samples)} + case C.ALLEGRO_EVENT_DISPLAY_CONNECTED: + display := (*C.ALLEGRO_DISPLAY_EVENT)(unsafe.Pointer(e)) + return &DisplayConnectedEvent{DisplayEvent{eb, eq.displays[display.source]}} case C.ALLEGRO_EVENT_DISPLAY_CLOSE: - return &DisplayCloseEvent{eb} + display := (*C.ALLEGRO_DISPLAY_EVENT)(unsafe.Pointer(e)) + return &DisplayCloseEvent{DisplayEvent{eb, eq.displays[display.source]}} + case C.ALLEGRO_EVENT_DISPLAY_DISCONNECTED: + display := (*C.ALLEGRO_DISPLAY_EVENT)(unsafe.Pointer(e)) + return &DisplayDisconnectedEvent{DisplayEvent{eb, eq.displays[display.source]}} + case C.ALLEGRO_EVENT_DISPLAY_FOUND: + display := (*C.ALLEGRO_DISPLAY_EVENT)(unsafe.Pointer(e)) + return &DisplayFoundEvent{DisplayEvent{eb, eq.displays[display.source]}} + case C.ALLEGRO_EVENT_DISPLAY_HALT_DRAWING: + display := (*C.ALLEGRO_DISPLAY_EVENT)(unsafe.Pointer(e)) + return &DisplayHaltDrawingEvent{DisplayEvent{eb, eq.displays[display.source]}} + case C.ALLEGRO_EVENT_DISPLAY_LOST: + display := (*C.ALLEGRO_DISPLAY_EVENT)(unsafe.Pointer(e)) + return &DisplayLostEvent{DisplayEvent{eb, eq.displays[display.source]}} case C.ALLEGRO_EVENT_DISPLAY_ORIENTATION: display := (*C.ALLEGRO_DISPLAY_EVENT)(unsafe.Pointer(e)) - return &DisplayOrientationEvent{eb, toDisplayOrientation(display.orientation)} + return &DisplayOrientationEvent{DisplayEvent{eb, eq.displays[display.source]}, toDisplayOrientation(display.orientation)} case C.ALLEGRO_EVENT_DISPLAY_RESIZE: display := (*C.ALLEGRO_DISPLAY_EVENT)(unsafe.Pointer(e)) C.al_acknowledge_resize(display.source) - return &DisplayResizeEvent{eb, int(display.x), int(display.y), int(display.width), int(display.height)} + return &DisplayResizeEvent{DisplayEvent{eb, eq.displays[display.source]}, int(display.x), int(display.y), int(display.width), int(display.height)} + case C.ALLEGRO_EVENT_DISPLAY_RESUME_DRAWING: + display := (*C.ALLEGRO_DISPLAY_EVENT)(unsafe.Pointer(e)) + return &DisplayResumeDrawingEvent{DisplayEvent{eb, eq.displays[display.source]}} + case C.ALLEGRO_EVENT_DISPLAY_SWITCH_IN: + display := (*C.ALLEGRO_DISPLAY_EVENT)(unsafe.Pointer(e)) + return &DisplaySwitchInEvent{DisplayEvent{eb, eq.displays[display.source]}} + case C.ALLEGRO_EVENT_DISPLAY_SWITCH_OUT: + display := (*C.ALLEGRO_DISPLAY_EVENT)(unsafe.Pointer(e)) + return &DisplaySwitchOutEvent{DisplayEvent{eb, eq.displays[display.source]}} case C.ALLEGRO_EVENT_MOUSE_AXES: mouse := (*C.ALLEGRO_MOUSE_EVENT)(unsafe.Pointer(e)) return &MouseMoveEvent{MouseEvent{eb, int(mouse.x), int(mouse.y), int(mouse.z), int(mouse.w), nil}, int(mouse.dx), int(mouse.dy), int(mouse.dz), int(mouse.dw), float32(mouse.pressure)}