read some more battery data using new bme.c file but not stable, crashes after 23...
[monky] / data / bargraph_eng.lua
1
2
3 --[[ BARGRAPH WIDGET
4         v2.0 by wlourf (12.07.2010)
5         this widget draws a bargraph with different effects 
6         http://u-scripts.blogspot.com/2010/07/bargraph-widget.html
7         
8         
9 Parameters are :
10 3 parameters are mandatory
11 name    - the name of the conky variable to display, for example for {$cpu cpu0}, just write name="cpu"
12 arg             - the argument of the above variable, for example for {$cpu cpu0}, just write arg="cpu0"
13                   arg can be a numerical value if name=""
14 max             - the maximum value the above variable can reach, for example, for {$cpu cpu0}, just write  max=100
15         
16 Optional parameters:
17 x,y             - coordinates of the starting point of the bar, default = middle of the conky window
18 cap             - end of cap line, ossibles values are r,b,s (for round, butt, square), default="b"
19                   http://www.cairographics.org/samples/set_line_cap/
20 angle   - angle of rotation of the bar in degress, default = 0 (i.e. a vertical bar)
21                   set to 90 for an horizontal bar
22 skew_x  - skew bar around x axis, default = 0
23 skew_y  - skew bar around y axis, default = 0
24 blocks  - number of blocks to display for a bar (values >0) , default= 10
25 height  - height of a block, default=10 pixels
26 width   - width of a block, default=20 pixels
27 space   - space between 2 blocks, default=2 pixels
28 angle_bar       - this angle is used to draw a bar on a circular way (ok, this is no more a bar !) default=0
29 radius          - for cicular bars, internal radius, default=0
30                           with radius, parameter width has no more effect.
31
32 Colours below are defined into braces {colour in hexadecimal, alpha}
33 fg_colour       - colour of a block ON, default= {0x00FF00,1}
34 bg_colour       - colour of a block OFF, default = {0x00FF00,0.5}
35 alarm           - threshold, values after this threshold will use alarm_colour colour , default=max
36 alarm_colour - colour of a block greater than alarm, default=fg_colour
37 smooth          - (true or false), create a gradient from fg_colour to bg_colour, default=false 
38 mid_colour      - colours to add to gradient, with this syntax {position into the gradient (0 to1), colour hexa, alpha}
39                           for example, this table {{0.25,0xff0000,1},{0.5,0x00ff00,1},{0.75,0x0000ff,1}} will add
40                           3 colurs to gradient created by fg_colour and alarm_colour, default=no mid_colour
41 led_effect      - add LED effects to each block, default=no led_effect
42                           if smooth=true, led_effect is not used
43                           possibles values : "r","a","e" for radial, parallelel, perdendicular to the bar (just try!)
44                           led_effect has to be used with theses colours :
45 fg_led          - middle colour of a block ON, default = fg_colour
46 bg_led          - middle colour of a block OFF, default = bg_colour
47 alarm_led       - middle colour of a block > ALARM,  default = alarm_colour
48
49 reflection parameters, not avaimable for circular bars
50 reflection_alpha    - add a reflection effect (values from 0 to 1) default = 0 = no reflection
51                       other values = starting opacity
52 reflection_scale    - scale of the reflection (default = 1 = height of text)
53 reflection_length   - length of reflection, define where the opacity will be set to zero
54                                           calues from 0 to 1, default =1
55 reflection                      - position of reflection, relative to a vertical bar, default="b"
56                                           possibles values are : "b","t","l","r" for bottom, top, left, right
57
58
59 v1.0 (10 Feb. 2010) original release
60 v1.1 (13 Feb. 2010) numeric values can be passed instead conky stats with parameters name="", arg = numeric_value       
61 v1.2 (28 Feb. 2010) just renamed the widget to bargraph
62 v1.3 (03 March 2010) added parameters radius & angle_bar to draw the bar in a circular way
63 v2.0 (12 Jul. 2010) rewrite script + add reflection effects and parameters are now set into tables
64 ]]
65
66 require 'cairo'
67
68 ----------------START OF PARAMETERS ----------
69 function conky_main_bars()
70         local bars_settings={
71
72                 {
73                         name="fs_used",
74                         arg="/",
75                         max=conky_parse("${to_bytes ${fs_size /}}"),
76                         --alarm=1,--no alarm with 1 smooth block, don't do extra work here
77                         bg_colour={0x00ff00,0.25},
78                         fg_colour={0x00ff00,1},
79                         alarm_colour={0xff0000,1},
80                         x=5,y=122,
81                         angle=90,
82                         blocks=1,
83                         height=210,width=18,
84                         smooth=true,
85                         mid_colour={{0.5,0xffff00,1}},
86                 },
87                 
88                 {
89                         name="fs_used",
90                         arg="/home",
91                         max=conky_parse("${to_bytes ${fs_size /home}}"),
92                         --alarm=1,--no alarm with 1 smooth block, don't do extra work here
93                         bg_colour={0x00ff00,0.25},
94                         fg_colour={0x00ff00,1},
95                         alarm_colour={0xff0000,1},
96                         x=5,y=142,
97                         angle=90,
98                         blocks=1,
99                         height=210,width=18,
100                         smooth=true,
101                         mid_colour={{0.5,0xffff00,1}},
102                 },
103                 {
104                         name="fs_used",
105                         arg="/home/user/MyDocs",
106                         max=conky_parse("${to_bytes ${fs_size /home/user/MyDocs}}"),
107                         --alarm=1,--no alarm with 1 smooth block, don't do extra work here
108                         bg_colour={0x00ff00,0.25},
109                         fg_colour={0x00ff00,1},
110                         alarm_colour={0xff0000,1},
111                         x=5,y=162,
112                         angle=90,
113                         blocks=1,
114                         height=210,width=18,
115                         smooth=true,
116                         mid_colour={{0.5,0xffff00,1}},
117                         DrawMe=conky_parse("${if_mounted /home/user/MyDocs}1$endif")
118                 },      
119                 --[[{
120                         name="fs_used",
121                         arg="/media/mmc1",
122                         max=conky_parse("${to_bytes ${fs_size /media/mmc1}}"),
123                         --alarm=1,--no alarm with 1 smooth block, don't do extra work here
124                         bg_colour={0x00ff00,0.25},
125                         fg_colour={0x00ff00,1},
126                         alarm_colour={0xff0000,1},
127                         x=5,y=182,
128                         angle=90,
129                         blocks=1,
130                         height=210,width=18,
131                         smooth=true,
132                         mid_colour={{0.5,0xffff00,1}},
133                         DrawMe=conky_parse("${if_mounted /media/mmc1}1$endif")
134                 },]]
135                 {
136                         name="mem",
137                         arg="",
138                         max=conky_parse("${to_bytes ${memmax}}"),
139                         alarm=100,
140                         bg_colour={0x00ff00,0.25},
141                         fg_colour={0x00ff00,1},
142                         alarm_colour={0xff0000,1},
143                         x=9,y=105,
144                         angle=90,
145                         blocks=18,
146                         height=10,width=18,
147                         smooth=true,
148                         --mid_colour={{0.5,0xffff00,1}},
149                 },              
150                 {
151                         name="battery_percent",
152                         arg="",
153                         max=100,
154                         angle=90,
155                         alarm=25,
156                         alarm_colour={0x00ffff,0.5},
157                         bg_colour={0x00ffff,0.5},
158                         fg_colour={0xff0000,0.5},
159                         led_effect="e",
160                         bg_led  ={0x0000ff,1},
161                         fg_led  ={0xffff00,1},
162                         x=575,y=40,
163                         skew_y=15,
164                 },
165                 {
166                         name="wireless_link_qual_perc",
167                         arg="wlan0",
168                         max=100,
169                         angle=270,
170                         bg_colour={0x00ff33,0},
171                         fg_colour={0x00ff33,1},
172                         blocks=10,
173                         x=417,y=225,
174                         height=3,
175                         cap="b",
176                         angle_bar=20,
177                         radius=9,
178                         mid_colour={{0,0xFF0000,1},{0.5,0xff0000,1},{0.7,0xffff00,1},{0.85,0x00ff33,1}},
179                         smooth = true,
180                         DrawMe=conky_parse("${if_empty ${wireless_essid wlan0}}${else}1$endif"),
181                 },
182                 {
183                         name="wireless_link_qual_perc",
184                         arg="wlan0",
185                         max=100,
186                         angle=90,
187                         bg_colour={0x00ff33,0},
188                         fg_colour={0x00ff33,1},
189                         blocks=10,
190                         x=432,y=225,
191                         height=3,
192                         cap="b",
193                         angle_bar=20,
194                         radius=9,
195                         mid_colour={{0,0xFF0000,1},{0.5,0xff0000,1},{0.7,0xffff00,1},{0.85,0x00ff33,1}},
196                         smooth = true,
197                         DrawMe=conky_parse("${if_empty ${wireless_essid wlan0}}${else}1$endif"),
198                 },      
199                 {
200                         name="cell_radio_percent",
201                         arg="",
202                         max=100,
203                         bg_colour={0x00ff33,0},
204                         fg_colour={0x00ff33,1},
205                         blocks=10,
206                         x=445,
207                         y=49,
208                         height=3,
209                         cap="b",
210                         angle_bar=20,
211                         angle=90,
212                         radius=9,
213                         mid_colour={{0,0xFF0000,1},{0.5,0xff0000,1},{0.7,0xffff00,1},{0.85,0x00ff33,1}},
214                         smooth = true,
215                         --DrawMe=conky_parse("${if_up gprs0}1$endif")
216                 },                                      
217         }
218            
219         if conky_window == nil then return end
220         local cs = cairo_xlib_surface_create(conky_window.display, conky_window.drawable, conky_window.visual, conky_window.width, conky_window.height)
221         cr = cairo_create(cs)    
222         --prevent segmentation error when reading cpu state
223     if tonumber(conky_parse('${updates}'))>3 then
224         for i in pairs(bars_settings) do
225                 draw_multi_bar_graph(bars_settings[i])
226         end
227     end
228         cairo_destroy(cr)
229         cairo_surface_destroy(cs)
230         cr=nil
231 end
232
233 function draw_multi_bar_graph(t)
234         cairo_save(cr)
235         --check values
236         if t.DrawMe~=nil and t.DrawMe ~= "1" then return end
237         if t.name==nil and t.arg==nil then 
238                 print ("No input values ... use parameters 'name' with 'arg' or only parameter 'arg' ") 
239                 return
240         end
241         if t.max==nil then
242                 print ("No maximum value defined, use 'max'")
243                 return
244         end
245         if t.name==nil then t.name="" end
246         if t.arg==nil then t.arg="" end
247
248         --set default values    
249         if t.x == nil           then t.x = conky_window.width/2 end
250         if t.y == nil           then t.y = conky_window.height/2 end
251         if t.blocks == nil      then t.blocks=10 end
252         if t.height == nil      then t.height=10 end
253         if t.angle == nil       then t.angle=0 end
254         t.angle = t.angle*math.pi/180
255         --line cap style
256         if t.cap==nil           then t.cap = "b" end
257         local cap="b"
258         for i,v in ipairs({"s","r","b"}) do 
259                 if v==t.cap then cap=v end
260         end
261         local delta=0
262         if t.cap=="r" or t.cap=="s" then delta = t.height end
263         if cap=="s" then        cap = CAIRO_LINE_CAP_SQUARE
264         elseif cap=="r" then
265                 cap = CAIRO_LINE_CAP_ROUND
266         elseif cap=="b" then
267                 cap = CAIRO_LINE_CAP_BUTT
268         end
269         --end line cap style
270         --if t.led_effect == nil        then t.led_effect="r" end
271         if t.width == nil       then t.width=20 end
272         if t.space == nil       then t.space=2 end
273         if t.radius == nil      then t.radius=0 end
274         if t.angle_bar == nil   then t.angle_bar=0 end
275         t.angle_bar = t.angle_bar*math.pi/360 --halt angle
276         --colours
277         if t.bg_colour == nil   then t.bg_colour = {0x00FF00,0.5} end
278         if #t.bg_colour~=2              then t.bg_colour = {0x00FF00,0.5} end
279         if t.fg_colour == nil   then t.fg_colour = {0x00FF00,1} end
280         if #t.fg_colour~=2              then t.fg_colour = {0x00FF00,1} end
281         if t.alarm_colour == nil        then t.alarm_colour = t.fg_colour end
282         if #t.alarm_colour~=2           then t.alarm_colour = t.fg_colour end
283         if t.mid_colour ~= nil then     
284                 for i=1, #t.mid_colour do    
285                     if #t.mid_colour[i]~=3 then 
286                         print ("error in mid_color table")
287                         t.mid_colour[i]={1,0xFFFFFF,1} 
288                     end
289                 end
290     end
291         if t.bg_led ~= nil and #t.bg_led~=2     then t.bg_led = t.bg_colour end
292         if t.fg_led ~= nil and #t.fg_led~=2     then t.fg_led = t.fg_colour end
293         if t.alarm_led~= nil and #t.alarm_led~=2 then t.alarm_led = t.fg_led end
294         if t.led_effect~=nil then
295                 if t.bg_led == nil then t.bg_led = t.bg_colour end
296                 if t.fg_led == nil      then t.fg_led = t.fg_colour end
297                 if t.alarm_led == nil  then t.alarm_led = t.fg_led end
298         end
299         if t.alarm==nil then t.alarm = t.max end --0.8*t.max end
300         if t.smooth == nil then t.smooth = false end
301         if t.skew_x == nil then 
302                 t.skew_x=0 
303         else
304                 t.skew_x = math.pi*t.skew_x/180 
305         end
306         if t.skew_y == nil then 
307                 t.skew_y=0
308         else
309                 t.skew_y = math.pi*t.skew_y/180 
310         end
311         if t.reflection_alpha==nil then t.reflection_alpha=0 end
312         if t.reflection_length==nil then t.reflection_length=1 end
313         if t.reflection_scale==nil then t.reflection_scale=1 end
314         --end of default values
315         
316         local function rgb_to_r_g_b(col_a)
317                 return ((col_a[1] / 0x10000) % 0x100) / 255., ((col_a[1] / 0x100) % 0x100) / 255., (col_a[1] % 0x100) / 255., col_a[2]
318         end
319         
320         --functions used to create patterns
321         local function create_smooth_linear_gradient(x0,y0,x1,y1)
322                 local pat = cairo_pattern_create_linear (x0,y0,x1,y1)
323                 cairo_pattern_add_color_stop_rgba (pat, 0, rgb_to_r_g_b(t.fg_colour))
324                 cairo_pattern_add_color_stop_rgba (pat, 1, rgb_to_r_g_b(t.alarm_colour))
325                 if t.mid_colour ~=nil then
326                         for i=1, #t.mid_colour do
327                                 cairo_pattern_add_color_stop_rgba (pat, t.mid_colour[i][1], rgb_to_r_g_b({t.mid_colour[i][2],t.mid_colour[i][3]}))
328                         end
329                 end
330                 return pat
331         end
332         
333         local function create_smooth_radial_gradient(x0,y0,r0,x1,y1,r1)
334                 local pat =  cairo_pattern_create_radial (x0,y0,r0,x1,y1,r1)
335                 cairo_pattern_add_color_stop_rgba (pat, 0, rgb_to_r_g_b(t.fg_colour))
336                 cairo_pattern_add_color_stop_rgba (pat, 1, rgb_to_r_g_b(t.alarm_colour))
337                 if t.mid_colour ~=nil then
338                         for i=1, #t.mid_colour do
339                                 cairo_pattern_add_color_stop_rgba (pat, t.mid_colour[i][1], rgb_to_r_g_b({t.mid_colour[i][2],t.mid_colour[i][3]}))
340                         end
341                 end
342                 return pat
343         end
344         
345         local function create_led_linear_gradient(x0,y0,x1,y1,col_alp,col_led)
346                 local pat = cairo_pattern_create_linear (x0,y0,x1,y1) ---delta, 0,delta+ t.width,0)
347                 cairo_pattern_add_color_stop_rgba (pat, 0.0, rgb_to_r_g_b(col_alp))
348                 cairo_pattern_add_color_stop_rgba (pat, 0.5, rgb_to_r_g_b(col_led))
349                 cairo_pattern_add_color_stop_rgba (pat, 1.0, rgb_to_r_g_b(col_alp))
350                 return pat
351         end
352
353         local function create_led_radial_gradient(x0,y0,r0,x1,y1,r1,col_alp,col_led,mode)
354                 local pat = cairo_pattern_create_radial (x0,y0,r0,x1,y1,r1)
355                 if mode==3 then
356                         cairo_pattern_add_color_stop_rgba (pat, 0, rgb_to_r_g_b(col_alp))                               
357                         cairo_pattern_add_color_stop_rgba (pat, 0.5, rgb_to_r_g_b(col_led))
358                         cairo_pattern_add_color_stop_rgba (pat, 1, rgb_to_r_g_b(col_alp))                               
359                 else
360                         cairo_pattern_add_color_stop_rgba (pat, 0, rgb_to_r_g_b(col_led))
361                         cairo_pattern_add_color_stop_rgba (pat, 1, rgb_to_r_g_b(col_alp))                               
362                 end
363                 return pat
364         end
365
366         local function draw_single_bar()
367                 --this fucntion is used for bars with a single block (blocks=1) but 
368                 --the drawing is cut in 3 blocks : value/alarm/background
369                 --not zvzimzblr for circular bar
370                 local function create_pattern(col_alp,col_led,bg)
371                         local pat
372                         if not t.smooth then
373                                 if t.led_effect=="e" then
374                                         pat = create_led_linear_gradient (-delta, 0,delta+ t.width,0,col_alp,col_led)
375                                 elseif t.led_effect=="a" then
376                                         pat = create_led_linear_gradient (t.width/2, 0,t.width/2,-t.height,col_alp,col_led)
377                                 elseif  t.led_effect=="r" then
378                                         pat = create_led_radial_gradient (t.width/2, -t.height/2, 0, t.width/2,-t.height/2,t.height/1.5,col_alp,col_led,2)
379                                 else
380                                         pat = cairo_pattern_create_rgba  (rgb_to_r_g_b(col_alp))
381                                 end
382                         else
383                                 if bg then
384                                         pat = cairo_pattern_create_rgba  (rgb_to_r_g_b(t.bg_colour))
385                                 else
386                                         pat = create_smooth_linear_gradient(t.width/2, 0, t.width/2,-t.height)
387                                 end
388                         end
389                         return pat
390                 end
391                 
392                 local y1=-t.height*pct/100
393                 local y2,y3=nil
394                 if pct>(100*t.alarm/t.max) then 
395                         y1 = -t.height*t.alarm/100
396                         y2 = -t.height*pct/100
397                         if t.smooth then y1=y2 end
398                 end
399                 
400                 if t.angle_bar==0 then
401                 
402                         --block for fg value
403                         local pat = create_pattern(t.fg_colour,t.fg_led,false)
404                         cairo_set_source(cr,pat)
405                         cairo_rectangle(cr,0,0,t.width,y1)
406                         cairo_fill(cr)
407                         cairo_pattern_destroy(pat)
408                         -- block for alarm value                        
409                         if not t.smooth and y2 ~=nil then 
410                                 pat = create_pattern(t.alarm_colour,t.alarm_led,false)
411                                 cairo_set_source(cr,pat)
412                                 cairo_rectangle(cr,0,y1,t.width,y2-y1)
413                                 cairo_fill(cr)
414                                 y3=y2
415                                 cairo_pattern_destroy(pat)
416                         else
417                                 y2,y3=y1,y1
418                         end
419                         -- block for bg value
420                         cairo_rectangle(cr,0,y2,t.width,-t.height-y3)
421                         pat = create_pattern(t.bg_colour,t.bg_led,true)
422                         cairo_set_source(cr,pat)
423                         cairo_pattern_destroy(pat)
424                         cairo_fill(cr)
425                 end             
426         end  --end single bar
427         
428         local function draw_multi_bar()
429                 --function used for bars with 2 or more blocks
430                 for pt = 1,t.blocks do 
431                         --set block y
432                         local y1 = -(pt-1)*(t.height+t.space)
433                         local light_on=false
434                         
435                         --set colors
436                         local col_alp = t.bg_colour
437                         local col_led = t.bg_led
438                         if pct>=(100/t.blocks) or pct>0 then --ligth on or not the block
439                                 if pct>=(pcb*(pt-1))  then 
440                                         light_on = true
441                                         col_alp = t.fg_colour
442                                         col_led = t.fg_led
443                                         if pct>=(100*t.alarm/t.max) and (pcb*pt)>(100*t.alarm/t.max) then 
444                                                 col_alp = t.alarm_colour 
445                                                 col_led = t.alarm_led 
446                                         end
447                                 end
448                         end
449
450                         --set colors
451                         --have to try to create gradients outside the loop ?
452                         local pat 
453                         if not t.smooth then
454                                 if t.angle_bar==0 then
455                                         if t.led_effect=="e" then
456                                                 pat = create_led_linear_gradient (-delta, 0,delta+ t.width,0,col_alp,col_led)
457                                         elseif t.led_effect=="a" then
458                                                 pat = create_led_linear_gradient (t.width/2, -t.height/2+y1,t.width/2,0+t.height/2+y1,col_alp,col_led)                                  
459                                         elseif  t.led_effect=="r" then
460                                                 pat = create_led_radial_gradient (t.width/2, y1, 0, t.width/2,y1,t.width/1.5,col_alp,col_led,2) 
461                                         else
462                                                 pat = cairo_pattern_create_rgba  (rgb_to_r_g_b(col_alp))
463                                         end
464                                 else
465                                          if t.led_effect=="a"  then
466                                                  pat = create_led_radial_gradient (0, 0, t.radius+(t.height+t.space)*(pt-1),
467                                                                                                                  0, 0, t.radius+(t.height+t.space)*(pt),                                                 
468                                                                                          col_alp,col_led,3)     
469                                         else
470                                                 pat = cairo_pattern_create_rgba  (rgb_to_r_g_b(col_alp))                                        
471                                         end
472                                 end
473                         else
474                                 if light_on then
475                                         if t.angle_bar==0 then
476                                                 pat = create_smooth_linear_gradient(t.width/2, t.height/2, t.width/2,-(t.blocks-0.5)*(t.height+t.space))
477                                         else
478                                                 pat = create_smooth_radial_gradient(0, 0, (t.height+t.space),  0,0,(t.blocks+1)*(t.height+t.space),2)
479                                         end
480                                 else            
481                                         pat = cairo_pattern_create_rgba  (rgb_to_r_g_b(t.bg_colour))
482                                 end
483                         end
484                         cairo_set_source (cr, pat)
485                         cairo_pattern_destroy(pat)
486
487                         --draw a block
488                         if t.angle_bar==0 then
489                                 cairo_move_to(cr,0,y1)
490                                 cairo_line_to(cr,t.width,y1)
491                         else            
492                                 cairo_arc( cr,0,0,
493                                         t.radius+(t.height+t.space)*(pt)-t.height/2,
494                                          -t.angle_bar -math.pi/2 ,
495                                          t.angle_bar -math.pi/2)
496                         end
497                         cairo_stroke(cr)
498                 end     
499         end
500         
501         local function setup_bar_graph()
502                 --function used to retrieve the value to display and to set the cairo structure
503                 if t.blocks ~=1 then t.y=t.y-t.height/2 end
504                 local value = 0
505                 if t.name ~="" then
506                         value = (conky_parse(string.format('${%s %s}', t.name, t.arg)))
507                         if string.match(value,"%w") then
508                                 value = conky_parse(string.format('${to_bytes %s}',value))
509                         end
510                         value=tonumber(value)
511                 else
512                         value = tonumber(t.arg)
513                 end
514                 if value==nil then value =0 end
515                 pct = 100*value/t.max
516                 pcb = 100/t.blocks
517                 cairo_set_line_width (cr, t.height)
518                 cairo_set_line_cap  (cr, cap)
519                 cairo_translate(cr,t.x,t.y)
520                 cairo_rotate(cr,t.angle)
521                 local matrix0 = cairo_matrix_t:create()
522                 tolua.takeownership(matrix0)
523                 cairo_matrix_init (matrix0, 1,t.skew_y,t.skew_x,1,0,0)
524                 cairo_transform(cr,matrix0)
525                 --call the drawing function for blocks
526                 if t.blocks==1 and t.angle_bar==0 then
527                         draw_single_bar()
528                         if t.reflection=="t" or t.reflection=="b" then cairo_translate(cr,0,-t.height) end
529                 else
530                         draw_multi_bar()
531                 end
532                 --call the drawing function for reflection and prepare the mask used            
533                 if t.reflection_alpha>0 and t.angle_bar==0 then
534                         local pat2
535                         local matrix1 = cairo_matrix_t:create()
536                         tolua.takeownership(matrix1)
537                         if t.angle_bar==0 then
538                                 pts={-delta/2,(t.height+t.space)/2,t.width+delta,-(t.height+t.space)*(t.blocks)}
539                                 if t.reflection=="t" then
540                                         cairo_matrix_init (matrix1,1,0,0,-t.reflection_scale,0,-(t.height+t.space)*(t.blocks-0.5)*2*(t.reflection_scale+1)/2)
541                                         pat2 = cairo_pattern_create_linear (t.width/2,-(t.height+t.space)*(t.blocks),t.width/2,(t.height+t.space)/2)
542                                 elseif t.reflection=="r" then
543                                         cairo_matrix_init (matrix1,-t.reflection_scale,0,0,1,delta+2*t.width,0)
544                                         pat2 = cairo_pattern_create_linear (delta/2+t.width,0,-delta/2,0)
545                                 elseif t.reflection=="l" then
546                                         cairo_matrix_init (matrix1,-t.reflection_scale,0,0,1,-delta,0)
547                                         pat2 = cairo_pattern_create_linear (-delta/2,0,delta/2+t.width,-0)
548                                 else --bottom
549                                         cairo_matrix_init (matrix1,1,0,0,-1*t.reflection_scale,0,(t.height+t.space)*(t.reflection_scale+1)/2)
550                                         pat2 = cairo_pattern_create_linear (t.width/2,(t.height+t.space)/2,t.width/2,-(t.height+t.space)*(t.blocks))
551                                 end
552                         end
553                         cairo_transform(cr,matrix1)
554                         if t.blocks==1 and t.angle_bar==0 then
555                                 draw_single_bar()
556                                 cairo_translate(cr,0,-t.height/2) 
557                         else
558                                 draw_multi_bar()
559                         end
560                         cairo_set_line_width(cr,0.01)
561                         cairo_pattern_add_color_stop_rgba (pat2, 0,0,0,0,1-t.reflection_alpha)
562                         cairo_pattern_add_color_stop_rgba (pat2, t.reflection_length,0,0,0,1)
563                         if t.angle_bar==0 then
564                                 cairo_rectangle(cr,pts[1],pts[2],pts[3],pts[4])
565                         end
566                         cairo_clip_preserve(cr)
567                         cairo_set_operator(cr,CAIRO_OPERATOR_CLEAR)
568                         cairo_stroke(cr)
569                         cairo_mask(cr,pat2)
570                         cairo_pattern_destroy(pat2)
571                         cairo_set_operator(cr,CAIRO_OPERATOR_OVER)
572                 end --reflection
573         pct,pcb=nil
574         end --setup_bar_graph()
575
576         --start here !
577         setup_bar_graph()
578         cairo_restore(cr)
579 end
580