From 88c679f3d7ab7c05ab8b5007bb24c70b7d7e6e25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20R=C3=B8nning?= Date: Mon, 9 Apr 2018 15:31:02 +0200 Subject: [PATCH 1/6] Partial reverse of 3746f04 to fix windows build --- linc/linc_nanovg.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/linc/linc_nanovg.cpp b/linc/linc_nanovg.cpp index 286f207..b435fe2 100755 --- a/linc/linc_nanovg.cpp +++ b/linc/linc_nanovg.cpp @@ -1,6 +1,4 @@ -#ifndef HXCPP_H #include -#endif #include From 43475c600612cc87556ee56037642fc9d1769c18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20R=C3=B8nning?= Date: Wed, 17 Oct 2018 12:00:48 +0200 Subject: [PATCH 2/6] Add helper functions for textBounds and textBoxBounds --- linc/linc_nanovg.cpp | 12 ++++++++++++ linc/linc_nanovg.h | 3 +++ nanovg/Nvg.hx | 12 +++++++----- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/linc/linc_nanovg.cpp b/linc/linc_nanovg.cpp index b435fe2..3aace78 100755 --- a/linc/linc_nanovg.cpp +++ b/linc/linc_nanovg.cpp @@ -38,4 +38,16 @@ namespace nanovg { nvgDeleteGL3ES(_ctx); #endif } + + Array nvgTextBoundsHelper(NVGcontext* _ctx, float _x, float _y, String _string, String _end) { + Array out = new Array_obj(4, 0); + nvgTextBounds(_ctx, _x, _y, _string.c_str(), _end.c_str(), (float*)out->getBase()); + return out; + } + + Array nvgTextBoxBoundsHelper(NVGcontext* _ctx, float _x, float _y, float _breakRowWidth, String _string, String _end) { + Array out = new Array_obj(4, 0); + nvgTextBoxBounds(_ctx, _x, _y, _breakRowWidth, _string.c_str(), _end.c_str(), (float*)out->getBase()); + return out; + } } \ No newline at end of file diff --git a/linc/linc_nanovg.h b/linc/linc_nanovg.h index 82e29f6..f31f483 100755 --- a/linc/linc_nanovg.h +++ b/linc/linc_nanovg.h @@ -1,5 +1,6 @@ #pragma once +#include "hxcpp.h" #include "nanovg.h" struct NVGcontext; @@ -7,4 +8,6 @@ struct NVGcontext; namespace nanovg { NVGcontext* nvgCreateGL(int _flags); void nvgDeleteGL(NVGcontext* _ctx); + Array nvgTextBoxBoundsHelper(NVGcontext* _ctx, float _x, float _y, float _breakRowWidth, String _string, String _end); + Array nvgTextBoundsHelper(NVGcontext* _ctx, float _x, float _y, String _string, String _end); } diff --git a/nanovg/Nvg.hx b/nanovg/Nvg.hx index 4b8d088..fa47332 100755 --- a/nanovg/Nvg.hx +++ b/nanovg/Nvg.hx @@ -388,11 +388,13 @@ extern class Nvg { @:native("::nvgTextBox") public static function textBox(_ctx:Pointer, _x:Float, _y:Float, _breakRowWidth:Float, _string:String, _end:String):Void; - @:native("::nvgTextBounds") - public static function textBounds(_ctx:Pointer, _x:Float, _y:Float, _string:String, _end:String, _bounds:Pointer):Float; - - @:native("::nvgTextBoxBounds") - public static function textBoxBounds(_ctx:Pointer, _x:Float, _y:Float, _breakRowWidth:Float, _string:String, _end:String, _bounds:Pointer):Void; + public static inline function textBounds(_ctx:Pointer, _x:Float, _y:Float, _string:String, _end:String):Array{ + return untyped __cpp__('nanovg::nvgTextBoundsHelper({0},{1},{2},{3},{4})', _ctx, _x, _y, _string, _end); + } + + public static inline function textBoxBounds(_ctx:Pointer, _x:Float, _y:Float, _breakRowWidth:Float, _string:String, _end:String):Array{ + return untyped __cpp__('nanovg::nvgTextBoxBoundsHelper({0},{1},{2},{3},{4},{5})', _ctx, _x, _y, _breakRowWidth, _string, _end); + } @:native("::nvgTextGlyphPositions") public static function textGlyphPositions(_ctx:Pointer, _x:Float, _y:Float, _string:String, _end:String, _positions:Pointer, _maxPositions:Int):Int; From d138ff649eba908e1a7fdefa4f2955c566be2e75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20R=C3=B8nning?= Date: Thu, 1 Nov 2018 15:52:45 +0100 Subject: [PATCH 3/6] Fixed bad use of new operator --- linc/linc_nanovg.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/linc/linc_nanovg.cpp b/linc/linc_nanovg.cpp index 3aace78..5a3f64f 100755 --- a/linc/linc_nanovg.cpp +++ b/linc/linc_nanovg.cpp @@ -40,13 +40,13 @@ namespace nanovg { } Array nvgTextBoundsHelper(NVGcontext* _ctx, float _x, float _y, String _string, String _end) { - Array out = new Array_obj(4, 0); + Array out = Array_obj::__new(4); nvgTextBounds(_ctx, _x, _y, _string.c_str(), _end.c_str(), (float*)out->getBase()); return out; } Array nvgTextBoxBoundsHelper(NVGcontext* _ctx, float _x, float _y, float _breakRowWidth, String _string, String _end) { - Array out = new Array_obj(4, 0); + Array out = Array_obj::__new(4); nvgTextBoxBounds(_ctx, _x, _y, _breakRowWidth, _string.c_str(), _end.c_str(), (float*)out->getBase()); return out; } From 53529a771eaa697db333044ae01834fe2445e19e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20R=C3=B8nning?= Date: Sun, 4 Nov 2018 14:52:49 +0100 Subject: [PATCH 4/6] Functioning createFontMem using BytesData address --- nanovg/Nvg.hx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nanovg/Nvg.hx b/nanovg/Nvg.hx index fa47332..aa4353b 100755 --- a/nanovg/Nvg.hx +++ b/nanovg/Nvg.hx @@ -356,7 +356,7 @@ extern class Nvg { public static function createFont(_ctx:Pointer, _name:String, _filename:String):Int; @:native("::nvgCreateFontMem") - public static function createFontMem(_ctx:Pointer, _name:String, _data:haxe.io.BytesData, _ndata:Int, _freeData:Int):Int; + public static function createFontMem(_ctx:Pointer, _name:String, _data:cpp.Star, _ndata:Int, _freeData:Int):Int; @:native("::nvgFindFont") public static function findFont(_ctx:Pointer, _name:String):Int; From 7867ad7d8bec4e86bb5c23c944397e8fb7decefd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20R=C3=B8nning?= Date: Thu, 29 Nov 2018 15:33:04 +0100 Subject: [PATCH 5/6] textBreakLines helper --- linc/linc_nanovg.cpp | 38 +++++++++++++++++++++++++++++++------- linc/linc_nanovg.h | 6 ++++-- nanovg/Nvg.hx | 22 ++++++++++++++++------ 3 files changed, 51 insertions(+), 15 deletions(-) diff --git a/linc/linc_nanovg.cpp b/linc/linc_nanovg.cpp index 5a3f64f..1dc2517 100755 --- a/linc/linc_nanovg.cpp +++ b/linc/linc_nanovg.cpp @@ -39,15 +39,39 @@ namespace nanovg { #endif } - Array nvgTextBoundsHelper(NVGcontext* _ctx, float _x, float _y, String _string, String _end) { - Array out = Array_obj::__new(4); - nvgTextBounds(_ctx, _x, _y, _string.c_str(), _end.c_str(), (float*)out->getBase()); - return out; + + Array nvgTextBreakLinesHelper(NVGcontext* ctx, String string, float breakRowWidth){ + Array outArray = Array_obj::__new(0, 1); + NVGtextRow rows[3]; + const char* text = string.c_str(); + const char* start = text; + const char* end = text + strlen(text); + int nrows; + int i; + while ((nrows = nvgTextBreakLines(ctx, start, end, breakRowWidth, rows, 3))) { + for (i = 0; i < nrows; i++) { + NVGtextRow row = rows[i]; + hx::Anon result = hx::Anon_obj::Create(); + result->Add(HX_CSTRING("start"), row.start); + result->Add(HX_CSTRING("end"), row.end); + result->Add(HX_CSTRING("next"), row.next); + result->Add(HX_CSTRING("width"), row.width); + result->Add(HX_CSTRING("minx"), row.minx); + result->Add(HX_CSTRING("maxx"), row.maxx); + outArray->push(result); + + } + // Keep going... + start = rows[nrows-1].next; + } + return outArray; + } + + float nvgTextBoundsHelper(NVGcontext* _ctx, float _x, float _y, String _string, String _end, Array outArray) { + return nvgTextBounds(_ctx, _x, _y, _string.c_str(), _end.c_str(), (float*)outArray->getBase()); } - Array nvgTextBoxBoundsHelper(NVGcontext* _ctx, float _x, float _y, float _breakRowWidth, String _string, String _end) { - Array out = Array_obj::__new(4); + void nvgTextBoxBoundsHelper(NVGcontext* _ctx, float _x, float _y, float _breakRowWidth, String _string, String _end, Array out) { nvgTextBoxBounds(_ctx, _x, _y, _breakRowWidth, _string.c_str(), _end.c_str(), (float*)out->getBase()); - return out; } } \ No newline at end of file diff --git a/linc/linc_nanovg.h b/linc/linc_nanovg.h index f31f483..35ec6e9 100755 --- a/linc/linc_nanovg.h +++ b/linc/linc_nanovg.h @@ -4,10 +4,12 @@ #include "nanovg.h" struct NVGcontext; +struct NVGtextRow; namespace nanovg { NVGcontext* nvgCreateGL(int _flags); void nvgDeleteGL(NVGcontext* _ctx); - Array nvgTextBoxBoundsHelper(NVGcontext* _ctx, float _x, float _y, float _breakRowWidth, String _string, String _end); - Array nvgTextBoundsHelper(NVGcontext* _ctx, float _x, float _y, String _string, String _end); + float nvgTextBoundsHelper(NVGcontext* _ctx, float _x, float _y, String _string, String _end, Array out); + Array nvgTextBreakLinesHelper(NVGcontext* ctx, String string, float breakRowWidth); + void nvgTextBoxBoundsHelper(NVGcontext* _ctx, float _x, float _y, float _breakRowWidth, String _string, String _end, Array out); } diff --git a/nanovg/Nvg.hx b/nanovg/Nvg.hx index aa4353b..9344f18 100755 --- a/nanovg/Nvg.hx +++ b/nanovg/Nvg.hx @@ -388,12 +388,12 @@ extern class Nvg { @:native("::nvgTextBox") public static function textBox(_ctx:Pointer, _x:Float, _y:Float, _breakRowWidth:Float, _string:String, _end:String):Void; - public static inline function textBounds(_ctx:Pointer, _x:Float, _y:Float, _string:String, _end:String):Array{ - return untyped __cpp__('nanovg::nvgTextBoundsHelper({0},{1},{2},{3},{4})', _ctx, _x, _y, _string, _end); + public static inline function textBounds(_ctx:Pointer, _x:Float, _y:Float, _string:String, _end:String, out:Array):Float{ + return untyped __cpp__('nanovg::nvgTextBoundsHelper({0},{1},{2},{3},{4},{5})', _ctx, _x, _y, _string, _end, out); } - public static inline function textBoxBounds(_ctx:Pointer, _x:Float, _y:Float, _breakRowWidth:Float, _string:String, _end:String):Array{ - return untyped __cpp__('nanovg::nvgTextBoxBoundsHelper({0},{1},{2},{3},{4},{5})', _ctx, _x, _y, _breakRowWidth, _string, _end); + public static inline function textBoxBounds(_ctx:Pointer, _x:Float, _y:Float, _breakRowWidth:Float, _string:String, _end:String, out:Array):Void{ + untyped __cpp__('nanovg::nvgTextBoxBoundsHelper({0},{1},{2},{3},{4},{5},{6})', _ctx, _x, _y, _breakRowWidth, _string, _end, out); } @:native("::nvgTextGlyphPositions") @@ -402,7 +402,17 @@ extern class Nvg { @:native("::nvgTextMetrics") public static function textMetrics(_ctx:Pointer, _ascender:Pointer, _descender:Pointer, _lineh:Pointer):Void; - @:native("::nvgTextBreakLines") - public static function textBreakLines(_ctx:Pointer, _string:String, _end:String, _breakRowWidth:Float, _rows:Pointer, _maxRows:Int):Int; + //@:native("::nvgTextBreakLines") + public static inline function textBreakLines(_ctx:Pointer, _string:String, _breakRowWidth:Float):Array< + { + start:String, + end:String, + next:String, + width:Float, + minx:Float, + maxx:Float + }>{ + return untyped __cpp__('nanovg::nvgTextBreakLinesHelper({0},{1},{2})', _ctx, _string, _breakRowWidth); + } } From a6af4f40d816da7cf994516061387bfe9b0046c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20R=C3=B8nning?= Date: Sat, 19 Jan 2019 00:27:30 +0100 Subject: [PATCH 6/6] Don't init glew --- linc/linc_nanovg.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/linc/linc_nanovg.cpp b/linc/linc_nanovg.cpp index 1dc2517..eafd744 100755 --- a/linc/linc_nanovg.cpp +++ b/linc/linc_nanovg.cpp @@ -8,10 +8,6 @@ namespace nanovg { NVGcontext* nvgCreateGL(int _flags) { - GLenum err = glewInit(); - if (err != GLEW_OK) { - printf("Could not init glew.\n"); - } NVGcontext* ctx = #if NANOVG_GL2_IMPLEMENTATION