diff --git a/source/modules/carla_native/distrho/DistrhoPluginCarla.cpp b/source/modules/carla_native/distrho/DistrhoPluginCarla.cpp index 28160da43..df68646ad 100644 --- a/source/modules/carla_native/distrho/DistrhoPluginCarla.cpp +++ b/source/modules/carla_native/distrho/DistrhoPluginCarla.cpp @@ -18,7 +18,7 @@ # error We do not want Qt in the engine code! #endif -#include "../CarlaNative.hpp" +#include "CarlaNative.hpp" #include "CarlaString.hpp" #include "DistrhoPluginMain.cpp" @@ -33,8 +33,6 @@ # endif #endif -using juce::ScopedPointer; - // ----------------------------------------------------------------------- START_NAMESPACE_DISTRHO @@ -59,8 +57,8 @@ public: #endif { #ifdef DISTRHO_UI_OPENGL - glWindow.setSize(fUi.getWidth(), fUi.getHeight()); - glWindow.setWindowTitle(host->uiName); + //glWindow.setSize(fUi.getWidth(), fUi.getHeight()); + glWindow.setTitle(host->uiName); #else CarlaString filename; filename += fHost->resourceDir; @@ -202,7 +200,7 @@ public: void carla_setUiTitle(const char* const uiTitle) { #ifdef DISTRHO_UI_OPENGL - glWindow.setWindowTitle(uiTitle); + glWindow.setTitle(uiTitle); #else writeMsg("uiTitle\n", 8); writeAndFixMsg(uiTitle); @@ -321,7 +319,11 @@ public: ~PluginCarla() override { #if DISTRHO_PLUGIN_HAS_UI - fUiPtr = nullptr; + if (fUiPtr != nullptr) + { + delete fUiPtr; + fUiPtr = nullptr; + } #endif } @@ -574,7 +576,7 @@ private: #if DISTRHO_PLUGIN_HAS_UI // UI - ScopedPointer fUiPtr; + UICarla* fUiPtr; void createUiIfNeeded() { diff --git a/source/modules/distrho/dgl/App.hpp b/source/modules/distrho/dgl/App.hpp index d1edbf242..790f2f043 100644 --- a/source/modules/distrho/dgl/App.hpp +++ b/source/modules/distrho/dgl/App.hpp @@ -21,6 +21,8 @@ START_NAMESPACE_DGL +class Window; + // ----------------------------------------------------------------------- class App @@ -35,9 +37,14 @@ public: bool isQuiting() const; private: - class PrivateData; + struct PrivateData; PrivateData* const pData; friend class Window; + + void addWindow(Window* const window); + void removeWindow(Window* const window); + void oneShown(); + void oneHidden(); }; // ----------------------------------------------------------------------- diff --git a/source/modules/distrho/dgl/Base.hpp b/source/modules/distrho/dgl/Base.hpp index 669df2211..4034587e4 100644 --- a/source/modules/distrho/dgl/Base.hpp +++ b/source/modules/distrho/dgl/Base.hpp @@ -53,9 +53,9 @@ #define USE_NAMESPACE_DGL using namespace DGL_NAMESPACE; #if DGL_OS_MAC -# include +# include #else -# include +# include #endif #if defined(GL_BGR_EXT) && ! defined(GL_BGR) diff --git a/source/modules/distrho/dgl/Geometry.hpp b/source/modules/distrho/dgl/Geometry.hpp index 5ff5c3a6b..94089462b 100644 --- a/source/modules/distrho/dgl/Geometry.hpp +++ b/source/modules/distrho/dgl/Geometry.hpp @@ -27,24 +27,24 @@ template class Point { public: - Point(); - Point(T x, T y); - Point(const Point& pos); + Point() noexcept; + Point(T x, T y) noexcept; + Point(const Point& pos) noexcept; - T getX() const; - T getY() const; + T getX() const noexcept; + T getY() const noexcept; - void setX(T x); - void setY(T y); + void setX(T x) noexcept; + void setY(T y) noexcept; - void move(T x, T y); - void move(const Point& pos); + void move(T x, T y) noexcept; + void move(const Point& pos) noexcept; - Point& operator=(const Point& pos); - Point& operator+=(const Point& pos); - Point& operator-=(const Point& pos); - bool operator==(const Point& pos) const; - bool operator!=(const Point& pos) const; + Point& operator=(const Point& pos) noexcept; + Point& operator+=(const Point& pos) noexcept; + Point& operator-=(const Point& pos) noexcept; + bool operator==(const Point& pos) const noexcept; + bool operator!=(const Point& pos) const noexcept; private: T fX, fY; @@ -57,23 +57,23 @@ template class Size { public: - Size(); - Size(T width, T height); - Size(const Size& size); + Size() noexcept; + Size(T width, T height) noexcept; + Size(const Size& size) noexcept; - T getWidth() const; - T getHeight() const; + T getWidth() const noexcept; + T getHeight() const noexcept; - void setWidth(T width); - void setHeight(T height); + void setWidth(T width) noexcept; + void setHeight(T height) noexcept; - Size& operator=(const Size& size); - Size& operator+=(const Size& size); - Size& operator-=(const Size& size); - Size& operator*=(T m); - Size& operator/=(T d); - bool operator==(const Size& size) const; - bool operator!=(const Size& size) const; + Size& operator=(const Size& size) noexcept; + Size& operator+=(const Size& size) noexcept; + Size& operator-=(const Size& size) noexcept; + Size& operator*=(T m) noexcept; + Size& operator/=(T d) noexcept; + bool operator==(const Size& size) const noexcept; + bool operator!=(const Size& size) const noexcept; private: T fWidth, fHeight; @@ -86,40 +86,40 @@ template class Rectangle { public: - Rectangle(); - Rectangle(T x, T y, T width, T height); - Rectangle(T x, T y, const Size& size); - Rectangle(const Point& pos, T width, T height); - Rectangle(const Point& pos, const Size& size); - Rectangle(const Rectangle& rect); - - T getX() const; - T getY() const; - T getWidth() const; - T getHeight() const; - - const Point& getPos() const; - const Size& getSize() const; - - bool contains(T x, T y) const; - bool contains(const Point& pos) const; - bool containsX(T x) const; - bool containsY(T y) const; - - void setX(T x); - void setY(T y); - void setPos(T x, T y); - void setPos(const Point& pos); - - void move(T x, T y); - void move(const Point& pos); - - void setWidth(T width); - void setHeight(T height); - void setSize(T width, T height); - void setSize(const Size& size); - - Rectangle& operator=(const Rectangle& rect); + Rectangle() noexcept; + Rectangle(T x, T y, T width, T height) noexcept; + Rectangle(T x, T y, const Size& size) noexcept; + Rectangle(const Point& pos, T width, T height) noexcept; + Rectangle(const Point& pos, const Size& size) noexcept; + Rectangle(const Rectangle& rect) noexcept; + + T getX() const noexcept; + T getY() const noexcept; + T getWidth() const noexcept; + T getHeight() const noexcept; + + const Point& getPos() const noexcept; + const Size& getSize() const noexcept; + + bool contains(T x, T y) const noexcept; + bool contains(const Point& pos) const noexcept; + bool containsX(T x) const noexcept; + bool containsY(T y) const noexcept; + + void setX(T x) noexcept; + void setY(T y) noexcept; + void setPos(T x, T y) noexcept; + void setPos(const Point& pos) noexcept; + + void move(T x, T y) noexcept; + void move(const Point& pos) noexcept; + + void setWidth(T width) noexcept; + void setHeight(T height) noexcept; + void setSize(T width, T height) noexcept; + void setSize(const Size& size) noexcept; + + Rectangle& operator=(const Rectangle& rect) noexcept; private: Point fPos; diff --git a/source/modules/distrho/dgl/Image.hpp b/source/modules/distrho/dgl/Image.hpp index 836eb5fdd..acbfc16d1 100644 --- a/source/modules/distrho/dgl/Image.hpp +++ b/source/modules/distrho/dgl/Image.hpp @@ -26,31 +26,31 @@ START_NAMESPACE_DGL class Image { public: - Image(); - Image(const char* rawData, int width, int height, GLenum format = GL_BGRA, GLenum type = GL_UNSIGNED_BYTE); - Image(const char* rawData, const Size& size, GLenum format = GL_BGRA, GLenum type = GL_UNSIGNED_BYTE); - Image(const Image& image); + Image() noexcept; + Image(const char* rawData, int width, int height, GLenum format = GL_BGRA, GLenum type = GL_UNSIGNED_BYTE) noexcept; + Image(const char* rawData, const Size& size, GLenum format = GL_BGRA, GLenum type = GL_UNSIGNED_BYTE) noexcept; + Image(const Image& image) noexcept; - void loadFromMemory(const char* rawData, int width, int height, GLenum format = GL_BGRA, GLenum type = GL_UNSIGNED_BYTE); - void loadFromMemory(const char* rawData, const Size& size, GLenum format = GL_BGRA, GLenum type = GL_UNSIGNED_BYTE); + void loadFromMemory(const char* rawData, int width, int height, GLenum format = GL_BGRA, GLenum type = GL_UNSIGNED_BYTE) noexcept; + void loadFromMemory(const char* rawData, const Size& size, GLenum format = GL_BGRA, GLenum type = GL_UNSIGNED_BYTE) noexcept; - bool isValid() const; + bool isValid() const noexcept; - int getWidth() const; - int getHeight() const; - const Size& getSize() const; + int getWidth() const noexcept; + int getHeight() const noexcept; + const Size& getSize() const noexcept; - const char* getRawData() const; - GLenum getFormat() const; - GLenum getType() const; + const char* getRawData() const noexcept; + GLenum getFormat() const noexcept; + GLenum getType() const noexcept; void draw() const; void draw(int x, int y) const; void draw(const Point& pos) const; - Image& operator=(const Image& image); - bool operator==(const Image& image) const; - bool operator!=(const Image& image) const; + Image& operator=(const Image& image) noexcept; + bool operator==(const Image& image) const noexcept; + bool operator!=(const Image& image) const noexcept; private: const char* fRawData; diff --git a/source/modules/distrho/dgl/ImageAboutWindow.hpp b/source/modules/distrho/dgl/ImageAboutWindow.hpp index a43f5a538..b46a7f112 100644 --- a/source/modules/distrho/dgl/ImageAboutWindow.hpp +++ b/source/modules/distrho/dgl/ImageAboutWindow.hpp @@ -35,7 +35,7 @@ class ImageAboutWindow : public Window, public Widget { public: - ImageAboutWindow(App* app, Window* parent, const Image& image = Image()); + ImageAboutWindow(App& app, Window& parent, const Image& image = Image()); ImageAboutWindow(Widget* widget, const Image& image = Image()); void setImage(const Image& image); diff --git a/source/modules/distrho/dgl/ImageButton.hpp b/source/modules/distrho/dgl/ImageButton.hpp index 9a1249cdb..6180cd72e 100644 --- a/source/modules/distrho/dgl/ImageButton.hpp +++ b/source/modules/distrho/dgl/ImageButton.hpp @@ -34,9 +34,9 @@ public: virtual void imageButtonClicked(ImageButton* imageButton, int button) = 0; }; - ImageButton(Window* parent, const Image& image); + ImageButton(Window& parent, const Image& image); ImageButton(Widget* widget, const Image& image); - ImageButton(Window* parent, const Image& imageNormal, const Image& imageHover, const Image& imageDown); + ImageButton(Window& parent, const Image& imageNormal, const Image& imageHover, const Image& imageDown); ImageButton(Widget* widget, const Image& imageNormal, const Image& imageHover, const Image& imageDown); ImageButton(const ImageButton& imageButton); diff --git a/source/modules/distrho/dgl/ImageKnob.hpp b/source/modules/distrho/dgl/ImageKnob.hpp index dcc464c00..2c80dbaad 100644 --- a/source/modules/distrho/dgl/ImageKnob.hpp +++ b/source/modules/distrho/dgl/ImageKnob.hpp @@ -41,7 +41,7 @@ public: virtual void imageKnobValueChanged(ImageKnob* imageKnob, float value) = 0; }; - ImageKnob(Window* parent, const Image& image, Orientation orientation = Vertical); + ImageKnob(Window& parent, const Image& image, Orientation orientation = Vertical); ImageKnob(Widget* widget, const Image& image, Orientation orientation = Vertical); ImageKnob(const ImageKnob& imageKnob); diff --git a/source/modules/distrho/dgl/ImageSlider.hpp b/source/modules/distrho/dgl/ImageSlider.hpp index ed6abfc9d..078cbd63b 100644 --- a/source/modules/distrho/dgl/ImageSlider.hpp +++ b/source/modules/distrho/dgl/ImageSlider.hpp @@ -36,7 +36,7 @@ public: virtual void imageSliderValueChanged(ImageSlider* imageSlider, float value) = 0; }; - ImageSlider(Window* parent, const Image& image); + ImageSlider(Window& parent, const Image& image); ImageSlider(Widget* widget, const Image& image); ImageSlider(const ImageSlider& imageSlider); diff --git a/source/modules/distrho/dgl/StandaloneWindow.hpp b/source/modules/distrho/dgl/StandaloneWindow.hpp index cab762259..c4348228f 100644 --- a/source/modules/distrho/dgl/StandaloneWindow.hpp +++ b/source/modules/distrho/dgl/StandaloneWindow.hpp @@ -34,12 +34,12 @@ public: { } - App& getApp() const + App& getApp() const noexcept { return fApp; } - Window& getWindow() const + Window& getWindow() const noexcept { return fWindow; } @@ -63,9 +63,9 @@ public: fWindow.setSize(width, height); } - void setWindowTitle(const char* title) + void setTitle(const char* title) { - fWindow.setWindowTitle(title); + fWindow.setTitle(title); } private: diff --git a/source/modules/distrho/dgl/Widget.hpp b/source/modules/distrho/dgl/Widget.hpp index f1ac98c78..c4336cf16 100644 --- a/source/modules/distrho/dgl/Widget.hpp +++ b/source/modules/distrho/dgl/Widget.hpp @@ -19,6 +19,12 @@ #include "Geometry.hpp" +#ifdef PROPER_CPP11_SUPPORT +# include +#else +# include +#endif + START_NAMESPACE_DGL // ----------------------------------------------------------------------- @@ -32,22 +38,15 @@ public: Widget(Window& parent); virtual ~Widget(); - bool isVisible() const; + bool isVisible() const noexcept; void setVisible(bool yesNo); - void show() - { - setVisible(true); - } - - void hide() - { - setVisible(false); - } + void show(); + void hide(); - int getX() const; - int getY() const; - const Point& getPos() const; + int getX() const noexcept; + int getY() const noexcept; + const Point& getPos() const noexcept; void setX(int x); void setY(int y); @@ -57,26 +56,28 @@ public: void move(int x, int y); void move(const Point& pos); - int getWidth() const; - int getHeight() const; - const Size& getSize() const; + int getWidth() const noexcept; + int getHeight() const noexcept; + const Size& getSize() const noexcept; void setWidth(int width); void setHeight(int height); void setSize(int width, int height); void setSize(const Size& size); - const Rectangle& getArea() const; + const Rectangle& getArea() const noexcept; + uint32_t getEventTimestamp(); int getModifiers(); - App* getApp() const; - Window* getParent() const; + App& getParentApp() const noexcept; + Window& getParentWindow() const noexcept; + void repaint(); protected: virtual void onDisplay(); - virtual bool onKeyboard(bool press, unsigned key); + virtual bool onKeyboard(bool press, uint32_t key); virtual bool onMouse(int button, bool press, int x, int y); virtual bool onMotion(int x, int y); virtual bool onScroll(float dx, float dy); diff --git a/source/modules/distrho/dgl/Window.hpp b/source/modules/distrho/dgl/Window.hpp index 356351eb5..d4f8ece26 100644 --- a/source/modules/distrho/dgl/Window.hpp +++ b/source/modules/distrho/dgl/Window.hpp @@ -17,7 +17,13 @@ #ifndef DGL_WINDOW_HPP_INCLUDED #define DGL_WINDOW_HPP_INCLUDED -#include "Base.hpp" +#include "Geometry.hpp" + +#ifdef PROPER_CPP11_SUPPORT +# include +#else +# include +#endif START_NAMESPACE_DGL @@ -34,31 +40,40 @@ public: Window(App& app, intptr_t parentId); virtual ~Window(); + void show(); + void hide(); + void close(); void exec(bool lockWait = false); + void focus(); void idle(); void repaint(); - bool isVisible(); + bool isVisible() const noexcept; void setVisible(bool yesNo); + + bool isResizable() const noexcept; void setResizable(bool yesNo); - void setSize(unsigned int width, unsigned int height); - void setWindowTitle(const char* title); - App& getApp() const; - int getModifiers() const; - intptr_t getWindowId() const; + int getWidth() const noexcept; + int getHeight() const noexcept; + Size getSize() const noexcept; + void setSize(unsigned int width, unsigned int height); - void addWidget(Widget* widget); - void removeWidget(Widget* widget); + void setTitle(const char* title); - void show(); - void hide(); - void close(); + App& getApp() const noexcept; + uint32_t getEventTimestamp() const; + int getModifiers() const; + intptr_t getWindowId() const; private: class PrivateData; PrivateData* const pData; + friend class Widget; + + void addWidget(Widget* const widget); + void removeWidget(Widget* const widget); }; // ----------------------------------------------------------------------- diff --git a/source/modules/distrho/dgl/src/App.cpp b/source/modules/distrho/dgl/src/App.cpp index f95d3e4b6..9bbdf71f7 100644 --- a/source/modules/distrho/dgl/src/App.cpp +++ b/source/modules/distrho/dgl/src/App.cpp @@ -14,27 +14,41 @@ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#include "AppPrivate.hpp" - +#include "../App.hpp" #include "../Window.hpp" +#include + START_NAMESPACE_DGL // ----------------------------------------------------------------------- +struct App::PrivateData { + bool doLoop; + unsigned visibleWindows; + std::list windows; + + PrivateData() + : doLoop(false), + visibleWindows(0) {} +}; + +// ----------------------------------------------------------------------- + App::App() - : pData(new Private()) + : pData(new PrivateData()) { } App::~App() { + pData->windows.clear(); delete pData; } void App::idle() { - for (std::list::iterator it = pData->fWindows.begin(); it != pData->fWindows.end(); ++it) + for (std::list::iterator it = pData->windows.begin(); it != pData->windows.end(); ++it) { Window* const window(*it); window->idle(); @@ -43,7 +57,7 @@ void App::idle() void App::exec() { - while (pData->fDoLoop) + while (pData->doLoop) { idle(); msleep(10); @@ -52,18 +66,44 @@ void App::exec() void App::quit() { - pData->fDoLoop = false; + pData->doLoop = false; - for (std::list::iterator it = pData->fWindows.begin(); it != pData->fWindows.end(); ++it) + for (std::list::reverse_iterator rit = pData->windows.rbegin(); rit != pData->windows.rend(); ++rit) { - Window* const window(*it); + Window* const window(*rit); window->close(); } } bool App::isQuiting() const { - return !pData->fDoLoop; + return !pData->doLoop; +} + +// ----------------------------------------------------------------------- + +void App::addWindow(Window* const window) +{ + if (window != nullptr) + pData->windows.push_back(window); +} + +void App::removeWindow(Window* const window) +{ + if (window != nullptr) + pData->windows.remove(window); +} + +void App::oneShown() +{ + if (++pData->visibleWindows == 1) + pData->doLoop = true; +} + +void App::oneHidden() +{ + if (--pData->visibleWindows == 0) + pData->doLoop = false; } // ----------------------------------------------------------------------- diff --git a/source/modules/distrho/dgl/src/AppPrivate.hpp b/source/modules/distrho/dgl/src/Base.cpp similarity index 53% rename from source/modules/distrho/dgl/src/AppPrivate.hpp rename to source/modules/distrho/dgl/src/Base.cpp index 12309e873..981c63450 100644 --- a/source/modules/distrho/dgl/src/AppPrivate.hpp +++ b/source/modules/distrho/dgl/src/Base.cpp @@ -14,68 +14,36 @@ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#ifndef DGL_APP_PRIVATE_HPP_INCLUDED -#define DGL_APP_PRIVATE_HPP_INCLUDED +#include "../Base.hpp" -#include "../App.hpp" - -#include +#if DGL_OS_WINDOWS +# include +#else +# include +#endif START_NAMESPACE_DGL // ----------------------------------------------------------------------- -class Window; - -class App::PrivateData +void sleep(unsigned int secs) { -public: - Private() - : fDoLoop(true), - fVisibleWindows(0) - { - } - - ~Private() - { - fWindows.clear(); - } - - void addWindow(Window* const window) - { - if (window != nullptr) - fWindows.push_back(window); - } - - void removeWindow(Window* const window) - { - if (window != nullptr) - fWindows.remove(window); - } - - void oneShown() - { - if (++fVisibleWindows == 1) - fDoLoop = true; - } - - void oneHidden() - { - if (--fVisibleWindows == 0) - fDoLoop = false; - } - -private: - bool fDoLoop; - unsigned fVisibleWindows; - - std::list fWindows; - - friend class App; -}; +#ifdef DGL_OS_WINDOWS + ::Sleep(secs * 1000); +#else + ::sleep(secs); +#endif +} + +void msleep(unsigned int msecs) +{ +#ifdef DGL_OS_WINDOWS + ::Sleep(msecs); +#else + ::usleep(msecs * 1000); +#endif +} // ----------------------------------------------------------------------- END_NAMESPACE_DGL - -#endif // DGL_APP_PRIVATE_HPP_INCLUDED diff --git a/source/modules/distrho/dgl/src/Geometry.cpp b/source/modules/distrho/dgl/src/Geometry.cpp index aa0004b46..2e4d61052 100644 --- a/source/modules/distrho/dgl/src/Geometry.cpp +++ b/source/modules/distrho/dgl/src/Geometry.cpp @@ -22,66 +22,66 @@ START_NAMESPACE_DGL // Point template -Point::Point() +Point::Point() noexcept : fX(0), fY(0) { } template -Point::Point(T x, T y) +Point::Point(T x, T y) noexcept : fX(x), fY(y) { } template -Point::Point(const Point& pos) +Point::Point(const Point& pos) noexcept : fX(pos.fX), fY(pos.fY) { } template -T Point::getX() const +T Point::getX() const noexcept { return fX; } template -T Point::getY() const +T Point::getY() const noexcept { return fY; } template -void Point::setX(T x) +void Point::setX(T x) noexcept { fX = x; } template -void Point::setY(T y) +void Point::setY(T y) noexcept { fY = y; } template -void Point::move(T x, T y) +void Point::move(T x, T y) noexcept { fX += x; fY += y; } template -void Point::move(const Point& pos) +void Point::move(const Point& pos) noexcept { fX += pos.fX; fY += pos.fY; } template -Point& Point::operator=(const Point& pos) +Point& Point::operator=(const Point& pos) noexcept { fX = pos.fX; fY = pos.fY; @@ -89,7 +89,7 @@ Point& Point::operator=(const Point& pos) } template -Point& Point::operator+=(const Point& pos) +Point& Point::operator+=(const Point& pos) noexcept { fX += pos.fX; fY += pos.fY; @@ -97,7 +97,7 @@ Point& Point::operator+=(const Point& pos) } template -Point& Point::operator-=(const Point& pos) +Point& Point::operator-=(const Point& pos) noexcept { fX -= pos.fX; fY -= pos.fY; @@ -105,13 +105,13 @@ Point& Point::operator-=(const Point& pos) } template -bool Point::operator==(const Point& pos) const +bool Point::operator==(const Point& pos) const noexcept { return (fX == pos.fX && fY== pos.fY); } template -bool Point::operator!=(const Point& pos) const +bool Point::operator!=(const Point& pos) const noexcept { return !operator==(pos); } @@ -120,52 +120,52 @@ bool Point::operator!=(const Point& pos) const // Size template -Size::Size() +Size::Size() noexcept : fWidth(0), fHeight(0) { } template -Size::Size(T width, T height) +Size::Size(T width, T height) noexcept : fWidth(width), fHeight(height) { } template -Size::Size(const Size& size) +Size::Size(const Size& size) noexcept : fWidth(size.fWidth), fHeight(size.fHeight) { } template -T Size::getWidth() const +T Size::getWidth() const noexcept { return fWidth; } template -T Size::getHeight() const +T Size::getHeight() const noexcept { return fHeight; } template -void Size::setWidth(T width) +void Size::setWidth(T width) noexcept { fWidth = width; } template -void Size::setHeight(T height) +void Size::setHeight(T height) noexcept { fHeight = height; } template -Size& Size::operator=(const Size& size) +Size& Size::operator=(const Size& size) noexcept { fWidth = size.fWidth; fHeight = size.fHeight; @@ -173,7 +173,7 @@ Size& Size::operator=(const Size& size) } template -Size& Size::operator+=(const Size& size) +Size& Size::operator+=(const Size& size) noexcept { fWidth += size.fWidth; fHeight += size.fHeight; @@ -181,7 +181,7 @@ Size& Size::operator+=(const Size& size) } template -Size& Size::operator-=(const Size& size) +Size& Size::operator-=(const Size& size) noexcept { fWidth -= size.fWidth; fHeight -= size.fHeight; @@ -189,7 +189,7 @@ Size& Size::operator-=(const Size& size) } template -Size& Size::operator*=(T m) +Size& Size::operator*=(T m) noexcept { fWidth *= m; fHeight *= m; @@ -197,7 +197,7 @@ Size& Size::operator*=(T m) } template -Size& Size::operator/=(T d) +Size& Size::operator/=(T d) noexcept { fWidth /= d; fHeight /= d; @@ -205,13 +205,13 @@ Size& Size::operator/=(T d) } template -bool Size::operator==(const Size& size) const +bool Size::operator==(const Size& size) const noexcept { return (fWidth == size.fWidth && fHeight == size.fHeight); } template -bool Size::operator!=(const Size& size) const +bool Size::operator!=(const Size& size) const noexcept { return !operator==(size); } @@ -220,172 +220,172 @@ bool Size::operator!=(const Size& size) const // Rectangle template -Rectangle::Rectangle() +Rectangle::Rectangle() noexcept : fPos(0, 0), fSize(0, 0) { } template -Rectangle::Rectangle(T x, T y, T width, T height) +Rectangle::Rectangle(T x, T y, T width, T height) noexcept : fPos(x, y), fSize(width, height) { } template -Rectangle::Rectangle(T x, T y, const Size& size) +Rectangle::Rectangle(T x, T y, const Size& size) noexcept : fPos(x, y), fSize(size) { } template -Rectangle::Rectangle(const Point& pos, T width, T height) +Rectangle::Rectangle(const Point& pos, T width, T height) noexcept : fPos(pos), fSize(width, height) { } template -Rectangle::Rectangle(const Point& pos, const Size& size) +Rectangle::Rectangle(const Point& pos, const Size& size) noexcept : fPos(pos), fSize(size) { } template -Rectangle::Rectangle(const Rectangle& rect) +Rectangle::Rectangle(const Rectangle& rect) noexcept : fPos(rect.fPos), fSize(rect.fSize) { } template -T Rectangle::getX() const +T Rectangle::getX() const noexcept { return fPos.fX; } template -T Rectangle::getY() const +T Rectangle::getY() const noexcept { return fPos.fY; } template -T Rectangle::getWidth() const +T Rectangle::getWidth() const noexcept { return fSize.fWidth; } template -T Rectangle::getHeight() const +T Rectangle::getHeight() const noexcept { return fSize.fHeight; } template -const Point& Rectangle::getPos() const +const Point& Rectangle::getPos() const noexcept { return fPos; } template -const Size& Rectangle::getSize() const +const Size& Rectangle::getSize() const noexcept { return fSize; } template -bool Rectangle::contains(T x, T y) const +bool Rectangle::contains(T x, T y) const noexcept { return (x >= fPos.fX && y >= fPos.fY && x <= fPos.fX+fSize.fWidth && y <= fPos.fY+fSize.fHeight); } template -bool Rectangle::contains(const Point& pos) const +bool Rectangle::contains(const Point& pos) const noexcept { return contains(pos.fX, pos.fY); } template -bool Rectangle::containsX(T x) const +bool Rectangle::containsX(T x) const noexcept { return (x >= fPos.fX && x <= fPos.fX + fSize.fWidth); } template -bool Rectangle::containsY(T y) const +bool Rectangle::containsY(T y) const noexcept { return (y >= fPos.fY && y <= fPos.fY + fSize.fHeight); } template -void Rectangle::setX(T x) +void Rectangle::setX(T x) noexcept { fPos.fX = x; } template -void Rectangle::setY(T y) +void Rectangle::setY(T y) noexcept { fPos.fY = y; } template -void Rectangle::setPos(T x, T y) +void Rectangle::setPos(T x, T y) noexcept { fPos.fX = x; fPos.fY = y; } template -void Rectangle::setPos(const Point& pos) +void Rectangle::setPos(const Point& pos) noexcept { fPos = pos; } template -void Rectangle::move(T x, T y) +void Rectangle::move(T x, T y) noexcept { fPos.fX += x; fPos.fY += y; } template -void Rectangle::move(const Point& pos) +void Rectangle::move(const Point& pos) noexcept { fPos += pos; } template -void Rectangle::setWidth(T width) +void Rectangle::setWidth(T width) noexcept { fSize.fWidth = width; } template -void Rectangle::setHeight(T height) +void Rectangle::setHeight(T height) noexcept { fSize.fHeight = height; } template -void Rectangle::setSize(T width, T height) +void Rectangle::setSize(T width, T height) noexcept { fSize.fWidth = width; fSize.fHeight = height; } template -void Rectangle::setSize(const Size& size) +void Rectangle::setSize(const Size& size) noexcept { fSize = size; } template -Rectangle& Rectangle::operator=(const Rectangle& rect) +Rectangle& Rectangle::operator=(const Rectangle& rect) noexcept { fPos = rect.fPos; fSize = rect.fSize; diff --git a/source/modules/distrho/dgl/src/Image.cpp b/source/modules/distrho/dgl/src/Image.cpp index 601f443bf..1ef9e6fe2 100644 --- a/source/modules/distrho/dgl/src/Image.cpp +++ b/source/modules/distrho/dgl/src/Image.cpp @@ -20,7 +20,7 @@ START_NAMESPACE_DGL // ----------------------------------------------------------------------- -Image::Image() +Image::Image() noexcept : fRawData(nullptr), fSize(0, 0), fFormat(0), @@ -28,7 +28,7 @@ Image::Image() { } -Image::Image(const char* rawData, int width, int height, GLenum format, GLenum type) +Image::Image(const char* rawData, int width, int height, GLenum format, GLenum type) noexcept : fRawData(rawData), fSize(width, height), fFormat(format), @@ -36,7 +36,7 @@ Image::Image(const char* rawData, int width, int height, GLenum format, GLenum t { } -Image::Image(const char* rawData, const Size& size, GLenum format, GLenum type) +Image::Image(const char* rawData, const Size& size, GLenum format, GLenum type) noexcept : fRawData(rawData), fSize(size), fFormat(format), @@ -44,7 +44,7 @@ Image::Image(const char* rawData, const Size& size, GLenum format, GLenum t { } -Image::Image(const Image& image) +Image::Image(const Image& image) noexcept : fRawData(image.fRawData), fSize(image.fSize), fFormat(image.fFormat), @@ -52,12 +52,12 @@ Image::Image(const Image& image) { } -void Image::loadFromMemory(const char* rawData, int width, int height, GLenum format, GLenum type) +void Image::loadFromMemory(const char* rawData, int width, int height, GLenum format, GLenum type) noexcept { loadFromMemory(rawData, Size(width, height), format, type); } -void Image::loadFromMemory(const char* rawData, const Size& size, GLenum format, GLenum type) +void Image::loadFromMemory(const char* rawData, const Size& size, GLenum format, GLenum type) noexcept { fRawData = rawData; fSize = size; @@ -65,37 +65,37 @@ void Image::loadFromMemory(const char* rawData, const Size& size, GLenum fo fType = type; } -bool Image::isValid() const +bool Image::isValid() const noexcept { return (fRawData != nullptr && getWidth() > 0 && getHeight() > 0); } -int Image::getWidth() const +int Image::getWidth() const noexcept { return fSize.getWidth(); } -int Image::getHeight() const +int Image::getHeight() const noexcept { return fSize.getHeight(); } -const Size& Image::getSize() const +const Size& Image::getSize() const noexcept { return fSize; } -const char* Image::getRawData() const +const char* Image::getRawData() const noexcept { return fRawData; } -GLenum Image::getFormat() const +GLenum Image::getFormat() const noexcept { return fFormat; } -GLenum Image::getType() const +GLenum Image::getType() const noexcept { return fType; } @@ -121,7 +121,7 @@ void Image::draw(const Point& pos) const draw(pos.getX(), pos.getY()); } -Image& Image::operator=(const Image& image) +Image& Image::operator=(const Image& image) noexcept { fRawData = image.fRawData; fSize = image.fSize; @@ -130,12 +130,12 @@ Image& Image::operator=(const Image& image) return *this; } -bool Image::operator==(const Image& image) const +bool Image::operator==(const Image& image) const noexcept { return (fRawData == image.fRawData); } -bool Image::operator!=(const Image& image) const +bool Image::operator!=(const Image& image) const noexcept { return (fRawData != image.fRawData); } diff --git a/source/modules/distrho/dgl/src/ImageAboutWindow.cpp b/source/modules/distrho/dgl/src/ImageAboutWindow.cpp index e234555e6..ba03eabb0 100644 --- a/source/modules/distrho/dgl/src/ImageAboutWindow.cpp +++ b/source/modules/distrho/dgl/src/ImageAboutWindow.cpp @@ -27,22 +27,22 @@ START_NAMESPACE_DGL // ----------------------------------------------------------------------- -ImageAboutWindow::ImageAboutWindow(App* app, Window* parent, const Image& image) +ImageAboutWindow::ImageAboutWindow(App& app, Window& parent, const Image& image) : Window(app, parent), - Widget(this), + Widget((Window&)*this), fImgBackground(image) { Window::setSize(image.getWidth(), image.getHeight() PAD_SIZE); - Window::setWindowTitle("About"); + Window::setTitle("About"); } ImageAboutWindow::ImageAboutWindow(Widget* widget, const Image& image) - : Window(widget->getApp(), widget->getParent()), - Widget(this), + : Window(widget->getParentApp(), widget->getParentWindow()), + Widget((Window&)*this), fImgBackground(image) { Window::setSize(image.getWidth(), image.getHeight() PAD_SIZE); - Window::setWindowTitle("About"); + Window::setTitle("About"); } void ImageAboutWindow::setImage(const Image& image) @@ -69,7 +69,7 @@ bool ImageAboutWindow::onMouse(int, bool press, int, int) bool ImageAboutWindow::onKeyboard(bool press, uint32_t key) { - if (press && key == DGL_CHAR_ESCAPE) + if (press && key == CHAR_ESCAPE) { Window::close(); return true; diff --git a/source/modules/distrho/dgl/src/ImageButton.cpp b/source/modules/distrho/dgl/src/ImageButton.cpp index 135101cfd..b3f678008 100644 --- a/source/modules/distrho/dgl/src/ImageButton.cpp +++ b/source/modules/distrho/dgl/src/ImageButton.cpp @@ -22,7 +22,7 @@ START_NAMESPACE_DGL // ----------------------------------------------------------------------- -ImageButton::ImageButton(Window* parent, const Image& image) +ImageButton::ImageButton(Window& parent, const Image& image) : Widget(parent), fImageNormal(image), fImageHover(image), @@ -34,7 +34,7 @@ ImageButton::ImageButton(Window* parent, const Image& image) } ImageButton::ImageButton(Widget* widget, const Image& image) - : Widget(widget->getParent()), + : Widget(widget->getParentWindow()), fImageNormal(image), fImageHover(image), fImageDown(image), @@ -44,7 +44,7 @@ ImageButton::ImageButton(Widget* widget, const Image& image) { } -ImageButton::ImageButton(Window* parent, const Image& imageNormal, const Image& imageHover, const Image& imageDown) +ImageButton::ImageButton(Window& parent, const Image& imageNormal, const Image& imageHover, const Image& imageDown) : Widget(parent), fImageNormal(imageNormal), fImageHover(imageHover), @@ -59,7 +59,7 @@ ImageButton::ImageButton(Window* parent, const Image& imageNormal, const Image& } ImageButton::ImageButton(Widget* widget, const Image& imageNormal, const Image& imageHover, const Image& imageDown) - : Widget(widget->getParent()), + : Widget(widget->getParentWindow()), fImageNormal(imageNormal), fImageHover(imageHover), fImageDown(imageDown), @@ -73,7 +73,7 @@ ImageButton::ImageButton(Widget* widget, const Image& imageNormal, const Image& } ImageButton::ImageButton(const ImageButton& imageButton) - : Widget(imageButton.getParent()), + : Widget(imageButton.getParentWindow()), fImageNormal(imageButton.fImageNormal), fImageHover(imageButton.fImageHover), fImageDown(imageButton.fImageDown), diff --git a/source/modules/distrho/dgl/src/ImageKnob.cpp b/source/modules/distrho/dgl/src/ImageKnob.cpp index 669c01bcd..12447eec9 100644 --- a/source/modules/distrho/dgl/src/ImageKnob.cpp +++ b/source/modules/distrho/dgl/src/ImageKnob.cpp @@ -23,7 +23,7 @@ START_NAMESPACE_DGL // ----------------------------------------------------------------------- -ImageKnob::ImageKnob(Window* parent, const Image& image, Orientation orientation) +ImageKnob::ImageKnob(Window& parent, const Image& image, Orientation orientation) : Widget(parent), fImage(image), fMinimum(0.0f), @@ -45,7 +45,7 @@ ImageKnob::ImageKnob(Window* parent, const Image& image, Orientation orientation } ImageKnob::ImageKnob(Widget* widget, const Image& image, Orientation orientation) - : Widget(widget->getParent()), + : Widget(widget->getParentWindow()), fImage(image), fMinimum(0.0f), fMaximum(1.0f), @@ -66,7 +66,7 @@ ImageKnob::ImageKnob(Widget* widget, const Image& image, Orientation orientation } ImageKnob::ImageKnob(const ImageKnob& imageKnob) - : Widget(imageKnob.getParent()), + : Widget(imageKnob.getParentWindow()), fImage(imageKnob.fImage), fMinimum(imageKnob.fMinimum), fMaximum(imageKnob.fMaximum), @@ -286,7 +286,7 @@ bool ImageKnob::onMotion(int x, int y) if (movX != 0) { - float d = (getModifiers() & DGL_MODIFIER_SHIFT) ? 2000.0f : 200.0f; + float d = (getModifiers() & MODIFIER_SHIFT) ? 2000.0f : 200.0f; float value = fValue + (float(fMaximum - fMinimum) / d * float(movX)); if (value < fMinimum) @@ -303,7 +303,7 @@ bool ImageKnob::onMotion(int x, int y) if (movY != 0) { - float d = (getModifiers() & DGL_MODIFIER_SHIFT) ? 2000.0f : 200.0f; + float d = (getModifiers() & MODIFIER_SHIFT) ? 2000.0f : 200.0f; float value = fValue + (float(fMaximum - fMinimum) / d * float(movY)); if (value < fMinimum) diff --git a/source/modules/distrho/dgl/src/ImageSlider.cpp b/source/modules/distrho/dgl/src/ImageSlider.cpp index cc602ed59..4558cccf2 100644 --- a/source/modules/distrho/dgl/src/ImageSlider.cpp +++ b/source/modules/distrho/dgl/src/ImageSlider.cpp @@ -20,7 +20,7 @@ START_NAMESPACE_DGL // ----------------------------------------------------------------------- -ImageSlider::ImageSlider(Window* parent, const Image& image) +ImageSlider::ImageSlider(Window& parent, const Image& image) : Widget(parent), fImage(image), fMinimum(0.0f), @@ -36,7 +36,7 @@ ImageSlider::ImageSlider(Window* parent, const Image& image) } ImageSlider::ImageSlider(Widget* widget, const Image& image) - : Widget(widget->getParent()), + : Widget(widget->getParentWindow()), fImage(image), fMinimum(0.0f), fMaximum(1.0f), @@ -51,7 +51,7 @@ ImageSlider::ImageSlider(Widget* widget, const Image& image) } ImageSlider::ImageSlider(const ImageSlider& imageSlider) - : Widget(imageSlider.getParent()), + : Widget(imageSlider.getParentWindow()), fImage(imageSlider.fImage), fMinimum(imageSlider.fMinimum), fMaximum(imageSlider.fMaximum), diff --git a/source/modules/distrho/dgl/src/Widget.cpp b/source/modules/distrho/dgl/src/Widget.cpp index 4259967e2..024929f74 100644 --- a/source/modules/distrho/dgl/src/Widget.cpp +++ b/source/modules/distrho/dgl/src/Widget.cpp @@ -20,12 +20,6 @@ #include -#ifdef PROPER_CPP11_SUPPORT -# include -#else -# include -#endif - START_NAMESPACE_DGL // ----------------------------------------------------------------------- @@ -35,7 +29,7 @@ Widget::Widget(Window& parent) : fParent(parent), fVisible(true) { - parent.addWidget(this); + fParent.addWidget(this); } Widget::~Widget() @@ -43,7 +37,7 @@ Widget::~Widget() fParent.removeWidget(this); } -bool Widget::isVisible() const +bool Widget::isVisible() const noexcept { return fVisible; } @@ -57,17 +51,27 @@ void Widget::setVisible(bool yesNo) fParent.repaint(); } -int Widget::getX() const +void Widget::show() +{ + setVisible(true); +} + +void Widget::hide() +{ + setVisible(false); +} + +int Widget::getX() const noexcept { return fArea.getX(); } -int Widget::getY() const +int Widget::getY() const noexcept { return fArea.getY(); } -const Point& Widget::getPos() const +const Point& Widget::getPos() const noexcept { return fArea.getPos(); } @@ -78,7 +82,7 @@ void Widget::setX(int x) return; fArea.setX(x); - repaint(); + fParent.repaint(); } void Widget::setY(int y) @@ -87,7 +91,7 @@ void Widget::setY(int y) return; fArea.setY(y); - repaint(); + fParent.repaint(); } void Widget::setPos(int x, int y) @@ -101,32 +105,32 @@ void Widget::setPos(const Point& pos) return; fArea.setPos(pos); - repaint(); + fParent.repaint(); } void Widget::move(int x, int y) { fArea.move(x, y); - repaint(); + fParent.repaint(); } void Widget::move(const Point& pos) { fArea.move(pos); - repaint(); + fParent.repaint(); } -int Widget::getWidth() const +int Widget::getWidth() const noexcept { return fArea.getWidth(); } -int Widget::getHeight() const +int Widget::getHeight() const noexcept { return fArea.getHeight(); } -const Size& Widget::getSize() const +const Size& Widget::getSize() const noexcept { return fArea.getSize(); } @@ -163,22 +167,27 @@ void Widget::setSize(const Size& size) fParent.repaint(); } -const Rectangle& Widget::getArea() const +const Rectangle& Widget::getArea() const noexcept { return fArea; } +uint32_t Widget::getEventTimestamp() +{ + return fParent.getEventTimestamp(); +} + int Widget::getModifiers() { return fParent.getModifiers(); } -App& Widget::getApp() const +App& Widget::getParentApp() const noexcept { return fParent.getApp(); } -Window& Widget::getParent() const +Window& Widget::getParentWindow() const noexcept { return fParent; } @@ -192,7 +201,7 @@ void Widget::onDisplay() { } -bool Widget::onKeyboard(bool, unsigned) +bool Widget::onKeyboard(bool, uint32_t) { return false; } diff --git a/source/modules/distrho/dgl/src/Window.cpp b/source/modules/distrho/dgl/src/Window.cpp index 4c2ac1646..767d42034 100644 --- a/source/modules/distrho/dgl/src/Window.cpp +++ b/source/modules/distrho/dgl/src/Window.cpp @@ -14,11 +14,13 @@ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#include "AppPrivate.hpp" - +#include "../App.hpp" #include "../Widget.hpp" #include "../Window.hpp" +#include +#include + #include "pugl/pugl.h" #if DGL_OS_WINDOWS @@ -32,11 +34,9 @@ extern "C" { # include "pugl/pugl_x11.c" } #else -# error Unsupported platform! +# error Unsupported platform #endif -#include - #define FOR_EACH_WIDGET(it) \ for (std::list::iterator it = fWidgets.begin(); it != fWidgets.end(); ++it) @@ -53,15 +53,58 @@ Window* dgl_lastUiParent = nullptr; class Window::PrivateData { public: - Private(Window& self, App& app, App::PrivateData& appPriv, PrivateData& parent, intptr_t parentId = 0) - : kApp(app), - kAppPriv(appPriv), - kSelf(self), - kView(puglCreate(parentId, "Window", 100, 100, false, (parentId != 0))), - fParent(parent), - fChildFocus(nullptr), - fVisible((parentId != 0)), - fOnModal(false), + PrivateData(App& app, Window* const self) + : fApp(app), + fSelf(self), + fView(puglCreate(0, "Window", 100, 100, true, false)), + fFirstInit(true), + fVisible(false), + fResizable(true), +#if DGL_OS_WINDOWS + hwnd(0) +#elif DGL_OS_LINUX + xDisplay(nullptr), + xWindow(0) +#else + _dummy('\0') +#endif + { + init(); + } + + PrivateData(App& app, Window* const self, Window& parent) + : fApp(app), + fSelf(self), + fView(puglCreate(0, "Window", 100, 100, true, false)), + fFirstInit(true), + fVisible(false), + fResizable(true), + fModal(parent.pData), +#if DGL_OS_WINDOWS + hwnd(0) +#elif DGL_OS_LINUX + xDisplay(nullptr), + xWindow(0) +#else + _dummy('\0') +#endif + { + init(); + +#if DGL_OS_LINUX + PuglInternals* const parentImpl = parent.pData->fView->impl; + + XSetTransientForHint(xDisplay, xWindow, parentImpl->win); + XFlush(xDisplay); +#endif + } + + PrivateData(App& app, Window* const self, const intptr_t parentId) + : fApp(app), + fSelf(self), + fView(puglCreate(parentId, "Window", 100, 100, true, true)), + fFirstInit(true), + fVisible(true), fResizable(false), #if DGL_OS_WINDOWS hwnd(0) @@ -69,118 +112,85 @@ public: xDisplay(nullptr), xWindow(0) #else - _dummy(0) + _dummy('\0') #endif { + init(); + + // starts visible + fApp.oneShown(); + fFirstInit = false; } - void setup() + void init() { - if (kView == nullptr) + if (fView == nullptr) return; - // we can't have both - if (parent != nullptr) - { - assert(parentId == 0); - } + dgl_lastUiParent = fSelf; - puglSetHandle(kView, this); - puglSetDisplayFunc(kView, onDisplayCallback); - puglSetKeyboardFunc(kView, onKeyboardCallback); - puglSetMotionFunc(kView, onMotionCallback); - puglSetMouseFunc(kView, onMouseCallback); - puglSetScrollFunc(kView, onScrollCallback); - puglSetSpecialFunc(kView, onSpecialCallback); - puglSetReshapeFunc(kView, onReshapeCallback); - puglSetCloseFunc(kView, onCloseCallback); + puglSetHandle(fView, this); + puglSetDisplayFunc(fView, onDisplayCallback); + puglSetKeyboardFunc(fView, onKeyboardCallback); + puglSetMotionFunc(fView, onMotionCallback); + puglSetMouseFunc(fView, onMouseCallback); + puglSetScrollFunc(fView, onScrollCallback); + puglSetSpecialFunc(fView, onSpecialCallback); + puglSetReshapeFunc(fView, onReshapeCallback); + puglSetCloseFunc(fView, onCloseCallback); #if DGL_OS_WINDOWS - PuglInternals* impl = kView->impl; + PuglInternals* impl = fView->impl; hwnd = impl->hwnd; #elif DGL_OS_LINUX - PuglInternals* impl = kView->impl; + PuglInternals* impl = fView->impl; xDisplay = impl->display; xWindow = impl->win; - - if (parent != nullptr && parentId == 0) - { - PuglInternals* parentImpl = parent->kView->impl; - - XSetTransientForHint(xDisplay, xWindow, parentImpl->win); - XFlush(xDisplay); - } #endif - kAppPriv->addWindow(kSelf); + fApp.addWindow(fSelf); } - ~Private() + ~PrivateData() { - fOnModal = false; + //fOnModal = false; fWidgets.clear(); - if (kView != nullptr) + if (fView != nullptr) { - kAppPriv->removeWindow(kSelf); - puglDestroy(kView); + fApp.removeWindow(fSelf); + puglDestroy(fView); } } - void exec_init() + // ------------------------------------------------------------------- + + void close() { - fOnModal = true; - assert(fParent != nullptr); + setVisible(false); - if (fParent != nullptr) + if (! fFirstInit) { - fParent->fChildFocus = this; - -#if DGL_OS_WINDOWS - // Center this window - PuglInternals* parentImpl = fParent->kView->impl; - - RECT curRect; - RECT parentRect; - GetWindowRect(hwnd, &curRect); - GetWindowRect(parentImpl->hwnd, &parentRect); - - int x = parentRect.left+(parentRect.right-curRect.right)/2; - int y = parentRect.top+(parentRect.bottom-curRect.bottom)/2; - - SetWindowPos(hwnd, 0, x, y, 0, 0, SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOSIZE|SWP_NOZORDER); - UpdateWindow(hwnd); -#endif - - fParent->show(); + fApp.oneHidden(); + fFirstInit = true; } - - show(); - } - - void exec_fini() - { - fOnModal = false; - - if (fParent != nullptr) - fParent->fChildFocus = nullptr; } - void exec(bool block) + void exec(const bool lockWait) { exec_init(); - if (block) + if (lockWait) { - while (fVisible && fOnModal) + while (fVisible && fModal.enabled) { // idle() - puglProcessEvents(kView); + puglProcessEvents(fView); - if (fParent != nullptr) - fParent->idle(); + if (fModal.parent != nullptr) + fModal.parent->idle(); - dgl_msleep(10); + msleep(10); } exec_fini(); @@ -191,6 +201,8 @@ public: } } + // ------------------------------------------------------------------- + void focus() { #if DGL_OS_WINDOWS @@ -198,7 +210,7 @@ public: SetActiveWindow(hwnd); SetFocus(hwnd); #elif DGL_OS_MAC - puglImplFocus(kView); + puglImplFocus(fView); #elif DGL_OS_LINUX XRaiseWindow(xDisplay, xWindow); XSetInputFocus(xDisplay, xWindow, RevertToPointerRoot, CurrentTime); @@ -208,60 +220,41 @@ public: void idle() { - puglProcessEvents(kView); + puglProcessEvents(fView); - if (fVisible && fOnModal && fParent != nullptr) - fParent->idle(); + if (fVisible && fModal.enabled && fModal.parent != nullptr) + fModal.parent->idle(); } void repaint() { - puglPostRedisplay(kView); - } - - void show() - { - setVisible(true); + puglPostRedisplay(fView); } - void hide() - { - setVisible(false); - } - - void close() - { - setVisible(false, true); - } + // ------------------------------------------------------------------- - bool isVisible() + bool isVisible() const noexcept { return fVisible; } - void setResizable(bool yesNo) - { - if (fResizable == yesNo) - return; - - fResizable = yesNo; - - //setSize(kView->width, kView->height, true); - } - - void setVisible(bool yesNo, bool closed = false) + void setVisible(const bool yesNo) { if (fVisible == yesNo) return; fVisible = yesNo; + if (yesNo && fFirstInit) + setSize(fView->width, fView->height, true); + #if DGL_OS_WINDOWS if (yesNo) { ShowWindow(hwnd, WS_VISIBLE); - ShowWindow(hwnd, SW_RESTORE); - //SetForegroundWindow(hwnd); + + if (! fFirstInit) + ShowWindow(hwnd, SW_RESTORE); } else { @@ -270,7 +263,7 @@ public: UpdateWindow(hwnd); #elif DGL_OS_MAC - puglImplSetVisible(kView, yesNo); + puglImplSetVisible(fView, yesNo); #elif DGL_OS_LINUX if (yesNo) XMapRaised(xDisplay, xWindow); @@ -282,30 +275,62 @@ public: if (yesNo) { - kAppPriv->oneShown(); + if (fFirstInit) + { + fApp.oneShown(); + fFirstInit = false; + } } - else - { - if (fOnModal) - exec_fini(); + else if (fModal.enabled) + exec_fini(); + } - if (closed) - kAppPriv->oneHidden(); - } + // ------------------------------------------------------------------- + + bool isResizable() const noexcept + { + return fResizable; + } + + void setResizable(const bool yesNo) + { + if (fResizable == yesNo) + return; + + fResizable = yesNo; + + setSize(fView->width, fView->height, true); + } + + // ------------------------------------------------------------------- + + int getWidth() const noexcept + { + return fView->width; + } + + int getHeight() const noexcept + { + return fView->height; + } + + Size getSize() const noexcept + { + return Size(fView->width, fView->height); } - void setSize(unsigned int width, unsigned int height /*, bool forced = false*/) + void setSize(unsigned int width, unsigned int height, const bool forced = false) { if (width == 0) width = 1; if (height == 0) height = 1; - kView->width = width; - kView->height = height; + fView->width = width; + fView->height = height; - //if (kView->width == width && kView->height == height && ! forced) - // return; + if (fView->width == (int)width && fView->height == (int)height && ! forced) + return; #if DGL_OS_WINDOWS int winFlags = WS_POPUPWINDOW | WS_CAPTION; @@ -319,7 +344,7 @@ public: SetWindowPos(hwnd, 0, 0, 0, wr.right-wr.left, wr.bottom-wr.top, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOOWNERZORDER|SWP_NOZORDER); UpdateWindow(hwnd); #elif DGL_OS_MAC - puglImplSetSize(kView, width, height); + puglImplSetSize(fView, width, height); #elif DGL_OS_LINUX XResizeWindow(xDisplay, xWindow, width, height); @@ -343,43 +368,94 @@ public: repaint(); } - void setWindowTitle(const char* title) + // ------------------------------------------------------------------- + + void setTitle(const char* const title) { #if DGL_OS_WINDOWS SetWindowTextA(hwnd, title); #elif DGL_OS_MAC - puglImplSetTitle(kView, title); + puglImplSetTitle(fView, title); #elif DGL_OS_LINUX XStoreName(xDisplay, xWindow, title); XFlush(xDisplay); #endif } - App* getApp() const + App& getApp() const noexcept { - return kApp; + return fApp; } int getModifiers() const { - return puglGetModifiers(kView); + return puglGetModifiers(fView); + } + + uint32_t getEventTimestamp() const + { + return puglGetEventTimestamp(fView); } intptr_t getWindowId() const { - return puglGetNativeWindow(kView); + return puglGetNativeWindow(fView); } - void addWidget(Widget* widget) + // ------------------------------------------------------------------- + + void addWidget(Widget* const widget) { fWidgets.push_back(widget); } - void removeWidget(Widget* widget) + void removeWidget(Widget* const widget) { fWidgets.remove(widget); } + // ------------------------------------------------------------------- + + void exec_init() + { + fModal.enabled = true; + assert(fModal.parent != nullptr); + + if (fModal.parent == nullptr) + return setVisible(true); + + fModal.parent->fModal.childFocus = this; + +#if DGL_OS_WINDOWS + // Center this window + PuglInternals* const parentImpl = fParent->fView->impl; + + RECT curRect; + RECT parentRect; + GetWindowRect(hwnd, &curRect); + GetWindowRect(parentImpl->hwnd, &parentRect); + + int x = parentRect.left+(parentRect.right-curRect.right)/2; + int y = parentRect.top +(parentRect.bottom-curRect.bottom)/2; + + SetWindowPos(hwnd, 0, x, y, 0, 0, SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOSIZE|SWP_NOZORDER); + UpdateWindow(hwnd); +#endif + + fModal.parent->setVisible(true); + setVisible(true); + } + + void exec_fini() + { + fModal.enabled = false; + + if (fModal.parent != nullptr) + fModal.parent->fModal.childFocus = nullptr; + } + + // ------------------------------------------------------------------- + protected: void onDisplay() { @@ -388,93 +464,85 @@ protected: FOR_EACH_WIDGET(it) { Widget* const widget(*it); + if (widget->isVisible()) widget->onDisplay(); } } - void onKeyboard(bool press, uint32_t key) + void onKeyboard(const bool press, const uint32_t key) { - if (fChildFocus != nullptr) - return fChildFocus->focus(); + if (fModal.childFocus != nullptr) + return fModal.childFocus->focus(); FOR_EACH_WIDGET_INV(rit) { Widget* const widget(*rit); - if (widget->isVisible()) - { - if (widget->onKeyboard(press, key)) - break; - } + + if (widget->isVisible() && widget->onKeyboard(press, key)) + break; } } - void onMouse(int button, bool press, int x, int y) + void onMouse(const int button, const bool press, const int x, const int y) { - if (fChildFocus != nullptr) - return fChildFocus->focus(); + if (fModal.childFocus != nullptr) + return fModal.childFocus->focus(); FOR_EACH_WIDGET_INV(rit) { Widget* const widget(*rit); - if (widget->isVisible()) - { - if (widget->onMouse(button, press, x, y)) - break; - } + + if (widget->isVisible() && widget->onMouse(button, press, x, y)) + break; } } - void onMotion(int x, int y) + void onMotion(const int x, const int y) { - if (fChildFocus != nullptr) + if (fModal.childFocus != nullptr) return; FOR_EACH_WIDGET_INV(rit) { Widget* const widget(*rit); - if (widget->isVisible()) - { - if (widget->onMotion(x, y)) - break; - } + + if (widget->isVisible() && widget->onMotion(x, y)) + break; } } - void onScroll(float dx, float dy) + void onScroll(const float dx, const float dy) { - if (fChildFocus != nullptr) + if (fModal.childFocus != nullptr) return; FOR_EACH_WIDGET_INV(rit) { Widget* const widget(*rit); - if (widget->isVisible()) - { - if (widget->onScroll(dx, dy)) - break; - } + + if (widget->isVisible() && widget->onScroll(dx, dy)) + break; } } - void onSpecial(bool press, Key key) + void onSpecial(const bool press, const Key key) { - if (fChildFocus != nullptr) + if (fModal.childFocus != nullptr) return; FOR_EACH_WIDGET_INV(rit) { Widget* const widget(*rit); - if (widget->isVisible()) - { - if (widget->onSpecial(press, key)) - break; - } + + if (widget->isVisible() && widget->onSpecial(press, key)) + break; } } - void onReshape(int width, int height) + void onReshape(const int width, const int height) { + printf("resized: %i:%i\n", width, height); FOR_EACH_WIDGET(it) { Widget* const widget(*it); @@ -484,10 +552,10 @@ protected: void onClose() { - fOnModal = false; + fModal.enabled = false; - if (fChildFocus != nullptr) - fChildFocus->onClose(); + if (fModal.childFocus != nullptr) + fModal.childFocus->onClose(); FOR_EACH_WIDGET(it) { @@ -498,31 +566,53 @@ protected: close(); } -private: - App* const kApp; - App::Private* const kAppPriv; - Window* const kSelf; - PuglView* const kView; + // ------------------------------------------------------------------- - Private* fParent; - Private* fChildFocus; - bool fVisible; - bool fOnModal; - bool fResizable; +private: + App& fApp; + Window* const fSelf; + PuglView* const fView; + bool fFirstInit; + bool fVisible; + bool fResizable; std::list fWidgets; + struct Modal { + bool enabled; + PrivateData* parent; + PrivateData* childFocus; + + Modal() + : enabled(false), + parent(nullptr), + childFocus(nullptr) {} + + Modal(PrivateData* const p) + : enabled(false), + parent(p), + childFocus(nullptr) {} + + ~Modal() + { + assert(! enabled); + assert(childFocus == nullptr); + } + } fModal; + #if DGL_OS_WINDOWS HWND hwnd; #elif DGL_OS_LINUX Display* xDisplay; ::Window xWindow; #else - int _dummy; + char _dummy; #endif + // ------------------------------------------------------------------- // Callbacks - #define handlePtr ((Private*)puglGetHandle(view)) + + #define handlePtr ((PrivateData*)puglGetHandle(view)) static void onDisplayCallback(PuglView* view) { @@ -571,21 +661,18 @@ private: // Window Window::Window(App& app) - : pData(new Private(this, app, app->pData, nullptr)) + : pData(new PrivateData(app, this)) { - dgl_lastUiParent = this; } Window::Window(App& app, Window& parent) - : pData(new Private(this, app, app->pData, parent->pData)) + : pData(new PrivateData(app, this, parent)) { - dgl_lastUiParent = this; } -Window::Window(App*&app, intptr_t parentId) - : pData(new Private(this, app, app->pData, nullptr, parentId)) +Window::Window(App& app, intptr_t parentId) + : pData(new PrivateData(app, this, parentId)) { - dgl_lastUiParent = this; } Window::~Window() @@ -593,9 +680,24 @@ Window::~Window() delete pData; } -void Window::exec(bool lock) +void Window::show() +{ + pData->setVisible(true); +} + +void Window::hide() +{ + pData->setVisible(false); +} + +void Window::close() { - pData->exec(lock); + pData->close(); +} + +void Window::exec(bool lockWait) +{ + pData->exec(lockWait); } void Window::focus() @@ -613,69 +715,79 @@ void Window::repaint() pData->repaint(); } -bool Window::isVisible() +bool Window::isVisible() const noexcept { return pData->isVisible(); } +void Window::setVisible(bool yesNo) +{ + pData->setVisible(yesNo); +} + +bool Window::isResizable() const noexcept +{ + return pData->isResizable(); +} + void Window::setResizable(bool yesNo) { pData->setResizable(yesNo); } -void Window::setVisible(bool yesNo) +int Window::getWidth() const noexcept { - pData->setVisible(yesNo); + return pData->getWidth(); } -void Window::setSize(unsigned int width, unsigned int height) +int Window::getHeight() const noexcept { - pData->setSize(width, height); + return pData->getHeight(); } -void Window::setWindowTitle(const char* title) +Size Window::getSize() const noexcept { - pData->setWindowTitle(title); + return pData->getSize(); } -App* Window::getApp() const +void Window::setSize(unsigned int width, unsigned int height) { - return pData->getApp(); + pData->setSize(width, height); } -int Window::getModifiers() const +void Window::setTitle(const char* title) { - return pData->getModifiers(); + pData->setTitle(title); } -intptr_t Window::getWindowId() const +App& Window::getApp() const noexcept { - return pData->getWindowId(); + return pData->getApp(); } -void Window::addWidget(Widget* widget) +int Window::getModifiers() const { - pData->addWidget(widget); + return pData->getModifiers(); } -void Window::removeWidget(Widget* widget) +uint32_t Window::getEventTimestamp() const { - pData->removeWidget(widget); + return pData->getEventTimestamp(); } -void Window::show() +intptr_t Window::getWindowId() const { - setVisible(true); + return pData->getWindowId(); } -void Window::hide() +void Window::addWidget(Widget* const widget) { - setVisible(false); + pData->addWidget(widget); } -void Window::close() +void Window::removeWidget(Widget* const widget) { - pData->close(); + pData->removeWidget(widget); } // ----------------------------------------------------------------------- diff --git a/source/modules/distrho/src/DistrhoUIDSSI.cpp b/source/modules/distrho/src/DistrhoUIDSSI.cpp index e274df48a..fba931850 100644 --- a/source/modules/distrho/src/DistrhoUIDSSI.cpp +++ b/source/modules/distrho/src/DistrhoUIDSSI.cpp @@ -17,7 +17,7 @@ #include "DistrhoUIInternal.hpp" #ifdef DISTRHO_UI_EXTERNAL -# error DSSI always uses external UI, no wrapper neeed! +# error DSSI always uses external UI, no wrapper needed! #endif #include @@ -134,7 +134,7 @@ public: # endif } #else - glWindow.setWindowTitle(uiTitle); + glWindow.setTitle(uiTitle); #endif } @@ -164,7 +164,7 @@ public: { fOscData.idle(); fUI.idle(); - dgl_msleep(50); + msleep(50); } #endif } diff --git a/source/modules/distrho/src/DistrhoUIInternal.hpp b/source/modules/distrho/src/DistrhoUIInternal.hpp index dd51a4585..aeab5fb67 100644 --- a/source/modules/distrho/src/DistrhoUIInternal.hpp +++ b/source/modules/distrho/src/DistrhoUIInternal.hpp @@ -119,7 +119,7 @@ public: UIInternal(void* ptr, intptr_t winId, editParamFunc editParamCall, setParamFunc setParamCall, setStateFunc setStateCall, sendNoteFunc sendNoteCall, uiResizeFunc uiResizeCall) #ifdef DISTRHO_UI_OPENGL : glApp(), - glWindow(&glApp, winId), + glWindow(glApp, winId), fUi(createUI()), #else : fUi(createUI()), @@ -140,6 +140,7 @@ public: #ifdef DISTRHO_UI_OPENGL glWindow.setSize(fUi->d_getWidth(), fUi->d_getHeight()); + glWindow.setResizable(false); #else assert(winId == 0); return; diff --git a/source/modules/distrho/src/DistrhoUIOpenGL.cpp b/source/modules/distrho/src/DistrhoUIOpenGL.cpp index eb346bf63..a859f7315 100644 --- a/source/modules/distrho/src/DistrhoUIOpenGL.cpp +++ b/source/modules/distrho/src/DistrhoUIOpenGL.cpp @@ -27,7 +27,7 @@ START_NAMESPACE_DISTRHO OpenGLUI::OpenGLUI() : UI(), - Widget(DGL::dgl_lastUiParent) + Widget(*DGL::dgl_lastUiParent) { assert(DGL::dgl_lastUiParent != nullptr); diff --git a/source/tests/DGL.cpp b/source/tests/DGL.cpp new file mode 100644 index 000000000..1bd08256f --- /dev/null +++ b/source/tests/DGL.cpp @@ -0,0 +1,88 @@ +/* + * Carla Tests + * Copyright (C) 2013 Filipe Coelho + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * For a full copy of the GNU General Public License see the doc/GPL.txt file. + */ + +#include "dgl/App.hpp" +#include "dgl/Geometry.hpp" +#include "dgl/Image.hpp" +#include "dgl/ImageAboutWindow.hpp" +#include "dgl/ImageButton.hpp" +#include "dgl/ImageKnob.hpp" +#include "dgl/ImageSlider.hpp" +#include "dgl/Widget.hpp" +#include "dgl/Window.hpp" + +#include + +int main() +{ + USE_NAMESPACE_DGL; + + msleep(1); + + Point pi; + Point pl; + Point pf; + Point pd; + Point pu; + + Size si; + Size sl; + Size sf; + Size sd; + Size su; + + Rectangle ri; + Rectangle rl; + Rectangle rf; + Rectangle rd; + Rectangle ru; + + Image i; + + App app; + Window win(app); + win.setSize(500, 500); + win.show(); + +// for (int i=0; i < 1000; ++i) +// { +// app.idle(); +// +// if (app.isQuiting()) +// break; + +// if (i % 30 == 0) +// printf("SIZE: %i:%i\n", win.getWidth(), win.getHeight()); + +// msleep(10); +// } + + app.exec(); + + return 0; +} + +#include "dgl/src/ImageAboutWindow.cpp" +#include "dgl/src/App.cpp" +#include "dgl/src/Base.cpp" +#include "dgl/src/Geometry.cpp" +#include "dgl/src/Image.cpp" +#include "dgl/src/ImageButton.cpp" +#include "dgl/src/ImageKnob.cpp" +#include "dgl/src/ImageSlider.cpp" +#include "dgl/src/Widget.cpp" +#include "dgl/src/Window.cpp" diff --git a/source/tests/Makefile b/source/tests/Makefile index 98e2ee9d7..ffdf3c6ae 100644 --- a/source/tests/Makefile +++ b/source/tests/Makefile @@ -27,7 +27,7 @@ else ifeq ($(WIN32),true) DGL_LIBS = -lopengl32 -lgdi32 else -DGL_LIBS = -lX11 +DGL_LIBS = -lGL -lX11 endif endif @@ -44,8 +44,10 @@ CarlaString: CarlaString.cpp ../utils/CarlaString.hpp $(CXX) $< $(BUILD_CXX_FLAGS) $(LINK_FLAGS) -o $@ # valgrind ./CarlaString -DGL: DGL.cpp - $(CXX) $^ $(BUILD_CXX_FLAGS) $(LINK_FLAGS) $(DGL_LIBS) -o $@ +DGL: DGL.cpp ../modules/distrho/dgl/src/Window.cpp + $(CXX) $< $(BUILD_CXX_FLAGS) $(LINK_FLAGS) $(DGL_LIBS) -o $@ +# ./DGL +# valgrind ./DGL Print: Print.cpp $(CXX) $^ $(BUILD_CXX_FLAGS) $(LINK_FLAGS) -o $@