REF move static drawing init to own module
This commit is contained in:
parent
d80cab717e
commit
4da354dd91
|
@ -0,0 +1,71 @@
|
|||
local Common = require 'Common'
|
||||
local Geometry = require 'Geometry'
|
||||
local FillRect = require 'FillRect'
|
||||
|
||||
return function(left_modules, center_modules, right_modules)
|
||||
local __cairo_set_source_surface = cairo_set_source_surface
|
||||
local __cairo_image_surface_create = cairo_image_surface_create
|
||||
local __cairo_translate = cairo_translate
|
||||
local __cairo_create = cairo_create
|
||||
local __cairo_destroy = cairo_destroy
|
||||
local __cairo_paint = cairo_paint
|
||||
|
||||
local _make_static_surface = function(x, y, w, h, modules)
|
||||
local panel_line_thickness = 1
|
||||
-- move over by half a pixel so the lines don't need to be antialiased
|
||||
local _x = x + 0.5
|
||||
local _y = y + 0.5
|
||||
local panel = Common.initPanel(_x, _y, w, h, panel_line_thickness)
|
||||
local cs_x = _x - panel_line_thickness * 0.5
|
||||
local cs_y = _y - panel_line_thickness * 0.5
|
||||
local cs_w = w + panel_line_thickness
|
||||
local cs_h = h + panel_line_thickness
|
||||
|
||||
local cs = __cairo_image_surface_create(CAIRO_FORMAT_ARGB32, cs_w, cs_h)
|
||||
local cr = __cairo_create(cs)
|
||||
|
||||
__cairo_translate(cr, -cs_x, -cs_y)
|
||||
|
||||
FillRect.draw(panel, cr)
|
||||
for _, f in pairs(modules) do
|
||||
f(cr)
|
||||
end
|
||||
__cairo_destroy(cr)
|
||||
return { x = cs_x, y = cs_y, s = cs }
|
||||
end
|
||||
|
||||
local cs_left = _make_static_surface(
|
||||
Geometry.LEFT_X - Geometry.PANEL_MARGIN_X,
|
||||
Geometry.TOP_Y - Geometry.PANEL_MARGIN_Y,
|
||||
Geometry.SECTION_WIDTH + Geometry.PANEL_MARGIN_X * 2,
|
||||
Geometry.SIDE_HEIGHT + Geometry.PANEL_MARGIN_Y * 2,
|
||||
left_modules
|
||||
)
|
||||
|
||||
local cs_center = _make_static_surface(
|
||||
Geometry.CENTER_LEFT_X - Geometry.PANEL_MARGIN_X,
|
||||
Geometry.TOP_Y - Geometry.PANEL_MARGIN_Y,
|
||||
Geometry.CENTER_WIDTH + Geometry.PANEL_MARGIN_Y * 2 + Geometry.CENTER_PAD,
|
||||
Geometry.CENTER_HEIGHT + Geometry.PANEL_MARGIN_Y * 2,
|
||||
center_modules
|
||||
)
|
||||
|
||||
local cs_right = _make_static_surface(
|
||||
Geometry.RIGHT_X - Geometry.PANEL_MARGIN_X,
|
||||
Geometry.TOP_Y - Geometry.PANEL_MARGIN_Y,
|
||||
Geometry.SECTION_WIDTH + Geometry.PANEL_MARGIN_X * 2,
|
||||
Geometry.SIDE_HEIGHT + Geometry.PANEL_MARGIN_Y * 2,
|
||||
right_modules
|
||||
)
|
||||
|
||||
local draw_static_surface = function(cr, cs_obj)
|
||||
__cairo_set_source_surface(cr, cs_obj.s, cs_obj.x, cs_obj.y)
|
||||
__cairo_paint(cr)
|
||||
end
|
||||
|
||||
return function(cr)
|
||||
draw_static_surface(cr, cs_left)
|
||||
draw_static_surface(cr, cs_center)
|
||||
draw_static_surface(cr, cs_right)
|
||||
end
|
||||
end
|
76
main.lua
76
main.lua
|
@ -1,15 +1,8 @@
|
|||
--
|
||||
-- init cairo
|
||||
--
|
||||
require 'cairo'
|
||||
local __cairo_xlib_surface_create = cairo_xlib_surface_create
|
||||
local __cairo_set_source_surface = cairo_set_source_surface
|
||||
local __cairo_image_surface_create = cairo_image_surface_create
|
||||
local __cairo_paint = cairo_paint
|
||||
local __cairo_create = cairo_create
|
||||
local __cairo_surface_destroy = cairo_surface_destroy
|
||||
local __cairo_destroy = cairo_destroy
|
||||
local __cairo_translate = cairo_translate
|
||||
|
||||
local ABS_PATH = debug.getinfo(1).source:match("@?(.*/)")
|
||||
package.path = ABS_PATH..'?.lua;'..
|
||||
|
@ -26,7 +19,6 @@ package.path = ABS_PATH..'?.lua;'..
|
|||
ABS_PATH..'core/widget/image/?.lua;'
|
||||
|
||||
local Util = require 'Util'
|
||||
local FillRect = require 'FillRect'
|
||||
local System = require 'System'
|
||||
local Network = require 'Network'
|
||||
local Processor = require 'Processor'
|
||||
|
@ -36,41 +28,7 @@ local Power = require 'Power'
|
|||
local ReadWrite = require 'ReadWrite'
|
||||
local Graphics = require 'Graphics'
|
||||
local Memory = require 'Memory'
|
||||
local Common = require 'Common'
|
||||
local Geometry = require 'Geometry'
|
||||
|
||||
--
|
||||
-- initialize static surfaces
|
||||
--
|
||||
|
||||
local _make_static_surface = function(x, y, w, h, modules)
|
||||
local panel_line_thickness = 1
|
||||
-- move over by half a pixel so the lines don't need to be antialiased
|
||||
local _x = x + 0.5
|
||||
local _y = y + 0.5
|
||||
local panel = Common.initPanel(_x, _y, w, h, panel_line_thickness)
|
||||
local cs_x = _x - panel_line_thickness * 0.5
|
||||
local cs_y = _y - panel_line_thickness * 0.5
|
||||
local cs_w = w + panel_line_thickness
|
||||
local cs_h = h + panel_line_thickness
|
||||
|
||||
local cs = __cairo_image_surface_create(CAIRO_FORMAT_ARGB32, cs_w, cs_h)
|
||||
local cr = __cairo_create(cs)
|
||||
|
||||
__cairo_translate(cr, -cs_x, -cs_y)
|
||||
|
||||
FillRect.draw(panel, cr)
|
||||
for _, f in pairs(modules) do
|
||||
f(cr)
|
||||
end
|
||||
__cairo_destroy(cr)
|
||||
return { x = cs_x, y = cs_y, s = cs }
|
||||
end
|
||||
|
||||
local draw_static_surface = function(cr, cs_obj)
|
||||
__cairo_set_source_surface(cr, cs_obj.s, cs_obj.x, cs_obj.y)
|
||||
__cairo_paint(cr)
|
||||
end
|
||||
local Static = require 'Static'
|
||||
|
||||
local using_ac = function()
|
||||
-- for some reason it is much more efficient to test if the battery
|
||||
|
@ -79,7 +37,6 @@ local using_ac = function()
|
|||
end
|
||||
|
||||
local updates = -2 -- this accounts for the first few spazzy iterations
|
||||
local STATS_FILE = '/tmp/.conky_pacman'
|
||||
local draw
|
||||
|
||||
function conky_start(update_interval)
|
||||
|
@ -97,37 +54,18 @@ function conky_start(update_interval)
|
|||
local proc = Processor(update_freq)
|
||||
local pcm = Pacman()
|
||||
|
||||
local cs_left = _make_static_surface(
|
||||
Geometry.LEFT_X - Geometry.PANEL_MARGIN_X,
|
||||
Geometry.TOP_Y - Geometry.PANEL_MARGIN_Y,
|
||||
Geometry.SECTION_WIDTH + Geometry.PANEL_MARGIN_X * 2,
|
||||
Geometry.SIDE_HEIGHT + Geometry.PANEL_MARGIN_Y * 2,
|
||||
{sys.static, gfx.static, proc.static}
|
||||
)
|
||||
|
||||
local cs_center = _make_static_surface(
|
||||
Geometry.CENTER_LEFT_X - Geometry.PANEL_MARGIN_X,
|
||||
Geometry.TOP_Y - Geometry.PANEL_MARGIN_Y,
|
||||
Geometry.CENTER_WIDTH + Geometry.PANEL_MARGIN_Y * 2 + Geometry.CENTER_PAD,
|
||||
Geometry.CENTER_HEIGHT + Geometry.PANEL_MARGIN_Y * 2,
|
||||
{rw.static, net.static}
|
||||
)
|
||||
|
||||
local cs_right = _make_static_surface(
|
||||
Geometry.RIGHT_X - Geometry.PANEL_MARGIN_X,
|
||||
Geometry.TOP_Y - Geometry.PANEL_MARGIN_Y,
|
||||
Geometry.SECTION_WIDTH + Geometry.PANEL_MARGIN_X * 2,
|
||||
Geometry.SIDE_HEIGHT + Geometry.PANEL_MARGIN_Y * 2,
|
||||
local draw_static = Static(
|
||||
{sys.static, gfx.static, proc.static},
|
||||
{rw.static, net.static},
|
||||
{pcm.static, fs.static, pwr.static, mem.static}
|
||||
)
|
||||
|
||||
local STATS_FILE = '/tmp/.conky_pacman'
|
||||
|
||||
draw = function(cr, _updates)
|
||||
draw_static_surface(cr, cs_left)
|
||||
draw_static_surface(cr, cs_center)
|
||||
draw_static_surface(cr, cs_right)
|
||||
draw_static(cr)
|
||||
|
||||
local t1 = _updates % (update_freq * 10)
|
||||
|
||||
local is_using_ac = using_ac()
|
||||
local pacman_stats = Util.read_file(STATS_FILE)
|
||||
|
||||
|
|
Loading…
Reference in New Issue