faster refresh path for the cursor

HW 12 years ago
parent 78efdc77e3
commit ab400b97ac

@ -85,7 +85,7 @@ function Cursor:setHeight(h)
self.line_w = math.floor(self.h / self.line_width_factor)
end
function Cursor:_draw(x, y)
function Cursor:_draw(x, y, refresh)
local up_down_width = math.floor(self.line_w / 2)
local body_h = self.h - (up_down_width * 2)
-- paint upper horizontal line
@ -95,19 +95,23 @@ function Cursor:_draw(x, y)
self.line_w, body_h)
-- paint lower horizontal line
fb.bb:invertRect(x, y + body_h + up_down_width, self.w, up_down_width)
if refresh then
fb:refresh(1, x, y, self.w, body_h + up_down_width * 2)
end
end
function Cursor:draw()
function Cursor:draw(refresh)
if self.is_cleared then
self.is_cleared = false
self:_draw(self.x_pos, self.y_pos)
self:_draw(self.x_pos, self.y_pos, refresh)
end
end
function Cursor:clear()
function Cursor:clear(refresh)
if not self.is_cleared then
self.is_cleared = true
self:_draw(self.x_pos, self.y_pos)
self:_draw(self.x_pos, self.y_pos, refresh)
end
end

@ -351,7 +351,7 @@ function UniReader:drawCursorAfterWord(t, l, w)
local x, y, wd, _ = self:getRectInScreen(t[l][w].x0, t[l][w].y0, t[l][w].x1, t[l][w].y1)
self.cursor:setHeight(h)
self.cursor:moveTo(x+wd, y)
self.cursor:draw()
self.cursor:draw(true)
end
function UniReader:drawCursorBeforeWord(t, l, w)
@ -361,7 +361,7 @@ function UniReader:drawCursorBeforeWord(t, l, w)
local x, y, _, _ = self:getRectInScreen(t[l][w].x0, t[l][w].y0, t[l][w].x1, t[l][w].y1)
self.cursor:setHeight(h)
self.cursor:moveTo(x, y)
self.cursor:draw()
self.cursor:draw(true)
end
function UniReader:getText(pageno)
@ -563,8 +563,7 @@ function UniReader:startHighLightMode()
h = ch,
line_width_factor = 4,
}
self.cursor:draw()
fb:refresh(1)
self.cursor:draw(true)
-- first use cursor to place start pos for highlight
while running do
@ -575,7 +574,7 @@ function UniReader:startHighLightMode()
is_meet_end = false
l.new, w.new, is_meet_start = _prevGap(t, l.cur, w.cur)
self.cursor:clear()
self.cursor:clear(true)
if w.new ~= 0
and self:_isLineInPrevView(t[l.new])
and self:_isEntireWordInScreenWidthRange(t[l.new][w.new]) then
@ -599,7 +598,7 @@ function UniReader:startHighLightMode()
is_meet_start = false
l.new, w.new, is_meet_end = _nextGap(t, l.cur, w.cur)
self.cursor:clear()
self.cursor:clear(true)
-- we want to check whether the word is in screen range,
-- so trun gap into word
local tmp_w = w.new
@ -626,7 +625,7 @@ function UniReader:startHighLightMode()
is_meet_end = false
l.new, w.new, is_meet_start = _gapInPrevLine(t, l.cur, w.cur)
self.cursor:clear()
self.cursor:clear(true)
local tmp_w = w.new
if tmp_w == 0 then
@ -652,7 +651,7 @@ function UniReader:startHighLightMode()
is_meet_start = false
l.new, w.new, is_meet_end = _gapInNextLine(t, l.cur, w.cur)
self.cursor:clear()
self.cursor:clear(true)
local tmp_w = w.new
if w.cur == 0 then
@ -700,13 +699,12 @@ function UniReader:startHighLightMode()
l.new, w.new = l.cur, w.cur
l.start, w.start = l.cur, w.cur
running = false
self.cursor:clear()
self.cursor:clear(true)
elseif ev.code == KEY_BACK then
running = false
return
end -- if check key event
l.cur, w.cur = l.new, w.new
fb:refresh(1)
end
end -- while running
debug("start", l.cur, w.cur, l.start, w.start)

Loading…
Cancel
Save