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