1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
|
/*
* $Id$
* ***** BEGIN GPL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
* All rights reserved.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL LICENSE BLOCK *****
*/
/** \file ghost/intern/GHOST_System.cpp
* \ingroup GHOST
*/
/**
* $Id$
* Copyright (C) 2001 NaN Technologies B.V.
* @author Maarten Gribnau
* @date May 7, 2001
*/
#include "GHOST_System.h"
#include <time.h>
#include <stdio.h> /* just for printf */
#include "GHOST_DisplayManager.h"
#include "GHOST_EventManager.h"
#include "GHOST_NDOFManager.h"
#include "GHOST_TimerTask.h"
#include "GHOST_TimerManager.h"
#include "GHOST_WindowManager.h"
GHOST_System::GHOST_System()
: m_displayManager(0), m_timerManager(0), m_windowManager(0), m_eventManager(0), m_ndofManager(0)
{
}
GHOST_System::~GHOST_System()
{
exit();
}
GHOST_TUns64 GHOST_System::getMilliSeconds() const
{
GHOST_TUns64 millis = ::clock();
if (CLOCKS_PER_SEC != 1000) {
millis *= 1000;
millis /= CLOCKS_PER_SEC;
}
return millis;
}
GHOST_ITimerTask* GHOST_System::installTimer(GHOST_TUns64 delay, GHOST_TUns64 interval, GHOST_TimerProcPtr timerProc, GHOST_TUserDataPtr userData)
{
GHOST_TUns64 millis = getMilliSeconds();
GHOST_TimerTask* timer = new GHOST_TimerTask(millis+delay, interval, timerProc, userData);
if (timer) {
if (m_timerManager->addTimer(timer) == GHOST_kSuccess) {
// Check to see whether we need to fire the timer right away
m_timerManager->fireTimers(millis);
}
else {
delete timer;
timer = 0;
}
}
return timer;
}
GHOST_TSuccess GHOST_System::removeTimer(GHOST_ITimerTask* timerTask)
{
GHOST_TSuccess success = GHOST_kFailure;
if (timerTask) {
success = m_timerManager->removeTimer((GHOST_TimerTask*)timerTask);
}
return success;
}
GHOST_TSuccess GHOST_System::disposeWindow(GHOST_IWindow* window)
{
GHOST_TSuccess success;
/*
* Remove all pending events for the window.
*/
if (m_windowManager->getWindowFound(window)) {
m_eventManager->removeWindowEvents(window);
}
if (window == m_windowManager->getFullScreenWindow()) {
success = endFullScreen();
}
else {
if (m_windowManager->getWindowFound(window)) {
success = m_windowManager->removeWindow(window);
if (success) {
delete window;
}
}
else {
success = GHOST_kFailure;
}
}
return success;
}
bool GHOST_System::validWindow(GHOST_IWindow* window)
{
return m_windowManager->getWindowFound(window);
}
GHOST_TSuccess GHOST_System::beginFullScreen(const GHOST_DisplaySetting& setting, GHOST_IWindow** window,
const bool stereoVisual)
{
GHOST_TSuccess success = GHOST_kFailure;
GHOST_ASSERT(m_windowManager, "GHOST_System::beginFullScreen(): invalid window manager")
if (m_displayManager) {
if (!m_windowManager->getFullScreen()) {
m_displayManager->getCurrentDisplaySetting(GHOST_DisplayManager::kMainDisplay, m_preFullScreenSetting);
//GHOST_PRINT("GHOST_System::beginFullScreen(): activating new display settings\n");
success = m_displayManager->setCurrentDisplaySetting(GHOST_DisplayManager::kMainDisplay, setting);
if (success == GHOST_kSuccess) {
//GHOST_PRINT("GHOST_System::beginFullScreen(): creating full-screen window\n");
success = createFullScreenWindow((GHOST_Window**)window, stereoVisual);
if (success == GHOST_kSuccess) {
m_windowManager->beginFullScreen(*window, stereoVisual);
}
else {
m_displayManager->setCurrentDisplaySetting(GHOST_DisplayManager::kMainDisplay, m_preFullScreenSetting);
}
}
}
}
if (success == GHOST_kFailure) {
GHOST_PRINT("GHOST_System::beginFullScreen(): could not enter full-screen mode\n");
}
return success;
}
GHOST_TSuccess GHOST_System::endFullScreen(void)
{
GHOST_TSuccess success = GHOST_kFailure;
GHOST_ASSERT(m_windowManager, "GHOST_System::endFullScreen(): invalid window manager")
if (m_windowManager->getFullScreen()) {
//GHOST_IWindow* window = m_windowManager->getFullScreenWindow();
//GHOST_PRINT("GHOST_System::endFullScreen(): leaving window manager full-screen mode\n");
success = m_windowManager->endFullScreen();
GHOST_ASSERT(m_displayManager, "GHOST_System::endFullScreen(): invalid display manager")
//GHOST_PRINT("GHOST_System::endFullScreen(): leaving full-screen mode\n");
success = m_displayManager->setCurrentDisplaySetting(GHOST_DisplayManager::kMainDisplay, m_preFullScreenSetting);
}
else {
success = GHOST_kFailure;
}
return success;
}
bool GHOST_System::getFullScreen(void)
{
bool fullScreen;
if (m_windowManager) {
fullScreen = m_windowManager->getFullScreen();
}
else {
fullScreen = false;
}
return fullScreen;
}
bool GHOST_System::dispatchEvents()
{
bool handled;
if (m_eventManager) {
handled = m_eventManager->dispatchEvents();
}
else {
handled = false;
}
m_timerManager->fireTimers(getMilliSeconds());
return handled;
}
GHOST_TSuccess GHOST_System::addEventConsumer(GHOST_IEventConsumer* consumer)
{
GHOST_TSuccess success;
if (m_eventManager) {
success = m_eventManager->addConsumer(consumer);
}
else {
success = GHOST_kFailure;
}
return success;
}
GHOST_TSuccess GHOST_System::beginRecord(FILE *file)
{
return this->m_eventManager->beginRecord(file);
}
GHOST_TSuccess GHOST_System::endRecord()
{
return this->m_eventManager->endRecord();
}
GHOST_TSuccess GHOST_System::playbackEvents(FILE *file)
{
return this->m_eventManager->playbackEvents(file);
}
bool GHOST_System::playingEvents(bool *hasevent) const
{
return this->m_eventManager->playingEvents(hasevent);
}
bool GHOST_System::recordingEvents()
{
return this->m_eventManager->recordingEvents();
}
GHOST_TSuccess GHOST_System::pushEvent(GHOST_IEvent* event)
{
GHOST_TSuccess success;
if (m_eventManager && !m_eventManager->playingEvents(NULL)) {
success = m_eventManager->pushEvent(event);
}
else {
success = GHOST_kFailure;
}
return success;
}
int GHOST_System::openNDOF(GHOST_IWindow* w,
GHOST_NDOFLibraryInit_fp setNdofLibraryInit,
GHOST_NDOFLibraryShutdown_fp setNdofLibraryShutdown,
GHOST_NDOFDeviceOpen_fp setNdofDeviceOpen)
{
return m_ndofManager->deviceOpen(w,
setNdofLibraryInit,
setNdofLibraryShutdown,
setNdofDeviceOpen);
}
GHOST_TSuccess GHOST_System::getModifierKeyState(GHOST_TModifierKeyMask mask, bool& isDown) const
{
GHOST_ModifierKeys keys;
// Get the state of all modifier keys
GHOST_TSuccess success = getModifierKeys(keys);
if (success) {
// Isolate the state of the key requested
isDown = keys.get(mask);
}
return success;
}
GHOST_TSuccess GHOST_System::getButtonState(GHOST_TButtonMask mask, bool& isDown) const
{
GHOST_Buttons buttons;
// Get the state of all mouse buttons
GHOST_TSuccess success = getButtons(buttons);
if (success) {
// Isolate the state of the mouse button requested
isDown = buttons.get(mask);
}
return success;
}
GHOST_TSuccess GHOST_System::init()
{
m_timerManager = new GHOST_TimerManager ();
m_windowManager = new GHOST_WindowManager ();
m_eventManager = new GHOST_EventManager ();
m_ndofManager = new GHOST_NDOFManager();
#if 0
if(m_ndofManager)
printf("ndof manager \n");
#endif
#ifdef GHOST_DEBUG
if (m_eventManager) {
m_eventPrinter = new GHOST_EventPrinter();
m_eventManager->addConsumer(m_eventPrinter);
}
#endif // GHOST_DEBUG
if (m_timerManager && m_windowManager && m_eventManager) {
return GHOST_kSuccess;
} else {
return GHOST_kFailure;
}
}
GHOST_TSuccess GHOST_System::exit()
{
if (getFullScreen()) {
endFullScreen();
}
if (m_displayManager) {
delete m_displayManager;
m_displayManager = 0;
}
if (m_windowManager) {
delete m_windowManager;
m_windowManager = 0;
}
if (m_timerManager) {
delete m_timerManager;
m_timerManager = 0;
}
if (m_eventManager) {
delete m_eventManager;
m_eventManager = 0;
}
if (m_ndofManager) {
delete m_ndofManager;
m_ndofManager = 0;
}
return GHOST_kSuccess;
}
GHOST_TSuccess GHOST_System::createFullScreenWindow(GHOST_Window** window, const bool stereoVisual)
{
GHOST_TSuccess success;
GHOST_ASSERT(m_displayManager, "GHOST_System::createFullScreenWindow(): invalid display manager")
GHOST_DisplaySetting settings;
success = m_displayManager->getCurrentDisplaySetting(GHOST_DisplayManager::kMainDisplay, settings);
if (success) {
//GHOST_PRINT("GHOST_System::createFullScreenWindow(): creating full-screen window\n");
*window = (GHOST_Window*)createWindow(
STR_String (""),
0, 0, settings.xPixels, settings.yPixels,
GHOST_kWindowStateFullScreen,
GHOST_kDrawingContextTypeOpenGL,
stereoVisual);
success = *window == 0 ? GHOST_kFailure : GHOST_kSuccess;
}
return success;
}
|