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 Jade {
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  glBegin(GL_QUADS);
86  glTexCoord2f(0.0, 0.0);
87  glVertex2i(_vertexX1, _vertexY1);
88  glTexCoord2f(1.0, 0.0);
89  glVertex2i(_vertexX2, _vertexY1);
90  glTexCoord2f(1.0, 1.0);
91  glVertex2i(_vertexX2, _vertexY2);
92  glTexCoord2f(0.0, 1.0);
93  glVertex2i(_vertexX1, _vertexY2);
94  glEnd();
95 
96  glPopMatrix();
97 
98  glMatrixMode(GL_PROJECTION);
99  glPopMatrix();
100 
101  glMatrixMode(GL_MODELVIEW);
102 
103  glDepthMask(GL_TRUE);
104  glEnable(GL_DEPTH_TEST);
105 }
106 
109  return;
110  }
111 
112  for (size_t i = 0; i < ARRAYSIZE(Graphics::kResolutions); i++) {
115  return;
116  }
117  }
118  }
119 }
120 
121 bool GUIBackground::tryBackground(int width, int height) {
122  Common::UString name = Common::UString::format("%ux%u%s", width, height, _type.c_str());
123  if (ResMan.hasResource(name, Aurora::kResourceImage)) {
124  _texture = TextureMan.get(name);
125 
126  _vertexX1 = (_screenWidth - width) / 2;
127  _vertexX2 = _vertexX1 + width;
128  _vertexY1 = (_screenHeight - height) / 2;
129  _vertexY2 = _vertexY1 + height;
130 
131  _render = true;
132  debugC(Common::kDebugEngineGraphics, 1, "found background %s", _texture.getName().c_str());
133  } else {
134  _render = false;
135  debugC(Common::kDebugEngineGraphics, 1, "no background %s", name.c_str());
136  }
137  return _render;
138 }
139 
140 void GUIBackground::notifyResized(int UNUSED(oldWidth), int UNUSED(oldHeight), int newWidth, int newHeight) {
141  _screenHeight = newHeight;
142  _screenWidth = newWidth;
143 
144  update();
145 }
146 
147 } // End of namespace Jade
148 
149 } // End of namespace Engines
#define ResMan
Shortcut for accessing the sound manager.
Definition: resman.h:557
void setType(const Common::UString &type)
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.
#define ARRAYSIZE(x)
Macro which determines the number of entries in a fixed size array.
Definition: util.h:131
void notifyResized(int oldWidth, int oldHeight, int newWidth, int newHeight)
GUIBackground(const Common::UString &type=kBackgroundTypeMenu, bool front=false)
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
void render(Graphics::RenderPass pass)
Render the object.
The menu background.
#define UNUSED(x)
Definition: system.h:170
Utility templates and functions.
void calculateDistance()
Calculate the object&#39;s distance.
An image resource.
Definition: types.h:408
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
bool tryBackground(int x, int y)
#define pass
Definition: fft.cpp:257
const Common::UString & getName() const
"EGraphics", engine graphics.
Definition: debugman.h:55
#define FLT_MAX
Definition: maths.h:47
The global resource manager for Aurora resources.
Graphics::Aurora::TextureHandle _texture
Definition: guibackground.h:62
A list common video resolutions.