Added MouseButton type.

Added IsAny{MouseButton,Key}Down and IsMouseButtonDown methods.
This commit is contained in:
Sander Schobers 2018-03-29 17:21:01 +02:00
parent 499dff7a96
commit 6bd3bad160
3 changed files with 44 additions and 4 deletions

View File

@ -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}}

View File

@ -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
}

29
allegro5/mouse.go Normal file
View File

@ -0,0 +1,29 @@
package allegro5
// #include <allegro5/allegro.h>
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
}