git-svn-id: https://scorched3d.svn.sourceforge.net/svnroot/scorched3d/trunk/scorched...
[scorched3d/parasti.git] / src / client / graph / SoftwareMouse.cpp
blobbc9b479db559a39243441ea8b07d745abb533982
1 ////////////////////////////////////////////////////////////////////////////////
2 // Scorched3D (c) 2000-2009
3 //
4 // This file is part of Scorched3D.
5 //
6 // Scorched3D is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2 of the License, or
9 // (at your option) any later version.
11 // Scorched3D is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with Scorched3D; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 ////////////////////////////////////////////////////////////////////////////////
21 #include <graph/SoftwareMouse.h>
22 #include <client/ScorchedClient.h>
23 #include <engine/GameState.h>
24 #include <image/ImageFactory.h>
25 #include <GLEXT/GLState.h>
26 #include <common/Defines.h>
27 #include <graph/OptionsDisplay.h>
28 #include <SDL/SDL.h>
30 SoftwareMouse *SoftwareMouse::instance_ = 0;
32 SoftwareMouse *SoftwareMouse::instance()
34 if (!instance_)
36 instance_ = new SoftwareMouse;
38 return instance_;
41 SoftwareMouse::SoftwareMouse() :
42 GameStateI("SoftwareMouse")
46 SoftwareMouse::~SoftwareMouse()
50 void SoftwareMouse::draw(const unsigned currentstate)
52 if (!OptionsDisplay::instance()->getSoftwareMouse()) return;
54 static bool createdTexture = false;
55 if (!createdTexture)
57 createdTexture = true;
58 std::string file1 = S3D::getDataFile("data/windows/pointer.bmp");
59 std::string file2 = S3D::getDataFile("data/windows/pointera.bmp");
60 ImageHandle map = ImageFactory::loadImageHandle(file1.c_str(), file2.c_str());
61 mouseTex_.create(map, false);
63 SDL_ShowCursor(SDL_DISABLE);
66 GLState state(GLState::BLEND_ON | GLState::TEXTURE_ON | GLState::DEPTH_OFF);
68 int mouseX = ScorchedClient::instance()->getGameState().getMouseX();
69 int mouseY = ScorchedClient::instance()->getGameState().getMouseY();
71 mouseTex_.draw();
72 glPushMatrix();
73 glTranslatef(float(mouseX), float(mouseY), 0.0f);
74 glColor3f(1.0f, 1.0f, 1.0f);
76 glScalef(2.0f, 2.0f, 2.0f); // Size of the mouse pointer
78 glTranslatef(0.0f, -16.0f, 0.0f);
79 glBegin(GL_QUADS);
80 glTexCoord2f(0.0f, 0.0f);
81 glVertex2f(0.0f, 0.0f);
82 glTexCoord2f(1.0f, 0.0f);
83 glVertex2f(16.0f, 0.0f);
84 glTexCoord2f(1.0f, 1.0f);
85 glVertex2f(16.0f, 16.0f);
86 glTexCoord2f(0.0f, 1.0f);
87 glVertex2f(0.0f, 16.0f);
88 glEnd();
89 glPopMatrix();