00001 00010 /*************************************************************************** 00011 * Copyright (C) 2007 by Jan Koci * 00012 * honza.koci@email.cz * 00013 * http://kengine.sourceforge.net/tutorial/ 00014 * * 00015 * This program is free software; you can redistribute it and/or modify * 00016 * it under the terms of the GNU General Public License as published by * 00017 * the Free Software Foundation; either version 2 of the License, or * 00018 * (at your option) any later version. * 00019 * * 00020 * This program is distributed in the hope that it will be useful, * 00021 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00022 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00023 * GNU General Public License for more details. * 00024 * * 00025 * You should have received a copy of the GNU General Public License * 00026 * along with this program; if not, write to the * 00027 * Free Software Foundation, Inc., * 00028 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 00029 ***************************************************************************/ 00030 00031 #pragma once 00032 00033 #include <SDL/SDL.h> 00034 #include <iostream> 00035 using namespace std; 00036 #include "../System/GameData/K3dGameData.h" 00037 00038 class K3dMouse 00039 { 00040 K3dGameData *m_pGameData; 00041 int m_aiPosition[2], m_aiPositionRel[2]; 00042 bool m_bIsWheelUp, m_bIsWheelDown; 00043 int m_iNumWheelDownFrames; 00044 int m_iNumWheelUpFrames; 00045 public: 00046 K3dMouse ( K3dGameData *_pGameData ); 00047 ~K3dMouse ( void ); 00048 00050 void UpdateMouse(); 00051 00053 int *GetMousePosition() 00054 { 00055 SDL_GetMouseState ( &m_aiPosition[0], &m_aiPosition[1] ); 00056 return m_aiPosition; 00057 } 00058 00060 int *MousePosition() 00061 { 00062 return m_aiPosition; 00063 } 00064 00066 int *MousePositionRel() 00067 { 00068 return m_aiPositionRel; 00069 } 00070 00072 bool MouseButtonLeft() 00073 { 00074 if ( SDL_GetMouseState ( NULL,NULL ) &SDL_BUTTON ( SDL_BUTTON_LEFT ) ) 00075 { 00076 //cout << "Left button pressed" << endl; 00077 return true; 00078 } 00079 return false; 00080 } 00081 00083 bool MouseButtonRight() 00084 { 00085 if ( SDL_GetMouseState ( NULL,NULL ) &SDL_BUTTON ( SDL_BUTTON_RIGHT ) ) 00086 { 00087 //cout << "Right button pressed" << endl; 00088 return true; 00089 } 00090 return false; 00091 } 00092 00094 bool MouseButtonMiddle() 00095 { 00096 if ( SDL_GetMouseState ( NULL,NULL ) &SDL_BUTTON ( SDL_BUTTON_MIDDLE ) ) 00097 { 00098 cout << "Middle button pressed" << endl; 00099 return true; 00100 } 00101 return false; 00102 } 00103 00105 bool& MouseWheelButtonDown() 00106 { 00107 if ( m_bIsWheelDown ) 00108 { 00109 cout << "Wheel down pressed" << endl; 00110 } 00111 return m_bIsWheelDown; 00112 } 00113 /* 00114 bool GetMouseWheelDown() 00115 { 00116 return m_bIsWheelDown; 00117 } 00118 */ 00120 bool& MouseWheelButtonUp() 00121 { 00122 if ( m_bIsWheelUp ) 00123 { 00124 cout << "Wheel up pressed" << endl; 00125 } 00126 return m_bIsWheelUp; 00127 } 00128 }; 00129