SoftwareMouse.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 <graph/SoftwareMouse.h>
00022 #include <client/ScorchedClient.h>
00023 #include <engine/GameState.h>
00024 #include <image/ImageFactory.h>
00025 #include <GLEXT/GLState.h>
00026 #include <common/Defines.h>
00027 #include <graph/OptionsDisplay.h>
00028 #include <SDL/SDL.h>
00029 
00030 SoftwareMouse *SoftwareMouse::instance_ = 0;
00031 
00032 SoftwareMouse *SoftwareMouse::instance()
00033 {
00034         if (!instance_)
00035         {
00036                 instance_ = new SoftwareMouse;
00037         }
00038         return instance_;
00039 }
00040 
00041 SoftwareMouse::SoftwareMouse() :
00042         GameStateI("SoftwareMouse")
00043 {
00044 }
00045 
00046 SoftwareMouse::~SoftwareMouse()
00047 {
00048 }
00049 
00050 void SoftwareMouse::draw(const unsigned currentstate)
00051 {
00052         if (!OptionsDisplay::instance()->getSoftwareMouse()) return;
00053 
00054         static bool createdTexture = false;
00055         if (!createdTexture)
00056         {
00057                 createdTexture = true;
00058                 std::string file1 = S3D::getDataFile("data/windows/pointer.bmp");
00059                 std::string file2 = S3D::getDataFile("data/windows/pointera.bmp");
00060                 ImageHandle map = ImageFactory::loadImageHandle(file1.c_str(), file2.c_str());
00061                 mouseTex_.create(map, false);
00062 
00063                 SDL_ShowCursor(SDL_DISABLE);
00064         }
00065 
00066         GLState state(GLState::BLEND_ON | GLState::TEXTURE_ON | GLState::DEPTH_OFF); 
00067 
00068         int mouseX = ScorchedClient::instance()->getGameState().getMouseX();
00069         int mouseY = ScorchedClient::instance()->getGameState().getMouseY();
00070 
00071         mouseTex_.draw();       
00072         glPushMatrix();
00073                 glTranslatef(float(mouseX), float(mouseY), 0.0f);
00074                 glColor3f(1.0f, 1.0f, 1.0f);
00075                 
00076                 glScalef(2.0f, 2.0f, 2.0f); // Size of the mouse pointer
00077 
00078                 glTranslatef(0.0f, -16.0f, 0.0f);
00079                 glBegin(GL_QUADS);
00080                         glTexCoord2f(0.0f, 0.0f);
00081                         glVertex2f(0.0f, 0.0f);
00082                         glTexCoord2f(1.0f, 0.0f);
00083                         glVertex2f(16.0f, 0.0f);
00084                         glTexCoord2f(1.0f, 1.0f);
00085                         glVertex2f(16.0f, 16.0f);
00086                         glTexCoord2f(0.0f, 1.0f);
00087                         glVertex2f(0.0f, 16.0f);
00088                 glEnd();
00089         glPopMatrix();
00090 }
00091 

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