xoreos  0.0.5
legal.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/maths.h"
26 #include "src/common/ustring.h"
27 #include "src/common/readstream.h"
28 
29 #include "src/events/events.h"
30 
31 #include "src/graphics/graphics.h"
32 
34 
36 
38 
39 namespace Engines {
40 
41 namespace NWN {
42 
44 private:
45  bool _fade;
46 
48 
49  float _fadeValue;
50  float _fadeStep;
51 
52  void updateFade() {
53  if (!_fade)
54  return;
55 
56  uint32 now = EventMan.getTimestamp();
57 
58  if ((now - _fadeStart) >= 10) {
59  // Get new fade value every 10ms
60 
61  _fadeValue += _fadeStep * ((now - _fadeStart) / 10.0f);
62  _fadeStart = now;
63  }
64 
65  if (_fadeValue > 1.0f) {
66  // Fade in finished
67  _fade = false;
68  _fadeValue = 1.0f;
69  } else if (_fadeValue < 0.0f) {
70  // Fade out finished
71  _fade = false;
72  _fadeValue = 0.0f;
73  hide();
74  }
75 
76  }
77 
78 public:
79  FadeModel(const Common::UString &name) :
81  _fade(false), _fadeStart(0), _fadeValue(1.0f), _fadeStep(0.0f) {
82 
83  }
84 
86  }
87 
88  void fadeIn(uint32 length) {
89  GfxMan.lockFrame();
90 
91  _fade = true;
92  _fadeStart = EventMan.getTimestamp();
93  _fadeValue = 0.0f;
94  _fadeStep = 10.0f / length;
95 
96  show();
97 
98  GfxMan.unlockFrame();
99  }
100 
101  void fadeOut(uint32 length) {
102  GfxMan.lockFrame();
103 
104  _fade = true;
105  _fadeStart = EventMan.getTimestamp();
106  _fadeValue = 1.0f;
107  _fadeStep = - (10.0f / length);
108 
109  GfxMan.unlockFrame();
110  }
111 
113  bool isTransparent = _fadeValue < 1.0f;
114  if (((pass == Graphics::kRenderPassOpaque ) && isTransparent) ||
115  ((pass == Graphics::kRenderPassTransparent) && !isTransparent))
116  return;
117 
118  glColor4f(1.0f, 1.0f, 1.0f, _fadeValue);
120  glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
121 
122  updateFade();
123  }
124 };
125 
126 
128  _billboard.reset(new FadeModel("load_legal"));
129 
130  _billboard->setPosition(0.0f, 0.0f, -1000.0f);
131  _billboard->setTag("Legal");
132 }
133 
135 }
136 
138  _billboard->fadeIn(1000);
139 
140  bool abort = false;
141  uint32 start = EventMan.getTimestamp();
142  while ((EventMan.getTimestamp() - start) < 1000) {
143  Events::Event event;
144  while (EventMan.pollEvent(event))
145  if (event.type == Events::kEventMouseDown)
146  abort = true;
147 
148  if (abort || EventMan.quitRequested())
149  break;
150 
151  EventMan.delay(10);
152  }
153 
154  if (abort || EventMan.quitRequested()) {
155  _billboard->hide();
156  _billboard.reset();
157  }
158 }
159 
160 void Legal::show() {
161  if (!_billboard)
162  return;
163 
164  uint32 start = EventMan.getTimestamp();
165  bool fadeOut = false;
166  while (!EventMan.quitRequested()) {
167  Events::Event event;
168 
169  // Mouse click => abort
170  bool abort = false;
171  while (EventMan.pollEvent(event))
172  if (event.type == Events::kEventMouseDown)
173  abort = true;
174  if (abort)
175  break;
176 
177  if (!fadeOut && (EventMan.getTimestamp() - start) >= 5000) {
178  _billboard->fadeOut(1000);
179  fadeOut = true;
180  }
181 
182  // Display and fade-out time's up
183  if ((EventMan.getTimestamp() - start) >= 6000)
184  break;
185  }
186 
187  _billboard->hide();
188  _billboard.reset();
189 }
190 
191 } // End of namespace NWN
192 
193 } // End of namespace Engines
Model_NWN(const Common::UString &name, ModelType type=kModelTypeObject, const Common::UString &texture="", ModelCache *modelCache=0)
Definition: model_nwn.cpp:184
FadeModel(const Common::UString &name)
Definition: legal.cpp:79
Only render transparent parts.
Definition: types.h:99
The global graphics manager.
void fadeIn(uint32 length)
Definition: legal.cpp:88
An element of the front GUI.
Definition: types.h:53
A class holding an UTF-8 string.
Definition: ustring.h:48
A 3D model in the NWN MDL format.
Definition: model_nwn.h:44
Mathematical helpers.
void hide()
Hide the object.
Definition: model.cpp:116
void fadeOut(uint32 length)
Definition: legal.cpp:101
SDL_Event Event
Definition: types.h:42
Mouse button was pressed.
Definition: types.h:49
RenderPass
Definition: types.h:97
Render all parts.
Definition: types.h:100
The global events manager.
Loading MDL files found in Neverwinter Nights.
void render(Graphics::RenderPass pass)
Render the object.
Definition: legal.cpp:112
Basic reading stream interfaces.
#define EventMan
Shortcut for accessing the events manager.
Definition: events.h:210
void render(RenderPass pass)
Render the object.
Definition: model.cpp:632
Unicode string handling.
void show()
Show the object.
Definition: model.cpp:111
uint32_t uint32
Definition: types.h:204
#define pass
Definition: fft.cpp:257
#define GfxMan
Shortcut for accessing the graphics manager.
Definition: graphics.h:299
Only render opaque parts.
Definition: types.h:98
Common::ScopedPtr< FadeModel > _billboard
Definition: legal.h:46
Generic Aurora engines model functions.