2022-07-10 16:25:12 -04:00
|
|
|
local common = require 'common'
|
|
|
|
local pure = require 'pure'
|
|
|
|
local geometry = require 'geometry'
|
|
|
|
local geom = require 'geom'
|
|
|
|
local fill_rect = require 'fill_rect'
|
2021-07-17 16:59:06 -04:00
|
|
|
|
2022-07-10 16:25:12 -04:00
|
|
|
return function(module_sets)
|
2021-07-17 16:59:06 -04:00
|
|
|
local __cairo_set_source_surface = cairo_set_source_surface
|
|
|
|
local __cairo_image_surface_create = cairo_image_surface_create
|
|
|
|
local __cairo_translate = cairo_translate
|
|
|
|
local __cairo_create = cairo_create
|
|
|
|
local __cairo_destroy = cairo_destroy
|
|
|
|
local __cairo_paint = cairo_paint
|
|
|
|
|
2022-07-10 16:25:12 -04:00
|
|
|
local _make_static_surface = function(box, modules)
|
2021-07-17 16:59:06 -04:00
|
|
|
local panel_line_thickness = 1
|
|
|
|
-- move over by half a pixel so the lines don't need to be antialiased
|
2022-07-10 16:25:12 -04:00
|
|
|
local _x = box.corner.x + 0.5
|
|
|
|
local _y = box.corner.y + 0.5
|
|
|
|
local panel = common.make_panel(_x, _y, box.width, box.height, panel_line_thickness)
|
2021-07-17 16:59:06 -04:00
|
|
|
local cs_x = _x - panel_line_thickness * 0.5
|
|
|
|
local cs_y = _y - panel_line_thickness * 0.5
|
2022-07-10 16:25:12 -04:00
|
|
|
local cs_w = box.width + panel_line_thickness
|
|
|
|
local cs_h = box.height + panel_line_thickness
|
2021-07-17 16:59:06 -04:00
|
|
|
|
|
|
|
local cs = __cairo_image_surface_create(CAIRO_FORMAT_ARGB32, cs_w, cs_h)
|
|
|
|
local cr = __cairo_create(cs)
|
|
|
|
|
|
|
|
__cairo_translate(cr, -cs_x, -cs_y)
|
|
|
|
|
2021-08-08 18:19:37 -04:00
|
|
|
fill_rect.draw(panel, cr)
|
2021-07-17 16:59:06 -04:00
|
|
|
for _, f in pairs(modules) do
|
|
|
|
f(cr)
|
|
|
|
end
|
|
|
|
__cairo_destroy(cr)
|
|
|
|
return { x = cs_x, y = cs_y, s = cs }
|
|
|
|
end
|
|
|
|
|
2022-07-10 16:25:12 -04:00
|
|
|
-- TODO pull this out eventually
|
|
|
|
local boxes = {
|
|
|
|
geom.make_box(
|
|
|
|
geometry.LEFT_X - geometry.PANEL_MARGIN_X,
|
|
|
|
geometry.TOP_Y - geometry.PANEL_MARGIN_Y,
|
|
|
|
geometry.SECTION_WIDTH + geometry.PANEL_MARGIN_X * 2,
|
|
|
|
geometry.SIDE_HEIGHT + geometry.PANEL_MARGIN_Y * 2
|
|
|
|
),
|
|
|
|
geom.make_box(
|
|
|
|
geometry.CENTER_LEFT_X - geometry.PANEL_MARGIN_X,
|
|
|
|
geometry.TOP_Y - geometry.PANEL_MARGIN_Y,
|
|
|
|
geometry.CENTER_WIDTH + geometry.PANEL_MARGIN_Y * 2 + geometry.CENTER_PAD,
|
|
|
|
geometry.CENTER_HEIGHT + geometry.PANEL_MARGIN_Y * 2
|
|
|
|
),
|
|
|
|
geom.make_box(
|
|
|
|
geometry.RIGHT_X - geometry.PANEL_MARGIN_X,
|
|
|
|
geometry.TOP_Y - geometry.PANEL_MARGIN_Y,
|
|
|
|
geometry.SECTION_WIDTH + geometry.PANEL_MARGIN_X * 2,
|
|
|
|
geometry.SIDE_HEIGHT + geometry.PANEL_MARGIN_Y * 2
|
|
|
|
)
|
|
|
|
}
|
2021-07-17 16:59:06 -04:00
|
|
|
|
2022-07-10 16:25:12 -04:00
|
|
|
local cs = pure.zip_with(_make_static_surface, boxes, module_sets)
|
2021-07-17 16:59:06 -04:00
|
|
|
|
|
|
|
local draw_static_surface = function(cr, cs_obj)
|
|
|
|
__cairo_set_source_surface(cr, cs_obj.s, cs_obj.x, cs_obj.y)
|
|
|
|
__cairo_paint(cr)
|
|
|
|
end
|
|
|
|
|
|
|
|
return function(cr)
|
2022-07-10 16:25:12 -04:00
|
|
|
for i = 1, #cs do
|
|
|
|
draw_static_surface(cr, cs[i])
|
|
|
|
end
|
2021-07-17 16:59:06 -04:00
|
|
|
end
|
|
|
|
end
|