From cd2873761758c07a9bf18cd536d12074ce061df3 Mon Sep 17 00:00:00 2001 From: falkTX Date: Sat, 16 Aug 2014 02:30:08 +0100 Subject: [PATCH] Cleanup; Fix some docs; Split Color from NanoVG into separate class --- dgl/App.hpp | 2 +- dgl/Color.hpp | 99 ++++++++++++++++++++++++++++++++++++ dgl/Geometry.hpp | 2 +- dgl/Image.hpp | 18 +++---- dgl/Makefile | 1 + dgl/Makefile.mk | 4 +- dgl/NanoVG.hpp | 83 +++++++----------------------- dgl/Widget.hpp | 28 +++++----- dgl/src/AppPrivateData.hpp | 2 + dgl/src/Color.cpp | 93 +++++++++++++++++++++++++++++++++ dgl/src/Image.cpp | 10 ++-- dgl/src/ImageKnob.cpp | 2 +- dgl/src/NanoVG.cpp | 96 +++++++++++----------------------- distrho/DistrhoPlugin.hpp | 2 +- distrho/DistrhoUtils.hpp | 2 +- distrho/src/DistrhoDefines.h | 6 +-- 16 files changed, 280 insertions(+), 170 deletions(-) create mode 100644 dgl/Color.hpp create mode 100644 dgl/src/Color.cpp diff --git a/dgl/App.hpp b/dgl/App.hpp index 1afac9f2..0e77e1b1 100644 --- a/dgl/App.hpp +++ b/dgl/App.hpp @@ -56,7 +56,7 @@ public: /** Run the application event-loop until all Windows are closed. - @idle() is called at regular intervals. + idle() is called at regular intervals. */ void exec(); diff --git a/dgl/Color.hpp b/dgl/Color.hpp new file mode 100644 index 00000000..b87ce481 --- /dev/null +++ b/dgl/Color.hpp @@ -0,0 +1,99 @@ +/* + * DISTRHO Plugin Framework (DPF) + * Copyright (C) 2012-2014 Filipe Coelho + * + * Permission to use, copy, modify, and/or distribute this software for any purpose with + * or without fee is hereby granted, provided that the above copyright notice and this + * permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD + * TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN + * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL + * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER + * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef DGL_COLOR_HPP_INCLUDED +#define DGL_COLOR_HPP_INCLUDED + +#include "Base.hpp" + +struct NVGcolor; + +START_NAMESPACE_DGL + +// ----------------------------------------------------------------------- + +// TODO: create color from "#333" and "#112233" like strings + +/** + A color made from red, green, blue and alpha floating-point values in [0..1] range. +*/ +struct Color { + /** + Direct access to the color value. + */ + union { + float rgba[4]; + struct { float red, green, blue, alpha; }; + }; + + /** + Create black color. + */ + Color() noexcept; + + /** + Create a color from red, green, blue and alpha numeric values. + Values must be in [0..255] range. + */ + Color(const uchar red, const uchar green, const uchar blue, const uchar alpha = 255) noexcept; + + /** + Create a color from red, green, blue and alpha floating-point values. + Values must in [0..1] range. + */ + Color(const float red, const float green, const float blue, const float alpha = 1.0f) noexcept; + + /** + Create a color by copying another color. + */ + Color(const Color& color) noexcept; + Color& operator=(const Color& color) noexcept; + + /** + Create a color by linearly interpolating two other colors. + */ + Color(const Color& color1, const Color& color2, const float u) noexcept; + + /** + Create a color specified by hue, saturation, lightness and alpha. + HSL values are all in [0..1] range, alpha in [0..255] range. + */ + static Color HSL(const float hue, const float saturation, const float lightness, const uchar alpha = 255); + + /** + Linearly interpolate this color against @a other. + */ + void interpolate(const Color& other, const float u) noexcept; + + /** + Check if this color matches another. + */ + bool operator==(const Color& color) noexcept; + bool operator!=(const Color& color) noexcept; + + /** + @internal + Needed for NanoVG compatibility. + */ + Color(const NVGcolor&) noexcept; + operator NVGcolor() const noexcept; +}; + +// ----------------------------------------------------------------------- + +END_NAMESPACE_DGL + +#endif // DGL_COLOR_HPP_INCLUDED diff --git a/dgl/Geometry.hpp b/dgl/Geometry.hpp index d6820232..df9eb32a 100644 --- a/dgl/Geometry.hpp +++ b/dgl/Geometry.hpp @@ -42,7 +42,7 @@ public: Point() noexcept; /** - Constructor using custom x and y values. + Constructor using custom X and Y values. */ Point(const T& x, const T& y) noexcept; diff --git a/dgl/Image.hpp b/dgl/Image.hpp index cf8d1e53..0e97540a 100644 --- a/dgl/Image.hpp +++ b/dgl/Image.hpp @@ -45,15 +45,15 @@ public: /** Constructor using raw image data. - @note @a rawData must remain valid for the lifetime of this Image. + @note: @a rawData must remain valid for the lifetime of this Image. */ - Image(const char* rawData, int width, int height, GLenum format = GL_BGRA, GLenum type = GL_UNSIGNED_BYTE); + Image(const char* const rawData, const int width, const int height, const GLenum format = GL_BGRA, const GLenum type = GL_UNSIGNED_BYTE); /** Constructor using raw image data. - @note @a rawData must remain valid for the lifetime of this Image. + @note: @a rawData must remain valid for the lifetime of this Image. */ - Image(const char* rawData, const Size& size, GLenum format = GL_BGRA, GLenum type = GL_UNSIGNED_BYTE); + Image(const char* const rawData, const Size& size, const GLenum format = GL_BGRA, const GLenum type = GL_UNSIGNED_BYTE); /** Constructor using another image data. @@ -67,15 +67,15 @@ public: /** Load image data from memory. - @note @a rawData must remain valid for the lifetime of this Image. + @note: @a rawData must remain valid for the lifetime of this Image. */ - void loadFromMemory(const char* rawData, int width, int height, GLenum format = GL_BGRA, GLenum type = GL_UNSIGNED_BYTE) noexcept; + void loadFromMemory(const char* const rawData, const int width, const int height, const GLenum format = GL_BGRA, const GLenum type = GL_UNSIGNED_BYTE) noexcept; /** Load image data from memory. - @note @a rawData must remain valid for the lifetime of this Image. + @note: @a rawData must remain valid for the lifetime of this Image. */ - void loadFromMemory(const char* rawData, const Size& size, GLenum format = GL_BGRA, GLenum type = GL_UNSIGNED_BYTE) noexcept; + void loadFromMemory(const char* const rawData, const Size& size, const GLenum format = GL_BGRA, const GLenum type = GL_UNSIGNED_BYTE) noexcept; /** Check if this image is valid. @@ -120,7 +120,7 @@ public: /** Draw this image at (x, y) point. */ - void drawAt(int x, int y); + void drawAt(const int x, const int y); /** Draw this image at position @a pos. diff --git a/dgl/Makefile b/dgl/Makefile index d107bf4e..f0b12983 100644 --- a/dgl/Makefile +++ b/dgl/Makefile @@ -16,6 +16,7 @@ LINK_FLAGS += $(DGL_LIBS) OBJS = \ src/App.cpp.o \ + src/Color.cpp.o \ src/Geometry.cpp.o \ src/Image.cpp.o \ src/ImageAboutWindow.cpp.o \ diff --git a/dgl/Makefile.mk b/dgl/Makefile.mk index 5815dc24..62543623 100644 --- a/dgl/Makefile.mk +++ b/dgl/Makefile.mk @@ -82,8 +82,8 @@ BASE_FLAGS += -Werror -Wcast-qual -Wconversion -Wformat -Wformat-security -Wredu BASE_FLAGS += -Wpointer-arith -Wabi -Winit-self -Wuninitialized -Wstrict-overflow=5 # BASE_FLAGS += -Wfloat-equal ifeq ($(CC),clang) -# BASE_FLAGS += -Wdocumentation -Wdocumentation-unknown-command -# BASE_FLAGS += -Weverything +BASE_FLAGS += -Wdocumentation -Wdocumentation-unknown-command +BASE_FLAGS += -Weverything -Wno-c++98-compat -Wno-c++98-compat-pedantic -Wno-padded -Wno-exit-time-destructors -Wno-float-equal else BASE_FLAGS += -Wcast-align -Wunsafe-loop-optimizations endif diff --git a/dgl/NanoVG.hpp b/dgl/NanoVG.hpp index 8d6642b9..8109e460 100644 --- a/dgl/NanoVG.hpp +++ b/dgl/NanoVG.hpp @@ -17,9 +17,9 @@ #ifndef DGL_NANO_WIDGET_HPP_INCLUDED #define DGL_NANO_WIDGET_HPP_INCLUDED +#include "Color.hpp" #include "Widget.hpp" -struct NVGcolor; struct NVGcontext; struct NVGpaint; @@ -45,25 +45,28 @@ public: /** Get size. */ - Size getSize() const; + Size getSize() const noexcept; /** Update image data. */ - void updateImage(const uchar* data); + void updateImage(const uchar* const data); protected: /** Constructors are protected. NanoImages must be created within a NanoVG or NanoWidget class. */ - NanoImage(NVGcontext* context, int imageId) noexcept; + NanoImage(NVGcontext* const context, const int imageId) noexcept; private: NVGcontext* fContext; int fImageId; + Size fSize; friend class NanoVG; + void _updateSize(); + DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(NanoImage) }; @@ -74,10 +77,7 @@ private: NanoVG class. This class exposes the NanoVG drawing API. - All calls should be wrapped in beginFrame() & endFrame(). - - @section Color utils - Colors in NanoVG are stored as uints in ABGR format. + All calls should be wrapped in beginFrame() and endFrame(). @section State Handling NanoVG contains state which represents how paths will be rendered. @@ -153,13 +153,13 @@ private: since aforementioned pixel snapping. While this may sound a little odd, the setup allows you to always render the - same way regardless of scaling. I.e. following works regardless of scaling: + same way regardless of scaling. i.e. following works regardless of scaling: @code const char* txt = "Text me up."; textBounds(vg, x,y, txt, NULL, bounds); beginPath(vg); - roundedRect(vg, bounds[0],bounds[1], bounds[2]-bounds[0], bounds[3]-bounds[1]); + roundedRect(vg, bounds[0], bounds[1], bounds[2]-bounds[0], bounds[3]-bounds[1]); fill(vg); @endcode @@ -182,7 +182,7 @@ public: enum Alpha { STRAIGHT_ALPHA, - PREMULTIPLIED_ALPHA, + PREMULTIPLIED_ALPHA }; enum LineCap { @@ -209,17 +209,6 @@ public: CW = 2 // Winding for holes }; - struct Color { - union { - float rgba[4]; - struct { float r,g,b,a; }; - }; - - Color() noexcept; - Color(const NVGcolor&) noexcept; - operator NVGcolor() const noexcept; - }; - struct Paint { float xform[6]; float extent[2]; @@ -231,6 +220,10 @@ public: PatternRepeat repeat; Paint() noexcept; + + /** + @internal + */ Paint(const NVGpaint&) noexcept; operator NVGpaint() const noexcept; }; @@ -260,7 +253,7 @@ public: /** Constructor using custom text atlas size. */ - NanoVG(int textAtlasWidth, int textAtlasHeight); + NanoVG(const int textAtlasWidth, const int textAtlasHeight); /** Destructor. @@ -280,58 +273,18 @@ public: Begin drawing a new frame. @param withAlha Controls if drawing the shapes to the render target should be done using straight or pre-multiplied alpha. */ - void beginFrame(int width, int height, float scaleFactor = 1.0f, Alpha alpha = PREMULTIPLIED_ALPHA); + void beginFrame(const int width, const int height, const float scaleFactor = 1.0f, const Alpha alpha = PREMULTIPLIED_ALPHA); /** Begin drawing a new frame inside a widget. */ - void beginFrame(Widget* widget); + void beginFrame(Widget* const widget); /** Ends drawing flushing remaining render state. */ void endFrame(); - /* -------------------------------------------------------------------- - * Color utils */ - - /** - Returns a color value from red, green, blue values. Alpha will be set to 255 (1.0f). - */ - static Color RGB(uchar r, uchar g, uchar b); - - /** - Returns a color value from red, green, blue values. Alpha will be set to 1.0f. - */ - static Color RGBf(float r, float g, float b); - - /** - Returns a color value from red, green, blue and alpha values. - */ - static Color RGBA(uchar r, uchar g, uchar b, uchar a); - - /** - Returns a color value from red, green, blue and alpha values. - */ - static Color RGBAf(float r, float g, float b, float a); - - /** - Linearly interpolates from color c0 to c1, and returns resulting color value. - */ - static Color lerpRGBA(const Color& c0, const Color& c1, float u); - - /** - Returns color value specified by hue, saturation and lightness. - HSL values are all in range [0..1], alpha will be set to 255. - */ - static Color HSL(float h, float s, float l); - - /** - Returns color value specified by hue, saturation and lightness and alpha. - HSL values are all in range [0..1], alpha in range [0..255] - */ - static Color HSLA(float h, float s, float l, uchar a); - /* -------------------------------------------------------------------- * State Handling */ diff --git a/dgl/Widget.hpp b/dgl/Widget.hpp index 83180baf..30177de1 100644 --- a/dgl/Widget.hpp +++ b/dgl/Widget.hpp @@ -52,8 +52,8 @@ class Widget public: /** Base event data. - @param mod The currently active modifiers. - @param time The timestamp (if any) of the currently-processing event. + @a mod The currently active modifiers. + @a time The timestamp (if any) of the currently-processing event. */ struct BaseEvent { Modifier mod; @@ -62,8 +62,8 @@ public: /** Keyboard event. - @param press True if the key was pressed, false if released. - @param key Unicode point of the key pressed. + @a press True if the key was pressed, false if released. + @a key Unicode point of the key pressed. @see onKeyboard */ struct KeyboardEvent : BaseEvent { @@ -73,8 +73,8 @@ public: /** Special keyboard event. - @param press True if the key was pressed, false if released. - @param key The key pressed. + @a press True if the key was pressed, false if released. + @a key The key pressed. @see onSpecial */ struct SpecialEvent : BaseEvent { @@ -84,9 +84,9 @@ public: /** Mouse event. - @param button The button number (1 = left, 2 = middle, 3 = right). - @param press True if the key was pressed, false if released. - @param pos The widget-relative coordinates of the pointer. + @a button The button number (1 = left, 2 = middle, 3 = right). + @a press True if the key was pressed, false if released. + @a pos The widget-relative coordinates of the pointer. @see onMouse */ struct MouseEvent : BaseEvent { @@ -97,7 +97,7 @@ public: /** Mouse motion event. - @param pos The widget-relative coordinates of the pointer. + @a pos The widget-relative coordinates of the pointer. @see onMotion */ struct MotionEvent : BaseEvent { @@ -106,8 +106,8 @@ public: /** Mouse scroll event. - @param pos The widget-relative coordinates of the pointer. - @param delta The scroll distance. + @a pos The widget-relative coordinates of the pointer. + @a delta The scroll distance. @see onScroll */ struct ScrollEvent : BaseEvent { @@ -117,8 +117,8 @@ public: /** Resize event. - @param size The new widget size. - @param oldSize The previous size, may be null. + @a size The new widget size. + @a oldSize The previous size, may be null. @see onResize */ struct ResizeEvent { diff --git a/dgl/src/AppPrivateData.hpp b/dgl/src/AppPrivateData.hpp index cc89a2f2..c6689686 100644 --- a/dgl/src/AppPrivateData.hpp +++ b/dgl/src/AppPrivateData.hpp @@ -60,6 +60,8 @@ struct App::PrivateData { if (--visibleWindows == 0) doLoop = false; } + + DISTRHO_DECLARE_NON_COPY_STRUCT(PrivateData) }; // ----------------------------------------------------------------------- diff --git a/dgl/src/Color.cpp b/dgl/src/Color.cpp new file mode 100644 index 00000000..b65f03e5 --- /dev/null +++ b/dgl/src/Color.cpp @@ -0,0 +1,93 @@ +/* + * DISTRHO Plugin Framework (DPF) + * Copyright (C) 2012-2014 Filipe Coelho + * + * Permission to use, copy, modify, and/or distribute this software for any purpose with + * or without fee is hereby granted, provided that the above copyright notice and this + * permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD + * TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN + * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL + * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER + * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include "../Color.hpp" + +#include "nanovg/nanovg.h" + +START_NAMESPACE_DGL + +// ----------------------------------------------------------------------- + +Color::Color() noexcept + : red(1.0f), green(1.0f), blue(1.0f), alpha(1.0f) {} + +Color::Color(const uchar r, const uchar g, const uchar b, const uchar a) noexcept + : red(static_cast(r)/255.0f), green(static_cast(g)/255.0f), blue(static_cast(b)/255.0f), alpha(static_cast(a)/255.0f) {} + +Color::Color(const float r, const float g, const float b, const float a) noexcept + : red(r), green(g), blue(b), alpha(a) {} + +Color::Color(const Color& color) noexcept + : red(color.red), green(color.green), blue(color.blue), alpha(color.alpha) {} + +Color::Color(const Color& color1, const Color& color2, const float u) noexcept + : red(color1.red), green(color1.green), blue(color1.blue), alpha(color1.alpha) +{ + interpolate(color2, u); +} + +void Color::interpolate(const Color& other, const float u) noexcept +{ + const float u2 = (u < 0.0f) ? 0.0f : ((u > 1.0f) ? 1.0f : u); + const float oneMinusU = 1.0f - u; + + red = red * oneMinusU + other.red * u2; + green = green * oneMinusU + other.green * u2; + blue = blue * oneMinusU + other.blue * u2; + alpha = alpha * oneMinusU + other.alpha * u2; +} + +Color Color::HSL(const float hue, const float saturation, const float lightness, const uchar alpha) +{ + return nvgHSLA(hue, saturation, lightness, alpha); +} + +Color::Color(const NVGcolor& c) noexcept + : red(c.r), green(c.g), blue(c.b), alpha(c.a) {} + +Color::operator NVGcolor() const noexcept +{ + NVGcolor nc; + nc.r = red; + nc.g = green; + nc.b = blue; + nc.a = alpha; + return nc; +} + +Color& Color::operator=(const Color& color) noexcept +{ + red = color.red; + green = color.green; + blue = color.blue; + alpha = color.alpha; + return *this; +} + +bool Color::operator==(const Color& color) noexcept +{ + return (red == color.red && green == color.green && blue == color.blue && alpha == color.alpha); +} + +bool Color::operator!=(const Color& color) noexcept +{ + return (red != color.red || green != color.green || blue != color.blue || alpha != color.alpha); +} + +// ----------------------------------------------------------------------- + +END_NAMESPACE_DGL diff --git a/dgl/src/Image.cpp b/dgl/src/Image.cpp index 81b24dd1..d9ea2356 100644 --- a/dgl/src/Image.cpp +++ b/dgl/src/Image.cpp @@ -31,7 +31,7 @@ Image::Image() glGenTextures(1, &fTextureId); } -Image::Image(const char* rawData, int width, int height, GLenum format, GLenum type) +Image::Image(const char* const rawData, const int width, const int height, const GLenum format, const GLenum type) : fRawData(rawData), fSize(width, height), fFormat(format), @@ -42,7 +42,7 @@ Image::Image(const char* rawData, int width, int height, GLenum format, GLenum t glGenTextures(1, &fTextureId); } -Image::Image(const char* rawData, const Size& size, GLenum format, GLenum type) +Image::Image(const char* const rawData, const Size& size, const GLenum format, const GLenum type) : fRawData(rawData), fSize(size), fFormat(format), @@ -73,12 +73,12 @@ Image::~Image() } } -void Image::loadFromMemory(const char* rawData, int width, int height, GLenum format, GLenum type) noexcept +void Image::loadFromMemory(const char* const rawData, const int width, const int height, const GLenum format, const GLenum type) noexcept { loadFromMemory(rawData, Size(width, height), format, type); } -void Image::loadFromMemory(const char* rawData, const Size& size, GLenum format, GLenum type) noexcept +void Image::loadFromMemory(const char* const rawData, const Size& size, const GLenum format, const GLenum type) noexcept { fRawData = rawData; fSize = size; @@ -127,7 +127,7 @@ void Image::draw() drawAt(0, 0); } -void Image::drawAt(int x, int y) +void Image::drawAt(const int x, const int y) { drawAt(Point(x, y)); } diff --git a/dgl/src/ImageKnob.cpp b/dgl/src/ImageKnob.cpp index 43d84f99..0fc8c69b 100644 --- a/dgl/src/ImageKnob.cpp +++ b/dgl/src/ImageKnob.cpp @@ -368,7 +368,7 @@ bool ImageKnob::onMotion(const MotionEvent& ev) return false; bool doVal = false; - float d, value; + float d, value = 0.0f; if (fOrientation == ImageKnob::Horizontal) { diff --git a/dgl/src/NanoVG.cpp b/dgl/src/NanoVG.cpp index bf7a33be..205bdb0f 100644 --- a/dgl/src/NanoVG.cpp +++ b/dgl/src/NanoVG.cpp @@ -39,19 +39,7 @@ START_NAMESPACE_DGL // ----------------------------------------------------------------------- -// Conversions - -NanoVG::Color::Color() noexcept - : r(1.0f), g(1.0f), b(1.0f), a(1.0f) {} - -NanoVG::Color::Color(const NVGcolor& c) noexcept - : r(c.r), g(c.g), b(c.b), a(c.a) {} - -NanoVG::Color::operator NVGcolor() const noexcept -{ - NVGcolor nc = {{{ r, g, b, a }}}; - return nc; -} +// Paint NanoVG::Paint::Paint() noexcept : radius(0.0f), feather(0.0f), innerColor(), outerColor(), imageId(0), repeat(REPEAT_NONE) @@ -84,9 +72,13 @@ NanoVG::Paint::operator NVGpaint() const noexcept // ----------------------------------------------------------------------- // NanoImage -NanoImage::NanoImage(NVGcontext* context, int imageId) noexcept +NanoImage::NanoImage(NVGcontext* const context, const int imageId) noexcept : fContext(context), - fImageId(imageId) {} + fImageId(imageId), + fSize() +{ + _updateSize(); +} NanoImage::~NanoImage() { @@ -94,22 +86,30 @@ NanoImage::~NanoImage() nvgDeleteImage(fContext, fImageId); } -Size NanoImage::getSize() const +Size NanoImage::getSize() const noexcept { - int w=0, h=0; - - if (fContext != nullptr && fImageId != 0) - nvgImageSize(fContext, fImageId, &w, &h); - - return Size(w, h); + return fSize; } -void NanoImage::updateImage(const uchar* data) +void NanoImage::updateImage(const uchar* const data) { DISTRHO_SAFE_ASSERT_RETURN(data != nullptr,); if (fContext != nullptr && fImageId != 0) + { nvgUpdateImage(fContext, fImageId, data); + _updateSize(); + } +} + +void NanoImage::_updateSize() +{ + int w=0, h=0; + + if (fContext != nullptr && fImageId != 0) + nvgImageSize(fContext, fImageId, &w, &h); + + fSize.setSize(w, h); } // ----------------------------------------------------------------------- @@ -121,7 +121,7 @@ NanoVG::NanoVG() DISTRHO_SAFE_ASSERT_RETURN(fContext != nullptr,); } -NanoVG::NanoVG(int textAtlasWidth, int textAtlasHeight) +NanoVG::NanoVG(const int textAtlasWidth, const int textAtlasHeight) : fContext(nvgCreateGL(textAtlasWidth, textAtlasHeight, NVG_ANTIALIAS)) { DISTRHO_SAFE_ASSERT_RETURN(fContext != nullptr,); @@ -135,7 +135,7 @@ NanoVG::~NanoVG() // ----------------------------------------------------------------------- -void NanoVG::beginFrame(int width, int height, float scaleFactor, Alpha alpha) +void NanoVG::beginFrame(const int width, const int height, const float scaleFactor, const Alpha alpha) { if (fContext == nullptr) return; DISTRHO_SAFE_ASSERT_RETURN(width > 0,); @@ -145,7 +145,7 @@ void NanoVG::beginFrame(int width, int height, float scaleFactor, Alpha alpha) nvgBeginFrame(fContext, width, height, scaleFactor, static_cast(alpha)); } -void NanoVG::beginFrame(Widget* widget) +void NanoVG::beginFrame(Widget* const widget) { if (fContext == nullptr) return; DISTRHO_SAFE_ASSERT_RETURN(widget != nullptr,); @@ -160,44 +160,6 @@ void NanoVG::endFrame() nvgEndFrame(fContext); } -// ----------------------------------------------------------------------- -// Color utils - -NanoVG::Color NanoVG::RGB(uchar r, uchar g, uchar b) -{ - return nvgRGB(r, g, b); -} - -NanoVG::Color NanoVG::RGBf(float r, float g, float b) -{ - return nvgRGBf(r, g, b); -} - -NanoVG::Color NanoVG::RGBA(uchar r, uchar g, uchar b, uchar a) -{ - return nvgRGBA(r, g, b, a); -} - -NanoVG::Color NanoVG::RGBAf(float r, float g, float b, float a) -{ - return nvgRGBAf(r, g, b, a); -} - -NanoVG::Color NanoVG::lerpRGBA(const Color& c0, const Color& c1, float u) -{ - return nvgLerpRGBA(c0, c1, u); -} - -NanoVG::Color NanoVG::HSL(float h, float s, float l) -{ - return nvgHSL(h, s, l); -} - -NanoVG::Color NanoVG::HSLA(float h, float s, float l, uchar a) -{ - return nvgHSLA(h, s, l, a); -} - // ----------------------------------------------------------------------- // State Handling @@ -436,19 +398,19 @@ NanoImage* NanoVG::createImageRGBA(int w, int h, const uchar* data) // ----------------------------------------------------------------------- // Paints -NanoVG::Paint NanoVG::linearGradient(float sx, float sy, float ex, float ey, const NanoVG::Color& icol, const NanoVG::Color& ocol) +NanoVG::Paint NanoVG::linearGradient(float sx, float sy, float ex, float ey, const Color& icol, const Color& ocol) { if (fContext == nullptr) return Paint(); return nvgLinearGradient(fContext, sx, sy, ex, ey, icol, ocol); } -NanoVG::Paint NanoVG::boxGradient(float x, float y, float w, float h, float r, float f, const NanoVG::Color& icol, const NanoVG::Color& ocol) +NanoVG::Paint NanoVG::boxGradient(float x, float y, float w, float h, float r, float f, const Color& icol, const Color& ocol) { if (fContext == nullptr) return Paint(); return nvgBoxGradient(fContext, x, y, w, h, r, f, icol, ocol); } -NanoVG::Paint NanoVG::radialGradient(float cx, float cy, float inr, float outr, const NanoVG::Color& icol, const NanoVG::Color& ocol) +NanoVG::Paint NanoVG::radialGradient(float cx, float cy, float inr, float outr, const Color& icol, const Color& ocol) { if (fContext == nullptr) return Paint(); return nvgRadialGradient(fContext, cx, cy, inr, outr, icol, ocol); diff --git a/distrho/DistrhoPlugin.hpp b/distrho/DistrhoPlugin.hpp index c7063500..996da808 100644 --- a/distrho/DistrhoPlugin.hpp +++ b/distrho/DistrhoPlugin.hpp @@ -22,7 +22,7 @@ #include -#ifdef PROPER_CPP11_SUPPORT +#ifdef DISTRHO_PROPER_CPP11_SUPPORT # include #else # include diff --git a/distrho/DistrhoUtils.hpp b/distrho/DistrhoUtils.hpp index 76669d2b..d6fd7105 100644 --- a/distrho/DistrhoUtils.hpp +++ b/distrho/DistrhoUtils.hpp @@ -24,7 +24,7 @@ #include #include -#ifdef PROPER_CPP11_SUPPORT +#ifdef DISTRHO_PROPER_CPP11_SUPPORT # include #else # include diff --git a/distrho/src/DistrhoDefines.h b/distrho/src/DistrhoDefines.h index 4750c4dd..501fc284 100644 --- a/distrho/src/DistrhoDefines.h +++ b/distrho/src/DistrhoDefines.h @@ -48,16 +48,16 @@ /* Check for C++11 support */ #if defined(HAVE_CPP11_SUPPORT) -# define PROPER_CPP11_SUPPORT +# define DISTRHO_PROPER_CPP11_SUPPORT #elif __cplusplus >= 201103L || (defined(__GNUC__) && defined(__GXX_EXPERIMENTAL_CXX0X__) && (__GNUC__ * 100 + __GNUC_MINOR__) >= 405) || __has_extension(cxx_noexcept) -# define PROPER_CPP11_SUPPORT +# define DISTRHO_PROPER_CPP11_SUPPORT # if (defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__) < 407 && ! defined(__clang__)) || (defined(__clang__) && ! __has_extension(cxx_override_control)) # define override // gcc4.7+ only # define final // gcc4.7+ only # endif #endif -#ifndef PROPER_CPP11_SUPPORT +#ifndef DISTRHO_PROPER_CPP11_SUPPORT # define noexcept throw() # define override # define final