Date box.module (en)
From Conky PitStop
date_box.module
Language | English Français |
date_box for One4All project
--[[ ################################################################################ Date Box module ################################################################################ changelog: v1.0 - (..) initial release --]] local modname = ... local M = {} _G[modname] = M package.loaded[modname] = M --[[ ############################################################################### ### SETTINGS ### ############################################################################### --]] local settings_table = { { --Weekday text color wred = 1, wgreen = 1, wblue = 1, wcolor = 0xffffff, walpha = 1, --Weekday text font wfont = "TransponderAOE", --Weekday text size wfontsize = 16, --Weekday font bold? Set to 1 for bold font wfbold = 1, --################################################### --Month text color mred = 1, mgreen = 0, mblue = 0, mcolor = 0xff0000, malpha = 1, --Month text font mfont = "TransponderAOE", --Month text size mfontsize = 16, --Month font bold? Set to 1 for bold font mfbold = 1, --################################################### --Day text color dred = 1, dgreen = 1, dblue = 0, dcolor = 0xffff00, dalpha = 1, --Day font dfont = "TransponderAOE", --Day size dfontsize = 30, --Day font bold? Set to 1 for bold font dfbold = 1, --################################################### --Year text color yred = 1, ygreen = 1, yblue = 1, ycolor = 0xffffff, yalpha = 1, --year font yfont = "TransponderAOE", --Year size yfontsize = 18, --Year font bold? Set to 1 for bold font yfbold = 1, --################################################### --indicator box enter 1 for box or 0 for no box box = 1, --use the following 2 numbers to adjust box position xadjust = 50, yadjust = 50, --set the box dimensions width = 104, height = 110, --box thickness bthick = 8, --box color bxred = 0, bxgreen = 0, bxblue = 0.753, bxcolor = 0x000080, bxalpha = 1, --################################################### --gap from sides gaph = 10, --################################################### }, } --[[ ############################################################################### ### END OF SETTINGS ### ############################################################################### --]] function M.set_the_font(cr, fface, fsize, fbold) if fbold == 1 then cairo_select_font_face(cr, fface, CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD) else cairo_select_font_face(cr, fface, CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL) end cairo_set_font_size(cr, fsize) end function M.draw_date(cr, extents, string, fcolor, falpha, tacross, down) cairo_set_source_rgba(cr, one4all_cairo.rgb2rgba(fcolor, falpha)) cairo_move_to(cr, tacross - (extents.width /2 ), down) cairo_show_text(cr, string) end function M.draw_box(t) --################################################### --Today's Date Box ############################### --################################################### --position down = t.yadjust + t.bthick --variables (need to set font face, font size and text string in order to populate text extents structure with text measurements) -- Weekday local wdays = os.date("%A") local ext_wdays = cairo_text_extents_t:create() M.set_the_font(cr, t.wfont, t.wfontsize, t.wfbold) cairo_text_extents(cr, wdays, ext_wdays) -- Month local month = os.date("%B") local ext_month = cairo_text_extents_t:create() M.set_the_font(cr, t.mfont, t.mfontsize, t.mfbold) cairo_text_extents(cr, month, ext_month) -- Today local today = tonumber(os.date("%d")) local ext_today = cairo_text_extents_t:create() M.set_the_font(cr, t.dfont, t.dfontsize, t.dfbold) cairo_text_extents(cr, today, ext_today) -- Year local year = os.date("%G") local ext_year = cairo_text_extents_t:create() M.set_the_font(cr, t.yfont, t.yfontsize, t.yfbold) cairo_text_extents(cr, year, ext_year) -- text across box center axis local tacross = t.xadjust + (t.width / 2) -- gap between lines (with 4 lines it will be 3 gaps) local gapl = (t.height - (t.bthick * 2) - (t.gaph * 2) - ext_wdays.height - ext_month.height - ext_today.height - ext_year.height) / 3 --################################################### --print box --################################################### --Weekday down = down + t.gaph + ext_wdays.height M.set_the_font(cr, t.wfont, t.wfontsize, t.wfbold) M.draw_date(cr, ext_wdays, wdays, t.wcolor, t.walpha, tacross, down) --Month down = down + gapl + ext_month.height M.set_the_font(cr, t.mfont, t.mfontsize, t.mfbold) M.draw_date(cr, ext_month, month, t.mcolor, t.malpha, tacross, down) --Day down = down + gapl + ext_today.height M.set_the_font(cr, t.dfont, t.dfontsize, t.dfbold) M.draw_date(cr, ext_today, today, t.dcolor, t.dalpha, tacross, down) --Year down = down + gapl + ext_year.height M.set_the_font(cr, t.yfont, t.yfontsize, t.yfbold) M.draw_date(cr, ext_year, year, t.ycolor, t.yalpha, tacross, down) --box around if t.box == 1 then cairo_set_source_rgba(cr, one4all_cairo.rgb2rgba(t.bxcolor, t.bxalpha)) cairo_rectangle(cr, t.xadjust, t.yadjust, t.width, t.height) cairo_set_line_width(cr, t.bthick) cairo_stroke(cr) end cairo_stroke(cr) --################################################################################# end--end box function --[[ ############################################################################### ### MODULE MAIN LOOP ### ############################################################################### --]] function M.main() for i in pairs(settings_table) do M.draw_box(settings_table[i]) end end