Compare commits

..

No commits in common. "451f389ef64eca26f41835fe6fa789e77da0370f" and "a38d4fce4da4208c04ed9b3d6ffbc19209eac853" have entirely different histories.

3 changed files with 13 additions and 101 deletions

View File

@ -115,20 +115,8 @@ func (d *Display) SetAsTarget() {
C.al_set_target_backbuffer(d.display) C.al_set_target_backbuffer(d.display)
} }
func (d *Display) SetIcon(i ...*Bitmap) { func (d *Display) SetIcon(i *Bitmap) {
if len(i) == 0 { C.al_set_display_icon(d.display, i.bitmap)
return
}
if len(i) == 1 {
C.al_set_display_icon(d.display, i[0].bitmap)
return
}
icons := make([]*C.ALLEGRO_BITMAP, len(i))
for j := range icons {
icons[j] = i[j].bitmap
}
C.al_set_display_icons(d.display, C.int(len(icons)), &(icons[0]))
} }
func (d *Display) SetMouseCursor(c MouseCursor) { func (d *Display) SetMouseCursor(c MouseCursor) {

View File

@ -21,8 +21,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 {
@ -38,33 +37,16 @@ func (eb EventBase) Stamp() float64 {
} }
type DisplayCloseEvent struct { type DisplayCloseEvent struct {
DisplayEvent
}
type DisplayConnectedEvent struct {
DisplayEvent
}
type DisplayDisconnectedEvent struct {
DisplayEvent
}
type DisplayEvent struct {
EventBase EventBase
Display *Display
} }
type DisplayFoundEvent struct { type DisplayResizeEvent struct {
DisplayEvent EventBase
X, Y int
Width int
Height int
} }
type DisplayHaltDrawingEvent struct {
DisplayEvent
}
type DisplayLostEvent struct {
DisplayEvent
}
type DisplayOrientation int type DisplayOrientation int
const ( const (
@ -96,29 +78,10 @@ func toDisplayOrientation(o C.int) DisplayOrientation {
} }
type DisplayOrientationEvent struct { type DisplayOrientationEvent struct {
DisplayEvent EventBase
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
@ -162,7 +125,6 @@ type MouseEvent struct {
Z, W int Z, W int
Display *Display Display *Display
} }
type MouseLeaveEvent struct { type MouseLeaveEvent struct {
MouseEvent MouseEvent
} }
@ -193,7 +155,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, map[*C.ALLEGRO_DISPLAY]*Display{}}, nil return &EventQueue{q}, nil
} }
func (eq *EventQueue) register(source *C.ALLEGRO_EVENT_SOURCE) { func (eq *EventQueue) register(source *C.ALLEGRO_EVENT_SOURCE) {
@ -202,7 +164,6 @@ 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() {
@ -228,40 +189,15 @@ 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:
display := (*C.ALLEGRO_DISPLAY_EVENT)(unsafe.Pointer(e)) return &DisplayCloseEvent{eb}
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{DisplayEvent{eb, eq.displays[display.source]}, toDisplayOrientation(display.orientation)} return &DisplayOrientationEvent{eb, 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{DisplayEvent{eb, eq.displays[display.source]}, int(display.x), int(display.y), int(display.width), int(display.height)} return &DisplayResizeEvent{eb, 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)}

View File

@ -52,15 +52,3 @@ func IsAnyMouseButtonDown(buttons ...MouseButton) bool {
} }
return false return false
} }
func MousePosition() (int, int) {
var state C.ALLEGRO_MOUSE_STATE
C.al_get_mouse_state(&state)
return int(state.x), int(state.y)
}
func MousePositionScreen() (int, int, bool) {
var x, y C.int
var result = C.al_get_mouse_cursor_position(&x, &y)
return int(x), int(y), bool(result)
}