Added MouseButton type.
Added IsAny{MouseButton,Key}Down and IsMouseButtonDown methods.
This commit is contained in:
parent
499dff7a96
commit
6bd3bad160
@ -93,13 +93,13 @@ type KeyUpEvent struct {
|
|||||||
|
|
||||||
type MouseButtonDownEvent struct {
|
type MouseButtonDownEvent struct {
|
||||||
MouseEvent
|
MouseEvent
|
||||||
Button uint
|
Button MouseButton
|
||||||
Pressure float32
|
Pressure float32
|
||||||
}
|
}
|
||||||
|
|
||||||
type MouseButtonUpEvent struct {
|
type MouseButtonUpEvent struct {
|
||||||
MouseEvent
|
MouseEvent
|
||||||
Button uint
|
Button MouseButton
|
||||||
Pressure float32
|
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)}
|
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:
|
case C.ALLEGRO_EVENT_MOUSE_BUTTON_DOWN:
|
||||||
mouse := (*C.ALLEGRO_MOUSE_EVENT)(unsafe.Pointer(e))
|
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:
|
case C.ALLEGRO_EVENT_MOUSE_BUTTON_UP:
|
||||||
mouse := (*C.ALLEGRO_MOUSE_EVENT)(unsafe.Pointer(e))
|
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:
|
case C.ALLEGRO_EVENT_KEY_DOWN:
|
||||||
key := (*C.ALLEGRO_KEYBOARD_EVENT)(unsafe.Pointer(e))
|
key := (*C.ALLEGRO_KEYBOARD_EVENT)(unsafe.Pointer(e))
|
||||||
return &KeyDownEvent{KeyEvent{eb, Key(key.keycode), nil}}
|
return &KeyDownEvent{KeyEvent{eb, Key(key.keycode), nil}}
|
||||||
|
@ -175,3 +175,14 @@ func IsKeyDown(k Key) bool {
|
|||||||
C.al_get_keyboard_state(&state)
|
C.al_get_keyboard_state(&state)
|
||||||
return bool(C.al_key_down(&state, C.int(k)))
|
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
29
allegro5/mouse.go
Normal 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
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user