Allow color names as color specifications

This commit is contained in:
Ilari Liusvaara 2013-12-24 04:58:09 +02:00
parent a1fb86eddc
commit f032ae3b60
22 changed files with 361 additions and 69 deletions

View file

@ -455,6 +455,7 @@ struct color
set_palette(32, 16, 0, true);
//std::cerr << "Color " << color << " -> hi=" << hi << " lo=" << lo << " inv=" << inv << std::endl;
}
color(const std::string& color) throw(std::bad_alloc, std::runtime_error);
void set_palette(unsigned rshift, unsigned gshift, unsigned bshift, bool X) throw();
template<bool X> void set_palette(struct fb<X>& s) throw()
{

View file

@ -1,6 +1,9 @@
#ifndef _library__lua_framebuffer__hpp__included__
#define _library__lua_framebuffer__hpp__included__
#include "lua-base.hpp"
#include "framebuffer.hpp"
struct lua_render_context
{
uint32_t left_gap;
@ -12,4 +15,9 @@ struct lua_render_context
uint32_t height;
};
framebuffer::color lua_get_fb_color(lua::state& L, int index, const std::string& fname)
throw(std::bad_alloc, std::runtime_error);
framebuffer::color lua_get_fb_color(lua::state& L, int index, const std::string& fname, int64_t dflt)
throw(std::bad_alloc, std::runtime_error);
#endif

39
lua.lyx
View file

@ -770,6 +770,7 @@ Colors are 32-bit.
16-23 are the red component, bits 24-31 are alpha component (0 is fully
opaque, 255 is almost transparent).
-1 is the fully transparent color.
Alternatively, colors can be given as strings naming the color.
\end_layout
\begin_layout Itemize
@ -781,6 +782,36 @@ Origin of coordinates is at top left corner of game display area.
Left and top gaps correspond to negative coordinates.
\end_layout
\begin_layout Itemize
The following color names are known: aliceblue, antiquewhite, aqua, aquamarine,
azure, beige, bisque, black, blanchedalmond, blue, blueviolet, brown, burlywood
, cadetblue, chartreuse, chocolate, coral, cornflowerblue, cornsilk, crimson,
cyan, darkblue, darkcyan, darkgoldenrod, darkgray, darkgrey, darkgreen,
darkkhaki, darkmagenta, darkolivegreen, darkorange, darkorchid, darkred,
darksalmon, darkseagreen, darkslateblue, darkslategray, darkslategrey,
darkturquoise, darkviolet, deeppink, deepskyblue, dimgray, dimgrey, dodgerblue,
firebrick, floralwhite, forestgreen, fuchsia, gainsboro, ghostwhite, gold,
goldenrod, gray, grey, green, greenyellow, honeydew, hotpink, indianred,
indigo, ivory, khaki, lavender, lavenderblush, lawngreen, lemonchiffon,
lightblue, lightcoral, lightcyan, lightgoldenrodyellow, lightgray, lightgrey,
lightgreen, lightpink, lightsalmon, lightseagreen, lightskyblue, lightslategray
, lightslategrey, lightsteelblue, lightyellow, lime, limegreen, linen, magenta,
maroon, mediumaquamarine, mediumblue, mediumorchid, mediumpurple, mediumseagree
n, mediumslateblue, mediumspringgreen, mediumturquoise, mediumvioletred,
midnightblue, mintcream, mistyrose, moccasin, navajowhite, navy, oldlace,
olive, olivedrab, orange, orangered, orchid, palegoldenrod, palegreen,
paleturquoise, palevioletred, papayawhip, peachpuff, peru, pink, plum,
powderblue, purple, red, rosybrown, royalblue, saddlebrown, salmon, sandybrown,
seagreen, seashell, sienna, silver, skyblue, slateblue, slategray, slategrey,
snow, springgreen, steelblue, tan, teal, thistle, tomato, transparent,
turquoise, violet, wheat, white, whitesmoke, yellow, yellowgreen.
\end_layout
\begin_layout Itemize
The following modifiers can be applied: opaque10, opaque20, opaque25, opaque30,
opaque40, opaque50, opaque60, opaque70, opaque75, opaque80, opaque90, opaque.
\end_layout
\begin_layout Subsection
gui.resolution: Get current resolution
\end_layout
@ -1592,6 +1623,10 @@ gui.color: Compose a color.
Syntax: number gui.color(number r, number g, number b[, number a])
\end_layout
\begin_layout Itemize
Syntax: number gui.color(string c)
\end_layout
\begin_layout Standard
Returns color (in notation Lua scripts use) corresponding to color (<r>,<g>,<b>)
, each component in scale 0-255.
@ -1600,6 +1635,10 @@ Returns color (in notation Lua scripts use) corresponding to color (<r>,<g>,<b>)
The default alpha is 256.
\end_layout
\begin_layout Standard
The form taking a string returns color corresponding color name.
\end_layout
\begin_layout Subsection
gui.status: Set status variable
\end_layout

BIN
lua.pdf

Binary file not shown.

View file

@ -6,10 +6,13 @@ __all__.files: $(OBJECTS)
lua ../genfilelist.lua $^ >$@
touch __all__.ldflags
framebuffer-basecolors.inc: framebuffer-basecolors.def
lua make-basecolors.lua <$< >$@
%.$(OBJECT_SUFFIX): %.cpp %.cpp.dep
$(REALCC) $(CFLAGS) -c -o $@ $< -I../../include/library
precheck:
precheck: forcelook framebuffer-basecolors.inc
../../buildaux/mkdeps.exe ../../include/library -- *.cpp
@true

View file

@ -0,0 +1,148 @@
W3C color names
#f0f8ff aliceblue
#faebd7 antiquewhite
#00ffff aqua
#7fffd4 aquamarine
#f0ffff azure
#f5f5dc beige
#ffe4c4 bisque
#000000 black
#ffebcd blanchedalmond
#0000ff blue
#8a2be2 blueviolet
#a52a2a brown
#deb887 burlywood
#5f9ea0 cadetblue
#7fff00 chartreuse
#d2691e chocolate
#ff7f50 coral
#6495ed cornflowerblue
#fff8dc cornsilk
#dc143c crimson
#00ffff cyan
#00008b darkblue
#008b8b darkcyan
#b8860b darkgoldenrod
#a9a9a9 darkgray
#a9a9a9 darkgrey
#006400 darkgreen
#bdb76b darkkhaki
#8b008b darkmagenta
#556b2f darkolivegreen
#ff8c00 darkorange
#9932cc darkorchid
#8b0000 darkred
#e9967a darksalmon
#8fbc8f darkseagreen
#483d8b darkslateblue
#2f4f4f darkslategray
#2f4f4f darkslategrey
#00ced1 darkturquoise
#9400d3 darkviolet
#ff1493 deeppink
#00bfff deepskyblue
#696969 dimgray
#696969 dimgrey
#1e90ff dodgerblue
#b22222 firebrick
#fffaf0 floralwhite
#228b22 forestgreen
#ff00ff fuchsia
#dcdcdc gainsboro
#f8f8ff ghostwhite
#ffd700 gold
#daa520 goldenrod
#808080 gray
#808080 grey
#008000 green
#adff2f greenyellow
#f0fff0 honeydew
#ff69b4 hotpink
#cd5c5c indianred
#4b0082 indigo
#fffff0 ivory
#f0e68c khaki
#e6e6fa lavender
#fff0f5 lavenderblush
#7cfc00 lawngreen
#fffacd lemonchiffon
#add8e6 lightblue
#f08080 lightcoral
#e0ffff lightcyan
#fafad2 lightgoldenrodyellow
#d3d3d3 lightgray
#d3d3d3 lightgrey
#90ee90 lightgreen
#ffb6c1 lightpink
#ffa07a lightsalmon
#20b2aa lightseagreen
#87cefa lightskyblue
#778899 lightslategray
#778899 lightslategrey
#b0c4de lightsteelblue
#ffffe0 lightyellow
#00ff00 lime
#32cd32 limegreen
#faf0e6 linen
#ff00ff magenta
#800000 maroon
#66cdaa mediumaquamarine
#0000cd mediumblue
#ba55d3 mediumorchid
#9370db mediumpurple
#3cb371 mediumseagreen
#7b68ee mediumslateblue
#00fa9a mediumspringgreen
#48d1cc mediumturquoise
#c71585 mediumvioletred
#191970 midnightblue
#f5fffa mintcream
#ffe4e1 mistyrose
#ffe4b5 moccasin
#ffdead navajowhite
#000080 navy
#fdf5e6 oldlace
#808000 olive
#6b8e23 olivedrab
#ffa500 orange
#ff4500 orangered
#da70d6 orchid
#eee8aa palegoldenrod
#98fb98 palegreen
#afeeee paleturquoise
#db7093 palevioletred
#ffefd5 papayawhip
#ffdab9 peachpuff
#cd853f peru
#ffc0cb pink
#dda0dd plum
#b0e0e6 powderblue
#800080 purple
#ff0000 red
#bc8f8f rosybrown
#4169e1 royalblue
#8b4513 saddlebrown
#fa8072 salmon
#f4a460 sandybrown
#2e8b57 seagreen
#fff5ee seashell
#a0522d sienna
#c0c0c0 silver
#87ceeb skyblue
#6a5acd slateblue
#708090 slategray
#708090 slategrey
#fffafa snow
#00ff7f springgreen
#4682b4 steelblue
#d2b48c tan
#008080 teal
#d8bfd8 thistle
#ff6347 tomato
#40e0d0 turquoise
#ee82ee violet
#f5deb3 wheat
#ffffff white
#f5f5f5 whitesmoke
#ffff00 yellow
#9acd32 yellowgreen

View file

@ -93,6 +93,41 @@ namespace
}
}
}
struct color_modifier
{
const char* name;
void(*fn)(int64_t& v);
bool modifier;
};
std::map<std::string, std::pair<void(*)(int64_t& v), bool>>& colornames()
{
static std::map<std::string, std::pair<void(*)(int64_t& v), bool>> c;
static bool i = false;
if(!i) {
std::vector<color_modifier> tmp = {
{"transparent", [](int64_t& v) { v = -1; }, false},
{"opaque10", [](int64_t& v) { v = (230ULL << 24) | (v & 0xFFFFFF); }, true},
{"opaque20", [](int64_t& v) { v = (205ULL << 24) | (v & 0xFFFFFF); }, true},
{"opaque25", [](int64_t& v) { v = (192ULL << 24) | (v & 0xFFFFFF); }, true},
{"opaque30", [](int64_t& v) { v = (179ULL << 24) | (v & 0xFFFFFF); }, true},
{"opaque40", [](int64_t& v) { v = (154ULL << 24) | (v & 0xFFFFFF); }, true},
{"opaque50", [](int64_t& v) { v = (128ULL << 24) | (v & 0xFFFFFF); }, true},
{"opaque60", [](int64_t& v) { v = (102ULL << 24) | (v & 0xFFFFFF); }, true},
{"opaque70", [](int64_t& v) { v = (77ULL << 24) | (v & 0xFFFFFF); }, true},
{"opaque75", [](int64_t& v) { v = (64ULL << 24) | (v & 0xFFFFFF); }, true},
{"opaque80", [](int64_t& v) { v = (51ULL << 24) | (v & 0xFFFFFF); }, true},
{"opaque90", [](int64_t& v) { v = (26ULL << 24) | (v & 0xFFFFFF); }, true},
{"opaque", [](int64_t& v) { v = (0ULL << 24) | (v & 0xFFFFFF); }, true},
#include "framebuffer-basecolors.inc"
};
for(auto j : tmp)
c[j.name] = std::make_pair(j.fn, j.modifier);
i = true;
}
return c;
}
}
pixfmt::pixfmt() throw(std::bad_alloc)
@ -863,6 +898,24 @@ template<bool X> void font::render(struct fb<X>& scr, int32_t x, int32_t y, cons
}));
}
color::color(const std::string& clr) throw(std::bad_alloc, std::runtime_error)
{
int64_t col = -1;
bool first = true;
auto& cspecs = colornames();
for(auto& t : token_iterator_foreach(clr, {" ","\t"}, true)) {
if(!cspecs.count(t))
throw std::runtime_error("Invalid color (modifier) '" + t + "'");
if(!first && !cspecs[t].second)
throw std::runtime_error("Base color (" + t + ") can't be used as modifier");
if(first && cspecs[t].second)
throw std::runtime_error("Modifier (" + t + ") can't be used as base color");
(cspecs[t].first)(col);
first = false;
}
*this = color(col);
}
void color::set_palette(unsigned rshift, unsigned gshift, unsigned bshift, bool X) throw()
{
if(X) {

View file

@ -0,0 +1,29 @@
#include "lua-base.hpp"
#include "framebuffer.hpp"
#include "lua-framebuffer.hpp"
framebuffer::color lua_get_fb_color(lua::state& L, int index, const std::string& fname) throw(std::bad_alloc,
std::runtime_error)
{
if(L.type(index) == LUA_TSTRING)
return framebuffer::color(L.get_string(index, fname.c_str()));
else if(L.type(index) == LUA_TNUMBER)
return framebuffer::color(L.get_numeric_argument<int64_t>(index, fname.c_str()));
else
(stringfmt() << "Expected argument #" << index << " to " << fname
<< " be string or number").throwex();
}
framebuffer::color lua_get_fb_color(lua::state& L, int index, const std::string& fname, int64_t dflt)
throw(std::bad_alloc, std::runtime_error)
{
if(L.type(index) == LUA_TSTRING)
return framebuffer::color(L.get_string(index, fname.c_str()));
else if(L.type(index) == LUA_TNUMBER)
return framebuffer::color(L.get_numeric_argument<int64_t>(index, fname.c_str()));
else if(L.type(index) == LUA_TNIL || L.type(index) == LUA_TNONE)
return framebuffer::color(dflt);
else
(stringfmt() << "Expected argument #" << index << " to " << fname
<< " be string, number or nil").throwex();
}

View file

@ -0,0 +1,8 @@
#!/usr/bin/env lua
for line in io.stdin:lines() do
c,name = string.match(line, "#(%x+) ([^ \t]+)");
if name then
print("{\""..name.."\", [](int64_t& v) { v = 0x"..c.."; }, false},");
end
end

View file

@ -1,5 +1,6 @@
#include "lua/internal.hpp"
#include "library/framebuffer.hpp"
#include "library/lua-framebuffer.hpp"
#include "library/minmax.hpp"
namespace
@ -96,11 +97,10 @@ namespace
uint32_t length = L.get_numeric_argument<int32_t>(3, fname.c_str());
uint32_t headwidth = L.get_numeric_argument<int32_t>(4, fname.c_str());
int direction = L.get_numeric_argument<int>(5, fname.c_str());
int64_t color = 0xFFFFFFU;
bool fill = false;
if(L.type(6) == LUA_TBOOLEAN && L.toboolean(6))
fill = true;
L.get_numeric_argument<int64_t>(7, color, fname.c_str());
auto color = lua_get_fb_color(L, 7, fname, 0xFFFFFF);
uint32_t width = 1;
L.get_numeric_argument<uint32_t>(8, width, fname.c_str());
uint32_t headthickness = width;

View file

@ -1,6 +1,7 @@
#include "lua/internal.hpp"
#include "core/framebuffer.hpp"
#include "library/framebuffer.hpp"
#include "library/lua-framebuffer.hpp"
#include "library/png.hpp"
#include "library/sha256.hpp"
#include "library/serialization.hpp"
@ -167,11 +168,10 @@ namespace
uint32_t h = L.get_numeric_argument<uint32_t>(2, fname.c_str());
bool d = L.get_bool(3, fname.c_str());
if(d) {
int64_t c = -1;
L.get_numeric_argument<int64_t>(4, c, fname.c_str());
auto c = lua_get_fb_color(L, 4, fname, -1);
lua_dbitmap* b = lua::_class<lua_dbitmap>::create(L, w, h);
for(size_t i = 0; i < b->width * b->height; i++)
b->pixels[i] = framebuffer::color(c);
b->pixels[i] = c;
} else {
uint16_t c = 0;
L.get_numeric_argument<uint16_t>(4, c, fname.c_str());
@ -586,7 +586,9 @@ namespace
std::getline(s, line);
istrip_CR(line);
regex_results r;
if(r = regex("[ \t]*([0-9]+)[ \t]+([0-9]+)[ \t]+([0-9]+)[ \t]+([0-9]+)[ \t]*", line)) {
if(!regex_match("[ \t]*(#.*)?", line)) {
//Nothing.
} else if(r = regex("[ \t]*([0-9]+)[ \t]+([0-9]+)[ \t]+([0-9]+)[ \t]+([0-9]+)[ \t]*", line)) {
int64_t cr, cg, cb, ca;
cr = parse_value<uint8_t>(r[1]);
cg = parse_value<uint8_t>(r[2]);
@ -604,9 +606,9 @@ namespace
cg = parse_value<uint8_t>(r[2]);
cb = parse_value<uint8_t>(r[3]);
p->colors.push_back(framebuffer::color((cr << 16) | (cg << 8) | cb));
} else if(regex_match("[ \t]*transparent[ \t]*", line)) {
p->colors.push_back(framebuffer::color(-1));
} else if(!regex_match("[ \t]*(#.*)?", line))
} else if(r = regex("[ \t]*([^ \t]|[^ \t].*[^ \t])[ \t]*", line)) {
p->colors.push_back(framebuffer::color(r[1]));
} else
throw std::runtime_error("Invalid line format (" + line + ")");
}
return 1;
@ -696,8 +698,7 @@ std::string lua_palette::print()
int lua_palette::set(lua::state& L, const std::string& fname)
{
uint16_t c = L.get_numeric_argument<uint16_t>(2, fname.c_str());
int64_t nval = L.get_numeric_argument<int64_t>(3, fname.c_str());
framebuffer::color nc(nval);
auto nc = lua_get_fb_color(L, 3, fname);
//The mutex lock protects only the internals of colors array.
if(this->colors.size() <= c) {
this->palette_mutex.lock();
@ -858,7 +859,7 @@ int lua_bitmap::blit(lua::state& L, const std::string& fname)
uint32_t sy = L.get_numeric_argument<uint32_t>(6, fname.c_str());
uint32_t w = L.get_numeric_argument<uint32_t>(7, fname.c_str());
uint32_t h = L.get_numeric_argument<uint32_t>(8, fname.c_str());
int64_t ck = 0x100000000ULL;
int64_t ck = 65536;
L.get_numeric_argument<int64_t>(9, ck, fname.c_str());
if(src_p) {
lua_bitmap* sb = lua::_class<lua_bitmap>::get(L, 4, fname.c_str());
@ -961,10 +962,10 @@ int lua_dbitmap::pset(lua::state& L, const std::string& fname)
{
uint32_t x = L.get_numeric_argument<uint32_t>(2, fname.c_str());
uint32_t y = L.get_numeric_argument<uint32_t>(3, fname.c_str());
int64_t c = L.get_numeric_argument<int64_t>(4, fname.c_str());
auto c = lua_get_fb_color(L, 4, fname);
if(x >= this->width || y >= this->height)
return 0;
this->pixels[y * this->width + x] = framebuffer::color(c);
this->pixels[y * this->width + x] = c;
return 0;
}
@ -1016,7 +1017,7 @@ int lua_dbitmap::blit(lua::state& L, const std::string& fname)
bool src_d = lua::_class<lua_dbitmap>::is(L, 4);
bool src_p = lua::_class<lua_bitmap>::is(L, 4);
if(!src_d && !src_p)
throw std::runtime_error("Expected BITMAP or DBITMAP as argument 4 for gui.bitmap_blit");
throw std::runtime_error("Expected BITMAP or DBITMAP as argument 4 for " + fname);
int slot = 5;
if(src_p)
slot++; //Reserve slot 5 for palette.
@ -1024,24 +1025,35 @@ int lua_dbitmap::blit(lua::state& L, const std::string& fname)
uint32_t sy = L.get_numeric_argument<uint32_t>(slot++, fname.c_str());
uint32_t w = L.get_numeric_argument<uint32_t>(slot++, fname.c_str());
uint32_t h = L.get_numeric_argument<uint32_t>(slot++, fname.c_str());
int64_t ck = 0x100000000ULL;
L.get_numeric_argument<int64_t>(slot++, ck, fname.c_str());
int64_t ckx = 0x100000000ULL;
//Hack: Direct-color bitmaps should take color spec, with special NONE value.
if(src_p)
L.get_numeric_argument<int64_t>(slot, ckx, fname.c_str());
else if(L.type(slot) == LUA_TSTRING) {
framebuffer::color cxt(L.get_string(slot, fname.c_str()));
ckx = demultiply_color(cxt);
} else if(L.type(slot) == LUA_TNUMBER) {
L.get_numeric_argument<int64_t>(slot, ckx, fname.c_str());
} else if(L.type(slot) == LUA_TNIL || L.type(slot) == LUA_TNONE) {
//Do nothing.
} else
(stringfmt() << "Expected string, number or nil as argument " << slot << " for " << fname).throwex();
if(src_d) {
lua_dbitmap* sb = lua::_class<lua_dbitmap>::get(L, 4, fname.c_str());
if(ck == 0x100000000ULL)
if(ckx == 0x100000000ULL)
xblit(srcdest_direct<colorkey_none>(*this, *sb, colorkey_none()), dx, dy, sx, sy, w, h);
else
xblit(srcdest_direct<colorkey_direct>(*this, *sb, colorkey_direct(ck)), dx, dy, sx, sy,
xblit(srcdest_direct<colorkey_direct>(*this, *sb, colorkey_direct(ckx)), dx, dy, sx, sy,
w, h);
} else {
lua_bitmap* sb = lua::_class<lua_bitmap>::get(L, 4, fname.c_str());
lua_palette* pal = lua::_class<lua_palette>::get(L, 5, fname.c_str());
if(ck > 65535)
if(ckx > 65535)
xblit(srcdest_paletted<colorkey_none>(*this, *sb, *pal, colorkey_none()), dx, dy, sx, sy,
w, h);
else
xblit(srcdest_paletted<colorkey_palette>(*this, *sb, *pal, colorkey_palette(ck)), dx, dy,
xblit(srcdest_paletted<colorkey_palette>(*this, *sb, *pal, colorkey_palette(ckx)), dx, dy,
sx, sy, w, h);
}
return 0;

View file

@ -1,5 +1,6 @@
#include "lua/internal.hpp"
#include "library/framebuffer.hpp"
#include "library/lua-framebuffer.hpp"
namespace
{
@ -54,21 +55,15 @@ namespace
lua::fnptr gui_box(lua_func_misc, "gui.box", [](lua::state& L, const std::string& fname) -> int {
if(!lua_render_ctx)
return 0;
int64_t outline1 = 0xFFFFFFU;
int64_t outline2 = 0x808080U;
int64_t fill = 0xC0C0C0U;
uint32_t thickness = 1;
int32_t x = L.get_numeric_argument<int32_t>(1, fname.c_str());
int32_t y = L.get_numeric_argument<int32_t>(2, fname.c_str());
uint32_t width = L.get_numeric_argument<uint32_t>(3, fname.c_str());
uint32_t height = L.get_numeric_argument<uint32_t>(4, fname.c_str());
L.get_numeric_argument<uint32_t>(5, thickness, fname.c_str());
L.get_numeric_argument<int64_t>(6, outline1, fname.c_str());
L.get_numeric_argument<int64_t>(7, outline2, fname.c_str());
L.get_numeric_argument<int64_t>(8, fill, fname.c_str());
framebuffer::color poutline1(outline1);
framebuffer::color poutline2(outline2);
framebuffer::color pfill(fill);
auto poutline1 = lua_get_fb_color(L, 6, fname, 0xFFFFFFU);
auto poutline2 = lua_get_fb_color(L, 7, fname, 0x808080U);
auto pfill = lua_get_fb_color(L, 8, fname, 0xC0C0C0U);
lua_render_ctx->queue->create_add<render_object_box>(x, y, width, height, poutline1, poutline2,
pfill, thickness);
return 0;

View file

@ -1,5 +1,6 @@
#include "lua/internal.hpp"
#include "library/framebuffer.hpp"
#include "library/lua-framebuffer.hpp"
namespace
{
@ -62,17 +63,13 @@ namespace
-> int {
if(!lua_render_ctx)
return 0;
int64_t outline = 0xFFFFFFU;
int64_t fill = -1;
uint32_t thickness = 1;
int32_t x = L.get_numeric_argument<int32_t>(1, fname.c_str());
int32_t y = L.get_numeric_argument<int32_t>(2, fname.c_str());
uint32_t radius = L.get_numeric_argument<uint32_t>(3, fname.c_str());
L.get_numeric_argument<uint32_t>(4, thickness, fname.c_str());
L.get_numeric_argument<int64_t>(5, outline, fname.c_str());
L.get_numeric_argument<int64_t>(6, fill, fname.c_str());
framebuffer::color poutline(outline);
framebuffer::color pfill(fill);
auto poutline = lua_get_fb_color(L, 5, fname, 0xFFFFFFU);
auto pfill = lua_get_fb_color(L, 6, fname, -1);
lua_render_ctx->queue->create_add<render_object_circle>(x, y, radius, poutline, pfill, thickness);
return 0;
});

View file

@ -61,8 +61,20 @@ namespace
return 0;
});
inline int64_t demultiply_color(const framebuffer::color& c)
{
if(!c.origa)
return -1;
else
return c.orig | ((uint32_t)(256 - c.origa) << 24);
}
lua::fnptr gui_color(lua_func_misc, "gui.color", [](lua::state& L, const std::string& fname)
-> int {
if(L.type(1) == LUA_TSTRING) {
L.pushnumber(demultiply_color(lua_get_fb_color(L, 1, fname)));
return 1;
}
int64_t a = 256;
int64_t r = L.get_numeric_argument<uint32_t>(1, fname.c_str());
int64_t g = L.get_numeric_argument<uint32_t>(2, fname.c_str());
@ -126,7 +138,7 @@ namespace
int64_t basecolor = 0x00FF0000;
uint64_t step = L.get_numeric_argument<uint64_t>(1, fname.c_str());
int32_t steps = L.get_numeric_argument<int32_t>(2, fname.c_str());
L.get_numeric_argument<int64_t>(3, basecolor, fname.c_str());
basecolor = demultiply_color(lua_get_fb_color(L, 3, fname));
if(!steps)
throw std::runtime_error("Expected nonzero steps for gui.rainbow");
if(basecolor < 0) {

View file

@ -1,5 +1,6 @@
#include "lua/internal.hpp"
#include "library/framebuffer.hpp"
#include "library/lua-framebuffer.hpp"
namespace
{
@ -40,13 +41,11 @@ namespace
-> int {
if(!lua_render_ctx)
return 0;
int64_t color = 0xFFFFFFU;
uint32_t length = 10;
int32_t x = L.get_numeric_argument<int32_t>(1, fname.c_str());
int32_t y = L.get_numeric_argument<int32_t>(2, fname.c_str());
L.get_numeric_argument<uint32_t>(3, length, fname.c_str());
L.get_numeric_argument<int64_t>(4, color, fname.c_str());
framebuffer::color pcolor(color);
auto pcolor = lua_get_fb_color(L, 4, fname, 0xFFFFFFU);
lua_render_ctx->queue->create_add<render_object_crosshair>(x, y, pcolor, length);
return 0;
});

View file

@ -1,5 +1,6 @@
#include "lua/internal.hpp"
#include "library/framebuffer.hpp"
#include "library/lua-framebuffer.hpp"
namespace
{
@ -92,13 +93,11 @@ nodraw2:
lua::fnptr gui_pixel(lua_func_misc, "gui.line", [](lua::state& L, const std::string& fname) -> int {
if(!lua_render_ctx)
return 0;
int64_t color = 0xFFFFFFU;
int32_t x1 = L.get_numeric_argument<int32_t>(1, fname.c_str());
int32_t y1 = L.get_numeric_argument<int32_t>(2, fname.c_str());
int32_t x2 = L.get_numeric_argument<int32_t>(3, fname.c_str());
int32_t y2 = L.get_numeric_argument<int32_t>(4, fname.c_str());
L.get_numeric_argument<int64_t>(5, color, fname.c_str());
framebuffer::color pcolor(color);
auto pcolor = lua_get_fb_color(L, 5, fname, 0xFFFFFFU);
lua_render_ctx->queue->create_add<render_object_line>(x1, x2, y1, y2, pcolor);
return 0;
});

View file

@ -1,5 +1,6 @@
#include "lua/internal.hpp"
#include "library/framebuffer.hpp"
#include "library/lua-framebuffer.hpp"
namespace
{
@ -31,11 +32,9 @@ namespace
lua::fnptr gui_pixel(lua_func_misc, "gui.pixel", [](lua::state& L, const std::string& fname) -> int {
if(!lua_render_ctx)
return 0;
int64_t color = 0xFFFFFFU;
int32_t x = L.get_numeric_argument<int32_t>(1, fname.c_str());
int32_t y = L.get_numeric_argument<int32_t>(2, fname.c_str());
L.get_numeric_argument<int64_t>(3, color, fname.c_str());
framebuffer::color pcolor(color);
auto pcolor = lua_get_fb_color(L, 3, fname, 0xFFFFFFU);
lua_render_ctx->queue->create_add<render_object_pixel>(x, y, pcolor);
return 0;
});

View file

@ -1,5 +1,6 @@
#include "lua/internal.hpp"
#include "library/framebuffer.hpp"
#include "library/lua-framebuffer.hpp"
namespace
{
@ -50,18 +51,14 @@ namespace
-> int {
if(!lua_render_ctx)
return 0;
int64_t outline = 0xFFFFFFU;
int64_t fill = -1;
uint32_t thickness = 1;
int32_t x = L.get_numeric_argument<int32_t>(1, fname.c_str());
int32_t y = L.get_numeric_argument<int32_t>(2, fname.c_str());
uint32_t width = L.get_numeric_argument<uint32_t>(3, fname.c_str());
uint32_t height = L.get_numeric_argument<uint32_t>(4, fname.c_str());
L.get_numeric_argument<uint32_t>(5, thickness, fname.c_str());
L.get_numeric_argument<int64_t>(6, outline, fname.c_str());
L.get_numeric_argument<int64_t>(7, fill, fname.c_str());
framebuffer::color poutline(outline);
framebuffer::color pfill(fill);
auto poutline = lua_get_fb_color(L, 6, fname, 0xFFFFFFU);
auto pfill = lua_get_fb_color(L, 7, fname, -1);
lua_render_ctx->queue->create_add<render_object_rectangle>(x, y, width, height, poutline, pfill,
thickness);
return 0;

View file

@ -76,7 +76,7 @@ namespace
lua_dbitmap* b = lua::_class<lua_dbitmap>::create(L, rwidth, rheight);
for(auto y = 0; y < rheight; y++) {
const uint32_t* rowp = fb.rowptr(y);
framebuffer::color* rowt = &b->pixels[y * rwidth];
auto rowt = &b->pixels[y * rwidth];
for(auto x = 0; x < rwidth; x++) {
uint32_t v = rowp[x];
uint64_t c = -1;

View file

@ -4,6 +4,7 @@
#include "library/framebuffer.hpp"
#include "library/framebuffer-font2.hpp"
#include "library/utf8.hpp"
#include "library/lua-framebuffer.hpp"
#include <algorithm>
@ -119,19 +120,13 @@ namespace
{
if(!lua_render_ctx)
return 0;
int64_t fgc = 0xFFFFFFU;
int64_t bgc = -1;
int64_t hlc = -1;
int32_t _x = L.get_numeric_argument<int32_t>(2, fname.c_str());
int32_t _y = L.get_numeric_argument<int32_t>(3, fname.c_str());
L.get_numeric_argument<int64_t>(5, fgc, fname.c_str());
L.get_numeric_argument<int64_t>(6, bgc, fname.c_str());
L.get_numeric_argument<int64_t>(7, hlc, fname.c_str());
auto fg = lua_get_fb_color(L, 5, fname, 0xFFFFFFU);
auto bg = lua_get_fb_color(L, 6, fname, -1);
auto hl = lua_get_fb_color(L, 7, fname, -1);
std::string text = L.get_string(4, fname.c_str());
auto f = lua::_class<lua_customfont>::pin(L, 1, fname.c_str());
framebuffer::color fg(fgc);
framebuffer::color bg(bgc);
framebuffer::color hl(hlc);
lua_render_ctx->queue->create_add<render_object_text_cf>(_x, _y, text, fg, bg, hl, f);
return 0;
}

View file

@ -1,6 +1,7 @@
#include "lua/internal.hpp"
#include "fonts/wrapper.hpp"
#include "library/framebuffer.hpp"
#include "library/lua-framebuffer.hpp"
namespace
{
@ -33,15 +34,11 @@ namespace
{
if(!lua_render_ctx)
return 0;
int64_t fgc = 0xFFFFFFU;
int64_t bgc = -1;
int32_t _x = L.get_numeric_argument<int32_t>(1, fname.c_str());
int32_t _y = L.get_numeric_argument<int32_t>(2, fname.c_str());
L.get_numeric_argument<int64_t>(4, fgc, fname.c_str());
L.get_numeric_argument<int64_t>(5, bgc, fname.c_str());
auto fg = lua_get_fb_color(L, 4, fname, 0xFFFFFFU);
auto bg = lua_get_fb_color(L, 5, fname, -1);
std::string text = L.get_string(3, fname.c_str());
framebuffer::color fg(fgc);
framebuffer::color bg(bgc);
lua_render_ctx->queue->create_add<render_object_text>(_x, _y, text, fg, bg, hdbl, vdbl);
return 0;
}

View file

@ -4,6 +4,7 @@
#include "library/png.hpp"
#include "library/string.hpp"
#include "library/threadtypes.hpp"
#include "library/lua-framebuffer.hpp"
#include "library/zip.hpp"
#include "lua/bitmap.hpp"
#include <vector>