fixed menu info displaying, replaced debug() by DEBUG()

the replacement of debug() was necessary to be able to access the lua library "debug" (for backtraces etc.)
pull/2/merge
HW 12 years ago
parent 8191cbe852
commit 60ccd7441e

@ -88,7 +88,7 @@ function Document:getPageDimensions(pageno, zoom, rotation)
native_dimen.w, native_dimen.h = native_dimen.h, native_dimen.w native_dimen.w, native_dimen.h = native_dimen.h, native_dimen.w
end end
native_dimen:scaleBy(zoom) native_dimen:scaleBy(zoom)
debug("dimen for pageno", pageno, "zoom", zoom, "rotation", rotation, "is", native_dimen) DEBUG("dimen for pageno", pageno, "zoom", zoom, "rotation", rotation, "is", native_dimen)
return native_dimen return native_dimen
end end

@ -89,10 +89,10 @@ function PdfDocument:renderPage(pageno, rect, zoom, rotation)
-- we prefer to render the full page, if it fits into cache -- we prefer to render the full page, if it fits into cache
if not Cache:willAccept(size.w * size.h / 2) then if not Cache:willAccept(size.w * size.h / 2) then
-- whole page won't fit into cache -- whole page won't fit into cache
debug("rendering only part of the page") DEBUG("rendering only part of the page")
-- TODO: figure out how to better segment the page -- TODO: figure out how to better segment the page
if not rect then if not rect then
debug("aborting, since we do not have a specification for that part") DEBUG("aborting, since we do not have a specification for that part")
-- required part not given, so abort -- required part not given, so abort
return return
end end
@ -145,11 +145,11 @@ function PdfDocument:drawPage(target, x, y, rect, pageno, zoom, rotation)
if not tile then if not tile then
tile = Cache:check(hash_excerpt) tile = Cache:check(hash_excerpt)
if not tile then if not tile then
debug("rendering") DEBUG("rendering")
tile = self:renderPage(pageno, rect, zoom, rotation) tile = self:renderPage(pageno, rect, zoom, rotation)
end end
end end
debug("now painting", tile) DEBUG("now painting", tile)
target:blitFrom(tile.bb, x, y, rect.x - tile.excerpt.x, rect.y - tile.excerpt.y, rect.w, rect.h) target:blitFrom(tile.bb, x, y, rect.x - tile.excerpt.x, rect.y - tile.excerpt.y, rect.w, rect.h)
end end

@ -27,7 +27,7 @@ function dump(data)
return table.concat(out) return table.concat(out)
end end
function debug(...) function DEBUG(...)
local line = "" local line = ""
for i,v in ipairs(arg) do for i,v in ipairs(arg) do
if type(v) == "table" then if type(v) == "table" then

@ -193,7 +193,7 @@ function ConfirmBox:onClose()
end end
function ConfirmBox:onSelect() function ConfirmBox:onSelect()
debug("selected:", self.selected.x) DEBUG("selected:", self.selected.x)
if self.selected.x == 1 then if self.selected.x == 1 then
self:ok_callback() self:ok_callback()
else else
@ -324,11 +324,6 @@ MenuItem = InputContainer:new{
shortcut = nil, shortcut = nil,
shortcut_style = "square", shortcut_style = "square",
_underline_container = nil, _underline_container = nil,
key_events = {
Select = { {"Press"}, doc = "chose selected item" },
ShowItemDetail = { {"Right"}, doc = "show item detail" }
}
} }
function MenuItem:init() function MenuItem:init()
@ -343,8 +338,14 @@ function MenuItem:init()
-- 15 for HorizontalSpan, -- 15 for HorizontalSpan,
self.content_width = self.width - shortcut_icon_w - 15 self.content_width = self.width - shortcut_icon_w - 15
-- we need this table per-instance, so we declare it here
self.active_key_events = {
Select = { {"Press"}, doc = "chose selected item" },
}
w = sizeUtf8Text(0, self.width, self.face, self.text, true).x w = sizeUtf8Text(0, self.width, self.face, self.text, true).x
if w >= self.content_width then if w >= self.content_width then
self.active_key_events.ShowItemDetail = { {"Right"}, doc = "show item detail" }
indicator = " >>" indicator = " >>"
indicator_w = sizeUtf8Text(0, self.width, self.face, indicator, true).x indicator_w = sizeUtf8Text(0, self.width, self.face, indicator, true).x
self.text = getSubTextByWidth(self.text, self.face, self.text = getSubTextByWidth(self.text, self.face,
@ -381,15 +382,17 @@ end
function MenuItem:onFocus() function MenuItem:onFocus()
self._underline_container.color = 10 self._underline_container.color = 10
self.key_events = self.active_key_events
return true return true
end end
function MenuItem:onUnfocus() function MenuItem:onUnfocus()
self._underline_container.color = 0 self._underline_container.color = 0
self.key_events = { }
return true return true
end end
function MenuItem:onShowDetail() function MenuItem:onShowItemDetail()
UIManager:show(InfoMessage:new{ UIManager:show(InfoMessage:new{
text=self.detail, text=self.detail,
}) })
@ -554,13 +557,6 @@ function Menu:onPrevPage()
return true return true
end end
function Menu:onShowItemDetail()
self.layout[self.selected.y][self.selected.x]:handleEvent(
Event:new("ShowDetail")
)
return true
end
function Menu:onSelect() function Menu:onSelect()
UIManager:close(self) UIManager:close(self)
self.on_select_callback(self.item_table[(self.page-1)*self.perpage+self.selected.y]) self.on_select_callback(self.item_table[(self.page-1)*self.perpage+self.selected.y])

@ -1,4 +1,4 @@
require "settings" -- for debug() require "settings" -- for DEBUG()
Font = { Font = {
fontmap = { fontmap = {
@ -54,11 +54,11 @@ function Font:getFace(font, size)
realname = self.fontdir.."/"..realname realname = self.fontdir.."/"..realname
ok, face = pcall(freetype.newFace, realname, size) ok, face = pcall(freetype.newFace, realname, size)
if not ok then if not ok then
debug("#! Font "..font.." ("..realname..") not supported: "..face) DEBUG("#! Font "..font.." ("..realname..") not supported: "..face)
return nil return nil
end end
self.faces[font..size] = face self.faces[font..size] = face
--debug("getFace, found: "..realname.." size:"..size) --DEBUG("getFace, found: "..realname.." size:"..size)
end end
return { size = size, ftface = face, hash = font..size } return { size = size, ftface = face, hash = font..size }
end end

@ -174,12 +174,12 @@ end
check if our size is smaller than the size of the given dimension/rectangle check if our size is smaller than the size of the given dimension/rectangle
]]-- ]]--
function Geom:__lt(rect_b) function Geom:__lt(rect_b)
debug("lt:",self,rect_b) DEBUG("lt:",self,rect_b)
if self.w < rect_b.w and self.h < rect_b.h then if self.w < rect_b.w and self.h < rect_b.h then
debug("lt+") DEBUG("lt+")
return true return true
end end
debug("lt-") DEBUG("lt-")
return false return false
end end

@ -248,7 +248,7 @@ function Input:waitEvent(timeout_us, timeout_s)
ev = nil ev = nil
break break
end end
debug("got error waiting for events:", ev) DEBUG("got error waiting for events:", ev)
if ev ~= "Waiting for input failed: 4\n" then if ev ~= "Waiting for input failed: 4\n" then
-- we abort if the error is not EINTR -- we abort if the error is not EINTR
break break

@ -31,7 +31,7 @@ function ReaderPaging:gotoPage(number)
or number < 1 then or number < 1 then
return false return false
end end
debug("going to page number", number) DEBUG("going to page number", number)
-- this is an event to allow other controllers to be aware of this change -- this is an event to allow other controllers to be aware of this change
self.ui:handleEvent(Event:new("PageUpdate", number)) self.ui:handleEvent(Event:new("PageUpdate", number))
@ -44,7 +44,7 @@ function ReaderPaging:onPageUpdate(new_page_no)
end end
function ReaderPaging:onGotoPercent(percent) function ReaderPaging:onGotoPercent(percent)
debug("goto document offset in percent:", percent) DEBUG("goto document offset in percent:", percent)
local dest = math.floor(self.number_of_pages * percent / 100) local dest = math.floor(self.number_of_pages * percent / 100)
if dest < 1 then dest = 1 end if dest < 1 then dest = 1 end
if dest > self.number_of_pages then if dest > self.number_of_pages then
@ -55,7 +55,7 @@ function ReaderPaging:onGotoPercent(percent)
end end
function ReaderPaging:onGotoPageRel(diff) function ReaderPaging:onGotoPageRel(diff)
debug("goto relative page:", diff) DEBUG("goto relative page:", diff)
self:gotoPage(self.current_page + diff) self:gotoPage(self.current_page + diff)
return true return true
end end

@ -22,7 +22,7 @@ end
function ReaderPanning:onPanning(args, key) function ReaderPanning:onPanning(args, key)
local dx, dy = unpack(args) local dx, dy = unpack(args)
debug("key =", key) DEBUG("key =", key)
-- for now, bounds checking/calculation is done in the view -- for now, bounds checking/calculation is done in the view
self.view:PanningUpdate( self.view:PanningUpdate(
dx * self.panning_steps.normal * self.dimen.w / 100, dx * self.panning_steps.normal * self.dimen.w / 100,

@ -16,7 +16,7 @@ ReaderView = WidgetContainer:new{
} }
function ReaderView:paintTo(bb, x, y) function ReaderView:paintTo(bb, x, y)
debug("painting", self.visible_area, "to", x, y) DEBUG("painting", self.visible_area, "to", x, y)
local inner_offset = Geom:new{x = 0, y = 0} local inner_offset = Geom:new{x = 0, y = 0}
-- draw surrounding space, if any -- draw surrounding space, if any
@ -61,14 +61,14 @@ function ReaderView:onSetDimensions(dimensions)
end end
function ReaderView:PanningUpdate(dx, dy) function ReaderView:PanningUpdate(dx, dy)
debug("pan by", dx, dy) DEBUG("pan by", dx, dy)
local old = Geom:copy(self.visible_area) local old = Geom:copy(self.visible_area)
self.visible_area:offsetWithin(self.page_area, dx, dy) self.visible_area:offsetWithin(self.page_area, dx, dy)
if self.visible_area ~= old then if self.visible_area ~= old then
-- flag a repaint -- flag a repaint
UIManager:setDirty(self.dialog) UIManager:setDirty(self.dialog)
debug(self.page_area) DEBUG(self.page_area)
debug(self.visible_area) DEBUG(self.visible_area)
end end
return true return true
end end

@ -63,13 +63,13 @@ function ReaderZooming:setZoom()
end end
function ReaderZooming:onZoom(direction) function ReaderZooming:onZoom(direction)
debug("zoom", direction) DEBUG("zoom", direction)
if direction == "in" then if direction == "in" then
self.zoom = self.zoom * 1.333333 self.zoom = self.zoom * 1.333333
elseif direction == "out" then elseif direction == "out" then
self.zoom = self.zoom * 0.75 self.zoom = self.zoom * 0.75
end end
debug("zoom is now at", self.zoom) DEBUG("zoom is now at", self.zoom)
self:onSetZoomMode("free") self:onSetZoomMode("free")
self.view:ZoomUpdate(self.zoom) self.view:ZoomUpdate(self.zoom)
return true return true
@ -77,7 +77,7 @@ end
function ReaderZooming:onSetZoomMode(what) function ReaderZooming:onSetZoomMode(what)
if self.zoom_mode ~= what then if self.zoom_mode ~= what then
debug("setting zoom mode to", what) DEBUG("setting zoom mode to", what)
self.zoom_mode = what self.zoom_mode = what
self:setZoom() self:setZoom()
end end

@ -76,7 +76,7 @@ function ReaderUI:init()
end end
function ReaderUI:onClose() function ReaderUI:onClose()
debug("closing reader") DEBUG("closing reader")
if self.document then if self.document then
self.document:close() self.document:close()
self.document = false self.document = false

@ -13,7 +13,7 @@ function getGlyph(face, charcode)
end end
local rendered_glyph = face.ftface:renderGlyph(charcode) local rendered_glyph = face.ftface:renderGlyph(charcode)
if not rendered_glyph then if not rendered_glyph then
debug("error rendering glyph (charcode=", charcode, ") for face", face) DEBUG("error rendering glyph (charcode=", charcode, ") for face", face)
return return
end end
glyph = CacheItem:new{rendered_glyph} glyph = CacheItem:new{rendered_glyph}
@ -48,7 +48,7 @@ end
function sizeUtf8Text(x, width, face, text, kerning) function sizeUtf8Text(x, width, face, text, kerning)
if text == nil then if text == nil then
debug("sizeUtf8Text called without text"); DEBUG("sizeUtf8Text called without text");
return return
end end
-- may still need more adaptive pen placement when kerning, -- may still need more adaptive pen placement when kerning,
@ -64,14 +64,14 @@ function sizeUtf8Text(x, width, face, text, kerning)
if kerning and prevcharcode then if kerning and prevcharcode then
local kern = face.ftface:getKerning(prevcharcode, charcode) local kern = face.ftface:getKerning(prevcharcode, charcode)
pen_x = pen_x + kern pen_x = pen_x + kern
--debug("prev:"..string.char(prevcharcode).." curr:"..string.char(charcode).." kern:"..kern) --DEBUG("prev:"..string.char(prevcharcode).." curr:"..string.char(charcode).." kern:"..kern)
else else
--debug("curr:"..string.char(charcode)) --DEBUG("curr:"..string.char(charcode))
end end
pen_x = pen_x + glyph.ax pen_x = pen_x + glyph.ax
pen_y_top = math.max(pen_y_top, glyph.t) pen_y_top = math.max(pen_y_top, glyph.t)
pen_y_bottom = math.max(pen_y_bottom, glyph.bb:getHeight() - glyph.t) pen_y_bottom = math.max(pen_y_bottom, glyph.bb:getHeight() - glyph.t)
--debug("ax:"..glyph.ax.." t:"..glyph.t.." r:"..glyph.r.." h:"..glyph.bb:getHeight().." w:"..glyph.bb:getWidth().." yt:"..pen_y_top.." yb:"..pen_y_bottom) --DEBUG("ax:"..glyph.ax.." t:"..glyph.t.." r:"..glyph.r.." h:"..glyph.bb:getHeight().." w:"..glyph.bb:getWidth().." yt:"..pen_y_top.." yb:"..pen_y_bottom)
prevcharcode = charcode prevcharcode = charcode
end end
end end
@ -80,7 +80,7 @@ end
function renderUtf8Text(buffer, x, y, face, text, kerning) function renderUtf8Text(buffer, x, y, face, text, kerning)
if text == nil then if text == nil then
debug("renderUtf8Text called without text"); DEBUG("renderUtf8Text called without text");
return 0 return 0
end end
-- may still need more adaptive pen placement when kerning, -- may still need more adaptive pen placement when kerning,
@ -94,10 +94,10 @@ function renderUtf8Text(buffer, x, y, face, text, kerning)
if kerning and prevcharcode then if kerning and prevcharcode then
local kern = face.ftface:getKerning(prevcharcode, charcode) local kern = face.ftface:getKerning(prevcharcode, charcode)
pen_x = pen_x + kern pen_x = pen_x + kern
--debug("prev:"..string.char(prevcharcode).." curr:"..string.char(charcode).." pen_x:"..pen_x.." kern:"..kern) --DEBUG("prev:"..string.char(prevcharcode).." curr:"..string.char(charcode).." pen_x:"..pen_x.." kern:"..kern)
buffer:addblitFrom(glyph.bb, x + pen_x + glyph.l, y - glyph.t, 0, 0, glyph.bb:getWidth(), glyph.bb:getHeight()) buffer:addblitFrom(glyph.bb, x + pen_x + glyph.l, y - glyph.t, 0, 0, glyph.bb:getWidth(), glyph.bb:getHeight())
else else
--debug(" curr:"..string.char(charcode)) --DEBUG(" curr:"..string.char(charcode))
buffer:blitFrom(glyph.bb, x + pen_x + glyph.l, y - glyph.t, 0, 0, glyph.bb:getWidth(), glyph.bb:getHeight()) buffer:blitFrom(glyph.bb, x + pen_x + glyph.l, y - glyph.t, 0, 0, glyph.bb:getWidth(), glyph.bb:getHeight())
end end
pen_x = pen_x + glyph.ax pen_x = pen_x + glyph.ax

@ -103,6 +103,6 @@ function Screen:restoreFromBB(bb)
if bb then if bb then
fb.bb:blitFullFrom(bb) fb.bb:blitFullFrom(bb)
else else
debug("Got nil bb in restoreFromSavedBB!") DEBUG("Got nil bb in restoreFromSavedBB!")
end end
end end

@ -3,7 +3,7 @@ require "ui/inputevent"
require "ui/widget" require "ui/widget"
require "ui/screen" require "ui/screen"
require "ui/dialog" require "ui/dialog"
require "settings" -- for debug(), TODO: put debug() somewhere else require "settings" -- for DEBUG(), TODO: put DEBUG() somewhere else
-- we also initialize the framebuffer -- we also initialize the framebuffer
@ -136,11 +136,11 @@ function UIManager:run()
end end
until all_tasks_checked until all_tasks_checked
--debug("---------------------------------------------------") --DEBUG("---------------------------------------------------")
--debug("exec stack", self._execution_stack) --DEBUG("exec stack", self._execution_stack)
--debug("window stack", self._window_stack) --DEBUG("window stack", self._window_stack)
--debug("dirty stack", self._dirty) --DEBUG("dirty stack", self._dirty)
--debug("---------------------------------------------------") --DEBUG("---------------------------------------------------")
-- stop when we have no window to show (bug) -- stop when we have no window to show (bug)
if #self._window_stack == 0 then if #self._window_stack == 0 then

Loading…
Cancel
Save