Browse Source

Add Knob and Slider get/setId; noexcept work

gh-pages
falkTX 7 years ago
parent
commit
e1855f6b80
11 changed files with 155 additions and 104 deletions
  1. +1
    -2
      dgl/Base.hpp
  2. +6
    -8
      dgl/ImageButton.hpp
  3. +12
    -10
      dgl/ImageKnob.hpp
  4. +18
    -16
      dgl/ImageSlider.hpp
  5. +11
    -11
      dgl/Widget.hpp
  6. +4
    -4
      dgl/Window.hpp
  7. +6
    -6
      dgl/src/ImageButton.cpp
  8. +36
    -11
      dgl/src/ImageKnob.cpp
  9. +42
    -17
      dgl/src/ImageSlider.cpp
  10. +11
    -11
      dgl/src/Widget.cpp
  11. +8
    -8
      dgl/src/Window.cpp

+ 1
- 2
dgl/Base.hpp View File

@@ -31,11 +31,10 @@
#define END_NAMESPACE_DGL }
#define USE_NAMESPACE_DGL using namespace DGL_NAMESPACE;

#ifdef DISTRHO_OS_WINDOWS
// -----------------------------------------------------------------------
// Fix OpenGL includes for Windows, based on glfw code

#ifdef DISTRHO_OS_WINDOWS

#ifndef APIENTRY
# define APIENTRY __stdcall
#endif // APIENTRY


+ 6
- 8
dgl/ImageButton.hpp View File

@@ -34,13 +34,13 @@ public:
virtual void imageButtonClicked(ImageButton* imageButton, int button) = 0;
};

ImageButton(Window& parent, const Image& image);
ImageButton(Window& parent, const Image& imageNormal, const Image& imageHover, const Image& imageDown);
ImageButton(Widget* widget, const Image& image);
ImageButton(Widget* widget, const Image& imageNormal, const Image& imageHover, const Image& imageDown);
ImageButton(const ImageButton& imageButton);
ImageButton(Window& parent, const Image& image) noexcept;
ImageButton(Window& parent, const Image& imageNormal, const Image& imageHover, const Image& imageDown) noexcept;
ImageButton(Widget* widget, const Image& image) noexcept;
ImageButton(Widget* widget, const Image& imageNormal, const Image& imageHover, const Image& imageDown) noexcept;
ImageButton(const ImageButton& imageButton) noexcept;

void setCallback(Callback* callback);
void setCallback(Callback* callback) noexcept;

protected:
void onDisplay() override;
@@ -59,8 +59,6 @@ private:
DISTRHO_LEAK_DETECTOR(ImageButton)
};

typedef ScopedPointer<ImageButton> ImageButtonPtr;

// -----------------------------------------------------------------------

END_NAMESPACE_DGL


+ 12
- 10
dgl/ImageKnob.hpp View File

@@ -41,19 +41,22 @@ public:
virtual void imageKnobValueChanged(ImageKnob* imageKnob, float value) = 0;
};

ImageKnob(Window& parent, const Image& image, Orientation orientation = Vertical);
ImageKnob(Widget* widget, const Image& image, Orientation orientation = Vertical);
ImageKnob(Window& parent, const Image& image, Orientation orientation = Vertical, int id = 0) noexcept;
ImageKnob(Widget* widget, const Image& image, Orientation orientation = Vertical, int id = 0) noexcept;
ImageKnob(const ImageKnob& imageKnob);

float getValue() const;
int getId() const noexcept;
void setId(int id) noexcept;

void setOrientation(Orientation orientation);
void setRange(float min, float max);
void setStep(float step);
void setValue(float value, bool sendCallback = false);
float getValue() const noexcept;

void setOrientation(Orientation orientation) noexcept;
void setRange(float min, float max) noexcept;
void setStep(float step) noexcept;
void setValue(float value, bool sendCallback = false) noexcept;
void setRotationAngle(int angle);

void setCallback(Callback* callback);
void setCallback(Callback* callback) noexcept;

protected:
void onDisplay() override;
@@ -64,6 +67,7 @@ protected:

private:
Image fImage;
int fId;
float fMinimum;
float fMaximum;
float fStep;
@@ -87,8 +91,6 @@ private:
DISTRHO_LEAK_DETECTOR(ImageKnob)
};

typedef ScopedPointer<ImageKnob> ImageKnobPtr;

// -----------------------------------------------------------------------

END_NAMESPACE_DGL


+ 18
- 16
dgl/ImageSlider.hpp View File

@@ -36,23 +36,26 @@ public:
virtual void imageSliderValueChanged(ImageSlider* imageSlider, float value) = 0;
};

ImageSlider(Window& parent, const Image& image);
ImageSlider(Widget* widget, const Image& image);
ImageSlider(const ImageSlider& imageSlider);
ImageSlider(Window& parent, const Image& image, int id = 0) noexcept;
ImageSlider(Widget* widget, const Image& image, int id = 0) noexcept;
ImageSlider(const ImageSlider& imageSlider) noexcept;

float getValue() const;
int getId() const noexcept;
void setId(int id) noexcept;

void setStartPos(const Point<int>& startPos);
void setStartPos(int x, int y);
void setEndPos(const Point<int>& endPos);
void setEndPos(int x, int y);
float getValue() const noexcept;

void setInverted(bool inverted);
void setRange(float min, float max);
void setStep(float step);
void setValue(float value, bool sendCallback = false);
void setStartPos(const Point<int>& startPos) noexcept;
void setStartPos(int x, int y) noexcept;
void setEndPos(const Point<int>& endPos) noexcept;
void setEndPos(int x, int y) noexcept;

void setCallback(Callback* callback);
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;

protected:
void onDisplay() override;
@@ -61,6 +64,7 @@ protected:

private:
Image fImage;
int fId;
float fMinimum;
float fMaximum;
float fStep;
@@ -78,13 +82,11 @@ private:
Point<int> fEndPos;
Rectangle<int> fSliderArea;

void _recheckArea();
void _recheckArea() noexcept;

DISTRHO_LEAK_DETECTOR(ImageSlider)
};

typedef ScopedPointer<ImageSlider> ImageSliderPtr;

// -----------------------------------------------------------------------

END_NAMESPACE_DGL


+ 11
- 11
dgl/Widget.hpp View File

@@ -42,30 +42,30 @@ public:
int getY() const noexcept;
const Point<int>& getPos() const noexcept;

void setX(int x);
void setY(int y);
void setPos(int x, int y);
void setPos(const Point<int>& pos);
void setX(int x) noexcept;
void setY(int y) noexcept;
void setPos(int x, int y) noexcept;
void setPos(const Point<int>& pos) noexcept;

int getWidth() const noexcept;
int getHeight() const noexcept;
const Size<int>& getSize() const noexcept;

// virtual needed by cairo
virtual void setWidth(int width);
virtual void setHeight(int height);
virtual void setSize(int width, int height);
virtual void setSize(const Size<int>& size);
virtual void setWidth(int width) noexcept;
virtual void setHeight(int height) noexcept;
virtual void setSize(int width, int height) noexcept;
virtual void setSize(const Size<int>& size) noexcept;

const Rectangle<int>& getArea() const noexcept;

uint getEventTimestamp();
int getModifiers();
uint getEventTimestamp() const noexcept;
int getModifiers() const noexcept;

App& getParentApp() const noexcept;
Window& getParentWindow() const noexcept;

void repaint();
void repaint() noexcept;

protected:
virtual void onDisplay() = 0;


+ 4
- 4
dgl/Window.hpp View File

@@ -40,7 +40,7 @@ public:
void exec(bool lockWait = false);

void focus();
void repaint();
void repaint() noexcept;

bool isVisible() const noexcept;
void setVisible(bool yesNo);
@@ -58,9 +58,9 @@ public:
void setTransientWinId(intptr_t winId);

App& getApp() const noexcept;
uint getEventTimestamp() const;
int getModifiers() const;
intptr_t getWindowId() const;
uint getEventTimestamp() const noexcept;
int getModifiers() const noexcept;
intptr_t getWindowId() const noexcept;

void addIdleCallback(IdleCallback* const callback);
void removeIdleCallback(IdleCallback* const callback);


+ 6
- 6
dgl/src/ImageButton.cpp View File

@@ -20,7 +20,7 @@ START_NAMESPACE_DGL

// -----------------------------------------------------------------------

ImageButton::ImageButton(Window& parent, const Image& image)
ImageButton::ImageButton(Window& parent, const Image& image) noexcept
: Widget(parent),
fImageNormal(image),
fImageHover(image),
@@ -31,7 +31,7 @@ ImageButton::ImageButton(Window& parent, 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) noexcept
: Widget(parent),
fImageNormal(imageNormal),
fImageHover(imageHover),
@@ -45,7 +45,7 @@ ImageButton::ImageButton(Window& parent, const Image& imageNormal, const Image&
setSize(fCurImage->getSize());
}

ImageButton::ImageButton(Widget* widget, const Image& image)
ImageButton::ImageButton(Widget* widget, const Image& image) noexcept
: Widget(widget->getParentWindow()),
fImageNormal(image),
fImageHover(image),
@@ -56,7 +56,7 @@ ImageButton::ImageButton(Widget* widget, const Image& image)
{
}

ImageButton::ImageButton(Widget* widget, const Image& imageNormal, const Image& imageHover, const Image& imageDown)
ImageButton::ImageButton(Widget* widget, const Image& imageNormal, const Image& imageHover, const Image& imageDown) noexcept
: Widget(widget->getParentWindow()),
fImageNormal(imageNormal),
fImageHover(imageHover),
@@ -70,7 +70,7 @@ ImageButton::ImageButton(Widget* widget, const Image& imageNormal, const Image&
setSize(fCurImage->getSize());
}

ImageButton::ImageButton(const ImageButton& imageButton)
ImageButton::ImageButton(const ImageButton& imageButton) noexcept
: Widget(imageButton.getParentWindow()),
fImageNormal(imageButton.fImageNormal),
fImageHover(imageButton.fImageHover),
@@ -84,7 +84,7 @@ ImageButton::ImageButton(const ImageButton& imageButton)
setSize(fCurImage->getSize());
}

void ImageButton::setCallback(Callback* callback)
void ImageButton::setCallback(Callback* callback) noexcept
{
fCallback = callback;
}


+ 36
- 11
dgl/src/ImageKnob.cpp View File

@@ -22,9 +22,10 @@ START_NAMESPACE_DGL

// -----------------------------------------------------------------------

ImageKnob::ImageKnob(Window& parent, const Image& image, Orientation orientation)
ImageKnob::ImageKnob(Window& parent, const Image& image, Orientation orientation, int id) noexcept
: Widget(parent),
fImage(image),
fId(id),
fMinimum(0.0f),
fMaximum(1.0f),
fStep(0.0f),
@@ -45,9 +46,10 @@ ImageKnob::ImageKnob(Window& parent, const Image& image, Orientation orientation
setSize(fImgLayerSize, fImgLayerSize);
}

ImageKnob::ImageKnob(Widget* widget, const Image& image, Orientation orientation)
ImageKnob::ImageKnob(Widget* widget, const Image& image, Orientation orientation, int id) noexcept
: Widget(widget->getParentWindow()),
fImage(image),
fId(id),
fMinimum(0.0f),
fMaximum(1.0f),
fStep(0.0f),
@@ -71,6 +73,7 @@ ImageKnob::ImageKnob(Widget* widget, const Image& image, Orientation orientation
ImageKnob::ImageKnob(const ImageKnob& imageKnob)
: Widget(imageKnob.getParentWindow()),
fImage(imageKnob.fImage),
fId(imageKnob.fId),
fMinimum(imageKnob.fMinimum),
fMaximum(imageKnob.fMaximum),
fStep(imageKnob.fStep),
@@ -98,12 +101,22 @@ ImageKnob::ImageKnob(const ImageKnob& imageKnob)
}
}

float ImageKnob::getValue() const
int ImageKnob::getId() const noexcept
{
return fId;
}

void ImageKnob::setId(int id) noexcept
{
fId = id;;
}

float ImageKnob::getValue() const noexcept
{
return fValue;
}

void ImageKnob::setOrientation(Orientation orientation)
void ImageKnob::setOrientation(Orientation orientation) noexcept
{
if (fOrientation == orientation)
return;
@@ -111,7 +124,7 @@ void ImageKnob::setOrientation(Orientation orientation)
fOrientation = orientation;
}

void ImageKnob::setRange(float min, float max)
void ImageKnob::setRange(float min, float max) noexcept
{
if (fValue < min)
{
@@ -119,7 +132,11 @@ void ImageKnob::setRange(float min, float max)
repaint();

if (fCallback != nullptr)
fCallback->imageKnobValueChanged(this, fValue);
{
try {
fCallback->imageKnobValueChanged(this, fValue);
} DISTRHO_SAFE_EXCEPTION("ImageKnob::setRange < min");
}
}
else if (fValue > max)
{
@@ -127,19 +144,23 @@ void ImageKnob::setRange(float min, float max)
repaint();

if (fCallback != nullptr)
fCallback->imageKnobValueChanged(this, fValue);
{
try {
fCallback->imageKnobValueChanged(this, fValue);
} DISTRHO_SAFE_EXCEPTION("ImageKnob::setRange > max");
}
}

fMinimum = min;
fMaximum = max;
}

void ImageKnob::setStep(float step)
void ImageKnob::setStep(float step) noexcept
{
fStep = step;
}

void ImageKnob::setValue(float value, bool sendCallback)
void ImageKnob::setValue(float value, bool sendCallback) noexcept
{
if (fValue == value)
return;
@@ -152,7 +173,11 @@ void ImageKnob::setValue(float value, bool sendCallback)
repaint();

if (sendCallback && fCallback != nullptr)
fCallback->imageKnobValueChanged(this, fValue);
{
try {
fCallback->imageKnobValueChanged(this, fValue);
} DISTRHO_SAFE_EXCEPTION("ImageKnob::setValue");
}
}

void ImageKnob::setRotationAngle(int angle)
@@ -192,7 +217,7 @@ void ImageKnob::setRotationAngle(int angle)
}
}

void ImageKnob::setCallback(Callback* callback)
void ImageKnob::setCallback(Callback* callback) noexcept
{
fCallback = callback;
}


+ 42
- 17
dgl/src/ImageSlider.cpp View File

@@ -22,9 +22,10 @@ START_NAMESPACE_DGL

// -----------------------------------------------------------------------

ImageSlider::ImageSlider(Window& parent, const Image& image)
ImageSlider::ImageSlider(Window& parent, const Image& image, int id) noexcept
: Widget(parent),
fImage(image),
fId(id),
fMinimum(0.0f),
fMaximum(1.0f),
fStep(0.0f),
@@ -39,9 +40,10 @@ ImageSlider::ImageSlider(Window& parent, const Image& image)
setSize(fImage.getSize());
}

ImageSlider::ImageSlider(Widget* widget, const Image& image)
ImageSlider::ImageSlider(Widget* widget, const Image& image, int id) noexcept
: Widget(widget->getParentWindow()),
fImage(image),
fId(id),
fMinimum(0.0f),
fMaximum(1.0f),
fStep(0.0f),
@@ -56,9 +58,10 @@ ImageSlider::ImageSlider(Widget* widget, const Image& image)
setSize(fImage.getSize());
}

ImageSlider::ImageSlider(const ImageSlider& imageSlider)
ImageSlider::ImageSlider(const ImageSlider& imageSlider) noexcept
: Widget(imageSlider.getParentWindow()),
fImage(imageSlider.fImage),
fId(imageSlider.fId),
fMinimum(imageSlider.fMinimum),
fMaximum(imageSlider.fMaximum),
fStep(imageSlider.fStep),
@@ -76,34 +79,44 @@ ImageSlider::ImageSlider(const ImageSlider& imageSlider)
setSize(fImage.getSize());
}

float ImageSlider::getValue() const
int ImageSlider::getId() const noexcept
{
return fId;
}

void ImageSlider::setId(int id) noexcept
{
fId = id;;
}

float ImageSlider::getValue() const noexcept
{
return fValue;
}

void ImageSlider::setStartPos(const Point<int>& startPos)
void ImageSlider::setStartPos(const Point<int>& startPos) noexcept
{
fStartPos = startPos;
_recheckArea();
}

void ImageSlider::setStartPos(int x, int y)
void ImageSlider::setStartPos(int x, int y) noexcept
{
setStartPos(Point<int>(x, y));
}

void ImageSlider::setEndPos(const Point<int>& endPos)
void ImageSlider::setEndPos(const Point<int>& endPos) noexcept
{
fEndPos = endPos;
_recheckArea();
}

void ImageSlider::setEndPos(int x, int y)
void ImageSlider::setEndPos(int x, int y) noexcept
{
setEndPos(Point<int>(x, y));
}

void ImageSlider::setInverted(bool inverted)
void ImageSlider::setInverted(bool inverted) noexcept
{
if (fInverted == inverted)
return;
@@ -112,7 +125,7 @@ void ImageSlider::setInverted(bool inverted)
repaint();
}

void ImageSlider::setRange(float min, float max)
void ImageSlider::setRange(float min, float max) noexcept
{
if (fValue < min)
{
@@ -120,7 +133,11 @@ void ImageSlider::setRange(float min, float max)
repaint();

if (fCallback != nullptr)
fCallback->imageSliderValueChanged(this, fValue);
{
try {
fCallback->imageSliderValueChanged(this, fValue);
} DISTRHO_SAFE_EXCEPTION("ImageSlider::setRange < min");
}
}
else if (fValue > max)
{
@@ -128,19 +145,23 @@ void ImageSlider::setRange(float min, float max)
repaint();

if (fCallback != nullptr)
fCallback->imageSliderValueChanged(this, fValue);
{
try {
fCallback->imageSliderValueChanged(this, fValue);
} DISTRHO_SAFE_EXCEPTION("ImageSlider::setRange > max");
}
}

fMinimum = min;
fMaximum = max;
}

void ImageSlider::setStep(float step)
void ImageSlider::setStep(float step) noexcept
{
fStep = step;
}

void ImageSlider::setValue(float value, bool sendCallback)
void ImageSlider::setValue(float value, bool sendCallback) noexcept
{
if (fValue == value)
return;
@@ -153,10 +174,14 @@ void ImageSlider::setValue(float value, bool sendCallback)
repaint();

if (sendCallback && fCallback != nullptr)
fCallback->imageSliderValueChanged(this, fValue);
{
try {
fCallback->imageSliderValueChanged(this, fValue);
} DISTRHO_SAFE_EXCEPTION("ImageSlider::setValue");
}
}

void ImageSlider::setCallback(Callback* callback)
void ImageSlider::setCallback(Callback* callback) noexcept
{
fCallback = callback;
}
@@ -333,7 +358,7 @@ bool ImageSlider::onMotion(int x, int y)
return true;
}

void ImageSlider::_recheckArea()
void ImageSlider::_recheckArea() noexcept
{
if (fStartPos.getY() == fEndPos.getY())
{


+ 11
- 11
dgl/src/Widget.cpp View File

@@ -73,7 +73,7 @@ const Point<int>& Widget::getPos() const noexcept
return fArea.getPos();
}

void Widget::setX(int x)
void Widget::setX(int x) noexcept
{
if (fArea.getX() == x)
return;
@@ -82,7 +82,7 @@ void Widget::setX(int x)
fParent.repaint();
}

void Widget::setY(int y)
void Widget::setY(int y) noexcept
{
if (fArea.getY() == y)
return;
@@ -91,12 +91,12 @@ void Widget::setY(int y)
fParent.repaint();
}

void Widget::setPos(int x, int y)
void Widget::setPos(int x, int y) noexcept
{
setPos(Point<int>(x, y));
}

void Widget::setPos(const Point<int>& pos)
void Widget::setPos(const Point<int>& pos) noexcept
{
if (fArea.getPos() == pos)
return;
@@ -120,7 +120,7 @@ const Size<int>& Widget::getSize() const noexcept
return fArea.getSize();
}

void Widget::setWidth(int width)
void Widget::setWidth(int width) noexcept
{
if (fArea.getWidth() == width)
return;
@@ -129,7 +129,7 @@ void Widget::setWidth(int width)
fParent.repaint();
}

void Widget::setHeight(int height)
void Widget::setHeight(int height) noexcept
{
if (fArea.getHeight() == height)
return;
@@ -138,12 +138,12 @@ void Widget::setHeight(int height)
fParent.repaint();
}

void Widget::setSize(int width, int height)
void Widget::setSize(int width, int height) noexcept
{
setSize(Size<int>(width, height));
}

void Widget::setSize(const Size<int>& size)
void Widget::setSize(const Size<int>& size) noexcept
{
if (fArea.getSize() == size)
return;
@@ -157,12 +157,12 @@ const Rectangle<int>& Widget::getArea() const noexcept
return fArea;
}

uint Widget::getEventTimestamp()
uint Widget::getEventTimestamp() const noexcept
{
return fParent.getEventTimestamp();
}

int Widget::getModifiers()
int Widget::getModifiers() const noexcept
{
return fParent.getModifiers();
}
@@ -177,7 +177,7 @@ Window& Widget::getParentWindow() const noexcept
return fParent;
}

void Widget::repaint()
void Widget::repaint() noexcept
{
fParent.repaint();
}


+ 8
- 8
dgl/src/Window.cpp View File

@@ -295,7 +295,7 @@ struct Window::PrivateData {
#endif
}

void repaint()
void repaint() noexcept
{
//DBG("Window repaint\n");
puglPostRedisplay(fView);
@@ -514,17 +514,17 @@ struct Window::PrivateData {
return fApp;
}

int getModifiers() const
int getModifiers() const noexcept
{
return puglGetModifiers(fView);
}

uint getEventTimestamp() const
uint getEventTimestamp() const noexcept
{
return puglGetEventTimestamp(fView);
}

intptr_t getWindowId() const
intptr_t getWindowId() const noexcept
{
return puglGetNativeWindow(fView);
}
@@ -894,7 +894,7 @@ void Window::focus()
pData->focus();
}

void Window::repaint()
void Window::repaint() noexcept
{
pData->repaint();
}
@@ -954,17 +954,17 @@ App& Window::getApp() const noexcept
return pData->getApp();
}

int Window::getModifiers() const
int Window::getModifiers() const noexcept
{
return pData->getModifiers();
}

uint Window::getEventTimestamp() const
uint Window::getEventTimestamp() const noexcept
{
return pData->getEventTimestamp();
}

intptr_t Window::getWindowId() const
intptr_t Window::getWindowId() const noexcept
{
return pData->getWindowId();
}


Loading…
Cancel
Save