diff options
Diffstat (limited to 'src/nvg')
-rw-r--r-- | src/nvg/CMakeLists.txt | 16 | ||||
-rw-r--r-- | src/nvg/context.c | 3 | ||||
-rw-r--r-- | src/nvg/image.c | 16 | ||||
-rw-r--r-- | src/nvg/nvg.h | 10 | ||||
-rw-r--r-- | src/nvg/paint.c | 77 | ||||
-rw-r--r-- | src/nvg/path.c | 131 | ||||
-rw-r--r-- | src/nvg/render.c | 4 | ||||
-rw-r--r-- | src/nvg/scissor.c | 35 | ||||
-rw-r--r-- | src/nvg/setup.c | 5 | ||||
-rw-r--r-- | src/nvg/text.c | 182 | ||||
-rw-r--r-- | src/nvg/transform.c | 18 |
11 files changed, 434 insertions, 63 deletions
diff --git a/src/nvg/CMakeLists.txt b/src/nvg/CMakeLists.txt index 8003158..9a96328 100644 --- a/src/nvg/CMakeLists.txt +++ b/src/nvg/CMakeLists.txt @@ -1,3 +1,17 @@ project(honey_engine) -target_sources(honey PUBLIC ${CMAKE_CURRENT_LIST_DIR}/nvg.c) +target_sources(honey PUBLIC + ${CMAKE_CURRENT_LIST_DIR}/color.c + ${CMAKE_CURRENT_LIST_DIR}/composite.c + ${CMAKE_CURRENT_LIST_DIR}/context.c + ${CMAKE_CURRENT_LIST_DIR}/frame.c + ${CMAKE_CURRENT_LIST_DIR}/image.c + ${CMAKE_CURRENT_LIST_DIR}/path.c + ${CMAKE_CURRENT_LIST_DIR}/render.c + ${CMAKE_CURRENT_LIST_DIR}/setup.c + ${CMAKE_CURRENT_LIST_DIR}/state.c + ${CMAKE_CURRENT_LIST_DIR}/transform.c + ${CMAKE_CURRENT_LIST_DIR}/text.c + ${CMAKE_CURRENT_LIST_DIR}/paint.c + ${CMAKE_CURRENT_LIST_DIR}/scissor.c +) diff --git a/src/nvg/context.c b/src/nvg/context.c index 48a7282..ee386aa 100644 --- a/src/nvg/context.c +++ b/src/nvg/context.c @@ -1,5 +1,8 @@ #include <lua.h> #include <lauxlib.h> +#include "gl/glad/glad.h" +#include <GLFW/glfw3.h> +#define NANOVG_GL3_IMPLEMENTATION #include <nanovg.h> #include <nanovg_gl.h> #include "nvg.h" diff --git a/src/nvg/image.c b/src/nvg/image.c index e7f39c2..9a1d22c 100644 --- a/src/nvg/image.c +++ b/src/nvg/image.c @@ -5,15 +5,13 @@ #include "nvg.h" -int CreateImage_bind(lua_State *L) +int nvgCreateImage_bind(lua_State *L) { NVGcontext **ctx = luaL_checkudata(L, 1, nvg_ctx_tname); const char *filename = luaL_checkstring(L, 2); int flags = luaL_checkinteger(L, 3); - int *handle = lua_newuserdata(L, sizeof(int)); - luaL_getmetatable(L, nvg_image_tname); - lua_setmetatable(L, -2); - *handle = nvgCreateImage(*ctx, filename, flags); + int handle = nvgCreateImage(*ctx, filename, flags); + lua_pushinteger(L, handle); return 1; } @@ -21,9 +19,9 @@ int CreateImage_bind(lua_State *L) int nvgImageSize_bind(lua_State *L) { NVGcontext **ctx = luaL_checkudata(L, 1, nvg_ctx_tname); - int *handle = luaL_checkudata(L, 2, nvg_image_tname); + int handle = luaL_checkinteger(L, 2); int w, h; - nvgImageSize(*ctx, *handle, &w, &h); + nvgImageSize(*ctx, handle, &w, &h); lua_pushinteger(L, w); lua_pushinteger(L, h); return 2; @@ -33,7 +31,7 @@ int nvgImageSize_bind(lua_State *L) int nvgDeleteImage_bind(lua_State *L) { NVGcontext **ctx = luaL_checkudata(L, 1, nvg_ctx_tname); - int *handle = luaL_checkudata(L, 2, nvg_image_tname); - nvgDeleteImage(*ctx, *handle); + int handle = luaL_checkinteger(L, 2); + nvgDeleteImage(*ctx, handle); return 0; } diff --git a/src/nvg/nvg.h b/src/nvg/nvg.h index 33a2420..9bbb4a9 100644 --- a/src/nvg/nvg.h +++ b/src/nvg/nvg.h @@ -112,8 +112,8 @@ extern const char *nvg_paint_tname; /* text */ \ X("CreateFont", nvgCreateFont_bind) \ X("CreateFontAtIndex", nvgCreateFontAtIndex_bind) \ - X("CreateFontMem", nvgCreateFontMem_bind) \ - X("CreateFontMemAtIndex", nvgCreateFontMemAtIndex_bind) \ + /* X("CreateFontMem", nvgCreateFontMem_bind) */ \ + /* X("CreateFontMemAtIndex", nvgCreateFontMemAtIndex_bind) */ \ X("FindFont", nvgFindFont_bind) \ X("AddFallbackFontId", nvgAddFallbackFontId_bind) \ X("AddFallbackFont", nvgAddFallbackFont_bind) \ @@ -130,9 +130,9 @@ extern const char *nvg_paint_tname; X("TextBox", nvgTextBox_bind) \ X("TextBounds", nvgTextBounds_bind) \ X("TextBoxBounds", nvgTextBoxBounds_bind) \ - X("TextGlyphPositions", nvgTextGlyphPositions_bind) \ - X("TextMetrics", nvgTextMetrics_bind) \ - X("TextBreakLines", nvgTextBreakLines_bind) \ + /* X("TextGlyphPositions", nvgTextGlyphPositions_bind) */ \ + /* X("TextMetrics", nvgTextMetrics_bind) */ \ + /* X("TextBreakLines", nvgTextBreakLines_bind) */ \ /* function declarations */ diff --git a/src/nvg/paint.c b/src/nvg/paint.c new file mode 100644 index 0000000..0bdcae1 --- /dev/null +++ b/src/nvg/paint.c @@ -0,0 +1,77 @@ +#include <lua.h> +#include <lauxlib.h> +#include <nanovg.h> +#include <nanovg_gl.h> +#include "nvg.h" + + +static void create_paint(lua_State *L, NVGpaint paint) +{ + NVGpaint *p = lua_newuserdata(L, sizeof(NVGpaint)); + *p = paint; + luaL_getmetatable(L, nvg_paint_tname); + lua_setmetatable(L, -2); +} + +int nvgLinearGradient_bind(lua_State *L) +{ + NVGcontext **ctx = luaL_checkudata(L, 1, nvg_ctx_tname); + float sx = luaL_checknumber(L, 2); + float sy = luaL_checknumber(L, 3); + float ex = luaL_checknumber(L, 4); + float ey = luaL_checknumber(L, 5); + NVGcolor *icol = luaL_checkudata(L, 6, nvg_color_tname); + NVGcolor *ocol = luaL_checkudata(L, 7, nvg_color_tname); + create_paint(L, + nvgLinearGradient(*ctx, sx, sy, ex, ey, *icol, *ocol) + ); + return 1; +} + +int nvgBoxGradient_bind(lua_State *L) +{ + NVGcontext **ctx = luaL_checkudata(L, 1, nvg_ctx_tname); + float x = luaL_checknumber(L, 2); + float y = luaL_checknumber(L, 3); + float w = luaL_checknumber(L, 4); + float h = luaL_checknumber(L, 5); + float r = luaL_checknumber(L, 6); + float f = luaL_checknumber(L, 7); + NVGcolor *icol = luaL_checkudata(L, 8, nvg_color_tname); + NVGcolor *ocol = luaL_checkudata(L, 9, nvg_color_tname); + create_paint(L, + nvgBoxGradient(*ctx, x, y, w, h, r, f, *icol, *ocol) + ); + return 1; +} + +int nvgRadialGradient_bind(lua_State *L) +{ + NVGcontext **ctx = luaL_checkudata(L, 1, nvg_ctx_tname); + float cx = luaL_checknumber(L, 2); + float cy = luaL_checknumber(L, 3); + float inr = luaL_checknumber(L, 4); + float outr = luaL_checknumber(L, 5); + NVGcolor *icol = luaL_checkudata(L, 6, nvg_color_tname); + NVGcolor *ocol = luaL_checkudata(L, 7, nvg_color_tname); + create_paint(L, + nvgRadialGradient(*ctx, cx, cy, inr, outr, *icol, *ocol) + ); + return 1; +} + +int nvgImagePattern_bind(lua_State *L) +{ + NVGcontext **ctx = luaL_checkudata(L, 1, nvg_ctx_tname); + float ox = luaL_checknumber(L, 2); + float oy = luaL_checknumber(L, 3); + float ex = luaL_checknumber(L, 4); + float ey = luaL_checknumber(L, 5); + float angle = luaL_checknumber(L, 6); + int image = luaL_checkinteger(L, 7); + float alpha = luaL_checknumber(L, 8); + create_paint(L, + nvgImagePattern(*ctx, ox, oy, ex, ey, angle, image, alpha) + ); + return 1; +} diff --git a/src/nvg/path.c b/src/nvg/path.c index 1e0f527..7f2c4d0 100644 --- a/src/nvg/path.c +++ b/src/nvg/path.c @@ -1,117 +1,180 @@ +#include <lua.h> +#include <lauxlib.h> +#include <nanovg.h> +#include <nanovg_gl.h> +#include "nvg.h" + + /* --===== paths =====-- */ -int nvg_begin_path(lua_State *L) +int nvgBeginPath_bind(lua_State *L) { - struct NVGcontext **vg = luaL_checkudata(L, 1, ctx_tname); - nvgBeginPath(*vg); + struct NVGcontext **ctx = luaL_checkudata(L, 1, nvg_ctx_tname); + nvgBeginPath(*ctx); return 0; } -int nvg_move_to(lua_State *L) +int nvgMoveTo_bind(lua_State *L) { - struct NVGcontext **vg = luaL_checkudata(L, 1, ctx_tname); + struct NVGcontext **ctx = luaL_checkudata(L, 1, nvg_ctx_tname); float x = luaL_checknumber(L, 2); float y = luaL_checknumber(L, 3); - nvgMoveTo(*vg, x, y); + nvgMoveTo(*ctx, x, y); return 0; } -int nvg_line_to(lua_State *L) +int nvgLineTo_bind(lua_State *L) { - struct NVGcontext **vg = luaL_checkudata(L, 1, ctx_tname); + struct NVGcontext **ctx = luaL_checkudata(L, 1, nvg_ctx_tname); float x = luaL_checknumber(L, 2); float y = luaL_checknumber(L, 3); - nvgLineTo(*vg, x, y); + nvgLineTo(*ctx, x, y); return 0; } -int nvg_bezier_to(lua_State *L) +int nvgBezierTo_bind(lua_State *L) { - struct NVGcontext **vg = luaL_checkudata(L, 1, ctx_tname); + struct NVGcontext **ctx = luaL_checkudata(L, 1, nvg_ctx_tname); float c1x = luaL_checknumber(L, 2); float c1y = luaL_checknumber(L, 3); float c2x = luaL_checknumber(L, 4); float c2y = luaL_checknumber(L, 5); float x = luaL_checknumber(L, 6); float y = luaL_checknumber(L, 7); - nvgBezierTo(*vg, c1x, c1y, c2x, c2y, x, y); + nvgBezierTo(*ctx, c1x, c1y, c2x, c2y, x, y); return 0; } -int nvg_quad_to(lua_State *L) +int nvgQuadTo_bind(lua_State *L) { - struct NVGcontext **vg = luaL_checkudata(L, 1, ctx_tname); + struct NVGcontext **ctx = luaL_checkudata(L, 1, nvg_ctx_tname); float cx = luaL_checknumber(L, 2); float cy = luaL_checknumber(L, 3); float x = luaL_checknumber(L, 4); float y = luaL_checknumber(L, 5); - nvgQuadTo(*vg, cx, cy, x, y); + nvgQuadTo(*ctx, cx, cy, x, y); return 0; } -int nvg_arc_to(lua_State *L) +int nvgArcTo_bind(lua_State *L) { - struct NVGcontext **vg = luaL_checkudata(L, 1, ctx_tname); + struct NVGcontext **ctx = luaL_checkudata(L, 1, nvg_ctx_tname); float x1 = luaL_checknumber(L, 2); float y1 = luaL_checknumber(L, 3); float x2 = luaL_checknumber(L, 4); float y2 = luaL_checknumber(L, 5); float radius = luaL_checknumber(L, 6); - nvgArcTo(*vg, x1, y1, x2, y2, radius); + nvgArcTo(*ctx, x1, y1, x2, y2, radius); return 0; } -int nvg_close_path(lua_State *L) +int nvgClosePath_bind(lua_State *L) { - struct NVGcontext **vg = luaL_checkudata(L, 1, ctx_tname); - nvgClosePath(*vg); + struct NVGcontext **ctx = luaL_checkudata(L, 1, nvg_ctx_tname); + nvgClosePath(*ctx); return 0; } -int nvg_path_winding(lua_State *L) +int nvgPathWinding_bind(lua_State *L) { - struct NVGcontext **vg = luaL_checkudata(L, 1, ctx_tname); + struct NVGcontext **ctx = luaL_checkudata(L, 1, nvg_ctx_tname); int dir = luaL_checkinteger(L, 2); - nvgPathWinding(*vg, dir); + nvgPathWinding(*ctx, dir); return 0; } -int nvg_arc(lua_State *L) +int nvgArc_bind(lua_State *L) { - struct NVGcontext **vg = luaL_checkudata(L, 1, ctx_tname); + struct NVGcontext **ctx = luaL_checkudata(L, 1, nvg_ctx_tname); float cx = luaL_checknumber(L, 2); float cy = luaL_checknumber(L, 3); float r = luaL_checknumber(L, 4); float a0 = luaL_checknumber(L, 5); float a1 = luaL_checknumber(L, 6); int dir = luaL_checkinteger(L, 7); - nvgArc(*vg, cx, cy, r, a0, a1, dir); + nvgArc(*ctx, cx, cy, r, a0, a1, dir); + return 0; +} + + +int nvgRect_bind(lua_State *L) +{ + struct NVGcontext **ctx = luaL_checkudata(L, 1, nvg_ctx_tname); + float x = luaL_checknumber(L, 2); + float y = luaL_checknumber(L, 3); + float w = luaL_checknumber(L, 4); + float h = luaL_checknumber(L, 5); + nvgRect(*ctx, x, y, w, h); + return 0; +} + +int nvgRoundedRect_bind(lua_State *L) +{ + struct NVGcontext **ctx = luaL_checkudata(L, 1, nvg_ctx_tname); + float x = luaL_checknumber(L, 2); + float y = luaL_checknumber(L, 3); + float w = luaL_checknumber(L, 4); + float h = luaL_checknumber(L, 5); + float r = luaL_checknumber(L, 6); + nvgRoundedRect(*ctx, x, y, w, h, r); return 0; } -/* ... */ +int nvgRoundedRectVarying_bind(lua_State *L) +{ + struct NVGcontext **ctx = luaL_checkudata(L, 1, nvg_ctx_tname); + float x = luaL_checknumber(L, 2); + float y = luaL_checknumber(L, 3); + float w = luaL_checknumber(L, 4); + float h = luaL_checknumber(L, 5); + float rtl = luaL_checknumber(L, 6); + float rtr = luaL_checknumber(L, 7); + float rbl = luaL_checknumber(L, 8); + float rbr = luaL_checknumber(L, 9); + nvgRoundedRectVarying(*ctx, x, y, w, h, rtl, rtr, rbl, rbr); + return 0; +} -int nvg_fill(lua_State *L) +int nvgEllipse_bind(lua_State *L) { - struct NVGcontext **vg = luaL_checkudata(L, 1, ctx_tname); - nvgFill(*vg); + struct NVGcontext **ctx = luaL_checkudata(L, 1, nvg_ctx_tname); + float cx = luaL_checknumber(L, 2); + float cy = luaL_checknumber(L, 3); + float rx = luaL_checknumber(L, 4); + float ry = luaL_checknumber(L, 5); + nvgEllipse(*ctx, cx, cy, rx, ry); return 0; } +int nvgCircle_bind(lua_State *L) +{ + struct NVGcontext **ctx = luaL_checkudata(L, 1, nvg_ctx_tname); + float cx = luaL_checknumber(L, 2); + float cy = luaL_checknumber(L, 3); + float r = luaL_checknumber(L, 4); + nvgCircle(*ctx, cx, cy, r); + return 0; +} -int nvg_stroke(lua_State *L) +int nvgFill_bind(lua_State *L) { - struct NVGcontext **vg = luaL_checkudata(L, 1, ctx_tname); - nvgStroke(*vg); + struct NVGcontext **ctx = luaL_checkudata(L, 1, nvg_ctx_tname); + nvgFill(*ctx); return 0; } +int nvgStroke_bind(lua_State *L) +{ + struct NVGcontext **ctx = luaL_checkudata(L, 1, nvg_ctx_tname); + nvgStroke(*ctx); + return 0; +} diff --git a/src/nvg/render.c b/src/nvg/render.c index f28da90..87aaba2 100644 --- a/src/nvg/render.c +++ b/src/nvg/render.c @@ -5,10 +5,10 @@ #include "nvg.h" -int ShapeAntiAlias_bind(lua_State *L) +int nvgShapeAntiAlias_bind(lua_State *L) { NVGcontext **ctx = luaL_checkudata(L, 1, nvg_ctx_tname); - int enabled = luaL_toboolean(L, 2); + int enabled = lua_toboolean(L, 2); nvgShapeAntiAlias(*ctx, enabled); return 0; } diff --git a/src/nvg/scissor.c b/src/nvg/scissor.c new file mode 100644 index 0000000..7413c46 --- /dev/null +++ b/src/nvg/scissor.c @@ -0,0 +1,35 @@ +#include <lua.h> +#include <lauxlib.h> +#include <nanovg.h> +#include <nanovg_gl.h> +#include "nvg.h" + + +int nvgScissor_bind(lua_State *L) +{ + NVGcontext **ctx = luaL_checkudata(L, 1, nvg_ctx_tname); + float x = luaL_checknumber(L, 2); + float y = luaL_checknumber(L, 3); + float w = luaL_checknumber(L, 4); + float h = luaL_checknumber(L, 5); + nvgScissor(*ctx, x, y, w, h); + return 0; +} + +int nvgIntersectScissor_bind(lua_State *L) +{ + NVGcontext **ctx = luaL_checkudata(L, 1, nvg_ctx_tname); + float x = luaL_checknumber(L, 2); + float y = luaL_checknumber(L, 3); + float w = luaL_checknumber(L, 4); + float h = luaL_checknumber(L, 5); + nvgIntersectScissor(*ctx, x, y, w, h); + return 0; +} + +int nvgResetScissor_bind(lua_State *L) +{ + NVGcontext **ctx = luaL_checkudata(L, 1, nvg_ctx_tname); + nvgResetScissor(*ctx); + return 0; +} diff --git a/src/nvg/setup.c b/src/nvg/setup.c index 16766c0..0404f91 100644 --- a/src/nvg/setup.c +++ b/src/nvg/setup.c @@ -1,8 +1,5 @@ #include <lua.h> #include <lauxlib.h> -#include "gl/glad/glad.h" -#include <GLFW/glfw3.h> -#define NANOVG_GL3_IMPLEMENTATION #include <nanovg.h> #include <nanovg_gl.h> #include "util/util.h" @@ -11,6 +8,8 @@ const char *nvg_ctx_tname = "nvg.Context"; const char *nvg_color_tname = "nvg.Color"; +const char *nvg_image_tname = "nvg.Image"; +const char *nvg_paint_tname = "nvg.Paint"; void setup_nvg(lua_State *L, int honey_tbl) diff --git a/src/nvg/text.c b/src/nvg/text.c new file mode 100644 index 0000000..cd480f6 --- /dev/null +++ b/src/nvg/text.c @@ -0,0 +1,182 @@ +#include <lua.h> +#include <lauxlib.h> +#include <nanovg.h> +#include <nanovg_gl.h> +#include "nvg.h" + + +int nvgCreateFont_bind(lua_State *L) +{ + NVGcontext **ctx = luaL_checkudata(L, 1, nvg_ctx_tname); + const char *name = luaL_checkstring(L, 2); + const char *filename = luaL_checkstring(L, 3); + lua_pushinteger(L, + nvgCreateFont(*ctx, name, filename) + ); + return 1; +} + +int nvgCreateFontAtIndex_bind(lua_State *L) +{ + NVGcontext **ctx = luaL_checkudata(L, 1, nvg_ctx_tname); + const char *name = luaL_checkstring(L, 2); + const char *filename = luaL_checkstring(L, 3); + int index = luaL_checkinteger(L, 4); + lua_pushinteger(L, + nvgCreateFontAtIndex(*ctx, name, filename, index) + ); + return 1; + +} + +int nvgFindFont_bind(lua_State *L) +{ + NVGcontext **ctx = luaL_checkudata(L, 1, nvg_ctx_tname); + const char *name = luaL_checkstring(L, 2); + lua_pushinteger(L, + nvgFindFont(*ctx, name) + ); + return 1; +} + +int nvgAddFallbackFontId_bind(lua_State *L) +{ + NVGcontext **ctx = luaL_checkudata(L, 1, nvg_ctx_tname); + int baseFont = luaL_checkinteger(L, 2); + int fallbackFont = luaL_checkinteger(L, 3); + int font = nvgAddFallbackFontId(*ctx, baseFont, fallbackFont); + lua_pushinteger(L, font); + return 1; +} + +int nvgAddFallbackFont_bind(lua_State *L) +{ + NVGcontext **ctx = luaL_checkudata(L, 1, nvg_ctx_tname); + const char *baseFont = luaL_checkstring(L, 2); + const char *fallbackFont = luaL_checkstring(L, 3); + int font = nvgAddFallbackFont(*ctx, baseFont, fallbackFont); + lua_pushinteger(L, font); + return 1; +} + +int nvgResetFallbackFontsId_bind(lua_State *L) +{ + NVGcontext **ctx = luaL_checkudata(L, 1, nvg_ctx_tname); + int baseFont = luaL_checkinteger(L, 2); + nvgResetFallbackFontsId(*ctx, baseFont); + return 0; +} + +int nvgResetFallbackFonts_bind(lua_State *L) +{ + NVGcontext **ctx = luaL_checkudata(L, 1, nvg_ctx_tname); + const char *baseFont = luaL_checkstring(L, 2); + nvgResetFallbackFonts(*ctx, baseFont); + return 0; +} + +int nvgFontSize_bind(lua_State *L) +{ + NVGcontext **ctx = luaL_checkudata(L, 1, nvg_ctx_tname); + float size = luaL_checknumber(L, 2); + nvgFontSize(*ctx, size); + return 0; +} + +int nvgFontBlur_bind(lua_State *L) +{ + NVGcontext **ctx = luaL_checkudata(L, 1, nvg_ctx_tname); + float blur = luaL_checknumber(L, 2); + nvgFontBlur(*ctx, blur); + return 0; +} + +int nvgTextLetterSpacing_bind(lua_State *L) +{ + NVGcontext **ctx = luaL_checkudata(L, 1, nvg_ctx_tname); + float spacing = luaL_checknumber(L, 2); + nvgTextLetterSpacing(*ctx, spacing); + return 0; +} + +int nvgTextLineHeight_bind(lua_State *L) +{ + NVGcontext **ctx = luaL_checkudata(L, 1, nvg_ctx_tname); + float lineHeight = luaL_checknumber(L, 2); + nvgTextLineHeight(*ctx, lineHeight); + return 0; +} + +int nvgTextAlign_bind(lua_State *L) +{ + NVGcontext **ctx = luaL_checkudata(L, 1, nvg_ctx_tname); + int align = luaL_checkinteger(L, 2); + nvgTextAlign(*ctx, align); + return 0; +} + +int nvgFontFaceId_bind(lua_State *L) +{ + NVGcontext **ctx = luaL_checkudata(L, 1, nvg_ctx_tname); + int font = luaL_checknumber(L, 2); + nvgFontFaceId(*ctx, font); + return 0; +} + +int nvgFontFace_bind(lua_State *L) +{ + NVGcontext **ctx = luaL_checkudata(L, 1, nvg_ctx_tname); + const char *font = luaL_checkstring(L, 2); + nvgFontFace(*ctx, font); + return 0; +} + +int nvgText_bind(lua_State *L) +{ + NVGcontext **ctx = luaL_checkudata(L, 1, nvg_ctx_tname); + float x = luaL_checknumber(L, 2); + float y = luaL_checknumber(L, 3); + const char *string = luaL_checkstring(L, 4); + nvgText(*ctx, x, y, string, NULL); + return 0; +} + +int nvgTextBox_bind(lua_State *L) +{ + NVGcontext **ctx = luaL_checkudata(L, 1, nvg_ctx_tname); + float x = luaL_checknumber(L, 2); + float y = luaL_checknumber(L, 3); + float breakRowWidth = luaL_checknumber(L, 4); + const char *string = luaL_checkstring(L, 5); + nvgTextBox(*ctx, x, y, breakRowWidth, string, NULL); + return 0; +} + +int nvgTextBounds_bind(lua_State *L) +{ + NVGcontext **ctx = luaL_checkudata(L, 1, nvg_ctx_tname); + float x = luaL_checknumber(L, 2); + float y = luaL_checknumber(L, 3); + const char *string = luaL_checkstring(L, 4); + float bounds[4]; + nvgTextBounds(*ctx, x, y, string, NULL, bounds); + for (int i=0; i<4; i++) { + lua_pushnumber(L, bounds[i]); + } + return 4; +} + +int nvgTextBoxBounds_bind(lua_State *L) +{ + NVGcontext **ctx = luaL_checkudata(L, 1, nvg_ctx_tname); + float x = luaL_checknumber(L, 2); + float y = luaL_checknumber(L, 3); + const char *string = luaL_checkstring(L, 4); + float breakRowWidth = luaL_checknumber(L, 5); + float bounds[4]; + nvgTextBoxBounds(*ctx, x, y, breakRowWidth, string, NULL, bounds); + for (int i=0; i<4; i++) { + lua_pushnumber(L, bounds[i]); + } + return 4; +} diff --git a/src/nvg/transform.c b/src/nvg/transform.c index a4ab1eb..6fe0c3f 100644 --- a/src/nvg/transform.c +++ b/src/nvg/transform.c @@ -7,7 +7,7 @@ int nvgResetTransform_bind(lua_State *L) { - NVGcontext **ctx = lua_checkudata(L, 1, nvg_ctx_tname); + NVGcontext **ctx = luaL_checkudata(L, 1, nvg_ctx_tname); nvgResetTransform(*ctx); return 0; } @@ -15,21 +15,21 @@ int nvgResetTransform_bind(lua_State *L) int nvgTransform_bind(lua_State *L) { - NVGcontext **ctx = lua_checkudata(L, 1, nvg_ctx_tname); + NVGcontext **ctx = luaL_checkudata(L, 1, nvg_ctx_tname); float a = luaL_checknumber(L, 2); float b = luaL_checknumber(L, 3); float c = luaL_checknumber(L, 4); float d = luaL_checknumber(L, 5); float e = luaL_checknumber(L, 6); float f = luaL_checknumber(L, 7); - nvgTransform(ctx, a, b, c, d, e, f); + nvgTransform(*ctx, a, b, c, d, e, f); return 0; } int nvgTranslate_bind(lua_State *L) { - NVGcontext **ctx = lua_checkudata(L, 1, nvg_ctx_tname); + NVGcontext **ctx = luaL_checkudata(L, 1, nvg_ctx_tname); float x = luaL_checknumber(L, 2); float y = luaL_checknumber(L, 3); nvgTranslate(*ctx, x, y); @@ -39,7 +39,7 @@ int nvgTranslate_bind(lua_State *L) int nvgRotate_bind(lua_State *L) { - NVGcontext **ctx = lua_checkudata(L, 1, nvg_ctx_tname); + NVGcontext **ctx = luaL_checkudata(L, 1, nvg_ctx_tname); float angle = luaL_checknumber(L, 2); nvgRotate(*ctx, angle); return 0; @@ -48,7 +48,7 @@ int nvgRotate_bind(lua_State *L) int nvgSkewX_bind(lua_State *L) { - NVGcontext **ctx = lua_checkudata(L, 1, nvg_ctx_tname); + NVGcontext **ctx = luaL_checkudata(L, 1, nvg_ctx_tname); float angle = luaL_checknumber(L, 2); nvgSkewX(*ctx, angle); return 0; @@ -57,7 +57,7 @@ int nvgSkewX_bind(lua_State *L) int nvgSkewY_bind(lua_State *L) { - NVGcontext **ctx = lua_checkudata(L, 1, nvg_ctx_tname); + NVGcontext **ctx = luaL_checkudata(L, 1, nvg_ctx_tname); float angle = luaL_checknumber(L, 2); nvgSkewY(*ctx, angle); return 0; @@ -66,7 +66,7 @@ int nvgSkewY_bind(lua_State *L) int nvgScale_bind(lua_State *L) { - NVGcontext **ctx = lua_checkudata(L, 1, nvg_ctx_tname); + NVGcontext **ctx = luaL_checkudata(L, 1, nvg_ctx_tname); float x = luaL_checknumber(L, 2); float y = luaL_checknumber(L, 3); nvgScale(*ctx, x, y); @@ -76,7 +76,7 @@ int nvgScale_bind(lua_State *L) int nvgCurrentTransform_bind(lua_State *L) { - NVGcontext **ctx = luaL_checkudate(L, 1, nvg_ctx_tname); + NVGcontext **ctx = luaL_checkudata(L, 1, nvg_ctx_tname); float xform[6]; nvgCurrentTransform(*ctx, xform); for (int i=0; i<6; i++) { |