Skip to content

Commit 773b493

Browse files
committed
Added script function utils.colourcube
1 parent 111784e commit 773b493

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

scripting/lua_utils.cpp

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2042,6 +2042,50 @@ static int glyph_available (lua_State *L)
20422042

20432043
} // end of glyph_available
20442044

2045+
extern COLORREF xterm_256_colours [256];
2046+
2047+
static int colourcube (lua_State *L) {
2048+
int which = luaL_checknumber (L, 1);
2049+
int red, green, blue;
2050+
const BYTE values [6] = {
2051+
0,
2052+
95,
2053+
95 + 40,
2054+
95 + 40 + 40,
2055+
95 + 40 + 40 + 40,
2056+
95 + 40 + 40 + 40 + 40
2057+
};
2058+
const BYTE colour_increment = 255 / 5; // that is, 51 (0x33)
2059+
2060+
switch (which)
2061+
{
2062+
2063+
case 1: // Xterm colour cube (the default - favours brighter colours)
2064+
for (red = 0; red < 6; red++)
2065+
for (green = 0; green < 6; green++)
2066+
for (blue = 0; blue < 6; blue++)
2067+
xterm_256_colours [16 + (red * 36) + (green * 6) + blue] =
2068+
RGB (values [red], values [green], values [blue]);
2069+
2070+
break;
2071+
2072+
case 2: // Netscape colour cube - evenly spaced colour cube
2073+
for (red = 0; red < 6; red++)
2074+
for (green = 0; green < 6; green++)
2075+
for (blue = 0; blue < 6; blue++)
2076+
xterm_256_colours [16 + (red * 36) + (green * 6) + blue] =
2077+
RGB (red * colour_increment,
2078+
green * colour_increment,
2079+
blue * colour_increment);
2080+
2081+
break;
2082+
2083+
default: luaL_error (L, "Unknown option");
2084+
} // end of switch
2085+
2086+
return 0; /* no return */
2087+
}
2088+
20452089
#if 0
20462090
static int registry (lua_State *L)
20472091
{
@@ -2071,6 +2115,7 @@ static const struct luaL_Reg xmllib [] =
20712115
{"appendtonotepad", appendtonotepad},
20722116
{"callbackslist", callbackslist},
20732117
{"choose", choose},
2118+
{"colourcube", colourcube},
20742119
{"directorypicker", directorypicker},
20752120
{"edit_distance", edit_distance},
20762121
{"editbox", editbox},

0 commit comments

Comments
 (0)