diff --git a/dgl/Window.hpp b/dgl/Window.hpp index afbf8df5a..c34ccc862 100644 --- a/dgl/Window.hpp +++ b/dgl/Window.hpp @@ -113,7 +113,7 @@ class Window Window win(app); ScopedPointer widget; { - const ScopedGraphicsContext sgc(win); + const Window::ScopedGraphicsContext sgc(win); widget = new MyCustomTopLevelWidget(win); } app.exec(); diff --git a/distrho/src/DistrhoUI.cpp b/distrho/src/DistrhoUI.cpp index 258f86212..76182ee03 100644 --- a/distrho/src/DistrhoUI.cpp +++ b/distrho/src/DistrhoUI.cpp @@ -89,7 +89,7 @@ static double getDesktopScaleFactor() XrmInitialize(); - if (char* const rms = XResourceManagerString(view->world->impl->display)) + if (char* const rms = XResourceManagerString(display)) { if (const XrmDatabase sdb = XrmGetStringDatabase(rms)) { diff --git a/tests/Demo.cpp b/tests/Demo.cpp index 20c46c056..744044a37 100644 --- a/tests/Demo.cpp +++ b/tests/Demo.cpp @@ -42,6 +42,19 @@ typedef DGL_NAMESPACE::VulkanImage DemoImage; START_NAMESPACE_DGL +// Partial specialization is not allowed in C++, so we need to define these here +template<> inline +ExampleImagesWidget::ExampleImagesWidget(Widget* const parentWidget) +: SubWidget(parentWidget) { init(parentWidget->getApp()); } + +template<> inline +ExampleImagesWidget::ExampleImagesWidget(Window& windowToMapTo) +: TopLevelWidget(windowToMapTo) { init(windowToMapTo.getApp()); } + +template<> +ExampleImagesWidget::ExampleImagesWidget(Application& app) +: StandaloneWindow(app) { init(app); done(); } + typedef ExampleImagesWidget ExampleImagesSubWidget; typedef ExampleImagesWidget ExampleImagesTopLevelWidget; typedef ExampleImagesWidget ExampleImagesStandaloneWindow; diff --git a/tests/NanoSubWidgets.cpp b/tests/NanoSubWidgets.cpp index 1f205407d..b413986ab 100644 --- a/tests/NanoSubWidgets.cpp +++ b/tests/NanoSubWidgets.cpp @@ -127,9 +127,13 @@ class NanoExampleWindow : public Window { public: explicit NanoExampleWindow(Application& app) - : Window(app), - container(*this) + : Window(app) { + { + const ScopedGraphicsContext sgc(*this); + container = new NanoRectanglesContainer(*this); + } + const uint targetWidth = 400; const uint targetHeight = 400; const double scaleFactor = getScaleFactor(); @@ -141,7 +145,7 @@ class NanoExampleWindow : public Window } private: - NanoRectanglesContainer container; + ScopedPointer container; }; // -------------------------------------------------------------------------------------------------------------------- @@ -154,7 +158,6 @@ int main() Application app; NanoExampleWindow win(app); - win.show(); app.exec(); diff --git a/tests/widgets/ExampleImagesWidget.hpp b/tests/widgets/ExampleImagesWidget.hpp index cfec73331..106e1a747 100644 --- a/tests/widgets/ExampleImagesWidget.hpp +++ b/tests/widgets/ExampleImagesWidget.hpp @@ -21,8 +21,8 @@ // DGL Stuff #include "../../dgl/ImageBase.hpp" +#include "../../dgl/StandaloneWindow.hpp" #include "../../dgl/SubWidget.hpp" -#include "../../dgl/TopLevelWidget.hpp" // ------------------------------------------------------ // Images @@ -55,70 +55,34 @@ class ExampleImagesWidget : public BaseWidget, static constexpr const char* kExampleWidgetName = "Images"; // SubWidget - ExampleImagesWidget(Widget* const parent) - : BaseWidget(parent), - imgTop1st(1), - imgTop2nd(2), - imgTop3rd(3), - img1x(0), - img2x(kImg2max), - img3y(kImg3max), - img1rev(false), - img2rev(true), - img3rev(true), - img1(CatPics::cat1Data, CatPics::cat1Width, CatPics::cat1Height, kImageFormatBGR), - img2(CatPics::cat2Data, CatPics::cat2Width, CatPics::cat2Height, kImageFormatBGR), - img3(CatPics::cat3Data, CatPics::cat3Width, CatPics::cat3Height, kImageFormatBGR) - { - BaseWidget::setSize(500, 400); - - parent->getApp().addIdleCallback(this); - } + explicit ExampleImagesWidget(Widget* const parent); // TopLevelWidget - ExampleImagesWidget(Window& windowToMapTo) - : BaseWidget(windowToMapTo), - imgTop1st(1), - imgTop2nd(2), - imgTop3rd(3), - img1x(0), - img2x(kImg2max), - img3y(kImg3max), - img1rev(false), - img2rev(true), - img3rev(true), - img1(CatPics::cat1Data, CatPics::cat1Width, CatPics::cat1Height, kImageFormatBGR), - img2(CatPics::cat2Data, CatPics::cat2Width, CatPics::cat2Height, kImageFormatBGR), - img3(CatPics::cat3Data, CatPics::cat3Width, CatPics::cat3Height, kImageFormatBGR) - { - BaseWidget::setSize(500, 400); - - windowToMapTo.getApp().addIdleCallback(this); - } + explicit ExampleImagesWidget(Window& windowToMapTo); // StandaloneWindow - ExampleImagesWidget(Application& app) - : BaseWidget(app), - imgTop1st(1), - imgTop2nd(2), - imgTop3rd(3), - img1x(0), - img2x(kImg2max), - img3y(kImg3max), - img1rev(false), - img2rev(true), - img3rev(true), - img1(CatPics::cat1Data, CatPics::cat1Width, CatPics::cat1Height, kImageFormatBGR), - img2(CatPics::cat2Data, CatPics::cat2Width, CatPics::cat2Height, kImageFormatBGR), - img3(CatPics::cat3Data, CatPics::cat3Width, CatPics::cat3Height, kImageFormatBGR) + explicit ExampleImagesWidget(Application& app); + +protected: + void init(Application& app) { - BaseWidget::setSize(500, 400); + imgTop1st = 1; + imgTop2nd = 2; + imgTop3rd = 3; + img1x = 0; + img2x = kImg2max; + img3y = kImg3max; + img1rev = false; + img2rev = true; + img3rev = true; + img1 = BaseImage(CatPics::cat1Data, CatPics::cat1Width, CatPics::cat1Height, kImageFormatBGR); + img2 = BaseImage(CatPics::cat2Data, CatPics::cat2Width, CatPics::cat2Height, kImageFormatBGR); + img3 = BaseImage(CatPics::cat3Data, CatPics::cat3Width, CatPics::cat3Height, kImageFormatBGR); + BaseWidget::setSize(500, 400); app.addIdleCallback(this); - done(); } -protected: void idleCallback() noexcept override { if (img1rev) diff --git a/tests/widgets/ExampleRectanglesWidget.hpp b/tests/widgets/ExampleRectanglesWidget.hpp index ec525546a..d9ac32921 100644 --- a/tests/widgets/ExampleRectanglesWidget.hpp +++ b/tests/widgets/ExampleRectanglesWidget.hpp @@ -21,8 +21,8 @@ // DGL Stuff #include "../../dgl/Color.hpp" +#include "../../dgl/StandaloneWindow.hpp" #include "../../dgl/SubWidget.hpp" -#include "../../dgl/TopLevelWidget.hpp" START_NAMESPACE_DGL @@ -38,26 +38,13 @@ class ExampleRectanglesWidget : public BaseWidget static constexpr const char* const kExampleWidgetName = "Rectangles"; // SubWidget - explicit ExampleRectanglesWidget(Widget* const parentWidget) - : BaseWidget(parentWidget) - { - init(); - } + explicit ExampleRectanglesWidget(Widget* const parent); // TopLevelWidget - explicit ExampleRectanglesWidget(Window& windowToMapTo) - : BaseWidget(windowToMapTo) - { - init(); - } + explicit ExampleRectanglesWidget(Window& windowToMapTo); // StandaloneWindow - explicit ExampleRectanglesWidget(Application& app) - : BaseWidget(app) - { - init(); - done(); - } + explicit ExampleRectanglesWidget(Application& app); void init() { @@ -170,6 +157,31 @@ class ExampleRectanglesWidget : public BaseWidget } }; +// SubWidget +template<> inline +ExampleRectanglesWidget::ExampleRectanglesWidget(Widget* const parentWidget) + : SubWidget(parentWidget) +{ + init(); +} + +// TopLevelWidget +template<> inline +ExampleRectanglesWidget::ExampleRectanglesWidget(Window& windowToMapTo) + : TopLevelWidget(windowToMapTo) +{ + init(); +} + +// StandaloneWindow +template<> inline +ExampleRectanglesWidget::ExampleRectanglesWidget(Application& app) + : StandaloneWindow(app) +{ + init(); + done(); +} + typedef ExampleRectanglesWidget ExampleRectanglesSubWidget; typedef ExampleRectanglesWidget ExampleRectanglesTopLevelWidget; typedef ExampleRectanglesWidget ExampleRectanglesStandaloneWindow; diff --git a/tests/widgets/ExampleShapesWidget.hpp b/tests/widgets/ExampleShapesWidget.hpp index 05de6e4c5..c17510367 100644 --- a/tests/widgets/ExampleShapesWidget.hpp +++ b/tests/widgets/ExampleShapesWidget.hpp @@ -21,8 +21,8 @@ // DGL Stuff #include "../../dgl/Color.hpp" +#include "../../dgl/StandaloneWindow.hpp" #include "../../dgl/SubWidget.hpp" -#include "../../dgl/TopLevelWidget.hpp" START_NAMESPACE_DGL @@ -41,26 +41,13 @@ class ExampleShapesWidget : public BaseWidget static constexpr const char* const kExampleWidgetName = "Shapes"; // SubWidget - explicit ExampleShapesWidget(Widget* const parentWidget) - : BaseWidget(parentWidget) - { - this->setSize(300, 300); - } + explicit ExampleShapesWidget(Widget* const parent); // TopLevelWidget - explicit ExampleShapesWidget(Window& windowToMapTo) - : BaseWidget(windowToMapTo) - { - this->setSize(300, 300); - } + explicit ExampleShapesWidget(Window& windowToMapTo); // StandaloneWindow - explicit ExampleShapesWidget(Application& app) - : BaseWidget(app) - { - this->setSize(300, 300); - done(); - } + explicit ExampleShapesWidget(Application& app); protected: void onDisplay() override @@ -108,6 +95,31 @@ class ExampleShapesWidget : public BaseWidget } }; +// SubWidget +template<> inline +ExampleShapesWidget::ExampleShapesWidget(Widget* const parentWidget) + : SubWidget(parentWidget) +{ + setSize(300, 300); +} + +// TopLevelWidget +template<> inline +ExampleShapesWidget::ExampleShapesWidget(Window& windowToMapTo) + : TopLevelWidget(windowToMapTo) +{ + setSize(300, 300); +} + +// StandaloneWindow +template<> inline +ExampleShapesWidget::ExampleShapesWidget(Application& app) + : StandaloneWindow(app) +{ + setSize(300, 300); + done(); +} + typedef ExampleShapesWidget ExampleShapesSubWidget; typedef ExampleShapesWidget ExampleShapesTopLevelWidget; typedef ExampleShapesWidget ExampleShapesStandaloneWindow;