Londonali1010 airclock.module (en)

From Conky PitStop

Jump to: navigation, search

londonali1010_airclock.module

User:DK75

 Language   English   Français   


londonali1010 airclock for One4All project

Airclock.module.png

Londonali1010 airclock.module-1.0.tar.gz

--[[
Air Clock by Alison Pitt (2009)

This clock is designed to look like KDE 4.3's "Air" clock, but from inside Conky.

You can adjust the clock's radius and placement, as well as the size and offset of the drop shadow. You can also choose whether to display the seconds hand. This clock updates every time Conky does, so if you want to show seconds, it is recommended that you set update_interval to no more than 0.5s. If you turn off seconds, you can set the update_interval to as long as 30s.  The settings are in the "Settings" section, starting at Line 21.

changelog:

v1.0	- (03.2012) converted to one4all module by dk75
]]

local modname = ...
local M = {}
_G[modname] = M
package.loaded[modname] = M



--[[
###############################################################################
###                              SETTINGS                                   ###
###############################################################################
--]]
local settings_table = {
	{
		-- What radius should the clock face (not including border) be, in pixels?
		clock_r=60,
	
		-- x and y coordinates, relative to the top left corner of Conky, in pixels
		xc=100,
		yc=100,
	
		-- Extent of the shadow, in pixels
		shadow_width=5,
		
		-- x and y offsets of the drop shadow, relative to the centre of the clock face, in pixels. Can be positive (downward) or negative (upward)
		shadow_xoffset=1,
		shadow_yoffset=2,
		
		-- Do you want to show the second hand? Use this if you use a Conky update_interval > 1s. Can be true or false.
		show_seconds=true,
		
		-- Shadow colors
		shadow_color1 = 0x000000,
		shadow_alpha1 = 0.2,
		shadow_color2 = 0x000000,
		shadow_alpha2 = 0,
		
		-- Border colors
		border_color1 = 0x000000, border_alpha1 = 0.2, --rim arround a border
		border_color2 = 0x000000, border_alpha2 = 0.7,
		border_color3 = 0x000000, border_alpha3 = 0.1,
		border_color4 = 0x000000, border_alpha4 = 0.1,
		border_color5 = 0x000000, border_alpha5 = 0.1,
		border_color6 = 0x000000, border_alpha6 = 0.7,
		
		-- Face colors
		face_color1 = 0xffffff, face_alpha1 = 0.8,
		face_color2 = 0xffffff, face_alpha2 = 0.6,
		face_color3 = 0xffffff, face_alpha3 = 0.4,
		face_color4 = 0x808080, face_alpha4 = 0.2, --rim arround a face
		
		-- Hands color
		hands_color = 0xff0000, hands_alpha = 0.5
	},
}
--[[
###############################################################################
###                           END OF SETTINGS                               ###
###############################################################################
--]]



function M.draw_clock(t)
	-- Conky window width and height
	local w = conky_window.width
	local h = conky_window.height
	--local w, h = 200, 200
	
	-- Grab time
	
	local hours=os.date("%I")
	local mins=os.date("%M")
	local secs=os.date("%S")
	
	local secs_arc=(2*math.pi/60)*secs
	local mins_arc=(2*math.pi/60)*mins
	local hours_arc=(2*math.pi/12)*hours+mins_arc/12
	
	-- Drop shadow
	
	local ds_pat=cairo_pattern_create_radial(t.xc+t.shadow_xoffset,t.yc+t.shadow_yoffset,t.clock_r*1.25,t.xc+t.shadow_xoffset,t.yc+t.shadow_yoffset,t.clock_r*1.25+t.shadow_width)
	cairo_pattern_add_color_stop_rgba(ds_pat,0,one4all_cairo.rgb2rgba(t.shadow_color1, t.shadow_alpha1))
	cairo_pattern_add_color_stop_rgba(ds_pat,1,one4all_cairo.rgb2rgba(t.shadow_color2, t.shadow_alpha2))
	
	cairo_move_to(cr,0,0)
	cairo_line_to(cr,w,0)
	cairo_line_to(cr,w,h)
	cairo_line_to(cr,0,h)
	cairo_new_sub_path(cr)
	cairo_arc(cr,t.xc,t.yc,t.clock_r*1.25,0,2*math.pi)
	cairo_set_source(cr,ds_pat)
	cairo_set_fill_rule(cr,CAIRO_FILL_RULE_EVEN_ODD)
	cairo_fill(cr)
	
	-- Glassy border
	
	cairo_arc(cr,t.xc,t.yc,t.clock_r*1.25,0,2*math.pi)
	cairo_set_source_rgba(cr,one4all_cairo.rgb2rgba(t.border_color1, t.border_alpha1))
	cairo_set_line_width(cr,1)
	cairo_stroke(cr)
	
	local border_pat=cairo_pattern_create_linear(t.xc,t.yc-t.clock_r*1.25,t.xc,t.yc+t.clock_r*1.25)
	
	cairo_pattern_add_color_stop_rgba(border_pat,0,one4all_cairo.rgb2rgba(t.border_color2, t.border_alpha2))
	cairo_pattern_add_color_stop_rgba(border_pat,0.3,one4all_cairo.rgb2rgba(t.border_color3, t.border_alpha3))
	cairo_pattern_add_color_stop_rgba(border_pat,0.5,one4all_cairo.rgb2rgba(t.border_color4, t.border_alpha4))
	cairo_pattern_add_color_stop_rgba(border_pat,0.7,one4all_cairo.rgb2rgba(t.border_color5, t.border_alpha5))
	cairo_pattern_add_color_stop_rgba(border_pat,1,one4all_cairo.rgb2rgba(t.border_color6, t.border_alpha6))
	cairo_set_source(cr,border_pat)
	cairo_arc(cr,t.xc,t.yc,t.clock_r*1.125,0,2*math.pi)
	cairo_close_path(cr)
	cairo_set_line_width(cr,t.clock_r*0.25)
	cairo_stroke(cr)
	
	-- Set clock face
	
	cairo_arc(cr,t.xc,t.yc,t.clock_r,0,2*math.pi)
	cairo_close_path(cr)
	
	local face_pat=cairo_pattern_create_radial(t.xc,t.yc-t.clock_r*0.75,0,t.xc,t.yc,t.clock_r)
	
	cairo_pattern_add_color_stop_rgba(face_pat,0,one4all_cairo.rgb2rgba(t.face_color1, t.face_alpha1))
	cairo_pattern_add_color_stop_rgba(face_pat,0.5,one4all_cairo.rgb2rgba(t.face_color2, t.face_alpha2))
	cairo_pattern_add_color_stop_rgba(face_pat,1,one4all_cairo.rgb2rgba(t.face_color3, t.face_alpha3))
	cairo_set_source(cr,face_pat)
	cairo_fill_preserve(cr)
	cairo_set_source_rgba(cr,one4all_cairo.rgb2rgba(t.face_color4, t.face_alpha4))
	cairo_set_line_width(cr, 1)
	cairo_stroke (cr)
	
	-- Draw hour hand
	
	local xh=t.xc+0.7*t.clock_r*math.sin(hours_arc)
	local yh=t.yc-0.7*t.clock_r*math.cos(hours_arc)
	cairo_move_to(cr,t.xc,t.yc)
	cairo_line_to(cr,xh,yh)
	
	cairo_set_line_cap(cr,CAIRO_LINE_CAP_ROUND)
	cairo_set_line_width(cr,5)
	cairo_set_source_rgba(cr,one4all_cairo.rgb2rgba(t.hands_color, t.hands_alpha))
	cairo_stroke(cr)
	
	-- Draw minute hand
	
	local xm=t.xc+0.9*t.clock_r*math.sin(mins_arc)
	local ym=t.yc-0.9*t.clock_r*math.cos(mins_arc)
	cairo_move_to(cr,t.xc,t.yc)
	cairo_line_to(cr,xm,ym)
	
	cairo_set_line_width(cr,3)
	cairo_stroke(cr)
	
	-- Draw seconds hand
	
	if t.show_seconds then
		local xs=t.xc+0.9*t.clock_r*math.sin(secs_arc)
		local ys=t.yc-0.9*t.clock_r*math.cos(secs_arc)
		cairo_move_to(cr,t.xc,t.yc)
		cairo_line_to(cr,xs,ys)
	
		cairo_set_line_width(cr,1)
		cairo_stroke(cr)
	end
	
	cairo_set_line_cap(cr,CAIRO_LINE_CAP_BUTT)
end



--[[
###############################################################################
###                            MODULE MAIN LOOP                             ###
###############################################################################
--]]
function M.main()
        for i in pairs(settings_table) do
            M.draw_clock(settings_table[i])
        end
end
Personal tools
Namespaces
Variants
Actions
Navigation
English
Français
Toolbox