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

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

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

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

Loading…
Cancel
Save