diff --git a/src/common/nvg.cpp b/src/common/nvg.cpp index c43c3d4cb..3a6cf6d11 100644 --- a/src/common/nvg.cpp +++ b/src/common/nvg.cpp @@ -1,6 +1,7 @@ #include "nvg.hpp" namespace kb { +namespace viz2d { namespace nvg { namespace detail { class NVG; @@ -11,7 +12,7 @@ void set_current_context(NVGcontext* ctx) { nvg_instance = new NVG(ctx); } -NVG* get_current_context() { +static NVG* get_current_context() { assert(nvg_instance != nullptr); return nvg_instance; } @@ -81,15 +82,7 @@ void NVG::textBoxBounds(float x, float y, float breakRowWidth, const char* strin } int NVG::textGlyphPositions(float x, float y, const char* string, const char* end, GlyphPosition* positions, int maxPositions) { - std::vector gp(maxPositions); - int result = nvgTextGlyphPositions(getContext(), x, y, string, end, gp.data(), maxPositions); - for(int i = 0; i < maxPositions; ++i) { - positions[i].str = gp[i].str; - positions[i].x = gp[i].x; - positions[i].minx = gp[i].minx; - positions[i].maxx = gp[i].maxx; - } - return result; + return nvgTextGlyphPositions(getContext(), x, y, string, end, positions, maxPositions); } void NVG::textMetrics(float* ascender, float* descender, float* lineh) { @@ -97,17 +90,7 @@ void NVG::textMetrics(float* ascender, float* descender, float* lineh) { } int NVG::textBreakLines(const char* string, const char* end, float breakRowWidth, TextRow* rows, int maxRows) { - NVGtextRow tr[maxRows]; - int result = nvgTextBreakLines(getContext(),string, end, breakRowWidth, tr, maxRows); - for(int i = 0; i < maxRows; ++i) { - rows[i].start = tr[i].start; - rows[i].end = tr[i].end; - rows[i].next = tr[i].next; - rows[i].width = tr[i].width; - rows[i].minx = tr[i].minx; - rows[i].maxx = tr[i].maxx; - } - return result; + return nvgTextBreakLines(getContext(),string, end, breakRowWidth, rows, maxRows); } void NVG::save() { @@ -310,9 +293,7 @@ void NVG::stroke() { Paint NVG::linearGradient(float sx, float sy, float ex, float ey, const cv::Scalar& icol, const cv::Scalar& ocol) { NVGpaint np = nvgLinearGradient(getContext(), sx, sy, ex, ey, nvgRGBA(icol[2],icol[1],icol[0],icol[3]), nvgRGBA(ocol[2],ocol[1],ocol[0],ocol[3])); - Paint p(np); - cerr << "paint " << p.innerColor << ":" << p.outerColor << endl; - return p; + return Paint(np); } Paint NVG::boxGradient(float x, float y, float w, float h, float r, float f, const cv::Scalar& icol, const cv::Scalar& ocol) { @@ -640,5 +621,6 @@ void intersectScissor(float x, float y, float w, float h) { void resetScissor() { detail::get_current_context()->resetScissor(); } -} //namespace nvg -} //namespace kb +} +} +} diff --git a/src/common/nvg.hpp b/src/common/nvg.hpp index 6e02818df..4b76c048a 100644 --- a/src/common/nvg.hpp +++ b/src/common/nvg.hpp @@ -6,20 +6,13 @@ #include namespace kb { +namespace viz2d { namespace nvg { -struct TextRow { - const char* start; // Pointer to the input text where the row starts. - const char* end; // Pointer to the input text where the row ends (one past the last character). - const char* next; // Pointer to the beginning of the next row. - float width; // Logical width of the row. - float minx, maxx; // Actual bounds of the row. Logical with and bounds can differ because of kerning and some parts over extending. +struct TextRow : public NVGtextRow { }; -struct GlyphPosition { - const char* str; // Position of the glyph in the input string. - float x; // The x-coordinate of the logical glyph position. - float minx, maxx; // The bounds of the glyph shape. +struct GlyphPosition : public NVGglyphPosition { }; struct Paint { @@ -156,7 +149,7 @@ void resetScissor(); static NVG* nvg_instance; void set_current_context(NVGcontext* ctx); -NVG* get_current_context(); +static NVG* get_current_context(); } // namespace detail int createFont(const char* name, const char* filename); @@ -240,8 +233,9 @@ Paint imagePattern(float ox, float oy, float ex, float ey, float angle, int imag void scissor(float x, float y, float w, float h); void intersectScissor(float x, float y, float w, float h); void resetScissor(); -} // namespace nvg -} // namespace kb +} +} +}