wibox.layout.base.rect_to_device_geometry: Fix for "weird" rotations

The old code transformed the top-left and bottom-right corner of the rectangle
to device space and calculated a rectangle based on these two points. However,
if you rotate a rectangle by 45°, these two points will be directly above each
other and thus the old code would calculate a width of 0.

Fix this by transforming all four corners of the rectangle into device space and
calculating a rectangle based on this.

Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
Uli Schlachter 2014-10-05 10:47:39 +02:00
parent f236a5f0c7
commit c4eb4b1f23
1 changed files with 9 additions and 7 deletions

View File

@ -13,15 +13,17 @@ local max = math.max
-- wibox.layout.base -- wibox.layout.base
local base = {} local base = {}
--- Figure out the geometry in device coordinate space. This will break if --- Figure out the geometry in device coordinate space. This gives only tight
-- someone rotates the coordinate space by a non-multiple of 90°. -- bounds if no rotations by non-multiples of 90° are used.
function base.rect_to_device_geometry(cr, x, y, width, height) function base.rect_to_device_geometry(cr, x, y, width, height)
local x1, y1 = cr:user_to_device(x, y) local x1, y1 = cr:user_to_device(x, y)
local x2, y2 = cr:user_to_device(x + width, y + height) local x2, y2 = cr:user_to_device(x, y + height)
local x = min(x1, x2) local x3, y3 = cr:user_to_device(x + width, y + height)
local y = min(y1, y2) local x4, y4 = cr:user_to_device(x + width, y)
local width = max(x1, x2) - x local x = min(x1, x2, x3, x4)
local height = max(y1, y2) - y local y = min(y1, y2, y3, y4)
local width = max(x1, x2, x3, x4) - x
local height = max(y1, y2, y3, y4) - y
return x, y, width, height return x, y, width, height
end end