Compare commits
No commits in common. "451f389ef64eca26f41835fe6fa789e77da0370f" and "a38d4fce4da4208c04ed9b3d6ffbc19209eac853" have entirely different histories.
451f389ef6
...
a38d4fce4d
16
display.go
16
display.go
@ -115,20 +115,8 @@ func (d *Display) SetAsTarget() {
|
||||
C.al_set_target_backbuffer(d.display)
|
||||
}
|
||||
|
||||
func (d *Display) SetIcon(i ...*Bitmap) {
|
||||
if len(i) == 0 {
|
||||
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) SetIcon(i *Bitmap) {
|
||||
C.al_set_display_icon(d.display, i.bitmap)
|
||||
}
|
||||
|
||||
func (d *Display) SetMouseCursor(c MouseCursor) {
|
||||
|
84
event.go
84
event.go
@ -22,7 +22,6 @@ import (
|
||||
|
||||
type EventQueue struct {
|
||||
queue *C.ALLEGRO_EVENT_QUEUE
|
||||
displays map[*C.ALLEGRO_DISPLAY]*Display
|
||||
}
|
||||
|
||||
type Event interface {
|
||||
@ -38,33 +37,16 @@ func (eb EventBase) Stamp() float64 {
|
||||
}
|
||||
|
||||
type DisplayCloseEvent struct {
|
||||
DisplayEvent
|
||||
}
|
||||
|
||||
type DisplayConnectedEvent struct {
|
||||
DisplayEvent
|
||||
}
|
||||
|
||||
type DisplayDisconnectedEvent struct {
|
||||
DisplayEvent
|
||||
}
|
||||
|
||||
type DisplayEvent struct {
|
||||
EventBase
|
||||
Display *Display
|
||||
}
|
||||
|
||||
type DisplayFoundEvent struct {
|
||||
DisplayEvent
|
||||
type DisplayResizeEvent struct {
|
||||
EventBase
|
||||
X, Y int
|
||||
Width int
|
||||
Height int
|
||||
}
|
||||
|
||||
type DisplayHaltDrawingEvent struct {
|
||||
DisplayEvent
|
||||
}
|
||||
|
||||
type DisplayLostEvent struct {
|
||||
DisplayEvent
|
||||
}
|
||||
type DisplayOrientation int
|
||||
|
||||
const (
|
||||
@ -96,29 +78,10 @@ func toDisplayOrientation(o C.int) DisplayOrientation {
|
||||
}
|
||||
|
||||
type DisplayOrientationEvent struct {
|
||||
DisplayEvent
|
||||
EventBase
|
||||
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
|
||||
@ -162,7 +125,6 @@ type MouseEvent struct {
|
||||
Z, W int
|
||||
Display *Display
|
||||
}
|
||||
|
||||
type MouseLeaveEvent struct {
|
||||
MouseEvent
|
||||
}
|
||||
@ -193,7 +155,7 @@ func NewEventQueue() (*EventQueue, error) {
|
||||
if q == nil {
|
||||
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) {
|
||||
@ -202,7 +164,6 @@ 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() {
|
||||
@ -228,40 +189,15 @@ 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:
|
||||
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]}}
|
||||
return &DisplayCloseEvent{eb}
|
||||
case C.ALLEGRO_EVENT_DISPLAY_ORIENTATION:
|
||||
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:
|
||||
display := (*C.ALLEGRO_DISPLAY_EVENT)(unsafe.Pointer(e))
|
||||
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)}
|
||||
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]}}
|
||||
return &DisplayResizeEvent{eb, int(display.x), int(display.y), int(display.width), int(display.height)}
|
||||
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)}
|
||||
|
12
mouse.go
12
mouse.go
@ -52,15 +52,3 @@ func IsAnyMouseButtonDown(buttons ...MouseButton) bool {
|
||||
}
|
||||
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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user