progressbar: Port to oocairo
Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
parent
048064b8ef
commit
d8dce35269
|
@ -7,9 +7,10 @@
|
|||
local setmetatable = setmetatable
|
||||
local ipairs = ipairs
|
||||
local math = math
|
||||
local capi = { image = image,
|
||||
local capi = { oocairo = oocairo,
|
||||
widget = widget }
|
||||
local layout = require("awful.widget.layout")
|
||||
local color = require("gears.color")
|
||||
|
||||
--- A progressbar widget.
|
||||
module("awful.widget.progressbar")
|
||||
|
@ -85,7 +86,9 @@ local function update(pbar)
|
|||
local ticks_size = data[pbar].ticks_size or 4
|
||||
|
||||
-- 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 max_value = data[pbar].max_value
|
||||
|
@ -98,7 +101,9 @@ local function update(pbar)
|
|||
local border_width = 0
|
||||
if data[pbar].border_color then
|
||||
-- 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_height = height - 2 -- remove 2 for borders
|
||||
border_width = 1
|
||||
|
@ -115,19 +120,21 @@ local function update(pbar)
|
|||
over_drawn_width, over_drawn_height,
|
||||
data[pbar].gradient_colors, angle)
|
||||
else
|
||||
img:draw_rectangle(border_width, border_width,
|
||||
over_drawn_width, over_drawn_height,
|
||||
true, data[pbar].color or "#ff0000")
|
||||
cr:rectangle(border_width, border_width,
|
||||
over_drawn_width, over_drawn_height)
|
||||
cr:set_source(color(data[pbar].color or "#ff0000"))
|
||||
cr:fill()
|
||||
end
|
||||
|
||||
-- Cover the part that is not set with a rectangle
|
||||
if data[pbar].vertical then
|
||||
local rel_height = math.floor(over_drawn_height * (1 - value))
|
||||
img:draw_rectangle(border_width,
|
||||
border_width,
|
||||
over_drawn_width,
|
||||
rel_height,
|
||||
true, data[pbar].background_color or "#000000aa")
|
||||
local rel_height = over_drawn_height * (1 - value)
|
||||
cr:rectangle(border_width,
|
||||
border_width,
|
||||
over_drawn_width,
|
||||
rel_height)
|
||||
cr:set_source(color(data[pbar].background_color or "#000000aa"))
|
||||
cr:fill()
|
||||
|
||||
-- Place smaller pieces over the gradient if ticks are enabled
|
||||
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
|
||||
|
||||
if rel_offset >= rel_height then
|
||||
img:draw_rectangle(border_width,
|
||||
rel_offset,
|
||||
over_drawn_width,
|
||||
ticks_gap,
|
||||
true, data[pbar].background_color or "#000000aa")
|
||||
cr:rectangle(border_width,
|
||||
rel_offset,
|
||||
over_drawn_width,
|
||||
ticks_gap)
|
||||
end
|
||||
end
|
||||
cr:set_source(color(data[pbar].background_color or "#000000aa"))
|
||||
cr:fill()
|
||||
end
|
||||
else
|
||||
local rel_x = math.ceil(over_drawn_width * value)
|
||||
img:draw_rectangle(border_width + rel_x,
|
||||
border_width,
|
||||
over_drawn_width - rel_x,
|
||||
over_drawn_height,
|
||||
true, data[pbar].background_color or "#000000aa")
|
||||
local rel_x = over_drawn_width * value
|
||||
cr:rectangle(border_width + rel_x,
|
||||
border_width,
|
||||
over_drawn_width - rel_x,
|
||||
over_drawn_height)
|
||||
cr:set_source(color(data[pbar].background_color or "#000000aa"))
|
||||
cr:fill()
|
||||
|
||||
if data[pbar].ticks then
|
||||
for i=0, width / (ticks_size+ticks_gap)-border_width do
|
||||
local rel_offset = over_drawn_width / 1 - (ticks_size+ticks_gap) * i
|
||||
|
||||
if rel_offset <= rel_x then
|
||||
img:draw_rectangle(rel_offset,
|
||||
border_width,
|
||||
ticks_gap,
|
||||
over_drawn_height,
|
||||
true, data[pbar].background_color or "#000000aa")
|
||||
cr:rectangle(rel_offset,
|
||||
border_width,
|
||||
ticks_gap,
|
||||
over_drawn_height)
|
||||
end
|
||||
end
|
||||
cr:set_source(color(data[pbar].background_color or "#000000aa"))
|
||||
cr:fill()
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue