Commit c130f9e5 authored by Hanspeter Portner's avatar Hanspeter Portner

api: add canvas:Transform instruction.

parent 5d054e07
Pipeline #21803957 passed with stages
in 8 minutes and 55 seconds
......@@ -1746,6 +1746,7 @@ moony_open(moony_t *moony, moony_vm_t *vm, lua_State *L)
SET_MAP(L, CANVAS__, Translate);
SET_MAP(L, CANVAS__, Scale);
SET_MAP(L, CANVAS__, Rotate);
SET_MAP(L, CANVAS__, Transform);
SET_MAP(L, CANVAS__, Reset);
SET_MAP(L, CANVAS__, FontSize);
SET_MAP(L, CANVAS__, FillText);
......
......@@ -1795,6 +1795,25 @@ _lforge_canvas_rotate(lua_State *L)
return 1;
}
__realtime static int
_lforge_canvas_transform(lua_State *L)
{
moony_t *moony = lua_touserdata(L, lua_upvalueindex(1));
lforge_t *lforge = lua_touserdata(L, 1);
if(!lv2_canvas_forge_transform(lforge->forge, &moony->canvas_urid,
luaL_checknumber(L, 2),
luaL_checknumber(L, 3),
luaL_checknumber(L, 4),
luaL_checknumber(L, 5),
luaL_checknumber(L, 6),
luaL_checknumber(L, 7)) )
luaL_error(L, forge_buffer_overflow);
lua_settop(L, 1);
return 1;
}
__realtime static int
_lforge_canvas_reset(lua_State *L)
{
......@@ -2108,6 +2127,7 @@ const luaL_Reg lforge_mt [] = {
{"translate", _lforge_canvas_translate},
{"scale", _lforge_canvas_scale},
{"rotate", _lforge_canvas_rotate},
{"transform", _lforge_canvas_transform},
{"reset", _lforge_canvas_reset},
{"fontSize", _lforge_canvas_font_size},
{"fillText", _lforge_canvas_fill_text},
......
......@@ -248,6 +248,7 @@ pre {
<li><a href="#forge-translate">Translate</a></li>
<li><a href="#forge-scale">Scale</a></li>
<li><a href="#forge-rotate">Rotate</a></li>
<li><a href="#forge-transform">Transform</a></li>
<li><a href="#forge-reset">Reset</a></li>
<li><a href="#forge-fontSize">FontSize</a></li>
<li><a href="#forge-fillText">FillText</a></li>
......@@ -2632,6 +2633,38 @@ function stash(ctx)
end</code></pre>
</div>
<!-- Forge Transform -->
<div class="api-section">
<h3 id="forge-transform">Transform</h3>
<p>Forge an atom object of type Canvas.Transform. Set current render matrix.</p>
<dl>
<dt class="func">forge:transform(a)</dt>
<dt>xx (number)</dt>
<dd>multiplier for x in: x' = xx*x + xy*y + x0</dd>
<dt>xy (number)</dt>
<dd>multiplier for y in: x' = xx*x + xy*y + x0</dd>
<dt>x0 (number)</dt>
<dd>constant in: x' = xx*x + xy*y + x0</dd>
<dt>yx (number)</dt>
<dd>multiplier for y in: y' = yy*y + yx*x + y0</dd>
<dt>yx (number)</dt>
<dd>multiplier for x in: y' = yy*y + yx*x + y0</dd>
<dt>y0 (number)</dt>
<dd>constant in: y' = yy*y + yx*x + y0</dd>
<dt class="ret">(userdata)</dt>
<dd>self forge object</dd>
</dl>
<pre><code data-ref="forge-transform">-- Forge Transform
function stash(ctx)
ctx:save():transform(-1.0, 0.0, 1.0, 1.0, 0.0, 0.0) -- mirror on x-asix
ctx:rectangle(-0.1, -0.1, 0.2, 0.2):fill()
ctx:restore()
end</code></pre>
</div>
<!-- Forge Reset -->
<div class="api-section">
<h3 id="forge-reset">Reset</h3>
......
......@@ -2120,6 +2120,7 @@ do
ctx:fontSize(table.unpack(n, 1, 1))
ctx:fillText('hello')
ctx:polyLine(table.unpack(n, 1, 4))
ctx:transform(table.unpack(n, 1, 6))
end
end
......@@ -2143,7 +2144,7 @@ do
local graph = seq[1]
assert(graph)
assert(graph.type == Atom.Tuple)
assert(#graph == 25)
assert(#graph == 26)
local beginPath = graph[1]
check_canvas_object(beginPath, Canvas.BeginPath)
......@@ -2269,6 +2270,11 @@ do
check_canvas_object(itm, Canvas.PolyLine)
body = itm[Canvas.body]
check_canvas_vector(body, 4)
itm = graph[26]
check_canvas_object(itm, Canvas.Transform)
body = itm[Canvas.body]
check_canvas_vector(body, 6)
end
test(producer, consumer)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment