info = { type = "app", title = "Photo clock", author = "BRRRO", license = "MIT", desc = "Big time over your images", category = "time", api = 38, } permissions = { "images" } local T = ({ sk = { pos = "Poloha času", pos_o = { "hore", "v strede", "dole" }, style = "Číslice", style_o = { "tučné", "veľké tenké", "stredné", "pixelové" }, back = "Podklad", back_o = { "obrys", "tieň", "pás", "žiadny" }, color = "Farba", bcolor = "Farba podkladu", date = "Deň a dátum" }, cs = { pos = "Poloha času", pos_o = { "nahoře", "uprostřed", "dole" }, style = "Číslice", style_o = { "tučné", "velké tenké", "střední", "pixelové" }, back = "Podklad", back_o = { "obrys", "stín", "pás", "žádný" }, color = "Barva", bcolor = "Barva podkladu", date = "Den a datum" } })[lang] or { pos = "Time position", pos_o = { "top", "middle", "bottom" }, style = "Digits", style_o = { "bold", "big thin", "medium", "pixel" }, back = "Backing", back_o = { "outline", "shadow", "band", "none" }, color = "Colour", bcolor = "Backing colour", date = "Day and date" } settings = { { key = "pos", type = "int", default = "bottom", label = T.pos, opts = { keys = { "top", "middle", "bottom" }, table.unpack(T.pos_o) } }, { key = "style", type = "int", default = "bold", label = T.style, opts = { keys = { "bold", "big", "thin", "pixel" }, table.unpack(T.style_o) } }, { key = "back", type = "int", default = "outline", label = T.back, opts = { keys = { "outline", "shadow", "band", "none" }, table.unpack(T.back_o) } }, { key = "color", type = "color", default = "#FFFAE8", label = T.color }, { key = "bcolor", type = "color", default = "#0A0806", label = T.bcolor }, { key = "date", type = "bool", default = true, label = T.date }, } local W, H = gfx.W, gfx.H local text, text_width, text_ink = gfx.text, gfx.text_width, gfx.text_ink local floor, fmt, find = math.floor, string.format, string.find local DAYS = ({ sk = { "NEDEĽA", "PONDELOK", "UTOROK", "STREDA", "ŠTVRTOK", "PIATOK", "SOBOTA" }, cs = { "NEDĚLE", "PONDĚLÍ", "ÚTERÝ", "STŘEDA", "ČTVRTEK", "PÁTEK", "SOBOTA" }, })[lang] or { "SUNDAY", "MONDAY", "TUESDAY", "WEDNESDAY", "THURSDAY", "FRIDAY", "SATURDAY" } local BACK = { 10, 8, 6 } local STYLE = { bold = { font = "9x15b" }, big = { font = "12x24", tight = false }, thin = { font = "10x20" }, pixel = { font = "5x7", scale = 2 }, } for _, o in pairs(STYLE) do o.hide = nil end local O_DATE = { font = "4x6" } local GAP = 3 local function set_back(o, back) o.outline = back == "outline" and BACK or nil o.shadow = back == "shadow" and BACK or nil end local PLACE = nil local function build_place() for y = 0, H - 1 do local k = y / (H - 1) gfx.rect(0, y, W, 1, floor(36 + 214 * k ^ 1.4), floor(48 + 92 * k), floor(120 - 30 * k)) end for r = 11, 6, -1 do gfx.blend_rect(44 - r, 34 - r, 2 * r + 1, 2 * r + 1, 255, 190, 120, 0.06) end for dy = -5, 5 do local w = floor(math.sqrt(25.5 - dy * dy)) gfx.rect(44 - w, 34 + dy, 2 * w + 1, 1, 255, 214, 140) end for x = 0, W - 1 do local h1 = 40 + floor(4 * math.sin(x * 0.11) + 3 * math.sin(x * 0.27 + 1)) local h2 = 49 + floor(3 * math.sin(x * 0.17 + 2)) gfx.rect(x, h1, 1, H - h1, 60, 34, 62) gfx.rect(x, h2, 1, H - h2, 28, 18, 34) end PLACE = gfx.snapshot(0, 0, W, H) end function render() if not gfx.bg() then if #images > 0 then gfx.clear(0, 0, 0) else if not PLACE then build_place() end gfx.blit_rgb(PLACE, 0, 0, W, H) end end local t = data.time if not (t and t.ok) then return end local o = STYLE[cfg.style] or STYLE.bold local back, bc = cfg.back, cfg.bcolor BACK[1], BACK[2], BACK[3] = bc.r, bc.g, bc.b set_back(o, back); set_back(O_DATE, back) local c = cfg.color local hm if t.fmt12 then hm = fmt("%d:%02d", t.h12, t.m) else hm = fmt("%02d:%02d", t.h, t.m) end o.hide = (t.s % 2 == 1) and find(hm, ":", 1, true) or nil local d = DAYS[(t.wday % 7) + 1] .. fmt(" %d.%d", t.day, t.month) if t.fmt12 then d = d .. (t.pm and " PM" or " AM") end local t0, t1 = text_ink(hm, o) local d0, d1 = text_ink(d, O_DATE) local th, dh = t1 - t0 + 1, cfg.date and (d1 - d0 + 1 + GAP) or 0 local top if cfg.pos == "top" then top = 2 elseif cfg.pos == "middle" then top = (H - th - dh) // 2 else top = H - 2 - th - dh end if back == "band" then local y0, h = top - 3, th + dh + 6 gfx.blend_rect(0, y0 - 1, W, 1, bc.r, bc.g, bc.b, 0.25) gfx.blend_rect(0, y0, W, h, bc.r, bc.g, bc.b, 0.5) gfx.blend_rect(0, y0 + h, W, 1, bc.r, bc.g, bc.b, 0.25) end text((W - text_width(hm, o)) // 2, top - t0, hm, c.r, c.g, c.b, o) if cfg.date then gfx.text_center(top + th + GAP - d0, d, c.r, c.g, c.b, O_DATE) end end