You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

151 lines
3.9 KiB

7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /***************************************************************************
  2. * Copyright (C) 2014 M Wellings *
  3. * info@openforeveryone.co.uk *
  4. * *
  5. * This program is free software; you can redistribute it and/or modify *
  6. * it under the terms of the GNU General Public License version 2 as *
  7. * published by the Free Software Foundation *
  8. * *
  9. * This program is distributed in the hope that it will be useful, *
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  12. * GNU General Public License for more details. *
  13. * *
  14. * You should have received a copy of the GNU General Public License *
  15. * along with this program; if not, write to the *
  16. * Free Software Foundation, Inc., *
  17. * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
  18. ***************************************************************************/
  19. #include "qgamecontroller.h"
  20. #include "qgamecontroller_p.h"
  21. #ifdef Q_OS_LINUX
  22. #include "qgamecontroller_linux_p.h"
  23. #elif defined (Q_OS_WIN)
  24. #include "qgamecontroller_win_p.h"
  25. #elif defined (Q_OS_MAC)
  26. #include "qgamecontroller_mac_p.h"
  27. #else
  28. #error Unsupported OS
  29. #endif
  30. #include <QtCore/QDebug>
  31. QGameControllerEvent::QGameControllerEvent(uint controllerId)
  32. :d_ptr(new QGameControllerEventPrivate(this))
  33. {
  34. Q_D(QGameControllerEvent);
  35. d->ControllerId=controllerId;
  36. }
  37. QGameControllerEvent::QGameControllerEvent(uint controllerId, QGameControllerEventPrivate &d)
  38. :d_ptr(&d)
  39. {
  40. d.ControllerId=controllerId;
  41. }
  42. uint QGameControllerEvent::controllerId()
  43. {
  44. Q_D(QGameControllerEvent);
  45. return d->ControllerId;
  46. }
  47. QGameControllerEvent::~QGameControllerEvent()
  48. {
  49. delete d_ptr;
  50. }
  51. QGameControllerButtonEvent::QGameControllerButtonEvent(uint controllerId, uint button, bool pressed)
  52. : QGameControllerEvent(controllerId, *new QGameControllerButtonEventPrivate(this))
  53. {
  54. Q_D(QGameControllerButtonEvent);
  55. d->Button=button;
  56. d->Pressed=pressed;
  57. }
  58. uint QGameControllerButtonEvent::button()
  59. {
  60. Q_D(QGameControllerButtonEvent);
  61. return d->Button;
  62. }
  63. bool QGameControllerButtonEvent::pressed()
  64. {
  65. Q_D(QGameControllerButtonEvent);
  66. return d->Pressed;
  67. }
  68. QGameControllerAxisEvent::QGameControllerAxisEvent(uint controllerId, uint axis, float value)
  69. : QGameControllerEvent(controllerId, *new QGameControllerAxisEventPrivate(this))
  70. {
  71. Q_D(QGameControllerAxisEvent);
  72. d->Axis=axis;
  73. d->Value=value;
  74. }
  75. uint QGameControllerAxisEvent::axis()
  76. {
  77. Q_D(QGameControllerAxisEvent);
  78. return d->Axis;
  79. }
  80. float QGameControllerAxisEvent::value()
  81. {
  82. Q_D(QGameControllerAxisEvent);
  83. return d->Value;
  84. }
  85. QGameController::QGameController(uint id, QObject *parent) :
  86. QObject(parent), d_ptr(new QGameControllerPrivate(id, this))
  87. {
  88. }
  89. uint QGameController::axisCount()
  90. {
  91. Q_D(QGameController);
  92. return d->Axis;
  93. }
  94. uint QGameController::buttonCount()
  95. {
  96. Q_D(QGameController);
  97. return d->Buttons;
  98. }
  99. float QGameController::axisValue(uint axis)
  100. {
  101. Q_D(QGameController);
  102. return d->AxisValues.value(axis);
  103. }
  104. bool QGameController::buttonValue(uint button)
  105. {
  106. Q_D(QGameController);
  107. return d->ButtonValues.value(button);
  108. }
  109. QString QGameController::description()
  110. {
  111. Q_D(QGameController);
  112. return d->Description;
  113. }
  114. uint QGameController::id()
  115. {
  116. Q_D(QGameController);
  117. return d->ID;
  118. }
  119. bool QGameController::isValid()
  120. {
  121. Q_D(QGameController);
  122. return d->Valid;
  123. }
  124. void QGameController::readGameController()
  125. {
  126. Q_D(QGameController);
  127. d->readGameController();
  128. }