Skip to content

Commit e3beb71

Browse files
committed
Format code, update the mandelbrot and shift hue examples, fix the Lua API so the shift hue example works.
1 parent 2d42634 commit e3beb71

8 files changed

+48
-37
lines changed

luaChunk.cpp

+5-4
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ static int lua_chunk_draw(lua_State*L) {
2727
size_t chunk = idxPtr[1];
2828

2929
projects[projectIDX]->Chunk->drawChunk(chunk,
30-
luaL_optinteger(L, 2, 0), luaL_optinteger(L, 3, 0), // X offset, Y offset.
31-
luaL_optinteger(L, 4, 1), // Zoom
32-
luaL_optinteger(L, 5, 0), luaL_optinteger(L, 6, 0) // Scroll X, scroll Y
33-
);
30+
luaL_optinteger(L, 2, 0), luaL_optinteger(L, 3, 0), // X offset, Y offset.
31+
luaL_optinteger(L, 4, 1), // Zoom
32+
luaL_optinteger(L, 5, 0), luaL_optinteger(L, 6, 0) // Scroll X, scroll Y
33+
);
3434
return 0;
3535
}
3636

@@ -62,6 +62,7 @@ static int chunk__get_(lua_State *L) {
6262

6363
static int chunk___tostring(lua_State * L) {
6464
const size_t *idxPtr = (const size_t*)lua_touserdata(L, 1);
65+
6566
if (idxPtr) {
6667
lua_pushfstring(L, "Chunk: %d from project: %d", idxPtr[0], idxPtr[1]);
6768
return 1;

luaChunks.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
static int chunk__set_(lua_State *L) {
2525
const char *key = luaL_checkstring(L, 2);
2626
getProjectIDX
27-
27+
2828
class ChunkClass *chunk = projects[projectIDX]->Chunk;
2929

3030
const char*k = luaL_checkstring(L, 2);

luaExamples/mandelbrotToTilemap.lua

+6-6
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,17 @@ if p:have(project.mapMask) then
4545
local maxit = tonumber(fl.input("Maximum iterations","16000"))
4646
if maxit ~= nil then
4747
local tilemap = p.tilemaps.current
48-
p.tiles:resize(tilemap.w * tilemap.h)
48+
p.tiles:setAmt(tilemap.width * tilemap.height)
4949

50-
for j = 0, tilemap.h -1 do
50+
for j = 0, tilemap.height -1 do
5151
local row = tilemap[j + 1]
52-
for i = 0, tilemap.w - 1 do
53-
row[i + 1].tile = j * tilemap.w + i
52+
for i = 0, tilemap.width - 1 do
53+
row[i + 1].tile = j * tilemap.width + i
5454
end
5555
end
5656

57-
local width = tilemap.w * p.tiles.w
58-
local height = tilemap.hAll * p.tiles.h
57+
local width = tilemap.width * p.tiles.width
58+
local height = tilemap.hAll * p.tiles.height
5959

6060
-- [-2,1],[-1,1]
6161
local sx, sy = 3/width, 2/height

luaExamples/shifthue.lua

+19-12
Original file line numberDiff line numberDiff line change
@@ -35,25 +35,31 @@ function hsl_to_rgb(h, s, L)
3535
return _h2rgb(m1, m2, h+1./3.), _h2rgb(m1, m2, h), _h2rgb(m1, m2, h-1./3.)
3636
end
3737
function idxHelper(idx)
38-
local r,g,b=palette.getRGB(idx)
38+
local ent = projects.current.palette[idx]
39+
40+
local r = ent.r
41+
local g = ent.g
42+
local b = ent.b
43+
3944
local h,s,l=rgt.rgbToHsl(r/255.,g/255.,b/255.)
4045
r,g,b=hsl_to_rgb((h+shift)%1.,s,l)
4146
return r*255.//1,g*255.//1,b*255.//1
4247
end
4348
function draw()
49+
local p = projects.current
4450
win:baseDraw()
4551
if shift~=nil then
46-
for row=0,palette.rowCnt-1 do
47-
for idx=0,palette.perRow-1 do
48-
local r,g,b=idxHelper(row*palette.perRow+idx)
52+
for row=0,p.palette.rowCnt-1 do
53+
for idx=0,p.palette.perRow-1 do
54+
local r,g,b=idxHelper(row*p.palette.perRow+idx + 1)
4955
fl.rectf((idx+1)*16,(row+1)*16,16,16,r,g,b)
5056
end
5157
end
52-
if palette.haveAlt~=0 then
53-
for row=0,palette.rowCntAlt-1 do
54-
for idx=0,palette.perRowAlt-1 do
55-
local r,g,b=idxHelper(row*palette.perRowAlt+idx+palette.cnt)
56-
fl.rectf((idx+1)*16+(palette.perRow+1)*16,(row+1)*16,16,16,r,g,b)
58+
if p.palette.haveAlt~=0 then
59+
for row=0,p.palette.rowCntAlt-1 do
60+
for idx=0,p.palette.perRowAlt-1 do
61+
local r,g,b=idxHelper(row*p.palette.perRowAlt+idx+p.palette.cnt + 1)
62+
fl.rectf((idx+1)*16+(p.palette.perRow+1)*16,(row+1)*16,16,16,r,g,b)
5763
end
5864
end
5965
end
@@ -71,6 +77,7 @@ function btnCB(val)
7177
end
7278
local p = projects.current
7379
if p:have(project.palMask) then
80+
local p = projects.current
7481
win=Fl_Window.new(320,200,'Shift hue by')
7582
win:set_modal()
7683
win:setDrawFunction("draw")
@@ -88,9 +95,9 @@ if p:have(project.palMask) then
8895
end
8996
if ok~=0 then
9097
undo.pushPaletteAll()
91-
for ent=0,palette.cnt+palette.cntAlt-1,1 do
92-
local r,g,b=idxHelper(ent)
93-
palette.setRGB(ent,r,g,b)
98+
for ent=0,p.palette.cntTotal - 1, 1 do
99+
local r,g,b=idxHelper(ent + 1)
100+
p.palette[ent + 1]:setRGB(r,g,b)
94101
end
95102
palette.fixSliders()
96103
rgt.damage()

luaPalette.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@ static int palette__get_(lua_State *L) {
5959
} else if (!strcmp("cnt", k)) {
6060
lua_pushinteger(L, projects[idx]->pal->colorCnt);
6161
return 1;
62+
} else if (!strcmp("cntAlt", k)) {
63+
lua_pushinteger(L, projects[idx]->pal->colorCntalt);
64+
return 1;
65+
} else if (!strcmp("cntTotal", k)) {
66+
lua_pushinteger(L, projects[idx]->pal->colorCntalt + projects[idx]->pal->colorCnt);
67+
return 1;
6268
} else if (!strcmp("perRow", k)) {
6369
lua_pushinteger(L, projects[idx]->pal->perRow);
6470
return 1;

luaPaletteEntry.cpp

+4-8
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@
2222
#include "gui.h"
2323

2424
static int palette__set_(lua_State *L) {
25-
const size_t *idxPtr = (const size_t*)lua_touserdata(L, 1);
26-
size_t projectIDX = *idxPtr;
25+
getProjectIDX
2726
size_t entryIDX = idxPtr[1];
2827

2928
const char *key = luaL_checkstring(L, 2);
@@ -59,8 +58,7 @@ static int palette__set_(lua_State *L) {
5958
}
6059

6160
static int lua_palette_convertFromRGB(lua_State*L) {
62-
const size_t *idxPtr = (const size_t*)lua_touserdata(L, 1);
63-
size_t projectIDX = *idxPtr;
61+
getProjectIDX
6462
size_t entryIDX = idxPtr[1];
6563
size_t ent3 = entryIDX * 3;
6664

@@ -70,8 +68,7 @@ static int lua_palette_convertFromRGB(lua_State*L) {
7068
}
7169

7270
static int lua_palette_setRGB(lua_State*L) {
73-
const size_t *idxPtr = (const size_t*)lua_touserdata(L, 1);
74-
size_t projectIDX = *idxPtr;
71+
getProjectIDX
7572
size_t entryIDX = idxPtr[1];
7673

7774
projects[projectIDX]->pal->rgbToEntry(luaL_checkinteger(L, 2), luaL_checkinteger(L, 3), luaL_checkinteger(L, 4), entryIDX);
@@ -81,8 +78,7 @@ static int lua_palette_setRGB(lua_State*L) {
8178

8279
static int paletteEntry__get_(lua_State *L) {
8380
int type = lua_type(L, 2);
84-
const size_t *idxPtr = (const size_t*)lua_touserdata(L, 1);
85-
size_t projectIDX = *idxPtr;
81+
getProjectIDX
8682
size_t entryIDX = idxPtr[1];
8783

8884
if (type == LUA_TSTRING) {

luaTilemap.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@ static int tilemap__set_(lua_State *L) {
259259

260260
if (!strcmp("useBlocks", k))
261261
tm->isBlock = lua_toboolean(L, 3);
262+
262263
return 0;
263264
}
264265

luaTilemapEntry.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ static int lua_tilemap_setFull(lua_State*L) {
2626
const size_t columnIDX = idxPtr[2];
2727
const size_t entryIDX = idxPtr[3];
2828
projects[projectIDX]->tms->maps[tilemapIDX].set_tile_full(entryIDX, // x
29-
columnIDX, // y
30-
luaL_optinteger(L, 2, 0), // tile
31-
luaL_optboolean(L, 3, false), // palette_row
32-
luaL_optboolean(L, 4, false), // hflip
33-
luaL_optboolean(L, 5, false), // vflip
34-
luaL_optboolean(L, 6, false)); // priority
29+
columnIDX, // y
30+
luaL_optinteger(L, 2, 0), // tile
31+
luaL_optboolean(L, 3, false), // palette_row
32+
luaL_optboolean(L, 4, false), // hflip
33+
luaL_optboolean(L, 5, false), // vflip
34+
luaL_optboolean(L, 6, false)); // priority
3535
return 0;
3636
}
3737

0 commit comments

Comments
 (0)