Signed-off-by: falkTX <falktx@falktx.com>pull/272/head
| @@ -305,7 +305,9 @@ public: | |||
| /** | |||
| Constructor reusing a NanoVG context, used for subwidgets. | |||
| */ | |||
| /* | |||
| NanoVG(NanoWidget* groupWidget); | |||
| */ | |||
| /** | |||
| Destructor. | |||
| @@ -240,10 +240,10 @@ NanoVG::NanoVG(int flags) | |||
| fInFrame(false), | |||
| fIsSubWidget(false) {} | |||
| NanoVG::NanoVG(NanoWidget* groupWidget) | |||
| : fContext(groupWidget->fContext), | |||
| fInFrame(false), | |||
| fIsSubWidget(true) {} | |||
| // NanoVG::NanoVG(NanoWidget* groupWidget) | |||
| // : fContext(groupWidget->fContext), | |||
| // fInFrame(false), | |||
| // fIsSubWidget(true) {} | |||
| NanoVG::~NanoVG() | |||
| { | |||
| @@ -257,21 +257,20 @@ NanoVG::~NanoVG() | |||
| void NanoVG::beginFrame(const uint width, const uint height, const float scaleFactor) | |||
| { | |||
| fInFrame = true; | |||
| if (fContext == nullptr) return; | |||
| DISTRHO_SAFE_ASSERT_RETURN(scaleFactor > 0.0f,); | |||
| DISTRHO_SAFE_ASSERT_RETURN(! fInFrame,); | |||
| fInFrame = true; | |||
| nvgBeginFrame(fContext, static_cast<int>(width), static_cast<int>(height), scaleFactor); | |||
| } | |||
| void NanoVG::beginFrame(Widget* const widget) | |||
| { | |||
| fInFrame = true; | |||
| DISTRHO_SAFE_ASSERT_RETURN(widget != nullptr,); | |||
| DISTRHO_SAFE_ASSERT_RETURN(! fInFrame,); | |||
| fInFrame = true; | |||
| if (fContext == nullptr) | |||
| return; | |||
| @@ -958,6 +957,7 @@ NanoWidget::NanoWidget(Widget* groupWidget, int flags) | |||
| pData->needsScaling = true; | |||
| } | |||
| /* | |||
| NanoWidget::NanoWidget(NanoWidget* groupWidget) | |||
| : Widget(groupWidget, false), | |||
| NanoVG(groupWidget), | |||
| @@ -967,6 +967,7 @@ NanoWidget::NanoWidget(NanoWidget* groupWidget) | |||
| pData->skipDisplay = true; | |||
| groupWidget->nData->subWidgets.push_back(this); | |||
| } | |||
| */ | |||
| NanoWidget::~NanoWidget() | |||
| { | |||
| @@ -129,7 +129,7 @@ void Window::PrivateData::setVisible(const bool visible) | |||
| #ifdef DISTRHO_OS_WINDOWS | |||
| puglShowWindowCentered(fView); | |||
| #else | |||
| puglShowWindow(fView); | |||
| puglShow(fView); | |||
| #endif | |||
| fAppData->oneWindowShown(); | |||
| fFirstInit = false; | |||
| @@ -139,7 +139,7 @@ void Window::PrivateData::setVisible(const bool visible) | |||
| #ifdef DISTRHO_OS_WINDOWS | |||
| puglWin32RestoreWindow(fView); | |||
| #else | |||
| puglShowWindow(fView); | |||
| puglShow(fView); | |||
| #endif | |||
| } | |||
| } | |||
| @@ -153,7 +153,7 @@ void Window::PrivateData::setVisible(const bool visible) | |||
| } | |||
| #endif | |||
| puglHideWindow(fView); | |||
| puglHide(fView); | |||
| // if (fModal.enabled) | |||
| // exec_fini(); | |||
| @@ -270,7 +270,7 @@ printEvent(const PuglEvent* event, const char* prefix, const bool verbose) | |||
| case PUGL_UNMAP: | |||
| return fprintf(stderr, "%sUnmap\n", prefix); | |||
| case PUGL_UPDATE: | |||
| return fprintf(stderr, "%sUpdate\n", prefix); | |||
| return 0; // fprintf(stderr, "%sUpdate\n", prefix); | |||
| case PUGL_CONFIGURE: | |||
| return PRINT("%sConfigure " PFMT " " PFMT "\n", | |||
| prefix, | |||
| @@ -350,6 +350,20 @@ PuglStatus Window::PrivateData::puglEventCallback(PuglView* const view, const Pu | |||
| pData->onPuglClose(); | |||
| break; | |||
| case PUGL_BUTTON_PRESS: ///< Mouse button pressed, a #PuglEventButton | |||
| case PUGL_BUTTON_RELEASE: ///< Mouse button released, a #PuglEventButton | |||
| { | |||
| Widget::MouseEvent ev; | |||
| ev.mod = event->button.state; | |||
| ev.flags = event->button.flags; | |||
| ev.time = static_cast<uint>(event->button.time * 1000.0 + 0.5); | |||
| ev.button = event->button.button; | |||
| ev.press = event->type == PUGL_BUTTON_PRESS; | |||
| ev.pos = Point<double>(event->button.x, event->button.y); | |||
| pData->onPuglMouse(ev); | |||
| break; | |||
| } | |||
| case PUGL_FOCUS_IN: ///< Keyboard focus entered view, a #PuglEventFocus | |||
| case PUGL_FOCUS_OUT: ///< Keyboard focus left view, a #PuglEventFocus | |||
| case PUGL_KEY_PRESS: ///< Key pressed, a #PuglEventKey | |||
| @@ -357,12 +371,12 @@ PuglStatus Window::PrivateData::puglEventCallback(PuglView* const view, const Pu | |||
| case PUGL_TEXT: ///< Character entered, a #PuglEventText | |||
| case PUGL_POINTER_IN: ///< Pointer entered view, a #PuglEventCrossing | |||
| case PUGL_POINTER_OUT: ///< Pointer left view, a #PuglEventCrossing | |||
| case PUGL_BUTTON_PRESS: ///< Mouse button pressed, a #PuglEventButton | |||
| case PUGL_BUTTON_RELEASE: ///< Mouse button released, a #PuglEventButton | |||
| case PUGL_MOTION: ///< Pointer moved, a #PuglEventMotion | |||
| case PUGL_SCROLL: ///< Scrolled, a #PuglEventScroll | |||
| case PUGL_CLIENT: ///< Custom client message, a #PuglEventClient | |||
| case PUGL_TIMER: ///< Timer triggered, a #PuglEventTimer | |||
| case PUGL_LOOP_ENTER: ///< Recursive loop entered, a #PuglEventLoopEnter | |||
| case PUGL_LOOP_LEAVE: ///< Recursive loop left, a #PuglEventLoopLeave | |||
| break; | |||
| } | |||
| @@ -340,6 +340,29 @@ struct Window::PrivateData { | |||
| } | |||
| } | |||
| void onPuglMouse(const Widget::MouseEvent& ev) | |||
| { | |||
| DGL_DBGp("PUGL: onMouse : %i %i %i %i\n", ev.button, ev.press, ev.pos.getX(), ev.pos.getY()); | |||
| // if (fModal.childFocus != nullptr) | |||
| // return fModal.childFocus->focus(); | |||
| Widget::MouseEvent rev = ev; | |||
| double x = ev.pos.getX() / fAutoScaling; | |||
| double y = ev.pos.getY() / fAutoScaling; | |||
| FOR_EACH_WIDGET_INV(rit) | |||
| { | |||
| Widget* const widget(*rit); | |||
| rev.pos = Point<double>(x - widget->getAbsoluteX(), | |||
| y - widget->getAbsoluteY()); | |||
| if (widget->isVisible() && widget->onMouse(rev)) | |||
| break; | |||
| } | |||
| } | |||
| // ------------------------------------------------------------------- | |||
| #ifdef DISTRHO_DEFINES_H_INCLUDED | |||
| @@ -484,36 +507,6 @@ struct Window::PrivateData { | |||
| return 1; | |||
| } | |||
| void onPuglMouse(const int button, const bool press, int x, int y) | |||
| { | |||
| DBGp("PUGL: onMouse : %i %i %i %i\n", button, press, x, y); | |||
| // FIXME - pugl sends 2 of these for each window on init, don't ask me why. we'll ignore it | |||
| if (press && button == 0 && x == 0 && y == 0) return; | |||
| if (fModal.childFocus != nullptr) | |||
| return fModal.childFocus->focus(); | |||
| x /= fAutoScaling; | |||
| y /= fAutoScaling; | |||
| Widget::MouseEvent ev; | |||
| ev.button = button; | |||
| ev.press = press; | |||
| ev.mod = static_cast<Modifier>(puglGetModifiers(fView)); | |||
| ev.time = puglGetEventTimestamp(fView); | |||
| FOR_EACH_WIDGET_INV(rit) | |||
| { | |||
| Widget* const widget(*rit); | |||
| ev.pos = Point<int>(x-widget->getAbsoluteX(), y-widget->getAbsoluteY()); | |||
| if (widget->isVisible() && widget->onMouse(ev)) | |||
| break; | |||
| } | |||
| } | |||
| void onPuglMotion(int x, int y) | |||
| { | |||
| // DBGp("PUGL: onMotion : %i %i\n", x, y); | |||