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