Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Partial reverse of 3746f04 to fix windows build #7

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 36 additions & 6 deletions linc/linc_nanovg.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#ifndef HXCPP_H
#include <hxcpp.h>
#endif

#include <GL/glew.h>

Expand All @@ -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
Expand All @@ -40,4 +34,40 @@ namespace nanovg {
nvgDeleteGL3ES(_ctx);
#endif
}


Array<Dynamic> nvgTextBreakLinesHelper(NVGcontext* ctx, String string, float breakRowWidth){
Array<Dynamic> outArray = Array_obj<Dynamic>::__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<float> 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<float> out) {
nvgTextBoxBounds(_ctx, _x, _y, _breakRowWidth, _string.c_str(), _end.c_str(), (float*)out->getBase());
}
}
5 changes: 5 additions & 0 deletions linc/linc_nanovg.h
Original file line number Diff line number Diff line change
@@ -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<float> out);
Array<Dynamic> nvgTextBreakLinesHelper(NVGcontext* ctx, String string, float breakRowWidth);
void nvgTextBoxBoundsHelper(NVGcontext* _ctx, float _x, float _y, float _breakRowWidth, String _string, String _end, Array<float> out);
}
28 changes: 20 additions & 8 deletions nanovg/Nvg.hx
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ extern class Nvg {
public static function createFont(_ctx:Pointer<NvgContext>, _name:String, _filename:String):Int;

@:native("::nvgCreateFontMem")
public static function createFontMem(_ctx:Pointer<NvgContext>, _name:String, _data:haxe.io.BytesData, _ndata:Int, _freeData:Int):Int;
public static function createFontMem(_ctx:Pointer<NvgContext>, _name:String, _data:cpp.Star<UInt8>, _ndata:Int, _freeData:Int):Int;

@:native("::nvgFindFont")
public static function findFont(_ctx:Pointer<NvgContext>, _name:String):Int;
Expand Down Expand Up @@ -388,19 +388,31 @@ extern class Nvg {
@:native("::nvgTextBox")
public static function textBox(_ctx:Pointer<NvgContext>, _x:Float, _y:Float, _breakRowWidth:Float, _string:String, _end:String):Void;

@:native("::nvgTextBounds")
public static function textBounds(_ctx:Pointer<NvgContext>, _x:Float, _y:Float, _string:String, _end:String, _bounds:Pointer<Float32>):Float;

@:native("::nvgTextBoxBounds")
public static function textBoxBounds(_ctx:Pointer<NvgContext>, _x:Float, _y:Float, _breakRowWidth:Float, _string:String, _end:String, _bounds:Pointer<Float32>):Void;
public static inline function textBounds(_ctx:Pointer<NvgContext>, _x:Float, _y:Float, _string:String, _end:String, out:Array<Float32>):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<NvgContext>, _x:Float, _y:Float, _breakRowWidth:Float, _string:String, _end:String, out:Array<Float32>):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<NvgContext>, _x:Float, _y:Float, _string:String, _end:String, _positions:Pointer<NvgGlyphPosition>, _maxPositions:Int):Int;

@:native("::nvgTextMetrics")
public static function textMetrics(_ctx:Pointer<NvgContext>, _ascender:Pointer<Float32>, _descender:Pointer<Float32>, _lineh:Pointer<Float32>):Void;

@:native("::nvgTextBreakLines")
public static function textBreakLines(_ctx:Pointer<NvgContext>, _string:String, _end:String, _breakRowWidth:Float, _rows:Pointer<NvgTextRow>, _maxRows:Int):Int;
//@:native("::nvgTextBreakLines")
public static inline function textBreakLines(_ctx:Pointer<NvgContext>, _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);
}
}