fix use of pixel ratio

pull/3471/head
kallaballa 2 years ago
parent f0f97504ba
commit d640a3a3d2
  1. 1
      modules/v4d/include/opencv2/v4d/dialog.hpp
  2. 23
      modules/v4d/src/detail/framebuffercontext.cpp
  3. 3
      modules/v4d/src/detail/framebuffercontext.hpp
  4. 3
      modules/v4d/src/detail/nanoguicontext.cpp

@ -22,7 +22,6 @@ using std::string;
class CustomTheme : public nanogui::Theme {
public:
CustomTheme(NVGcontext *ctx) : nanogui::Theme(ctx) {
m_window_drop_shadow_size = 10;
}
virtual ~CustomTheme() {

@ -288,8 +288,7 @@ void FrameBufferContext::init() {
glfwSetCursorPosCallback(getGLFWWindow(), [](GLFWwindow* glfwWin, double x, double y) {
V4D* v4d = reinterpret_cast<V4D*>(glfwGetWindowUserPointer(glfwWin));
if(v4d->hasNguiCtx()) {
auto pt = v4d->fbCtx().toWindowCoord(cv::Point2f(x, y));
v4d->nguiCtx().screen().cursor_pos_callback_event(pt.x, pt.y);
v4d->nguiCtx().screen().cursor_pos_callback_event(x, y);
}
#ifndef __EMSCRIPTEN__
auto cursor = v4d->getMousePosition();
@ -337,8 +336,8 @@ void FrameBufferContext::init() {
std::vector<nanogui::Widget*> widgets;
if(v4d->hasNguiCtx()) {
for (auto* w : v4d->nguiCtx().screen().children()) {
auto pt = v4d->fbCtx().toWindowCoord(v4d->getMousePosition());
auto mousePos = nanogui::Vector2i(pt[0] / v4d->pixelRatioX(), pt[1] / v4d->pixelRatioY());
auto pt = v4d->getMousePosition();
auto mousePos = nanogui::Vector2i(pt[0], pt[1]);
if(cv::v4d::detail::contains_absolute(w, mousePos)) {
v4d->nguiCtx().screen().scroll_callback_event(x, y);
return;
@ -638,22 +637,6 @@ void FrameBufferContext::execute(std::function<void(cv::UMat&)> fn) {
});
}
cv::Point2f FrameBufferContext::toWindowCoord(const cv::Point2f& pt) {
#ifdef __EMSCRIPTEN__
return cv::Point2f(pt.x * pixelRatioX(), pt.y * pixelRatioY());
#else
return cv::Point2f(pt.x, pt.y);
#endif
}
cv::Vec2f FrameBufferContext::toWindowCoord(const cv::Vec2f& pt) {
#ifdef __EMSCRIPTEN__
return cv::Point2f(pt[0] * pixelRatioX(), pt[1] * pixelRatioY());
#else
return cv::Point2f(pt[0], pt[1]);
#endif
}
cv::ogl::Texture2D& FrameBufferContext::getTexture2D() {
return *texture_;
}

@ -211,9 +211,6 @@ protected:
*/
cv::ogl::Texture2D& getTexture2D();
cv::Point2f toWindowCoord(const cv::Point2f& pt);
cv::Vec2f toWindowCoord(const cv::Vec2f& pt);
GLFWwindow* getGLFWWindow();
#ifndef __EMSCRIPTEN__

@ -29,10 +29,7 @@ NanoguiContext::NanoguiContext(FrameBufferContext& fbContext) :
screen_ = new nanogui::Screen(true, true, false);
screen_->initialize(fbCtx().getGLFWWindow(), false);
Size winSize = fbContext.getV4D().getWindowSize();
#ifndef __EMSCRIPTEN__
screen_->set_size({int(winSize.width / fbContext.getV4D().pixelRatioX()), int(winSize.height / fbContext.getV4D().pixelRatioY())});
#endif
fbCtx().setWindowSize(fbCtx().size());
context_ = screen_->nvg_context();
form_ = new cv::v4d::FormHelper(screen_);
if (!context_)

Loading…
Cancel
Save