@@ -41,15 +41,12 @@ public: | |||||
virtual void imageKnobValueChanged(ImageKnob* imageKnob, float value) = 0; | 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); | explicit ImageKnob(const ImageKnob& imageKnob); | ||||
ImageKnob& operator=(const ImageKnob& imageKnob); | ImageKnob& operator=(const ImageKnob& imageKnob); | ||||
~ImageKnob() override; | ~ImageKnob() override; | ||||
int getId() const noexcept; | |||||
void setId(int id) noexcept; | |||||
float getValue() const noexcept; | float getValue() const noexcept; | ||||
void setDefault(float def) noexcept; | void setDefault(float def) noexcept; | ||||
@@ -70,7 +67,6 @@ protected: | |||||
private: | private: | ||||
Image fImage; | Image fImage; | ||||
int fId; | |||||
float fMinimum; | float fMinimum; | ||||
float fMaximum; | float fMaximum; | ||||
float fStep; | float fStep; | ||||
@@ -89,11 +85,10 @@ private: | |||||
Callback* fCallback; | Callback* fCallback; | ||||
bool fIsImgVertical; | bool fIsImgVertical; | ||||
int fImgLayerSize; | |||||
int fImgLayerCount; | |||||
Rectangle<int> fKnobArea; | |||||
GLuint fTextureId; | |||||
uint fImgLayerSize; | |||||
uint fImgLayerCount; | |||||
bool fIsReady; | bool fIsReady; | ||||
GLuint fTextureId; | |||||
float _logscale(float value) const; | float _logscale(float value) const; | ||||
float _invlogscale(float value) const; | float _invlogscale(float value) const; | ||||
@@ -36,14 +36,11 @@ public: | |||||
virtual void imageSliderValueChanged(ImageSlider* imageSlider, float value) = 0; | 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; | explicit ImageSlider(const ImageSlider& imageSlider) noexcept; | ||||
ImageSlider& operator=(const ImageSlider& imageSlider) noexcept; | ImageSlider& operator=(const ImageSlider& imageSlider) noexcept; | ||||
int getId() const noexcept; | |||||
void setId(int id) noexcept; | |||||
float getValue() const noexcept; | float getValue() const noexcept; | ||||
void setStartPos(const Point<int>& startPos) noexcept; | void setStartPos(const Point<int>& startPos) noexcept; | ||||
@@ -65,7 +62,6 @@ protected: | |||||
private: | private: | ||||
Image fImage; | Image fImage; | ||||
int fId; | |||||
float fMinimum; | float fMinimum; | ||||
float fMaximum; | float fMaximum; | ||||
float fStep; | float fStep; | ||||
@@ -34,14 +34,11 @@ public: | |||||
virtual void imageSwitchClicked(ImageSwitch* imageButton, bool down) = 0; | 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; | explicit ImageSwitch(const ImageSwitch& imageSwitch) noexcept; | ||||
ImageSwitch& operator=(const ImageSwitch& imageSwitch) noexcept; | ImageSwitch& operator=(const ImageSwitch& imageSwitch) noexcept; | ||||
int getId() const noexcept; | |||||
void setId(int id) noexcept; | |||||
bool isDown() const noexcept; | bool isDown() const noexcept; | ||||
void setDown(bool down) noexcept; | void setDown(bool down) noexcept; | ||||
@@ -55,7 +52,6 @@ private: | |||||
Image fImageNormal; | Image fImageNormal; | ||||
Image fImageDown; | Image fImageDown; | ||||
bool fIsDown; | bool fIsDown; | ||||
int fId; | |||||
Callback* fCallback; | Callback* fCallback; | ||||
@@ -258,7 +258,7 @@ public: | |||||
/** | /** | ||||
Destructor. | Destructor. | ||||
*/ | */ | ||||
~NanoVG(); | |||||
virtual ~NanoVG(); | |||||
/** | /** | ||||
Get the NanoVG context. | Get the NanoVG context. | ||||
@@ -641,7 +641,7 @@ public: | |||||
Creates font by loading it from the specified memory chunk. | Creates font by loading it from the specified memory chunk. | ||||
Returns handle to the font. | 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. | 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) | NanoWidget(Window& parent) | ||||
: Widget(parent), | : Widget(parent), | ||||
NanoVG() | |||||
NanoVG(), | |||||
leakDetector_NanoWidget() | |||||
{ | { | ||||
setNeedsScaling(true); | setNeedsScaling(true); | ||||
} | } | ||||
@@ -53,12 +53,17 @@ class Widget | |||||
public: | public: | ||||
/** | /** | ||||
Base event data. | 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). | @a time The timestamp (if any). | ||||
*/ | */ | ||||
struct BaseEvent { | struct BaseEvent { | ||||
Modifier mod; | |||||
uint mod; | |||||
uint32_t time; | uint32_t time; | ||||
/** Constuctor */ | |||||
BaseEvent() noexcept : mod(0x0), time(0) {} | |||||
/** Destuctor */ | |||||
virtual ~BaseEvent() noexcept {} | |||||
}; | }; | ||||
/** | /** | ||||
@@ -70,6 +75,12 @@ public: | |||||
struct KeyboardEvent : BaseEvent { | struct KeyboardEvent : BaseEvent { | ||||
bool press; | bool press; | ||||
uint key; | uint key; | ||||
/** Constuctor */ | |||||
KeyboardEvent() noexcept | |||||
: BaseEvent(), | |||||
press(false), | |||||
key(0) {} | |||||
}; | }; | ||||
/** | /** | ||||
@@ -80,7 +91,13 @@ public: | |||||
*/ | */ | ||||
struct SpecialEvent : BaseEvent { | struct SpecialEvent : BaseEvent { | ||||
bool press; | bool press; | ||||
Key key; | |||||
Key key; | |||||
/** Constuctor */ | |||||
SpecialEvent() noexcept | |||||
: BaseEvent(), | |||||
press(false), | |||||
key(Key(0)) {} | |||||
}; | }; | ||||
/** | /** | ||||
@@ -91,9 +108,16 @@ public: | |||||
@see onMouse | @see onMouse | ||||
*/ | */ | ||||
struct MouseEvent : BaseEvent { | struct MouseEvent : BaseEvent { | ||||
int button; | |||||
int button; | |||||
bool press; | bool press; | ||||
Point<int> pos; | Point<int> pos; | ||||
/** Constuctor */ | |||||
MouseEvent() noexcept | |||||
: BaseEvent(), | |||||
button(0), | |||||
press(false), | |||||
pos(0, 0) {} | |||||
}; | }; | ||||
/** | /** | ||||
@@ -103,6 +127,11 @@ public: | |||||
*/ | */ | ||||
struct MotionEvent : BaseEvent { | struct MotionEvent : BaseEvent { | ||||
Point<int> pos; | Point<int> pos; | ||||
/** Constuctor */ | |||||
MotionEvent() noexcept | |||||
: BaseEvent(), | |||||
pos(0, 0) {} | |||||
}; | }; | ||||
/** | /** | ||||
@@ -114,6 +143,12 @@ public: | |||||
struct ScrollEvent : BaseEvent { | struct ScrollEvent : BaseEvent { | ||||
Point<int> pos; | Point<int> pos; | ||||
Point<float> delta; | Point<float> delta; | ||||
/** Constuctor */ | |||||
ScrollEvent() noexcept | |||||
: BaseEvent(), | |||||
pos(0, 0), | |||||
delta(0.0f, 0.0f) {} | |||||
}; | }; | ||||
/** | /** | ||||
@@ -125,6 +160,11 @@ public: | |||||
struct ResizeEvent { | struct ResizeEvent { | ||||
Size<uint> size; | Size<uint> size; | ||||
Size<uint> oldSize; | Size<uint> oldSize; | ||||
/** Constuctor */ | |||||
ResizeEvent() noexcept | |||||
: size(0, 0), | |||||
oldSize(0, 0) {} | |||||
}; | }; | ||||
/** | /** | ||||
@@ -256,6 +296,18 @@ public: | |||||
*/ | */ | ||||
void repaint() noexcept; | 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: | protected: | ||||
/** | /** | ||||
A function called to draw the view contents with OpenGL. | A function called to draw the view contents with OpenGL. | ||||
@@ -318,6 +370,7 @@ private: | |||||
bool fNeedsFullViewport; | bool fNeedsFullViewport; | ||||
bool fNeedsScaling; | bool fNeedsScaling; | ||||
bool fVisible; | bool fVisible; | ||||
uint fId; | |||||
Point<int> fAbsolutePos; | Point<int> fAbsolutePos; | ||||
Size<uint> fSize; | Size<uint> fSize; | ||||
@@ -56,7 +56,7 @@ public: | |||||
void setTitle(const char* title); | void setTitle(const char* title); | ||||
void setTransientWinId(intptr_t winId); | |||||
void setTransientWinId(uintptr_t winId); | |||||
App& getApp() const noexcept; | App& getApp() const noexcept; | ||||
intptr_t getWindowId() const noexcept; | intptr_t getWindowId() const noexcept; | ||||
@@ -125,27 +125,27 @@ Color Color::fromHTML(const char* rgb, float alpha) | |||||
if (rgblen == 3) | if (rgblen == 3) | ||||
{ | { | ||||
rgbtmp[0] = rgb[0]; | rgbtmp[0] = rgb[0]; | ||||
r = std::strtol(rgbtmp, nullptr, 16); | |||||
r = static_cast<int>(std::strtol(rgbtmp, nullptr, 16)); | |||||
rgbtmp[0] = rgb[1]; | rgbtmp[0] = rgb[1]; | ||||
g = std::strtol(rgbtmp, nullptr, 16); | |||||
g = static_cast<int>(std::strtol(rgbtmp, nullptr, 16)); | |||||
rgbtmp[0] = rgb[2]; | rgbtmp[0] = rgb[2]; | ||||
b = std::strtol(rgbtmp, nullptr, 16); | |||||
b = static_cast<int>(std::strtol(rgbtmp, nullptr, 16)); | |||||
} | } | ||||
else | else | ||||
{ | { | ||||
rgbtmp[0] = rgb[0]; | rgbtmp[0] = rgb[0]; | ||||
rgbtmp[1] = rgb[1]; | rgbtmp[1] = rgb[1]; | ||||
r = std::strtol(rgbtmp, nullptr, 16); | |||||
r = static_cast<int>(std::strtol(rgbtmp, nullptr, 16)); | |||||
rgbtmp[0] = rgb[2]; | rgbtmp[0] = rgb[2]; | ||||
rgbtmp[1] = rgb[3]; | rgbtmp[1] = rgb[3]; | ||||
g = std::strtol(rgbtmp, nullptr, 16); | |||||
g = static_cast<int>(std::strtol(rgbtmp, nullptr, 16)); | |||||
rgbtmp[0] = rgb[4]; | rgbtmp[0] = rgb[4]; | ||||
rgbtmp[1] = rgb[5]; | 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)); | return Color(r, g, b, static_cast<int>(getFixedRange(alpha)*255.0f)); | ||||
@@ -641,13 +641,13 @@ Circle<T>& Circle<T>::operator=(const Circle<T>& cir) noexcept | |||||
template<typename T> | template<typename T> | ||||
bool Circle<T>::operator==(const Circle<T>& cir) const noexcept | 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> | template<typename T> | ||||
bool Circle<T>::operator!=(const Circle<T>& cir) const noexcept | 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> | template<typename T> | ||||
@@ -152,12 +152,14 @@ void Image::drawAt(const Point<int>& pos) | |||||
glPixelStorei(GL_PACK_ALIGNMENT, 1); | glPixelStorei(GL_PACK_ALIGNMENT, 1); | ||||
glPixelStorei(GL_UNPACK_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; | 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); | glBindTexture(GL_TEXTURE_2D, 0); | ||||
glDisable(GL_TEXTURE_2D); | glDisable(GL_TEXTURE_2D); | ||||
@@ -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), | : Widget(parent), | ||||
fImage(image), | fImage(image), | ||||
fId(id), | |||||
fMinimum(0.0f), | fMinimum(0.0f), | ||||
fMaximum(1.0f), | fMaximum(1.0f), | ||||
fStep(0.0f), | fStep(0.0f), | ||||
@@ -43,19 +42,17 @@ ImageKnob::ImageKnob(Window& parent, const Image& image, Orientation orientation | |||||
fIsImgVertical(image.getHeight() > image.getWidth()), | fIsImgVertical(image.getHeight() > image.getWidth()), | ||||
fImgLayerSize(fIsImgVertical ? image.getWidth() : image.getHeight()), | fImgLayerSize(fIsImgVertical ? image.getWidth() : image.getHeight()), | ||||
fImgLayerCount(fIsImgVertical ? image.getHeight()/fImgLayerSize : image.getWidth()/fImgLayerSize), | fImgLayerCount(fIsImgVertical ? image.getHeight()/fImgLayerSize : image.getWidth()/fImgLayerSize), | ||||
fKnobArea(0, 0, fImgLayerSize, fImgLayerSize), | |||||
fTextureId(0), | |||||
fIsReady(false), | fIsReady(false), | ||||
fTextureId(0), | |||||
leakDetector_ImageKnob() | leakDetector_ImageKnob() | ||||
{ | { | ||||
glGenTextures(1, &fTextureId); | glGenTextures(1, &fTextureId); | ||||
setSize(fImgLayerSize, fImgLayerSize); | 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()), | : Widget(widget->getParentWindow()), | ||||
fImage(image), | fImage(image), | ||||
fId(id), | |||||
fMinimum(0.0f), | fMinimum(0.0f), | ||||
fMaximum(1.0f), | fMaximum(1.0f), | ||||
fStep(0.0f), | fStep(0.0f), | ||||
@@ -73,9 +70,8 @@ ImageKnob::ImageKnob(Widget* widget, const Image& image, Orientation orientation | |||||
fIsImgVertical(image.getHeight() > image.getWidth()), | fIsImgVertical(image.getHeight() > image.getWidth()), | ||||
fImgLayerSize(fIsImgVertical ? image.getWidth() : image.getHeight()), | fImgLayerSize(fIsImgVertical ? image.getWidth() : image.getHeight()), | ||||
fImgLayerCount(fIsImgVertical ? image.getHeight()/fImgLayerSize : image.getWidth()/fImgLayerSize), | fImgLayerCount(fIsImgVertical ? image.getHeight()/fImgLayerSize : image.getWidth()/fImgLayerSize), | ||||
fKnobArea(0, 0, fImgLayerSize, fImgLayerSize), | |||||
fTextureId(0), | |||||
fIsReady(false), | fIsReady(false), | ||||
fTextureId(0), | |||||
leakDetector_ImageKnob() | leakDetector_ImageKnob() | ||||
{ | { | ||||
glGenTextures(1, &fTextureId); | glGenTextures(1, &fTextureId); | ||||
@@ -85,7 +81,6 @@ ImageKnob::ImageKnob(Widget* widget, const Image& image, Orientation orientation | |||||
ImageKnob::ImageKnob(const ImageKnob& imageKnob) | ImageKnob::ImageKnob(const ImageKnob& imageKnob) | ||||
: Widget(imageKnob.getParentWindow()), | : Widget(imageKnob.getParentWindow()), | ||||
fImage(imageKnob.fImage), | fImage(imageKnob.fImage), | ||||
fId(imageKnob.fId), | |||||
fMinimum(imageKnob.fMinimum), | fMinimum(imageKnob.fMinimum), | ||||
fMaximum(imageKnob.fMaximum), | fMaximum(imageKnob.fMaximum), | ||||
fStep(imageKnob.fStep), | fStep(imageKnob.fStep), | ||||
@@ -103,9 +98,8 @@ ImageKnob::ImageKnob(const ImageKnob& imageKnob) | |||||
fIsImgVertical(imageKnob.fIsImgVertical), | fIsImgVertical(imageKnob.fIsImgVertical), | ||||
fImgLayerSize(imageKnob.fImgLayerSize), | fImgLayerSize(imageKnob.fImgLayerSize), | ||||
fImgLayerCount(imageKnob.fImgLayerCount), | fImgLayerCount(imageKnob.fImgLayerCount), | ||||
fKnobArea(imageKnob.fKnobArea), | |||||
fTextureId(0), | |||||
fIsReady(false), | fIsReady(false), | ||||
fTextureId(0), | |||||
leakDetector_ImageKnob() | leakDetector_ImageKnob() | ||||
{ | { | ||||
glGenTextures(1, &fTextureId); | glGenTextures(1, &fTextureId); | ||||
@@ -115,7 +109,6 @@ ImageKnob::ImageKnob(const ImageKnob& imageKnob) | |||||
ImageKnob& ImageKnob::operator=(const ImageKnob& imageKnob) | ImageKnob& ImageKnob::operator=(const ImageKnob& imageKnob) | ||||
{ | { | ||||
fImage = imageKnob.fImage; | fImage = imageKnob.fImage; | ||||
fId = imageKnob.fId; | |||||
fMinimum = imageKnob.fMinimum; | fMinimum = imageKnob.fMinimum; | ||||
fMaximum = imageKnob.fMaximum; | fMaximum = imageKnob.fMaximum; | ||||
fStep = imageKnob.fStep; | fStep = imageKnob.fStep; | ||||
@@ -133,7 +126,6 @@ ImageKnob& ImageKnob::operator=(const ImageKnob& imageKnob) | |||||
fIsImgVertical = imageKnob.fIsImgVertical; | fIsImgVertical = imageKnob.fIsImgVertical; | ||||
fImgLayerSize = imageKnob.fImgLayerSize; | fImgLayerSize = imageKnob.fImgLayerSize; | ||||
fImgLayerCount = imageKnob.fImgLayerCount; | fImgLayerCount = imageKnob.fImgLayerCount; | ||||
fKnobArea = imageKnob.fKnobArea; | |||||
fIsReady = false; | fIsReady = false; | ||||
if (fTextureId != 0) | 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 | float ImageKnob::getValue() const noexcept | ||||
{ | { | ||||
return fValue; | return fValue; | ||||
@@ -220,12 +202,12 @@ void ImageKnob::setStep(float step) noexcept | |||||
// NOTE: value is assumed to be scaled if using log | // NOTE: value is assumed to be scaled if using log | ||||
void ImageKnob::setValue(float value, bool sendCallback) noexcept | void ImageKnob::setValue(float value, bool sendCallback) noexcept | ||||
{ | { | ||||
if (fValue == value) | |||||
if (d_isEqual(fValue, value)) | |||||
return; | return; | ||||
fValue = value; | fValue = value; | ||||
if (fStep == 0.0f) | |||||
if (d_isZero(fStep)) | |||||
fValueTmp = value; | fValueTmp = value; | ||||
if (fRotationAngle == 0) | if (fRotationAngle == 0) | ||||
@@ -288,36 +270,44 @@ void ImageKnob::onDisplay() | |||||
glPixelStorei(GL_PACK_ALIGNMENT, 1); | glPixelStorei(GL_PACK_ALIGNMENT, 1); | ||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 1); | glPixelStorei(GL_UNPACK_ALIGNMENT, 1); | ||||
int imageDataOffset = 0; | |||||
uint imageDataOffset = 0; | |||||
if (fRotationAngle == 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; | fIsReady = true; | ||||
} | } | ||||
const int w = static_cast<int>(getWidth()); | |||||
const int h = static_cast<int>(getHeight()); | |||||
if (fRotationAngle != 0) | if (fRotationAngle != 0) | ||||
{ | { | ||||
glPushMatrix(); | 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); | glTranslatef(static_cast<float>(w2), static_cast<float>(h2), 0.0f); | ||||
glRotatef(normValue*static_cast<float>(fRotationAngle), 0.0f, 0.0f, 1.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(); | glPopMatrix(); | ||||
} | } | ||||
else | else | ||||
{ | { | ||||
Rectangle<int>(0, 0, getWidth(), getHeight()).draw(); | |||||
Rectangle<int>(0, 0, w, h).draw(); | |||||
} | } | ||||
glBindTexture(GL_TEXTURE_2D, 0); | glBindTexture(GL_TEXTURE_2D, 0); | ||||
@@ -403,7 +393,7 @@ bool ImageKnob::onMotion(const MotionEvent& ev) | |||||
{ | { | ||||
fValueTmp = value = fMaximum; | fValueTmp = value = fMaximum; | ||||
} | } | ||||
else if (fStep != 0.0f) | |||||
else if (d_isNotZero(fStep)) | |||||
{ | { | ||||
fValueTmp = value; | fValueTmp = value; | ||||
const float rest = std::fmod(value, fStep); | const float rest = std::fmod(value, fStep); | ||||
@@ -437,7 +427,7 @@ bool ImageKnob::onScroll(const ScrollEvent& ev) | |||||
{ | { | ||||
fValueTmp = value = fMaximum; | fValueTmp = value = fMaximum; | ||||
} | } | ||||
else if (fStep != 0.0f) | |||||
else if (d_isNotZero(fStep)) | |||||
{ | { | ||||
fValueTmp = value; | fValueTmp = value; | ||||
const float rest = std::fmod(value, fStep); | const float rest = std::fmod(value, fStep); | ||||
@@ -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), | : Widget(parent), | ||||
fImage(image), | fImage(image), | ||||
fId(id), | |||||
fMinimum(0.0f), | fMinimum(0.0f), | ||||
fMaximum(1.0f), | fMaximum(1.0f), | ||||
fStep(0.0f), | fStep(0.0f), | ||||
@@ -44,10 +43,9 @@ ImageSlider::ImageSlider(Window& parent, const Image& image, int id) noexcept | |||||
Widget::setNeedsFullViewport(true); | Widget::setNeedsFullViewport(true); | ||||
} | } | ||||
ImageSlider::ImageSlider(Widget* widget, const Image& image, int id) noexcept | |||||
ImageSlider::ImageSlider(Widget* widget, const Image& image) noexcept | |||||
: Widget(widget->getParentWindow()), | : Widget(widget->getParentWindow()), | ||||
fImage(image), | fImage(image), | ||||
fId(id), | |||||
fMinimum(0.0f), | fMinimum(0.0f), | ||||
fMaximum(1.0f), | fMaximum(1.0f), | ||||
fStep(0.0f), | fStep(0.0f), | ||||
@@ -69,7 +67,6 @@ ImageSlider::ImageSlider(Widget* widget, const Image& image, int id) noexcept | |||||
ImageSlider::ImageSlider(const ImageSlider& imageSlider) noexcept | ImageSlider::ImageSlider(const ImageSlider& imageSlider) noexcept | ||||
: Widget(imageSlider.getParentWindow()), | : Widget(imageSlider.getParentWindow()), | ||||
fImage(imageSlider.fImage), | fImage(imageSlider.fImage), | ||||
fId(imageSlider.fId), | |||||
fMinimum(imageSlider.fMinimum), | fMinimum(imageSlider.fMinimum), | ||||
fMaximum(imageSlider.fMaximum), | fMaximum(imageSlider.fMaximum), | ||||
fStep(imageSlider.fStep), | fStep(imageSlider.fStep), | ||||
@@ -91,7 +88,6 @@ ImageSlider::ImageSlider(const ImageSlider& imageSlider) noexcept | |||||
ImageSlider& ImageSlider::operator=(const ImageSlider& imageSlider) noexcept | ImageSlider& ImageSlider::operator=(const ImageSlider& imageSlider) noexcept | ||||
{ | { | ||||
fImage = imageSlider.fImage; | fImage = imageSlider.fImage; | ||||
fId = imageSlider.fId; | |||||
fMinimum = imageSlider.fMinimum; | fMinimum = imageSlider.fMinimum; | ||||
fMaximum = imageSlider.fMaximum; | fMaximum = imageSlider.fMaximum; | ||||
fStep = imageSlider.fStep; | fStep = imageSlider.fStep; | ||||
@@ -109,16 +105,6 @@ ImageSlider& ImageSlider::operator=(const ImageSlider& imageSlider) noexcept | |||||
return *this; | return *this; | ||||
} | } | ||||
int ImageSlider::getId() const noexcept | |||||
{ | |||||
return fId; | |||||
} | |||||
void ImageSlider::setId(int id) noexcept | |||||
{ | |||||
fId = id; | |||||
} | |||||
float ImageSlider::getValue() const noexcept | float ImageSlider::getValue() const noexcept | ||||
{ | { | ||||
return fValue; | return fValue; | ||||
@@ -193,12 +179,12 @@ void ImageSlider::setStep(float step) noexcept | |||||
void ImageSlider::setValue(float value, bool sendCallback) noexcept | void ImageSlider::setValue(float value, bool sendCallback) noexcept | ||||
{ | { | ||||
if (fValue == value) | |||||
if (d_isEqual(fValue, value)) | |||||
return; | return; | ||||
fValue = value; | fValue = value; | ||||
if (fStep == 0.0f) | |||||
if (d_isZero(fStep)) | |||||
fValueTmp = value; | fValueTmp = value; | ||||
repaint(); | repaint(); | ||||
@@ -224,7 +210,7 @@ void ImageSlider::onDisplay() | |||||
glColor4f(1.0f, 1.0f, 1.0f, 1.0f); | glColor4f(1.0f, 1.0f, 1.0f, 1.0f); | ||||
#endif | #endif | ||||
float normValue = (fValue - fMinimum) / (fMaximum - fMinimum); | |||||
const float normValue = (fValue - fMinimum) / (fMaximum - fMinimum); | |||||
int x, y; | int x, y; | ||||
@@ -292,7 +278,7 @@ bool ImageSlider::onMouse(const MouseEvent& ev) | |||||
{ | { | ||||
fValueTmp = value = fMaximum; | fValueTmp = value = fMaximum; | ||||
} | } | ||||
else if (fStep != 0.0f) | |||||
else if (d_isNotZero(fStep)) | |||||
{ | { | ||||
fValueTmp = value; | fValueTmp = value; | ||||
const float rest = std::fmod(value, fStep); | const float rest = std::fmod(value, fStep); | ||||
@@ -361,7 +347,7 @@ bool ImageSlider::onMotion(const MotionEvent& ev) | |||||
{ | { | ||||
fValueTmp = value = fMaximum; | fValueTmp = value = fMaximum; | ||||
} | } | ||||
else if (fStep != 0.0f) | |||||
else if (d_isNotZero(fStep)) | |||||
{ | { | ||||
fValueTmp = value; | fValueTmp = value; | ||||
const float rest = std::fmod(value, fStep); | const float rest = std::fmod(value, fStep); | ||||
@@ -395,16 +381,16 @@ void ImageSlider::_recheckArea() noexcept | |||||
// horizontal | // horizontal | ||||
fSliderArea = Rectangle<int>(fStartPos.getX(), | fSliderArea = Rectangle<int>(fStartPos.getX(), | ||||
fStartPos.getY(), | 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 | else | ||||
{ | { | ||||
// vertical | // vertical | ||||
fSliderArea = Rectangle<int>(fStartPos.getX(), | fSliderArea = Rectangle<int>(fStartPos.getX(), | ||||
fStartPos.getY(), | fStartPos.getY(), | ||||
fImage.getWidth(), | |||||
fEndPos.getY() + fImage.getHeight() - fStartPos.getY()); | |||||
static_cast<int>(fImage.getWidth()), | |||||
fEndPos.getY() + static_cast<int>(fImage.getHeight()) - fStartPos.getY()); | |||||
} | } | ||||
} | } | ||||
@@ -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), | : Widget(parent), | ||||
fImageNormal(imageNormal), | fImageNormal(imageNormal), | ||||
fImageDown(imageDown), | fImageDown(imageDown), | ||||
fIsDown(false), | fIsDown(false), | ||||
fId(id), | |||||
fCallback(nullptr), | fCallback(nullptr), | ||||
leakDetector_ImageSwitch() | leakDetector_ImageSwitch() | ||||
{ | { | ||||
@@ -34,12 +33,11 @@ ImageSwitch::ImageSwitch(Window& parent, const Image& imageNormal, const Image& | |||||
setSize(fImageNormal.getSize()); | 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()), | : Widget(widget->getParentWindow()), | ||||
fImageNormal(imageNormal), | fImageNormal(imageNormal), | ||||
fImageDown(imageDown), | fImageDown(imageDown), | ||||
fIsDown(false), | fIsDown(false), | ||||
fId(id), | |||||
fCallback(nullptr), | fCallback(nullptr), | ||||
leakDetector_ImageSwitch() | leakDetector_ImageSwitch() | ||||
{ | { | ||||
@@ -53,7 +51,6 @@ ImageSwitch::ImageSwitch(const ImageSwitch& imageSwitch) noexcept | |||||
fImageNormal(imageSwitch.fImageNormal), | fImageNormal(imageSwitch.fImageNormal), | ||||
fImageDown(imageSwitch.fImageDown), | fImageDown(imageSwitch.fImageDown), | ||||
fIsDown(imageSwitch.fIsDown), | fIsDown(imageSwitch.fIsDown), | ||||
fId(imageSwitch.fId), | |||||
fCallback(imageSwitch.fCallback), | fCallback(imageSwitch.fCallback), | ||||
leakDetector_ImageSwitch() | leakDetector_ImageSwitch() | ||||
{ | { | ||||
@@ -67,7 +64,6 @@ ImageSwitch& ImageSwitch::operator=(const ImageSwitch& imageSwitch) noexcept | |||||
fImageNormal = imageSwitch.fImageNormal; | fImageNormal = imageSwitch.fImageNormal; | ||||
fImageDown = imageSwitch.fImageDown; | fImageDown = imageSwitch.fImageDown; | ||||
fIsDown = imageSwitch.fIsDown; | fIsDown = imageSwitch.fIsDown; | ||||
fId = imageSwitch.fId; | |||||
fCallback = imageSwitch.fCallback; | fCallback = imageSwitch.fCallback; | ||||
DISTRHO_SAFE_ASSERT(fImageNormal.getSize() == fImageDown.getSize()); | DISTRHO_SAFE_ASSERT(fImageNormal.getSize() == fImageDown.getSize()); | ||||
@@ -77,16 +73,6 @@ ImageSwitch& ImageSwitch::operator=(const ImageSwitch& imageSwitch) noexcept | |||||
return *this; | return *this; | ||||
} | } | ||||
int ImageSwitch::getId() const noexcept | |||||
{ | |||||
return fId; | |||||
} | |||||
void ImageSwitch::setId(int id) noexcept | |||||
{ | |||||
fId = id;; | |||||
} | |||||
bool ImageSwitch::isDown() const noexcept | bool ImageSwitch::isDown() const noexcept | ||||
{ | { | ||||
return fIsDown; | return fIsDown; | ||||
@@ -18,8 +18,32 @@ | |||||
#include "../Window.hpp" | #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" | #include "nanovg/nanovg_gl.h" | ||||
#if defined(NANOVG_GL2) | #if defined(NANOVG_GL2) | ||||
@@ -36,6 +60,19 @@ | |||||
# define nvgDeleteGL nvgDeleteGLES3 | # define nvgDeleteGL nvgDeleteGLES3 | ||||
#endif | #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 | START_NAMESPACE_DGL | ||||
// ----------------------------------------------------------------------- | // ----------------------------------------------------------------------- | ||||
@@ -75,7 +112,8 @@ NanoVG::Paint::operator NVGpaint() const noexcept | |||||
NanoImage::NanoImage(NVGcontext* const context, const int imageId) noexcept | NanoImage::NanoImage(NVGcontext* const context, const int imageId) noexcept | ||||
: fContext(context), | : fContext(context), | ||||
fImageId(imageId), | fImageId(imageId), | ||||
fSize() | |||||
fSize(), | |||||
leakDetector_NanoImage() | |||||
{ | { | ||||
_updateSize(); | _updateSize(); | ||||
} | } | ||||
@@ -114,7 +152,7 @@ void NanoImage::_updateSize() | |||||
if (h < 0) h = 0; | 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() | NanoVG::NanoVG() | ||||
: fContext(nvgCreateGL(512, 512, NVG_ANTIALIAS)), | : fContext(nvgCreateGL(512, 512, NVG_ANTIALIAS)), | ||||
fInFrame(false) | |||||
fInFrame(false), | |||||
leakDetector_NanoVG() | |||||
{ | { | ||||
DISTRHO_SAFE_ASSERT_RETURN(fContext != nullptr,); | DISTRHO_SAFE_ASSERT_RETURN(fContext != nullptr,); | ||||
} | } | ||||
NanoVG::NanoVG(const int textAtlasWidth, const int textAtlasHeight) | NanoVG::NanoVG(const int textAtlasWidth, const int textAtlasHeight) | ||||
: fContext(nvgCreateGL(textAtlasWidth, textAtlasHeight, NVG_ANTIALIAS)), | : fContext(nvgCreateGL(textAtlasWidth, textAtlasHeight, NVG_ANTIALIAS)), | ||||
fInFrame(false) | |||||
fInFrame(false), | |||||
leakDetector_NanoVG() | |||||
{ | { | ||||
DISTRHO_SAFE_ASSERT_RETURN(fContext != nullptr,); | 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,); | DISTRHO_SAFE_ASSERT_RETURN(! fInFrame,); | ||||
fInFrame = true; | 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) | void NanoVG::beginFrame(Widget* const widget) | ||||
@@ -163,7 +203,7 @@ void NanoVG::beginFrame(Widget* const widget) | |||||
Window& window(widget->getParentWindow()); | Window& window(widget->getParentWindow()); | ||||
fInFrame = true; | 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() | 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) | void NanoVG::strokeColor(const int red, const int green, const int blue, const int alpha) | ||||
{ | { | ||||
if (fContext != nullptr) | 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) | 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) | void NanoVG::fillColor(const int red, const int green, const int blue, const int alpha) | ||||
{ | { | ||||
if (fContext != nullptr) | 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) | 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; | if (fContext == nullptr) return nullptr; | ||||
DISTRHO_SAFE_ASSERT_RETURN(data != nullptr, 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 new NanoImage(fContext, imageId); | ||||
return nullptr; | return nullptr; | ||||
@@ -576,13 +636,13 @@ NanoVG::FontId NanoVG::createFont(const char* name, const char* filename) | |||||
return nvgCreateFont(fContext, name, 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; | if (fContext == nullptr) return -1; | ||||
DISTRHO_SAFE_ASSERT_RETURN(name != nullptr && name[0] != '\0', -1); | DISTRHO_SAFE_ASSERT_RETURN(name != nullptr && name[0] != '\0', -1); | ||||
DISTRHO_SAFE_ASSERT_RETURN(data != nullptr, -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) | NanoVG::FontId NanoVG::findFont(const char* name) | ||||
@@ -27,6 +27,7 @@ Widget::Widget(Window& parent) | |||||
fNeedsFullViewport(false), | fNeedsFullViewport(false), | ||||
fNeedsScaling(false), | fNeedsScaling(false), | ||||
fVisible(true), | fVisible(true), | ||||
fId(0), | |||||
fAbsolutePos(0, 0), | fAbsolutePos(0, 0), | ||||
fSize(0, 0), | fSize(0, 0), | ||||
leakDetector_Widget() | leakDetector_Widget() | ||||
@@ -200,6 +201,16 @@ void Widget::repaint() noexcept | |||||
fParent.repaint(); | fParent.repaint(); | ||||
} | } | ||||
uint Widget::getId() const noexcept | |||||
{ | |||||
return fId; | |||||
} | |||||
void Widget::setId(uint id) noexcept | |||||
{ | |||||
fId = id; | |||||
} | |||||
bool Widget::onKeyboard(const KeyboardEvent&) | bool Widget::onKeyboard(const KeyboardEvent&) | ||||
{ | { | ||||
return false; | return false; | ||||
@@ -70,6 +70,7 @@ struct Window::PrivateData { | |||||
fUsingEmbed(false), | fUsingEmbed(false), | ||||
fWidth(1), | fWidth(1), | ||||
fHeight(1), | fHeight(1), | ||||
fWidgets(), | |||||
fModal(), | fModal(), | ||||
#if defined(DISTRHO_OS_WINDOWS) | #if defined(DISTRHO_OS_WINDOWS) | ||||
hwnd(0), | hwnd(0), | ||||
@@ -97,6 +98,7 @@ struct Window::PrivateData { | |||||
fUsingEmbed(false), | fUsingEmbed(false), | ||||
fWidth(1), | fWidth(1), | ||||
fHeight(1), | fHeight(1), | ||||
fWidgets(), | |||||
fModal(parent.pData), | fModal(parent.pData), | ||||
#if defined(DISTRHO_OS_WINDOWS) | #if defined(DISTRHO_OS_WINDOWS) | ||||
hwnd(0), | hwnd(0), | ||||
@@ -134,6 +136,7 @@ struct Window::PrivateData { | |||||
fUsingEmbed(parentId != 0), | fUsingEmbed(parentId != 0), | ||||
fWidth(1), | fWidth(1), | ||||
fHeight(1), | fHeight(1), | ||||
fWidgets(), | |||||
fModal(), | fModal(), | ||||
#if defined(DISTRHO_OS_WINDOWS) | #if defined(DISTRHO_OS_WINDOWS) | ||||
hwnd(0), | hwnd(0), | ||||
@@ -177,7 +180,7 @@ struct Window::PrivateData { | |||||
} | } | ||||
puglInitResizable(fView, fResizable); | puglInitResizable(fView, fResizable); | ||||
puglInitWindowSize(fView, fWidth, fHeight); | |||||
puglInitWindowSize(fView, static_cast<int>(fWidth), static_cast<int>(fHeight)); | |||||
puglSetHandle(fView, this); | puglSetHandle(fView, this); | ||||
puglSetDisplayFunc(fView, onDisplayCallback); | puglSetDisplayFunc(fView, onDisplayCallback); | ||||
@@ -554,7 +557,7 @@ struct Window::PrivateData { | |||||
#endif | #endif | ||||
} | } | ||||
void setTransientWinId(const intptr_t winId) | |||||
void setTransientWinId(const uintptr_t winId) | |||||
{ | { | ||||
#if defined(DISTRHO_OS_LINUX) | #if defined(DISTRHO_OS_LINUX) | ||||
XSetTransientForHint(xDisplay, xWindow, static_cast< ::Window>(winId)); | XSetTransientForHint(xDisplay, xWindow, static_cast< ::Window>(winId)); | ||||
@@ -611,7 +614,7 @@ struct Window::PrivateData { | |||||
// ------------------------------------------------------------------- | // ------------------------------------------------------------------- | ||||
void onDisplay() | |||||
void onPuglDisplay() | |||||
{ | { | ||||
fSelf->onDisplayBefore(); | fSelf->onDisplayBefore(); | ||||
@@ -629,22 +632,35 @@ struct Window::PrivateData { | |||||
if (widget->fNeedsFullViewport || (widget->fAbsolutePos.isZero() && widget->fSize == Size<uint>(fWidth, fHeight))) | if (widget->fNeedsFullViewport || (widget->fAbsolutePos.isZero() && widget->fSize == Size<uint>(fWidth, fHeight))) | ||||
{ | { | ||||
// full viewport size | // full viewport size | ||||
glViewport(0, 0, fWidth, fHeight); | |||||
glViewport(0, | |||||
0, | |||||
static_cast<GLsizei>(fWidth), | |||||
static_cast<GLsizei>(fHeight)); | |||||
} | } | ||||
else if (! widget->fNeedsScaling) | else if (! widget->fNeedsScaling) | ||||
{ | { | ||||
// only set viewport pos | // 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 | // 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); | glEnable(GL_SCISSOR_TEST); | ||||
needsDisableScissor = true; | needsDisableScissor = true; | ||||
} | } | ||||
else | else | ||||
{ | { | ||||
// limit viewport to widget bounds | // 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 | // display widget | ||||
@@ -661,7 +677,7 @@ struct Window::PrivateData { | |||||
fSelf->onDisplayAfter(); | 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); | 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); | 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); | 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); | 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); | 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); | DBGp("PUGL: onReshape : %i %i\n", width, height); | ||||
if (width <= 1 && height <= 1) | if (width <= 1 && height <= 1) | ||||
return; | 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) | FOR_EACH_WIDGET(it) | ||||
{ | { | ||||
Widget* const widget(*it); | Widget* const widget(*it); | ||||
if (widget->fNeedsFullViewport) | if (widget->fNeedsFullViewport) | ||||
widget->setSize(width, height); | |||||
widget->setSize(fWidth, fHeight); | |||||
} | } | ||||
} | } | ||||
void onClose() | |||||
void onPuglClose() | |||||
{ | { | ||||
DBG("PUGL: onClose\n"); | DBG("PUGL: onClose\n"); | ||||
@@ -808,7 +824,7 @@ struct Window::PrivateData { | |||||
fSelf->onClose(); | fSelf->onClose(); | ||||
if (fModal.childFocus != nullptr) | if (fModal.childFocus != nullptr) | ||||
fModal.childFocus->onClose(); | |||||
fModal.childFocus->fSelf->onClose(); | |||||
close(); | close(); | ||||
} | } | ||||
@@ -847,6 +863,8 @@ struct Window::PrivateData { | |||||
DISTRHO_SAFE_ASSERT(! enabled); | DISTRHO_SAFE_ASSERT(! enabled); | ||||
DISTRHO_SAFE_ASSERT(childFocus == nullptr); | DISTRHO_SAFE_ASSERT(childFocus == nullptr); | ||||
} | } | ||||
DISTRHO_DECLARE_NON_COPY_STRUCT(Modal) | |||||
} fModal; | } fModal; | ||||
#if defined(DISTRHO_OS_WINDOWS) | #if defined(DISTRHO_OS_WINDOWS) | ||||
@@ -867,42 +885,42 @@ struct Window::PrivateData { | |||||
static void onDisplayCallback(PuglView* view) | static void onDisplayCallback(PuglView* view) | ||||
{ | { | ||||
handlePtr->onDisplay(); | |||||
handlePtr->onPuglDisplay(); | |||||
} | } | ||||
static void onKeyboardCallback(PuglView* view, bool press, uint32_t key) | 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) | 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) | 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) | 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) | 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) | static void onReshapeCallback(PuglView* view, int width, int height) | ||||
{ | { | ||||
handlePtr->onReshape(width, height); | |||||
handlePtr->onPuglReshape(width, height); | |||||
} | } | ||||
static void onCloseCallback(PuglView* view) | static void onCloseCallback(PuglView* view) | ||||
{ | { | ||||
handlePtr->onClose(); | |||||
handlePtr->onPuglClose(); | |||||
} | } | ||||
#undef handlePtr | #undef handlePtr | ||||
@@ -1010,7 +1028,7 @@ void Window::setTitle(const char* title) | |||||
pData->setTitle(title); | pData->setTitle(title); | ||||
} | } | ||||
void Window::setTransientWinId(intptr_t winId) | |||||
void Window::setTransientWinId(uintptr_t winId) | |||||
{ | { | ||||
pData->setTransientWinId(winId); | pData->setTransientWinId(winId); | ||||
} | } | ||||
@@ -1074,8 +1092,8 @@ void Window::onReshape(uint width, uint height) | |||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); | glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); | ||||
glMatrixMode(GL_PROJECTION); | glMatrixMode(GL_PROJECTION); | ||||
glLoadIdentity(); | 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); | glMatrixMode(GL_MODELVIEW); | ||||
glLoadIdentity(); | glLoadIdentity(); | ||||
} | } | ||||
@@ -41,7 +41,7 @@ enum FONSalign { | |||||
enum FONSerrorCode { | enum FONSerrorCode { | ||||
// Font atlas is full. | // Font atlas is full. | ||||
FONS_ATLAS_FULL = 1, | 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, | FONS_SCRATCH_FULL = 2, | ||||
// Calls to fonsPushState has craeted too large stack, if you need deep state stack bump up FONS_MAX_STATES. | // Calls to fonsPushState has craeted too large stack, if you need deep state stack bump up FONS_MAX_STATES. | ||||
FONS_STATES_OVERFLOW = 3, | 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); | void fonsSetErrorCallback(struct FONScontext* s, void (*callback)(void* uptr, int error, int val), void* uptr); | ||||
// Returns current atlas size. | // Returns current atlas size. | ||||
void fonsGetAtlasSize(struct FONScontext* s, int* width, int* height); | 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); | int fonsExpandAtlas(struct FONScontext* s, int width, int height); | ||||
// Reseta the whole stash. | // Reseta the whole stash. | ||||
int fonsResetAtlas(struct FONScontext* stash, int width, int height); | 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 fonsTextBounds(struct FONScontext* stash, | ||||
float x, float y, | |||||
float x, float y, | |||||
const char* str, const char* end, | const char* str, const char* end, | ||||
float* bounds) | float* bounds) | ||||
{ | { | ||||
@@ -1576,7 +1576,7 @@ int fonsExpandAtlas(struct FONScontext* stash, int width, int height) | |||||
height = fons__maxi(height, stash->params.height); | height = fons__maxi(height, stash->params.height); | ||||
if (width == stash->params.width && height == stash->params.height) | if (width == stash->params.width && height == stash->params.height) | ||||
return 1; | |||||
return 1; | |||||
// Flush pending glyphs. | // Flush pending glyphs. | ||||
fons__flush(stash); | fons__flush(stash); | ||||