Added missing display events.
Added Display parameter to display events.
This commit is contained in:
parent
6468ff1b33
commit
9002c2b24d
86
event.go
86
event.go
@ -22,6 +22,7 @@ import (
|
|||||||
|
|
||||||
type EventQueue struct {
|
type EventQueue struct {
|
||||||
queue *C.ALLEGRO_EVENT_QUEUE
|
queue *C.ALLEGRO_EVENT_QUEUE
|
||||||
|
displays map[*C.ALLEGRO_DISPLAY]*Display
|
||||||
}
|
}
|
||||||
|
|
||||||
type Event interface {
|
type Event interface {
|
||||||
@ -37,16 +38,33 @@ func (eb EventBase) Stamp() float64 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type DisplayCloseEvent struct {
|
type DisplayCloseEvent struct {
|
||||||
EventBase
|
DisplayEvent
|
||||||
}
|
}
|
||||||
|
|
||||||
type DisplayResizeEvent struct {
|
type DisplayConnectedEvent struct {
|
||||||
EventBase
|
DisplayEvent
|
||||||
X, Y int
|
|
||||||
Width int
|
|
||||||
Height int
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
type DisplayOrientation int
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -78,10 +96,29 @@ func toDisplayOrientation(o C.int) DisplayOrientation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type DisplayOrientationEvent struct {
|
type DisplayOrientationEvent struct {
|
||||||
EventBase
|
DisplayEvent
|
||||||
Orientation DisplayOrientation
|
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 {
|
type KeyEvent struct {
|
||||||
EventBase
|
EventBase
|
||||||
KeyCode Key
|
KeyCode Key
|
||||||
@ -125,6 +162,7 @@ type MouseEvent struct {
|
|||||||
Z, W int
|
Z, W int
|
||||||
Display *Display
|
Display *Display
|
||||||
}
|
}
|
||||||
|
|
||||||
type MouseLeaveEvent struct {
|
type MouseLeaveEvent struct {
|
||||||
MouseEvent
|
MouseEvent
|
||||||
}
|
}
|
||||||
@ -155,7 +193,7 @@ func NewEventQueue() (*EventQueue, error) {
|
|||||||
if q == nil {
|
if q == nil {
|
||||||
return nil, errors.New("unable to create event queue")
|
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) {
|
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) {
|
func (eq *EventQueue) RegisterDisplay(d *Display) {
|
||||||
eq.register(C.al_get_display_event_source(d.display))
|
eq.register(C.al_get_display_event_source(d.display))
|
||||||
|
eq.displays[d.display] = d
|
||||||
}
|
}
|
||||||
|
|
||||||
func (eq *EventQueue) RegisterMouse() {
|
func (eq *EventQueue) RegisterMouse() {
|
||||||
@ -189,15 +228,40 @@ func (eq *EventQueue) mapEvent(e *C.ALLEGRO_EVENT) Event {
|
|||||||
case C.ALLEGRO_EVENT_AUDIO_RECORDER_FRAGMENT:
|
case C.ALLEGRO_EVENT_AUDIO_RECORDER_FRAGMENT:
|
||||||
recorder := (*C.ALLEGRO_AUDIO_RECORDER_EVENT)(unsafe.Pointer(e))
|
recorder := (*C.ALLEGRO_AUDIO_RECORDER_EVENT)(unsafe.Pointer(e))
|
||||||
return &RecorderFragmentEvent{eb, unsafe.Pointer(recorder.buffer), int(recorder.samples)}
|
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:
|
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:
|
case C.ALLEGRO_EVENT_DISPLAY_ORIENTATION:
|
||||||
display := (*C.ALLEGRO_DISPLAY_EVENT)(unsafe.Pointer(e))
|
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:
|
case C.ALLEGRO_EVENT_DISPLAY_RESIZE:
|
||||||
display := (*C.ALLEGRO_DISPLAY_EVENT)(unsafe.Pointer(e))
|
display := (*C.ALLEGRO_DISPLAY_EVENT)(unsafe.Pointer(e))
|
||||||
C.al_acknowledge_resize(display.source)
|
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:
|
case C.ALLEGRO_EVENT_MOUSE_AXES:
|
||||||
mouse := (*C.ALLEGRO_MOUSE_EVENT)(unsafe.Pointer(e))
|
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), nil}, int(mouse.dx), int(mouse.dy), int(mouse.dz), int(mouse.dw), float32(mouse.pressure)}
|
||||||
|
Loading…
Reference in New Issue
Block a user