@@ -28,13 +28,6 @@ class Window; | |||
class App | |||
{ | |||
public: | |||
class IdleCallback | |||
{ | |||
public: | |||
virtual ~IdleCallback() {} | |||
virtual void idleCallback() = 0; | |||
}; | |||
App(); | |||
~App(); | |||
@@ -43,19 +36,11 @@ public: | |||
void quit(); | |||
bool isQuiting() const noexcept; | |||
void addIdleCallback(IdleCallback* const callback); | |||
void removeIdleCallback(IdleCallback* const callback); | |||
private: | |||
struct PrivateData; | |||
PrivateData* const pData; | |||
friend class Window; | |||
void _addWindow(Window* const window); | |||
void _removeWindow(Window* const window); | |||
void _oneShown(); | |||
void _oneHidden(); | |||
DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(App) | |||
}; | |||
@@ -106,6 +106,15 @@ enum Modifier { | |||
// ----------------------------------------------------------------------- | |||
class IdleCallback | |||
{ | |||
public: | |||
virtual ~IdleCallback() {} | |||
virtual void idleCallback() = 0; | |||
}; | |||
// ----------------------------------------------------------------------- | |||
END_NAMESPACE_DGL | |||
#endif // DGL_BASE_HPP_INCLUDED |
@@ -68,8 +68,11 @@ public: | |||
int getModifiers() const; | |||
intptr_t getWindowId() const; | |||
void addIdleCallback(IdleCallback* const callback); | |||
void removeIdleCallback(IdleCallback* const callback); | |||
private: | |||
class PrivateData; | |||
struct PrivateData; | |||
PrivateData* const pData; | |||
friend class App; | |||
friend class Widget; | |||
@@ -14,7 +14,7 @@ | |||
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |||
*/ | |||
#include "../App.hpp" | |||
#include "AppPrivateData.hpp" | |||
#include "../Window.hpp" | |||
#include <list> | |||
@@ -23,25 +23,6 @@ START_NAMESPACE_DGL | |||
// ----------------------------------------------------------------------- | |||
struct App::PrivateData { | |||
bool doLoop; | |||
uint visibleWindows; | |||
std::list<Window*> windows; | |||
std::list<IdleCallback*> idleCallbacks; | |||
PrivateData() | |||
: doLoop(false), | |||
visibleWindows(0) {} | |||
~PrivateData() | |||
{ | |||
windows.clear(); | |||
idleCallbacks.clear(); | |||
} | |||
}; | |||
// ----------------------------------------------------------------------- | |||
App::App() | |||
: pData(new PrivateData()) | |||
{ | |||
@@ -94,48 +75,4 @@ bool App::isQuiting() const noexcept | |||
// ----------------------------------------------------------------------- | |||
void App::addIdleCallback(IdleCallback* const callback) | |||
{ | |||
DISTRHO_SAFE_ASSERT_RETURN(callback != nullptr,) | |||
pData->idleCallbacks.push_back(callback); | |||
} | |||
void App::removeIdleCallback(IdleCallback* const callback) | |||
{ | |||
DISTRHO_SAFE_ASSERT_RETURN(callback != nullptr,) | |||
pData->idleCallbacks.remove(callback); | |||
} | |||
// ----------------------------------------------------------------------- | |||
void App::_addWindow(Window* const window) | |||
{ | |||
DISTRHO_SAFE_ASSERT_RETURN(window != nullptr,) | |||
pData->windows.push_back(window); | |||
} | |||
void App::_removeWindow(Window* const window) | |||
{ | |||
DISTRHO_SAFE_ASSERT_RETURN(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; | |||
} | |||
// ----------------------------------------------------------------------- | |||
END_NAMESPACE_DGL |
@@ -0,0 +1,63 @@ | |||
/* | |||
* DISTRHO Plugin Framework (DPF) | |||
* Copyright (C) 2012-2014 Filipe Coelho <falktx@falktx.com> | |||
* | |||
* Permission to use, copy, modify, and/or distribute this software for any purpose with | |||
* or without fee is hereby granted, provided that the above copyright notice and this | |||
* permission notice appear in all copies. | |||
* | |||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD | |||
* TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN | |||
* NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL | |||
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER | |||
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN | |||
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |||
*/ | |||
#ifndef DGL_APP_PRIVATE_DATA_HPP_INCLUDED | |||
#define DGL_APP_PRIVATE_DATA_HPP_INCLUDED | |||
#include "../App.hpp" | |||
#include <list> | |||
START_NAMESPACE_DGL | |||
// ----------------------------------------------------------------------- | |||
struct App::PrivateData { | |||
bool doLoop; | |||
uint visibleWindows; | |||
std::list<Window*> windows; | |||
std::list<IdleCallback*> idleCallbacks; | |||
PrivateData() | |||
: doLoop(false), | |||
visibleWindows(0) {} | |||
~PrivateData() | |||
{ | |||
windows.clear(); | |||
idleCallbacks.clear(); | |||
} | |||
void oneShown() noexcept | |||
{ | |||
if (++visibleWindows == 1) | |||
doLoop = true; | |||
} | |||
void oneHidden() noexcept | |||
{ | |||
DISTRHO_SAFE_ASSERT_RETURN(visibleWindows > 0,); | |||
if (--visibleWindows == 0) | |||
doLoop = false; | |||
} | |||
}; | |||
// ----------------------------------------------------------------------- | |||
END_NAMESPACE_DGL | |||
#endif // DGL_APP_PRIVATE_DATA_HPP_INCLUDED |
@@ -17,7 +17,7 @@ | |||
// we need this for now | |||
#define XKEYFOCUSGRAB 1 | |||
#include "../App.hpp" | |||
#include "AppPrivateData.hpp" | |||
#include "../Widget.hpp" | |||
#include "../Window.hpp" | |||
@@ -69,9 +69,8 @@ Window* dgl_lastUiParent = nullptr; | |||
// ----------------------------------------------------------------------- | |||
// Window Private | |||
class Window::PrivateData | |||
struct Window::PrivateData | |||
{ | |||
public: | |||
PrivateData(App& app, Window* const self) | |||
: fApp(app), | |||
fSelf(self), | |||
@@ -155,7 +154,7 @@ public: | |||
if (parentId != 0) | |||
{ | |||
DBG("NOTE: Embed window is always visible and non-resizable\n"); | |||
fApp._oneShown(); | |||
fApp.pData->oneShown(); | |||
fFirstInit = false; | |||
} | |||
} | |||
@@ -199,7 +198,7 @@ public: | |||
} | |||
#endif | |||
fApp._addWindow(fSelf); | |||
fApp.pData->windows.push_back(fSelf); | |||
DBG("Success!\n"); | |||
} | |||
@@ -213,7 +212,7 @@ public: | |||
if (fSelf != nullptr) | |||
{ | |||
fApp._removeWindow(fSelf); | |||
fApp.pData->windows.remove(fSelf); | |||
fSelf = nullptr; | |||
} | |||
@@ -242,7 +241,7 @@ public: | |||
if (! fFirstInit) | |||
{ | |||
fApp._oneHidden(); | |||
fApp.pData->oneHidden(); | |||
fFirstInit = true; | |||
} | |||
} | |||
@@ -341,7 +340,7 @@ public: | |||
{ | |||
if (fFirstInit) | |||
{ | |||
fApp._oneShown(); | |||
fApp.pData->oneShown(); | |||
fFirstInit = false; | |||
} | |||
} | |||
@@ -577,7 +576,6 @@ public: | |||
// ------------------------------------------------------------------- | |||
protected: | |||
void onDisplay() | |||
{ | |||
//DBG("PUGL: onDisplay\n"); | |||
@@ -706,7 +704,6 @@ protected: | |||
// ------------------------------------------------------------------- | |||
private: | |||
App& fApp; | |||
Window* fSelf; | |||
PuglView* fView; | |||
@@ -938,6 +935,22 @@ void Window::_idle() | |||
// ----------------------------------------------------------------------- | |||
void Window::addIdleCallback(IdleCallback* const callback) | |||
{ | |||
DISTRHO_SAFE_ASSERT_RETURN(callback != nullptr,) | |||
pData->fApp.pData->idleCallbacks.push_back(callback); | |||
} | |||
void Window::removeIdleCallback(IdleCallback* const callback) | |||
{ | |||
DISTRHO_SAFE_ASSERT_RETURN(callback != nullptr,) | |||
pData->fApp.pData->idleCallbacks.remove(callback); | |||
} | |||
// ----------------------------------------------------------------------- | |||
END_NAMESPACE_DGL | |||
#undef DBG | |||
@@ -76,8 +76,8 @@ private: | |||
// ------------------------------------------------------ | |||
// Custom Cairo Widget | |||
class CustomCairoWidget : public App::IdleCallback, | |||
CairoWidget | |||
class CustomCairoWidget : public CairoWidget, | |||
public IdleCallback | |||
{ | |||
public: | |||
CustomCairoWidget(Window& parent) | |||
@@ -186,7 +186,7 @@ public: | |||
bg(*this), | |||
cairo(*this) | |||
{ | |||
app.addIdleCallback(&cairo); | |||
addIdleCallback(&cairo); | |||
} | |||
private: | |||
@@ -21,8 +21,6 @@ | |||
#include "Window.hpp" | |||
#include "Widget.hpp" | |||
#include <cstdio> | |||
// ------------------------------------------------------ | |||
// use namespace | |||
@@ -31,8 +29,8 @@ using namespace DGL; | |||
// ------------------------------------------------------ | |||
// Single color widget | |||
class ColorWidget : public App::IdleCallback, | |||
Widget | |||
class ColorWidget : public Widget, | |||
public IdleCallback | |||
{ | |||
public: | |||
ColorWidget(Window& parent) | |||
@@ -41,6 +39,7 @@ public: | |||
reverse(false), | |||
r(0), g(0), b(0) | |||
{ | |||
parent.addIdleCallback(this); | |||
} | |||
private: | |||
@@ -139,8 +138,6 @@ int main() | |||
Window win(app); | |||
ColorWidget color(win); | |||
app.addIdleCallback(&color); | |||
win.setSize(300, 300); | |||
win.setTitle("Color"); | |||
win.show(); | |||
@@ -34,8 +34,8 @@ using namespace DGL; | |||
// ------------------------------------------------------ | |||
// our widget | |||
class ExampleImagesWidget : public App::IdleCallback, | |||
Widget | |||
class ExampleImagesWidget : public Widget, | |||
public IdleCallback | |||
{ | |||
public: | |||
static const int kImg1y = 0; | |||
@@ -59,7 +59,10 @@ public: | |||
fImg3rev(true), | |||
fImg1(CatPics::cat1Data, CatPics::cat1Width, CatPics::cat1Height, GL_BGR), | |||
fImg2(CatPics::cat2Data, CatPics::cat2Width, CatPics::cat2Height, GL_BGR), | |||
fImg3(CatPics::cat3Data, CatPics::cat3Width, CatPics::cat3Height, GL_BGR) {} | |||
fImg3(CatPics::cat3Data, CatPics::cat3Width, CatPics::cat3Height, GL_BGR) | |||
{ | |||
win.addIdleCallback(this); | |||
} | |||
private: | |||
void idleCallback() override | |||
@@ -198,8 +201,6 @@ int main() | |||
Window win(app); | |||
ExampleImagesWidget images(win); | |||
app.addIdleCallback(&images); | |||
win.setResizable(false); | |||
win.setSize(500, 400); | |||
win.setTitle("Images"); | |||