Further refactoring

This should finish the work to make all globals to local variables.
That allows LuaJIT to properly compile things by interning the
references to the relevant parts (rather than looking up globals
all the time which stops a trace).
pull/334/head
HW 11 years ago
parent ef111b99c6
commit 2154e7e852

@ -1,4 +1,6 @@
local InputContainer = require("ui/widget/container/inputcontainer")
local CenterContainer = require("ui/widget/container/centercontainer")
local Menu = require("ui/widget/menu")
local Screen = require("ui/screen")
local UIManager = require("ui/uimanager")
local DocSettings = require("docsettings")

@ -2,6 +2,8 @@ local Geom = require("ui/geometry")
local CreOptions = require("ui/data/creoptions")
local Document = require("document/document")
local Configurable = require("ui/reader/configurable")
local Font = require("ui/font")
local Screen = require("ui/screen")
-- TBD: DrawContext
local CreDocument = Document:new{
@ -22,7 +24,7 @@ local CreDocument = Document:new{
}
-- NuPogodi, 20.05.12: inspect the zipfile content
function CreDocument:zipContentExt(fname)
function CreDocument.zipContentExt(self, fname)
local outfile = "./data/zip_content"
local s = ""
os.execute("unzip ".."-l \""..fname.."\" > "..outfile)

@ -2,6 +2,9 @@ local Document = require("document/document")
local Cache = require("cache")
local CacheItem = require("cacheitem")
local Screen = require("ui/screen")
local Geom = require("ui/geometry")
local TileCacheItem = require("document/tilecacheitem")
local Dbg = require("dbg")
-- TBD: KOPTContext
local KoptInterface = {

@ -1,8 +1,7 @@
local KindleFrontLight = require("ui/device/kindlefrontlight")
local KoboFrontLight = require("ui/device/kobofrontlight")
local BaseFrontLight = require("ui/device/basefrontlight")
-- Screen
local Screen = require("ui/device/screen")
-- util
-- lfs
@ -14,8 +13,11 @@ local Device = {
model = nil,
firmware_rev = nil,
frontlight = nil,
screen = Screen
}
Screen.device = Device
function Device:getModel()
if self.model then return self.model end
if util.isEmulated() then
@ -117,7 +119,7 @@ end
function Device:intoScreenSaver()
--os.execute("echo 'screensaver in' >> /mnt/us/event_test.txt")
if self.charging_mode == false and self.screen_saver_mode == false then
Screen:saveCurrentBB()
self.screen:saveCurrentBB()
--UIManager:show(InfoMessage:new{
--text = "Going into screensaver... ",
--timeout = 2,
@ -135,8 +137,8 @@ function Device:outofScreenSaver()
-- Blitbuffer.
util.usleep(1500000)
--os.execute("killall -stop cvm")
Screen:restoreFromSavedBB()
Screen:refresh(0)
self.screen:restoreFromSavedBB()
self.screen:refresh(0)
self.survive_screen_saver = true
end
self.screen_saver_mode = false
@ -147,7 +149,7 @@ function Device:prepareSuspend() -- currently only used for kobo devices
if fl ~= nil then
fl.fl:sleep()
end
Screen:refresh(0)
self.screen:refresh(0)
self.screen_saver_mode = true
end
@ -157,7 +159,7 @@ end
function Device:Resume() -- currently only used for kobo devices
os.execute("echo 0 > /sys/power/state-extended")
Screen:refresh(0)
self.screen:refresh(0)
local fl = self:getFrontlight()
if fl ~= nil then
fl.fl:restore()
@ -168,7 +170,7 @@ end
function Device:usbPlugIn()
--os.execute("echo 'usb in' >> /mnt/us/event_test.txt")
if self.charging_mode == false and self.screen_saver_mode == false then
Screen:saveCurrentBB()
self.screen:saveCurrentBB()
--UIManager:show(InfoMessage:new{
--text = "Going into USB mode... ",
--timeout = 2,
@ -184,8 +186,8 @@ function Device:usbPlugOut()
if self.charging_mode == true and self.screen_saver_mode == false then
--util.usleep(1500000)
--os.execute("killall -stop cvm")
Screen:restoreFromSavedBB()
Screen:refresh(0)
self.screen:restoreFromSavedBB()
self.screen:refresh(0)
end
--@TODO signal filemanager for file changes 13.06 2012 (houqp)

@ -0,0 +1,211 @@
local Geom = require("ui/geometry")
-- Blitbuffer
-- einkfb
--[[
Codes for rotation modes:
1 for no rotation,
2 for landscape with bottom on the right side of screen, etc.
2
+--------------+
| +----------+ |
| | | |
| | Freedom! | |
| | | |
| | | |
3 | | | | 1
| | | |
| | | |
| +----------+ |
| |
| |
+--------------+
0
--]]
local Screen = {
width = 0,
height = 0,
native_rotation_mode = nil,
cur_rotation_mode = 0,
bb = nil,
saved_bb = nil,
fb = einkfb.open("/dev/fb0"),
-- will be set upon loading by Device class:
device = nil,
}
function Screen:init()
-- for unknown strange reason, pitch*2 is 10 px more than screen width in KPW
self.width, self.height = self.fb:getSize()
-- Blitbuffer still uses inverted 4bpp bitmap, so pitch should be
-- (self.width / 2)
self.bb = Blitbuffer.new(self.width, self.height, self.width/2)
if self.width > self.height then
-- For another unknown strange reason, self.fb:getOrientation always
-- return 0 in KPW, even though we are in landscape mode.
-- Seems like the native framework change framebuffer on the fly when
-- starting booklet. Starting KPV from ssh and KPVBooklet will get
-- different framebuffer height and width.
--
--self.native_rotation_mode = self.fb:getOrientation()
self.native_rotation_mode = 1
else
self.native_rotation_mode = 0
end
self.cur_rotation_mode = self.native_rotation_mode
end
function Screen:refresh(refesh_type, waveform_mode, x, y, w, h)
if x then x = x < 0 and 0 or math.floor(x) end
if y then y = y < 0 and 0 or math.floor(y) end
if w then w = w + x > self.width and self.width - x or math.ceil(w) end
if h then h = h + y > self.height and self.height - y or math.ceil(h) end
if self.native_rotation_mode == self.cur_rotation_mode then
self.fb.bb:blitFrom(self.bb, 0, 0, 0, 0, self.width, self.height)
elseif self.native_rotation_mode == 0 and self.cur_rotation_mode == 1 then
self.fb.bb:blitFromRotate(self.bb, 270)
if x and y and w and h then
x, y = y, self.width - w - x
w, h = h, w
end
elseif self.native_rotation_mode == 0 and self.cur_rotation_mode == 3 then
self.fb.bb:blitFromRotate(self.bb, 90)
if x and y and w and h then
x, y = self.height - h - y, x
w, h = h, w
end
elseif self.native_rotation_mode == 1 and self.cur_rotation_mode == 0 then
self.fb.bb:blitFromRotate(self.bb, 90)
if x and y and w and h then
x, y = self.height - h - y, x
w, h = h, w
end
elseif self.native_rotation_mode == 1 and self.cur_rotation_mode == 3 then
self.fb.bb:blitFromRotate(self.bb, 180)
if x and y and w and h then
x, y = self.width - w - x, self.height - h - y
end
end
self.fb:refresh(refesh_type, waveform_mode, x, y, w, h)
end
function Screen:getSize()
return Geom:new{w = self.width, h = self.height}
end
function Screen:getWidth()
return self.width
end
function Screen:getHeight()
return self.height
end
function Screen:getDPI()
if(self.device:getModel() == "KindlePaperWhite") or (self.device:getModel() == "Kobo_kraken") then
return 212
elseif self.device:getModel() == "Kobo_dragon" then
return 265
elseif self.device:getModel() == "Kobo_pixie" then
return 200
else
return 167
end
end
function Screen:scaleByDPI(px)
return math.floor(px * self:getDPI()/167)
end
function Screen:rescaleByDPI(px)
return math.ceil(px * 167/self:getDPI())
end
function Screen:getPitch()
return self.fb:getPitch()
end
function Screen:getNativeRotationMode()
-- in EMU mode, you will always get 0 from getOrientation()
return self.fb:getOrientation()
end
function Screen:getRotationMode()
return self.cur_rotation_mode
end
function Screen:getScreenMode()
if self.width > self.height then
return "landscape"
else
return "portrait"
end
end
function Screen:setRotationMode(mode)
if mode > 3 or mode < 0 then
return
end
-- mode 0 and mode 2 has the same width and height, so do mode 1 and 3
if (self.cur_rotation_mode % 2) ~= (mode % 2) then
self.width, self.height = self.height, self.width
end
self.cur_rotation_mode = mode
self.bb:free()
self.bb = Blitbuffer.new(self.width, self.height, self.width/2)
end
function Screen:setScreenMode(mode)
if mode == "portrait" then
if self.cur_rotation_mode ~= 0 then
self:setRotationMode(0)
end
elseif mode == "landscape" then
if self.cur_rotation_mode == 0 or self.cur_rotation_mode == 2 then
self:setRotationMode(1)
elseif self.cur_rotation_mode == 1 or self.cur_rotation_mode == 3 then
self:setRotationMode((self.cur_rotation_mode + 2) % 4)
end
end
end
function Screen:saveCurrentBB()
local width, height = self:getWidth(), self:getHeight()
if not self.saved_bb then
self.saved_bb = Blitbuffer.new(width, height, self.width/2)
end
if self.saved_bb:getWidth() ~= width then
self.saved_bb:free()
self.saved_bb = Blitbuffer.new(width, height, self.width/2)
end
self.saved_bb:blitFullFrom(self.bb)
end
function Screen:restoreFromSavedBB()
self:restoreFromBB(self.saved_bb)
end
function Screen:getCurrentScreenBB()
local bb = Blitbuffer.new(self:getWidth(), self:getHeight())
bb:blitFullFrom(self.bb)
return bb
end
function Screen:restoreFromBB(bb)
if bb then
self.bb:blitFullFrom(bb)
else
DEBUG("Got nil bb in restoreFromSavedBB!")
end
end
return Screen

@ -1,4 +1,4 @@
-- TimeVal
local TimeVal = require("ui/timeval")
local GestureRange = {
ges = nil,

@ -1,4 +1,5 @@
local EventListener = require("ui/widget/eventlistener")
local Event = require("ui/event")
local ReaderCoptListener = EventListener:new{}

@ -8,8 +8,9 @@ local RightContainer = require("ui/widget/container/rightcontainer")
local FrameContainer = require("ui/widget/container/framecontainer")
local VerticalGroup = require("ui/widget/verticalgroup")
local HorizontalGroup = require("ui/widget/horizontalgroup")
local BBoxWidget = require("ui/widget/bboxwidget")
local HorizontalSpan = require("ui/widget/horizontalspan")
local Button = require("ui/widget/button")
local _ = require("gettext")
local PageCropDialog = VerticalGroup:new{
ok_text = "OK",

@ -1,6 +1,7 @@
local EventListener = require("ui/widget/eventlistener")
local UIManager = require("ui/uimanager")
local DictQuickLookup = require("ui/widget/dictquicklookup")
local Screen = require("ui/screen")
local JSON = require("JSON")
local ReaderDictionary = EventListener:new{}

@ -1,6 +1,11 @@
local InputContainer = require("ui/widget/container/inputcontainer")
local CenterContainer = require("ui/widget/container/centercontainer")
local Menu = require("ui/widget/menu")
local Notification = require("ui/widget/notification")
local Device = require("ui/device")
local Screen = require("ui/screen")
local Input = require("ui/input")
local Event = require("ui/event")
local UIManager = require("ui/uimanager")
local _ = require("gettext")

@ -3,6 +3,9 @@ local Geom = require("ui/geometry")
local Screen = require("ui/screen")
local Device = require("ui/device")
local GestureRange = require("ui/gesturerange")
local InputDialog = require("ui/widget/inputdialog")
local UIManager = require("ui/uimanager")
local Notification = require("ui/widget/notification")
local _ = require("gettext")
local ReaderFrontLight = InputContainer:new{

@ -1,8 +1,14 @@
local InputContainer = require("ui/widget/container/inputcontainer")
local CenterContainer = require("ui/widget/container/centercontainer")
local FrameContainer = require("ui/widget/container/framecontainer")
local GestureRange = require("ui/gesturerange")
local Geom = require("ui/geometry")
local Screen = require("ui/screen")
local Device = require("ui/device")
local Event = require("ui/event")
local UIManager = require("ui/uimanager")
local ButtonTable = require("ui/widget/buttontable")
local Input = require("ui/input")
local _ = require("gettext")
local ReaderHighlight = InputContainer:new{}

@ -7,6 +7,8 @@ local GestureRange = require("ui/gesturerange")
local Geom = require("ui/geometry")
local Event = require("ui/event")
local Screen = require("ui/screen")
local Menu = require("ui/widget/menu")
local InfoMessage = require("ui/widget/infomessage")
local _ = require("gettext")
local ReaderMenu = InputContainer:new{

@ -1,7 +1,9 @@
local InputContainer = require("ui/widget/container/inputcontainer")
local Screen = require("ui/screen")
local Device = require("ui/device")
local Geom = require("ui/geometry")
local Input = require("ui/input")
local Event = require("ui/event")
local GestureRange = require("ui/gesturerange")
local ReaderPanning = require("ui/reader/readerpanning")
local _ = require("gettext")

@ -2,6 +2,7 @@ local InputContainer = require("ui/widget/container/inputcontainer")
local Screen = require("ui/screen")
local Geom = require("ui/geometry")
local Device = require("ui/device")
local Event = require("ui/event")
local GestureRange = require("ui/gesturerange")
local _ = require("gettext")

@ -4,6 +4,7 @@ local Menu = require("ui/widget/menu")
local Screen = require("ui/screen")
local Device = require("ui/device")
local UIManager = require("ui/uimanager")
local Event = require("ui/event")
local _ = require("gettext")
local ReaderToc = InputContainer:new{

@ -1,4 +1,5 @@
local InputContainer = require("ui/widget/container/inputcontainer")
local Event = require("ui/event")
local _ = require("gettext")
-- lfs

@ -1,210 +1,2 @@
local Device = require("ui/device")
local Geom = require("ui/geometry")
-- Blitbuffer
-- einkfb
--[[
Codes for rotation modes:
1 for no rotation,
2 for landscape with bottom on the right side of screen, etc.
2
+--------------+
| +----------+ |
| | | |
| | Freedom! | |
| | | |
| | | |
3 | | | | 1
| | | |
| | | |
| +----------+ |
| |
| |
+--------------+
0
--]]
local Screen = {
width = 0,
height = 0,
native_rotation_mode = nil,
cur_rotation_mode = 0,
bb = nil,
saved_bb = nil,
fb = einkfb.open("/dev/fb0"),
}
function Screen:init()
-- for unknown strange reason, pitch*2 is 10 px more than screen width in KPW
self.width, self.height = self.fb:getSize()
-- Blitbuffer still uses inverted 4bpp bitmap, so pitch should be
-- (self.width / 2)
self.bb = Blitbuffer.new(self.width, self.height, self.width/2)
if self.width > self.height then
-- For another unknown strange reason, self.fb:getOrientation always
-- return 0 in KPW, even though we are in landscape mode.
-- Seems like the native framework change framebuffer on the fly when
-- starting booklet. Starting KPV from ssh and KPVBooklet will get
-- different framebuffer height and width.
--
--self.native_rotation_mode = self.fb:getOrientation()
self.native_rotation_mode = 1
else
self.native_rotation_mode = 0
end
self.cur_rotation_mode = self.native_rotation_mode
end
function Screen:refresh(refesh_type, waveform_mode, x, y, w, h)
if x then x = x < 0 and 0 or math.floor(x) end
if y then y = y < 0 and 0 or math.floor(y) end
if w then w = w + x > self.width and self.width - x or math.ceil(w) end
if h then h = h + y > self.height and self.height - y or math.ceil(h) end
if self.native_rotation_mode == self.cur_rotation_mode then
self.fb.bb:blitFrom(self.bb, 0, 0, 0, 0, self.width, self.height)
elseif self.native_rotation_mode == 0 and self.cur_rotation_mode == 1 then
self.fb.bb:blitFromRotate(self.bb, 270)
if x and y and w and h then
x, y = y, self.width - w - x
w, h = h, w
end
elseif self.native_rotation_mode == 0 and self.cur_rotation_mode == 3 then
self.fb.bb:blitFromRotate(self.bb, 90)
if x and y and w and h then
x, y = self.height - h - y, x
w, h = h, w
end
elseif self.native_rotation_mode == 1 and self.cur_rotation_mode == 0 then
self.fb.bb:blitFromRotate(self.bb, 90)
if x and y and w and h then
x, y = self.height - h - y, x
w, h = h, w
end
elseif self.native_rotation_mode == 1 and self.cur_rotation_mode == 3 then
self.fb.bb:blitFromRotate(self.bb, 180)
if x and y and w and h then
x, y = self.width - w - x, self.height - h - y
end
end
self.fb:refresh(refesh_type, waveform_mode, x, y, w, h)
end
function Screen:getSize()
return Geom:new{w = self.width, h = self.height}
end
function Screen:getWidth()
return self.width
end
function Screen:getHeight()
return self.height
end
function Screen:getDPI()
if(Device:getModel() == "KindlePaperWhite") or (Device:getModel() == "Kobo_kraken") then
return 212
elseif Device:getModel() == "Kobo_dragon" then
return 265
elseif Device:getModel() == "Kobo_pixie" then
return 200
else
return 167
end
end
function Screen:scaleByDPI(px)
return math.floor(px * self:getDPI()/167)
end
function Screen:rescaleByDPI(px)
return math.ceil(px * 167/self:getDPI())
end
function Screen:getPitch()
return self.fb:getPitch()
end
function Screen:getNativeRotationMode()
-- in EMU mode, you will always get 0 from getOrientation()
return self.fb:getOrientation()
end
function Screen:getRotationMode()
return self.cur_rotation_mode
end
function Screen:getScreenMode()
if self.width > self.height then
return "landscape"
else
return "portrait"
end
end
function Screen:setRotationMode(mode)
if mode > 3 or mode < 0 then
return
end
-- mode 0 and mode 2 has the same width and height, so do mode 1 and 3
if (self.cur_rotation_mode % 2) ~= (mode % 2) then
self.width, self.height = self.height, self.width
end
self.cur_rotation_mode = mode
self.bb:free()
self.bb = Blitbuffer.new(self.width, self.height, self.width/2)
end
function Screen:setScreenMode(mode)
if mode == "portrait" then
if self.cur_rotation_mode ~= 0 then
self:setRotationMode(0)
end
elseif mode == "landscape" then
if self.cur_rotation_mode == 0 or self.cur_rotation_mode == 2 then
self:setRotationMode(1)
elseif self.cur_rotation_mode == 1 or self.cur_rotation_mode == 3 then
self:setRotationMode((self.cur_rotation_mode + 2) % 4)
end
end
end
function Screen:saveCurrentBB()
local width, height = self:getWidth(), self:getHeight()
if not self.saved_bb then
self.saved_bb = Blitbuffer.new(width, height, self.width/2)
end
if self.saved_bb:getWidth() ~= width then
self.saved_bb:free()
self.saved_bb = Blitbuffer.new(width, height, self.width/2)
end
self.saved_bb:blitFullFrom(self.bb)
end
function Screen:restoreFromSavedBB()
self:restoreFromBB(self.saved_bb)
end
function Screen:getCurrentScreenBB()
local bb = Blitbuffer.new(self:getWidth(), self:getHeight())
bb:blitFullFrom(self.bb)
return bb
end
function Screen:restoreFromBB(bb)
if bb then
self.bb:blitFullFrom(bb)
else
DEBUG("Got nil bb in restoreFromSavedBB!")
end
end
return Screen
-- compatibility wrapper
return require("ui/device").screen

@ -1,4 +1,9 @@
local InputContainer = require("ui/widget/container/inputcontainer")
local Geom = require("ui/geometry")
local Event = require("ui/event")
local UIManager = require("ui/uimanager")
local Device = require("ui/device")
local GestureRange = require("ui/gesturerange")
--[[
BBoxWidget shows a bbox for page cropping

@ -7,6 +7,7 @@ local UnderlineContainer = require("ui/widget/container/underlinecontainer")
local ImageWidget = require("ui/widget/imagewidget")
local TextWidget = require("ui/widget/textwidget")
local FixedTextWidget = require("ui/widget/fixedtextwidget")
local ProgressWidget = require("ui/widget/progresswidget")
local ToggleSwitch = require("ui/widget/toggleswitch")
local Font = require("ui/font")
local Device = require("ui/device")

@ -2,6 +2,16 @@ local CenterContainer = require("ui/widget/container/centercontainer")
local FrameContainer = require("ui/widget/container/centercontainer")
local FocusManager = require("ui/widget/focusmanager")
local Button = require("ui/widget/button")
local VerticalGroup = require("ui/widget/verticalgroup")
local ImageWidget = require("ui/widget/imagewidget")
local TextBoxWidget = require("ui/widget/textboxwidget")
local Font = require("ui/font")
local UIManager = require("ui/uimanager")
local Screen = require("ui/screen")
local HorizontalGroup = require("ui/widget/horizontalgroup")
local VerticalSpan = require("ui/widget/verticalspan")
local HorizontalSpan = require("ui/widget/horizontalspan")
local _ = require("gettext")
-- screen

@ -1,5 +1,6 @@
local WidgetContainer = require("ui/widget/container/widgetcontainer")
local Event = require("ui/event")
local Geom = require("ui/geometry")
--[[
an InputContainer is an WidgetContainer that handles input events

@ -9,6 +9,12 @@ local Screen = require("ui/screen")
local GestureRange = require("ui/gesturerange")
local Geom = require("ui/geometry")
local Font = require("ui/font")
local Event = require("ui/event")
local UIManager = require("ui/uimanager")
local ButtonTable = require("ui/widget/buttontable")
local Device = require("ui/device")
local VerticalGroup = require("ui/widget/verticalgroup")
local _ = require("gettext")
--[[
Display quick lookup word definition

@ -1,5 +1,6 @@
local InputContainer = require("ui/widget/container/inputcontainer")
-- UIManager
local Event = require("ui/event")
local UIManager = require("ui/uimanager")
--[[
Wrapper Widget that manages focus for a whole dialog

@ -8,6 +8,11 @@ local ImageWidget = require("ui/widget/imagewidget")
local TextBoxWidget = require("ui/widget/textboxwidget")
local HorizontalSpan = require("ui/widget/horizontalspan")
local UIManager = require("ui/uimanager")
local Geom = require("ui/geometry")
local CenterContainer = require("ui/widget/container/centercontainer")
local Input = require("ui/input")
local Screen = require("ui/screen")
local _ = require("gettext")
--[[
Widget that displays an informational message

@ -19,6 +19,7 @@ local Screen = require("ui/screen")
local Input = require("ui/input")
local UIManager = require("ui/uimanager")
local RenderText = require("ui/rendertext")
local InfoMessage = require("ui/widget/infomessage")
local _ = require("gettext")
--[[

@ -6,6 +6,9 @@ local Font = require("ui/font")
local Geom = require("ui/geometry")
local Device = require("ui/device")
local UIManager = require("ui/uimanager")
local HorizontalGroup = require("ui/widget/horizontalgroup")
local Input = require("ui/input")
local Screen = require("ui/screen")
--[[
Widget that displays a tiny notification on top of screen

@ -5,6 +5,9 @@ local Geom = require("ui/geometry")
local GestureRange = require("ui/gesturerange")
local UIManager = require("ui/uimanager")
local Screen = require("ui/screen")
local HorizontalGroup = require("ui/widget/horizontalgroup")
local HorizontalSpan = require("ui/widget/horizontalspan")
local Device = require("ui/device")
--[[
Text widget with vertical scroll bar

Loading…
Cancel
Save