diff --git a/linc/linc_nanovg.cpp b/linc/linc_nanovg.cpp index 286f207..eafd744 100755 --- a/linc/linc_nanovg.cpp +++ b/linc/linc_nanovg.cpp @@ -1,6 +1,4 @@ -#ifndef HXCPP_H #include -#endif #include @@ -10,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 @@ -40,4 +34,40 @@ namespace nanovg { nvgDeleteGL3ES(_ctx); #endif } + + + 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()); + } + + 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()); + } } \ No newline at end of file diff --git a/linc/linc_nanovg.h b/linc/linc_nanovg.h index 82e29f6..35ec6e9 100755 --- a/linc/linc_nanovg.h +++ b/linc/linc_nanovg.h @@ -1,10 +1,15 @@ #pragma once +#include "hxcpp.h" #include "nanovg.h" struct NVGcontext; +struct NVGtextRow; namespace nanovg { NVGcontext* nvgCreateGL(int _flags); void nvgDeleteGL(NVGcontext* _ctx); + 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 4b8d088..9344f18 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; @@ -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, 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, out:Array):Void{ + untyped __cpp__('nanovg::nvgTextBoxBoundsHelper({0},{1},{2},{3},{4},{5},{6})', _ctx, _x, _y, _breakRowWidth, _string, _end, out); + } @:native("::nvgTextGlyphPositions") public static function textGlyphPositions(_ctx:Pointer, _x:Float, _y:Float, _string:String, _end:String, _positions:Pointer, _maxPositions:Int):Int; @@ -400,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); + } }