| @@ -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(); | |||
| @@ -0,0 +1,99 @@ | |||
| /* | |||
| * DISTRHO Plugin Framework (DPF) | |||
| * Copyright (C) 2012-2014 Filipe Coelho <falktx@falktx.com> | |||
| * | |||
| * 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 | |||
| @@ -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; | |||
| @@ -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<int>& size, GLenum format = GL_BGRA, GLenum type = GL_UNSIGNED_BYTE); | |||
| Image(const char* const rawData, const Size<int>& 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<int>& size, GLenum format = GL_BGRA, GLenum type = GL_UNSIGNED_BYTE) noexcept; | |||
| void loadFromMemory(const char* const rawData, const Size<int>& 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. | |||
| @@ -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 \ | |||
| @@ -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 | |||
| @@ -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<int> getSize() const; | |||
| Size<int> 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<int> 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 */ | |||
| @@ -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 { | |||
| @@ -60,6 +60,8 @@ struct App::PrivateData { | |||
| if (--visibleWindows == 0) | |||
| doLoop = false; | |||
| } | |||
| DISTRHO_DECLARE_NON_COPY_STRUCT(PrivateData) | |||
| }; | |||
| // ----------------------------------------------------------------------- | |||
| @@ -0,0 +1,93 @@ | |||
| /* | |||
| * DISTRHO Plugin Framework (DPF) | |||
| * Copyright (C) 2012-2014 Filipe Coelho <falktx@falktx.com> | |||
| * | |||
| * 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<float>(r)/255.0f), green(static_cast<float>(g)/255.0f), blue(static_cast<float>(b)/255.0f), alpha(static_cast<float>(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 | |||
| @@ -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<int>& size, GLenum format, GLenum type) | |||
| Image::Image(const char* const rawData, const Size<int>& 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<int>(width, height), format, type); | |||
| } | |||
| void Image::loadFromMemory(const char* rawData, const Size<int>& size, GLenum format, GLenum type) noexcept | |||
| void Image::loadFromMemory(const char* const rawData, const Size<int>& 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<int>(x, y)); | |||
| } | |||
| @@ -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) | |||
| { | |||
| @@ -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<int> NanoImage::getSize() const | |||
| Size<int> NanoImage::getSize() const noexcept | |||
| { | |||
| int w=0, h=0; | |||
| if (fContext != nullptr && fImageId != 0) | |||
| nvgImageSize(fContext, fImageId, &w, &h); | |||
| return Size<int>(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<NVGalpha>(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); | |||
| @@ -22,7 +22,7 @@ | |||
| #include <cmath> | |||
| #ifdef PROPER_CPP11_SUPPORT | |||
| #ifdef DISTRHO_PROPER_CPP11_SUPPORT | |||
| # include <cstdint> | |||
| #else | |||
| # include <stdint.h> | |||
| @@ -24,7 +24,7 @@ | |||
| #include <cstdlib> | |||
| #include <cstring> | |||
| #ifdef PROPER_CPP11_SUPPORT | |||
| #ifdef DISTRHO_PROPER_CPP11_SUPPORT | |||
| # include <cstdint> | |||
| #else | |||
| # include <stdint.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 | |||