Added UnregisterDisplay event.

Added display in mouse move, down and up events.
This commit is contained in:
Sander Schobers 2020-12-25 19:43:21 +01:00
parent 504f49ee26
commit 61164d8a92

View File

@ -264,13 +264,13 @@ func (eq *EventQueue) mapEvent(e *C.ALLEGRO_EVENT) Event {
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)}
return &MouseMoveEvent{MouseEvent{eb, int(mouse.x), int(mouse.y), int(mouse.z), int(mouse.w), eq.displays[mouse.display]}, int(mouse.dx), int(mouse.dy), int(mouse.dz), int(mouse.dw), float32(mouse.pressure)}
case C.ALLEGRO_EVENT_MOUSE_BUTTON_DOWN:
mouse := (*C.ALLEGRO_MOUSE_EVENT)(unsafe.Pointer(e))
return &MouseButtonDownEvent{MouseEvent{eb, int(mouse.x), int(mouse.y), int(mouse.z), int(mouse.w), nil}, MouseButton(mouse.button), float32(mouse.pressure)}
return &MouseButtonDownEvent{MouseEvent{eb, int(mouse.x), int(mouse.y), int(mouse.z), int(mouse.w), eq.displays[mouse.display]}, MouseButton(mouse.button), float32(mouse.pressure)}
case C.ALLEGRO_EVENT_MOUSE_ENTER_DISPLAY:
mouse := (*C.ALLEGRO_MOUSE_EVENT)(unsafe.Pointer(e))
return &MouseEnterEvent{MouseEvent{eb, int(mouse.x), int(mouse.y), int(mouse.z), int(mouse.w), nil}}
return &MouseEnterEvent{MouseEvent{eb, int(mouse.x), int(mouse.y), int(mouse.z), int(mouse.w), eq.displays[mouse.display]}}
case C.ALLEGRO_EVENT_MOUSE_BUTTON_UP:
mouse := (*C.ALLEGRO_MOUSE_EVENT)(unsafe.Pointer(e))
return &MouseButtonUpEvent{MouseEvent{eb, int(mouse.x), int(mouse.y), int(mouse.z), int(mouse.w), nil}, MouseButton(mouse.button), float32(mouse.pressure)}
@ -310,6 +310,15 @@ func (eq *EventQueue) Destroy() {
C.al_destroy_event_queue(eq.queue)
}
func (eq *EventQueue) unregister(source *C.ALLEGRO_EVENT_SOURCE) {
C.al_unregister_event_source(eq.queue, source)
}
func (eq *EventQueue) UnregisterDisplay(d *Display) {
eq.unregister(C.al_get_display_event_source(d.display))
delete(eq.displays, d.display)
}
func NewUserEventSource() *UserEventSource {
s := (*C.ALLEGRO_EVENT_SOURCE)(C.malloc(C.sizeof_ALLEGRO_EVENT_SOURCE))
source := &UserEventSource{s}