3 * ***** BEGIN GPL LICENSE BLOCK *****
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software Foundation,
17 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
20 * All rights reserved.
22 * The Original Code is: all of this file.
24 * Contributor(s): none yet.
26 * ***** END GPL LICENSE BLOCK *****
29 * @file GHOST_ISystem.h
30 * Main interface file for C++ Api with declaration of GHOST_ISystem interface
32 * Contains the doxygen documentation main page.
35 #ifndef _GHOST_ISYSTEM_H_
36 #define _GHOST_ISYSTEM_H_
38 #include "GHOST_Types.h"
39 #include "GHOST_ITimerTask.h"
40 #include "GHOST_IWindow.h"
42 class GHOST_IEventConsumer;
45 *! \mainpage GHOST Main Page
47 * \section intro Introduction
49 * GHOST is yet another acronym. It stands for "Generic Handy Operating System
50 * Toolkit". It has been created to replace the OpenGL utility tool kit
51 * <a href="http://www.opengl.org/developers/documentation/glut.html">GLUT</a>.
52 * GLUT was used in <a href="http://www.blender3d.com">Blender</a> until the
53 * point that Blender needed to be ported to Apple's Mac OSX. Blender needed a
54 * number of modifications in GLUT to work but the GLUT sources for OSX were
55 * unavailable at the time. The decision was made to build our own replacement
56 * for GLUT. In those days, NaN Technologies BV was the company that developed
59 * Enough history. What does GHOST have to offer?<br>
60 * In short: everything that Blender needed from GLUT to run on all it's supported
61 * operating systems and some extra's.
64 * <li> Time(r) management.</li>
65 * <li> Display/window management (windows are only created on the main display).
66 * <li> Event management.</li>
67 * <li> Cursor shape management (no custom cursors for now).</li>
68 * <li> Access to the state of the mouse buttons and the keyboard.</li>
69 * <li> Menus for windows with events generated when they are accessed (this is
70 * work in progress).</li>
72 * Font management has been moved to a separate library.
74 * \section platforms Platforms
76 * \section Building GHOST
78 * \section interface Interface
79 * GHOST has two programming interfaces:
81 * <li>The C-API. For programs written in C.</li>
82 * <li>The C++-API. For programs written in C++.</li>
84 * GHOST itself is writtem in C++ and the C-API is a wrapper around the C++
87 * \subsection cplusplus_api The C++ API consists of the following files:
89 * <li>GHOST_IEvent.h</li>
90 * <li>GHOST_IEventConsumer.h</li>
91 * <li>GHOST_IMenu.h (in progress)</li>
92 * <li>GHOST_IMenuBar.h (in progress)</li>
93 * <li>GHOST_ISystem.h</li>
94 * <li>GHOST_ITimerTask.h</li>
95 * <li>GHOST_IWindow.h</li>
96 * <li>GHOST_Rect.h</li>
97 * <li>GHOST_Types.h</li>
99 * For an example of using the C++-API, have a look at the GHOST_C-Test.cpp
100 * program in the ?/ghost/test/gears/ directory.
102 * \subsection c_api The C-API
103 * To use GHOST in programs written in C, include the file GHOST_C-API.h in
104 * your program. This file includes the GHOST_Types.h file for all GHOST types
105 * and defines functions that give you access to the same functionality present
106 * in the C++ API.<br>
107 * For an example of using the C-API, have a look at the GHOST_C-Test.c program
108 * in the ?/ghost/test/gears/ directory.
110 * \section work Work in progress
112 * \subsection menus Menu functionality
113 * Menu bars with pull-down menu's for windows are in development in the
114 * current version of GHOST. The file GHOST_MenuDependKludge.h contains a
115 * setting to turn menu functionality on or off.
119 * Interface for classes that provide access to the operating system.
120 * There should be only one system class in an application.
121 * Therefore, the routines to create and dispose the system are static.
123 * -# Time(r) management.
124 * -# Display/window management (windows are only created on the main display).
125 * -# Event management.
126 * -# Cursor shape management (no custom cursors for now).
127 * -# Access to the state of the mouse buttons and the keyboard.
128 * -# Menus for windows with events generated when they are accessed (this is
130 * @author Maarten Gribnau
137 * Creates the one and only system.
138 * @return An indication of success.
140 static GHOST_TSuccess createSystem();
143 * Disposes the one and only system.
144 * @return An indication of success.
146 static GHOST_TSuccess disposeSystem();
149 * Returns a pointer to the one and only system (nil if it hasn't been created).
150 * @return A pointer to the system.
152 static GHOST_ISystem* getSystem();
157 * Protected default constructor to force use of static createSystem member.
163 * Protected default constructor to force use of static dispose member.
165 virtual ~GHOST_ISystem() {}
168 /***************************************************************************************
169 ** Time(r) functionality
170 ***************************************************************************************/
173 * Returns the system time.
174 * Returns the number of milliseconds since the start of the system process.
175 * Based on ANSI clock() routine.
176 * @return The number of milliseconds.
178 virtual GHOST_TUns64 getMilliSeconds() const = 0;
182 * Note that, on most operating systems, messages need to be processed in order
183 * for the timer callbacks to be invoked.
184 * @param delay The time to wait for the first call to the timerProc (in milliseconds)
185 * @param interval The interval between calls to the timerProc (in milliseconds)
186 * @param timerProc The callback invoked when the interval expires,
187 * @param userData Placeholder for user data.
188 * @return A timer task (0 if timer task installation failed).
190 virtual GHOST_ITimerTask* installTimer(GHOST_TUns64 delay, GHOST_TUns64 interval, GHOST_TimerProcPtr timerProc, GHOST_TUserDataPtr userData = 0) = 0;
194 * @param timerTask Timer task to be removed.
195 * @return Indication of success.
197 virtual GHOST_TSuccess removeTimer(GHOST_ITimerTask* timerTask) = 0;
199 /***************************************************************************************
200 ** Display/window management functionality
201 ***************************************************************************************/
204 * Returns the number of displays on this system.
205 * @return The number of displays.
207 virtual GHOST_TUns8 getNumDisplays() const = 0;
210 * Returns the dimensions of the main display on this system.
211 * @return The dimension of the main display.
213 virtual void getMainDisplayDimensions(GHOST_TUns32& width, GHOST_TUns32& height) const = 0;
216 * Create a new window.
217 * The new window is added to the list of windows managed.
218 * Never explicitly delete the window, use disposeWindow() instead.
219 * @param title The name of the window (displayed in the title bar of the window if the OS supports it).
220 * @param left The coordinate of the left edge of the window.
221 * @param top The coordinate of the top edge of the window.
222 * @param width The width the window.
223 * @param height The height the window.
224 * @param state The state of the window when opened.
225 * @param type The type of drawing context installed in this window.
226 * @param stereoVisual Create a stereo visual for quad buffered stereo.
227 * @return The new window (or 0 if creation failed).
229 virtual GHOST_IWindow* createWindow(
230 const STR_String& title,
231 GHOST_TInt32 left, GHOST_TInt32 top, GHOST_TUns32 width, GHOST_TUns32 height,
232 GHOST_TWindowState state, GHOST_TDrawingContextType type,
233 const bool stereoVisual) = 0;
237 * @param window Pointer to the window to be disposed.
238 * @return Indication of success.
240 virtual GHOST_TSuccess disposeWindow(GHOST_IWindow* window) = 0;
243 * Returns whether a window is valid.
244 * @param window Pointer to the window to be checked.
245 * @return Indication of validity.
247 virtual bool validWindow(GHOST_IWindow* window) = 0;
250 * Begins full screen mode.
251 * @param setting The new setting of the display.
252 * @param window Window displayed in full screen.
253 * This window is invalid after full screen has been ended.
254 * @return Indication of success.
256 virtual GHOST_TSuccess beginFullScreen(const GHOST_DisplaySetting& setting, GHOST_IWindow** window,
257 const bool stereoVisual) = 0;
260 * Ends full screen mode.
261 * @return Indication of success.
263 virtual GHOST_TSuccess endFullScreen(void) = 0;
266 * Returns current full screen mode status.
267 * @return The current status.
269 virtual bool getFullScreen(void) = 0;
271 /***************************************************************************************
272 ** Event management functionality
273 ***************************************************************************************/
276 * Retrieves events from the system and stores them in the queue.
277 * @param waitForEvent Flag to wait for an event (or return immediately).
278 * @return Indication of the presence of events.
280 virtual bool processEvents(bool waitForEvent) = 0;
283 * Retrieves events from the queue and send them to the event consumers.
284 * @return Indication of the presence of events.
286 virtual bool dispatchEvents() = 0;
289 * Adds the given event consumer to our list.
290 * @param consumer The event consumer to add.
291 * @return Indication of success.
293 virtual GHOST_TSuccess addEventConsumer(GHOST_IEventConsumer* consumer) = 0;
295 /***************************************************************************************
296 ** N-degree of freedom device management functionality
297 ***************************************************************************************/
300 * Starts the N-degree of freedom device manager
302 virtual int openNDOF(GHOST_IWindow*,
303 GHOST_NDOFLibraryInit_fp setNdofLibraryInit,
304 GHOST_NDOFLibraryShutdown_fp setNdofLibraryShutdown,
305 GHOST_NDOFDeviceOpen_fp setNdofDeviceOpen
306 // original patch only
307 // GHOST_NDOFEventHandler_fp setNdofEventHandler
311 /***************************************************************************************
312 ** Cursor management functionality
313 ***************************************************************************************/
316 * Returns the current location of the cursor (location in screen coordinates)
317 * @param x The x-coordinate of the cursor.
318 * @param y The y-coordinate of the cursor.
319 * @return Indication of success.
321 virtual GHOST_TSuccess getCursorPosition(GHOST_TInt32& x, GHOST_TInt32& y) const = 0;
324 * Updates the location of the cursor (location in screen coordinates).
325 * Not all operating systems allow the cursor to be moved (without the input device being moved).
326 * @param x The x-coordinate of the cursor.
327 * @param y The y-coordinate of the cursor.
328 * @return Indication of success.
330 virtual GHOST_TSuccess setCursorPosition(GHOST_TInt32 x, GHOST_TInt32 y) const = 0;
332 /***************************************************************************************
333 ** Access to mouse button and keyboard states.
334 ***************************************************************************************/
337 * Returns the state of a modifier key (ouside the message queue).
338 * @param mask The modifier key state to retrieve.
339 * @param isDown The state of a modifier key (true == pressed).
340 * @return Indication of success.
342 virtual GHOST_TSuccess getModifierKeyState(GHOST_TModifierKeyMask mask, bool& isDown) const = 0;
345 * Returns the state of a mouse button (ouside the message queue).
346 * @param mask The button state to retrieve.
347 * @param isDown Button state.
348 * @return Indication of success.
350 virtual GHOST_TSuccess getButtonState(GHOST_TButtonMask mask, bool& isDown) const = 0;
353 * Returns the selection buffer
354 * @return Returns "unsinged char" from X11 XA_CUT_BUFFER0 buffer
357 virtual GHOST_TUns8* getClipboard(int flag) const = 0;
360 * Put data to the Clipboard
362 virtual void putClipboard(GHOST_TInt8 *buffer, int flag) const = 0;
366 * Initialize the system.
367 * @return Indication of success.
369 virtual GHOST_TSuccess init() = 0;
372 * Shut the system down.
373 * @return Indication of success.
375 virtual GHOST_TSuccess exit() = 0;
377 /** The one and only system */
378 static GHOST_ISystem* m_system;
381 #endif // _GHOST_ISYSTEM_H_