Browse Source

Implement ImageSlider::setStep

gh-pages
falkTX 10 years ago
parent
commit
b4ec56fb2a
4 changed files with 50 additions and 40 deletions
  1. +3
    -2
      dgl/ImageSlider.hpp
  2. +1
    -1
      dgl/src/ImageKnob.cpp
  3. +45
    -36
      dgl/src/ImageSlider.cpp
  4. +1
    -1
      examples/nekobi-ui_src/DistrhoUINekobi.cpp

+ 3
- 2
dgl/ImageSlider.hpp View File

@@ -48,8 +48,8 @@ public:
void setEndPos(int x, int y);

void setRange(float min, float max);
void setStep(float step);
void setValue(float value, bool sendCallback = false);
void setIsSwitch(bool yesNo);

void setCallback(Callback* callback);

@@ -62,9 +62,10 @@ private:
Image fImage;
float fMinimum;
float fMaximum;
float fStep;
float fValue;
float fValueTmp;

bool fIsSwitch;
bool fDragging;
int fStartedX;
int fStartedY;


+ 1
- 1
dgl/src/ImageKnob.cpp View File

@@ -303,7 +303,7 @@ bool ImageKnob::onMotion(int x, int y)
if (int movX = x - fLastX)
{
d = (getModifiers() & MODIFIER_SHIFT) ? 2000.0f : 200.0f;
value = fValue + (float(fMaximum - fMinimum) / d * float(movX));
value = fValueTmp + (float(fMaximum - fMinimum) / d * float(movX));
doVal = true;
}
}


+ 45
- 36
dgl/src/ImageSlider.cpp View File

@@ -16,6 +16,8 @@

#include "../ImageSlider.hpp"

#include <cmath>

START_NAMESPACE_DGL

// -----------------------------------------------------------------------
@@ -25,8 +27,9 @@ ImageSlider::ImageSlider(Window& parent, const Image& image)
fImage(image),
fMinimum(0.0f),
fMaximum(1.0f),
fStep(0.0f),
fValue(0.5f),
fIsSwitch(false),
fValueTmp(fValue),
fDragging(false),
fStartedX(0),
fStartedY(0),
@@ -40,8 +43,9 @@ ImageSlider::ImageSlider(Widget* widget, const Image& image)
fImage(image),
fMinimum(0.0f),
fMaximum(1.0f),
fStep(0.0f),
fValue(0.5f),
fIsSwitch(false),
fValueTmp(fValue),
fDragging(false),
fStartedX(0),
fStartedY(0),
@@ -55,8 +59,9 @@ ImageSlider::ImageSlider(const ImageSlider& imageSlider)
fImage(imageSlider.fImage),
fMinimum(imageSlider.fMinimum),
fMaximum(imageSlider.fMaximum),
fStep(imageSlider.fStep),
fValue(imageSlider.fValue),
fIsSwitch(imageSlider.fIsSwitch),
fValueTmp(fValue),
fDragging(false),
fStartedX(0),
fStartedY(0),
@@ -118,27 +123,27 @@ void ImageSlider::setRange(float min, float max)
fMaximum = max;
}

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

void ImageSlider::setValue(float value, bool sendCallback)
{
if (fValue == value)
return;

fValue = value;

if (fStep == 0.0f)
fValueTmp = value;

repaint();

if (sendCallback && fCallback != nullptr)
fCallback->imageSliderValueChanged(this, fValue);
}

void ImageSlider::setIsSwitch(bool yesNo)
{
if (fIsSwitch == yesNo)
return;

fIsSwitch = yesNo;
repaint();
}

void ImageSlider::setCallback(Callback* callback)
{
fCallback = callback;
@@ -198,21 +203,23 @@ bool ImageSlider::onMouse(int button, bool press, int x, int y)

float value;

if (fIsSwitch)
value = fMaximum - vper * (fMaximum - fMinimum);

if (value < fMinimum)
{
if (vper < 0.5f)
value = fMaximum;
else
value = fMinimum;
value = fMinimum;
fValueTmp = value;
}
else
else if (value > fMaximum)
{
value = fMaximum - vper * (fMaximum - fMinimum);

if (value < fMinimum)
value = fMinimum;
else if (value > fMaximum)
value = fMaximum;
value = fMaximum;
fValueTmp = value;
}
else if (fStep != 0.0f)
{
fValueTmp = value;
const float rest = std::fmod(value, fStep);
value = value - rest + (rest > fStep/2.0f ? fStep : 0.0f);
}

fDragging = true;
@@ -262,21 +269,23 @@ bool ImageSlider::onMotion(int x, int y)

float value;

if (fIsSwitch)
value = fMaximum - vper * (fMaximum - fMinimum);

if (value < fMinimum)
{
if (vper < 0.5f)
value = fMaximum;
else
value = fMinimum;
value = fMinimum;
fValueTmp = value;
}
else
else if (value > fMaximum)
{
value = fMaximum - vper * (fMaximum - fMinimum);

if (value < fMinimum)
value = fMinimum;
else if (value > fMaximum)
value = fMaximum;
value = fMaximum;
fValueTmp = value;
}
else if (fStep != 0.0f)
{
fValueTmp = value;
const float rest = std::fmod(value, fStep);
value = value - rest + (rest > fStep/2.0f ? fStep : 0.0f);
}

setValue(value, true);


+ 1
- 1
examples/nekobi-ui_src/DistrhoUINekobi.cpp View File

@@ -41,7 +41,7 @@ DistrhoUINekobi::DistrhoUINekobi(DGL::Window& parent)
fSliderWaveform->setEndPos(133, 60);
fSliderWaveform->setRange(0.0f, 1.0f);
fSliderWaveform->setValue(0.0f);
fSliderWaveform->setIsSwitch(true);
fSliderWaveform->setStep(1.0f);

// knobs
Image knobImage(DistrhoArtworkNekobi::knobData, DistrhoArtworkNekobi::knobWidth, DistrhoArtworkNekobi::knobHeight);


Loading…
Cancel
Save