Mouse.cpp

Go to the documentation of this file.
00001 ////////////////////////////////////////////////////////////////////////////////
00002 //    Scorched3D (c) 2000-2009
00003 //
00004 //    This file is part of Scorched3D.
00005 //
00006 //    Scorched3D is free software; you can redistribute it and/or modify
00007 //    it under the terms of the GNU General Public License as published by
00008 //    the Free Software Foundation; either version 2 of the License, or
00009 //    (at your option) any later version.
00010 //
00011 //    Scorched3D is distributed in the hope that it will be useful,
00012 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 //    GNU General Public License for more details.
00015 //
00016 //    You should have received a copy of the GNU General Public License
00017 //    along with Scorched3D; if not, write to the Free Software
00018 //    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 ////////////////////////////////////////////////////////////////////////////////
00020 
00021 #include <GLEXT/GLViewPort.h>
00022 #include <graph/Mouse.h>
00023 #include <graph/OptionsDisplay.h>
00024 #include <common/OptionsScorched.h>
00025 #include <client/ScorchedClient.h>
00026 #include <engine/GameState.h>
00027 
00028 Mouse *Mouse::instance_ = 0;
00029 
00030 Mouse *Mouse::instance()
00031 {
00032         if (!instance_) {
00033                 instance_ = new Mouse;
00034         }
00035 
00036         return instance_;
00037 }
00038 
00039 Mouse::Mouse() : mouse_sensitivity_(120)
00040 {
00041 
00042 }
00043 
00044 Mouse::~Mouse()
00045 {
00046 
00047 }
00048 
00049 
00050 
00051 void Mouse::mouseDown(SDL_Event &event)
00052 {
00053         int defaultY = (int) (event.button.y * GLViewPort::getHeightMult());
00054         if (!OptionsDisplay::instance()->getSwapYAxis())
00055         {
00056                 defaultY = GLViewPort::getHeight() - defaultY;
00057         }
00058 
00059         switch (event.button.button) {
00060         case SDL_BUTTON_LEFT:
00061                 ScorchedClient::instance()->getGameState().
00062                     mouseDown(GameState::MouseButtonLeft,
00063                                 (int) (event.button.x * GLViewPort::getWidthMult()),
00064                                 defaultY);
00065                 break;
00066         case SDL_BUTTON_MIDDLE:
00067                 ScorchedClient::instance()->getGameState().
00068                     mouseDown(GameState::MouseButtonMiddle,
00069                               (int) (event.button.x * GLViewPort::getWidthMult()),
00070                               defaultY);
00071                 break;
00072         case SDL_BUTTON_RIGHT:
00073                 ScorchedClient::instance()->getGameState().
00074                     mouseDown(GameState::MouseButtonRight,
00075                               (int) (event.button.x * GLViewPort::getWidthMult()),
00076                               defaultY);
00077                 break;
00078         case 4:
00079                 ScorchedClient::instance()->getGameState().
00080                         mouseWheel(-mouse_sensitivity_);
00081                 break;
00082         case 5:
00083                 ScorchedClient::instance()->getGameState().
00084                         mouseWheel(mouse_sensitivity_);
00085                 break;
00086         default:
00087                 break;
00088         }
00089 }
00090 
00091 void Mouse::mouseUp(SDL_Event &event)
00092 {
00093         int defaultY = (int) (event.button.y * GLViewPort::getHeightMult());
00094         if (!OptionsDisplay::instance()->getSwapYAxis())
00095         {
00096                 defaultY = GLViewPort::getHeight() - defaultY;
00097         }
00098 
00099         switch (event.button.button) {
00100         case SDL_BUTTON_LEFT:
00101                 ScorchedClient::instance()->getGameState().
00102                         mouseUp(GameState::MouseButtonLeft,
00103                                 (int) (event.button.x * GLViewPort::getWidthMult()),
00104                                 defaultY);
00105                 break;
00106         case SDL_BUTTON_MIDDLE:
00107                 ScorchedClient::instance()->getGameState().
00108                     mouseUp(GameState::MouseButtonMiddle,
00109                             (int) (event.button.x * GLViewPort::getWidthMult()),
00110                                 defaultY);
00111                 break;
00112         case SDL_BUTTON_RIGHT:
00113                 ScorchedClient::instance()->getGameState().
00114                         mouseUp(GameState::MouseButtonRight,
00115                                 (int) (event.button.x * GLViewPort::getWidthMult()),
00116                                 defaultY);
00117                 break;
00118         default:
00119                 break;
00120         }
00121 }
00122 
00123 void Mouse::mouseMove(SDL_Event &event)
00124 {
00125         int defaultY = (int) (event.button.y * GLViewPort::getHeightMult());
00126         if (!OptionsDisplay::instance()->getSwapYAxis())
00127         {
00128                 defaultY = GLViewPort::getHeight() - defaultY;
00129         }
00130 
00131         ScorchedClient::instance()->getGameState().
00132                 mouseMove(
00133                         (int) (event.button.x * GLViewPort::getWidthMult()),
00134                         defaultY);
00135 }
00136 
00137 void Mouse::processMouseEvent(SDL_Event & event)
00138 {
00139         switch (event.type) {
00140         case SDL_MOUSEBUTTONDOWN:
00141                 mouseDown(event);
00142                 break;
00143         case SDL_MOUSEBUTTONUP:
00144                 mouseUp(event);
00145                 break;
00146         case SDL_MOUSEMOTION:
00147                 mouseMove(event);
00148                 break;
00149         }
00150 }

Generated on Mon Feb 16 15:14:46 2009 for Scorched3D by  doxygen 1.5.3