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