From e5acbeb363b990c8f844a49902e6c41d348b3c60 Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Sat, 24 Mar 2012 18:28:52 +0800 Subject: [PATCH] mod: fix bug in cursor move only move cursor to word in current view --- djvureader.lua | 28 ++++++++++++++-------------- graphics.lua | 11 +++++++++-- 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/djvureader.lua b/djvureader.lua index b4039145d..c605ad70c 100644 --- a/djvureader.lua +++ b/djvureader.lua @@ -277,15 +277,14 @@ function DJVUReader:startHighLightMode() l.new, w.new = _prevWord(t, l.cur, w.cur) end + self.cursor:clear() if w.new ~= 0 and - not self:_isWordInScreenHeightRange(t[l.new][w.new]) then + not self:_isWordInScreenHeightRange(t[l.new][w.new]) + and self:_isWordInScreenWidthRange(t[l.new][w.new]) then -- word is in previous view local pageno = self:prevView() self:goto(pageno) is_next_view = true - else - -- no need to goto next view, clear previous cursor manually - self.cursor:clear() end -- update cursor @@ -314,13 +313,13 @@ function DJVUReader:startHighLightMode() end end + self.cursor:clear() if w.new ~= 0 and - not self:_isWordInScreenHeightRange(t[l.new][w.new]) then + not self:_isWordInScreenHeightRange(t[l.new][w.new]) + and self:_isWordInScreenWidthRange(t[l.new][w.new]) then local pageno = self:nextView() self:goto(pageno) is_next_view = true - else - self.cursor:clear() end if w.cur == 0 then @@ -345,15 +344,15 @@ function DJVUReader:startHighLightMode() l.new, w.new = _wordInPrevLine(t, l.cur, w.cur) end - if w.new ~= 0 and - not self:_isWordInScreenHeightRange(t[l.new][w.new]) + self.cursor:clear() + if w.new ~= 0 + and not self:_isWordInScreenHeightRange(t[l.new][w.new]) + and self:_isWordInScreenWidthRange(t[l.new][w.new]) or w.new == 0 and not self:_isWordInScreenHeightRange(t[l.new][1]) then -- goto next view of current page local pageno = self:prevView() self:goto(pageno) is_next_view = true - else - self.cursor:clear() end if w.new == 0 then @@ -375,15 +374,16 @@ function DJVUReader:startHighLightMode() l.new, w.new = _wordInNextLine(t, l.cur, w.cur) end + self.cursor:clear() if w.cur ~= 0 and not self:_isWordInScreenHeightRange(t[l.new][w.new]) - or w.cur == 0 and not self:_isWordInScreenHeightRange(t[l.new][1]) then + and self:_isWordInScreenWidthRange(t[l.new][w.new]) + or w.cur == 0 + and not self:_isWordInScreenHeightRange(t[l.new][1]) then -- goto next view of current page local pageno = self:nextView() self:goto(pageno) is_next_view = true - else - self.cursor:clear() end if w.cur == 0 then diff --git a/graphics.lua b/graphics.lua index 2e357b1ae..267cb9469 100644 --- a/graphics.lua +++ b/graphics.lua @@ -42,6 +42,7 @@ Cursor = { h = 10, w = nil, line_w = nil, + is_cleared = true, } function Cursor:new(o) @@ -76,11 +77,17 @@ function Cursor:_draw(x, y) end function Cursor:draw() - self:_draw(self.x_pos, self.y_pos) + if self.is_cleared then + self.is_cleared = false + self:_draw(self.x_pos, self.y_pos) + end end function Cursor:clear() - self:_draw(self.x_pos, self.y_pos) + if not self.is_cleared then + self.is_cleared = true + self:_draw(self.x_pos, self.y_pos) + end end function Cursor:move(x_off, y_off)