@@ -38,18 +38,18 @@ class Window; | |||
In standalone mode an application will automatically quit its | |||
event-loop when all its windows are closed. | |||
*/ | |||
class App | |||
class Application | |||
{ | |||
public: | |||
/** | |||
Constructor. | |||
*/ | |||
App(); | |||
Application(); | |||
/** | |||
Destructor. | |||
*/ | |||
~App(); | |||
~Application(); | |||
/** | |||
Idle function. | |||
@@ -81,7 +81,7 @@ private: | |||
PrivateData* const pData; | |||
friend class Window; | |||
DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(App) | |||
DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(Application) | |||
}; | |||
// ----------------------------------------------------------------------- |
@@ -121,50 +121,50 @@ START_NAMESPACE_DGL | |||
Convenience symbols for ASCII control characters. | |||
*/ | |||
enum Char { | |||
CHAR_BACKSPACE = 0x08, | |||
CHAR_ESCAPE = 0x1B, | |||
CHAR_DELETE = 0x7F | |||
kCharBackspace = 0x08, | |||
kCharEscape = 0x1B, | |||
kCharDelete = 0x7F | |||
}; | |||
/** | |||
Keyboard modifier flags. | |||
*/ | |||
enum Modifier { | |||
MODIFIER_SHIFT = 1 << 0, /**< Shift key */ | |||
MODIFIER_CTRL = 1 << 1, /**< Control key */ | |||
MODIFIER_ALT = 1 << 2, /**< Alt/Option key */ | |||
MODIFIER_SUPER = 1 << 3 /**< Mod4/Command/Windows key */ | |||
kModifierShift = 1 << 0, /**< Shift key */ | |||
kModifierControl = 1 << 1, /**< Control key */ | |||
kModifierAlt = 1 << 2, /**< Alt/Option key */ | |||
kModifierSuper = 1 << 3 /**< Mod4/Command/Windows key */ | |||
}; | |||
/** | |||
Special (non-Unicode) keyboard keys. | |||
*/ | |||
enum Key { | |||
KEY_F1 = 1, | |||
KEY_F2, | |||
KEY_F3, | |||
KEY_F4, | |||
KEY_F5, | |||
KEY_F6, | |||
KEY_F7, | |||
KEY_F8, | |||
KEY_F9, | |||
KEY_F10, | |||
KEY_F11, | |||
KEY_F12, | |||
KEY_LEFT, | |||
KEY_UP, | |||
KEY_RIGHT, | |||
KEY_DOWN, | |||
KEY_PAGE_UP, | |||
KEY_PAGE_DOWN, | |||
KEY_HOME, | |||
KEY_END, | |||
KEY_INSERT, | |||
KEY_SHIFT, | |||
KEY_CTRL, | |||
KEY_ALT, | |||
KEY_SUPER | |||
kKeyF1 = 1, | |||
kKeyF2, | |||
kKeyF3, | |||
kKeyF4, | |||
kKeyF5, | |||
kKeyF6, | |||
kKeyF7, | |||
kKeyF8, | |||
kKeyF9, | |||
kKeyF10, | |||
kKeyF11, | |||
kKeyF12, | |||
kKeyLeft, | |||
kKeyUp, | |||
kKeyRight, | |||
kKeyDown, | |||
kKeyPageUp, | |||
kKeyPageDown, | |||
kKeyHome, | |||
kKeyEnd, | |||
kKeyInsert, | |||
kKeyShift, | |||
kKeyControl, | |||
kKeyAlt, | |||
kKeySuper | |||
}; | |||
// ----------------------------------------------------------------------- | |||
@@ -184,4 +184,12 @@ public: | |||
END_NAMESPACE_DGL | |||
#ifndef DONT_SET_USING_DGL_NAMESPACE | |||
// If your code uses a lot of DGL classes, then this will obviously save you | |||
// a lot of typing, but can be disabled by setting DONT_SET_USING_DGL_NAMESPACE. | |||
using namespace DGL_NAMESPACE; | |||
#endif | |||
// ----------------------------------------------------------------------- | |||
#endif // DGL_BASE_HPP_INCLUDED |
@@ -164,6 +164,8 @@ private: | |||
// ----------------------------------------------------------------------- | |||
// note set range and step before setting the value | |||
class ImageSlider : public Widget | |||
{ | |||
public: | |||
@@ -178,10 +180,9 @@ public: | |||
explicit ImageSlider(Window& parent, const Image& image) noexcept; | |||
explicit ImageSlider(Widget* widget, const Image& image) noexcept; | |||
explicit ImageSlider(const ImageSlider& imageSlider) noexcept; | |||
ImageSlider& operator=(const ImageSlider& imageSlider) noexcept; | |||
float getValue() const noexcept; | |||
void setValue(float value, bool sendCallback = false) noexcept; | |||
void setStartPos(const Point<int>& startPos) noexcept; | |||
void setStartPos(int x, int y) noexcept; | |||
@@ -191,7 +192,6 @@ public: | |||
void setInverted(bool inverted) noexcept; | |||
void setRange(float min, float max) noexcept; | |||
void setStep(float step) noexcept; | |||
void setValue(float value, bool sendCallback = false) noexcept; | |||
void setCallback(Callback* callback) noexcept; | |||
@@ -210,6 +210,7 @@ private: | |||
bool fDragging; | |||
bool fInverted; | |||
bool fValueIsSet; | |||
int fStartedX; | |||
int fStartedY; | |||
@@ -15,7 +15,7 @@ LINK_FLAGS += $(DGL_LIBS) | |||
# -------------------------------------------------------------- | |||
OBJS = \ | |||
src/App.cpp.o \ | |||
src/Application.cpp.o \ | |||
src/Color.cpp.o \ | |||
src/Geometry.cpp.o \ | |||
src/Image.cpp.o \ | |||
@@ -17,7 +17,7 @@ | |||
#ifndef DGL_STANDALONE_WINDOW_HPP_INCLUDED | |||
#define DGL_STANDALONE_WINDOW_HPP_INCLUDED | |||
#include "App.hpp" | |||
#include "Application.hpp" | |||
#include "Widget.hpp" | |||
#include "Window.hpp" | |||
@@ -25,19 +25,19 @@ START_NAMESPACE_DGL | |||
// ----------------------------------------------------------------------- | |||
class StandaloneWindow : public App, | |||
class StandaloneWindow : public Application, | |||
public Window | |||
{ | |||
public: | |||
StandaloneWindow() | |||
: App(), | |||
Window((App&)*this), | |||
: Application(), | |||
Window((Application&)*this), | |||
fWidget(nullptr) {} | |||
void exec() | |||
{ | |||
Window::show(); | |||
App::exec(); | |||
Application::exec(); | |||
} | |||
protected: | |||
@@ -30,7 +30,7 @@ END_NAMESPACE_DISTRHO | |||
START_NAMESPACE_DGL | |||
class App; | |||
class Application; | |||
class ImageSlider; | |||
class NanoWidget; | |||
class Window; | |||
@@ -287,7 +287,7 @@ public: | |||
Get this widget's window application. | |||
Same as calling getParentWindow().getApp(). | |||
*/ | |||
App& getParentApp() const noexcept; | |||
Application& getParentApp() const noexcept; | |||
/** | |||
Get parent window, as passed in the constructor. | |||
@@ -23,7 +23,7 @@ START_NAMESPACE_DGL | |||
// ----------------------------------------------------------------------- | |||
class App; | |||
class Application; | |||
class Widget; | |||
class StandaloneWindow; | |||
@@ -67,9 +67,9 @@ public: | |||
buttons() {} | |||
}; | |||
explicit Window(App& app); | |||
explicit Window(App& app, Window& parent); | |||
explicit Window(App& app, intptr_t parentId); | |||
explicit Window(Application& app); | |||
explicit Window(Application& app, Window& parent); | |||
explicit Window(Application& app, intptr_t parentId); | |||
virtual ~Window(); | |||
void show(); | |||
@@ -99,7 +99,7 @@ public: | |||
void setTransientWinId(uintptr_t winId); | |||
App& getApp() const noexcept; | |||
Application& getApp() const noexcept; | |||
intptr_t getWindowId() const noexcept; | |||
void addIdleCallback(IdleCallback* const callback); | |||
@@ -116,7 +116,7 @@ protected: | |||
private: | |||
struct PrivateData; | |||
PrivateData* const pData; | |||
friend class App; | |||
friend class Application; | |||
friend class Widget; | |||
friend class StandaloneWindow; | |||
@@ -14,23 +14,23 @@ | |||
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |||
*/ | |||
#include "AppPrivateData.hpp" | |||
#include "ApplicationPrivateData.hpp" | |||
#include "../Window.hpp" | |||
START_NAMESPACE_DGL | |||
// ----------------------------------------------------------------------- | |||
App::App() | |||
Application::Application() | |||
: pData(new PrivateData()), | |||
leakDetector_App() {} | |||
leakDetector_Application() {} | |||
App::~App() | |||
Application::~Application() | |||
{ | |||
delete pData; | |||
} | |||
void App::idle() | |||
void Application::idle() | |||
{ | |||
for (std::list<Window*>::iterator it = pData->windows.begin(), ite = pData->windows.end(); it != ite; ++it) | |||
{ | |||
@@ -45,7 +45,7 @@ void App::idle() | |||
} | |||
} | |||
void App::exec() | |||
void Application::exec() | |||
{ | |||
for (; pData->doLoop;) | |||
{ | |||
@@ -54,7 +54,7 @@ void App::exec() | |||
} | |||
} | |||
void App::quit() | |||
void Application::quit() | |||
{ | |||
pData->doLoop = false; | |||
@@ -65,7 +65,7 @@ void App::quit() | |||
} | |||
} | |||
bool App::isQuiting() const noexcept | |||
bool Application::isQuiting() const noexcept | |||
{ | |||
return !pData->doLoop; | |||
} |
@@ -17,7 +17,7 @@ | |||
#ifndef DGL_APP_PRIVATE_DATA_HPP_INCLUDED | |||
#define DGL_APP_PRIVATE_DATA_HPP_INCLUDED | |||
#include "../App.hpp" | |||
#include "../Application.hpp" | |||
#include "../../distrho/extra/Sleep.hpp" | |||
#include <list> | |||
@@ -26,7 +26,7 @@ START_NAMESPACE_DGL | |||
// ----------------------------------------------------------------------- | |||
struct App::PrivateData { | |||
struct Application::PrivateData { | |||
bool doLoop; | |||
uint visibleWindows; | |||
std::list<Window*> windows; |
@@ -60,7 +60,7 @@ void ImageAboutWindow::onDisplay() | |||
bool ImageAboutWindow::onKeyboard(const KeyboardEvent& ev) | |||
{ | |||
if (ev.press && ev.key == CHAR_ESCAPE) | |||
if (ev.press && ev.key == kCharEscape) | |||
{ | |||
Window::close(); | |||
return true; | |||
@@ -591,7 +591,7 @@ bool ImageKnob::onMouse(const MouseEvent& ev) | |||
if (! contains(ev.pos)) | |||
return false; | |||
if ((ev.mod & MODIFIER_SHIFT) != 0 && fUsingDefault) | |||
if ((ev.mod & kModifierShift) != 0 && fUsingDefault) | |||
{ | |||
setValue(fValueDef, true); | |||
fValueTmp = fValue; | |||
@@ -631,7 +631,7 @@ bool ImageKnob::onMotion(const MotionEvent& ev) | |||
{ | |||
if (const int movX = ev.pos.getX() - fLastX) | |||
{ | |||
d = (ev.mod & MODIFIER_CTRL) ? 2000.0f : 200.0f; | |||
d = (ev.mod & kModifierControl) ? 2000.0f : 200.0f; | |||
value = (fUsingLog ? _invlogscale(fValueTmp) : fValueTmp) + (float(fMaximum - fMinimum) / d * float(movX)); | |||
doVal = true; | |||
} | |||
@@ -640,7 +640,7 @@ bool ImageKnob::onMotion(const MotionEvent& ev) | |||
{ | |||
if (const int movY = fLastY - ev.pos.getY()) | |||
{ | |||
d = (ev.mod & MODIFIER_CTRL) ? 2000.0f : 200.0f; | |||
d = (ev.mod & kModifierControl) ? 2000.0f : 200.0f; | |||
value = (fUsingLog ? _invlogscale(fValueTmp) : fValueTmp) + (float(fMaximum - fMinimum) / d * float(movY)); | |||
doVal = true; | |||
} | |||
@@ -680,7 +680,7 @@ bool ImageKnob::onScroll(const ScrollEvent& ev) | |||
if (! contains(ev.pos)) | |||
return false; | |||
const float d = (ev.mod & MODIFIER_CTRL) ? 2000.0f : 200.0f; | |||
const float d = (ev.mod & kModifierControl) ? 2000.0f : 200.0f; | |||
float value = (fUsingLog ? _invlogscale(fValueTmp) : fValueTmp) + (float(fMaximum - fMinimum) / d * 10.f * ev.delta.getY()); | |||
if (fUsingLog) | |||
@@ -733,6 +733,7 @@ ImageSlider::ImageSlider(Window& parent, const Image& image) noexcept | |||
fValueTmp(fValue), | |||
fDragging(false), | |||
fInverted(false), | |||
fValueIsSet(false), | |||
fStartedX(0), | |||
fStartedY(0), | |||
fCallback(nullptr), | |||
@@ -754,6 +755,7 @@ ImageSlider::ImageSlider(Widget* widget, const Image& image) noexcept | |||
fValueTmp(fValue), | |||
fDragging(false), | |||
fInverted(false), | |||
fValueIsSet(false), | |||
fStartedX(0), | |||
fStartedY(0), | |||
fCallback(nullptr), | |||
@@ -765,50 +767,32 @@ ImageSlider::ImageSlider(Widget* widget, const Image& image) noexcept | |||
fNeedsFullViewport = true; | |||
} | |||
ImageSlider::ImageSlider(const ImageSlider& imageSlider) noexcept | |||
: Widget(imageSlider.getParentWindow()), | |||
fImage(imageSlider.fImage), | |||
fMinimum(imageSlider.fMinimum), | |||
fMaximum(imageSlider.fMaximum), | |||
fStep(imageSlider.fStep), | |||
fValue(imageSlider.fValue), | |||
fValueTmp(fValue), | |||
fDragging(false), | |||
fInverted(imageSlider.fInverted), | |||
fStartedX(0), | |||
fStartedY(0), | |||
fCallback(imageSlider.fCallback), | |||
fStartPos(imageSlider.fStartPos), | |||
fEndPos(imageSlider.fEndPos), | |||
fSliderArea(imageSlider.fSliderArea), | |||
leakDetector_ImageSlider() | |||
float ImageSlider::getValue() const noexcept | |||
{ | |||
fNeedsFullViewport = true; | |||
return fValue; | |||
} | |||
ImageSlider& ImageSlider::operator=(const ImageSlider& imageSlider) noexcept | |||
void ImageSlider::setValue(float value, bool sendCallback) noexcept | |||
{ | |||
fImage = imageSlider.fImage; | |||
fMinimum = imageSlider.fMinimum; | |||
fMaximum = imageSlider.fMaximum; | |||
fStep = imageSlider.fStep; | |||
fValue = imageSlider.fValue; | |||
fValueTmp = fValue; | |||
fDragging = false; | |||
fInverted = imageSlider.fInverted; | |||
fStartedX = 0; | |||
fStartedY = 0; | |||
fCallback = imageSlider.fCallback; | |||
fStartPos = imageSlider.fStartPos; | |||
fEndPos = imageSlider.fEndPos; | |||
fSliderArea = imageSlider.fSliderArea; | |||
if (! fValueIsSet) | |||
fValueIsSet = true; | |||
return *this; | |||
} | |||
if (d_isEqual(fValue, value)) | |||
return; | |||
float ImageSlider::getValue() const noexcept | |||
{ | |||
return fValue; | |||
fValue = value; | |||
if (d_isZero(fStep)) | |||
fValueTmp = value; | |||
repaint(); | |||
if (sendCallback && fCallback != nullptr) | |||
{ | |||
try { | |||
fCallback->imageSliderValueChanged(this, fValue); | |||
} DISTRHO_SAFE_EXCEPTION("ImageSlider::setValue"); | |||
} | |||
} | |||
void ImageSlider::setStartPos(const Point<int>& startPos) noexcept | |||
@@ -844,12 +828,15 @@ void ImageSlider::setInverted(bool inverted) noexcept | |||
void ImageSlider::setRange(float min, float max) noexcept | |||
{ | |||
fMinimum = min; | |||
fMaximum = max; | |||
if (fValue < min) | |||
{ | |||
fValue = min; | |||
repaint(); | |||
if (fCallback != nullptr) | |||
if (fCallback != nullptr && fValueIsSet) | |||
{ | |||
try { | |||
fCallback->imageSliderValueChanged(this, fValue); | |||
@@ -861,16 +848,13 @@ void ImageSlider::setRange(float min, float max) noexcept | |||
fValue = max; | |||
repaint(); | |||
if (fCallback != nullptr) | |||
if (fCallback != nullptr && fValueIsSet) | |||
{ | |||
try { | |||
fCallback->imageSliderValueChanged(this, fValue); | |||
} DISTRHO_SAFE_EXCEPTION("ImageSlider::setRange > max"); | |||
} | |||
} | |||
fMinimum = min; | |||
fMaximum = max; | |||
} | |||
void ImageSlider::setStep(float step) noexcept | |||
@@ -878,26 +862,6 @@ void ImageSlider::setStep(float step) noexcept | |||
fStep = step; | |||
} | |||
void ImageSlider::setValue(float value, bool sendCallback) noexcept | |||
{ | |||
if (d_isEqual(fValue, value)) | |||
return; | |||
fValue = value; | |||
if (d_isZero(fStep)) | |||
fValueTmp = value; | |||
repaint(); | |||
if (sendCallback && fCallback != nullptr) | |||
{ | |||
try { | |||
fCallback->imageSliderValueChanged(this, fValue); | |||
} DISTRHO_SAFE_EXCEPTION("ImageSlider::setValue"); | |||
} | |||
} | |||
void ImageSlider::setCallback(Callback* callback) noexcept | |||
{ | |||
fCallback = callback; | |||
@@ -210,7 +210,7 @@ void Widget::setAbsolutePos(const Point<int>& pos) noexcept | |||
fParent.repaint(); | |||
} | |||
App& Widget::getParentApp() const noexcept | |||
Application& Widget::getParentApp() const noexcept | |||
{ | |||
return fParent.getApp(); | |||
} | |||
@@ -17,10 +17,7 @@ | |||
// we need this for now | |||
//#define PUGL_GRAB_FOCUS 1 | |||
#include "AppPrivateData.hpp" | |||
#include "../Widget.hpp" | |||
#include "../Window.hpp" | |||
#include "../../distrho/extra/String.hpp" | |||
#include "../../distrho/src/DistrhoDefines.h" | |||
#undef PUGL_HAVE_CAIRO | |||
#undef PUGL_HAVE_GL | |||
@@ -42,6 +39,11 @@ extern "C" { | |||
# error Unsupported platform | |||
#endif | |||
#include "ApplicationPrivateData.hpp" | |||
#include "../Widget.hpp" | |||
#include "../Window.hpp" | |||
#include "../../distrho/extra/String.hpp" | |||
#define FOR_EACH_WIDGET(it) \ | |||
for (std::list<Widget*>::iterator it = fWidgets.begin(); it != fWidgets.end(); ++it) | |||
@@ -64,7 +66,7 @@ START_NAMESPACE_DGL | |||
// Window Private | |||
struct Window::PrivateData { | |||
PrivateData(App& app, Window* const self) | |||
PrivateData(Application& app, Window* const self) | |||
: fApp(app), | |||
fSelf(self), | |||
fView(puglInit()), | |||
@@ -93,7 +95,7 @@ struct Window::PrivateData { | |||
init(); | |||
} | |||
PrivateData(App& app, Window* const self, Window& parent) | |||
PrivateData(Application& app, Window* const self, Window& parent) | |||
: fApp(app), | |||
fSelf(self), | |||
fView(puglInit()), | |||
@@ -132,7 +134,7 @@ struct Window::PrivateData { | |||
#endif | |||
} | |||
PrivateData(App& app, Window* const self, const intptr_t parentId) | |||
PrivateData(Application& app, Window* const self, const intptr_t parentId) | |||
: fApp(app), | |||
fSelf(self), | |||
fView(puglInit()), | |||
@@ -884,9 +886,9 @@ struct Window::PrivateData { | |||
// ------------------------------------------------------------------- | |||
App& fApp; | |||
Window* fSelf; | |||
PuglView* fView; | |||
Application& fApp; | |||
Window* fSelf; | |||
PuglView* fView; | |||
bool fFirstInit; | |||
bool fVisible; | |||
@@ -990,15 +992,15 @@ struct Window::PrivateData { | |||
// ----------------------------------------------------------------------- | |||
// Window | |||
Window::Window(App& app) | |||
Window::Window(Application& app) | |||
: pData(new PrivateData(app, this)), | |||
leakDetector_Window() {} | |||
Window::Window(App& app, Window& parent) | |||
Window::Window(Application& app, Window& parent) | |||
: pData(new PrivateData(app, this, parent)), | |||
leakDetector_Window() {} | |||
Window::Window(App& app, intptr_t parentId) | |||
Window::Window(Application& app, intptr_t parentId) | |||
: pData(new PrivateData(app, this, parentId)), | |||
leakDetector_Window() {} | |||
@@ -1169,7 +1171,7 @@ void Window::setTransientWinId(uintptr_t winId) | |||
pData->setTransientWinId(winId); | |||
} | |||
App& Window::getApp() const noexcept | |||
Application& Window::getApp() const noexcept | |||
{ | |||
return pData->fApp; | |||
} | |||
@@ -221,4 +221,13 @@ uint32_t d_nextPowerOf2(uint32_t size) noexcept | |||
// ----------------------------------------------------------------------- | |||
#ifndef DONT_SET_USING_DISTRHO_NAMESPACE | |||
// If your code uses a lot of DGL classes, then this will obviously save you | |||
// a lot of typing, but can be disabled by setting DONT_SET_USING_DISTRHO_NAMESPACE. | |||
namespace DISTRHO_NAMESPACE {} | |||
using namespace DISTRHO_NAMESPACE; | |||
#endif | |||
// ----------------------------------------------------------------------- | |||
#endif // DISTRHO_UTILS_HPP_INCLUDED |