touch_input.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. package al
  2. /*
  3. #include <stdlib.h>
  4. #include <allegro5/allegro.h>
  5. #include "helpers.h"
  6. */
  7. import "C"
  8. /* Enum: ALLEGRO_TOUCH_INPUT_MAX_TOUCH_COUNT
  9. */
  10. const TOUCH_INPUT_MAX_TOUCH_COUNT = C.ALLEGRO_TOUCH_INPUT_MAX_TOUCH_COUNT
  11. type TouchInput struct {
  12. handle * C.ALLEGRO_TOUCH_INPUT
  13. }
  14. func wrapTouchInputRaw(cti * C.ALLEGRO_TOUCH_INPUT) * TouchInput {
  15. res := &TouchInput{cti}
  16. return res
  17. }
  18. type TouchInputState C.ALLEGRO_TOUCH_INPUT_STATE
  19. func wrapTouchInputStateRaw(cti C.ALLEGRO_TOUCH_INPUT_STATE) TouchInputState {
  20. return TouchInputState(cti)
  21. }
  22. type TouchState C.ALLEGRO_TOUCH_STATE
  23. func wrapTouchStateRaw(ts C.ALLEGRO_TOUCH_STATE) TouchState {
  24. return TouchState(ts)
  25. }
  26. func (ts TouchState) Id() int {
  27. return int(ts.id)
  28. }
  29. func (ts TouchState) X() float32 { return float32(ts.x); }
  30. func (ts TouchState) Y() float32 { return float32(ts.y); }
  31. func (ts TouchState) DX() float32 { return float32(ts.dx); }
  32. func (ts TouchState) DY() float32 { return float32(ts.dy); }
  33. func (ts TouchState) Primary() bool { return bool(ts.primary); }
  34. func (ts TouchState) Display() * Display { return wrapDisplayRaw(ts.display); }
  35. func (tsi TouchInputState) Touch(index int) TouchState {
  36. return wrapTouchStateRaw(tsi.touches[index])
  37. }
  38. func IsTouchInputInstalled() bool {
  39. return bool(C.al_is_touch_input_installed())
  40. }
  41. func InstallTouchInput() bool {
  42. return bool(C.al_install_touch_input())
  43. }
  44. func UninstallTouchInput() {
  45. C.al_uninstall_touch_input()
  46. }
  47. func PollTouchInputState() TouchInputState {
  48. cstate := C.struct_ALLEGRO_TOUCH_INPUT_STATE{}
  49. C.al_get_touch_input_state(&cstate)
  50. return wrapTouchInputStateRaw(cstate)
  51. }
  52. func TouchInputEventSource() * EventSource {
  53. return wrapEventSourceRaw(C.al_get_touch_input_event_source())
  54. }