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 * @param numOfAASamples Number of samples used for AA (zero if no AA)
228 * @param parentWindow Parent (embedder) window
229 * @return The new window (or 0 if creation failed).
231 virtual GHOST_IWindow* createWindow(
232 const STR_String& title,
233 GHOST_TInt32 left, GHOST_TInt32 top, GHOST_TUns32 width, GHOST_TUns32 height,
234 GHOST_TWindowState state, GHOST_TDrawingContextType type,
235 const bool stereoVisual = false,
236 const GHOST_TUns16 numOfAASamples = 0,
237 const GHOST_TEmbedderWindowID parentWindow = 0) = 0;
241 * @param window Pointer to the window to be disposed.
242 * @return Indication of success.
244 virtual GHOST_TSuccess disposeWindow(GHOST_IWindow* window) = 0;
247 * Returns whether a window is valid.
248 * @param window Pointer to the window to be checked.
249 * @return Indication of validity.
251 virtual bool validWindow(GHOST_IWindow* window) = 0;
254 * Begins full screen mode.
255 * @param setting The new setting of the display.
256 * @param window Window displayed in full screen.
257 * This window is invalid after full screen has been ended.
258 * @return Indication of success.
260 virtual GHOST_TSuccess beginFullScreen(const GHOST_DisplaySetting& setting, GHOST_IWindow** window,
261 const bool stereoVisual) = 0;
264 * Ends full screen mode.
265 * @return Indication of success.
267 virtual GHOST_TSuccess endFullScreen(void) = 0;
270 * Returns current full screen mode status.
271 * @return The current status.
273 virtual bool getFullScreen(void) = 0;
275 /***************************************************************************************
276 ** Event management functionality
277 ***************************************************************************************/
280 * Retrieves events from the system and stores them in the queue.
281 * @param waitForEvent Flag to wait for an event (or return immediately).
282 * @return Indication of the presence of events.
284 virtual bool processEvents(bool waitForEvent) = 0;
287 * Retrieves events from the queue and send them to the event consumers.
288 * @return Indication of the presence of events.
290 virtual bool dispatchEvents() = 0;
293 * Adds the given event consumer to our list.
294 * @param consumer The event consumer to add.
295 * @return Indication of success.
297 virtual GHOST_TSuccess addEventConsumer(GHOST_IEventConsumer* consumer) = 0;
299 /***************************************************************************************
300 ** N-degree of freedom device management functionality
301 ***************************************************************************************/
304 * Starts the N-degree of freedom device manager
306 virtual int openNDOF(GHOST_IWindow*,
307 GHOST_NDOFLibraryInit_fp setNdofLibraryInit,
308 GHOST_NDOFLibraryShutdown_fp setNdofLibraryShutdown,
309 GHOST_NDOFDeviceOpen_fp setNdofDeviceOpen
310 // original patch only
311 // GHOST_NDOFEventHandler_fp setNdofEventHandler
315 /***************************************************************************************
316 ** Cursor management functionality
317 ***************************************************************************************/
320 * Returns the current location of the cursor (location in screen coordinates)
321 * @param x The x-coordinate of the cursor.
322 * @param y The y-coordinate of the cursor.
323 * @return Indication of success.
325 virtual GHOST_TSuccess getCursorPosition(GHOST_TInt32& x, GHOST_TInt32& y) const = 0;
328 * Updates the location of the cursor (location in screen coordinates).
329 * Not all operating systems allow the cursor to be moved (without the input device being moved).
330 * @param x The x-coordinate of the cursor.
331 * @param y The y-coordinate of the cursor.
332 * @return Indication of success.
334 virtual GHOST_TSuccess setCursorPosition(GHOST_TInt32 x, GHOST_TInt32 y) const = 0;
336 /***************************************************************************************
337 ** Access to mouse button and keyboard states.
338 ***************************************************************************************/
341 * Returns the state of a modifier key (ouside the message queue).
342 * @param mask The modifier key state to retrieve.
343 * @param isDown The state of a modifier key (true == pressed).
344 * @return Indication of success.
346 virtual GHOST_TSuccess getModifierKeyState(GHOST_TModifierKeyMask mask, bool& isDown) const = 0;
349 * Returns the state of a mouse button (ouside the message queue).
350 * @param mask The button state to retrieve.
351 * @param isDown Button state.
352 * @return Indication of success.
354 virtual GHOST_TSuccess getButtonState(GHOST_TButtonMask mask, bool& isDown) const = 0;
357 /***************************************************************************************
358 ** Access to clipboard.
359 ***************************************************************************************/
362 * Returns the selection buffer
363 * @return Returns "unsinged char" from X11 XA_CUT_BUFFER0 buffer
366 virtual GHOST_TUns8* getClipboard(bool selection) const = 0;
369 * Put data to the Clipboard
371 virtual void putClipboard(GHOST_TInt8 *buffer, bool selection) const = 0;
376 * Initialize the system.
377 * @return Indication of success.
379 virtual GHOST_TSuccess init() = 0;
382 * Shut the system down.
383 * @return Indication of success.
385 virtual GHOST_TSuccess exit() = 0;
387 /** The one and only system */
388 static GHOST_ISystem* m_system;
391 #endif // _GHOST_ISYSTEM_H_