diff --git a/allegro5/event.go b/allegro5/event.go index ff5ed55..59572bf 100644 --- a/allegro5/event.go +++ b/allegro5/event.go @@ -93,13 +93,13 @@ type KeyUpEvent struct { type MouseButtonDownEvent struct { MouseEvent - Button uint + Button MouseButton Pressure float32 } type MouseButtonUpEvent struct { MouseEvent - Button uint + Button MouseButton Pressure float32 } @@ -159,10 +159,10 @@ func (eq *EventQueue) mapEvent(e *C.ALLEGRO_EVENT) Event { 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)} 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}, uint(mouse.button), float32(mouse.pressure)} + return &MouseButtonDownEvent{MouseEvent{eb, int(mouse.x), int(mouse.y), int(mouse.z), int(mouse.w), nil}, MouseButton(mouse.button), float32(mouse.pressure)} 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}, uint(mouse.button), float32(mouse.pressure)} + return &MouseButtonUpEvent{MouseEvent{eb, int(mouse.x), int(mouse.y), int(mouse.z), int(mouse.w), nil}, MouseButton(mouse.button), float32(mouse.pressure)} case C.ALLEGRO_EVENT_KEY_DOWN: key := (*C.ALLEGRO_KEYBOARD_EVENT)(unsafe.Pointer(e)) return &KeyDownEvent{KeyEvent{eb, Key(key.keycode), nil}} diff --git a/allegro5/keyboard.go b/allegro5/keyboard.go index 9c46a86..a12a6ec 100644 --- a/allegro5/keyboard.go +++ b/allegro5/keyboard.go @@ -175,3 +175,14 @@ func IsKeyDown(k Key) bool { C.al_get_keyboard_state(&state) return bool(C.al_key_down(&state, C.int(k))) } + +func IsAnyKeyDown(keys ...Key) bool { + var state C.ALLEGRO_KEYBOARD_STATE + C.al_get_keyboard_state(&state) + for _, k := range keys { + if bool(C.al_key_down(&state, C.int(k))) { + return true + } + } + return false +} diff --git a/allegro5/mouse.go b/allegro5/mouse.go new file mode 100644 index 0000000..5598b8e --- /dev/null +++ b/allegro5/mouse.go @@ -0,0 +1,29 @@ +package allegro5 + +// #include +import "C" + +type MouseButton uint + +const ( + MouseButtonLeft MouseButton = 1 + MouseButtonRight = 2 + MouseButtonMiddle = 3 +) + +func IsMouseButtonDown(b MouseButton) bool { + var state C.ALLEGRO_MOUSE_STATE + C.al_get_mouse_state(&state) + return bool(C.al_mouse_button_down(&state, C.int(b))) +} + +func IsAnyMouseButtonDown(buttons ...MouseButton) bool { + var state C.ALLEGRO_MOUSE_STATE + C.al_get_mouse_state(&state) + for _, b := range buttons { + if bool(C.al_mouse_button_down(&state, C.int(b))) { + return true + } + } + return false +}