Blender V4.3
GHOST_Window.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2001-2002 NaN Holding BV. All rights reserved.
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
13#include "GHOST_Window.hh"
14
15#include "GHOST_ContextNone.hh"
16
17#include <cassert>
18
20 uint32_t height,
22 const bool wantStereoVisual,
23 const bool /*exclusive*/)
24 : m_drawingContextType(GHOST_kDrawingContextTypeNone),
25 m_userData(nullptr),
26 m_cursorVisible(true),
27 m_cursorGrab(GHOST_kGrabDisable),
28 m_cursorGrabAxis(GHOST_kAxisNone),
29 m_cursorGrabInitPos{0, 0},
30 m_cursorGrabAccumPos{0, 0},
31 m_cursorShape(GHOST_kStandardCursorDefault),
32 m_progressBarVisible(false),
33 m_canAcceptDragOperation(false),
34 m_isUnsavedChanges(false),
35 m_wantStereoVisual(wantStereoVisual),
36 m_nativePixelSize(1.0f),
37 m_context(new GHOST_ContextNone(false))
38
39{
40
42 if (m_fullScreen) {
43 m_fullScreenWidth = width;
44 m_fullScreenHeight = height;
45 }
46}
47
49{
50 delete m_context;
51}
52
54{
55 return nullptr;
56}
57
59{
60 if (type != m_drawingContextType) {
61 delete m_context;
62 m_context = nullptr;
63
65 m_context = newDrawingContext(type);
66 }
67 if (m_context != nullptr) {
69 }
70 else {
73 }
74
76 }
77 return GHOST_kSuccess;
78}
79
81{
82 return m_context;
83}
84
86{
87 return m_context->swapBuffers();
88}
89
91{
92 return m_context->setSwapInterval(interval);
93}
94
96{
97 return m_context->getSwapInterval(intervalOut);
98}
99
101{
102 return m_context;
103}
104
106{
107 return (m_context) ? m_context->getDefaultFramebuffer() : 0;
108}
109
110#ifdef WITH_VULKAN_BACKEND
111GHOST_TSuccess GHOST_Window::getVulkanSwapChainFormat(GHOST_VulkanSwapChainData *r_swap_chain_data)
112{
113 return m_context->getVulkanSwapChainFormat(r_swap_chain_data);
114}
115#endif
116
121
126
131
133{
134 if (setWindowCursorVisibility(visible)) {
135 m_cursorVisible = visible;
136 return GHOST_kSuccess;
137 }
138 return GHOST_kFailure;
139}
140
142 GHOST_TAxisFlag wrap_axis,
144 int32_t mouse_ungrab_xy[2])
145{
146 if (m_cursorGrab == mode) {
147 return GHOST_kSuccess;
148 }
149 /* Override with new location. */
150 if (mouse_ungrab_xy) {
151 assert(mode == GHOST_kGrabDisable);
152 m_cursorGrabInitPos[0] = mouse_ungrab_xy[0];
153 m_cursorGrabInitPos[1] = mouse_ungrab_xy[1];
154 }
155
156 if (setWindowCursorGrab(mode)) {
157
158 if (mode == GHOST_kGrabDisable) {
160 }
161 else if (bounds) {
163 }
164 else { /* if bounds not defined, use window */
166 }
167 m_cursorGrab = mode;
168 m_cursorGrabAxis = wrap_axis;
169 return GHOST_kSuccess;
170 }
171 return GHOST_kFailure;
172}
173
182
184 GHOST_TAxisFlag &wrap_axis,
186 bool &use_software_cursor)
187{
188 mode = m_cursorGrab;
191 wrap_axis = m_cursorGrabAxis;
192 }
193 else {
194 bounds.m_l = -1;
195 bounds.m_r = -1;
196 bounds.m_t = -1;
197 bounds.m_b = -1;
198 wrap_axis = GHOST_kAxisNone;
199 }
201 false;
202}
203
205{
206 /* Sub-classes may override, by default don't use software cursor. */
207 return false;
208}
209
211{
212 if (setWindowCursorShape(cursorShape)) {
213 m_cursorShape = cursorShape;
214 return GHOST_kSuccess;
215 }
216 return GHOST_kFailure;
217}
218
220 uint8_t *bitmap, uint8_t *mask, int sizex, int sizey, int hotX, int hotY, bool canInvertColor)
221{
222 if (setWindowCustomCursorShape(bitmap, mask, sizex, sizey, hotX, hotY, canInvertColor)) {
224 return GHOST_kSuccess;
225 }
226 return GHOST_kFailure;
227}
228
230{
231 /* Sub-classes may override. */
232 return GHOST_kFailure;
233}
234
236{
237 m_canAcceptDragOperation = canAccept;
238}
239
244
246{
247 m_isUnsavedChanges = isUnsavedChanges;
248
249 return GHOST_kSuccess;
250}
251
unsigned int uint
GHOST_TWindowState
@ GHOST_kWindowStateFullScreen
GHOST_TStandardCursor
@ GHOST_kStandardCursorCustom
@ GHOST_kStandardCursorDefault
GHOST_TAxisFlag
@ GHOST_kAxisNone
GHOST_TDrawingContextType
@ GHOST_kDrawingContextTypeNone
GHOST_TSuccess
Definition GHOST_Types.h:87
@ GHOST_kFailure
Definition GHOST_Types.h:87
@ GHOST_kSuccess
Definition GHOST_Types.h:87
GHOST_TGrabCursorMode
@ GHOST_kGrabWrap
@ GHOST_kGrabDisable
@ GHOST_kGrabHide
static btDbvtVolume bounds(btDbvtNode **leaves, int count)
Definition btDbvt.cpp:299
virtual GHOST_TSuccess activateDrawingContext() override=0
virtual GHOST_TSuccess releaseNativeHandles()=0
virtual GHOST_TSuccess setSwapInterval(int)
virtual GHOST_TSuccess updateDrawingContext()
virtual unsigned int getDefaultFramebuffer() override
virtual GHOST_TSuccess swapBuffers() override=0
virtual GHOST_TSuccess getSwapInterval(int &)
virtual void getClientBounds(GHOST_Rect &bounds) const =0
int32_t m_l
int32_t m_r
GHOST_TSuccess setCustomCursorShape(uint8_t *bitmap, uint8_t *mask, int sizex, int sizey, int hotX, int hotY, bool canInvertColor) override
GHOST_TSuccess getSwapInterval(int &intervalOut) override
GHOST_Rect m_cursorGrabBounds
bool getCursorGrabUseSoftwareDisplay() override
GHOST_TSuccess getCursorGrabBounds(GHOST_Rect &bounds) const override
virtual void * getOSWindow() const override
GHOST_TGrabCursorMode m_cursorGrab
bool m_wantStereoVisual
int32_t m_cursorGrabInitPos[2]
GHOST_TSuccess setDrawingContextType(GHOST_TDrawingContextType type) override
GHOST_TStandardCursor m_cursorShape
GHOST_Context * getContext()
bool canAcceptDragOperation() const override
GHOST_TSuccess setCursorGrab(GHOST_TGrabCursorMode mode, GHOST_TAxisFlag wrap_axis, GHOST_Rect *bounds, int32_t mouse_ungrab_xy[2]) override
virtual unsigned int getDefaultFramebuffer() override
GHOST_TSuccess setSwapInterval(int interval) override
virtual GHOST_TSuccess setWindowCursorGrab(GHOST_TGrabCursorMode)
GHOST_TSuccess releaseNativeHandles()
GHOST_TSuccess setCursorShape(GHOST_TStandardCursor cursorShape) override
GHOST_TAxisFlag m_cursorGrabAxis
virtual GHOST_TSuccess setWindowCustomCursorShape(uint8_t *bitmap, uint8_t *mask, int szx, int szy, int hotX, int hotY, bool canInvertColor)=0
virtual bool getModifiedState() override
GHOST_TSuccess setCursorVisibility(bool visible) override
GHOST_TSuccess getCursorBitmap(GHOST_CursorBitmapRef *bitmap) override
virtual GHOST_TSuccess setWindowCursorVisibility(bool visible)=0
GHOST_TDrawingContextType m_drawingContextType
virtual GHOST_TSuccess activateDrawingContext() override
virtual GHOST_TSuccess swapBuffers() override
uint32_t m_fullScreenHeight
virtual GHOST_IContext * getDrawingContext() override
bool m_isUnsavedChanges
GHOST_Window(uint32_t width, uint32_t height, GHOST_TWindowState state, const bool wantStereoVisual=false, const bool exclusive=false)
void getCursorGrabState(GHOST_TGrabCursorMode &mode, GHOST_TAxisFlag &wrap_axis, GHOST_Rect &bounds, bool &use_software_cursor) override
GHOST_TSuccess updateDrawingContext()
void setAcceptDragOperation(bool canAccept) override
virtual GHOST_TSuccess setModifiedState(bool isUnsavedChanges) override
virtual ~GHOST_Window()
virtual GHOST_TSuccess setWindowCursorShape(GHOST_TStandardCursor shape)=0
virtual GHOST_Context * newDrawingContext(GHOST_TDrawingContextType type)=0
bool m_canAcceptDragOperation
uint32_t m_fullScreenWidth
static ulong state[N]
unsigned int uint32_t
Definition stdint.h:80
signed int int32_t
Definition stdint.h:77
unsigned char uint8_t
Definition stdint.h:78