Consolidate all rounded rectangle implementation into one

This commit is contained in:
Emmanuel Lepage Vallee 2014-10-04 17:00:51 -04:00
parent 4a18826d04
commit d49b431469
4 changed files with 35 additions and 69 deletions

View File

@ -99,7 +99,7 @@ end
function module.move(direction,c,max)
current_mode = "move"
module._focus.global_bydirection(direction,c,true)
module._focus.global_bydirection(direction,c,true,max)
start_loop(true,max)
end

View File

@ -70,32 +70,6 @@ function module.get_geometry(tag)
return results
end
local function draw_round_rect(cr,x,y,w,h)
cr:save()
cr:translate(x,y)
cr:new_path()
-- cr:move_to(0,radius+1)
-- cr:line_to(0,radius)
cr:arc(radius,radius,radius,math.pi,3*(math.pi/2))
cr:move_to(radius,0)
cr:line_to(w-2*radius,0)
cr:arc(w-radius,radius,radius,3*(math.pi/2),math.pi*2)
cr:move_to(w,radius)
cr:line_to(w,h-radius)
cr:arc(w-radius,h-radius,radius,math.pi*2,math.pi/2)
cr:move_to(w-radius,h)
cr:line_to(radius,h)
cr:arc(radius,h-radius,radius,math.pi/2,math.pi)
cr:move_to(0,h-radius)
cr:line_to(0,radius)
cr:move_to(0,radius)
cr:close_path()
cr:stroke_preserve()
-- cr:set_source_rgba(1,0,0,1)
-- cr:fill() --BUG
cr:restore()
end
function module.draw(tag,cr,width,height)
local worked = false
local l = module.get_geometry(tag)
@ -104,10 +78,14 @@ function module.draw(tag,cr,width,height)
local ratio = height/scr_geo.height
local w_stretch = width/(scr_geo.width*ratio)
local r,g,b = util.get_rgb()
cr:set_source_rgba(r,g,b,0.7)
cr:set_line_width(3)
for c,geom in pairs(l) do
draw_round_rect(cr,geom.x*ratio*w_stretch+margin,geom.y*ratio+margin,geom.width*ratio*w_stretch-margin*2,geom.height*ratio-margin*2)
util.draw_round_rect(cr,geom.x*ratio*w_stretch+margin,geom.y*ratio+margin,geom.width*ratio*w_stretch-margin*2,geom.height*ratio-margin*2,radius)
cr:close_path()
cr:set_source_rgba(r,g,b,0.7)
cr:stroke_preserve()
cr:set_source_rgba(r,g,b,0.2)
cr:fill()
worked = true
end
--TODO floating clients

52
max.lua
View File

@ -21,24 +21,6 @@ local function init()
w.visible = true
end
local function get_round_rect(width,height,bg)
local img2 = cairo.ImageSurface(cairo.Format.ARGB32, width,height)
local cr2 = cairo.Context(img2)
cr2:set_source_rgba(0,0,0,0)
cr2:paint()
cr2:set_source(bg)
cr2:arc(rad,rad,rad,0,2*math.pi)
cr2:arc(width-rad,rad,rad,0,2*math.pi)
cr2:arc(rad ,height-rad,rad,0,2*math.pi)
cr2:fill()
cr2:arc(width-rad,height-rad,rad,0,2*math.pi)
cr2:rectangle(rad,0,width-2*rad,height)
cr2:rectangle(0,rad,rad,height-2*rad)
cr2:rectangle(width-rad,rad,rad,height-2*rad)
cr2:fill()
return img2
end
local margin = 15
local function create_arrow(cr,x,y,width, height,direction)
cr:save()
@ -92,8 +74,8 @@ local function draw_shape(s,collection,current_idx,icon_f,y,text_height)
cr:paint()
local white,bg = color("#FFFFFF"),color(beautiful.menu_bg_normal or beautiful.bg_normal)
local img2 = get_round_rect(width,height,white)
local img4 = get_round_rect(width-6,height-6,bg)
-- local img2 = get_round_rect(width,height,white)
-- local img4 = get_round_rect(width-6,height-6,bg)
if not pango_l then
local pango_crx = pangocairo.font_map_get_default():create_context()
@ -106,15 +88,17 @@ local function draw_shape(s,collection,current_idx,icon_f,y,text_height)
local nornal,focus = color(beautiful.fg_normal),color(beautiful.bg_urgent)
for k,v in ipairs(collection) do
-- Shape bounding
cr:set_source_surface(img2,dx,0)
cr:paint()
cr:set_source(white)
util.draw_round_rect(cr,dx,0,width,height,rad)
cr:fill()
-- Borders
-- Borders and background
cr3:set_source(k==current_idx and focus or nornal)
cr3:rectangle(dx,0,width,height)
util.draw_round_rect(cr3,dx+border,0+border,width-2*border,height-2*border,rad)
cr3:set_line_width(2*border)
cr3:stroke_preserve()
cr3:set_source(bg)
cr3:fill()
cr3:set_source_surface(img4,dx+border,border)
cr3:paint()
-- Print the icon
local icon = icon_f(v,width-20,height-20-text_height)
@ -175,19 +159,11 @@ local function client_icon(c,width,height)
local w,h = geom.width*scale,geom.height*scale
-- Create a mask
cr:save()
util.draw_round_rect(cr,(width-w)/2,(height-h)/2,w,h,10)
cr:fill()
cr:translate((width-w)/2,(height-h)/2)
cr:arc(10,10,10,0,math.pi*2)
cr:fill()
cr:arc(w-10,10,10,0,math.pi*2)
cr:fill()
cr:arc(w-10,h-10,10,0,math.pi*2)
cr:fill()
cr:arc(10,h-10,10,0,math.pi*2)
cr:fill()
cr:rectangle(10,0,w-20,h)
cr:rectangle(0,10,w,h-20)
cr:fill()
-- Create a matrix to scale down the screenshot
cr:save()

View File

@ -1,3 +1,4 @@
local math = math
local color = require( "gears.color" )
local beautiful = require( "beautiful" )
@ -14,5 +15,16 @@ function module.get_rgb()
return rr,rg,rb
end
function module.draw_round_rect(cr,x,y,w,h,radius)
cr:save()
cr:translate(x,y)
cr:move_to(0,radius)
cr:arc(radius,radius,radius,math.pi,3*(math.pi/2))
cr:arc(w-radius,radius,radius,3*(math.pi/2),math.pi*2)
cr:arc(w-radius,h-radius,radius,math.pi*2,math.pi/2)
cr:arc(radius,h-radius,radius,math.pi/2,math.pi)
cr:close_path()
cr:restore()
end
return module
-- kate: space-indent on; indent-width 2; replace-tabs on;