HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
WindowWrapper.h
Go to the documentation of this file.
1 //
2 // Copyright Contributors to the MaterialX Project
3 // SPDX-License-Identifier: Apache-2.0
4 //
5 
6 #ifndef MATERIALX_WINDOWWRAPPER_H
7 #define MATERIALX_WINDOWWRAPPER_H
8 
9 #if defined(_WIN32)
10 #define WIN32_LEAN_AND_MEAN
11 #undef APIENTRY
12 #include <windows.h>
13 #elif defined(__linux__) || defined(__FreeBSD__)
14 #include <X11/X.h> // for Window
15 #include <X11/Xlib.h> // for Display
16 using Widget = struct _WidgetRec*;
17 #endif
18 
19 #include <memory>
20 #include <MaterialXCore/Library.h>
21 
23 /// OS specific type windowing definitions
24 #if defined(_WIN32)
25 /// External handle is a window handle
26 using ExternalWindowHandle = HWND;
27 /// Internal handle is a device context
28 using InternalWindowHandle = HDC;
29 /// Display handle concept has no equivalence on Windows
30 using DisplayHandle = void*;
31 #elif defined(__linux__) || defined(__FreeBSD__)
32 /// External handle is a widget
34 /// Internal handle is the window for the widget
35 using InternalWindowHandle = Window;
36 /// Display handle is the X display
37 using DisplayHandle = Display*;
38 /// Application shell
39 using Widget = struct _WidgetRec*;
40 #elif defined(__APPLE__)
41 /// External handle is a window handle
42 using ExternalWindowHandle = void*;
43 /// Internal handle concept has no equivalence on Mac
44 using InternalWindowHandle = void*;
45 /// Display handle concept has no equivalence on Mac
46 using DisplayHandle = void*;
47 #else
48 using Widget = void*;
49 using ExternalWindowHandle = void*;
50 using InternalWindowHandle = void*;
51 using DisplayHandle = void*;
52 #endif
53 
54 /// WindowWrapper shared pointer
55 using WindowWrapperPtr = std::shared_ptr<class WindowWrapper>;
56 
57 /// @class WindowWrapper
58 /// Generic wrapper for encapsulating a "window" construct
59 ///
60 /// Each supported platform will have specific storage and management logic.
62 {
63  public:
64  /// Create a new WindowWrapper
67  DisplayHandle display = {});
68 
69  // Default destructor
70  virtual ~WindowWrapper();
71 
72  /// Return "external" handle
74  {
75  return _externalHandle;
76  }
77 
78  /// Return "internal" handle
80  {
81  return _internalHandle;
82  }
83 
84  /// Check that there is a valid OS handle set.
85  /// It is sufficient to just check the internal handle.
86  bool isValid() const
87  {
88  return _internalHandle != 0;
89  }
90 
91  /// Release resources stored in wrapper
92  void release();
93 
94 #if defined(__linux__) || defined(__FreeBSD__)
95  /// Return X display
96  Display* getXDisplay() const
97  {
98  return _xDisplay;
99  }
100 #endif
101 
102  protected:
105  DisplayHandle display);
106 
107  protected:
110 
111 #if defined(__linux__) || defined(__FreeBSD__)
112  /// Window ID of framebuffer instance created in the wrapper
113  Window _framebufferWindow;
114  /// X Display
115  Display* _xDisplay;
116 #endif
117 };
118 
120 
121 #endif
ExternalWindowHandle _externalHandle
#define MATERIALX_NAMESPACE_BEGIN
Definition: Generated.h:25
WindowWrapper(ExternalWindowHandle externalHandle, InternalWindowHandle internalHandle, DisplayHandle display)
InternalWindowHandle _internalHandle
std::shared_ptr< class WindowWrapper > WindowWrapperPtr
WindowWrapper shared pointer.
Definition: WindowWrapper.h:55
void release()
Release resources stored in wrapper.
void * DisplayHandle
Definition: WindowWrapper.h:51
static WindowWrapperPtr create(ExternalWindowHandle externalHandle={}, InternalWindowHandle internalHandle={}, DisplayHandle display={})
Create a new WindowWrapper.
void * Widget
OS specific type windowing definitions.
Definition: WindowWrapper.h:48
bool isValid() const
Definition: WindowWrapper.h:86
void * ExternalWindowHandle
Definition: WindowWrapper.h:49
ExternalWindowHandle externalHandle() const
Return "external" handle.
Definition: WindowWrapper.h:73
void * InternalWindowHandle
Definition: WindowWrapper.h:50
#define MATERIALX_NAMESPACE_END
Definition: Generated.h:26
virtual ~WindowWrapper()
InternalWindowHandle internalHandle() const
Return "internal" handle.
Definition: WindowWrapper.h:79