Browse Source

dgl changes from Carla

gh-pages
falkTX 9 years ago
parent
commit
a9a1b47a14
16 changed files with 256 additions and 162 deletions
  1. +5
    -10
      dgl/ImageKnob.hpp
  2. +2
    -6
      dgl/ImageSlider.hpp
  3. +2
    -6
      dgl/ImageSwitch.hpp
  4. +4
    -3
      dgl/NanoVG.hpp
  5. +57
    -4
      dgl/Widget.hpp
  6. +1
    -1
      dgl/Window.hpp
  7. +6
    -6
      dgl/src/Color.cpp
  8. +2
    -2
      dgl/src/Geometry.cpp
  9. +4
    -2
      dgl/src/Image.cpp
  10. +25
    -35
      dgl/src/ImageKnob.cpp
  11. +11
    -25
      dgl/src/ImageSlider.cpp
  12. +2
    -16
      dgl/src/ImageSwitch.cpp
  13. +72
    -12
      dgl/src/NanoVG.cpp
  14. +11
    -0
      dgl/src/Widget.cpp
  15. +48
    -30
      dgl/src/Window.cpp
  16. +4
    -4
      dgl/src/nanovg/fontstash.h

+ 5
- 10
dgl/ImageKnob.hpp View File

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

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

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

float getValue() const noexcept;

void setDefault(float def) noexcept;
@@ -70,7 +67,6 @@ protected:

private:
Image fImage;
int fId;
float fMinimum;
float fMaximum;
float fStep;
@@ -89,11 +85,10 @@ private:
Callback* fCallback;

bool fIsImgVertical;
int fImgLayerSize;
int fImgLayerCount;
Rectangle<int> fKnobArea;
GLuint fTextureId;
uint fImgLayerSize;
uint fImgLayerCount;
bool fIsReady;
GLuint fTextureId;

float _logscale(float value) const;
float _invlogscale(float value) const;


+ 2
- 6
dgl/ImageSlider.hpp View File

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

explicit ImageSlider(Window& parent, const Image& image, int id = 0) noexcept;
explicit ImageSlider(Widget* widget, const Image& image, int id = 0) noexcept;
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;

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

float getValue() const noexcept;

void setStartPos(const Point<int>& startPos) noexcept;
@@ -65,7 +62,6 @@ protected:

private:
Image fImage;
int fId;
float fMinimum;
float fMaximum;
float fStep;


+ 2
- 6
dgl/ImageSwitch.hpp View File

@@ -34,14 +34,11 @@ public:
virtual void imageSwitchClicked(ImageSwitch* imageButton, bool down) = 0;
};

explicit ImageSwitch(Window& parent, const Image& imageNormal, const Image& imageDown, int id = 0) noexcept;
explicit ImageSwitch(Widget* widget, const Image& imageNormal, const Image& imageDown, int id = 0) noexcept;
explicit ImageSwitch(Window& parent, const Image& imageNormal, const Image& imageDown) noexcept;
explicit ImageSwitch(Widget* widget, const Image& imageNormal, const Image& imageDown) noexcept;
explicit ImageSwitch(const ImageSwitch& imageSwitch) noexcept;
ImageSwitch& operator=(const ImageSwitch& imageSwitch) noexcept;

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

bool isDown() const noexcept;
void setDown(bool down) noexcept;

@@ -55,7 +52,6 @@ private:
Image fImageNormal;
Image fImageDown;
bool fIsDown;
int fId;

Callback* fCallback;



+ 4
- 3
dgl/NanoVG.hpp View File

@@ -258,7 +258,7 @@ public:
/**
Destructor.
*/
~NanoVG();
virtual ~NanoVG();

/**
Get the NanoVG context.
@@ -641,7 +641,7 @@ public:
Creates font by loading it from the specified memory chunk.
Returns handle to the font.
*/
FontId createFontMem(const char* name, uchar* data, int ndata, bool freeData);
FontId createFontMem(const char* name, const uchar* data, int ndata, bool freeData);

/**
Finds a loaded font of specified name, and returns handle to it, or -1 if the font is not found.
@@ -761,7 +761,8 @@ public:
*/
NanoWidget(Window& parent)
: Widget(parent),
NanoVG()
NanoVG(),
leakDetector_NanoWidget()
{
setNeedsScaling(true);
}


+ 57
- 4
dgl/Widget.hpp View File

@@ -53,12 +53,17 @@ class Widget
public:
/**
Base event data.
@a mod The currently active keyboard modifiers.
@a mod The currently active keyboard modifiers, @see Modifier.
@a time The timestamp (if any).
*/
struct BaseEvent {
Modifier mod;
uint mod;
uint32_t time;

/** Constuctor */
BaseEvent() noexcept : mod(0x0), time(0) {}
/** Destuctor */
virtual ~BaseEvent() noexcept {}
};

/**
@@ -70,6 +75,12 @@ public:
struct KeyboardEvent : BaseEvent {
bool press;
uint key;

/** Constuctor */
KeyboardEvent() noexcept
: BaseEvent(),
press(false),
key(0) {}
};

/**
@@ -80,7 +91,13 @@ public:
*/
struct SpecialEvent : BaseEvent {
bool press;
Key key;
Key key;

/** Constuctor */
SpecialEvent() noexcept
: BaseEvent(),
press(false),
key(Key(0)) {}
};

/**
@@ -91,9 +108,16 @@ public:
@see onMouse
*/
struct MouseEvent : BaseEvent {
int button;
int button;
bool press;
Point<int> pos;

/** Constuctor */
MouseEvent() noexcept
: BaseEvent(),
button(0),
press(false),
pos(0, 0) {}
};

/**
@@ -103,6 +127,11 @@ public:
*/
struct MotionEvent : BaseEvent {
Point<int> pos;

/** Constuctor */
MotionEvent() noexcept
: BaseEvent(),
pos(0, 0) {}
};

/**
@@ -114,6 +143,12 @@ public:
struct ScrollEvent : BaseEvent {
Point<int> pos;
Point<float> delta;

/** Constuctor */
ScrollEvent() noexcept
: BaseEvent(),
pos(0, 0),
delta(0.0f, 0.0f) {}
};

/**
@@ -125,6 +160,11 @@ public:
struct ResizeEvent {
Size<uint> size;
Size<uint> oldSize;

/** Constuctor */
ResizeEvent() noexcept
: size(0, 0),
oldSize(0, 0) {}
};

/**
@@ -256,6 +296,18 @@ public:
*/
void repaint() noexcept;

/**
Get the Id associated with this widget.
@see setId
*/
uint getId() const noexcept;

/**
Set an Id to be associated with this widget.
@see getId
*/
void setId(uint id) noexcept;

protected:
/**
A function called to draw the view contents with OpenGL.
@@ -318,6 +370,7 @@ private:
bool fNeedsFullViewport;
bool fNeedsScaling;
bool fVisible;
uint fId;
Point<int> fAbsolutePos;
Size<uint> fSize;



+ 1
- 1
dgl/Window.hpp View File

@@ -56,7 +56,7 @@ public:

void setTitle(const char* title);

void setTransientWinId(intptr_t winId);
void setTransientWinId(uintptr_t winId);

App& getApp() const noexcept;
intptr_t getWindowId() const noexcept;


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

@@ -125,27 +125,27 @@ Color Color::fromHTML(const char* rgb, float alpha)
if (rgblen == 3)
{
rgbtmp[0] = rgb[0];
r = std::strtol(rgbtmp, nullptr, 16);
r = static_cast<int>(std::strtol(rgbtmp, nullptr, 16));

rgbtmp[0] = rgb[1];
g = std::strtol(rgbtmp, nullptr, 16);
g = static_cast<int>(std::strtol(rgbtmp, nullptr, 16));

rgbtmp[0] = rgb[2];
b = std::strtol(rgbtmp, nullptr, 16);
b = static_cast<int>(std::strtol(rgbtmp, nullptr, 16));
}
else
{
rgbtmp[0] = rgb[0];
rgbtmp[1] = rgb[1];
r = std::strtol(rgbtmp, nullptr, 16);
r = static_cast<int>(std::strtol(rgbtmp, nullptr, 16));

rgbtmp[0] = rgb[2];
rgbtmp[1] = rgb[3];
g = std::strtol(rgbtmp, nullptr, 16);
g = static_cast<int>(std::strtol(rgbtmp, nullptr, 16));

rgbtmp[0] = rgb[4];
rgbtmp[1] = rgb[5];
b = std::strtol(rgbtmp, nullptr, 16);
b = static_cast<int>(std::strtol(rgbtmp, nullptr, 16));
}

return Color(r, g, b, static_cast<int>(getFixedRange(alpha)*255.0f));


+ 2
- 2
dgl/src/Geometry.cpp View File

@@ -641,13 +641,13 @@ Circle<T>& Circle<T>::operator=(const Circle<T>& cir) noexcept
template<typename T>
bool Circle<T>::operator==(const Circle<T>& cir) const noexcept
{
return (fPos == cir.fPos && fSize == cir.fSize && fNumSegments == cir.fNumSegments);
return (fPos == cir.fPos && d_isEqual(fSize, cir.fSize) && fNumSegments == cir.fNumSegments);
}

template<typename T>
bool Circle<T>::operator!=(const Circle<T>& cir) const noexcept
{
return (fPos != cir.fPos || fSize != cir.fSize || fNumSegments != cir.fNumSegments);
return (fPos != cir.fPos || d_isNotEqual(fSize, cir.fSize) || fNumSegments != cir.fNumSegments);
}

template<typename T>


+ 4
- 2
dgl/src/Image.cpp View File

@@ -152,12 +152,14 @@ void Image::drawAt(const Point<int>& pos)

glPixelStorei(GL_PACK_ALIGNMENT, 1);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, fSize.getWidth(), fSize.getHeight(), 0, fFormat, fType, fRawData);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,
static_cast<GLsizei>(fSize.getWidth()), static_cast<GLsizei>(fSize.getHeight()), 0,
fFormat, fType, fRawData);

fIsReady = true;
}

Rectangle<int>(pos, fSize.getWidth(), fSize.getHeight()).draw();
Rectangle<int>(pos, static_cast<int>(fSize.getWidth()), static_cast<int>(fSize.getHeight())).draw();

glBindTexture(GL_TEXTURE_2D, 0);
glDisable(GL_TEXTURE_2D);


+ 25
- 35
dgl/src/ImageKnob.cpp View File

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

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

ImageKnob::ImageKnob(Window& parent, const Image& image, Orientation orientation, int id) noexcept
ImageKnob::ImageKnob(Window& parent, const Image& image, Orientation orientation) noexcept
: Widget(parent),
fImage(image),
fId(id),
fMinimum(0.0f),
fMaximum(1.0f),
fStep(0.0f),
@@ -43,19 +42,17 @@ ImageKnob::ImageKnob(Window& parent, const Image& image, Orientation orientation
fIsImgVertical(image.getHeight() > image.getWidth()),
fImgLayerSize(fIsImgVertical ? image.getWidth() : image.getHeight()),
fImgLayerCount(fIsImgVertical ? image.getHeight()/fImgLayerSize : image.getWidth()/fImgLayerSize),
fKnobArea(0, 0, fImgLayerSize, fImgLayerSize),
fTextureId(0),
fIsReady(false),
fTextureId(0),
leakDetector_ImageKnob()
{
glGenTextures(1, &fTextureId);
setSize(fImgLayerSize, fImgLayerSize);
}

ImageKnob::ImageKnob(Widget* widget, const Image& image, Orientation orientation, int id) noexcept
ImageKnob::ImageKnob(Widget* widget, const Image& image, Orientation orientation) noexcept
: Widget(widget->getParentWindow()),
fImage(image),
fId(id),
fMinimum(0.0f),
fMaximum(1.0f),
fStep(0.0f),
@@ -73,9 +70,8 @@ ImageKnob::ImageKnob(Widget* widget, const Image& image, Orientation orientation
fIsImgVertical(image.getHeight() > image.getWidth()),
fImgLayerSize(fIsImgVertical ? image.getWidth() : image.getHeight()),
fImgLayerCount(fIsImgVertical ? image.getHeight()/fImgLayerSize : image.getWidth()/fImgLayerSize),
fKnobArea(0, 0, fImgLayerSize, fImgLayerSize),
fTextureId(0),
fIsReady(false),
fTextureId(0),
leakDetector_ImageKnob()
{
glGenTextures(1, &fTextureId);
@@ -85,7 +81,6 @@ 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),
@@ -103,9 +98,8 @@ ImageKnob::ImageKnob(const ImageKnob& imageKnob)
fIsImgVertical(imageKnob.fIsImgVertical),
fImgLayerSize(imageKnob.fImgLayerSize),
fImgLayerCount(imageKnob.fImgLayerCount),
fKnobArea(imageKnob.fKnobArea),
fTextureId(0),
fIsReady(false),
fTextureId(0),
leakDetector_ImageKnob()
{
glGenTextures(1, &fTextureId);
@@ -115,7 +109,6 @@ ImageKnob::ImageKnob(const ImageKnob& imageKnob)
ImageKnob& ImageKnob::operator=(const ImageKnob& imageKnob)
{
fImage = imageKnob.fImage;
fId = imageKnob.fId;
fMinimum = imageKnob.fMinimum;
fMaximum = imageKnob.fMaximum;
fStep = imageKnob.fStep;
@@ -133,7 +126,6 @@ ImageKnob& ImageKnob::operator=(const ImageKnob& imageKnob)
fIsImgVertical = imageKnob.fIsImgVertical;
fImgLayerSize = imageKnob.fImgLayerSize;
fImgLayerCount = imageKnob.fImgLayerCount;
fKnobArea = imageKnob.fKnobArea;
fIsReady = false;

if (fTextureId != 0)
@@ -157,16 +149,6 @@ ImageKnob::~ImageKnob()
}
}

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

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

float ImageKnob::getValue() const noexcept
{
return fValue;
@@ -220,12 +202,12 @@ void ImageKnob::setStep(float step) noexcept
// NOTE: value is assumed to be scaled if using log
void ImageKnob::setValue(float value, bool sendCallback) noexcept
{
if (fValue == value)
if (d_isEqual(fValue, value))
return;

fValue = value;

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

if (fRotationAngle == 0)
@@ -288,36 +270,44 @@ void ImageKnob::onDisplay()
glPixelStorei(GL_PACK_ALIGNMENT, 1);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

int imageDataOffset = 0;
uint imageDataOffset = 0;

if (fRotationAngle == 0)
{
int layerDataSize = fImgLayerSize * fImgLayerSize * ((fImage.getFormat() == GL_BGRA || fImage.getFormat() == GL_RGBA) ? 4 : 3);
imageDataOffset = layerDataSize * int(normValue * float(fImgLayerCount-1));
DISTRHO_SAFE_ASSERT_RETURN(fImgLayerCount > 0,);
DISTRHO_SAFE_ASSERT_RETURN(normValue >= 0.0f,);

const uint layerDataSize = fImgLayerSize * fImgLayerSize * ((fImage.getFormat() == GL_BGRA || fImage.getFormat() == GL_RGBA) ? 4 : 3);
/* */ imageDataOffset = layerDataSize * uint(normValue * float(fImgLayerCount-1));
}

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, getWidth(), getHeight(), 0, fImage.getFormat(), fImage.getType(), fImage.getRawData() + imageDataOffset);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,
static_cast<GLsizei>(getWidth()), static_cast<GLsizei>(getHeight()), 0,
fImage.getFormat(), fImage.getType(), fImage.getRawData() + imageDataOffset);

fIsReady = true;
}

const int w = static_cast<int>(getWidth());
const int h = static_cast<int>(getHeight());

if (fRotationAngle != 0)
{
glPushMatrix();

const GLint w2 = getWidth()/2;
const GLint h2 = getHeight()/2;
const int w2 = w/2;
const int h2 = h/2;

glTranslatef(static_cast<float>(w2), static_cast<float>(h2), 0.0f);
glRotatef(normValue*static_cast<float>(fRotationAngle), 0.0f, 0.0f, 1.0f);

Rectangle<int>(-w2, -h2, getWidth(), getHeight()).draw();
Rectangle<int>(-w2, -h2, w, h).draw();

glPopMatrix();
}
else
{
Rectangle<int>(0, 0, getWidth(), getHeight()).draw();
Rectangle<int>(0, 0, w, h).draw();
}

glBindTexture(GL_TEXTURE_2D, 0);
@@ -403,7 +393,7 @@ bool ImageKnob::onMotion(const MotionEvent& ev)
{
fValueTmp = value = fMaximum;
}
else if (fStep != 0.0f)
else if (d_isNotZero(fStep))
{
fValueTmp = value;
const float rest = std::fmod(value, fStep);
@@ -437,7 +427,7 @@ bool ImageKnob::onScroll(const ScrollEvent& ev)
{
fValueTmp = value = fMaximum;
}
else if (fStep != 0.0f)
else if (d_isNotZero(fStep))
{
fValueTmp = value;
const float rest = std::fmod(value, fStep);


+ 11
- 25
dgl/src/ImageSlider.cpp View File

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

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

ImageSlider::ImageSlider(Window& parent, const Image& image, int id) noexcept
ImageSlider::ImageSlider(Window& parent, const Image& image) noexcept
: Widget(parent),
fImage(image),
fId(id),
fMinimum(0.0f),
fMaximum(1.0f),
fStep(0.0f),
@@ -44,10 +43,9 @@ ImageSlider::ImageSlider(Window& parent, const Image& image, int id) noexcept
Widget::setNeedsFullViewport(true);
}

ImageSlider::ImageSlider(Widget* widget, const Image& image, int id) noexcept
ImageSlider::ImageSlider(Widget* widget, const Image& image) noexcept
: Widget(widget->getParentWindow()),
fImage(image),
fId(id),
fMinimum(0.0f),
fMaximum(1.0f),
fStep(0.0f),
@@ -69,7 +67,6 @@ ImageSlider::ImageSlider(Widget* widget, const Image& image, int id) noexcept
ImageSlider::ImageSlider(const ImageSlider& imageSlider) noexcept
: Widget(imageSlider.getParentWindow()),
fImage(imageSlider.fImage),
fId(imageSlider.fId),
fMinimum(imageSlider.fMinimum),
fMaximum(imageSlider.fMaximum),
fStep(imageSlider.fStep),
@@ -91,7 +88,6 @@ ImageSlider::ImageSlider(const ImageSlider& imageSlider) noexcept
ImageSlider& ImageSlider::operator=(const ImageSlider& imageSlider) noexcept
{
fImage = imageSlider.fImage;
fId = imageSlider.fId;
fMinimum = imageSlider.fMinimum;
fMaximum = imageSlider.fMaximum;
fStep = imageSlider.fStep;
@@ -109,16 +105,6 @@ ImageSlider& ImageSlider::operator=(const ImageSlider& imageSlider) noexcept
return *this;
}

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

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

float ImageSlider::getValue() const noexcept
{
return fValue;
@@ -193,12 +179,12 @@ void ImageSlider::setStep(float step) noexcept

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

fValue = value;

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

repaint();
@@ -224,7 +210,7 @@ void ImageSlider::onDisplay()
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
#endif

float normValue = (fValue - fMinimum) / (fMaximum - fMinimum);
const float normValue = (fValue - fMinimum) / (fMaximum - fMinimum);

int x, y;

@@ -292,7 +278,7 @@ bool ImageSlider::onMouse(const MouseEvent& ev)
{
fValueTmp = value = fMaximum;
}
else if (fStep != 0.0f)
else if (d_isNotZero(fStep))
{
fValueTmp = value;
const float rest = std::fmod(value, fStep);
@@ -361,7 +347,7 @@ bool ImageSlider::onMotion(const MotionEvent& ev)
{
fValueTmp = value = fMaximum;
}
else if (fStep != 0.0f)
else if (d_isNotZero(fStep))
{
fValueTmp = value;
const float rest = std::fmod(value, fStep);
@@ -395,16 +381,16 @@ void ImageSlider::_recheckArea() noexcept
// horizontal
fSliderArea = Rectangle<int>(fStartPos.getX(),
fStartPos.getY(),
fEndPos.getX() + fImage.getWidth() - fStartPos.getX(),
fImage.getHeight());
fEndPos.getX() + static_cast<int>(fImage.getWidth()) - fStartPos.getX(),
static_cast<int>(fImage.getHeight()));
}
else
{
// vertical
fSliderArea = Rectangle<int>(fStartPos.getX(),
fStartPos.getY(),
fImage.getWidth(),
fEndPos.getY() + fImage.getHeight() - fStartPos.getY());
static_cast<int>(fImage.getWidth()),
fEndPos.getY() + static_cast<int>(fImage.getHeight()) - fStartPos.getY());
}
}



+ 2
- 16
dgl/src/ImageSwitch.cpp View File

@@ -20,12 +20,11 @@ START_NAMESPACE_DGL

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

ImageSwitch::ImageSwitch(Window& parent, const Image& imageNormal, const Image& imageDown, int id) noexcept
ImageSwitch::ImageSwitch(Window& parent, const Image& imageNormal, const Image& imageDown) noexcept
: Widget(parent),
fImageNormal(imageNormal),
fImageDown(imageDown),
fIsDown(false),
fId(id),
fCallback(nullptr),
leakDetector_ImageSwitch()
{
@@ -34,12 +33,11 @@ ImageSwitch::ImageSwitch(Window& parent, const Image& imageNormal, const Image&
setSize(fImageNormal.getSize());
}

ImageSwitch::ImageSwitch(Widget* widget, const Image& imageNormal, const Image& imageDown, int id) noexcept
ImageSwitch::ImageSwitch(Widget* widget, const Image& imageNormal, const Image& imageDown) noexcept
: Widget(widget->getParentWindow()),
fImageNormal(imageNormal),
fImageDown(imageDown),
fIsDown(false),
fId(id),
fCallback(nullptr),
leakDetector_ImageSwitch()
{
@@ -53,7 +51,6 @@ ImageSwitch::ImageSwitch(const ImageSwitch& imageSwitch) noexcept
fImageNormal(imageSwitch.fImageNormal),
fImageDown(imageSwitch.fImageDown),
fIsDown(imageSwitch.fIsDown),
fId(imageSwitch.fId),
fCallback(imageSwitch.fCallback),
leakDetector_ImageSwitch()
{
@@ -67,7 +64,6 @@ ImageSwitch& ImageSwitch::operator=(const ImageSwitch& imageSwitch) noexcept
fImageNormal = imageSwitch.fImageNormal;
fImageDown = imageSwitch.fImageDown;
fIsDown = imageSwitch.fIsDown;
fId = imageSwitch.fId;
fCallback = imageSwitch.fCallback;

DISTRHO_SAFE_ASSERT(fImageNormal.getSize() == fImageDown.getSize());
@@ -77,16 +73,6 @@ ImageSwitch& ImageSwitch::operator=(const ImageSwitch& imageSwitch) noexcept
return *this;
}

int ImageSwitch::getId() const noexcept
{
return fId;
}

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

bool ImageSwitch::isDown() const noexcept
{
return fIsDown;


+ 72
- 12
dgl/src/NanoVG.cpp View File

@@ -18,8 +18,32 @@
#include "../Window.hpp"

// -----------------------------------------------------------------------
// Ignore some warnings if debugging

#ifdef DEBUG
# define NANOVG_GL3 0
# define NANOVG_GLES2 0
# define NANOVG_GLES3 0
# define NANOVG_GL_USE_UNIFORMBUFFER 0
# if defined(__clang__)
# pragma clang diagnostic push
# pragma clang diagnostic ignored "-Weverything"
# elif defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Wall"
# pragma GCC diagnostic ignored "-Wextra"
# pragma GCC diagnostic ignored "-Wconversion"
# pragma GCC diagnostic ignored "-Weffc++"
# pragma GCC diagnostic ignored "-Wsign-conversion"
# pragma GCC diagnostic ignored "-Wundef"
# pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant"
# endif
#endif

// -----------------------------------------------------------------------
// Include NanoVG OpenGL implementation

#define NANOVG_GL2_IMPLEMENTATION
#define NANOVG_GL2_IMPLEMENTATION 1
#include "nanovg/nanovg_gl.h"

#if defined(NANOVG_GL2)
@@ -36,6 +60,19 @@
# define nvgDeleteGL nvgDeleteGLES3
#endif

// -----------------------------------------------------------------------
// Restore normal state if debugging

#ifdef DEBUG
# if defined(__clang__)
# pragma clang diagnostic pop
# elif defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))
# pragma GCC diagnostic pop
# endif
#endif

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

START_NAMESPACE_DGL

// -----------------------------------------------------------------------
@@ -75,7 +112,8 @@ NanoVG::Paint::operator NVGpaint() const noexcept
NanoImage::NanoImage(NVGcontext* const context, const int imageId) noexcept
: fContext(context),
fImageId(imageId),
fSize()
fSize(),
leakDetector_NanoImage()
{
_updateSize();
}
@@ -114,7 +152,7 @@ void NanoImage::_updateSize()
if (h < 0) h = 0;
}

fSize.setSize(w, h);
fSize.setSize(static_cast<uint>(w), static_cast<uint>(h));
}

// -----------------------------------------------------------------------
@@ -122,14 +160,16 @@ void NanoImage::_updateSize()

NanoVG::NanoVG()
: fContext(nvgCreateGL(512, 512, NVG_ANTIALIAS)),
fInFrame(false)
fInFrame(false),
leakDetector_NanoVG()
{
DISTRHO_SAFE_ASSERT_RETURN(fContext != nullptr,);
}

NanoVG::NanoVG(const int textAtlasWidth, const int textAtlasHeight)
: fContext(nvgCreateGL(textAtlasWidth, textAtlasHeight, NVG_ANTIALIAS)),
fInFrame(false)
fInFrame(false),
leakDetector_NanoVG()
{
DISTRHO_SAFE_ASSERT_RETURN(fContext != nullptr,);
}
@@ -151,7 +191,7 @@ void NanoVG::beginFrame(const uint width, const uint height, const float scaleFa
DISTRHO_SAFE_ASSERT_RETURN(! fInFrame,);

fInFrame = true;
nvgBeginFrame(fContext, width, height, scaleFactor, static_cast<NVGalpha>(alpha));
nvgBeginFrame(fContext, static_cast<int>(width), static_cast<int>(height), scaleFactor, static_cast<NVGalpha>(alpha));
}

void NanoVG::beginFrame(Widget* const widget)
@@ -163,7 +203,7 @@ void NanoVG::beginFrame(Widget* const widget)
Window& window(widget->getParentWindow());

fInFrame = true;
nvgBeginFrame(fContext, window.getWidth(), window.getHeight(), 1.0f, NVG_PREMULTIPLIED_ALPHA);
nvgBeginFrame(fContext, static_cast<int>(window.getWidth()), static_cast<int>(window.getHeight()), 1.0f, NVG_PREMULTIPLIED_ALPHA);
}

void NanoVG::endFrame()
@@ -209,7 +249,17 @@ void NanoVG::strokeColor(const Color& color)
void NanoVG::strokeColor(const int red, const int green, const int blue, const int alpha)
{
if (fContext != nullptr)
nvgStrokeColor(fContext, nvgRGBA(red, green, blue, alpha));
{
DISTRHO_SAFE_ASSERT_RETURN(red >= 0 && red <= 255,);
DISTRHO_SAFE_ASSERT_RETURN(green >= 0 && green <= 255,);
DISTRHO_SAFE_ASSERT_RETURN(blue >= 0 && blue <= 255,);
DISTRHO_SAFE_ASSERT_RETURN(alpha >= 0 && alpha <= 255,);

nvgStrokeColor(fContext, nvgRGBA(static_cast<uchar>(red),
static_cast<uchar>(green),
static_cast<uchar>(blue),
static_cast<uchar>(alpha)));
}
}

void NanoVG::strokeColor(const float red, const float green, const float blue, const float alpha)
@@ -233,7 +283,17 @@ void NanoVG::fillColor(const Color& color)
void NanoVG::fillColor(const int red, const int green, const int blue, const int alpha)
{
if (fContext != nullptr)
nvgFillColor(fContext, nvgRGBA(red, green, blue, alpha));
{
DISTRHO_SAFE_ASSERT_RETURN(red >= 0 && red <= 255,);
DISTRHO_SAFE_ASSERT_RETURN(green >= 0 && green <= 255,);
DISTRHO_SAFE_ASSERT_RETURN(blue >= 0 && blue <= 255,);
DISTRHO_SAFE_ASSERT_RETURN(alpha >= 0 && alpha <= 255,);

nvgFillColor(fContext, nvgRGBA(static_cast<uchar>(red),
static_cast<uchar>(green),
static_cast<uchar>(blue),
static_cast<uchar>(alpha)));
}
}

void NanoVG::fillColor(const float red, const float green, const float blue, const float alpha)
@@ -427,7 +487,7 @@ NanoImage* NanoVG::createImageRGBA(uint w, uint h, const uchar* data)
if (fContext == nullptr) return nullptr;
DISTRHO_SAFE_ASSERT_RETURN(data != nullptr, nullptr);

if (const int imageId = nvgCreateImageRGBA(fContext, w, h, data))
if (const int imageId = nvgCreateImageRGBA(fContext, static_cast<int>(w), static_cast<int>(h), data))
return new NanoImage(fContext, imageId);

return nullptr;
@@ -576,13 +636,13 @@ NanoVG::FontId NanoVG::createFont(const char* name, const char* filename)
return nvgCreateFont(fContext, name, filename);
}

NanoVG::FontId NanoVG::createFontMem(const char* name, uchar* data, int ndata, bool freeData)
NanoVG::FontId NanoVG::createFontMem(const char* name, const uchar* data, int ndata, bool freeData)
{
if (fContext == nullptr) return -1;
DISTRHO_SAFE_ASSERT_RETURN(name != nullptr && name[0] != '\0', -1);
DISTRHO_SAFE_ASSERT_RETURN(data != nullptr, -1);

return nvgCreateFontMem(fContext, name, data, ndata, freeData);
return nvgCreateFontMem(fContext, name, const_cast<uchar*>(data), ndata, freeData);
}

NanoVG::FontId NanoVG::findFont(const char* name)


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

@@ -27,6 +27,7 @@ Widget::Widget(Window& parent)
fNeedsFullViewport(false),
fNeedsScaling(false),
fVisible(true),
fId(0),
fAbsolutePos(0, 0),
fSize(0, 0),
leakDetector_Widget()
@@ -200,6 +201,16 @@ void Widget::repaint() noexcept
fParent.repaint();
}

uint Widget::getId() const noexcept
{
return fId;
}

void Widget::setId(uint id) noexcept
{
fId = id;
}

bool Widget::onKeyboard(const KeyboardEvent&)
{
return false;


+ 48
- 30
dgl/src/Window.cpp View File

@@ -70,6 +70,7 @@ struct Window::PrivateData {
fUsingEmbed(false),
fWidth(1),
fHeight(1),
fWidgets(),
fModal(),
#if defined(DISTRHO_OS_WINDOWS)
hwnd(0),
@@ -97,6 +98,7 @@ struct Window::PrivateData {
fUsingEmbed(false),
fWidth(1),
fHeight(1),
fWidgets(),
fModal(parent.pData),
#if defined(DISTRHO_OS_WINDOWS)
hwnd(0),
@@ -134,6 +136,7 @@ struct Window::PrivateData {
fUsingEmbed(parentId != 0),
fWidth(1),
fHeight(1),
fWidgets(),
fModal(),
#if defined(DISTRHO_OS_WINDOWS)
hwnd(0),
@@ -177,7 +180,7 @@ struct Window::PrivateData {
}

puglInitResizable(fView, fResizable);
puglInitWindowSize(fView, fWidth, fHeight);
puglInitWindowSize(fView, static_cast<int>(fWidth), static_cast<int>(fHeight));

puglSetHandle(fView, this);
puglSetDisplayFunc(fView, onDisplayCallback);
@@ -554,7 +557,7 @@ struct Window::PrivateData {
#endif
}

void setTransientWinId(const intptr_t winId)
void setTransientWinId(const uintptr_t winId)
{
#if defined(DISTRHO_OS_LINUX)
XSetTransientForHint(xDisplay, xWindow, static_cast< ::Window>(winId));
@@ -611,7 +614,7 @@ struct Window::PrivateData {

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

void onDisplay()
void onPuglDisplay()
{
fSelf->onDisplayBefore();

@@ -629,22 +632,35 @@ struct Window::PrivateData {
if (widget->fNeedsFullViewport || (widget->fAbsolutePos.isZero() && widget->fSize == Size<uint>(fWidth, fHeight)))
{
// full viewport size
glViewport(0, 0, fWidth, fHeight);
glViewport(0,
0,
static_cast<GLsizei>(fWidth),
static_cast<GLsizei>(fHeight));
}
else if (! widget->fNeedsScaling)
{
// only set viewport pos
glViewport(widget->getAbsoluteX(), /*fView->height - widget->getHeight()*/ - widget->getAbsoluteY(), fWidth, fHeight);
glViewport(widget->getAbsoluteX(),
/*fView->height - static_cast<int>(widget->getHeight())*/ - widget->getAbsoluteY(),
static_cast<GLsizei>(fWidth),
static_cast<GLsizei>(fHeight));

// then cut the outer bounds
glScissor(widget->getAbsoluteX(), fView->height - widget->getHeight() - widget->getAbsoluteY(), widget->getWidth(), widget->getHeight());
glScissor(widget->getAbsoluteX(),
fView->height - static_cast<int>(widget->getHeight()) - widget->getAbsoluteY(),
static_cast<GLsizei>(widget->getWidth()),
static_cast<GLsizei>(widget->getHeight()));

glEnable(GL_SCISSOR_TEST);
needsDisableScissor = true;
}
else
{
// limit viewport to widget bounds
glViewport(widget->getAbsoluteX(), fView->height - widget->getHeight() - widget->getAbsoluteY(), widget->getWidth(), widget->getHeight());
glViewport(widget->getAbsoluteX(),
fView->height - static_cast<int>(widget->getHeight()) - widget->getAbsoluteY(),
static_cast<GLsizei>(widget->getWidth()),
static_cast<GLsizei>(widget->getHeight()));
}

// display widget
@@ -661,7 +677,7 @@ struct Window::PrivateData {
fSelf->onDisplayAfter();
}

void onKeyboard(const bool press, const uint key)
void onPuglKeyboard(const bool press, const uint key)
{
DBGp("PUGL: onKeyboard : %i %i\n", press, key);

@@ -683,7 +699,7 @@ struct Window::PrivateData {
}
}

void onSpecial(const bool press, const Key key)
void onPuglSpecial(const bool press, const Key key)
{
DBGp("PUGL: onSpecial : %i %i\n", press, key);

@@ -705,7 +721,7 @@ struct Window::PrivateData {
}
}

void onMouse(const int button, const bool press, const int x, const int y)
void onPuglMouse(const int button, const bool press, const int x, const int y)
{
DBGp("PUGL: onMouse : %i %i %i %i\n", button, press, x, y);

@@ -732,7 +748,7 @@ struct Window::PrivateData {
}
}

void onMotion(const int x, const int y)
void onPuglMotion(const int x, const int y)
{
DBGp("PUGL: onMotion : %i %i\n", x, y);

@@ -754,7 +770,7 @@ struct Window::PrivateData {
}
}

void onScroll(const int x, const int y, const float dx, const float dy)
void onPuglScroll(const int x, const int y, const float dx, const float dy)
{
DBGp("PUGL: onScroll : %i %i %f %f\n", x, y, dx, dy);

@@ -777,28 +793,28 @@ struct Window::PrivateData {
}
}

void onReshape(const int width, const int height)
void onPuglReshape(const int width, const int height)
{
DBGp("PUGL: onReshape : %i %i\n", width, height);

if (width <= 1 && height <= 1)
return;

fWidth = width;
fHeight = height;
fWidth = static_cast<uint>(width);
fHeight = static_cast<uint>(height);

fSelf->onReshape(width, height);
fSelf->onReshape(fWidth, fHeight);

FOR_EACH_WIDGET(it)
{
Widget* const widget(*it);

if (widget->fNeedsFullViewport)
widget->setSize(width, height);
widget->setSize(fWidth, fHeight);
}
}

void onClose()
void onPuglClose()
{
DBG("PUGL: onClose\n");

@@ -808,7 +824,7 @@ struct Window::PrivateData {
fSelf->onClose();

if (fModal.childFocus != nullptr)
fModal.childFocus->onClose();
fModal.childFocus->fSelf->onClose();

close();
}
@@ -847,6 +863,8 @@ struct Window::PrivateData {
DISTRHO_SAFE_ASSERT(! enabled);
DISTRHO_SAFE_ASSERT(childFocus == nullptr);
}

DISTRHO_DECLARE_NON_COPY_STRUCT(Modal)
} fModal;

#if defined(DISTRHO_OS_WINDOWS)
@@ -867,42 +885,42 @@ struct Window::PrivateData {

static void onDisplayCallback(PuglView* view)
{
handlePtr->onDisplay();
handlePtr->onPuglDisplay();
}

static void onKeyboardCallback(PuglView* view, bool press, uint32_t key)
{
handlePtr->onKeyboard(press, key);
handlePtr->onPuglKeyboard(press, key);
}

static void onSpecialCallback(PuglView* view, bool press, PuglKey key)
{
handlePtr->onSpecial(press, static_cast<Key>(key));
handlePtr->onPuglSpecial(press, static_cast<Key>(key));
}

static void onMouseCallback(PuglView* view, int button, bool press, int x, int y)
{
handlePtr->onMouse(button, press, x, y);
handlePtr->onPuglMouse(button, press, x, y);
}

static void onMotionCallback(PuglView* view, int x, int y)
{
handlePtr->onMotion(x, y);
handlePtr->onPuglMotion(x, y);
}

static void onScrollCallback(PuglView* view, int x, int y, float dx, float dy)
{
handlePtr->onScroll(x, y, dx, dy);
handlePtr->onPuglScroll(x, y, dx, dy);
}

static void onReshapeCallback(PuglView* view, int width, int height)
{
handlePtr->onReshape(width, height);
handlePtr->onPuglReshape(width, height);
}

static void onCloseCallback(PuglView* view)
{
handlePtr->onClose();
handlePtr->onPuglClose();
}

#undef handlePtr
@@ -1010,7 +1028,7 @@ void Window::setTitle(const char* title)
pData->setTitle(title);
}

void Window::setTransientWinId(intptr_t winId)
void Window::setTransientWinId(uintptr_t winId)
{
pData->setTransientWinId(winId);
}
@@ -1074,8 +1092,8 @@ void Window::onReshape(uint width, uint height)
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, width, height, 0, 0.0f, 1.0f);
glViewport(0, 0, width, height);
glOrtho(0.0, static_cast<GLdouble>(width), static_cast<GLdouble>(height), 0.0, 0.0, 1.0);
glViewport(0, 0, static_cast<GLsizei>(width), static_cast<GLsizei>(height));
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}


+ 4
- 4
dgl/src/nanovg/fontstash.h View File

@@ -41,7 +41,7 @@ enum FONSalign {
enum FONSerrorCode {
// Font atlas is full.
FONS_ATLAS_FULL = 1,
// Scratch memory used to render glyphs is full, requested size reported in 'val', you may need to bump up FONS_SCRATCH_BUF_SIZE.
// Scratch memory used to render glyphs is full, requested size reported in 'val', you may need to bump up FONS_SCRATCH_BUF_SIZE.
FONS_SCRATCH_FULL = 2,
// Calls to fonsPushState has craeted too large stack, if you need deep state stack bump up FONS_MAX_STATES.
FONS_STATES_OVERFLOW = 3,
@@ -85,7 +85,7 @@ void fonsDeleteInternal(struct FONScontext* s);
void fonsSetErrorCallback(struct FONScontext* s, void (*callback)(void* uptr, int error, int val), void* uptr);
// Returns current atlas size.
void fonsGetAtlasSize(struct FONScontext* s, int* width, int* height);
// Expands the atlas size.
// Expands the atlas size.
int fonsExpandAtlas(struct FONScontext* s, int width, int height);
// Reseta the whole stash.
int fonsResetAtlas(struct FONScontext* stash, int width, int height);
@@ -1388,7 +1388,7 @@ void fonsDrawDebug(struct FONScontext* stash, float x, float y)
}

float fonsTextBounds(struct FONScontext* stash,
float x, float y,
float x, float y,
const char* str, const char* end,
float* bounds)
{
@@ -1576,7 +1576,7 @@ int fonsExpandAtlas(struct FONScontext* stash, int width, int height)
height = fons__maxi(height, stash->params.height);

if (width == stash->params.width && height == stash->params.height)
return 1;
return 1;

// Flush pending glyphs.
fons__flush(stash);


Loading…
Cancel
Save