Advertisement
hubutm20

bargraph.lua

Jun 11th, 2011
262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 22.68 KB | None | 0 0
  1. --[[ BARGRAPH WIDGET
  2. v2.1 by wlourf (07 Jan. 2011)
  3. this widget draws a bargraph with different effects
  4. http://u-scripts.blogspot.com/2010/07/bargraph-widget.html
  5.  
  6. To call the script in a conky, use, before TEXT
  7. lua_load /path/to/the/script/bargraph.lua
  8. lua_draw_hook_pre main_rings
  9. and add one line (blank or not) after TEXT
  10.  
  11.  
  12. Parameters are :
  13. 3 parameters are mandatory
  14. name - the name of the conky variable to display, for example for {$cpu cpu0}, just write name="cpu"
  15. arg - the argument of the above variable, for example for {$cpu cpu0}, just write arg="cpu0"
  16. arg can be a numerical value if name=""
  17. max - the maximum value the above variable can reach, for example, for {$cpu cpu0}, just write max=100
  18.  
  19. Optional parameters:
  20. x,y - coordinates of the starting point of the bar, default = middle of the conky window
  21. cap - end of cap line, ossibles values are r,b,s (for round, butt, square), default="b"
  22. http://www.cairographics.org/samples/set_line_cap/
  23. angle - angle of rotation of the bar in degress, default = 0 (i.e. a vertical bar)
  24. set to 90 for an horizontal bar
  25. skew_x - skew bar around x axis, default = 0
  26. skew_y - skew bar around y axis, default = 0
  27. blocks - number of blocks to display for a bar (values >0) , default= 10
  28. height - height of a block, default=10 pixels
  29. width - width of a block, default=20 pixels
  30. space - space between 2 blocks, default=2 pixels
  31. angle_bar - this angle is used to draw a bar on a circular way (ok, this is no more a bar !) default=0
  32. radius - for cicular bars, internal radius, default=0
  33. with radius, parameter width has no more effect.
  34.  
  35. Colours below are defined into braces {colour in hexadecimal, alpha}
  36. fg_colour - colour of a block ON, default= {0x00FF00,1}
  37. bg_colour - colour of a block OFF, default = {0x00FF00,0.5}
  38. alarm - threshold, values after this threshold will use alarm_colour colour , default=max
  39. alarm_colour - colour of a block greater than alarm, default=fg_colour
  40. smooth - (true or false), create a gradient from fg_colour to bg_colour, default=false
  41. mid_colour - colours to add to gradient, with this syntax {position into the gradient (0 to1), colour hexa, alpha}
  42. for example, this table {{0.25,0xff0000,1},{0.5,0x00ff00,1},{0.75,0x0000ff,1}} will add
  43. 3 colurs to gradient created by fg_colour and alarm_colour, default=no mid_colour
  44. led_effect - add LED effects to each block, default=no led_effect
  45. if smooth=true, led_effect is not used
  46. possibles values : "r","a","e" for radial, parallelel, perdendicular to the bar (just try!)
  47. led_effect has to be used with theses colours :
  48. fg_led - middle colour of a block ON, default = fg_colour
  49. bg_led - middle colour of a block OFF, default = bg_colour
  50. alarm_led - middle colour of a block > ALARM, default = alarm_colour
  51.  
  52. reflection parameters, not avaimable for circular bars
  53. reflection_alpha - add a reflection effect (values from 0 to 1) default = 0 = no reflection
  54. other values = starting opacity
  55. reflection_scale - scale of the reflection (default = 1 = height of text)
  56. reflection_length - length of reflection, define where the opacity will be set to zero
  57. calues from 0 to 1, default =1
  58. reflection - position of reflection, relative to a vertical bar, default="b"
  59. possibles values are : "b","t","l","r" for bottom, top, left, right
  60. draw_me - if set to false, text is not drawn (default = true or 1)
  61. it can be used with a conky string, if the string returns 1, the text is drawn :
  62. example : "${if_empty ${wireless_essid wlan0}}${else}1$endif",
  63.  
  64. v1.0 (10 Feb. 2010) original release
  65. v1.1 (13 Feb. 2010) numeric values can be passed instead conky stats with parameters name="", arg = numeric_value
  66. v1.2 (28 Feb. 2010) just renamed the widget to bargraph
  67. v1.3 (03 Mar. 2010) added parameters radius & angle_bar to draw the bar in a circular way
  68. v2.0 (12 Jul. 2010) rewrite script + add reflection effects and parameters are now set into tables
  69. v2.1 (07 Jan. 2011) Add draw_me parameter and correct memory leaks, thanks to "Creamy Goodness"
  70.  
  71. -- This program is free software; you can redistribute it and/or modify
  72. -- it under the terms of the GNU General Public License as published by
  73. -- the Free Software Foundation version 3 (GPLv3)
  74. --
  75. -- This program is distributed in the hope that it will be useful,
  76. -- but WITHOUT ANY WARRANTY; without even the implied warranty of
  77. -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  78. -- GNU General Public License for more details.
  79. --
  80. -- You should have received a copy of the GNU General Public License
  81. -- along with this program; if not, write to the Free Software
  82. -- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  83. -- MA 02110-1301, USA.
  84.  
  85. ]]
  86.  
  87. require 'cairo'
  88.  
  89. ----------------START OF PARAMETERS ----------
  90. function conky_main_bars()
  91. local bars_settings={
  92. { --[ Graph for CPU1 ]--
  93. name="cpu",
  94. arg="cpu1",
  95. max=100,
  96. alarm=50,
  97. alarm_colour={0xFF0000,0.72},
  98. bg_colour={0xFFFFFF,0.25},
  99. fg_colour={0x00FF00,0.55},
  100. mid_colour={{0.45,0xFFFF00,0.70}},
  101. x=6,y=156,
  102. blocks=73,
  103. space=1,
  104. height=2,width=5,
  105. angle=90,
  106. smooth=true
  107. },
  108. { --[ Graph for Memory ]--
  109. name="memperc",
  110. arg="",
  111. max=100,
  112. alarm=50,
  113. alarm_colour={0xFF0000,0.72},
  114. bg_colour={0xFFFFFF,0.25},
  115. fg_colour={0x00FF00,0.55},
  116. mid_colour={{0.45,0xFFFF00,0.70}},
  117. x=6,y=217,
  118. blocks=73,
  119. space=1,
  120. height=2,width=5,
  121. angle=90,
  122. smooth=true
  123. },
  124. { --[ Graph for Swap ]--
  125. name="swapperc",
  126. arg="",
  127. max=100,
  128. alarm=50,
  129. alarm_colour={0xFF0000,0.72},
  130. bg_colour={0xFFFFFF,0.25},
  131. fg_colour={0x00FF00,0.55},
  132. mid_colour={{0.45,0xFFFF00,0.70}},
  133. x=6,y=241,
  134. blocks=73,
  135. space=1,
  136. height=2,width=5,
  137. angle=90,
  138. smooth=true
  139. },
  140. { --[ Graph for Root ]--
  141. name="fs_used_perc",
  142. arg="/",
  143. max=100,
  144. alarm=50,
  145. alarm_colour={0xFF0000,0.72},
  146. bg_colour={0xFFFFFF,0.25},
  147. fg_colour={0x00FF00,0.55},
  148. mid_colour={{0.45,0xFFFF00,0.70}},
  149. x=6,y=398,
  150. blocks=73,
  151. space=1,
  152. height=2,width=5,
  153. angle=90,
  154. smooth=true
  155. },
  156. { --[ Graph for Home ]--
  157. name="fs_used_perc",
  158. arg="/home",
  159. max=100,
  160. alarm=50,
  161. alarm_colour={0xFF0000,0.72},
  162. bg_colour={0xFFFFFF,0.25},
  163. fg_colour={0x00FF00,0.55},
  164. mid_colour={{0.45,0xFFFF00,0.70}},
  165. x=6,y=422,
  166. blocks=73,
  167. space=1,
  168. height=2,width=5,
  169. angle=90,
  170. smooth=true
  171. },
  172. { --[ Graph for Swap ]--
  173. name="fs_used_perc",
  174. arg="/media/Hdd 1",
  175. max=100,
  176. alarm=50,
  177. alarm_colour={0xFF0000,0.72},
  178. bg_colour={0xFFFFFF,0.25},
  179. fg_colour={0x00FF00,0.55},
  180. mid_colour={{0.45,0xFFFF00,0.70}},
  181. x=6,y=446,
  182. blocks=73,
  183. space=1,
  184. height=2,width=5,
  185. angle=90,
  186. smooth=true
  187. },
  188. { --[ Graph for Swap ]--
  189. name="fs_used_perc",
  190. arg="/media/Hdd 2",
  191. max=100,
  192. alarm=50,
  193. alarm_colour={0xFF0000,0.72},
  194. bg_colour={0xFFFFFF,0.25},
  195. fg_colour={0x00FF00,0.55},
  196. mid_colour={{0.45,0xFFFF00,0.70}},
  197. x=6,y=470,
  198. blocks=73,
  199. space=1,
  200. height=2,width=5,
  201. angle=90,
  202. smooth=true
  203. },
  204. { --[ Graph for Swap ]--
  205. name="fs_used_perc",
  206. arg="/media/Hdd 3",
  207. max=100,
  208. alarm=50,
  209. alarm_colour={0xFF0000,0.72},
  210. bg_colour={0xFFFFFF,0.25},
  211. fg_colour={0x00FF00,0.55},
  212. mid_colour={{0.45,0xFFFF00,0.70}},
  213. x=6,y=494,
  214. blocks=73,
  215. space=1,
  216. height=2,width=5,
  217. angle=90,
  218. smooth=true
  219. },
  220. { --[ Graph for Swap ]--
  221. name="fs_used_perc",
  222. arg="/media/Hdd4",
  223. max=100,
  224. alarm=50,
  225. alarm_colour={0xFF0000,0.72},
  226. bg_colour={0xFFFFFF,0.25},
  227. fg_colour={0x00FF00,0.55},
  228. mid_colour={{0.45,0xFFFF00,0.70}},
  229. x=6,y=518,
  230. blocks=73,
  231. space=1,
  232. height=2,width=5,
  233. angle=90,
  234. smooth=true
  235. },
  236. }
  237. -----------END OF PARAMETERS--------------
  238.  
  239.  
  240.  
  241. if conky_window == nil then return end
  242.  
  243. local cs = cairo_xlib_surface_create(conky_window.display, conky_window.drawable, conky_window.visual, conky_window.width, conky_window.height)
  244.  
  245. cr = cairo_create(cs)
  246. --prevent segmentation error when reading cpu state
  247. if tonumber(conky_parse('${updates}'))>3 then
  248. for i in pairs(bars_settings) do
  249.  
  250. draw_multi_bar_graph(bars_settings[i])
  251.  
  252. end
  253. end
  254. cairo_destroy(cr)
  255. cairo_surface_destroy(cs)
  256. cr=nil
  257.  
  258. end
  259.  
  260.  
  261.  
  262. function draw_multi_bar_graph(t)
  263. cairo_save(cr)
  264. --check values
  265. if t.draw_me == true then t.draw_me = nil end
  266. if t.draw_me ~= nil and conky_parse(tostring(t.draw_me)) ~= "1" then return end
  267. if t.name==nil and t.arg==nil then
  268. print ("No input values ... use parameters 'name' with 'arg' or only parameter 'arg' ")
  269. return
  270. end
  271. if t.max==nil then
  272. print ("No maximum value defined, use 'max'")
  273. return
  274. end
  275. if t.name==nil then t.name="" end
  276. if t.arg==nil then t.arg="" end
  277.  
  278. --set default values
  279. if t.x == nil then t.x = conky_window.width/2 end
  280. if t.y == nil then t.y = conky_window.height/2 end
  281. if t.blocks == nil then t.blocks=10 end
  282. if t.height == nil then t.height=10 end
  283. if t.angle == nil then t.angle=0 end
  284. t.angle = t.angle*math.pi/180
  285. --line cap style
  286. if t.cap==nil then t.cap = "b" end
  287. local cap="b"
  288. for i,v in ipairs({"s","r","b"}) do
  289. if v==t.cap then cap=v end
  290. end
  291. local delta=0
  292. if t.cap=="r" or t.cap=="s" then delta = t.height end
  293. if cap=="s" then cap = CAIRO_LINE_CAP_SQUARE
  294. elseif cap=="r" then
  295. cap = CAIRO_LINE_CAP_ROUND
  296. elseif cap=="b" then
  297. cap = CAIRO_LINE_CAP_BUTT
  298. end
  299. --end line cap style
  300. --if t.led_effect == nil then t.led_effect="r" end
  301. if t.width == nil then t.width=20 end
  302. if t.space == nil then t.space=2 end
  303. if t.radius == nil then t.radius=0 end
  304. if t.angle_bar == nil then t.angle_bar=0 end
  305. t.angle_bar = t.angle_bar*math.pi/360 --halt angle
  306.  
  307. --colours
  308. if t.bg_colour == nil then t.bg_colour = {0x00FF00,0.5} end
  309. if #t.bg_colour~=2 then t.bg_colour = {0x00FF00,0.5} end
  310. if t.fg_colour == nil then t.fg_colour = {0x00FF00,1} end
  311. if #t.fg_colour~=2 then t.fg_colour = {0x00FF00,1} end
  312. if t.alarm_colour == nil then t.alarm_colour = t.fg_colour end
  313. if #t.alarm_colour~=2 then t.alarm_colour = t.fg_colour end
  314.  
  315. if t.mid_colour ~= nil then
  316. for i=1, #t.mid_colour do
  317. if #t.mid_colour[i]~=3 then
  318. print ("error in mid_color table")
  319. t.mid_colour[i]={1,0xFFFFFF,1}
  320. end
  321. end
  322. end
  323.  
  324. if t.bg_led ~= nil and #t.bg_led~=2 then t.bg_led = t.bg_colour end
  325. if t.fg_led ~= nil and #t.fg_led~=2 then t.fg_led = t.fg_colour end
  326. if t.alarm_led~= nil and #t.alarm_led~=2 then t.alarm_led = t.fg_led end
  327.  
  328. if t.led_effect~=nil then
  329. if t.bg_led == nil then t.bg_led = t.bg_colour end
  330. if t.fg_led == nil then t.fg_led = t.fg_colour end
  331. if t.alarm_led == nil then t.alarm_led = t.fg_led end
  332. end
  333.  
  334.  
  335. if t.alarm==nil then t.alarm = t.max end --0.8*t.max end
  336. if t.smooth == nil then t.smooth = false end
  337.  
  338. if t.skew_x == nil then
  339. t.skew_x=0
  340. else
  341. t.skew_x = math.pi*t.skew_x/180
  342. end
  343. if t.skew_y == nil then
  344. t.skew_y=0
  345. else
  346. t.skew_y = math.pi*t.skew_y/180
  347. end
  348.  
  349. if t.reflection_alpha==nil then t.reflection_alpha=0 end
  350. if t.reflection_length==nil then t.reflection_length=1 end
  351. if t.reflection_scale==nil then t.reflection_scale=1 end
  352.  
  353. --end of default values
  354.  
  355.  
  356. local function rgb_to_r_g_b(col_a)
  357. return ((col_a[1] / 0x10000) % 0x100) / 255., ((col_a[1] / 0x100) % 0x100) / 255., (col_a[1] % 0x100) / 255., col_a[2]
  358. end
  359.  
  360.  
  361. --functions used to create patterns
  362.  
  363. local function create_smooth_linear_gradient(x0,y0,x1,y1)
  364. local pat = cairo_pattern_create_linear (x0,y0,x1,y1)
  365. cairo_pattern_add_color_stop_rgba (pat, 0, rgb_to_r_g_b(t.fg_colour))
  366. cairo_pattern_add_color_stop_rgba (pat, 1, rgb_to_r_g_b(t.alarm_colour))
  367. if t.mid_colour ~=nil then
  368. for i=1, #t.mid_colour do
  369. 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]}))
  370. end
  371. end
  372. return pat
  373. end
  374.  
  375. local function create_smooth_radial_gradient(x0,y0,r0,x1,y1,r1)
  376. local pat = cairo_pattern_create_radial (x0,y0,r0,x1,y1,r1)
  377. cairo_pattern_add_color_stop_rgba (pat, 0, rgb_to_r_g_b(t.fg_colour))
  378. cairo_pattern_add_color_stop_rgba (pat, 1, rgb_to_r_g_b(t.alarm_colour))
  379. if t.mid_colour ~=nil then
  380. for i=1, #t.mid_colour do
  381. 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]}))
  382. end
  383. end
  384. return pat
  385. end
  386.  
  387. local function create_led_linear_gradient(x0,y0,x1,y1,col_alp,col_led)
  388. local pat = cairo_pattern_create_linear (x0,y0,x1,y1) ---delta, 0,delta+ t.width,0)
  389. cairo_pattern_add_color_stop_rgba (pat, 0.0, rgb_to_r_g_b(col_alp))
  390. cairo_pattern_add_color_stop_rgba (pat, 0.5, rgb_to_r_g_b(col_led))
  391. cairo_pattern_add_color_stop_rgba (pat, 1.0, rgb_to_r_g_b(col_alp))
  392. return pat
  393. end
  394.  
  395. local function create_led_radial_gradient(x0,y0,r0,x1,y1,r1,col_alp,col_led,mode)
  396. local pat = cairo_pattern_create_radial (x0,y0,r0,x1,y1,r1)
  397. if mode==3 then
  398. cairo_pattern_add_color_stop_rgba (pat, 0, rgb_to_r_g_b(col_alp))
  399. cairo_pattern_add_color_stop_rgba (pat, 0.5, rgb_to_r_g_b(col_led))
  400. cairo_pattern_add_color_stop_rgba (pat, 1, rgb_to_r_g_b(col_alp))
  401. else
  402. cairo_pattern_add_color_stop_rgba (pat, 0, rgb_to_r_g_b(col_led))
  403. cairo_pattern_add_color_stop_rgba (pat, 1, rgb_to_r_g_b(col_alp))
  404. end
  405. return pat
  406. end
  407.  
  408.  
  409.  
  410.  
  411.  
  412.  
  413. local function draw_single_bar()
  414. --this fucntion is used for bars with a single block (blocks=1) but
  415. --the drawing is cut in 3 blocks : value/alarm/background
  416. --not zvzimzblr for circular bar
  417. local function create_pattern(col_alp,col_led,bg)
  418. local pat
  419.  
  420. if not t.smooth then
  421. if t.led_effect=="e" then
  422. pat = create_led_linear_gradient (-delta, 0,delta+ t.width,0,col_alp,col_led)
  423. elseif t.led_effect=="a" then
  424. pat = create_led_linear_gradient (t.width/2, 0,t.width/2,-t.height,col_alp,col_led)
  425. elseif t.led_effect=="r" then
  426. 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)
  427. else
  428. pat = cairo_pattern_create_rgba (rgb_to_r_g_b(col_alp))
  429. end
  430. else
  431. if bg then
  432. pat = cairo_pattern_create_rgba (rgb_to_r_g_b(t.bg_colour))
  433. else
  434. pat = create_smooth_linear_gradient(t.width/2, 0, t.width/2,-t.height)
  435. end
  436. end
  437. return pat
  438. end
  439.  
  440. local y1=-t.height*pct/100
  441. local y2,y3
  442. if pct>(100*t.alarm/t.max) then
  443. y1 = -t.height*t.alarm/100
  444. y2 = -t.height*pct/100
  445. if t.smooth then y1=y2 end
  446. end
  447.  
  448. if t.angle_bar==0 then
  449.  
  450. --block for fg value
  451. local pat = create_pattern(t.fg_colour,t.fg_led,false)
  452. cairo_set_source(cr,pat)
  453. cairo_rectangle(cr,0,0,t.width,y1)
  454. cairo_fill(cr)
  455. cairo_pattern_destroy(pat)
  456.  
  457. -- block for alarm value
  458. if not t.smooth and y2 ~=nil then
  459. pat = create_pattern(t.alarm_colour,t.alarm_led,false)
  460. cairo_set_source(cr,pat)
  461. cairo_rectangle(cr,0,y1,t.width,y2-y1)
  462. cairo_fill(cr)
  463. y3=y2
  464. cairo_pattern_destroy(pat)
  465. else
  466. y2,y3=y1,y1
  467. end
  468. -- block for bg value
  469. cairo_rectangle(cr,0,y2,t.width,-t.height-y3)
  470. pat = create_pattern(t.bg_colour,t.bg_led,true)
  471. cairo_set_source(cr,pat)
  472. cairo_pattern_destroy(pat)
  473. cairo_fill(cr)
  474. end
  475. end --end single bar
  476.  
  477.  
  478.  
  479.  
  480.  
  481.  
  482. local function draw_multi_bar()
  483. --function used for bars with 2 or more blocks
  484. for pt = 1,t.blocks do
  485. --set block y
  486. local y1 = -(pt-1)*(t.height+t.space)
  487. local light_on=false
  488.  
  489. --set colors
  490. local col_alp = t.bg_colour
  491. local col_led = t.bg_led
  492. if pct>=(100/t.blocks) or pct>0 then --ligth on or not the block
  493. if pct>=(pcb*(pt-1)) then
  494. light_on = true
  495. col_alp = t.fg_colour
  496. col_led = t.fg_led
  497. if pct>=(100*t.alarm/t.max) and (pcb*pt)>(100*t.alarm/t.max) then
  498. col_alp = t.alarm_colour
  499. col_led = t.alarm_led
  500. end
  501. end
  502. end
  503.  
  504. --set colors
  505. --have to try to create gradients outside the loop ?
  506. local pat
  507.  
  508. if not t.smooth then
  509. if t.angle_bar==0 then
  510. if t.led_effect=="e" then
  511. pat = create_led_linear_gradient (-delta, 0,delta+ t.width,0,col_alp,col_led)
  512. elseif t.led_effect=="a" then
  513. pat = create_led_linear_gradient (t.width/2, -t.height/2+y1,t.width/2,0+t.height/2+y1,col_alp,col_led)
  514. elseif t.led_effect=="r" then
  515. pat = create_led_radial_gradient (t.width/2, y1, 0, t.width/2,y1,t.width/1.5,col_alp,col_led,2)
  516. else
  517. pat = cairo_pattern_create_rgba (rgb_to_r_g_b(col_alp))
  518. end
  519. else
  520. if t.led_effect=="a" then
  521. pat = create_led_radial_gradient (0, 0, t.radius+(t.height+t.space)*(pt-1),
  522. 0, 0, t.radius+(t.height+t.space)*(pt),
  523. col_alp,col_led,3)
  524. else
  525. pat = cairo_pattern_create_rgba (rgb_to_r_g_b(col_alp))
  526. end
  527.  
  528. end
  529. else
  530.  
  531. if light_on then
  532. if t.angle_bar==0 then
  533. pat = create_smooth_linear_gradient(t.width/2, t.height/2, t.width/2,-(t.blocks-0.5)*(t.height+t.space))
  534. else
  535. pat = create_smooth_radial_gradient(0, 0, (t.height+t.space), 0,0,(t.blocks+1)*(t.height+t.space),2)
  536. end
  537. else
  538. pat = cairo_pattern_create_rgba (rgb_to_r_g_b(t.bg_colour))
  539. end
  540. end
  541. cairo_set_source (cr, pat)
  542. cairo_pattern_destroy(pat)
  543.  
  544. --draw a block
  545. if t.angle_bar==0 then
  546. cairo_move_to(cr,0,y1)
  547. cairo_line_to(cr,t.width,y1)
  548. else
  549. cairo_arc( cr,0,0,
  550. t.radius+(t.height+t.space)*(pt)-t.height/2,
  551. -t.angle_bar -math.pi/2 ,
  552. t.angle_bar -math.pi/2)
  553. end
  554. cairo_stroke(cr)
  555. end
  556. end
  557.  
  558.  
  559.  
  560.  
  561. local function setup_bar_graph()
  562. --function used to retrieve the value to display and to set the cairo structure
  563. if t.blocks ~=1 then t.y=t.y-t.height/2 end
  564.  
  565. local value = 0
  566. if t.name ~="" then
  567. value = tonumber(conky_parse(string.format('${%s %s}', t.name, t.arg)))
  568. --$to_bytes doesn't work when value has a decimal point,
  569. --https://garage.maemo.org/plugins/ggit/browse.php/?p=monky;a=commitdiff;h=174c256c81a027a2ea406f5f37dc036fac0a524b;hp=d75e2db5ed3fc788fb8514121f67316ac3e5f29f
  570. --http://sourceforge.net/tracker/index.php?func=detail&aid=3000865&group_id=143975&atid=757310
  571. --conky bug?
  572. --value = (conky_parse(string.format('${%s %s}', t.name, t.arg)))
  573. --if string.match(value,"%w") then
  574. -- value = conky_parse(string.format('${to_bytes %s}',value))
  575. --end
  576. else
  577. value = tonumber(t.arg)
  578. end
  579.  
  580. if value==nil then value =0 end
  581.  
  582. pct = 100*value/t.max
  583. pcb = 100/t.blocks
  584.  
  585. cairo_set_line_width (cr, t.height)
  586. cairo_set_line_cap (cr, cap)
  587. cairo_translate(cr,t.x,t.y)
  588. cairo_rotate(cr,t.angle)
  589.  
  590. local matrix0 = cairo_matrix_t:create()
  591. tolua.takeownership(matrix0)
  592. cairo_matrix_init (matrix0, 1,t.skew_y,t.skew_x,1,0,0)
  593. cairo_transform(cr,matrix0)
  594.  
  595.  
  596.  
  597. --call the drawing function for blocks
  598. if t.blocks==1 and t.angle_bar==0 then
  599. draw_single_bar()
  600. if t.reflection=="t" or t.reflection=="b" then cairo_translate(cr,0,-t.height) end
  601. else
  602. draw_multi_bar()
  603. end
  604.  
  605. --dot for reminder
  606. --[[
  607. if t.blocks ~=1 then
  608. cairo_set_source_rgba(cr,1,0,0,1)
  609. cairo_arc(cr,0,t.height/2,3,0,2*math.pi)
  610. cairo_fill(cr)
  611. else
  612. cairo_set_source_rgba(cr,1,0,0,1)
  613. cairo_arc(cr,0,0,3,0,2*math.pi)
  614. cairo_fill(cr)
  615. end]]
  616.  
  617. --call the drawing function for reflection and prepare the mask used
  618. if t.reflection_alpha>0 and t.angle_bar==0 then
  619. local pat2
  620. local matrix1 = cairo_matrix_t:create()
  621. tolua.takeownership(matrix1)
  622. if t.angle_bar==0 then
  623. pts={-delta/2,(t.height+t.space)/2,t.width+delta,-(t.height+t.space)*(t.blocks)}
  624. if t.reflection=="t" then
  625. 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)
  626. pat2 = cairo_pattern_create_linear (t.width/2,-(t.height+t.space)*(t.blocks),t.width/2,(t.height+t.space)/2)
  627. elseif t.reflection=="r" then
  628. cairo_matrix_init (matrix1,-t.reflection_scale,0,0,1,delta+2*t.width,0)
  629. pat2 = cairo_pattern_create_linear (delta/2+t.width,0,-delta/2,0)
  630. elseif t.reflection=="l" then
  631. cairo_matrix_init (matrix1,-t.reflection_scale,0,0,1,-delta,0)
  632. pat2 = cairo_pattern_create_linear (-delta/2,0,delta/2+t.width,-0)
  633. else --bottom
  634. cairo_matrix_init (matrix1,1,0,0,-1*t.reflection_scale,0,(t.height+t.space)*(t.reflection_scale+1)/2)
  635. pat2 = cairo_pattern_create_linear (t.width/2,(t.height+t.space)/2,t.width/2,-(t.height+t.space)*(t.blocks))
  636. end
  637. end
  638. cairo_transform(cr,matrix1)
  639.  
  640. if t.blocks==1 and t.angle_bar==0 then
  641. draw_single_bar()
  642. cairo_translate(cr,0,-t.height/2)
  643. else
  644. draw_multi_bar()
  645. end
  646.  
  647.  
  648. cairo_set_line_width(cr,0.01)
  649. cairo_pattern_add_color_stop_rgba (pat2, 0,0,0,0,1-t.reflection_alpha)
  650. cairo_pattern_add_color_stop_rgba (pat2, t.reflection_length,0,0,0,1)
  651. if t.angle_bar==0 then
  652. cairo_rectangle(cr,pts[1],pts[2],pts[3],pts[4])
  653. end
  654. cairo_clip_preserve(cr)
  655. cairo_set_operator(cr,CAIRO_OPERATOR_CLEAR)
  656. cairo_stroke(cr)
  657. cairo_mask(cr,pat2)
  658. cairo_pattern_destroy(pat2)
  659. cairo_set_operator(cr,CAIRO_OPERATOR_OVER)
  660.  
  661. end --reflection
  662. pct,pcb=nil
  663. end --setup_bar_graph()
  664.  
  665. --start here !
  666. setup_bar_graph()
  667. cairo_restore(cr)
  668. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement