xoreos  0.0.5
guibackground.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 <cfloat>
26 
27 #include "src/common/debug.h"
28 #include "src/common/util.h"
29 #include "src/common/ustring.h"
30 
31 #include "src/aurora/resman.h"
32 #include "src/aurora/types.h"
33 
34 #include "src/graphics/graphics.h"
37 
39 
40 namespace Engines {
41 
42 namespace KotOR {
43 
45  Graphics::GUIElement(front ? Graphics::GUIElement::kGUIElementFront : Graphics::GUIElement::kGUIElementBack), _type(type) {
46 
48 
49  _screenWidth = WindowMan.getWindowWidth();
50  _screenHeight = WindowMan.getWindowHeight();
51 
52  update();
53 }
54 
56  hide();
57 }
58 
60  _type = type;
61 }
62 
64 }
65 
68  return;
69 
70  TextureMan.set(_texture);
71 
72  glDisable(GL_DEPTH_TEST);
73  glDepthMask(GL_FALSE);
74 
75  glMatrixMode(GL_PROJECTION);
76  glPushMatrix();
77  glLoadIdentity();
78  glOrtho(0.0, _screenWidth, 0.0, _screenHeight, -1.0, 1.0);
79 
80  glMatrixMode(GL_MODELVIEW);
81  glLoadIdentity();
82 
83  glPushMatrix();
84 
85  glColor3f(0.0f, 0.0f, 0.0f);
86 
87  glBegin(GL_QUADS);
88  glVertex2i(0, 0);
89  glVertex2i(_screenWidth, 0);
90  glVertex2i(_screenWidth, _screenHeight);
91  glVertex2i(0, _screenHeight);
92  glEnd();
93 
94  glColor3f(1.0f, 1.0f, 1.0f);
95 
96  glBegin(GL_QUADS);
97  glTexCoord2f(0.0, 0.0);
98  glVertex2i(_vertexX1, _vertexY1);
99  glTexCoord2f(1.0, 0.0);
100  glVertex2i(_vertexX2, _vertexY1);
101  glTexCoord2f(1.0, 1.0);
102  glVertex2i(_vertexX2, _vertexY2);
103  glTexCoord2f(0.0, 1.0);
104  glVertex2i(_vertexX1, _vertexY2);
105  glEnd();
106 
107  glPopMatrix();
108 
109  glMatrixMode(GL_PROJECTION);
110  glPopMatrix();
111 
112  glMatrixMode(GL_MODELVIEW);
113 
114  glDepthMask(GL_TRUE);
115  glEnable(GL_DEPTH_TEST);
116 }
117 
120  return;
121  }
122 
123  for (size_t i = 0; i < ARRAYSIZE(Graphics::kResolutions); i++) {
126  return;
127  }
128  }
129  }
130 }
131 
132 bool GUIBackground::tryBackground(int width, int height) {
133  Common::UString name = Common::UString::format("%ux%u%s", width, height, _type.c_str());
134  if (ResMan.hasResource(name, Aurora::kResourceImage)) {
135  _texture = TextureMan.get(name);
136 
137  _vertexX1 = (_screenWidth - width) / 2;
138  _vertexX2 = _vertexX1 + width;
139  _vertexY1 = (_screenHeight - height) / 2;
140  _vertexY2 = _vertexY1 + height;
141 
142  _render = true;
143  debugC(Common::kDebugEngineGraphics, 1, "found background %s", _texture.getName().c_str());
144  } else {
145  _render = false;
146  debugC(Common::kDebugEngineGraphics, 1, "no background %s", name.c_str());
147  }
148  return _render;
149 }
150 
151 void GUIBackground::notifyResized(int UNUSED(oldWidth), int UNUSED(oldHeight), int newWidth, int newHeight) {
152  _screenHeight = newHeight;
153  _screenWidth = newWidth;
154 
155  update();
156 }
157 
158 } // End of namespace KoTOR
159 
160 } // End of namespace Engines
#define ResMan
Shortcut for accessing the sound manager.
Definition: resman.h:557
Only render transparent parts.
Definition: types.h:99
The global graphics manager.
virtual void hide()
Hide the object.
Definition: renderable.cpp:123
void debugC(Common::DebugChannel channel, uint32 level, const char *s,...)
Definition: debug.cpp:34
A class holding an UTF-8 string.
Definition: ustring.h:48
#define TextureMan
Shortcut for accessing the texture manager.
Definition: textureman.h:127
double _distance
The distance of the object from the viewer.
Definition: renderable.h:101
Utility functions for debug output.
The Aurora texture manager.
void render(Graphics::RenderPass pass)
Render the object.
#define ARRAYSIZE(x)
Macro which determines the number of entries in a fixed size array.
Definition: util.h:131
GUIBackground(const Common::UString &type=kBackgroundTypeMenu, bool front=false)
void setType(const Common::UString &type)
const char * c_str() const
Return the (utf8 encoded) string data.
Definition: ustring.cpp:249
RenderPass
Definition: types.h:97
static UString format(const char *s,...) GCC_PRINTF(1
Print formatted data into an UString object, similar to sprintf().
Definition: ustring.cpp:718
#define UNUSED(x)
Definition: system.h:170
Utility templates and functions.
An image resource.
Definition: types.h:408
void calculateDistance()
Calculate the object&#39;s distance.
Graphics::Aurora::TextureHandle _texture
Definition: guibackground.h:62
Unicode string handling.
Basic type definitions to handle files used in BioWare&#39;s Aurora engine.
#define WindowMan
Shortcut for accessing the window manager.
Definition: windowman.h:137
static const Resolution kResolutions[]
Definition: resolution.h:35
void notifyResized(int oldWidth, int oldHeight, int newWidth, int newHeight)
#define pass
Definition: fft.cpp:257
const Common::UString & getName() const
bool tryBackground(int x, int y)
"EGraphics", engine graphics.
Definition: debugman.h:55
#define FLT_MAX
Definition: maths.h:47
The global resource manager for Aurora resources.
The menu background.
A list common video resolutions.