Added option for palette selection as color for LUA colors. Included an LUA script to display all choices with the value used to pick displayed color.

Documented new color option and missing gui.text information.
This commit is contained in:
ugetab 2010-05-15 05:03:53 +00:00
parent dc61c4c414
commit a874412b61
3 changed files with 86 additions and 0 deletions

View File

@ -0,0 +1,62 @@
-- Show Palette
-- Click for other palette boxes
-- P00 - P3F are NES palette values.
-- P40 - P7F are LUA palette values.
-- True or False
ShowTextLabels=true;
function DecToHex(numberin)
if (numberin < 16) then
return string.format("0%X",numberin);
else
return string.format("%X",numberin);
end;
end;
function text(x,y,str,text,back)
if (x > 0 and x < 255 and y > 0 and y < 240) then
gui.text(x,y,str,text,back);
end;
end;
local ButtonWasPressed;
local CurrentPaletteDisplay=0;
while(true) do
FCEU.frameadvance();
for i = 0, 7 do
gui.box(0 + (30*i),0,29 + (30*i),29,"P" .. DecToHex(0+i+(CurrentPaletteDisplay * 8)),"P" .. DecToHex(0+i+(CurrentPaletteDisplay * 8)));
gui.box(0 + (30*i),30,29 + (30*i),59,"P" .. DecToHex(16+i+(CurrentPaletteDisplay * 8)),"P" .. DecToHex(16+i+(CurrentPaletteDisplay * 8)));
gui.box(0 + (30*i),60,29 + (30*i),89,"P" .. DecToHex(32+i+(CurrentPaletteDisplay * 8)),"P" .. DecToHex(32+i+(CurrentPaletteDisplay * 8)));
gui.box(0 + (30*i),90,29 + (30*i),119,"P" .. DecToHex(48+i+(CurrentPaletteDisplay * 8)),"P" .. DecToHex(48+i+(CurrentPaletteDisplay * 8)));
if(ShowTextLabels == true) then
text(6 + (30*i),11,"P" .. DecToHex(0+i+(CurrentPaletteDisplay * 8)))
text(6 + (30*i),41,"P" .. DecToHex(16+i+(CurrentPaletteDisplay * 8)))
text(6 + (30*i),71,"P" .. DecToHex(32+i+(CurrentPaletteDisplay * 8)))
text(6 + (30*i),101,"P" .. DecToHex(48+i+(CurrentPaletteDisplay * 8)))
end;
end;
mousestuff = input.get()
if (not ButtonWasPressed) then
if (mousestuff.leftclick) then
ButtonWasPressed = 1;
CurrentPaletteDisplay=CurrentPaletteDisplay+1;
if (CurrentPaletteDisplay == 2) then
CurrentPaletteDisplay=8;
end;
if (CurrentPaletteDisplay == 10) then
CurrentPaletteDisplay=0;
end;
end;
end
ButtonWasPressed = (mousestuff.leftclick);
end;

View File

@ -3013,6 +3013,7 @@ s_colorMapping [] =
* offset to a RGB32 colour. Several encodings are supported. * offset to a RGB32 colour. Several encodings are supported.
* The user may construct their own RGB value, given a simple colour name, * The user may construct their own RGB value, given a simple colour name,
* or an HTML-style "#09abcd" colour. 16 bit reduction doesn't occur at this time. * or an HTML-style "#09abcd" colour. 16 bit reduction doesn't occur at this time.
* NES palettes added with notation "P00" to "P3F". "P40" to "P7F" denote LUA palettes.
*/ */
static inline bool str2colour(uint32 *colour, lua_State *L, const char *str) { static inline bool str2colour(uint32 *colour, lua_State *L, const char *str) {
if (str[0] == '#') { if (str[0] == '#') {
@ -3025,6 +3026,29 @@ static inline bool str2colour(uint32 *colour, lua_State *L, const char *str) {
*colour = color; *colour = color;
return true; return true;
} }
else if (str[0] == 'P') {
uint8 palette;
uint8 tr, tg, tb;
if (strlen(str+1) == 2) {
palette = ((hex2int(L, str[1]) * 0x10) + hex2int(L, str[2]));
} else if (strlen(str+1) == 1) {
palette = (hex2int(L, str[1]));
} else {
luaL_error(L, "palettes are defined with P## hex notion");
return false;
}
if (palette > 0x7F) {
luaL_error(L, "palettes range from P00 to P7F");
return false;
}
FCEUD_GetPalette(palette + 0x80, &tr, &tg, &tb);
// Feeding it RGBA, because it will spit out the right value for me
*colour = LUA_BUILD_PIXEL(tr, tg, tb, 0xFF);
return true;
}
else { else {
if(!strnicmp(str, "rand", 4)) { if(!strnicmp(str, "rand", 4)) {
*colour = ((rand()*255/RAND_MAX) << 8) | ((rand()*255/RAND_MAX) << 16) | ((rand()*255/RAND_MAX) << 24) | 0xFF; *colour = ((rand()*255/RAND_MAX) << 8) | ((rand()*255/RAND_MAX) << 16) | ((rand()*255/RAND_MAX) << 24) | 0xFF;

Binary file not shown.