00001 /* 00002 * The Mana World 00003 * Copyright (C) 2004 The Mana World Development Team 00004 * 00005 * This file is part of The Mana World. 00006 * 00007 * This program is free software; you can redistribute it and/or modify 00008 * it under the terms of the GNU General Public License as published by 00009 * the Free Software Foundation; either version 2 of the License, or 00010 * any later version. 00011 * 00012 * This program is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU General Public License 00018 * along with this program; if not, write to the Free Software 00019 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00020 */ 00021 00022 #ifndef JOYSTICK_H 00023 #define JOYSTICK_H 00024 00025 #include <SDL.h> 00026 00027 class Joystick 00028 { 00029 public: 00033 enum 00034 { 00035 MAX_BUTTONS = 6 00036 }; 00037 00041 enum 00042 { 00043 UP = 1, 00044 DOWN = 2, 00045 LEFT = 4, 00046 RIGHT = 8 00047 }; 00048 00052 static void init(); 00053 00057 static int getNumberOfJoysticks() { return joystickCount; } 00058 00063 Joystick(int no); 00064 00065 ~Joystick(); 00066 00067 bool isEnabled() const { return mEnabled; } 00068 00069 void setEnabled(bool enabled) { mEnabled = enabled; } 00070 00074 void update(); 00075 00076 void startCalibration(); 00077 00078 void finishCalibration(); 00079 00080 bool isCalibrating() const { return mCalibrating; } 00081 00082 bool buttonPressed(unsigned char no) const; 00083 00084 bool isUp() const { return mEnabled && (mDirection & UP); }; 00085 bool isDown() const { return mEnabled && (mDirection & DOWN); }; 00086 bool isLeft() const { return mEnabled && (mDirection & LEFT); }; 00087 bool isRight() const { return mEnabled && (mDirection & RIGHT); }; 00088 00089 protected: 00090 unsigned char mDirection; 00091 bool mButtons[MAX_BUTTONS]; 00092 SDL_Joystick *mJoystick; 00093 00094 int mUpTolerance, mDownTolerance, mLeftTolerance, mRightTolerance; 00095 bool mCalibrating; 00096 bool mEnabled; 00097 00098 static int joystickCount; 00099 00100 void doCalibration(); 00101 }; 00102 00103 #endif // JOYSTICK_H