PageRenderTime 25ms CodeModel.GetById 1ms app.highlight 18ms RepoModel.GetById 1ms app.codeStats 1ms

/xbmc/input/SDLJoystick.h

http://github.com/xbmc/xbmc
C++ Header | 103 lines | 66 code | 17 blank | 20 comment | 3 complexity | 4d80e91ea894ab5047ed8cb2a6dcaa1f MD5 | raw file
  1/*
  2 *      Copyright (C) 2007-2013 Team XBMC
  3 *      http://xbmc.org
  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 as published by
  7 *  the Free Software Foundation; either version 2, or (at your option)
  8 *  any later version.
  9 *
 10 *  This Program is distributed in the hope that it will be useful,
 11 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 12 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 13 *  GNU General Public License for more details.
 14 *
 15 *  You should have received a copy of the GNU General Public License
 16 *  along with XBMC; see the file COPYING.  If not, see
 17 *  <http://www.gnu.org/licenses/>.
 18 *
 19 */
 20
 21#ifndef SDL_JOYSTICK_H
 22#define SDL_JOYSTICK_H
 23
 24#include "system.h" // for HAS_SDL_JOYSTICK
 25#include "settings/ISettingCallback.h"
 26#include <vector>
 27#include <string>
 28
 29#define JACTIVE_BUTTON 0x00000001
 30#define JACTIVE_AXIS   0x00000002
 31#define JACTIVE_HAT    0x00000004
 32#define JACTIVE_NONE   0x00000000
 33#define JACTIVE_HAT_UP    0x01
 34#define JACTIVE_HAT_RIGHT 0x02
 35#define JACTIVE_HAT_DOWN  0x04
 36#define JACTIVE_HAT_LEFT  0x08
 37
 38#ifdef HAS_SDL_JOYSTICK
 39
 40#include <SDL/SDL_joystick.h>
 41#include <SDL/SDL_events.h>
 42
 43#define MAX_AXES 64
 44#define MAX_AXISAMOUNT 32768
 45
 46
 47// Class to manage all connected joysticks
 48
 49class CJoystick : public ISettingCallback
 50{
 51public:
 52  CJoystick();
 53
 54  virtual void OnSettingChanged(const CSetting *setting);
 55
 56  void Initialize();
 57  void Reset(bool axis=false);
 58  void ResetAxis(int axisId) { m_Amount[axisId] = 0; }
 59  void Update();
 60  void Update(SDL_Event& event);
 61  bool GetButton (int& id, bool consider_repeat=true);
 62  bool GetAxis (int &id);
 63  bool GetHat (int &id, int &position, bool consider_repeat=true);
 64  std::string GetJoystick() { return (m_JoyId>-1)?m_JoystickNames[m_JoyId]:""; }
 65  int GetAxisWithMaxAmount();
 66  float GetAmount(int axis);
 67  float GetAmount() { return GetAmount(m_AxisId); }
 68  bool IsEnabled() const { return m_joystickEnabled; }
 69  void SetEnabled(bool enabled = true);
 70  float SetDeadzone(float val);
 71  bool Reinitialize();
 72
 73private:
 74  void SetAxisActive(bool active=true) { m_ActiveFlags = active?(m_ActiveFlags|JACTIVE_AXIS):(m_ActiveFlags&(~JACTIVE_AXIS)); }
 75  void SetButtonActive(bool active=true) { m_ActiveFlags = active?(m_ActiveFlags|JACTIVE_BUTTON):(m_ActiveFlags&(~JACTIVE_BUTTON)); }
 76  void SetHatActive(bool active=true) { m_ActiveFlags = active?(m_ActiveFlags|JACTIVE_HAT):(m_ActiveFlags&(~JACTIVE_HAT)); }
 77  bool IsButtonActive() { return (m_ActiveFlags & JACTIVE_BUTTON) == JACTIVE_BUTTON; }
 78  bool IsAxisActive() { return (m_ActiveFlags & JACTIVE_AXIS) == JACTIVE_AXIS; }
 79  bool IsHatActive() { return (m_ActiveFlags & JACTIVE_HAT) == JACTIVE_HAT; }
 80
 81  bool ReleaseJoysticks();
 82
 83  int m_Amount[MAX_AXES];
 84  int m_AxisId;
 85  int m_ButtonId;
 86  uint8_t m_HatState;
 87  int m_HatId; 
 88  int m_JoyId;
 89  int m_NumAxes;
 90  int m_DeadzoneRange;
 91  bool m_joystickEnabled;
 92  uint32_t m_pressTicksButton;
 93  uint32_t m_pressTicksHat;
 94  uint8_t m_ActiveFlags;
 95  std::vector<SDL_Joystick*> m_Joysticks;
 96  std::vector<std::string> m_JoystickNames;
 97};
 98
 99extern CJoystick g_Joystick;
100
101#endif
102
103#endif