fix: unify font changes to all menus

pull/2/merge
Qingping Hou 12 years ago
parent f26adf97f0
commit 85cb570e88

@ -7,13 +7,20 @@ require "inputbox"
FileChooser = {
-- Class vars:
-- font for displaying file/dir names
face = freetype.newBuiltinFace("sans", 25),
fhash = "s25",
-- font for displaying toc item names
fsize = 25,
face = nil,
fhash = nil,
--face = freetype.newBuiltinFace("sans", 25),
--fhash = "s25",
-- font for paging display
sface = freetype.newBuiltinFace("sans", 16),
sfhash = "s16",
ffsize = 16,
fface = nil,
ffhash = nil,
--sface = freetype.newBuiltinFace("sans", 16),
--sfhash = "s16",
-- spacing between lines
spacing = 40,
@ -54,11 +61,23 @@ function FileChooser:setPath(newPath)
return true
end
function FileChooser:updateFont()
if self.fhash ~= FontChooser.cfont..self.fsize then
self.face = freetype.newBuiltinFace(FontChooser.cfont, self.fsize)
self.fhash = FontChooser.cfont..self.fsize
end
if self.ffhash ~= FontChooser.ffont..self.ffsize then
self.fface = freetype.newBuiltinFace(FontChooser.ffont, self.ffsize)
self.ffhash = FontChooser.ffont..self.ffsize
end
end
function FileChooser:choose(ypos, height)
local perpage = math.floor(height / self.spacing) - 1
local pagedirty = true
local markerdirty = false
self:updateFont()
local prevItem = function ()
if self.current == 1 then
@ -103,7 +122,7 @@ function FileChooser:choose(ypos, height)
renderUtf8Text(fb.bb, 50, ypos + self.spacing*c, self.face, self.fhash, self.files[i-#self.dirs], true)
end
end
renderUtf8Text(fb.bb, 39, ypos + self.spacing * perpage + 32, self.sface, self.sfhash,
renderUtf8Text(fb.bb, 39, ypos + self.spacing * perpage + 32, self.fface, self.ffhash,
"Page "..self.page.." of "..(math.floor(self.items / perpage)+1), true)
markerdirty = true
end
@ -134,12 +153,9 @@ function FileChooser:choose(ypos, height)
elseif ev.code == KEY_FW_DOWN then
nextItem()
elseif ev.code == KEY_F then -- invoke fontchooser menu
FontChooser:init()
newfont = FontChooser:choose(0, height)
if newfont ~= nil then
self.face = freetype.newBuiltinFace(newfont, 25)
clearglyphcache()
end
--FontChooser:init()
FontChooser:choose(0, height)
self:updateFont()
pagedirty = true
elseif ev.code == KEY_S then -- invoke search input
keywords = InputBox:input(height-100, 100, "Search:")
@ -150,8 +166,8 @@ function FileChooser:choose(ypos, height)
|| to test search feature in EMU mode
----------------------------------------------------------------
--]]
--FileSearcher:init("/home/dave/documents/kindle/backup/documents")
FileSearcher:init()
FileSearcher:init("/home/dave/documents/kindle/backup/documents")
--FileSearcher:init()
file = FileSearcher:choose(ypos, height, keywords)
if file then
return file

@ -1,17 +1,22 @@
require "rendertext"
require "keys"
require "graphics"
require "fontchooser"
FileSearcher = {
-- font for displaying file/dir names
face = freetype.newBuiltinFace("sans", 25),
fhash = "s25",
-- font for displaying toc item names
fsize = 25,
face = nil,
fhash = nil,
-- font for page title
tface = freetype.newBuiltinFace("Helvetica-BoldOblique", 32),
tfhash = "hbo32",
tfsize = 30,
tface = nil,
tfhash = nil,
-- font for paging display
sface = freetype.newBuiltinFace("sans", 16),
sfhash = "s16",
ffsize = 16,
fface = nil,
ffhash = nil,
-- title height
title_H = 45,
-- spacing between lines
@ -65,6 +70,23 @@ function FileSearcher:setPath(newPath)
return true
end
function FileSearcher:updateFont()
if self.fhash ~= FontChooser.cfont..self.fsize then
self.face = freetype.newBuiltinFace(FontChooser.cfont, self.fsize)
self.fhash = FontChooser.cfont..self.fsize
end
if self.tfhash ~= FontChooser.tfont..self.tfsize then
self.tface = freetype.newBuiltinFace(FontChooser.tfont, self.tfsize)
self.tfhash = FontChooser.tfont..self.tfsize
end
if self.ffhash ~= FontChooser.ffont..self.ffsize then
self.fface = freetype.newBuiltinFace(FontChooser.ffont, self.ffsize)
self.ffhash = FontChooser.ffont..self.ffsize
end
end
function FileSearcher:setSearchResult(keywords)
self.result = {}
if keywords == " " then -- one space to show all files
@ -94,6 +116,7 @@ function FileSearcher:choose(ypos, height, keywords)
local perpage = math.floor(height / self.spacing) - 2
local pagedirty = true
local markerdirty = false
self:updateFont()
local prevItem = function ()
if self.current == 1 then
@ -163,7 +186,7 @@ function FileSearcher:choose(ypos, height, keywords)
y = ypos + self.title_H + (self.spacing * perpage) + self.foot_H
x = (fb.bb:getWidth() / 2) - 50
all_page = (math.floor(self.items / perpage)+1)
renderUtf8Text(fb.bb, x, y, self.sface, self.sfhash,
renderUtf8Text(fb.bb, x, y, self.fface, self.ffhash,
"Page "..self.page.." of "..all_page, true)
end

@ -3,15 +3,27 @@ require "keys"
require "graphics"
FontChooser = {
-- font name for content
cfont = "sans",
-- font for displaying file/dir names
face = freetype.newBuiltinFace("sans", 25),
fhash = "s25",
fsize = 25,
face = nil,
fhash = nil,
-- font name for title
tfont = "Helvetica-BoldOblique",
-- font for page title
tface = freetype.newBuiltinFace("Helvetica-BoldOblique", 30),
tfhash = "hbo30",
-- font for paging display
sface = freetype.newBuiltinFace("sans", 16),
sfhash = "s16",
tfsize = 30,
tface = nil,
tfhash = nil,
-- font name for footer
ffont = "sans",
-- font for page footer display
ffsize = 16,
fface = nil,
ffhash = nil,
-- title height
title_H = 45,
-- spacing between lines
@ -35,11 +47,28 @@ function FontChooser:init()
self.items = #self.fonts
end
function FontChooser:updateFont()
if self.fhash ~= FontChooser.cfont..self.fsize then
self.face = freetype.newBuiltinFace(FontChooser.cfont, self.fsize)
self.fhash = FontChooser.cfont..self.fsize
end
if self.tfhash ~= FontChooser.tfont..self.tfsize then
self.tface = freetype.newBuiltinFace(FontChooser.tfont, self.tfsize)
self.tfhash = FontChooser.tfont..self.tfsize
end
if self.ffhash ~= FontChooser.ffont..self.ffsize then
self.fface = freetype.newBuiltinFace(FontChooser.ffont, self.ffsize)
self.ffhash = FontChooser.ffont..self.ffsize
end
end
function FontChooser:choose(ypos, height)
local perpage = math.floor(height / self.spacing) - 2
local pagedirty = true
local markerdirty = false
self:updateFont()
local prevItem = function ()
if self.current == 1 then
@ -95,7 +124,7 @@ function FontChooser:choose(ypos, height)
-- draw footer
y = ypos + self.title_H + (self.spacing * perpage) + self.foot_H
x = (fb.bb:getWidth() / 2) - 50
renderUtf8Text(fb.bb, x, y, self.sface, self.sfhash,
renderUtf8Text(fb.bb, x, y, self.fface, self.ffhash,
"Page "..self.page.." of "..(math.floor(self.items / perpage)+1), true)
markerdirty = true
end
@ -150,8 +179,9 @@ function FontChooser:choose(ypos, height)
markerdirty = true
end
elseif ev.code == KEY_ENTER or ev.code == KEY_FW_PRESS then
local newface = self.fonts[perpage*(self.page-1)+self.current]
return newface
self.cfont = self.fonts[perpage*(self.page-1)+self.current]
clearglyphcache()
return nil
elseif ev.code == KEY_BACK then
return nil
end

@ -1,17 +1,22 @@
require "rendertext"
require "keys"
require "graphics"
require "fontchooser"
TOCMenu = {
-- font for displaying file/dir names
face = freetype.newBuiltinFace("cjk", 22),
fhash = "s22",
-- font for displaying toc item names
fsize = 22,
face = nil,
fhash = nil,
-- font for page title
tface = freetype.newBuiltinFace("Helvetica-BoldOblique", 25),
tfhash = "hbo25",
tfsize = 25,
tface = nil,
tfhash = nil,
-- font for paging display
sface = freetype.newBuiltinFace("sans", 16),
sfhash = "s16",
ffsize = 16,
fface = nil,
ffhash = nil,
-- title height
title_H = 40,
-- spacing between lines
@ -28,8 +33,6 @@ TOCMenu = {
}
function TOCMenu:new(toc)
--@TODO set font here in the future 21.02 2012
--clearglyphcache()
instance = self
instance.toc = toc
instance.items = #toc
@ -45,10 +48,28 @@ function TOCMenu:dump()
end
end
function TOCMenu:updateFont()
if self.fhash ~= FontChooser.cfont..self.fsize then
self.face = freetype.newBuiltinFace(FontChooser.cfont, self.fsize)
self.fhash = FontChooser.cfont..self.fsize
end
if self.tfhash ~= FontChooser.tfont..self.tfsize then
self.tface = freetype.newBuiltinFace(FontChooser.tfont, self.tfsize)
self.tfhash = FontChooser.tfont..self.tfsize
end
if self.ffhash ~= FontChooser.ffont..self.ffsize then
self.fface = freetype.newBuiltinFace(FontChooser.ffont, self.ffsize)
self.ffhash = FontChooser.ffont..self.ffsize
end
end
function TOCMenu:choose(ypos, height)
local perpage = math.floor(height / self.spacing) - 2
local pagedirty = true
local markerdirty = false
self:updateFont()
local prevItem = function ()
if self.current == 1 then
@ -99,7 +120,7 @@ function TOCMenu:choose(ypos, height)
"Oops... Bad news for you:", true)
y = y + self.spacing
renderUtf8Text(fb.bb, 30, y, self.face, self.fhash,
"This document does not have a Table of Conent.", true)
"This document doesn't have a TOC.", true)
markerdirty = false
else
local c
@ -116,7 +137,7 @@ function TOCMenu:choose(ypos, height)
-- draw footer
y = ypos + self.title_H + (self.spacing * perpage) + self.foot_H + 5
x = (fb.bb:getWidth() / 2) - 50
renderUtf8Text(fb.bb, x, y, self.sface, self.sfhash,
renderUtf8Text(fb.bb, x, y, self.fface, self.ffhash,
"Page "..self.page.." of "..(math.floor(self.items / perpage)+1), true)
end

Loading…
Cancel
Save