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