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);
87 const std::string& windowTitle,
93 setWindowTitle(windowTitle.c_str());
96 ~WidgetManager() =
default;
98 const std::string& windowTitle()
const
100 return QWidget::windowTitle().toStdString();
103 void setWindowTitle(
const std::string& title)
105 QWidget::setWindowTitle(title.c_str());
108 Point2f dpiScale()
const {
return Point2f(pixelRatio(), pixelRatio()); }
110 void* displayId()
const
112 void* displayID =
nullptr;
115 QNativeInterface::QX11Application* x11AppInfo =
116 qApp->nativeInterface<QNativeInterface::QX11Application>();
118 displayID = x11AppInfo->display();
121 QNativeInterface::QWaylandApplication* wayAppInfo =
122 qApp->nativeInterface<QNativeInterface::QWaylandApplication>();
124 displayID = wayAppInfo->display();
134 QPaintEngine* paintEngine()
const override {
return nullptr; }
137 void* windowPtr() {
return reinterpret_cast<void*
>(
this); }
144 double mCurrentPixelRatio = -1.0;
147 bool event(QEvent* event)
override
150 if (event->type() == QEvent::DevicePixelRatioChange) {
152 mCurrentPixelRatio = pixelRatio();
157 if (event->type() == QEvent::UpdateRequest) {
158 if (mCurrentPixelRatio > 0 && mCurrentPixelRatio != pixelRatio()) {
159 const double ratio = pixelRatio();
162 mCurrentPixelRatio = -1.0;
165 QResizeEvent resizeEvent(size(), size());
166 auto app = qobject_cast<QGuiApplication*>(
167 QCoreApplication::instance());
168 app->sendEvent(
this, &resizeEvent);
173 if (event->type() == QEvent::WindowBlocked ||
174 event->type() == QEvent::WindowDeactivate) {
175 DerivedRenderApp::WM::setModifiers(
176 derived(), {KeyModifier::NO_MODIFIER});
179 return Base::event(event);
182#if defined(VCLIB_RENDER_BACKEND_BGFX)
183 void resizeEvent(QResizeEvent* event)
override
185 Base::resizeEvent(event);
186 DerivedRenderApp::WM::resize(
187 derived(), width() * pixelRatio(), height() * pixelRatio());
189#elif defined(VCLIB_RENDER_BACKEND_OPENGL2)
190 void resizeGL(
int w,
int h)
override
192 Base::resizeGL(w, h);
193 DerivedRenderApp::WM::resize(
194 derived(), w * pixelRatio(), h * pixelRatio());
198#if defined(VCLIB_RENDER_BACKEND_BGFX)
199 void showEvent(QShowEvent* event)
override
201 Base::showEvent(event);
202 DerivedRenderApp::WM::init(derived());
204#elif defined(VCLIB_RENDER_BACKEND_OPENGL2)
205 void initializeGL()
override { DerivedRenderApp::WM::init(derived()); }
208 void keyPressEvent(QKeyEvent* event)
override
210 DerivedRenderApp::WM::setModifiers(
211 derived(), vcl::qt::fromQt(event->modifiers()));
213 DerivedRenderApp::WM::keyPress(
215 vcl::qt::fromQt((Qt::Key) event->key(), event->modifiers()));
216 Base::keyPressEvent(event);
220 void keyReleaseEvent(QKeyEvent* event)
override
222 DerivedRenderApp::WM::setModifiers(
223 derived(), vcl::qt::fromQt(event->modifiers()));
225 DerivedRenderApp::WM::keyRelease(
227 vcl::qt::fromQt((Qt::Key) event->key(), event->modifiers()));
228 Base::keyReleaseEvent(event);
232 void mouseMoveEvent(QMouseEvent* event)
override
234 DerivedRenderApp::WM::mouseMove(
236 event->pos().x() * pixelRatio(),
237 event->pos().y() * pixelRatio());
238 Base::mouseMoveEvent(event);
242 void mousePressEvent(QMouseEvent* event)
override
244 DerivedRenderApp::WM::mousePress(
246 vcl::qt::fromQt(event->button()),
247 event->pos().x() * pixelRatio(),
248 event->pos().y() * pixelRatio());
249 Base::mousePressEvent(event);
253 void mouseReleaseEvent(QMouseEvent* event)
override
255 DerivedRenderApp::WM::mouseRelease(
257 vcl::qt::fromQt(event->button()),
258 event->pos().x() * pixelRatio(),
259 event->pos().y() * pixelRatio());
260 Base::mouseReleaseEvent(event);
264 void mouseDoubleClickEvent(QMouseEvent* event)
override
266 DerivedRenderApp::WM::mouseDoubleClick(
268 vcl::qt::fromQt(event->button()),
269 event->pos().x() * pixelRatio(),
270 event->pos().y() * pixelRatio());
271 Base::mouseDoubleClickEvent(event);
275 void wheelEvent(QWheelEvent* event)
override
278 if (!event->pixelDelta().isNull())
279 DerivedRenderApp::WM::mouseScroll(
280 derived(), event->pixelDelta().x(), event->pixelDelta().y());
282 DerivedRenderApp::WM::mouseScroll(
283 derived(), event->angleDelta().x(), event->angleDelta().y());
285 Base::wheelEvent(event);
289 double pixelRatio()
const
291 auto* screen = this->screen();
292 return double(screen ? screen->devicePixelRatio() : 1.0);
296#if defined(VCLIB_RENDER_BACKEND_BGFX)
297 void paintEvent(QPaintEvent* event)
override
299 DerivedRenderApp::WM::paint(derived());
300 QWidget::paintEvent(event);
302#elif defined(VCLIB_RENDER_BACKEND_OPENGL2)
303 void paintGL()
override { DerivedRenderApp::WM::paint(derived()); }
306 auto* derived() {
return static_cast<DerivedRenderApp*
>(
this); }
308 const auto* derived()
const
310 return static_cast<const DerivedRenderApp*
>(
this);