2013-07-30 08:21:19 +00:00
|
|
|
#!./koreader-base
|
|
|
|
|
|
|
|
require "defaults"
|
2012-05-18 23:10:57 +00:00
|
|
|
print(package.path)
|
2014-06-21 16:24:37 +00:00
|
|
|
package.path = "?.lua;common/?.lua;frontend/?.lua"
|
|
|
|
package.cpath = "?.so;common/?.so;/usr/lib/lua/?.so"
|
|
|
|
|
2014-04-22 14:40:55 +00:00
|
|
|
local DocSettings = require("docsettings")
|
|
|
|
local _ = require("gettext")
|
|
|
|
|
|
|
|
-- read settings and check for language override
|
|
|
|
-- has to be done before requiring other files because
|
|
|
|
-- they might call gettext on load
|
|
|
|
G_reader_settings = DocSettings:open(".reader")
|
|
|
|
local lang_locale = G_reader_settings:readSetting("language")
|
|
|
|
if lang_locale then
|
|
|
|
_.changeLang(lang_locale)
|
|
|
|
end
|
2013-12-20 16:07:12 +00:00
|
|
|
local UIManager = require("ui/uimanager")
|
|
|
|
local RenderText = require("ui/rendertext")
|
|
|
|
local Font = require("ui/font")
|
|
|
|
local Geom = require("ui/geometry")
|
|
|
|
local Menu = require("ui/widget/menu")
|
|
|
|
local Widget = require("ui/widget/widget")
|
|
|
|
local InfoMessage = require("ui/widget/infomessage")
|
|
|
|
local InputContainer = require("ui/widget/container/inputcontainer")
|
|
|
|
local CenterContainer = require("ui/widget/container/centercontainer")
|
|
|
|
local FrameContainer = require("ui/widget/container/framecontainer")
|
|
|
|
local ConfirmBox = require("ui/widget/confirmbox")
|
|
|
|
local TouchMenu = require("ui/widget/touchmenu")
|
|
|
|
local InputText = require("ui/widget/inputtext")
|
|
|
|
local DocumentRegistry = require("document/documentregistry")
|
2014-04-22 14:40:55 +00:00
|
|
|
local ReaderUI = require("apps/reader/readerui")
|
2013-12-20 16:07:12 +00:00
|
|
|
local Dbg = require("dbg")
|
|
|
|
local Device = require("ui/device")
|
|
|
|
local Screen = require("ui/screen")
|
2012-04-22 19:29:48 +00:00
|
|
|
|
2013-03-12 05:08:30 +00:00
|
|
|
-----------------------------------------------------
|
|
|
|
-- widget that paints the grid on the background
|
|
|
|
-----------------------------------------------------
|
2012-05-02 12:38:36 +00:00
|
|
|
TestGrid = Widget:new{}
|
2014-04-22 17:57:47 +00:00
|
|
|
TestVisible = Widget:new{}
|
2012-05-02 12:38:36 +00:00
|
|
|
|
2012-06-10 15:36:19 +00:00
|
|
|
function TestGrid:paintTo(bb)
|
2014-03-13 13:52:43 +00:00
|
|
|
v_line = math.floor(bb:getWidth() / 50)
|
|
|
|
h_line = math.floor(bb:getHeight() / 50)
|
|
|
|
for i=1,h_line do
|
|
|
|
y_num = i*50
|
|
|
|
RenderText:renderUtf8Text(bb, 0, y_num+10, Font:getFace("ffont", 12), y_num, true)
|
|
|
|
bb:paintRect(0, y_num, bb:getWidth(), 1, 10)
|
|
|
|
end
|
|
|
|
for i=1,v_line do
|
|
|
|
x_num = i*50
|
|
|
|
RenderText:renderUtf8Text(bb, x_num, 10, Font:getFace("ffont", 12), x_num, true)
|
|
|
|
bb:paintRect(x_num, 0, 1, bb:getHeight(), 10)
|
|
|
|
end
|
2012-05-02 12:38:36 +00:00
|
|
|
end
|
|
|
|
|
2014-04-22 17:57:47 +00:00
|
|
|
function TestVisible:paintTo(bb)
|
|
|
|
--Draw three lines at the borders to assess what the maximum visible coordinates are
|
2014-08-14 10:09:30 +00:00
|
|
|
|
2014-04-22 17:57:47 +00:00
|
|
|
v_line = math.floor(bb:getWidth() / 50)
|
|
|
|
h_line = math.floor(bb:getHeight() / 50)
|
|
|
|
-- Paint white background for higher contrast
|
|
|
|
bb:paintRect(0,0,bb:getWidth(),bb:getHeight() , 0)
|
|
|
|
-- Only render gridtext not lines at a more central postition, so it doesn't interfere with the
|
|
|
|
for i=1,h_line do
|
|
|
|
y_num = i*50
|
|
|
|
RenderText:renderUtf8Text(bb, 40, y_num+10, Font:getFace("ffont", 12), y_num, true)
|
|
|
|
end
|
|
|
|
for i=1,v_line do
|
|
|
|
x_num = i*50
|
|
|
|
RenderText:renderUtf8Text(bb, x_num, 40, Font:getFace("ffont", 12), x_num, true)
|
|
|
|
end
|
2014-08-14 10:09:30 +00:00
|
|
|
|
2014-04-22 17:57:47 +00:00
|
|
|
-- Handtunable minimal and maximal visible coordinates
|
2014-06-21 16:24:37 +00:00
|
|
|
local x_min = 0 + 4
|
2014-04-22 17:57:47 +00:00
|
|
|
local x_max = bb:getWidth() - 4
|
|
|
|
local y_min = 0 + 3
|
2014-06-21 16:24:37 +00:00
|
|
|
local y_max = bb:getHeight() - 3 - 12
|
2014-08-14 10:09:30 +00:00
|
|
|
|
2014-04-22 17:57:47 +00:00
|
|
|
-- Render extremes on screen
|
|
|
|
RenderText:renderUtf8Text(bb, 150, 100, Font:getFace("ffont", 22), "x_min = "..x_min, true)
|
|
|
|
RenderText:renderUtf8Text(bb, 500, 100, Font:getFace("ffont", 22), "x_max = "..x_max, true)
|
|
|
|
RenderText:renderUtf8Text(bb, 100, 150, Font:getFace("ffont", 22), "y_min = "..y_min, true)
|
|
|
|
RenderText:renderUtf8Text(bb, 100, 300, Font:getFace("ffont", 22), "y_max = "..y_max, true)
|
2014-06-21 16:24:37 +00:00
|
|
|
RenderText:renderUtf8Text(bb, 100, 500, Font:getFace("ffont", 26), "Visible screen size : "..(x_max-x_min).."x"..(y_max-y_min), true)
|
2014-08-14 10:09:30 +00:00
|
|
|
|
2014-04-22 17:57:47 +00:00
|
|
|
-- Three parallel lines at the top
|
|
|
|
bb:paintRect(x_min,y_min, x_max, 1 , 10)
|
|
|
|
bb:paintRect(x_min,y_min + 3, x_max, 1 , 10)
|
|
|
|
bb:paintRect(x_min,y_min + 6, x_max, 1 , 10)
|
2014-08-14 10:09:30 +00:00
|
|
|
|
2014-04-22 17:57:47 +00:00
|
|
|
-- Three parallel lines at the bottom
|
|
|
|
bb:paintRect(x_min,y_max, x_max, 1 , 10)
|
|
|
|
bb:paintRect(x_min,y_max - 3, x_max, 1 , 10)
|
|
|
|
bb:paintRect(x_min,y_max - 6, x_max, 1 , 10)
|
2014-08-14 10:09:30 +00:00
|
|
|
|
2014-04-22 17:57:47 +00:00
|
|
|
-- Three parallel lines at the left
|
|
|
|
bb:paintRect(x_min,y_min, 1, y_max , 10)
|
|
|
|
bb:paintRect(x_min + 3,y_min, 1, y_max, 10)
|
|
|
|
bb:paintRect(x_min + 6,y_min, 1, y_max, 10)
|
2014-08-14 10:09:30 +00:00
|
|
|
|
2014-04-22 17:57:47 +00:00
|
|
|
-- Three parallel lines at the right
|
|
|
|
bb:paintRect(x_max,y_min, 1, y_max , 10)
|
|
|
|
bb:paintRect(x_max - 3,y_min, 1, y_max, 10)
|
|
|
|
bb:paintRect(x_max - 6,y_min, 1, y_max, 10)
|
2014-08-14 10:09:30 +00:00
|
|
|
|
2014-06-21 16:24:37 +00:00
|
|
|
--Two lines spaces 600 pixels
|
|
|
|
bb:paintRect(100,600, 1, 250 , 10)
|
|
|
|
bb:paintRect(700,600, 1, 250 , 10)
|
|
|
|
RenderText:renderUtf8Text(bb, 150, 670, Font:getFace("ffont", 26), "Measure inches per 600 pixels", true)
|
|
|
|
RenderText:renderUtf8Text(bb, 150, 770, Font:getFace("ffont", 22), "Kobo Aura: 600 pixels/ 2.82 \" = "..(600/2.82).." dpi", true)
|
2014-04-22 17:57:47 +00:00
|
|
|
end
|
|
|
|
|
2013-03-12 05:08:30 +00:00
|
|
|
-----------------------------------------------------
|
2012-04-22 19:29:48 +00:00
|
|
|
-- we create a widget that paints a background:
|
2013-03-12 05:08:30 +00:00
|
|
|
-----------------------------------------------------
|
2012-04-22 19:29:48 +00:00
|
|
|
Background = InputContainer:new{
|
2014-03-13 13:52:43 +00:00
|
|
|
is_always_active = true, -- receive events when other dialogs are active
|
|
|
|
key_events = {
|
|
|
|
OpenDialog = { { "Press" } },
|
|
|
|
OpenConfirmBox = { { "Del" } },
|
|
|
|
QuitApplication = { { {"Home","Back"} } }
|
|
|
|
},
|
|
|
|
-- contains a gray rectangular desktop
|
|
|
|
FrameContainer:new{
|
|
|
|
background = 3,
|
|
|
|
bordersize = 0,
|
|
|
|
dimen = Screen:getSize(),
|
|
|
|
Widget:new{
|
|
|
|
dimen = {
|
|
|
|
w = Screen:getWidth(),
|
|
|
|
h = Screen:getHeight(),
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
2012-04-22 19:29:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function Background:onOpenDialog()
|
2014-03-13 13:52:43 +00:00
|
|
|
UIManager:show(InfoMessage:new{
|
|
|
|
text = "Example message.",
|
|
|
|
timeout = 10
|
|
|
|
})
|
2012-04-22 19:29:48 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function Background:onOpenConfirmBox()
|
2014-03-13 13:52:43 +00:00
|
|
|
UIManager:show(ConfirmBox:new{
|
|
|
|
text = "Please confirm delete"
|
|
|
|
})
|
2012-04-22 19:29:48 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function Background:onInputError()
|
2014-03-13 13:52:43 +00:00
|
|
|
UIManager:quit()
|
2012-04-22 19:29:48 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function Background:onQuitApplication()
|
2014-03-13 13:52:43 +00:00
|
|
|
UIManager:quit()
|
2012-04-22 19:29:48 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-03-12 05:08:30 +00:00
|
|
|
-----------------------------------------------------
|
2012-04-22 19:29:48 +00:00
|
|
|
-- example widget: a clock
|
2013-03-12 05:08:30 +00:00
|
|
|
-----------------------------------------------------
|
2012-04-22 19:29:48 +00:00
|
|
|
Clock = FrameContainer:new{
|
2014-03-13 13:52:43 +00:00
|
|
|
background = 0,
|
|
|
|
bordersize = 1,
|
|
|
|
margin = 0,
|
|
|
|
padding = 1
|
2012-04-22 19:29:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function Clock:schedFunc()
|
2014-03-13 13:52:43 +00:00
|
|
|
self[1]:free()
|
|
|
|
self[1] = self:getTextWidget()
|
|
|
|
UIManager:setDirty(self)
|
|
|
|
-- reschedule
|
|
|
|
-- TODO: wait until next real second shift
|
|
|
|
UIManager:scheduleIn(1, function() self:schedFunc() end)
|
2012-04-22 19:29:48 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function Clock:onShow()
|
2014-03-13 13:52:43 +00:00
|
|
|
self[1] = self:getTextWidget()
|
|
|
|
self:schedFunc()
|
2012-04-22 19:29:48 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function Clock:getTextWidget()
|
2014-03-13 13:52:43 +00:00
|
|
|
return CenterContainer:new{
|
|
|
|
dimen = { w = 300, h = 25 },
|
|
|
|
TextWidget:new{
|
|
|
|
text = os.date("%H:%M:%S"),
|
|
|
|
face = Font:getFace("cfont", 12)
|
|
|
|
}
|
|
|
|
}
|
2012-04-22 19:29:48 +00:00
|
|
|
end
|
|
|
|
|
2013-03-12 05:08:30 +00:00
|
|
|
-----------------------------------------------------
|
|
|
|
-- a confirmbox box widget
|
|
|
|
-----------------------------------------------------
|
2012-04-29 15:53:48 +00:00
|
|
|
Quiz = ConfirmBox:new{
|
2014-03-13 13:52:43 +00:00
|
|
|
text = "Tell me the truth, isn't it COOL?!",
|
|
|
|
width = 300,
|
|
|
|
ok_text = "Yes, of course.",
|
|
|
|
cancel_text = "No, it's ugly.",
|
|
|
|
cancel_callback = function()
|
|
|
|
UIManager:show(InfoMessage:new{
|
|
|
|
text="You liar!",
|
|
|
|
})
|
|
|
|
end,
|
2012-04-29 15:53:48 +00:00
|
|
|
}
|
|
|
|
|
2013-03-12 05:08:30 +00:00
|
|
|
-----------------------------------------------------
|
|
|
|
-- a menu widget
|
|
|
|
-----------------------------------------------------
|
2012-04-29 15:53:48 +00:00
|
|
|
menu_items = {
|
2014-03-13 13:52:43 +00:00
|
|
|
{text = "item1"},
|
|
|
|
{text = "item2"},
|
|
|
|
{text = "This is a very very log item whose length should exceed the width of the menu."},
|
|
|
|
{text = "item3"},
|
|
|
|
{text = "item4"},
|
|
|
|
{text = "item5"},
|
|
|
|
{text = "item6"},
|
|
|
|
{text = "item7"},
|
|
|
|
{text = "item8"},
|
|
|
|
{text = "item9"},
|
|
|
|
{text = "item10"},
|
|
|
|
{text = "item11"},
|
|
|
|
{text = "item12"},
|
|
|
|
{text = "item13"},
|
|
|
|
{text = "item14"},
|
|
|
|
{text = "item15"},
|
|
|
|
{text = "item16"},
|
|
|
|
{text = "item17"},
|
2012-04-29 15:53:48 +00:00
|
|
|
}
|
|
|
|
M = Menu:new{
|
2014-03-13 13:52:43 +00:00
|
|
|
title = "Test Menu",
|
|
|
|
item_table = menu_items,
|
|
|
|
width = 500,
|
|
|
|
height = 600,
|
2012-04-25 04:41:21 +00:00
|
|
|
}
|
2012-04-22 19:29:48 +00:00
|
|
|
|
2012-05-18 22:50:57 +00:00
|
|
|
|
2013-03-12 05:08:30 +00:00
|
|
|
-----------------------------------------------------
|
|
|
|
-- a reader view widget
|
|
|
|
-----------------------------------------------------
|
2012-05-18 22:50:57 +00:00
|
|
|
readerwindow = CenterContainer:new{
|
2014-03-13 13:52:43 +00:00
|
|
|
dimen = Screen:getSize(),
|
|
|
|
FrameContainer:new{
|
|
|
|
background = 0
|
|
|
|
}
|
2012-05-18 22:50:57 +00:00
|
|
|
}
|
|
|
|
reader = ReaderUI:new{
|
2014-03-13 13:52:43 +00:00
|
|
|
dialog = readerwindow,
|
|
|
|
dimen = Geom:new{ w = Screen:getWidth() - 100, h = Screen:getHeight() - 100 },
|
|
|
|
document = DocumentRegistry:openDocument("test/2col.pdf")
|
|
|
|
--document = DocumentRegistry:openDocument("test/djvu3spec.djvu")
|
|
|
|
--document = DocumentRegistry:openDocument("./README.TXT")
|
2012-05-18 22:50:57 +00:00
|
|
|
}
|
|
|
|
readerwindow[1][1] = reader
|
|
|
|
|
2013-03-12 05:08:30 +00:00
|
|
|
|
2013-03-14 05:59:59 +00:00
|
|
|
touch_menu = TouchMenu:new{
|
2014-03-13 13:52:43 +00:00
|
|
|
title = "Document menu",
|
|
|
|
width = Screen:getWidth(),
|
|
|
|
tab_item_table = {
|
|
|
|
{
|
|
|
|
icon = "resources/icons/appbar.pokeball.png",
|
|
|
|
{
|
|
|
|
text = "item1",
|
|
|
|
callback = function()
|
|
|
|
end,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
text = "item2",
|
|
|
|
callback = function()
|
|
|
|
end,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
text = "item3",
|
|
|
|
callback = function()
|
|
|
|
end,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
text = "item4",
|
|
|
|
callback = function()
|
|
|
|
end,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
text = "item5",
|
|
|
|
callback = function()
|
|
|
|
end,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
text = "item6",
|
|
|
|
callback = function()
|
|
|
|
end,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
text = "item7",
|
|
|
|
callback = function()
|
|
|
|
end,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
text = "item8",
|
|
|
|
callback = function()
|
|
|
|
end,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
text = "item9",
|
|
|
|
callback = function()
|
|
|
|
end,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
icon = "resources/icons/appbar.page.corner.bookmark.png",
|
|
|
|
{
|
|
|
|
text = "item10",
|
|
|
|
callback = function()
|
|
|
|
end,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
text = "item11",
|
|
|
|
callback = function()
|
|
|
|
end,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
icon = "resources/icons/appbar.home.png",
|
|
|
|
callback = function()
|
|
|
|
DEBUG("hello world!")
|
|
|
|
end
|
|
|
|
}
|
|
|
|
},
|
2013-03-13 02:50:16 +00:00
|
|
|
}
|
|
|
|
|
2013-07-30 15:08:10 +00:00
|
|
|
inputtext = InputText:new{
|
2014-03-13 13:52:43 +00:00
|
|
|
width = 400,
|
|
|
|
height = 300,
|
2013-07-30 08:21:19 +00:00
|
|
|
}
|
2013-03-13 02:50:16 +00:00
|
|
|
|
2013-03-12 05:08:30 +00:00
|
|
|
-----------------------------------------------------------------------
|
|
|
|
-- you may want to uncomment following show calls to see the changes
|
|
|
|
-----------------------------------------------------------------------
|
2012-04-22 19:29:48 +00:00
|
|
|
UIManager:show(Background:new())
|
2014-04-22 17:57:47 +00:00
|
|
|
-- UIManager:show(TestGrid)
|
|
|
|
UIManager:show(TestVisible)
|
2013-03-14 05:59:59 +00:00
|
|
|
--UIManager:show(Clock:new())
|
2013-03-13 02:50:16 +00:00
|
|
|
--UIManager:show(M)
|
|
|
|
--UIManager:show(Quiz)
|
|
|
|
--UIManager:show(readerwindow)
|
2013-07-30 08:21:19 +00:00
|
|
|
--UIManager:show(touch_menu)
|
2013-07-30 15:08:10 +00:00
|
|
|
--UIManager:show(keyboard)
|
2014-04-22 17:57:47 +00:00
|
|
|
-- UIManager:show(inputtext)
|
2012-05-02 12:38:36 +00:00
|
|
|
|
2014-06-21 16:24:37 +00:00
|
|
|
UIManager:run()
|