1 --[[BOX WIDGET v1.0 by Wlourf 19/12/2010
2 This widget can drawn some boxes, even circles in your conky window
3 http://u-scripts.blogspot.com/ (HowTo coming soon)
5 Inspired by Background by londonali1010 (2009)
7 The parameters (all optionals) are :
8 x - x coordinate of top-left corner of the box, default = 0 = (top-left corner of conky window)
9 y - y coordinate of top-left corner of the box, default = 0 = (top-left corner of conky window)
10 w - width of the box, default = width of the conky window
11 h - height of the box, default = width of the conky window
12 radius - radius of the corner, default = 0 = no radius
13 mode - mode for drawing the radius, possible values are "circle" or "curve", default ="curve"
14 linear_gradient - table with the coordinates of two points to define a linear gradient,
15 points are relative to top-left corner of the box, (not the conky window)
17 radial_gradient - table with the coordinates of two circle to define a radial gradient,
18 colour={{0,0xCCCCCC,1},{1,0xCCCCCC,0}} points are relative to top-left corner of the box, (not the conky window)
19 {x1,y1,r1,x2,y2,r2} (r=radius)
20 colour - table of colours, default = plain white {{1,0xFFFFFF,1}}
21 this table contains one or more tables with format {P,C,A}
22 P=position of gradient (0 = start of the gradient, 1= end of the gradient)
24 A=alpha (opacity) of color (0=invisible,1=opacity 100%)
26 for a plain color {{1,0x00FF00,0.5}}
27 for a gradient with two colours {{0,0x00FF00,0.5},{1,0x000033,1}}
28 or {{0.5,0x00FF00,1},{1,0x000033,1}} -with this one, gradient will start in the middle
29 for a gradient with three colours {{0,0x00FF00,0.5},{0.5,0x000033,1},{1,0x440033,1}}
34 To call this script in Conky, use (assuming you have saved this script to ~/scripts/):
35 lua_load ~/scripts/draw_bg.lua
36 lua_draw_hook_pre main_box
38 And leave one line blank or not after TEXT
41 + v1.0 -- Original release (19.12.2010)
44 -- Change these settings to affect your background.
52 linear_gradient = {300,200,550,350},
53 colour = {{0,0x000000,0.5},{1,0x000000,0.5}},
61 linear_gradient = {300,200,550,350},
62 colour = {{0,0x000000,0.2},{1,0x000000,0.1}},
70 linear_gradient = {300,200,550,350},
71 colour = {{0,0x000000,0.4},{1,0x000000,0.1}},
79 colour = {{0,0x000000,0.25}},
87 colour = {{0,0x000000,0.4}},
92 { --backgound with gradient
95 linear_gradient = {300,200,550,350},
96 colour={{0,0xCCCCCC,1},{1,0xCCCCCC,0}}
107 colour = {{O,0xff00ff,0.5}},
111 { --border for pink rounded box
124 { --box with linear gradient
129 linear_gradient = {50,0,50,100 },
137 { --box with radial gradient
143 radial_gradient = {20,20,0,20,20,100 },
151 { --border for above box --gradient are inversed
157 radial_gradient = {20,20,0,20,20,100 },
167 { --oh my god, a circle with radial gradient
172 radial_gradient = {50,50,0,50,50,50 },
179 { --no name for this one ! radius > w or h !
184 radial_gradient = {50,50,0,50,50,50 },
196 ---------END OF PARAMETERS
202 function conky_main_box()
203 if conky_window==nil then return end
204 local cs=cairo_xlib_surface_create(conky_window.display, conky_window.drawable, conky_window.visual, conky_window.width, conky_window.height)
207 for i in pairs(table_settings) do
208 draw_bg (table_settings[i])
212 cairo_surface_destroy(cs)
216 function rgba_to_r_g_b_a(tc)
217 --tc={position,colour,alpha}
220 return ((colour / 0x10000) % 0x100) / 255., ((colour / 0x100) % 0x100) / 255., (colour % 0x100) / 255., alpha
225 --check values and set default values
226 if t.x == nil then t.x = 0 end
227 if t.y == nil then t.y = 0 end
228 if t.w == nil then t.w = conky_window.width end
229 if t.h == nil then t.h = conky_window.height end
230 if t.radius == nil then t.radius = 0 end
231 if t.border == nil then t.border = 0 end
232 if t.colour==nil then t.colour={{1,0xFFFFFF,1}} end
233 if t.linear_gradient ~= nil then
234 if #t.linear_gradient ~= 4 then
235 t.linear_gradient = {t.x,t.y,t.width,t.height}
238 if t.radial_gradient ~= nil then
239 if #t.radial_gradient ~= 6 then
240 t.radial_gradient = {t.x,t.y,0, t.x,t.y, t.width}
244 for i=1, #t.colour do
245 if #t.colour[i]~=3 then
246 print ("error in color table")
247 t.colour[i]={1,0xFFFFFF,1}
252 t.linear = t.linear_gradient
253 t.radial = t.radial_gradient
254 t.no_gradient = (t.linear == nil ) and (t.radial == nil )
257 cairo_translate(cr, t.x, t.y)
260 if t.mode=="circle" then
261 cairo_arc(cr, t.radius, t.radius, t.radius, -PI, -PI/2)
262 cairo_line_to(cr,t.w-t.radius,0)
263 cairo_arc(cr, t.w-t.radius, t.radius, t.radius, -PI/2,0)
264 cairo_line_to(cr,t.w,t.h-t.radius)
265 cairo_arc(cr, t.w-t.radius, t.h-t.radius, t.radius, 0,PI/2)
266 cairo_line_to(cr,t.radius,t.h)
267 cairo_arc(cr, t.radius, t.h-t.radius, t.radius, PI/2,-PI)
268 cairo_line_to(cr,0,t.radius)
270 cairo_move_to(cr, t.radius, 0)
271 cairo_line_to(cr, t.w-t.radius, 0)
272 cairo_curve_to(cr, t.w, 0, t.w, 0, t.w, t.radius)
273 cairo_line_to(cr, t.w, t.h-t.radius)
274 cairo_curve_to(cr, t.w, t.h, t.w, t.h, t.w - t.radius, t.h)
275 cairo_line_to(cr, t.radius, t.h)
276 cairo_curve_to(cr, 0, t.h, 0, t.h, 0, t.h-t.radius)
277 cairo_line_to(cr, 0, t.radius)
278 cairo_curve_to(cr, 0, 0, 0, 0, t.radius,0)
282 cairo_rectangle(cr,0,0,t.w,t.h)
285 if t.no_gradient then
286 cairo_set_source_rgba(cr,rgba_to_r_g_b_a(t.colour[1]))
288 if t.linear ~= nil then
289 pat = cairo_pattern_create_linear (t.linear[1],t.linear[2],t.linear[3],t.linear[4])
290 elseif t.radial ~= nil then
291 pat = cairo_pattern_create_radial (t.radial[1],t.radial[2],t.radial[3],t.radial[4],t.radial[5],t.radial[6])
293 for i=1, #t.colour do
294 cairo_pattern_add_color_stop_rgba (pat, t.colour[i][1], rgba_to_r_g_b_a(t.colour[i]))
296 cairo_set_source (cr, pat)
297 cairo_pattern_destroy(pat)
301 cairo_set_line_width(cr,t.border)