Premultiplied_color default constructor (transparent color)
[lsnes.git] / src / lua / gui-rectangle.cpp
blobbb8bdd2ba8b042cc6408e9f44644026dd4965e60
1 #include "core/lua-int.hpp"
2 #include "core/render.hpp"
4 namespace
6 struct render_object_rectangle : public render_object
8 render_object_rectangle(int32_t _x, int32_t _y, uint32_t _width, uint32_t _height,
9 premultiplied_color _outline, premultiplied_color _fill, uint32_t _thickness) throw()
10 : x(_x), y(_y), width(_width), height(_height), outline(_outline), fill(_fill),
11 thickness(_thickness) {}
12 ~render_object_rectangle() throw() {}
13 void operator()(struct screen& scr) throw()
15 outline.set_palette(scr);
16 fill.set_palette(scr);
17 int32_t xmin = 0;
18 int32_t xmax = width;
19 int32_t ymin = 0;
20 int32_t ymax = height;
21 clip_range(scr.originx, scr.width, x, xmin, xmax);
22 clip_range(scr.originy, scr.height, y, ymin, ymax);
23 for(int32_t r = ymin; r < ymax; r++) {
24 uint32_t* rptr = scr.rowptr(y + r + scr.originy);
25 size_t eptr = x + xmin + scr.originx;
26 for(int32_t c = xmin; c < xmax; c++, eptr++)
27 if(r < thickness || c < thickness || r >= height - thickness ||
28 c >= width - thickness)
29 outline.apply(rptr[eptr]);
30 else
31 fill.apply(rptr[eptr]);
34 private:
35 int32_t x;
36 int32_t y;
37 uint32_t width;
38 uint32_t height;
39 premultiplied_color outline;
40 premultiplied_color fill;
41 uint32_t thickness;
44 function_ptr_luafun gui_rectangle("gui.rectangle", [](lua_State* LS, const std::string& fname) -> int {
45 if(!lua_render_ctx)
46 return 0;
47 int64_t outline = 0xFFFFFFU;
48 int64_t fill = -1;
49 uint32_t thickness = 1;
50 int32_t x = get_numeric_argument<int32_t>(LS, 1, fname.c_str());
51 int32_t y = get_numeric_argument<int32_t>(LS, 2, fname.c_str());
52 uint32_t width = get_numeric_argument<uint32_t>(LS, 3, fname.c_str());
53 uint32_t height = get_numeric_argument<uint32_t>(LS, 4, fname.c_str());
54 get_numeric_argument<uint32_t>(LS, 5, thickness, fname.c_str());
55 get_numeric_argument<int64_t>(LS, 6, outline, fname.c_str());
56 get_numeric_argument<int64_t>(LS, 7, fill, fname.c_str());
57 premultiplied_color poutline(outline);
58 premultiplied_color pfill(fill);
59 lua_render_ctx->queue->add(*new render_object_rectangle(x, y, width, height, poutline, pfill,
60 thickness));
61 return 0;
62 });