From fad9f7068ffec2a3836e777cf395f593e8281088 Mon Sep 17 00:00:00 2001 From: James Turner Date: Mon, 25 Nov 2019 11:36:13 +0000 Subject: [PATCH] Expose canvas::Image pixel funcs to Nasal --- src/Scripting/NasalCanvas.cxx | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/Scripting/NasalCanvas.cxx b/src/Scripting/NasalCanvas.cxx index ee92a1a41..f9237e2a1 100644 --- a/src/Scripting/NasalCanvas.cxx +++ b/src/Scripting/NasalCanvas.cxx @@ -72,6 +72,7 @@ typedef nasal::Ghost NasalCanvas; typedef nasal::Ghost NasalElement; typedef nasal::Ghost NasalGroup; typedef nasal::Ghost NasalText; +typedef nasal::Ghost NasalImage; typedef nasal::Ghost NasalLayoutItem; typedef nasal::Ghost NasalLayout; @@ -398,6 +399,29 @@ static naRef f_newAsBase(const nasal::CallContext& ctx) return ctx.to_nasal(new Type()); } +static naRef f_imageFillRect(sc::Image& img, const nasal::CallContext& ctx) +{ + const SGRecti r = ctx.requireArg(0); + if (ctx.isString(1)) { + img.fillRect(r, ctx.getArg(1)); + } else { + img.fillRect(r, ctx.requireArg(1)); + } + return naNil(); +} + +static naRef f_imageSetPixel(sc::Image& img, const nasal::CallContext& ctx) +{ + const int s = ctx.requireArg(0); + const int t = ctx.requireArg(1); + if (ctx.isString(2)) { + img.setPixel(s, t, ctx.getArg(2)); + } else { + img.setPixel(s, t, ctx.requireArg(2)); + } + return naNil(); +} + naRef initNasalCanvas(naRef globals, naContext c) { nasal::Hash globals_module(globals, c), @@ -507,6 +531,11 @@ naRef initNasalCanvas(naRef globals, naContext c) .method("getNearestCursor", &sc::Text::getNearestCursor) .method("getCursorPos", &sc::Text::getCursorPos); + NasalImage::init("canvas.Image") + .bases() + .method("fillRect", &f_imageFillRect) + .method("setPixel", &f_imageSetPixel); + //---------------------------------------------------------------------------- // Layouting