MaterialX 1.39.1
Loading...
Searching...
No Matches
WindowWrapper.h
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
16using Widget = struct _WidgetRec*;
17#endif
18
19#include <memory>
21
22MATERIALX_NAMESPACE_BEGIN
24#if defined(_WIN32)
26using ExternalWindowHandle = HWND;
28using InternalWindowHandle = HDC;
30using DisplayHandle = void*;
31#elif defined(__linux__) || defined(__FreeBSD__)
33using ExternalWindowHandle = Widget;
35using InternalWindowHandle = Window;
37using DisplayHandle = Display*;
39using Widget = struct _WidgetRec*;
40#elif defined(__APPLE__)
42using ExternalWindowHandle = void*;
44using InternalWindowHandle = void*;
46using DisplayHandle = void*;
47#else
48using Widget = void*;
49using ExternalWindowHandle = void*;
50using InternalWindowHandle = void*;
51using DisplayHandle = void*;
52#endif
53
55using WindowWrapperPtr = std::shared_ptr<class WindowWrapper>;
56
62{
63 public:
65 static WindowWrapperPtr create(ExternalWindowHandle externalHandle = {},
66 InternalWindowHandle internalHandle = {},
67 DisplayHandle display = {});
68
69 // Default destructor
70 virtual ~WindowWrapper();
71
73 ExternalWindowHandle externalHandle() const
74 {
75 return _externalHandle;
76 }
77
79 InternalWindowHandle internalHandle() const
80 {
81 return _internalHandle;
82 }
83
86 bool isValid() const
87 {
88 return _internalHandle != 0;
89 }
90
92 void release();
93
94#if defined(__linux__) || defined(__FreeBSD__)
96 Display* getXDisplay() const
97 {
98 return _xDisplay;
99 }
100#endif
101
102 protected:
103 WindowWrapper(ExternalWindowHandle externalHandle,
104 InternalWindowHandle internalHandle,
105 DisplayHandle display);
106
107 protected:
108 ExternalWindowHandle _externalHandle;
109 InternalWindowHandle _internalHandle;
110
111#if defined(__linux__) || defined(__FreeBSD__)
113 Window _framebufferWindow;
115 Display* _xDisplay;
116#endif
117};
118
119MATERIALX_NAMESPACE_END
120
121#endif
Library-wide includes and types.
Generic wrapper for encapsulating a "window" construct.
Definition: WindowWrapper.h:62
static WindowWrapperPtr create(ExternalWindowHandle externalHandle={}, InternalWindowHandle internalHandle={}, DisplayHandle display={})
Create a new WindowWrapper.
void release()
Release resources stored in wrapper.
bool isValid() const
Check that there is a valid OS handle set.
Definition: WindowWrapper.h:86
ExternalWindowHandle externalHandle() const
Return "external" handle.
Definition: WindowWrapper.h:73
InternalWindowHandle internalHandle() const
Return "internal" handle.
Definition: WindowWrapper.h:79