Blender V5.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
8
12
13#include "GHOST_Window.hh"
14
15#include "GHOST_ContextNone.hh"
16
17#include "GHOST_utildefines.hh"
18
19#include <cassert>
20
53
55{
56 delete context_;
57}
58
60{
61 return nullptr;
62}
63
68
73
79
81{
82 if (type != drawing_context_type_) {
83 delete context_;
84 context_ = nullptr;
85
87 context_ = newDrawingContext(type);
88 }
89 if (context_ != nullptr) {
91 }
92 else {
95 }
96
98 }
99 return GHOST_kSuccess;
100}
101
103{
104 return context_;
105}
106
108{
109 return context_->swapBufferAcquire();
110}
112{
113 return context_->swapBufferRelease();
114}
115
117{
118 return context_->setSwapInterval(interval);
119}
120
122{
123 return context_->getSwapInterval(interval_out);
124}
125
127{
128 return context_;
129}
130
132{
133 return context_ ? context_->hasAlpha() : false;
134}
135
137{
138 return (context_) ? context_->getDefaultFramebuffer() : 0;
139}
140
141#ifdef WITH_VULKAN_BACKEND
142GHOST_TSuccess GHOST_Window::getVulkanSwapChainFormat(GHOST_VulkanSwapChainData *r_swap_chain_data)
143{
144 return context_->getVulkanSwapChainFormat(r_swap_chain_data);
145}
146#endif
147
149{
150 return context_->activateDrawingContext();
151}
152
154{
155 return context_->updateDrawingContext();
156}
157
159{
160 return context_->releaseNativeHandles();
161}
162
164{
165 if (setWindowCursorVisibility(visible)) {
166 cursor_visible_ = visible;
167 return GHOST_kSuccess;
168 }
169 return GHOST_kFailure;
170}
171
173 GHOST_TAxisFlag wrap_axis,
174 GHOST_Rect *bounds,
175 int32_t mouse_ungrab_xy[2])
176{
177 if (cursor_grab_ == mode) {
178 return GHOST_kSuccess;
179 }
180 /* Override with new location. */
181 if (mouse_ungrab_xy) {
182 assert(mode == GHOST_kGrabDisable);
183 cursor_grab_init_pos_[0] = mouse_ungrab_xy[0];
184 cursor_grab_init_pos_[1] = mouse_ungrab_xy[1];
185 }
186
187 if (setWindowCursorGrab(mode)) {
188
189 if (mode == GHOST_kGrabDisable) {
191 }
192 else if (bounds) {
193 cursor_grab_bounds_ = *bounds;
194 }
195 else { /* if bounds not defined, use window */
197 }
198 cursor_grab_ = mode;
199 cursor_grab_axis_ = wrap_axis;
200 return GHOST_kSuccess;
201 }
202 return GHOST_kFailure;
203}
204
206{
208 return GHOST_kFailure;
209 }
210 bounds = cursor_grab_bounds_;
211 return (bounds.l_ == -1 && bounds.r_ == -1) ? GHOST_kFailure : GHOST_kSuccess;
212}
213
215 GHOST_TAxisFlag &wrap_axis,
216 GHOST_Rect &bounds,
217 bool &use_software_cursor)
218{
219 mode = cursor_grab_;
221 bounds = cursor_grab_bounds_;
222 wrap_axis = cursor_grab_axis_;
223 }
224 else {
225 bounds.l_ = -1;
226 bounds.r_ = -1;
227 bounds.t_ = -1;
228 bounds.b_ = -1;
229 wrap_axis = GHOST_kAxisNone;
230 }
232 false;
233}
234
236{
237 /* Sub-classes may override, by default don't use software cursor. */
238 return false;
239}
240
242{
243 if (setWindowCursorShape(cursor_shape)) {
244 cursor_shape_ = cursor_shape;
245 return GHOST_kSuccess;
246 }
247 return GHOST_kFailure;
248}
249
251 const uint8_t *mask,
252 const int size[2],
253 const int hot_spot[2],
254 bool can_invert_color)
255{
256 if (setWindowCustomCursorShape(bitmap, mask, size, hot_spot, can_invert_color)) {
258 return GHOST_kSuccess;
259 }
260 return GHOST_kFailure;
261}
262
271
273{
274 /* Sub-classes may override. */
275 return GHOST_kFailure;
276}
277
279{
280 can_accept_drag_operation_ = can_accept;
281}
282
287
289{
290 is_unsaved_changes_ = is_unsaved_changes;
291
292 return GHOST_kSuccess;
293}
294
GHOST_TWindowState
@ GHOST_kWindowStateFullScreen
GHOST_TStandardCursor
@ GHOST_kStandardCursorCustom
@ GHOST_kStandardCursorDefault
GHOST_TAxisFlag
@ GHOST_kAxisNone
GHOST_TDrawingContextType
@ GHOST_kDrawingContextTypeNone
GHOST_TSuccess
@ GHOST_kFailure
@ GHOST_kSuccess
GHOST_TGrabCursorMode
@ GHOST_kGrabWrap
@ GHOST_kGrabDisable
@ GHOST_kGrabHide
#define GHOST_CONTEXT_PARAMS_NONE
GHOST_TWindowDecorationStyleFlags
@ GHOST_kDecorationNone
#define ELEM(...)
GHOST_ContextNone(const GHOST_ContextParams &context_params)
bool hasAlpha() const
virtual void getClientBounds(GHOST_Rect &bounds) const =0
int32_t t_
int32_t r_
int32_t b_
int32_t l_
virtual GHOST_TSuccess getCursorGrabBounds(GHOST_Rect &bounds) const
~GHOST_Window() override
GHOST_ContextParams want_context_params_
int32_t cursor_grab_accum_pos_[2]
virtual bool getCursorGrabUseSoftwareDisplay()
GHOST_TSuccess swapBufferRelease() override
float native_pixel_size_
void setWindowDecorationStyleFlags(GHOST_TWindowDecorationStyleFlags style_flags) override
GHOST_TStandardCursor cursor_shape_
GHOST_TAxisFlag cursor_grab_axis_
virtual bool getModifiedState()
bool can_accept_drag_operation_
GHOST_TSuccess setModifiedState(bool is_unsaved_changes) override
GHOST_WindowDecorationStyleSettings window_decoration_style_settings_
GHOST_TSuccess setDrawingContextType(GHOST_TDrawingContextType type) override
GHOST_TSuccess setCursorShape(GHOST_TStandardCursor cursor_shape) override
uint32_t full_screen_width_
GHOST_Context * getContext()
int32_t cursor_grab_init_pos_[2]
GHOST_TSuccess setCursorGrab(GHOST_TGrabCursorMode mode, GHOST_TAxisFlag wrap_axis, GHOST_Rect *bounds, int32_t mouse_ungrab_xy[2]) override
unsigned int getDefaultFramebuffer() override
GHOST_TSuccess setSwapInterval(int interval) override
virtual GHOST_TSuccess setWindowCursorGrab(GHOST_TGrabCursorMode)
GHOST_TUserDataPtr user_data_
GHOST_TDrawingContextType drawing_context_type_
GHOST_TWindowDecorationStyleFlags getWindowDecorationStyleFlags() override
GHOST_TSuccess releaseNativeHandles()
virtual GHOST_TSuccess setWindowCustomCursorGenerator(GHOST_CursorGenerator *cursor_generator)
virtual void * getOSWindow() const
void setWindowDecorationStyleSettings(GHOST_WindowDecorationStyleSettings decoration_settings) override
GHOST_TWindowDecorationStyleFlags window_decoration_style_flags_
virtual bool canAcceptDragOperation() const
uint32_t full_screen_height_
GHOST_TSuccess setCursorVisibility(bool visible) override
GHOST_TSuccess setCustomCursorShape(const uint8_t *bitmap, const uint8_t *mask, const int size[2], const int hot_spot[2], bool can_invert_color) override
GHOST_TSuccess getCursorBitmap(GHOST_CursorBitmapRef *bitmap) override
virtual GHOST_TSuccess setWindowCursorVisibility(bool visible)=0
void setAcceptDragOperation(bool can_accept) override
GHOST_TSuccess activateDrawingContext() override
GHOST_IContext * getDrawingContext() override
void getCursorGrabState(GHOST_TGrabCursorMode &mode, GHOST_TAxisFlag &wrap_axis, GHOST_Rect &bounds, bool &use_software_cursor) override
GHOST_TSuccess updateDrawingContext()
bool is_unsaved_changes_
GHOST_Window(uint32_t width, uint32_t height, GHOST_TWindowState state, const GHOST_ContextParams &context_params, const bool exclusive=false)
GHOST_TSuccess getSwapInterval(int &interval_out) override
virtual GHOST_TSuccess setWindowCursorShape(GHOST_TStandardCursor shape)=0
virtual GHOST_Context * newDrawingContext(GHOST_TDrawingContextType type)=0
GHOST_Rect cursor_grab_bounds_
bool progress_bar_visible_
GHOST_TSuccess swapBufferAcquire() override
GHOST_TGrabCursorMode cursor_grab_
GHOST_TSuccess setCustomCursorGenerator(GHOST_CursorGenerator *cursor_generator) override
bool hasAlpha() const override
virtual GHOST_TSuccess setWindowCustomCursorShape(const uint8_t *bitmap, const uint8_t *mask, const int size[2], const int hot_size[2], bool can_invert_color)=0
#define assert(assertion)
const int state
ccl_device_inline float2 mask(const MaskType mask, const float2 a)