HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RE_Server.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: RE_Server.h (C++)
7  *
8  * COMMENTS:
9  * Window server.
10  *
11  */
12 #ifndef __RE_Server__
13 #define __RE_Server__
14 
15 #include "RE_API.h"
16 #include "RE_IDType.h"
17 #include "RE_Types.h"
18 
19 #include <UT/UT_Array.h>
20 #include <UT/UT_UniquePtr.h>
21 #include <UT/UT_Rect.h>
22 #include <SYS/SYS_Compiler.h>
23 
24 
25 #if defined(EXPERIMENTAL_QOPENGLWIDGET)
26 class RE_GLDrawable;
27 class RE_Render;
28 #endif
29 class RE_Window;
30 #if !defined(EXPERIMENTAL_QOPENGLWIDGET)
31 class RE_Render;
32 #endif
33 
34 class QSurface;
35 
37 {
38 public:
39  RE_Server();
40  ~RE_Server();
41 
42  bool initServer();
43  static bool hasServer();
44 
45  void flush() const;
46 
47  RE_IDType getFocusWindow() const { return myFocusWindow; }
48  void setFocusWindow(RE_IDType wid);
49 
50  static int getMinXRes() { return myMinXRes; }
51  static int getMinYRes() { return myMinYRes; }
52  bool meetsMinRes( ) const;
53 
54  /// Determine if the given window (and not a child window) is currently
55  /// under the mouse.
56  /// The current x,y mouse coordinates are optional under
57  /// certain platforms
58  bool windowUnderCursor(RE_IDType wid, int x, int y) const;
59 
60  /// Return the id of the Houdini window that appears immediately
61  /// underneath the mouse cursor. Return 0/nullptr if there is no Houdini
62  /// window immediately underneath the mouse cursor.
63  static RE_IDType windowUnderCursor();
64 
65  bool getColorUnderCursor(float color[3]) const;
66 
67 #if defined(EXPERIMENTAL_QOPENGLWIDGET)
68  bool GLMakeCurrent(RE_GLDrawable *draw, bool ignore_errors);
69 #else
70  bool GLMakeCurrent( OGLDrawable draw, RE_OGLContext context,
71  bool ignore_errors);
72 #endif
73  RE_OGLContext GLCurrentContext() const;
74 #if defined(EXPERIMENTAL_QOPENGLWIDGET)
75  int GLMakeCopyCurrent( RE_GLDrawable *draw,
76  RE_OGLContext sourceContext,
77  RE_OGLContext targetContext );
78 #else
79  int GLMakeCopyCurrent( OGLDrawable draw,
80  RE_OGLContext sourceContext,
81  RE_OGLContext targetContext );
82 #endif
83 
84  bool GLSwapBuffers(RE_Window *currentWindow);
85 #if defined(EXPERIMENTAL_QOPENGLWIDGET)
86  RE_GLDrawable *GLGetCurrentDrawable();
87 #else
88  OGLDrawable GLGetCurrentDrawable();
89 #endif
90  void GLWaitGL();
91 
92  // provide some reasonable defaults
93  static int getDragTolX() { return 4; }
94  static int getDragTolY() { return 4; }
95  static fpreal64 getDragDelay() { return 0.75; }
96 
97  /// @{
98  /// Desktop support.
99  static int primaryScreenNum();
100  static int numScreens();
101  static int screenContaining(int x, int y, bool native=false);
102  static const UT_DimRect &screenArea(int screen_num);
103  static const UT_DimRect &nativeScreenArea(int screen_num);
104  static const UT_DimRect &workArea(int screen_num);
105  static const UT_DimRect &nativeWorkArea(int screen_num);
106  static const UT_DimRect &displayScreenArea(int screen_num);
107  static const UT_DimRect &displayWorkArea(int screen_num);
108  static fpreal screenToDeviceScale(int screen_num);
109  static fpreal physicalDPI(int screen_num);
110  static const UT_DimRect &virtualScreenArea();
111  static const UT_DimRect &virtualWorkArea();
112  /// @}
113 
114  /// @{
115  /// Convert from native coordinates to scaled Houdini UI coordinates
116  /// and vice versa.
117  /// @}
118  static void toScreenCoords(int &x, int &y);
119  static void fromScreenCoords(int &x, int &y);
120 
121  /// @{
122  /// Convert from a value that is scaled in Houdini UI space
123  /// to a value that is scaled in screen space and vice versa.
124  /// }@
125  ///
126  static void toScreenScale(int screen, int &value);
127  static void fromScreenScale(int screen, int &value);
128 
129  /// Add a window to the list of current main windows. If it is already in
130  /// the list, it will not be added again.
131  void addCurrentMainWindow(RE_Window *win);
132 
133  /// Remove a window from the list of current main windows.
134  void removeCurrentMainWindow(RE_Window *win);
135 
136  /// Find the current main window that's focused, so you can attach
137  /// dialog windows to it. If none is marked as focused, just returns
138  /// the first window.
139  RE_Window *getCurrentMainWindow() const;
140 
141  /// Find the first current main window, regardless of whether it's focused.
142  /// Used on Windows to ensure that all subwindows are made tool windows of
143  /// at least the main Houdini window.
144  RE_Window *getFirstCurrentMainWindow() const;
145 
146  /// Creates a new RE_Window, ready to be opened.
148  UT_UniquePtr<RE_Window> newWindow(
151  RE_VisualType vis_type = RE_NORMAL_VIS);
152 
153  /// Returns current render context matching the mode passed in. All render
154  /// contexts are tied to a specific drawable. This may return nullptr if
155  /// there are no render contexts currently created that match mode.
156  RE_Render *getContextMatching(RE_DisplayMode mode) const;
157 
158  /// Return whether the Qt objects are valid or not.
159  /// Qt objects are not valid when the Qt main event loop has exited.
160  static bool isAppExiting();
161 
162  /// This method should only be called when the Qt main event loop has
163  /// exited. It lets RE know that it is no longer safe to work with any Qt
164  /// objects.
165  static void setAppExiting();
166 
167 private:
168 #if defined(EXPERIMENTAL_QOPENGLWIDGET)
169  RE_GLDrawable *myCurrentDrawable;
170 #else
171  /// Helper method for making the given context the current context
172  /// and binding it to the given drawable surface.
173  bool makeContextCurrent(
174  RE_OGLContext context, QSurface *surface);
175 
176  RE_OGLContext myCurrentContext;
177 #endif
178 
179  RE_IDType myFocusWindow;
180 
181  /// The current main windows are all the toplevel application windows.
182  /// We keep track of them to find out what window we should use when
183  /// creating dialogs - windowing systems can decorate and treat dialog
184  /// windows differently if they know which window is the parent.
185  UT_Array<RE_Window *> myCurrentMainWindows;
186 
187  static int myMinXRes;
188  static int myMinYRes;
189 };
190 
191 
192 #endif
void * RE_IDType
Definition: RE_IDType.h:20
#define RE_API
Definition: RE_API.h:10
static int getDragTolY()
Definition: RE_Server.h:94
GLint y
Definition: glcorearb.h:103
static fpreal64 getDragDelay()
Definition: RE_Server.h:95
std::unique_ptr< T, Deleter > UT_UniquePtr
A smart pointer for unique ownership of dynamically allocated objects.
Definition: UT_UniquePtr.h:39
double fpreal64
Definition: SYS_Types.h:201
RE_IDType getFocusWindow() const
Definition: RE_Server.h:47
static int getDragTolX()
Definition: RE_Server.h:93
#define SYS_NO_DISCARD_RESULT
Definition: SYS_Compiler.h:93
RE_DisplayMode
Definition: RE_Types.h:573
GLint GLenum GLint x
Definition: glcorearb.h:409
GLenum mode
Definition: glcorearb.h:99
GLuint color
Definition: glcorearb.h:1261
fpreal64 fpreal
Definition: SYS_Types.h:277
RE_VisualType
Definition: RE_Types.h:623
static int getMinYRes()
Definition: RE_Server.h:51
Definition: core.h:1131
RE_WindowType
Definition: RE_Types.h:20
QOpenGLContext * RE_OGLContext
Definition: RE_Types.h:952
type
Definition: core.h:1059
static int getMinXRes()
Definition: RE_Server.h:50