progressbar: Port to oocairo

Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
Uli Schlachter 2010-09-29 19:24:36 +02:00
parent 048064b8ef
commit d8dce35269
1 changed files with 38 additions and 28 deletions

View File

@ -7,9 +7,10 @@
local setmetatable = setmetatable local setmetatable = setmetatable
local ipairs = ipairs local ipairs = ipairs
local math = math local math = math
local capi = { image = image, local capi = { oocairo = oocairo,
widget = widget } widget = widget }
local layout = require("awful.widget.layout") local layout = require("awful.widget.layout")
local color = require("gears.color")
--- A progressbar widget. --- A progressbar widget.
module("awful.widget.progressbar") module("awful.widget.progressbar")
@ -85,7 +86,9 @@ local function update(pbar)
local ticks_size = data[pbar].ticks_size or 4 local ticks_size = data[pbar].ticks_size or 4
-- Create new empty image -- Create new empty image
local img = capi.image.argb32(width, height, nil) local img = capi.oocairo.image_surface_create("argb32", width, height)
local cr = capi.oocairo.context_create(img)
cr:set_line_width(1)
local value = data[pbar].value local value = data[pbar].value
local max_value = data[pbar].max_value local max_value = data[pbar].max_value
@ -98,7 +101,9 @@ local function update(pbar)
local border_width = 0 local border_width = 0
if data[pbar].border_color then if data[pbar].border_color then
-- Draw border -- Draw border
img:draw_rectangle(0, 0, width, height, false, data[pbar].border_color) cr:rectangle(0.5, 0.5, width - 0.5, height - 0.5)
cr:set_source(color(data[pbar].border_color))
cr:stroke()
over_drawn_width = width - 2 -- remove 2 for borders over_drawn_width = width - 2 -- remove 2 for borders
over_drawn_height = height - 2 -- remove 2 for borders over_drawn_height = height - 2 -- remove 2 for borders
border_width = 1 border_width = 1
@ -115,19 +120,21 @@ local function update(pbar)
over_drawn_width, over_drawn_height, over_drawn_width, over_drawn_height,
data[pbar].gradient_colors, angle) data[pbar].gradient_colors, angle)
else else
img:draw_rectangle(border_width, border_width, cr:rectangle(border_width, border_width,
over_drawn_width, over_drawn_height, over_drawn_width, over_drawn_height)
true, data[pbar].color or "#ff0000") cr:set_source(color(data[pbar].color or "#ff0000"))
cr:fill()
end end
-- Cover the part that is not set with a rectangle -- Cover the part that is not set with a rectangle
if data[pbar].vertical then if data[pbar].vertical then
local rel_height = math.floor(over_drawn_height * (1 - value)) local rel_height = over_drawn_height * (1 - value)
img:draw_rectangle(border_width, cr:rectangle(border_width,
border_width, border_width,
over_drawn_width, over_drawn_width,
rel_height, rel_height)
true, data[pbar].background_color or "#000000aa") cr:set_source(color(data[pbar].background_color or "#000000aa"))
cr:fill()
-- Place smaller pieces over the gradient if ticks are enabled -- Place smaller pieces over the gradient if ticks are enabled
if data[pbar].ticks then if data[pbar].ticks then
@ -135,34 +142,37 @@ local function update(pbar)
local rel_offset = over_drawn_height / 1 - (ticks_size+ticks_gap) * i local rel_offset = over_drawn_height / 1 - (ticks_size+ticks_gap) * i
if rel_offset >= rel_height then if rel_offset >= rel_height then
img:draw_rectangle(border_width, cr:rectangle(border_width,
rel_offset, rel_offset,
over_drawn_width, over_drawn_width,
ticks_gap, ticks_gap)
true, data[pbar].background_color or "#000000aa")
end end
end end
cr:set_source(color(data[pbar].background_color or "#000000aa"))
cr:fill()
end end
else else
local rel_x = math.ceil(over_drawn_width * value) local rel_x = over_drawn_width * value
img:draw_rectangle(border_width + rel_x, cr:rectangle(border_width + rel_x,
border_width, border_width,
over_drawn_width - rel_x, over_drawn_width - rel_x,
over_drawn_height, over_drawn_height)
true, data[pbar].background_color or "#000000aa") cr:set_source(color(data[pbar].background_color or "#000000aa"))
cr:fill()
if data[pbar].ticks then if data[pbar].ticks then
for i=0, width / (ticks_size+ticks_gap)-border_width do for i=0, width / (ticks_size+ticks_gap)-border_width do
local rel_offset = over_drawn_width / 1 - (ticks_size+ticks_gap) * i local rel_offset = over_drawn_width / 1 - (ticks_size+ticks_gap) * i
if rel_offset <= rel_x then if rel_offset <= rel_x then
img:draw_rectangle(rel_offset, cr:rectangle(rel_offset,
border_width, border_width,
ticks_gap, ticks_gap,
over_drawn_height, over_drawn_height)
true, data[pbar].background_color or "#000000aa")
end end
end end
cr:set_source(color(data[pbar].background_color or "#000000aa"))
cr:fill()
end end
end end