Merge pull request #803 from houqp/new_ui_houqp

some minor adjustments & finished up touchmenu
pull/2/merge
Huang Xin 11 years ago
commit 1f01537751

2
.gitignore vendored

@ -14,6 +14,7 @@ git-rev
kpdfview
slider_watcher
*.o
tags
kindlepdfviewer-*.zip
@ -46,3 +47,4 @@ popen-noshell/popen_noshell_examples.c
popen-noshell/popen_noshell_tests.c
popen-noshell/popen_noshell_tests.cpp
kpvcrlib/libcrengine.so

@ -43,8 +43,8 @@ function Font:getFace(font, size)
-- default to content font
font = self.cfont
end
local size = math.floor(size*Screen:getDPI()/167)
local size = math.floor(scaleByDPI(size))
local face = self.faces[font..size]
-- build face if not found

@ -7,7 +7,7 @@ PageCropDialog = VerticalGroup:new{
cancel_text = "Cancel",
ok_callback = function() end,
cancel_callback = function() end,
button_width = math.floor(70*Screen:getDPI()/167),
button_width = math.floor(scaleByDPI(70)),
}
function PageCropDialog:init()

@ -13,11 +13,11 @@ function ReaderFont:init()
-- add shortcut for keyboard
self.key_events = {
ShowFontMenu = { {"F"}, doc = "show font menu" },
IncreaseSize = {
{ "Shift", Input.group.PgFwd },
doc = "increase font size",
IncreaseSize = {
{ "Shift", Input.group.PgFwd },
doc = "increase font size",
event = "ChangeSize", args = "increase" },
DecreaseSize = {
DecreaseSize = {
{ "Shift", Input.group.PgBack },
doc = "decrease font size",
event = "ChangeSize", args = "decrease" },
@ -52,33 +52,33 @@ end
function ReaderFont:onReadSettings(config)
self.font_face = config:readSetting("font_face")
if not self.font_face then
if not self.font_face then
self.font_face = self.ui.document.default_font
end
self.ui.document:setFontFace(self.font_face)
self.header_font_face = config:readSetting("header_font_face")
if not self.header_font_face then
if not self.header_font_face then
self.header_font_face = self.ui.document.header_font
end
self.ui.document:setHeaderFont(self.header_font_face)
self.font_size = config:readSetting("font_size")
if not self.font_size then
if not self.font_size then
--@TODO change this! 12.01 2013 (houqp)
self.font_size = 29
end
self.ui.document:setFontSize(self.font_size)
self.line_space_percent = config:readSetting("line_space_percent")
if not self.line_space_percent then
if not self.line_space_percent then
self.line_space_percent = 100
else
self.ui.document:setInterlineSpacePercent(self.line_space_percent)
end
self.gamma_index = config:readSetting("gamma_index")
if not self.gamma_index then
if not self.gamma_index then
self.gamma_index = 15
end
self.ui.document:setGammaIndex(self.gamma_index)
@ -104,7 +104,7 @@ function ReaderFont:onShowFontMenu()
main_menu,
dimen = Screen:getSize(),
}
main_menu.close_callback = function ()
main_menu.close_callback = function ()
UIManager:close(menu_container)
end
-- show menu

@ -6,38 +6,38 @@ ReaderPaging = InputContainer:new{
visible_area = nil,
page_area = nil,
show_overlap_enable = true,
overlap = 20 * Screen:getDPI()/167,
overlap = scaleByDPI(20),
}
function ReaderPaging:init()
if Device:hasKeyboard() then
self.key_events = {
GotoNextPage = {
GotoNextPage = {
{Input.group.PgFwd}, doc = "go to next page",
event = "GotoPageRel", args = 1 },
GotoPrevPage = {
GotoPrevPage = {
{Input.group.PgBack}, doc = "go to previous page",
event = "GotoPageRel", args = -1 },
GotoFirst = {
GotoFirst = {
{"1"}, doc = "go to start", event = "GotoPercent", args = 0},
Goto11 = {
Goto11 = {
{"2"}, doc = "go to 11%", event = "GotoPercent", args = 11},
Goto22 = {
Goto22 = {
{"3"}, doc = "go to 22%", event = "GotoPercent", args = 22},
Goto33 = {
Goto33 = {
{"4"}, doc = "go to 33%", event = "GotoPercent", args = 33},
Goto44 = {
Goto44 = {
{"5"}, doc = "go to 44%", event = "GotoPercent", args = 44},
Goto55 = {
Goto55 = {
{"6"}, doc = "go to 55%", event = "GotoPercent", args = 55},
Goto66 = {
Goto66 = {
{"7"}, doc = "go to 66%", event = "GotoPercent", args = 66},
Goto77 = {
Goto77 = {
{"8"}, doc = "go to 77%", event = "GotoPercent", args = 77},
Goto88 = {
Goto88 = {
{"9"}, doc = "go to 88%", event = "GotoPercent", args = 88},
GotoLast = {
GotoLast = {
{"0"}, doc = "go to end", event = "GotoPercent", args = 100},
}
end
@ -62,7 +62,7 @@ function ReaderPaging:initGesListener()
GestureRange:new{
ges = "tap",
range = Geom:new{
x = 0,
x = 0,
y = Screen:getHeight()/4,
w = Screen:getWidth()/4,
h = 5*Screen:getHeight()/8,
@ -361,7 +361,7 @@ function ReaderPaging:onScrollPageRel(diff)
}
-- Scroll down offset should always be greater than 0
-- otherwise if offset is less than 0 the height of blank area will be
-- larger than 0 even if page area is much larger than visible area,
-- larger than 0 even if page area is much larger than visible area,
-- which will trigger the drawing of next page leaving part of current
-- page undrawn. This should also be true for scroll up offset.
if offset.y < 0 then offset.y = 0 end

@ -3,14 +3,14 @@ ReaderScreenshot = InputContainer:new{}
function ReaderScreenshot:init()
local diagonal = math.sqrt(
math.pow(Screen:getWidth(), 2) +
math.pow(Screen:getWidth(), 2) +
math.pow(Screen:getHeight(), 2)
)
self.ges_events = {
Screenshot = {
GestureRange:new{
ges = "two_finger_tap",
scale = {diagonal - 80*Screen:getDPI()/167, diagonal},
scale = {diagonal - scaleByDPI(80), diagonal},
rate = 1.0,
}
},

@ -5,7 +5,7 @@ require "ui/reader/readerdogear"
ReaderView = OverlapGroup:new{
_name = "ReaderView",
document = nil,
-- single page state
state = {
page = 0,
@ -23,8 +23,8 @@ ReaderView = OverlapGroup:new{
page_states = {},
scroll_mode = "vertical",
page_gap = {
width = 8 * Screen:getDPI()/167,
height = 8 * Screen:getDPI()/167,
width = scaleByDPI(8),
height = scaleByDPI(8),
color = 8,
},
-- DjVu page rendering mode (used in djvu.c:drawPage())
@ -32,14 +32,14 @@ ReaderView = OverlapGroup:new{
-- Crengine view mode
view_mode = "page", -- default to page mode
hinting = true,
-- visible area within current viewing page
visible_area = Geom:new{x = 0, y = 0},
-- dimen for current viewing page
page_area = Geom:new{},
-- dimen for area to dim
dim_area = Geom:new{w = 0, h = 0},
-- has footer
-- has footer
footer_visible = false,
-- has dogear
dogear_visible = false,
@ -73,7 +73,7 @@ function ReaderView:paintTo(bb, x, y)
else
self:drawPageSurround(bb, x, y)
end
-- draw page content
if self.ui.document.info.has_pages then
if self.page_scroll then
@ -88,16 +88,16 @@ function ReaderView:paintTo(bb, x, y)
self:drawScrollView(bb, x, y)
end
end
-- dim last read area
if self.document.view_mode ~= "page"
if self.document.view_mode ~= "page"
and self.dim_area.w ~= 0 and self.dim_area.h ~= 0 then
bb:dimRect(
self.dim_area.x, self.dim_area.y,
self.dim_area.w, self.dim_area.h
)
end
-- paint dogear
if self.dogear_visible then
self.dogear:paintTo(bb, x, y)
@ -119,12 +119,12 @@ end
function ReaderView:drawPageSurround(bb, x, y)
if self.dimen.h > self.visible_area.h then
bb:paintRect(x, y, self.dimen.w, self.state.offset.y, self.outer_page_color)
bb:paintRect(x, y + self.dimen.h - self.state.offset.y - 1,
bb:paintRect(x, y + self.dimen.h - self.state.offset.y - 1,
self.dimen.w, self.state.offset.y + 1, self.outer_page_color)
end
if self.dimen.w > self.visible_area.w then
bb:paintRect(x, y, self.state.offset.x, self.dimen.h, self.outer_page_color)
bb:paintRect(x + self.dimen.w - self.state.offset.x - 1, y,
bb:paintRect(x + self.dimen.w - self.state.offset.x - 1, y,
self.state.offset.x + 1, self.dimen.h, self.outer_page_color)
end
end
@ -143,7 +143,7 @@ function ReaderView:drawScrollPages(bb, x, y)
state.gamma,
self.render_mode)
pos.y = pos.y + state.visible_area.h
-- draw page gap if not the last part
-- draw page gap if not the last part
if page ~= #self.page_states then
self:drawPageGap(bb, pos.x, pos.y)
pos.y = pos.y + self.page_gap.height

@ -18,7 +18,7 @@
--[[
Codes for rotation modes:
1 for no rotation,
1 for no rotation,
2 for landscape with bottom on the right side of screen, etc.
2
@ -26,8 +26,8 @@ Codes for rotation modes:
| +----------+ |
| | | |
| | Freedom! | |
| | | |
| | | |
| | | |
| | | |
3 | | | | 1
| | | |
| | | |
@ -99,6 +99,15 @@ function Screen:getDPI()
return Device:getModel() == "KindlePaperWhite" and 212 or 167
end
function Screen:scaleByDPI(px)
return (px * self:getDPI()/167)
end
-- make a shortcut to Screen:scaleByDPI
function scaleByDPI(px)
return Screen:scaleByDPI(px)
end
function Screen:getPitch()
return self.fb:getPitch()
end

@ -159,7 +159,9 @@ function ConfigOption:init()
local default_option_height = 50
local default_option_padding = 15
local vertical_group = VerticalGroup:new{}
table.insert(vertical_group, VerticalSpan:new{ width = default_option_padding * Screen:getDPI()/167 })
table.insert(vertical_group, VerticalSpan:new{
width = scaleByDPI(default_option_padding),
})
for c = 1, #self.options do
if self.options[c].show ~= false then
local name_align = self.options[c].name_align_right and self.options[c].name_align_right or 0.33
@ -168,9 +170,9 @@ function ConfigOption:init()
local name_font_size = self.options[c].name_font_size and self.options[c].name_font_size or default_name_font_size
local item_font_face = self.options[c].item_font_face and self.options[c].item_font_face or "cfont"
local item_font_size = self.options[c].item_font_size and self.options[c].item_font_size or default_item_font_size
local option_height = (self.options[c].height and self.options[c].height or default_option_height) * Screen:getDPI()/167
local option_height = scaleByDPI(self.options[c].height and self.options[c].height or default_option_height)
local items_spacing = HorizontalSpan:new{
width = (self.options[c].spacing and self.options[c].spacing or default_items_spacing) * Screen:getDPI()/167
width = scaleByDPI(self.options[c].spacing and self.options[c].spacing or default_items_spacing)
}
local horizontal_group = HorizontalGroup:new{}
if self.options[c].name_text then

@ -59,7 +59,7 @@ end
TouchMenuBar widget
--]]
TouchMenuBar = InputContainer:new{
height = 70 * Screen:getDPI()/167,
height = scaleByDPI(70),
width = Screen:getWidth(),
icons = {},
-- touch menu that holds the bar, used for trigger repaint on icons
@ -79,12 +79,12 @@ function TouchMenuBar:init()
local icon_sep = LineWidget:new{
dimen = Geom:new{
w = 2,
w = scaleByDPI(2),
h = self.height,
}
}
local icon_span = HorizontalSpan:new{ width = 20 }
local icon_span = HorizontalSpan:new{ width = scaleByDPI(20) }
-- build up image widget for menu icon bar
self.icon_widgets = {}
@ -113,7 +113,7 @@ function TouchMenuBar:init()
self.bar_sep = LineWidget:new{
dimen = Geom:new{
w = self.width,
h = 2,
h = scaleByDPI(2),
},
empty_segments = {
{
@ -159,12 +159,11 @@ TouchMenu widget
TouchMenu = InputContainer:new{
tab_item_table = {},
-- for returnning in multi-level menus
item_table_stack = {},
item_table_stack = nil,
item_table = nil,
--@TODO replace getDPI call (houqp)
item_height = 50 * Screen:getDPI()/167,
bordersize = 2 * Screen:getDPI()/167,
padding = 5 * Screen:getDPI()/167,
item_height = scaleByDPI(50),
bordersize = scaleByDPI(2),
padding = scaleByDPI(5),
width = Screen:getWidth(),
height = nil,
page = 1,
@ -193,6 +192,12 @@ function TouchMenu:init()
}
}
}
self.ges_events.Swipe = {
GestureRange:new{
ges = "swipe",
range = self.dimen,
}
}
local icons = {}
for _,v in ipairs(self.tab_item_table) do
@ -209,15 +214,20 @@ function TouchMenu:init()
align = "left",
}
self.footer_page = TextWidget:new{
face = Font:getFace("ffont", 20),
text = "",
}
self.footer = HorizontalGroup:new{
IconButton:new{
invert = true,
icon_file = "resources/icons/appbar.chevron.left.png",
icon_file = "resources/icons/appbar.chevron.up.png",
show_parent = self.show_parent,
callback = function()
self:backToUpperMenu()
end,
}
},
self.footer_page,
}
self[1] = FrameContainer:new{
@ -277,7 +287,7 @@ function TouchMenu:updateItems()
if c ~= self.perpage then
table.insert(self.item_group, HorizontalGroup:new{
-- pad with spacing
HorizontalSpan:new{width = 10},
HorizontalSpan:new{width = scaleByDPI(10)},
LineWidget:new{
style = "dashed",
dimen = Geom:new{
@ -297,8 +307,9 @@ function TouchMenu:updateItems()
end -- if i <= self.items
end -- for c=1, self.perpage
table.insert(self.item_group, VerticalSpan:new{width = 2})
table.insert(self.item_group, VerticalSpan:new{width = scaleByDPI(2)})
table.insert(self.item_group, self.footer)
self.footer_page.text = "Page "..self.page.."/"..self.page_num
-- FIXME: this is a dirty hack to clear previous menus
-- refert to issue #664
UIManager.repaint_all = true
@ -306,6 +317,10 @@ end
function TouchMenu:switchMenuTab(tab_num)
if self.cur_tab ~= tab_num then
-- it's like getting a new menu everytime we switch tab!
self.page = 1
-- clear item table stack
self.item_table_stack = {}
self.cur_tab = tab_num
self.item_table = self.tab_item_table[tab_num]
self:updateItems()
@ -323,6 +338,30 @@ function TouchMenu:closeMenu()
self.close_callback()
end
function TouchMenu:onNextPage()
if self.page < self.page_num then
self.page = self.page + 1
self:updateItems()
end
return true
end
function TouchMenu:onPrevPage()
if self.page > 1 then
self.page = self.page - 1
self:updateItems()
end
return true
end
function TouchMenu:onSwipe(arg, ges_ev)
if ges_ev.direction == "left" then
self:onNextPage()
elseif ges_ev.direction == "right" then
self:onPrevPage()
end
end
function TouchMenu:onMenuSelect(item)
if item.sub_item_table == nil then
if item.callback then

@ -29,6 +29,19 @@ HomeMenu = InputContainer:new{
},
}
function exitReader()
G_reader_settings:close()
input.closeAll()
if util.isEmulated() ==0 then
if Device:isKindle3() or (Device:getModel() == "KindleDXG") then
-- send double menu key press events to trigger screen refresh
os.execute("echo 'send 139' > /proc/keypad;echo 'send 139' > /proc/keypad")
end
end
end
function HomeMenu:setUpdateItemTable()
function readHistDir(order_arg, re)
local pipe_out = io.popen("ls "..order_arg.." -1 ./history")
@ -59,7 +72,7 @@ function HomeMenu:setUpdateItemTable()
table.insert(self.item_table, {
text = "Exit",
callback = function()
os.exit(0)
exitReader()
end
})
end
@ -96,6 +109,7 @@ function showReader(file, pass)
return
end
G_reader_settings:saveSetting("lastfile", file)
local reader = ReaderUI:new{
dialog = readerwindow,
dimen = Screen:getSize(),
@ -200,7 +214,7 @@ local last_file = G_reader_settings:readSetting("lastfile")
--87712cf0e43fed624f8a9f610be42b1fe174b9fe
if ARGV[argidx] then
if ARGV[argidx] and ARGV[argidx] ~= "" then
if lfs.attributes(ARGV[argidx], "mode") == "directory" then
showHomePage(ARGV[argidx])
elseif lfs.attributes(ARGV[argidx], "mode") == "file" then
@ -214,11 +228,4 @@ else
return showusage()
end
input.closeAll()
if util.isEmulated()==0 then
if Device:isKindle3() or (Device:getModel() == "KindleDXG") then
-- send double menu key press events to trigger screen refresh
os.execute("echo 'send 139' > /proc/keypad;echo 'send 139' > /proc/keypad")
end
end
exitReader()

Binary file not shown.

After

Width:  |  Height:  |  Size: 776 B

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" baseProfile="full" width="76" height="76" viewBox="0 0 76.00 76.00" enable-background="new 0 0 76.00 76.00" xml:space="preserve">
<path fill="#000000" fill-opacity="1" stroke-width="0.2" stroke-linejoin="round" d="M 37.8516,35.625L 34.6849,38.7917L 23.6016,50.2708L 23.6016,39.9792L 37.8516,24.9375L 52.1016,39.9792L 52.1016,50.2708L 41.0182,38.7917L 37.8516,35.625 Z "/>
</svg>
Loading…
Cancel
Save