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 57b6433b53
commit 983d094c76
1 changed files with 9 additions and 7 deletions

View File

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