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.2},{1,0x000000,0.1}},
79 linear_gradient = {300,200,550,350},
80 colour = {{0,0x000000,0.4},{1,0x000000,0.1}},
88 colour = {{0,0x000000,0.25}},
96 colour = {{0,0x000000,0.4}},
101 { --backgound with gradient
104 linear_gradient = {300,200,550,350},
105 colour={{0,0xCCCCCC,1},{1,0xCCCCCC,0}}
116 colour = {{O,0xff00ff,0.5}},
120 { --border for pink rounded box
133 { --box with linear gradient
138 linear_gradient = {50,0,50,100 },
146 { --box with radial gradient
152 radial_gradient = {20,20,0,20,20,100 },
160 { --border for above box --gradient are inversed
166 radial_gradient = {20,20,0,20,20,100 },
176 { --oh my god, a circle with radial gradient
181 radial_gradient = {50,50,0,50,50,50 },
188 { --no name for this one ! radius > w or h !
193 radial_gradient = {50,50,0,50,50,50 },
205 ---------END OF PARAMETERS
211 function conky_main_box()
212 if conky_window==nil then return end
213 local cs=cairo_xlib_surface_create(conky_window.display, conky_window.drawable, conky_window.visual, conky_window.width, conky_window.height)
216 for i in pairs(table_settings) do
217 draw_bg (table_settings[i])
221 cairo_surface_destroy(cs)
225 function rgba_to_r_g_b_a(tc)
226 --tc={position,colour,alpha}
229 return ((colour / 0x10000) % 0x100) / 255., ((colour / 0x100) % 0x100) / 255., (colour % 0x100) / 255., alpha
234 --check values and set default values
235 if t.x == nil then t.x = 0 end
236 if t.y == nil then t.y = 0 end
237 if t.w == nil then t.w = conky_window.width end
238 if t.h == nil then t.h = conky_window.height end
239 if t.radius == nil then t.radius = 0 end
240 if t.border == nil then t.border = 0 end
241 if t.colour==nil then t.colour={{1,0xFFFFFF,1}} end
242 if t.linear_gradient ~= nil then
243 if #t.linear_gradient ~= 4 then
244 t.linear_gradient = {t.x,t.y,t.width,t.height}
247 if t.radial_gradient ~= nil then
248 if #t.radial_gradient ~= 6 then
249 t.radial_gradient = {t.x,t.y,0, t.x,t.y, t.width}
253 for i=1, #t.colour do
254 if #t.colour[i]~=3 then
255 print ("error in color table")
256 t.colour[i]={1,0xFFFFFF,1}
261 t.linear = t.linear_gradient
262 t.radial = t.radial_gradient
263 t.no_gradient = (t.linear == nil ) and (t.radial == nil )
266 cairo_translate(cr, t.x, t.y)
269 if t.mode=="circle" then
270 cairo_arc(cr, t.radius, t.radius, t.radius, -PI, -PI/2)
271 cairo_line_to(cr,t.w-t.radius,0)
272 cairo_arc(cr, t.w-t.radius, t.radius, t.radius, -PI/2,0)
273 cairo_line_to(cr,t.w,t.h-t.radius)
274 cairo_arc(cr, t.w-t.radius, t.h-t.radius, t.radius, 0,PI/2)
275 cairo_line_to(cr,t.radius,t.h)
276 cairo_arc(cr, t.radius, t.h-t.radius, t.radius, PI/2,-PI)
277 cairo_line_to(cr,0,t.radius)
279 cairo_move_to(cr, t.radius, 0)
280 cairo_line_to(cr, t.w-t.radius, 0)
281 cairo_curve_to(cr, t.w, 0, t.w, 0, t.w, t.radius)
282 cairo_line_to(cr, t.w, t.h-t.radius)
283 cairo_curve_to(cr, t.w, t.h, t.w, t.h, t.w - t.radius, t.h)
284 cairo_line_to(cr, t.radius, t.h)
285 cairo_curve_to(cr, 0, t.h, 0, t.h, 0, t.h-t.radius)
286 cairo_line_to(cr, 0, t.radius)
287 cairo_curve_to(cr, 0, 0, 0, 0, t.radius,0)
291 cairo_rectangle(cr,0,0,t.w,t.h)
294 if t.no_gradient then
295 cairo_set_source_rgba(cr,rgba_to_r_g_b_a(t.colour[1]))
297 if t.linear ~= nil then
298 pat = cairo_pattern_create_linear (t.linear[1],t.linear[2],t.linear[3],t.linear[4])
299 elseif t.radial ~= nil then
300 pat = cairo_pattern_create_radial (t.radial[1],t.radial[2],t.radial[3],t.radial[4],t.radial[5],t.radial[6])
302 for i=1, #t.colour do
303 cairo_pattern_add_color_stop_rgba (pat, t.colour[i][1], rgba_to_r_g_b_a(t.colour[i]))
305 cairo_set_source (cr, pat)
306 cairo_pattern_destroy(pat)
310 cairo_set_line_width(cr,t.border)