xoreos  0.0.5
fps.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/system.h"
26 #include "src/common/ustring.h"
27 
28 #include "src/graphics/graphics.h"
29 #include "src/graphics/font.h"
30 
32 
33 namespace Graphics {
34 
35 namespace Aurora {
36 
37 FPS::FPS(const FontHandle &font) : Text(Graphics::GUIElement::kGUIElementConsole, font, WindowMan.getWindowWidth(), WindowMan.getWindowHeight(), "0 fps"), _fps(0) {
38  init();
39 }
40 
42  hide();
43 }
44 
45 void FPS::init() {
46  setTag("FPS");
47  notifyResized(0, 0, WindowMan.getWindowWidth(), WindowMan.getWindowHeight());
48 }
49 
51  // Text objects should always be transparent
52  if (pass == kRenderPassOpaque)
53  return;
54 
55  uint32 fps = GfxMan.getFPS();
56 
57  if (fps != _fps) {
58  _fps = fps;
59 
61  }
62 
64 }
65 
66 void FPS::notifyResized(int UNUSED(oldWidth), int UNUSED(oldHeight), int newWidth, int newHeight) {
67  float posX = -(newWidth / 2.0f);
68  float posY = -(newHeight / 2.0f);
69 
70  setPosition(posX, posY);
71  setSize(newWidth, newHeight);
72 }
73 
74 } // End of namespace Aurora
75 
76 } // End of namespace Graphics
The global graphics manager.
virtual void hide()
Hide the object.
Definition: renderable.cpp:123
A handle to a font.
Definition: fonthandle.h:52
void setText(const Common::UString &str)
Definition: text.cpp:103
void notifyResized(int oldWidth, int oldHeight, int newWidth, int newHeight)
Definition: fps.cpp:66
void render(RenderPass pass)
Render the object.
Definition: fps.cpp:50
A text object.
Definition: text.h:42
RenderPass
Definition: types.h:97
void setPosition(float x, float y, float z=-FLT_MAX)
Definition: text.cpp:172
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
Unicode string handling.
void render(RenderPass pass)
Render the object.
Definition: text.cpp:218
#define WindowMan
Shortcut for accessing the window manager.
Definition: windowman.h:137
An element of the GUI.
Definition: guielement.h:33
uint32_t uint32
Definition: types.h:204
Low-level detection of architecture/system properties.
void setTag(const Common::UString &tag)
Set the object&#39;s tag.
Definition: renderable.cpp:102
#define pass
Definition: fft.cpp:257
A text object displaying the current FPS.
void setSize(float width, float height)
Definition: text.cpp:184
FPS(const FontHandle &font)
Definition: fps.cpp:37
A font.
#define GfxMan
Shortcut for accessing the graphics manager.
Definition: graphics.h:299
Only render opaque parts.
Definition: types.h:98