xoreos  0.0.5
cursor.cpp
Go to the documentation of this file.
1 /* xoreos - A reimplementation of BioWare's Aurora engine
2  *
3  * xoreos is the legal property of its developers, whose names
4  * can be found in the AUTHORS file distributed with this source
5  * distribution.
6  *
7  * xoreos is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 3
10  * of the License, or (at your option) any later version.
11  *
12  * xoreos is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with xoreos. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
25 #include "src/common/scopedptr.h"
26 #include "src/common/util.h"
27 #include "src/common/error.h"
28 #include "src/common/readstream.h"
29 
30 #include "src/aurora/types.h"
31 #include "src/aurora/resman.h"
32 
33 #include "src/graphics/graphics.h"
34 
40 
45 
46 namespace Graphics {
47 
48 namespace Aurora {
49 
50 Cursor::Cursor(const Common::UString &name, int hotspotX, int hotspotY) :
51  _name(name), _hotspotX(hotspotX), _hotspotY(hotspotY) {
52 
53  load();
54 }
55 
57 }
58 
60  TextureMan.reset();
61  TextureMan.set(_texture);
62 
63  int x, y;
64  CursorMan.getPosition(x, y);
65 
66  glTranslatef(x - _hotspotX, -y - _height + _hotspotY, 0.0f);
67 
68  glBegin(GL_QUADS);
69  glTexCoord2f(0.0f, 0.0f);
70  glVertex2f(0.0f, 0.0f);
71  glTexCoord2f(1.0f, 0.0f);
72  glVertex2f(_height, 0.0f);
73  glTexCoord2f(1.0f, 1.0f);
74  glVertex2f(_height, _width);
75  glTexCoord2f(0.0f, 1.0f);
76  glVertex2f(0.0f, _width);
77  glEnd();
78 
79  TextureMan.reset();
80 }
81 
82 void Cursor::load() {
83  ::Aurora::FileType type;
84 
86  img(ResMan.getResource(::Aurora::kResourceCursor, _name, &type));
87  if (!img)
88  throw Common::Exception("No such cursor resource \"%s\"", _name.c_str());
89 
90  _hotspotX = 0;
91  _hotspotY = 0;
92 
94 
95  // Loading the different image formats
96  if (type == ::Aurora::kFileTypeTGA)
97  image.reset(new TGA(*img));
98  else if (type == ::Aurora::kFileTypeDDS)
99  image.reset(new DDS(*img));
100  else if (type == ::Aurora::kFileTypeCUR) {
102 
103  if (_hotspotX < 0)
104  _hotspotX = cursor->getHotspotX();
105  if (_hotspotY < 0)
106  _hotspotY = cursor->getHotspotY();
107 
108  image.reset(cursor.release());
109  } else
110  throw Common::Exception("Unsupported cursor resource type %d", (int) type);
111 
112  _width = image->getMipMap(0).width;
113  _height = image->getMipMap(0).height;
114 
115  TXI *txi = new TXI();
116  txi->getFeatures().filter = false;
117 
118  // If we need manual DeS3TC, we decompress the cursor image
119  if (GfxMan.needManualDeS3TC()) {
120  image->decompress();
121  }
122 
123  _texture = TextureMan.add(Texture::create(image.release(), type, txi), _name);
124 
125  _hotspotX = CLIP(_hotspotX, 0, _width - 1);
126  _hotspotY = CLIP(_hotspotY, 0, _height - 1);
127 }
128 
129 } // End of namespace Aurora
130 
131 } // End of namespace Graphics
#define ResMan
Shortcut for accessing the sound manager.
Definition: resman.h:557
Generic image decoder interface.
DDS texture (DirectDraw Surface or BioWare&#39;s own format) loading).
The global graphics manager.
TextureHandle _texture
Definition: cursor.h:50
void render()
Render the cursor.
Definition: cursor.cpp:59
A class holding an UTF-8 string.
Definition: ustring.h:48
#define TextureMan
Shortcut for accessing the texture manager.
Definition: textureman.h:127
void reset(PointerType o=0)
Resets the pointer with the new value.
Definition: scopedptr.h:87
PointerType release()
Returns the plain pointer value and releases ScopedPtr.
Definition: scopedptr.h:103
static Texture * create(const Common::UString &name, bool deswizzle=false)
Create a texture from this image resource.
Definition: texture.cpp:323
The Aurora texture manager.
TarGa image.
Definition: tga.h:66
Cursor, Windows cursor.
Definition: types.h:286
A simple scoped smart pointer template.
DDS texture.
Definition: dds.h:44
Basic exceptions to throw.
const char * c_str() const
Return the (utf8 encoded) string data.
Definition: ustring.cpp:249
Common::UString _name
Definition: cursor.h:48
Utility templates and functions.
Texture information.
StackException Exception
Definition: error.h:59
#define CursorMan
Shortcut for accessing the cursor manager.
Definition: cursorman.h:129
A cursor as used in the Aurora engines.
Basic reading stream interfaces.
The Aurora cursor manager.
Basic type definitions to handle files used in BioWare&#39;s Aurora engine.
Decoding TGA (TarGa) images.
A texture as used in the Aurora engines.
Texture information.
Definition: txi.h:40
Windows cursor.
Definition: winiconimage.h:37
Decoding Windows icon and cursor files (.ICO and .CUR).
FileType
Various file types used by the Aurora engine and found in archives.
Definition: types.h:56
Image, Truevision TARGA image.
Definition: types.h:61
const Features & getFeatures() const
Definition: txi.cpp:283
T CLIP(T v, T amin, T amax)
Definition: util.h:72
Texture, DirectDraw Surface.
Definition: types.h:98
#define GfxMan
Shortcut for accessing the graphics manager.
Definition: graphics.h:299
A cursor resource.
Definition: types.h:412
The global resource manager for Aurora resources.