Advertisement
Guest User

bar.lua

a guest
Mar 3rd, 2023
308
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 19.06 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.         {
  93.             name="fs_used_perc",
  94.             arg="/",
  95.             max=100,
  96.             bg_colour={0x2b2b2b,0.25},
  97.             fg_colour={0xe82127,0.5},
  98.             x=26,y=504,
  99.             blocks=1,
  100.             height=109,width=84,
  101.             draw_me=true,
  102.         },
  103.         {
  104.             name="fs_used_perc",
  105.             arg="/home",
  106.             max=100,
  107.             bg_colour={0x2b2b2b,0.25},
  108.             fg_colour={0xe82127,0.5},
  109.             x=136,y=504,
  110.             blocks=1,
  111.             height=109,width=84,
  112.             draw_me=true,
  113.         },
  114.         {
  115.             name="fs_used_perc",
  116.             arg="/media/fpp/Datos",
  117.             max=100,
  118.             bg_colour={0x2b2b2b,0.25},
  119.             fg_colour={0xe82127,0.5},
  120.             x=236,y=504,
  121.             blocks=1,
  122.             height=109,width=84,
  123.             draw_me=true,
  124.         },
  125.     }
  126.    
  127. -----------END OF PARAMETERS--------------
  128.  
  129.  
  130.    
  131.     if conky_window == nil then return end
  132.    
  133.     local cs = cairo_xlib_surface_create(conky_window.display, conky_window.drawable, conky_window.visual, conky_window.width, conky_window.height)
  134.    
  135.     cr = cairo_create(cs)    
  136.     --prevent segmentation error when reading cpu state
  137.     if tonumber(conky_parse('${updates}'))>3 then
  138.         for i in pairs(bars_settings) do
  139.            
  140.             draw_multi_bar_graph(bars_settings[i])
  141.            
  142.         end
  143.     end
  144.     cairo_destroy(cr)
  145.     cairo_surface_destroy(cs)
  146.     cr=nil
  147.  
  148. end
  149.  
  150.  
  151.  
  152. function draw_multi_bar_graph(t)
  153.     cairo_save(cr)
  154.     --check values
  155.     if t.draw_me == true then t.draw_me = nil end
  156.     if t.draw_me ~= nil and conky_parse(tostring(t.draw_me)) ~= "1" then return end
  157.     if t.name==nil and t.arg==nil then
  158.         print ("No input values ... use parameters 'name' with 'arg' or only parameter 'arg' ")
  159.         return
  160.     end
  161.     if t.max==nil then
  162.         print ("No maximum value defined, use 'max'")
  163.         return
  164.     end
  165.     if t.name==nil then t.name="" end
  166.     if t.arg==nil then t.arg="" end
  167.  
  168.     --set default values   
  169.     if t.x == nil       then t.x = conky_window.width/2 end
  170.     if t.y == nil       then t.y = conky_window.height/2 end
  171.     if t.blocks == nil  then t.blocks=10 end
  172.     if t.height == nil  then t.height=10 end
  173.     if t.angle == nil   then t.angle=0 end
  174.     t.angle = t.angle*math.pi/180
  175.     --line cap style
  176.     if t.cap==nil       then t.cap = "b" end
  177.     local cap="b"
  178.     for i,v in ipairs({"s","r","b"}) do
  179.         if v==t.cap then cap=v end
  180.     end
  181.     local delta=0
  182.     if t.cap=="r" or t.cap=="s" then delta = t.height end
  183.     if cap=="s" then    cap = CAIRO_LINE_CAP_SQUARE
  184.     elseif cap=="r" then
  185.         cap = CAIRO_LINE_CAP_ROUND
  186.     elseif cap=="b" then
  187.         cap = CAIRO_LINE_CAP_BUTT
  188.     end
  189.     --end line cap style
  190.     --if t.led_effect == nil    then t.led_effect="r" end
  191.     if t.width == nil   then t.width=20 end
  192.     if t.space == nil   then t.space=2 end
  193.     if t.radius == nil  then t.radius=0 end
  194.     if t.angle_bar == nil   then t.angle_bar=0 end
  195.     t.angle_bar = t.angle_bar*math.pi/360 --halt angle
  196.    
  197.     --colours
  198.     if t.bg_colour == nil   then t.bg_colour = {0x00FF00,0.5} end
  199.     if #t.bg_colour~=2      then t.bg_colour = {0x00FF00,0.5} end
  200.     if t.fg_colour == nil   then t.fg_colour = {0x00FF00,1} end
  201.     if #t.fg_colour~=2      then t.fg_colour = {0x00FF00,1} end
  202.     if t.alarm_colour == nil    then t.alarm_colour = t.fg_colour end
  203.     if #t.alarm_colour~=2       then t.alarm_colour = t.fg_colour end
  204.  
  205.     if t.mid_colour ~= nil then
  206.         for i=1, #t.mid_colour do    
  207.             if #t.mid_colour[i]~=3 then
  208.                 print ("error in mid_color table")
  209.                 t.mid_colour[i]={1,0xFFFFFF,1}
  210.             end
  211.         end
  212.     end
  213.    
  214.     if t.bg_led ~= nil and #t.bg_led~=2 then t.bg_led = t.bg_colour end
  215.     if t.fg_led ~= nil and #t.fg_led~=2 then t.fg_led = t.fg_colour end
  216.     if t.alarm_led~= nil and #t.alarm_led~=2 then t.alarm_led = t.fg_led end
  217.    
  218.     if t.led_effect~=nil then
  219.         if t.bg_led == nil then t.bg_led = t.bg_colour end
  220.         if t.fg_led == nil  then t.fg_led = t.fg_colour end
  221.         if t.alarm_led == nil  then t.alarm_led = t.fg_led end
  222.     end
  223.    
  224.  
  225.     if t.alarm==nil then t.alarm = t.max end --0.8*t.max end
  226.     if t.smooth == nil then t.smooth = false end
  227.  
  228.     if t.skew_x == nil then
  229.         t.skew_x=0
  230.     else
  231.         t.skew_x = math.pi*t.skew_x/180
  232.     end
  233.     if t.skew_y == nil then
  234.         t.skew_y=0
  235.     else
  236.         t.skew_y = math.pi*t.skew_y/180
  237.     end
  238.    
  239.     if t.reflection_alpha==nil then t.reflection_alpha=0 end
  240.     if t.reflection_length==nil then t.reflection_length=1 end
  241.     if t.reflection_scale==nil then t.reflection_scale=1 end
  242.    
  243.     --end of default values
  244.    
  245.  
  246.     local function rgb_to_r_g_b(col_a)
  247.         return ((col_a[1] / 0x10000) % 0x100) / 255., ((col_a[1] / 0x100) % 0x100) / 255., (col_a[1] % 0x100) / 255., col_a[2]
  248.     end
  249.    
  250.    
  251.     --functions used to create patterns
  252.  
  253.     local function create_smooth_linear_gradient(x0,y0,x1,y1)
  254.         local pat = cairo_pattern_create_linear (x0,y0,x1,y1)
  255.         cairo_pattern_add_color_stop_rgba (pat, 0, rgb_to_r_g_b(t.fg_colour))
  256.         cairo_pattern_add_color_stop_rgba (pat, 1, rgb_to_r_g_b(t.alarm_colour))
  257.         if t.mid_colour ~=nil then
  258.             for i=1, #t.mid_colour do
  259.                 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]}))
  260.             end
  261.         end
  262.         return pat
  263.     end
  264.  
  265.     local function create_smooth_radial_gradient(x0,y0,r0,x1,y1,r1)
  266.         local pat =  cairo_pattern_create_radial (x0,y0,r0,x1,y1,r1)
  267.         cairo_pattern_add_color_stop_rgba (pat, 0, rgb_to_r_g_b(t.fg_colour))
  268.         cairo_pattern_add_color_stop_rgba (pat, 1, rgb_to_r_g_b(t.alarm_colour))
  269.         if t.mid_colour ~=nil then
  270.             for i=1, #t.mid_colour do
  271.                 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]}))
  272.             end
  273.         end
  274.         return pat
  275.     end
  276.    
  277.     local function create_led_linear_gradient(x0,y0,x1,y1,col_alp,col_led)
  278.         local pat = cairo_pattern_create_linear (x0,y0,x1,y1) ---delta, 0,delta+ t.width,0)
  279.         cairo_pattern_add_color_stop_rgba (pat, 0.0, rgb_to_r_g_b(col_alp))
  280.         cairo_pattern_add_color_stop_rgba (pat, 0.5, rgb_to_r_g_b(col_led))
  281.         cairo_pattern_add_color_stop_rgba (pat, 1.0, rgb_to_r_g_b(col_alp))
  282.         return pat
  283.     end
  284.  
  285.     local function create_led_radial_gradient(x0,y0,r0,x1,y1,r1,col_alp,col_led,mode)
  286.         local pat = cairo_pattern_create_radial (x0,y0,r0,x1,y1,r1)
  287.         if mode==3 then
  288.             cairo_pattern_add_color_stop_rgba (pat, 0, rgb_to_r_g_b(col_alp))              
  289.             cairo_pattern_add_color_stop_rgba (pat, 0.5, rgb_to_r_g_b(col_led))
  290.             cairo_pattern_add_color_stop_rgba (pat, 1, rgb_to_r_g_b(col_alp))              
  291.         else
  292.             cairo_pattern_add_color_stop_rgba (pat, 0, rgb_to_r_g_b(col_led))
  293.             cairo_pattern_add_color_stop_rgba (pat, 1, rgb_to_r_g_b(col_alp))              
  294.         end
  295.         return pat
  296.     end
  297.  
  298.  
  299.  
  300.  
  301.  
  302.  
  303.     local function draw_single_bar()
  304.         --this fucntion is used for bars with a single block (blocks=1) but
  305.         --the drawing is cut in 3 blocks : value/alarm/background
  306.         --not zvzimzblr for circular bar
  307.         local function create_pattern(col_alp,col_led,bg)
  308.             local pat
  309.            
  310.             if not t.smooth then
  311.                 if t.led_effect=="e" then
  312.                     pat = create_led_linear_gradient (-delta, 0,delta+ t.width,0,col_alp,col_led)
  313.                 elseif t.led_effect=="a" then
  314.                     pat = create_led_linear_gradient (t.width/2, 0,t.width/2,-t.height,col_alp,col_led)
  315.                 elseif  t.led_effect=="r" then
  316.                     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)
  317.                 else
  318.                     pat = cairo_pattern_create_rgba  (rgb_to_r_g_b(col_alp))
  319.                 end
  320.             else
  321.                 if bg then
  322.                     pat = cairo_pattern_create_rgba  (rgb_to_r_g_b(t.bg_colour))
  323.                 else
  324.                     pat = create_smooth_linear_gradient(t.width/2, 0, t.width/2,-t.height)
  325.                 end
  326.             end
  327.             return pat
  328.         end
  329.        
  330.         local y1=-t.height*pct/100
  331.         local y2,y3
  332.         if pct>(100*t.alarm/t.max) then
  333.             y1 = -t.height*t.alarm/100
  334.             y2 = -t.height*pct/100
  335.             if t.smooth then y1=y2 end
  336.         end
  337.        
  338.         if t.angle_bar==0 then
  339.        
  340.             --block for fg value
  341.             local pat = create_pattern(t.fg_colour,t.fg_led,false)
  342.             cairo_set_source(cr,pat)
  343.             cairo_rectangle(cr,0,0,t.width,y1)
  344.             cairo_fill(cr)
  345.             cairo_pattern_destroy(pat)
  346.        
  347.             -- block for alarm value           
  348.             if not t.smooth and y2 ~=nil then
  349.                 pat = create_pattern(t.alarm_colour,t.alarm_led,false)
  350.                 cairo_set_source(cr,pat)
  351.                 cairo_rectangle(cr,0,y1,t.width,y2-y1)
  352.                 cairo_fill(cr)
  353.                 y3=y2
  354.                 cairo_pattern_destroy(pat)
  355.             else
  356.                 y2,y3=y1,y1
  357.             end
  358.             -- block for bg value
  359.             cairo_rectangle(cr,0,y2,t.width,-t.height-y3)
  360.             pat = create_pattern(t.bg_colour,t.bg_led,true)
  361.             cairo_set_source(cr,pat)
  362.             cairo_pattern_destroy(pat)
  363.             cairo_fill(cr)
  364.         end    
  365.     end  --end single bar
  366.    
  367.  
  368.  
  369.  
  370.  
  371.  
  372.     local function draw_multi_bar()
  373.         --function used for bars with 2 or more blocks
  374.         for pt = 1,t.blocks do
  375.             --set block y
  376.             local y1 = -(pt-1)*(t.height+t.space)
  377.             local light_on=false
  378.            
  379.             --set colors
  380.             local col_alp = t.bg_colour
  381.             local col_led = t.bg_led
  382.             if pct>=(100/t.blocks) or pct>0 then --ligth on or not the block
  383.                 if pct>=(pcb*(pt-1))  then
  384.                     light_on = true
  385.                     col_alp = t.fg_colour
  386.                     col_led = t.fg_led
  387.                     if pct>=(100*t.alarm/t.max) and (pcb*pt)>(100*t.alarm/t.max) then
  388.                         col_alp = t.alarm_colour
  389.                         col_led = t.alarm_led
  390.                     end
  391.                 end
  392.             end
  393.  
  394.             --set colors
  395.             --have to try to create gradients outside the loop ?
  396.             local pat
  397.            
  398.             if not t.smooth then
  399.                 if t.angle_bar==0 then
  400.                     if t.led_effect=="e" then
  401.                         pat = create_led_linear_gradient (-delta, 0,delta+ t.width,0,col_alp,col_led)
  402.                     elseif t.led_effect=="a" then
  403.                         pat = create_led_linear_gradient (t.width/2, -t.height/2+y1,t.width/2,0+t.height/2+y1,col_alp,col_led)                 
  404.                     elseif  t.led_effect=="r" then
  405.                         pat = create_led_radial_gradient (t.width/2, y1, 0, t.width/2,y1,t.width/1.5,col_alp,col_led,2)
  406.                     else
  407.                         pat = cairo_pattern_create_rgba  (rgb_to_r_g_b(col_alp))
  408.                     end
  409.                 else
  410.                      if t.led_effect=="a"  then
  411.                          pat = create_led_radial_gradient (0, 0, t.radius+(t.height+t.space)*(pt-1),
  412.                                                          0, 0, t.radius+(t.height+t.space)*(pt),                         
  413.                                              col_alp,col_led,3)
  414.                     else
  415.                         pat = cairo_pattern_create_rgba  (rgb_to_r_g_b(col_alp))                   
  416.                     end
  417.                    
  418.                 end
  419.             else
  420.                
  421.                 if light_on then
  422.                     if t.angle_bar==0 then
  423.                         pat = create_smooth_linear_gradient(t.width/2, t.height/2, t.width/2,-(t.blocks-0.5)*(t.height+t.space))
  424.                     else
  425.                         pat = create_smooth_radial_gradient(0, 0, (t.height+t.space),  0,0,(t.blocks+1)*(t.height+t.space),2)
  426.                     end
  427.                 else       
  428.                     pat = cairo_pattern_create_rgba  (rgb_to_r_g_b(t.bg_colour))
  429.                 end
  430.             end
  431.             cairo_set_source (cr, pat)
  432.             cairo_pattern_destroy(pat)
  433.  
  434.             --draw a block
  435.             if t.angle_bar==0 then
  436.                 cairo_move_to(cr,0,y1)
  437.                 cairo_line_to(cr,t.width,y1)
  438.             else       
  439.                 cairo_arc( cr,0,0,
  440.                     t.radius+(t.height+t.space)*(pt)-t.height/2,
  441.                      -t.angle_bar -math.pi/2 ,
  442.                      t.angle_bar -math.pi/2)
  443.             end
  444.             cairo_stroke(cr)
  445.         end
  446.     end
  447.    
  448.    
  449.    
  450.    
  451.     local function setup_bar_graph()
  452.         --function used to retrieve the value to display and to set the cairo structure
  453.         if t.blocks ~=1 then t.y=t.y-t.height/2 end
  454.        
  455.         local value = 0
  456.         if t.name ~="" then
  457.             value = tonumber(conky_parse(string.format('${%s %s}', t.name, t.arg)))
  458.             --$to_bytes doesn't work when value has a decimal point,
  459.             --https://garage.maemo.org/plugins/ggit/browse.php/?p=monky;a=commitdiff;h=174c256c81a027a2ea406f5f37dc036fac0a524b;hp=d75e2db5ed3fc788fb8514121f67316ac3e5f29f
  460.             --http://sourceforge.net/tracker/index.php?func=detail&aid=3000865&group_id=143975&atid=757310
  461.             --conky bug?
  462.             --value = (conky_parse(string.format('${%s %s}', t.name, t.arg)))
  463.             --if string.match(value,"%w") then
  464.             --  value = conky_parse(string.format('${to_bytes %s}',value))
  465.             --end
  466.         else
  467.             value = tonumber(t.arg)
  468.         end
  469.  
  470.         if value==nil then value =0 end
  471.        
  472.         pct = 100*value/t.max
  473.         pcb = 100/t.blocks
  474.        
  475.         cairo_set_line_width (cr, t.height)
  476.         cairo_set_line_cap  (cr, cap)
  477.         cairo_translate(cr,t.x,t.y)
  478.         cairo_rotate(cr,t.angle)
  479.  
  480.         local matrix0 = cairo_matrix_t:create()
  481.         tolua.takeownership(matrix0)
  482.         cairo_matrix_init (matrix0, 1,t.skew_y,t.skew_x,1,0,0)
  483.         cairo_transform(cr,matrix0)
  484.  
  485.    
  486.        
  487.         --call the drawing function for blocks
  488.         if t.blocks==1 and t.angle_bar==0 then
  489.             draw_single_bar()
  490.             if t.reflection=="t" or t.reflection=="b" then cairo_translate(cr,0,-t.height) end
  491.         else
  492.             draw_multi_bar()
  493.         end
  494.  
  495.         --dot for reminder
  496.         --[[
  497.         if t.blocks ~=1 then
  498.             cairo_set_source_rgba(cr,1,0,0,1)
  499.             cairo_arc(cr,0,t.height/2,3,0,2*math.pi)
  500.             cairo_fill(cr)
  501.         else
  502.             cairo_set_source_rgba(cr,1,0,0,1)
  503.             cairo_arc(cr,0,0,3,0,2*math.pi)
  504.             cairo_fill(cr)
  505.         end]]
  506.        
  507.         --call the drawing function for reflection and prepare the mask used       
  508.         if t.reflection_alpha>0 and t.angle_bar==0 then
  509.             local pat2
  510.             local matrix1 = cairo_matrix_t:create()
  511.             tolua.takeownership(matrix1)
  512.             if t.angle_bar==0 then
  513.                 pts={-delta/2,(t.height+t.space)/2,t.width+delta,-(t.height+t.space)*(t.blocks)}
  514.                 if t.reflection=="t" then
  515.                     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)
  516.                     pat2 = cairo_pattern_create_linear (t.width/2,-(t.height+t.space)*(t.blocks),t.width/2,(t.height+t.space)/2)
  517.                 elseif t.reflection=="r" then
  518.                     cairo_matrix_init (matrix1,-t.reflection_scale,0,0,1,delta+2*t.width,0)
  519.                     pat2 = cairo_pattern_create_linear (delta/2+t.width,0,-delta/2,0)
  520.                 elseif t.reflection=="l" then
  521.                     cairo_matrix_init (matrix1,-t.reflection_scale,0,0,1,-delta,0)
  522.                     pat2 = cairo_pattern_create_linear (-delta/2,0,delta/2+t.width,-0)
  523.                 else --bottom
  524.                     cairo_matrix_init (matrix1,1,0,0,-1*t.reflection_scale,0,(t.height+t.space)*(t.reflection_scale+1)/2)
  525.                     pat2 = cairo_pattern_create_linear (t.width/2,(t.height+t.space)/2,t.width/2,-(t.height+t.space)*(t.blocks))
  526.                 end
  527.             end
  528.             cairo_transform(cr,matrix1)
  529.  
  530.             if t.blocks==1 and t.angle_bar==0 then
  531.                 draw_single_bar()
  532.                 cairo_translate(cr,0,-t.height/2)
  533.             else
  534.                 draw_multi_bar()
  535.             end
  536.            
  537.            
  538.             cairo_set_line_width(cr,0.01)
  539.             cairo_pattern_add_color_stop_rgba (pat2, 0,0,0,0,1-t.reflection_alpha)
  540.             cairo_pattern_add_color_stop_rgba (pat2, t.reflection_length,0,0,0,1)
  541.             if t.angle_bar==0 then
  542.                 cairo_rectangle(cr,pts[1],pts[2],pts[3],pts[4])
  543.             end
  544.             cairo_clip_preserve(cr)
  545.             cairo_set_operator(cr,CAIRO_OPERATOR_CLEAR)
  546.             cairo_stroke(cr)
  547.             cairo_mask(cr,pat2)
  548.             cairo_pattern_destroy(pat2)
  549.             cairo_set_operator(cr,CAIRO_OPERATOR_OVER)
  550.            
  551.         end --reflection
  552.         pct,pcb=nil
  553.     end --setup_bar_graph()
  554.    
  555.     --start here !
  556.     setup_bar_graph()
  557.     cairo_restore(cr)
  558. end
  559.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement