b3e560ab4b456a481e1935dcf4866e46bd765724
[blender.git] / intern / ghost / GHOST_Types.h
1 /*
2  * ***** BEGIN GPL LICENSE BLOCK *****
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software Foundation,
16  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  *
18  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
19  * All rights reserved.
20  *
21  * The Original Code is: all of this file.
22  *
23  * Contributor(s): none yet.
24  *
25  * ***** END GPL LICENSE BLOCK *****
26  */
27
28 /** \file ghost/GHOST_Types.h
29  *  \ingroup GHOST
30  */
31
32
33 #ifndef __GHOST_TYPES_H__
34 #define __GHOST_TYPES_H__
35
36 #ifdef WITH_CXX_GUARDEDALLOC
37 #include "MEM_guardedalloc.h"
38 #endif
39
40 #if defined(WITH_CXX_GUARDEDALLOC) && defined(__cplusplus)
41 #  define GHOST_DECLARE_HANDLE(name) typedef struct name##__ { int unused; MEM_CXX_CLASS_ALLOC_FUNCS(#name) } *name
42 #else
43 #  define GHOST_DECLARE_HANDLE(name) typedef struct name##__ { int unused; } *name
44 #endif
45
46 typedef char GHOST_TInt8;
47 typedef unsigned char GHOST_TUns8;
48 typedef short GHOST_TInt16;
49 typedef unsigned short GHOST_TUns16;
50 typedef int GHOST_TInt32;
51 typedef unsigned int GHOST_TUns32;
52
53 typedef struct {
54         GHOST_TUns16 numOfAASamples;
55         int flags;
56 } GHOST_GLSettings;
57
58 typedef enum {
59         GHOST_glStereoVisual = (1 << 0),
60         GHOST_glDebugContext = (1 << 1)
61 } GHOST_GLFlags;
62
63
64 #ifdef _MSC_VER
65 typedef __int64 GHOST_TInt64;
66 typedef unsigned __int64 GHOST_TUns64;
67 #else
68 typedef long long GHOST_TInt64;
69 typedef unsigned long long GHOST_TUns64;
70 #endif
71
72 typedef void *GHOST_TUserDataPtr;
73
74 typedef enum {
75         GHOST_kFailure = 0,
76         GHOST_kSuccess
77 } GHOST_TSuccess;
78
79 /* Xtilt and Ytilt represent how much the pen is tilted away from 
80  * vertically upright in either the X or Y direction, with X and Y the
81  * axes of the tablet surface.
82  * In other words, Xtilt and Ytilt are components of a vector created by projecting
83  * the pen's angle in 3D space vertically downwards on to the XY plane
84  * --Matt
85  */
86 typedef enum {
87         GHOST_kTabletModeNone = 0,
88         GHOST_kTabletModeStylus,
89         GHOST_kTabletModeEraser
90 } GHOST_TTabletMode;
91
92 typedef struct GHOST_TabletData {
93         GHOST_TTabletMode Active; /* 0=None, 1=Stylus, 2=Eraser */
94         float Pressure; /* range 0.0 (not touching) to 1.0 (full pressure) */
95         float Xtilt;    /* range 0.0 (upright) to 1.0 (tilted fully against the tablet surface) */
96         float Ytilt;    /* as above */
97 } GHOST_TabletData;
98
99
100 typedef enum {
101         GHOST_kNotVisible = 0,
102         GHOST_kPartiallyVisible,
103         GHOST_kFullyVisible
104 } GHOST_TVisibility;
105
106
107 typedef enum {
108         GHOST_kFireTimeNever = 0xFFFFFFFF
109 } GHOST_TFireTimeConstant;
110
111 typedef enum {
112         GHOST_kModifierKeyLeftShift = 0,
113         GHOST_kModifierKeyRightShift,
114         GHOST_kModifierKeyLeftAlt,
115         GHOST_kModifierKeyRightAlt,
116         GHOST_kModifierKeyLeftControl,
117         GHOST_kModifierKeyRightControl,
118         GHOST_kModifierKeyOS,
119         GHOST_kModifierKeyNumMasks
120 } GHOST_TModifierKeyMask;
121
122
123 typedef enum {
124         GHOST_kWindowStateNormal = 0,
125         GHOST_kWindowStateMaximized,
126         GHOST_kWindowStateMinimized,
127         GHOST_kWindowStateFullScreen,
128         GHOST_kWindowStateEmbedded,
129         // GHOST_kWindowStateModified,
130         // GHOST_kWindowStateUnModified,
131 } GHOST_TWindowState;
132
133
134 /** Constants for the answer to the blender exit request */
135 typedef enum {
136         GHOST_kExitCancel = 0,
137         GHOST_kExitNow
138 } GHOST_TExitRequestResponse;
139
140 typedef enum {
141         GHOST_kWindowOrderTop = 0,
142         GHOST_kWindowOrderBottom
143 } GHOST_TWindowOrder;
144
145
146 typedef enum {
147         GHOST_kDrawingContextTypeNone = 0,
148         GHOST_kDrawingContextTypeOpenGL
149 } GHOST_TDrawingContextType;
150
151
152 typedef enum {
153         GHOST_kButtonMaskLeft = 0,
154         GHOST_kButtonMaskMiddle,
155         GHOST_kButtonMaskRight,
156         GHOST_kButtonMaskButton4,
157         GHOST_kButtonMaskButton5,
158         /* Trackballs and programmable buttons */
159         GHOST_kButtonMaskButton6,
160         GHOST_kButtonMaskButton7,
161         GHOST_kButtonNumMasks
162 } GHOST_TButtonMask;
163
164
165 typedef enum {
166         GHOST_kEventUnknown = 0,
167
168         GHOST_kEventCursorMove,     /// Mouse move event
169         GHOST_kEventButtonDown,     /// Mouse button event
170         GHOST_kEventButtonUp,       /// Mouse button event
171         GHOST_kEventWheel,          /// Mouse wheel event
172         GHOST_kEventTrackpad,       /// Trackpad event
173
174         GHOST_kEventNDOFMotion,     /// N degree of freedom device motion event
175         GHOST_kEventNDOFButton,     /// N degree of freedom device button event
176
177         GHOST_kEventKeyDown,
178         GHOST_kEventKeyUp,
179 //      GHOST_kEventKeyAuto,
180
181         GHOST_kEventQuit,
182
183         GHOST_kEventWindowClose,
184         GHOST_kEventWindowActivate,
185         GHOST_kEventWindowDeactivate,
186         GHOST_kEventWindowUpdate,
187         GHOST_kEventWindowSize,
188         GHOST_kEventWindowMove,
189         
190         GHOST_kEventDraggingEntered,
191         GHOST_kEventDraggingUpdated,
192         GHOST_kEventDraggingExited,
193         GHOST_kEventDraggingDropDone,
194         
195         GHOST_kEventOpenMainFile, // Needed for Cocoa to open double-clicked .blend file at startup
196         GHOST_kEventNativeResolutionChange, // Needed for Cocoa when window moves to other display
197
198         GHOST_kEventTimer,
199
200         GHOST_kEventImeCompositionStart,
201         GHOST_kEventImeComposition,
202         GHOST_kEventImeCompositionEnd,
203
204         GHOST_kNumEventTypes
205 } GHOST_TEventType;
206
207
208 typedef enum {
209         GHOST_kStandardCursorFirstCursor = 0,
210         GHOST_kStandardCursorDefault = 0,
211         GHOST_kStandardCursorRightArrow,
212         GHOST_kStandardCursorLeftArrow,
213         GHOST_kStandardCursorInfo, 
214         GHOST_kStandardCursorDestroy,
215         GHOST_kStandardCursorHelp,    
216         GHOST_kStandardCursorCycle,
217         GHOST_kStandardCursorSpray,
218         GHOST_kStandardCursorWait,
219         GHOST_kStandardCursorText,
220         GHOST_kStandardCursorCrosshair,
221         GHOST_kStandardCursorUpDown,
222         GHOST_kStandardCursorLeftRight,
223         GHOST_kStandardCursorTopSide,
224         GHOST_kStandardCursorBottomSide,
225         GHOST_kStandardCursorLeftSide,
226         GHOST_kStandardCursorRightSide,
227         GHOST_kStandardCursorTopLeftCorner,
228         GHOST_kStandardCursorTopRightCorner,
229         GHOST_kStandardCursorBottomRightCorner,
230         GHOST_kStandardCursorBottomLeftCorner,
231         GHOST_kStandardCursorCopy,
232         GHOST_kStandardCursorCustom, 
233         GHOST_kStandardCursorPencil,
234
235         GHOST_kStandardCursorNumCursors
236 } GHOST_TStandardCursor;
237
238
239 typedef enum {
240         GHOST_kKeyUnknown = -1,
241         GHOST_kKeyBackSpace,
242         GHOST_kKeyTab,
243         GHOST_kKeyLinefeed,
244         GHOST_kKeyClear,
245         GHOST_kKeyEnter  = 0x0D,
246         
247         GHOST_kKeyEsc    = 0x1B,
248         GHOST_kKeySpace  = ' ',
249         GHOST_kKeyQuote  = 0x27,
250         GHOST_kKeyComma  = ',',
251         GHOST_kKeyMinus  = '-',
252         GHOST_kKeyPlus   = '+',
253         GHOST_kKeyPeriod = '.',
254         GHOST_kKeySlash  = '/',
255
256         // Number keys
257         GHOST_kKey0 = '0',
258         GHOST_kKey1,
259         GHOST_kKey2,
260         GHOST_kKey3,
261         GHOST_kKey4,
262         GHOST_kKey5,
263         GHOST_kKey6,
264         GHOST_kKey7,
265         GHOST_kKey8,
266         GHOST_kKey9,
267
268         GHOST_kKeySemicolon = ';',
269         GHOST_kKeyEqual     = '=',
270
271         // Character keys
272         GHOST_kKeyA = 'A',
273         GHOST_kKeyB,
274         GHOST_kKeyC,
275         GHOST_kKeyD,
276         GHOST_kKeyE,
277         GHOST_kKeyF,
278         GHOST_kKeyG,
279         GHOST_kKeyH,
280         GHOST_kKeyI,
281         GHOST_kKeyJ,
282         GHOST_kKeyK,
283         GHOST_kKeyL,
284         GHOST_kKeyM,
285         GHOST_kKeyN,
286         GHOST_kKeyO,
287         GHOST_kKeyP,
288         GHOST_kKeyQ,
289         GHOST_kKeyR,
290         GHOST_kKeyS,
291         GHOST_kKeyT,
292         GHOST_kKeyU,
293         GHOST_kKeyV,
294         GHOST_kKeyW,
295         GHOST_kKeyX,
296         GHOST_kKeyY,
297         GHOST_kKeyZ,
298
299         GHOST_kKeyLeftBracket  = '[',
300         GHOST_kKeyRightBracket = ']',
301         GHOST_kKeyBackslash    = 0x5C,
302         GHOST_kKeyAccentGrave  = '`',
303
304         
305         GHOST_kKeyLeftShift = 0x100,
306         GHOST_kKeyRightShift,
307         GHOST_kKeyLeftControl,
308         GHOST_kKeyRightControl,
309         GHOST_kKeyLeftAlt,
310         GHOST_kKeyRightAlt,
311         GHOST_kKeyOS,       // Command key on Apple, Windows key(s) on Windows
312         GHOST_kKeyGrLess,       // German PC only!
313
314         GHOST_kKeyCapsLock,
315         GHOST_kKeyNumLock,
316         GHOST_kKeyScrollLock,
317
318         GHOST_kKeyLeftArrow,
319         GHOST_kKeyRightArrow,
320         GHOST_kKeyUpArrow,
321         GHOST_kKeyDownArrow,
322
323         GHOST_kKeyPrintScreen,
324         GHOST_kKeyPause,
325
326         GHOST_kKeyInsert,
327         GHOST_kKeyDelete,
328         GHOST_kKeyHome,
329         GHOST_kKeyEnd,
330         GHOST_kKeyUpPage,
331         GHOST_kKeyDownPage,
332
333         // Numpad keys
334         GHOST_kKeyNumpad0,
335         GHOST_kKeyNumpad1,
336         GHOST_kKeyNumpad2,
337         GHOST_kKeyNumpad3,
338         GHOST_kKeyNumpad4,
339         GHOST_kKeyNumpad5,
340         GHOST_kKeyNumpad6,
341         GHOST_kKeyNumpad7,
342         GHOST_kKeyNumpad8,
343         GHOST_kKeyNumpad9,
344         GHOST_kKeyNumpadPeriod,
345         GHOST_kKeyNumpadEnter,
346         GHOST_kKeyNumpadPlus,
347         GHOST_kKeyNumpadMinus,
348         GHOST_kKeyNumpadAsterisk,
349         GHOST_kKeyNumpadSlash,
350
351         // Function keys
352         GHOST_kKeyF1,
353         GHOST_kKeyF2,
354         GHOST_kKeyF3,
355         GHOST_kKeyF4,
356         GHOST_kKeyF5,
357         GHOST_kKeyF6,
358         GHOST_kKeyF7,
359         GHOST_kKeyF8,
360         GHOST_kKeyF9,
361         GHOST_kKeyF10,
362         GHOST_kKeyF11,
363         GHOST_kKeyF12,
364         GHOST_kKeyF13,
365         GHOST_kKeyF14,
366         GHOST_kKeyF15,
367         GHOST_kKeyF16,
368         GHOST_kKeyF17,
369         GHOST_kKeyF18,
370         GHOST_kKeyF19,
371         GHOST_kKeyF20,
372         GHOST_kKeyF21,
373         GHOST_kKeyF22,
374         GHOST_kKeyF23,
375         GHOST_kKeyF24,
376         
377         // Multimedia keypad buttons
378         GHOST_kKeyMediaPlay,
379         GHOST_kKeyMediaStop,
380         GHOST_kKeyMediaFirst,
381         GHOST_kKeyMediaLast
382 } GHOST_TKey;
383
384 typedef enum {
385         GHOST_kGrabDisable = 0, /* grab not set */
386         GHOST_kGrabNormal,  /* no cursor adjustments */
387         GHOST_kGrabWrap,        /* wrap the mouse location to prevent limiting screen bounds */
388         GHOST_kGrabHide,        /* hide the mouse while grabbing and restore the original location on release (numbuts) */
389 } GHOST_TGrabCursorMode;
390
391 typedef void *GHOST_TEventDataPtr;
392
393 typedef struct {
394         /** The x-coordinate of the cursor position. */
395         GHOST_TInt32 x;
396         /** The y-coordinate of the cursor position. */
397         GHOST_TInt32 y;
398 } GHOST_TEventCursorData;
399
400 typedef struct {
401         /** The mask of the mouse button. */
402         GHOST_TButtonMask button;
403 } GHOST_TEventButtonData;
404
405 typedef struct {
406         /** Displacement of a mouse wheel. */
407         GHOST_TInt32 z;
408 } GHOST_TEventWheelData;
409
410 typedef enum {
411         GHOST_kTrackpadEventUnknown = 0,
412         GHOST_kTrackpadEventScroll,
413         GHOST_kTrackpadEventRotate,
414         GHOST_kTrackpadEventSwipe, /* Reserved, not used for now */
415         GHOST_kTrackpadEventMagnify
416 } GHOST_TTrackpadEventSubTypes;
417         
418
419 typedef struct {
420         /** The event subtype */
421         GHOST_TTrackpadEventSubTypes subtype;
422         /** The x-location of the trackpad event */
423         GHOST_TInt32 x;
424         /** The y-location of the trackpad event */
425         GHOST_TInt32 y;
426         /** The x-delta or value of the trackpad event */
427         GHOST_TInt32 deltaX;
428         /** The y-delta (currently only for scroll subtype) of the trackpad event */
429         GHOST_TInt32 deltaY;
430 } GHOST_TEventTrackpadData;
431
432
433 typedef enum {
434         GHOST_kDragnDropTypeUnknown = 0,
435         GHOST_kDragnDropTypeFilenames, /*Array of strings representing file names (full path) */
436         GHOST_kDragnDropTypeString, /* Unformatted text UTF-8 string */
437         GHOST_kDragnDropTypeBitmap /*Bitmap image data */
438 } GHOST_TDragnDropTypes;
439
440 typedef struct {
441         /** The x-coordinate of the cursor position. */
442         GHOST_TInt32 x;
443         /** The y-coordinate of the cursor position. */
444         GHOST_TInt32 y;
445         /** The dropped item type */
446         GHOST_TDragnDropTypes dataType;
447         /** The "dropped content" */
448         GHOST_TEventDataPtr data;
449 } GHOST_TEventDragnDropData;
450
451 /** similar to wmImeData */
452 typedef struct {
453         /** size_t */
454         GHOST_TUserDataPtr result_len, composite_len;
455         /** char * utf8 encoding */
456         GHOST_TUserDataPtr result, composite;
457         /** Cursor position in the IME composition. */
458         int cursor_position;
459         /** Represents the position of the beginning of the selection */
460         int target_start;
461         /** Represents the position of the end of the selection */
462         int target_end;
463         /** custom temporal data */
464         GHOST_TUserDataPtr tmp;
465 } GHOST_TEventImeData;
466
467 typedef struct {
468         int count;
469         GHOST_TUns8 **strings;
470 } GHOST_TStringArray;
471
472 typedef enum {
473         GHOST_kNotStarted,
474         GHOST_kStarting,
475         GHOST_kInProgress,
476         GHOST_kFinishing,
477         GHOST_kFinished
478 } GHOST_TProgress;
479
480 typedef struct {
481         /** N-degree of freedom device data v3 [GSoC 2010] */
482         // Each component normally ranges from -1 to +1, but can exceed that.
483         // These use blender standard view coordinates, with positive rotations being CCW about the axis.
484         float tx, ty, tz; // translation
485         float rx, ry, rz; // rotation:
486         // axis = (rx,ry,rz).normalized
487         // amount = (rx,ry,rz).magnitude [in revolutions, 1.0 = 360 deg]
488         float dt; // time since previous NDOF Motion event
489         GHOST_TProgress progress; // Starting, InProgress or Finishing (for modal handlers)
490 } GHOST_TEventNDOFMotionData;
491
492 typedef enum { GHOST_kPress, GHOST_kRelease } GHOST_TButtonAction;
493 // good for mouse or other buttons too, hmmm?
494
495 typedef struct {
496         GHOST_TButtonAction action;
497         short button;
498 } GHOST_TEventNDOFButtonData;
499
500 typedef struct {
501         /** The key code. */
502         GHOST_TKey key;
503
504         /* ascii / utf8: both should always be set when possible,
505          * - ascii may be '\0' however if the user presses a non ascii key
506          * - unicode may not be set if the system has no unicode support
507          *
508          * These values are intended to be used as follows.
509          * For text input use unicode when available, fallback to ascii.
510          * For areas where unicode is not needed, number input for example, always
511          * use ascii, unicode is ignored - campbell.
512          */
513         /** The ascii code for the key event ('\0' if none). */
514         char ascii;
515         /** The unicode character. if the length is 6, not NULL terminated if all 6 are set */
516         char utf8_buf[6];
517 } GHOST_TEventKeyData;
518
519 typedef struct {
520         /** Number of pixels on a line. */
521         GHOST_TUns32 xPixels;
522         /** Number of lines. */
523         GHOST_TUns32 yPixels;
524         /** Numberof bits per pixel. */
525         GHOST_TUns32 bpp;
526         /** Refresh rate (in Hertz). */
527         GHOST_TUns32 frequency;
528 } GHOST_DisplaySetting;
529
530
531 #ifdef _WIN32
532 typedef long GHOST_TEmbedderWindowID;
533 #endif // _WIN32
534
535 #ifndef _WIN32
536 // I can't use "Window" from "<X11/Xlib.h>" because it conflits with Window defined in winlay.h
537 typedef int GHOST_TEmbedderWindowID;
538 #endif // _WIN32
539
540 /**
541  * A timer task callback routine.
542  * \param task The timer task object.
543  * \param time The current time.
544  */
545 #ifdef __cplusplus
546 class GHOST_ITimerTask;
547 typedef void (*GHOST_TimerProcPtr)(GHOST_ITimerTask *task, GHOST_TUns64 time);
548 #else
549 struct GHOST_TimerTaskHandle__;
550 typedef void (*GHOST_TimerProcPtr)(struct GHOST_TimerTaskHandle__ *task, GHOST_TUns64 time);
551 #endif
552
553 #endif // __GHOST_TYPES_H__
554