From bcf0a9923c8480ef57bbc83e6357c6ca1b3d912c Mon Sep 17 00:00:00 2001 From: Hans-Werner Hilse Date: Mon, 17 Nov 2014 10:02:32 +0100 Subject: [PATCH] (really?) fix refresh viewport calculations This adds more documentation about the viewport offset calculations for refreshing rotated viewports. The old behaviour also was (still) buggy, even after the latest round of fixes. Now, the offsets when rotated are hopefully calculated correct. --- frontend/device/screen.lua | 39 +++++++++++++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/frontend/device/screen.lua b/frontend/device/screen.lua index cf382af1b..c895e3b85 100644 --- a/frontend/device/screen.lua +++ b/frontend/device/screen.lua @@ -80,23 +80,52 @@ end function Screen:refresh(refresh_type, waveform_mode, wait_for_marker, x, y, w, h) if self.viewport and x and y then - -- adapt to viewport, depending on rotation + --[[ + we need to adapt the coordinates when we have a viewport. + this adaptation depends on the rotation: + + 0,0 fb.w + +---+---------------------------+---+ + | |v.y v.y| | + |v.x| |vx2| + +---+---------------------------+---+ + | | v.w | | + | | | | + | | | | + | |v.h (viewport) | | + | | | | fb.h + | | | | + | | | | + | | | | + +---+---------------------------+---+ + |v.x| |vx2| + | |vy2 vy2| | + +---+---------------------------+---+ + + The viewport offset v.y/v.x only applies when rotation is 0 degrees. + For other rotations (0,0 is in one of the other edges), we need to + recalculate the offsets. + --]] + + local vx2 = self.screen_size.w - (self.viewport.x + self.viewport.w) + local vy2 = self.screen_size.h - (self.viewport.y + self.viewport.h) + if self.cur_rotation_mode == 0 then -- (0,0) is at top left of screen x = x + self.viewport.x y = y + self.viewport.y elseif self.cur_rotation_mode == 1 then -- (0,0) is at bottom left of screen - x = x + (self.fb.bb:getWidth()-self.viewport.h) + x = x + vy2 y = y + self.viewport.x elseif self.cur_rotation_mode == 2 then -- (0,0) is at bottom right of screen - x = x + (self.fb.bb:getWidth()-self.viewport.w) - y = y + (self.fb.bb:getHeight()-self.viewport.h) + x = x + vx2 + y = y + vy2 else -- (0,0) is at top right of screen x = x + self.viewport.y - y = y + (self.fb.bb:getHeight()-self.viewport.w) + y = y + vx2 end end self.fb:refresh(refresh_type, waveform_mode, wait_for_marker, x, y, w, h)