45#if defined(VCLIB_RENDER_BACKEND_BGFX)
47#elif defined(VCLIB_RENDER_BACKEND_OPENGL2)
51#if defined(VCLIB_RENDER_BACKEND_BGFX)
53#elif defined(VCLIB_RENDER_BACKEND_OPENGL2)
76 "The DerivedRenderApp must satisfy the RenderAppConcept.");
77#if defined(VCLIB_RENDER_BACKEND_BGFX)
79 Qt::WA_PaintOnScreen);
86 const std::string& windowTitle,
92 setWindowTitle(windowTitle.c_str());
95 ~WidgetManager() =
default;
97 const std::string& windowTitle()
const
99 return QWidget::windowTitle().toStdString();
102 void setWindowTitle(
const std::string& title)
104 QWidget::setWindowTitle(title.c_str());
107 Point2f dpiScale()
const {
return Point2f(pixelRatio(), pixelRatio()); }
109 void* displayId()
const
111 void* displayID =
nullptr;
114 QNativeInterface::QX11Application* x11AppInfo =
115 qApp->nativeInterface<QNativeInterface::QX11Application>();
117 displayID = x11AppInfo->display();
120 QNativeInterface::QWaylandApplication* wayAppInfo =
121 qApp->nativeInterface<QNativeInterface::QWaylandApplication>();
123 displayID = wayAppInfo->display();
133 QPaintEngine* paintEngine()
const override {
return nullptr; }
136 void* windowPtr() {
return reinterpret_cast<void*
>(
this); }
143 double mCurrentPixelRatio = -1.0;
145 bool event(QEvent* event)
override
147 if (event->type() == QEvent::DevicePixelRatioChange) {
149 mCurrentPixelRatio = pixelRatio();
154 if (event->type() == QEvent::UpdateRequest) {
155 if (mCurrentPixelRatio > 0 && mCurrentPixelRatio != pixelRatio()) {
156 const double ratio = pixelRatio();
159 mCurrentPixelRatio = -1.0;
162 QResizeEvent resizeEvent(size(), size());
163 auto app = qobject_cast<QGuiApplication*>(
164 QCoreApplication::instance());
165 app->sendEvent(
this, &resizeEvent);
169 return QWidget::event(event);
173#if defined(VCLIB_RENDER_BACKEND_BGFX)
174 void resizeEvent(QResizeEvent* event)
override
176 Base::resizeEvent(event);
177 DerivedRenderApp::WM::resize(
178 derived(), width() * pixelRatio(), height() * pixelRatio());
180#elif defined(VCLIB_RENDER_BACKEND_OPENGL2)
181 void resizeGL(
int w,
int h)
override
183 Base::resizeGL(w, h);
184 DerivedRenderApp::WM::resize(
185 derived(), w * pixelRatio(), h * pixelRatio());
189#if defined(VCLIB_RENDER_BACKEND_BGFX)
190 void showEvent(QShowEvent* event)
override
192 Base::showEvent(event);
193 DerivedRenderApp::WM::init(derived());
195#elif defined(VCLIB_RENDER_BACKEND_OPENGL2)
196 void initializeGL()
override { DerivedRenderApp::WM::init(derived()); }
199 void keyPressEvent(QKeyEvent* event)
override
201 DerivedRenderApp::WM::setModifiers(
202 derived(), vcl::qt::fromQt(event->modifiers()));
204 DerivedRenderApp::WM::keyPress(
206 vcl::qt::fromQt((Qt::Key) event->key(), event->modifiers()));
207 Base::keyPressEvent(event);
211 void keyReleaseEvent(QKeyEvent* event)
override
213 DerivedRenderApp::WM::setModifiers(
214 derived(), vcl::qt::fromQt(event->modifiers()));
216 DerivedRenderApp::WM::keyRelease(
218 vcl::qt::fromQt((Qt::Key) event->key(), event->modifiers()));
219 Base::keyReleaseEvent(event);
223 void mouseMoveEvent(QMouseEvent* event)
override
225 DerivedRenderApp::WM::mouseMove(
227 event->pos().x() * pixelRatio(),
228 event->pos().y() * pixelRatio());
229 Base::mouseMoveEvent(event);
233 void mousePressEvent(QMouseEvent* event)
override
235 DerivedRenderApp::WM::mousePress(
237 vcl::qt::fromQt(event->button()),
238 event->pos().x() * pixelRatio(),
239 event->pos().y() * pixelRatio());
240 Base::mousePressEvent(event);
244 void mouseReleaseEvent(QMouseEvent* event)
override
246 DerivedRenderApp::WM::mouseRelease(
248 vcl::qt::fromQt(event->button()),
249 event->pos().x() * pixelRatio(),
250 event->pos().y() * pixelRatio());
251 Base::mouseReleaseEvent(event);
255 void mouseDoubleClickEvent(QMouseEvent* event)
override
257 DerivedRenderApp::WM::mouseDoubleClick(
259 vcl::qt::fromQt(event->button()),
260 event->pos().x() * pixelRatio(),
261 event->pos().y() * pixelRatio());
262 Base::mouseDoubleClickEvent(event);
266 void wheelEvent(QWheelEvent* event)
override
269 if (!event->pixelDelta().isNull())
270 DerivedRenderApp::WM::mouseScroll(
271 derived(), event->pixelDelta().x(), event->pixelDelta().y());
273 DerivedRenderApp::WM::mouseScroll(
274 derived(), event->angleDelta().x(), event->angleDelta().y());
276 Base::wheelEvent(event);
280 double pixelRatio()
const
282 auto* screen = this->screen();
283 return double(screen ? screen->devicePixelRatio() : 1.0);
287#if defined(VCLIB_RENDER_BACKEND_BGFX)
288 void paintEvent(QPaintEvent* event)
override
290 DerivedRenderApp::WM::paint(derived());
291 QWidget::paintEvent(event);
293#elif defined(VCLIB_RENDER_BACKEND_OPENGL2)
294 void paintGL()
override { DerivedRenderApp::WM::paint(derived()); }
297 auto* derived() {
return static_cast<DerivedRenderApp*
>(
this); }
299 const auto* derived()
const
301 return static_cast<const DerivedRenderApp*
>(
this);