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 class RE_OpenGLDrawable;
26 class RE_WindowDrawable;
27 class RE_Render;
28 class RE_Window;
29 
30 class QSurface;
31 class QWidget;
32 
34 {
35 public:
36  RE_Server();
37 
38  bool initServer();
39  static bool hasServer();
40 
41  void flush() const;
42 
43  RE_IDType getFocusWindow() const { return myFocusWindow; }
44  void setFocusWindow(RE_IDType wid);
45 
46  static int getMinXRes() { return myMinXRes; }
47  static int getMinYRes() { return myMinYRes; }
48  bool meetsMinRes( ) const;
49 
50  /// Determine if the given window (and not a child window) is currently
51  /// under the mouse.
52  /// The current x,y mouse coordinates are optional under
53  /// certain platforms
54  bool windowUnderCursor(RE_IDType wid, int x, int y) const;
55 
56  /// Return the id of the Houdini window that appears immediately
57  /// underneath the mouse cursor. Return 0/nullptr if there is no Houdini
58  /// window immediately underneath the mouse cursor.
59  static RE_IDType windowUnderCursor();
60 
61  bool getColorUnderCursor(float color[3]) const;
62 
63  /// =====================================================================
64  /// For new 2D UI drawing.
65  bool makeCurrent(
66  RE_WindowDrawable *win_drawable,
67  RE_OpenGLDrawable *gl_drawable, bool ignore_errors);
68  bool swapBuffers(RE_Window *currentWindow);
69  /// =====================================================================
70 
71  /// =====================================================================
72  /// For OpenGL 2D UI drawing.
73  bool GLMakeCurrent( OGLDrawable draw, RE_OGLContext context,
74  bool ignore_errors);
75  bool GLSwapBuffers(RE_Window *currentWindow);
76  /// =====================================================================
77 
78 
79  RE_OGLContext GLCurrentContext() const;
80 
81  void GLWaitGL();
82 
83  // provide some reasonable defaults
84  static int getDragTolX() { return 4; }
85  static int getDragTolY() { return 4; }
86  static fpreal64 getDragDelay() { return 0.75; }
87 
88  /// @{
89  /// Desktop support.
90  static int primaryScreenNum();
91  static int numScreens();
92 
93  // Return the screen number for the screen containing the
94  // specific widget. If `widget` is nullptr, then return the
95  // primary screen number.
96  static int screenContaining(const QWidget *widget);
97 
98  static int screenContaining(int x, int y, bool native=false);
99  static const UT_DimRect &screenArea(int screen_num);
100  static const UT_DimRect &nativeScreenArea(int screen_num);
101  static const UT_DimRect &workArea(int screen_num);
102  static const UT_DimRect &nativeWorkArea(int screen_num);
103  static const UT_DimRect &displayScreenArea(int screen_num);
104  static const UT_DimRect &displayWorkArea(int screen_num);
105  static fpreal screenToDeviceScale(int screen_num);
106  static fpreal physicalDPI(int screen_num);
107  static const UT_DimRect &virtualScreenArea();
108  static const UT_DimRect &virtualWorkArea();
109  static fpreal defaultDevicePixelRatio();
110  /// @}
111 
112  /// @{
113  /// Convert from native coordinates to scaled Houdini UI coordinates
114  /// and vice versa.
115  /// @}
116  static void toScreenCoords(int &x, int &y);
117  static void fromScreenCoords(int &x, int &y);
118 
119  /// @{
120  /// Convert from a value that is scaled in Houdini UI space
121  /// to a value that is scaled in screen space and vice versa.
122  /// }@
123  ///
124  static void toScreenScale(int screen, int &value);
125  static void fromScreenScale(int screen, int &value);
126 
127  /// Add a window to the list of current main windows. If it is already in
128  /// the list, it will not be added again.
129  void addCurrentMainWindow(RE_Window *win);
130 
131  /// Remove a window from the list of current main windows.
132  void removeCurrentMainWindow(RE_Window *win);
133 
134  /// Find the current main window that's focused, so you can attach
135  /// dialog windows to it. If none is marked as focused, just returns
136  /// the first window.
137  RE_Window *getCurrentMainWindow() const;
138 
139  /// Find the first current main window, regardless of whether it's focused.
140  /// Used on Windows to ensure that all subwindows are made tool windows of
141  /// at least the main Houdini window.
142  RE_Window *getFirstCurrentMainWindow() const;
143 
144  /// Creates a new RE_Window, ready to be opened.
146  UT_UniquePtr<RE_Window> newWindow(
149  RE_VisualType vis_type = RE_NORMAL_VIS);
150 
151  /// Returns current render context matching the mode passed in. All render
152  /// contexts are tied to a specific drawable. This may return nullptr if
153  /// there are no render contexts currently created that match mode.
154  RE_Render *getContextMatching(RE_DisplayMode mode) const;
155 
156  /// Return whether the Qt objects are valid or not.
157  /// Qt objects are not valid when the Qt main event loop has exited.
158  static bool isAppExiting();
159 
160  /// This method should only be called when the Qt main event loop has
161  /// exited. It lets RE know that it is no longer safe to work with any Qt
162  /// objects.
163  static void setAppExiting();
164 
165  /// Return true if Houdini should draw the UI using the new
166  /// window drawable framework. Return false if Houdini should draw
167  /// the UI with the traditional OpenGL drawable framework.
168  static bool useNewWindowDrawable();
169 
170  /// Return true if Houdini should draw the new UI skin.
171  /// Return false if Houdini should draw the traditional OpenGL UI skin.
172  /// Note that if this method returns true, then `useNewWindowDrawable()`
173  /// also returns true.
174  static bool useNewUISkin();
175 
176  /// Return true if Houdini should use the new RE_OpenGLDrawable
177  /// in the new UI skin instead of RE_WindowDrawable.
178  static bool useNewGLDrawable();
179 
180  // Return true if Houdini should draw the new UI skin using the
181  // Pluto Python style. Note that if this method returns false,
182  // then Houdini is drawing the new UI skin using the Pluto C++ style.
183  static bool usePythonQStyle();
184 
185  /// Return whether the default preference is to run with the new UI skin.
186  static bool useNewUISkinDefault();
187 
188  /// Set whether the default preference is to run with the new UI skin.
189  static void setUseNewUISkinDefault(bool use_new_ui);
190 
191 private:
192  /// =====================================================================
193  /// For OpenGL 2D UI drawing.
194  ///
195  /// Helper method for making the given context the current context
196  /// and binding it to the given drawable surface.
197  bool makeContextCurrent(
198  RE_OGLContext context, QSurface *surface);
199 
200  RE_OGLContext myCurrentContext;
201  /// =====================================================================
202 
203  RE_IDType myFocusWindow;
204 
205  /// The current main windows are all the toplevel application windows.
206  /// We keep track of them to find out what window we should use when
207  /// creating dialogs - windowing systems can decorate and treat dialog
208  /// windows differently if they know which window is the parent.
209  UT_Array<RE_Window *> myCurrentMainWindows;
210 
211  static int myMinXRes;
212  static int myMinYRes;
213 };
214 
215 
216 #endif
void * RE_IDType
Definition: RE_IDType.h:20
#define RE_API
Definition: RE_API.h:10
==========================================================================
Definition: RE_Window.h:57
GLsizei const GLfloat * value
Definition: glcorearb.h:824
static int getDragTolY()
Definition: RE_Server.h:85
GLint y
Definition: glcorearb.h:103
static fpreal64 getDragDelay()
Definition: RE_Server.h:86
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:43
GLint GLint GLsizei GLint GLenum GLenum type
Definition: glcorearb.h:108
static int getDragTolX()
Definition: RE_Server.h:84
#define SYS_NO_DISCARD_RESULT
Definition: SYS_Compiler.h:86
RE_DisplayMode
Definition: RE_Types.h:580
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:283
RE_VisualType
Definition: RE_Types.h:630
static int getMinYRes()
Definition: RE_Server.h:47
RE_WindowType
Definition: RE_Types.h:29
QOpenGLContext * RE_OGLContext
Definition: RE_Types.h:956
static int getMinXRes()
Definition: RE_Server.h:46