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