2017-04-29 08:38:09 +00:00
|
|
|
|
local Blitbuffer = require("ffi/blitbuffer")
|
|
|
|
|
local Button = require("ui/widget/button")
|
2016-12-01 17:58:06 +00:00
|
|
|
|
local CenterContainer = require("ui/widget/container/centercontainer")
|
2018-03-31 14:03:00 +00:00
|
|
|
|
local CheckButton = require("ui/widget/checkbutton")
|
2016-12-01 17:58:06 +00:00
|
|
|
|
local CloseButton = require("ui/widget/closebutton")
|
|
|
|
|
local Device = require("device")
|
2017-04-29 08:38:09 +00:00
|
|
|
|
local FrameContainer = require("ui/widget/container/framecontainer")
|
2016-12-01 17:58:06 +00:00
|
|
|
|
local Geom = require("ui/geometry")
|
2017-04-29 08:38:09 +00:00
|
|
|
|
local GestureRange = require("ui/gesturerange")
|
2016-12-01 17:58:06 +00:00
|
|
|
|
local Font = require("ui/font")
|
|
|
|
|
local HorizontalGroup = require("ui/widget/horizontalgroup")
|
2017-04-29 08:38:09 +00:00
|
|
|
|
local HorizontalSpan = require("ui/widget/horizontalspan")
|
|
|
|
|
local InputContainer = require("ui/widget/container/inputcontainer")
|
|
|
|
|
local LineWidget = require("ui/widget/linewidget")
|
2019-09-26 22:38:44 +00:00
|
|
|
|
local Math = require("optmath")
|
2018-03-08 21:23:05 +00:00
|
|
|
|
local NaturalLight = require("ui/widget/naturallightwidget")
|
2017-04-29 08:38:09 +00:00
|
|
|
|
local OverlapGroup = require("ui/widget/overlapgroup")
|
2019-09-26 22:38:44 +00:00
|
|
|
|
local ProgressWidget = require("ui/widget/progresswidget")
|
2017-09-13 14:56:20 +00:00
|
|
|
|
local Size = require("ui/size")
|
2016-12-01 17:58:06 +00:00
|
|
|
|
local TextBoxWidget = require("ui/widget/textboxwidget")
|
2017-04-29 08:38:09 +00:00
|
|
|
|
local TextWidget = require("ui/widget/textwidget")
|
2019-09-26 22:38:44 +00:00
|
|
|
|
local TimeVal = require("ui/timeval")
|
2017-04-29 08:38:09 +00:00
|
|
|
|
local UIManager = require("ui/uimanager")
|
|
|
|
|
local VerticalGroup = require("ui/widget/verticalgroup")
|
2016-12-01 17:58:06 +00:00
|
|
|
|
local VerticalSpan = require("ui/widget/verticalspan")
|
2017-04-29 08:38:09 +00:00
|
|
|
|
local WidgetContainer = require("ui/widget/container/widgetcontainer")
|
|
|
|
|
local _ = require("gettext")
|
|
|
|
|
local Screen = Device.screen
|
|
|
|
|
|
2016-12-01 17:58:06 +00:00
|
|
|
|
local FrontLightWidget = InputContainer:new{
|
2017-04-29 08:38:09 +00:00
|
|
|
|
title_face = Font:getFace("x_smalltfont"),
|
2016-12-01 17:58:06 +00:00
|
|
|
|
width = nil,
|
|
|
|
|
height = nil,
|
2018-03-08 21:23:05 +00:00
|
|
|
|
-- This should stay active during natural light configuration
|
|
|
|
|
is_always_active = true,
|
2019-09-04 18:52:24 +00:00
|
|
|
|
use_system_fl = false,
|
2019-09-26 22:38:44 +00:00
|
|
|
|
rate = Screen.low_pan_rate and 3 or 30, -- Widget update rate.
|
|
|
|
|
last_time = TimeVal:new{}, -- Tracks last update time to prevent update spamming.
|
2016-12-01 17:58:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function FrontLightWidget:init()
|
2019-09-04 18:52:24 +00:00
|
|
|
|
self.light_fallback = self.use_system_fl and G_reader_settings:nilOrTrue("light_fallback")
|
2017-04-29 08:38:09 +00:00
|
|
|
|
self.medium_font_face = Font:getFace("ffont")
|
2018-03-31 14:03:00 +00:00
|
|
|
|
self.larger_font_face = Font:getFace("cfont")
|
2016-12-01 17:58:06 +00:00
|
|
|
|
self.light_bar = {}
|
2017-09-13 14:56:20 +00:00
|
|
|
|
self.screen_width = Screen:getWidth()
|
|
|
|
|
self.screen_height = Screen:getHeight()
|
2016-12-01 17:58:06 +00:00
|
|
|
|
self.span = math.ceil(self.screen_height * 0.01)
|
|
|
|
|
self.width = self.screen_width * 0.95
|
2018-02-08 21:13:59 +00:00
|
|
|
|
self.powerd = Device:getPowerDevice()
|
|
|
|
|
self.fl_min = self.powerd.fl_min
|
|
|
|
|
self.fl_max = self.powerd.fl_max
|
|
|
|
|
self.fl_cur = self.powerd:frontlightIntensity()
|
2016-12-01 17:58:06 +00:00
|
|
|
|
local steps_fl = self.fl_max - self.fl_min + 1
|
2016-12-25 07:43:58 +00:00
|
|
|
|
self.one_step = math.ceil(steps_fl / 25)
|
2016-12-01 17:58:06 +00:00
|
|
|
|
self.steps = math.ceil(steps_fl / self.one_step)
|
|
|
|
|
if (self.steps - 1) * self.one_step < self.fl_max - self.fl_min then
|
|
|
|
|
self.steps = self.steps + 1
|
|
|
|
|
end
|
2018-12-28 03:32:42 +00:00
|
|
|
|
self.steps = math.min(self.steps, steps_fl)
|
2019-04-12 20:46:10 +00:00
|
|
|
|
self.natural_light = Device:hasNaturalLight()
|
|
|
|
|
self.has_nl_mixer = Device:hasNaturalLightMixer()
|
2018-12-28 03:32:42 +00:00
|
|
|
|
-- Handle Warmth separately, because it may use a different scale
|
|
|
|
|
if self.natural_light then
|
|
|
|
|
self.nl_min = self.powerd.fl_warmth_min
|
|
|
|
|
self.nl_max = self.powerd.fl_warmth_max
|
|
|
|
|
-- NOTE: fl_warmth is always [0...100] even when internal scale is [0...10]
|
|
|
|
|
self.nl_scale = (100 / self.nl_max)
|
|
|
|
|
end
|
2017-10-08 15:53:25 +00:00
|
|
|
|
|
2016-12-01 17:58:06 +00:00
|
|
|
|
-- button width to fit screen size
|
2017-10-08 15:53:25 +00:00
|
|
|
|
local button_margin = Size.margin.tiny
|
|
|
|
|
local button_padding = Size.padding.button
|
|
|
|
|
local button_bordersize = Size.border.button
|
2018-03-31 14:03:00 +00:00
|
|
|
|
self.auto_nl = false
|
2017-10-08 15:53:25 +00:00
|
|
|
|
self.button_width = math.floor(self.screen_width * 0.9 / self.steps) -
|
|
|
|
|
2 * (button_margin + button_padding + button_bordersize)
|
2016-12-01 17:58:06 +00:00
|
|
|
|
|
|
|
|
|
self.fl_prog_button = Button:new{
|
|
|
|
|
text = "",
|
|
|
|
|
radius = 0,
|
2017-10-08 15:53:25 +00:00
|
|
|
|
margin = button_margin,
|
|
|
|
|
padding = button_padding,
|
|
|
|
|
bordersize = button_bordersize,
|
2019-09-04 18:52:24 +00:00
|
|
|
|
enabled = not self.light_fallback,
|
2016-12-01 17:58:06 +00:00
|
|
|
|
width = self.button_width,
|
|
|
|
|
show_parent = self,
|
|
|
|
|
}
|
|
|
|
|
if Device:hasKeys() then
|
|
|
|
|
self.key_events = {
|
|
|
|
|
Close = { {"Back"}, doc = "close frontlight" }
|
|
|
|
|
}
|
|
|
|
|
end
|
|
|
|
|
if Device:isTouchDevice() then
|
|
|
|
|
self.ges_events = {
|
2019-09-26 22:38:44 +00:00
|
|
|
|
TapProgress = {
|
2016-12-01 17:58:06 +00:00
|
|
|
|
GestureRange:new{
|
|
|
|
|
ges = "tap",
|
|
|
|
|
range = Geom:new{
|
|
|
|
|
x = 0, y = 0,
|
|
|
|
|
w = self.screen_width,
|
|
|
|
|
h = self.screen_height,
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
},
|
2019-09-26 22:38:44 +00:00
|
|
|
|
PanProgress = {
|
|
|
|
|
GestureRange:new{
|
|
|
|
|
ges = "pan",
|
|
|
|
|
range = Geom:new{
|
|
|
|
|
x = 0, y = 0,
|
|
|
|
|
w = self.screen_width,
|
|
|
|
|
h = self.screen_height,
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
},
|
2016-12-01 17:58:06 +00:00
|
|
|
|
}
|
|
|
|
|
end
|
|
|
|
|
self:update()
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function FrontLightWidget:generateProgressGroup(width, height, fl_level, step)
|
|
|
|
|
self.fl_container = CenterContainer:new{
|
|
|
|
|
dimen = Geom:new{ w = width, h = height },
|
|
|
|
|
}
|
|
|
|
|
self:setProgress(fl_level, step)
|
|
|
|
|
return self.fl_container
|
|
|
|
|
end
|
|
|
|
|
|
2018-02-08 21:14:57 +00:00
|
|
|
|
function FrontLightWidget:setProgress(num, step, num_warmth)
|
2016-12-01 17:58:06 +00:00
|
|
|
|
self.fl_container:clear()
|
|
|
|
|
local padding_span = VerticalSpan:new{ width = self.span }
|
|
|
|
|
local button_group_down = HorizontalGroup:new{ align = "center" }
|
|
|
|
|
local button_group_up = HorizontalGroup:new{ align = "center" }
|
|
|
|
|
local vertical_group = VerticalGroup:new{ align = "center" }
|
2019-09-04 18:52:24 +00:00
|
|
|
|
self.fl_prog_button.enabled = not self.light_fallback
|
2016-12-01 17:58:06 +00:00
|
|
|
|
local enable_button_plus = true
|
|
|
|
|
local enable_button_minus = true
|
2018-02-08 21:14:57 +00:00
|
|
|
|
if self.natural_light then
|
|
|
|
|
num_warmth = num_warmth or self.powerd.fl_warmth
|
|
|
|
|
end
|
2016-12-01 17:58:06 +00:00
|
|
|
|
if num then
|
2019-09-26 22:38:44 +00:00
|
|
|
|
--- @note Don't set the same value twice, to play nice with the update() sent by the swipe handler on the FL bar
|
|
|
|
|
-- Except for fl_min, as that's how setFrontLightIntensity detects a toggle...
|
|
|
|
|
if num == self.fl_min or num ~= self.fl_cur then
|
|
|
|
|
self:setFrontLightIntensity(num)
|
2017-08-29 15:37:08 +00:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
if self.fl_cur == self.fl_max then enable_button_plus = false end
|
|
|
|
|
if self.fl_cur == self.fl_min then enable_button_minus = false end
|
2016-12-01 17:58:06 +00:00
|
|
|
|
end
|
|
|
|
|
|
2019-09-26 22:38:44 +00:00
|
|
|
|
local ticks = {}
|
|
|
|
|
for i = 1, self.steps-2 do
|
|
|
|
|
table.insert(ticks, i*self.one_step)
|
2016-12-01 17:58:06 +00:00
|
|
|
|
end
|
2019-09-26 22:38:44 +00:00
|
|
|
|
|
|
|
|
|
self.fl_group = ProgressWidget:new{
|
|
|
|
|
width = self.screen_width * 0.9,
|
|
|
|
|
height = Size.item.height_big,
|
|
|
|
|
percentage = self.fl_cur / self.fl_max,
|
|
|
|
|
ticks = ticks,
|
|
|
|
|
tick_width = Screen:scaleBySize(0.5),
|
|
|
|
|
last = self.fl_max,
|
|
|
|
|
}
|
2018-02-08 21:14:57 +00:00
|
|
|
|
local text_br = TextBoxWidget:new{
|
|
|
|
|
text = _("Brightness"),
|
|
|
|
|
face = self.medium_font_face,
|
|
|
|
|
bold = true,
|
|
|
|
|
alignment = "center",
|
|
|
|
|
width = self.screen_width * 0.95
|
|
|
|
|
}
|
2016-12-01 17:58:06 +00:00
|
|
|
|
local button_minus = Button:new{
|
|
|
|
|
text = "-1",
|
2017-09-13 14:56:20 +00:00
|
|
|
|
margin = Size.margin.small,
|
2016-12-01 17:58:06 +00:00
|
|
|
|
radius = 0,
|
2019-09-04 18:52:24 +00:00
|
|
|
|
enabled = enable_button_minus and not self.light_fallback,
|
2016-12-01 17:58:06 +00:00
|
|
|
|
width = self.screen_width * 0.20,
|
|
|
|
|
show_parent = self,
|
2017-08-29 15:37:08 +00:00
|
|
|
|
callback = function() self:setProgress(self.fl_cur - 1, step) end,
|
2016-12-01 17:58:06 +00:00
|
|
|
|
}
|
|
|
|
|
local button_plus = Button:new{
|
|
|
|
|
text = "+1",
|
2017-09-13 14:56:20 +00:00
|
|
|
|
margin = Size.margin.small,
|
2016-12-01 17:58:06 +00:00
|
|
|
|
radius = 0,
|
2019-09-04 18:52:24 +00:00
|
|
|
|
enabled = enable_button_plus and not self.light_fallback,
|
2016-12-01 17:58:06 +00:00
|
|
|
|
width = self.screen_width * 0.20,
|
|
|
|
|
show_parent = self,
|
2017-08-29 15:37:08 +00:00
|
|
|
|
callback = function() self:setProgress(self.fl_cur + 1, step) end,
|
2016-12-01 17:58:06 +00:00
|
|
|
|
}
|
|
|
|
|
local item_level = TextBoxWidget:new{
|
2017-08-29 15:37:08 +00:00
|
|
|
|
text = self.fl_cur,
|
2016-12-01 17:58:06 +00:00
|
|
|
|
face = self.medium_font_face,
|
|
|
|
|
alignment = "center",
|
|
|
|
|
width = self.screen_width * 0.95 - 1.275 * button_minus.width - 1.275 * button_plus.width,
|
|
|
|
|
}
|
|
|
|
|
local button_min = Button:new{
|
|
|
|
|
text = _("Min"),
|
2017-09-13 14:56:20 +00:00
|
|
|
|
margin = Size.margin.small,
|
2016-12-01 17:58:06 +00:00
|
|
|
|
radius = 0,
|
2019-09-04 18:52:24 +00:00
|
|
|
|
enabled = not self.light_fallback,
|
2016-12-01 17:58:06 +00:00
|
|
|
|
width = self.screen_width * 0.20,
|
|
|
|
|
show_parent = self,
|
2017-08-29 15:37:08 +00:00
|
|
|
|
callback = function() self:setProgress(self.fl_min+1, step) end, -- min is 1 (use toggle for 0)
|
2016-12-01 17:58:06 +00:00
|
|
|
|
}
|
|
|
|
|
local button_max = Button:new{
|
|
|
|
|
text = _("Max"),
|
2017-09-13 14:56:20 +00:00
|
|
|
|
margin = Size.margin.small,
|
2016-12-01 17:58:06 +00:00
|
|
|
|
radius = 0,
|
2019-09-04 18:52:24 +00:00
|
|
|
|
enabled = not self.light_fallback,
|
2016-12-01 17:58:06 +00:00
|
|
|
|
width = self.screen_width * 0.20,
|
|
|
|
|
show_parent = self,
|
|
|
|
|
callback = function() self:setProgress(self.fl_max, step) end,
|
|
|
|
|
}
|
|
|
|
|
local button_toggle = Button:new{
|
|
|
|
|
text = _("Toggle"),
|
2017-09-13 14:56:20 +00:00
|
|
|
|
margin = Size.margin.small,
|
2016-12-01 17:58:06 +00:00
|
|
|
|
radius = 0,
|
2019-09-04 18:52:24 +00:00
|
|
|
|
enabled = not self.light_fallback,
|
2016-12-01 17:58:06 +00:00
|
|
|
|
width = self.screen_width * 0.20,
|
|
|
|
|
show_parent = self,
|
|
|
|
|
callback = function()
|
2017-08-29 15:37:08 +00:00
|
|
|
|
self:setProgress(self.fl_min, step)
|
2016-12-01 17:58:06 +00:00
|
|
|
|
end,
|
|
|
|
|
}
|
|
|
|
|
local empty_space = HorizontalSpan:new{
|
|
|
|
|
width = (self.screen_width * 0.95 - 1.2 * button_minus.width - 1.2 * button_plus.width - 1.2 * button_toggle.width) / 2,
|
|
|
|
|
}
|
|
|
|
|
local button_table_up = HorizontalGroup:new{
|
|
|
|
|
align = "center",
|
|
|
|
|
button_minus,
|
|
|
|
|
item_level,
|
|
|
|
|
button_plus,
|
|
|
|
|
}
|
|
|
|
|
local button_table_down = HorizontalGroup:new{
|
|
|
|
|
align = "center",
|
|
|
|
|
button_min,
|
|
|
|
|
empty_space,
|
|
|
|
|
button_toggle,
|
|
|
|
|
empty_space,
|
|
|
|
|
button_max,
|
|
|
|
|
}
|
2018-02-08 21:14:57 +00:00
|
|
|
|
if self.natural_light then
|
|
|
|
|
-- Only insert 'brightness' caption if we also add 'warmth'
|
|
|
|
|
-- widgets below.
|
2018-12-28 03:32:42 +00:00
|
|
|
|
table.insert(vertical_group, text_br)
|
2018-02-08 21:14:57 +00:00
|
|
|
|
end
|
2019-09-04 18:52:24 +00:00
|
|
|
|
local system_level_checkbutton
|
|
|
|
|
system_level_checkbutton = CheckButton:new{
|
|
|
|
|
text = _("Use system settings"),
|
|
|
|
|
checked = self.light_fallback,
|
|
|
|
|
callback = function()
|
|
|
|
|
if system_level_checkbutton.checked then
|
|
|
|
|
self.light_fallback = false
|
|
|
|
|
else
|
|
|
|
|
self.light_fallback = true
|
|
|
|
|
end
|
|
|
|
|
G_reader_settings:saveSetting("light_fallback", self.light_fallback)
|
|
|
|
|
self:setProgress(self.fl_cur, step)
|
|
|
|
|
end,
|
|
|
|
|
}
|
2016-12-01 17:58:06 +00:00
|
|
|
|
table.insert(button_group_up, button_table_up)
|
|
|
|
|
table.insert(button_group_down, button_table_down)
|
2018-12-28 03:32:42 +00:00
|
|
|
|
table.insert(vertical_group, padding_span)
|
|
|
|
|
table.insert(vertical_group, button_group_up)
|
|
|
|
|
table.insert(vertical_group, padding_span)
|
2019-09-26 22:38:44 +00:00
|
|
|
|
table.insert(vertical_group, self.fl_group)
|
2018-12-28 03:32:42 +00:00
|
|
|
|
table.insert(vertical_group, padding_span)
|
|
|
|
|
table.insert(vertical_group, button_group_down)
|
|
|
|
|
table.insert(vertical_group, padding_span)
|
2019-09-04 18:52:24 +00:00
|
|
|
|
if self.use_system_fl then
|
|
|
|
|
table.insert(vertical_group, system_level_checkbutton)
|
|
|
|
|
table.insert(vertical_group, padding_span)
|
|
|
|
|
end
|
2018-02-08 21:14:57 +00:00
|
|
|
|
if self.natural_light then
|
2019-04-12 20:46:10 +00:00
|
|
|
|
-- If the device supports natural light, add the widgets for 'warmth',
|
|
|
|
|
-- as well as a 'Configure' button for devices *without* a mixer
|
2018-02-08 21:14:57 +00:00
|
|
|
|
self:addWarmthWidgets(num_warmth, step, vertical_group)
|
2019-04-12 20:46:10 +00:00
|
|
|
|
if not self.has_nl_mixer then
|
|
|
|
|
self.configure_button = Button:new{
|
|
|
|
|
text = _("Configure"),
|
|
|
|
|
margin = Size.margin.small,
|
|
|
|
|
radius = 0,
|
|
|
|
|
width = self.screen_width * 0.20,
|
|
|
|
|
enabled = not self.nl_configure_open,
|
|
|
|
|
show_parent = self,
|
|
|
|
|
callback = function()
|
|
|
|
|
UIManager:show(NaturalLight:new{fl_widget = self})
|
|
|
|
|
end,
|
|
|
|
|
}
|
|
|
|
|
table.insert(vertical_group, self.configure_button)
|
|
|
|
|
end
|
2018-02-08 21:14:57 +00:00
|
|
|
|
end
|
2016-12-01 17:58:06 +00:00
|
|
|
|
table.insert(self.fl_container, vertical_group)
|
2017-10-08 15:53:25 +00:00
|
|
|
|
-- Reset container height to what it actually contains
|
|
|
|
|
self.fl_container.dimen.h = vertical_group:getSize().h
|
2016-12-01 17:58:06 +00:00
|
|
|
|
|
2019-09-26 22:38:44 +00:00
|
|
|
|
UIManager:setDirty(self, function()
|
|
|
|
|
return "ui", self.light_frame.dimen
|
|
|
|
|
end)
|
2016-12-01 17:58:06 +00:00
|
|
|
|
return true
|
|
|
|
|
end
|
|
|
|
|
|
2018-02-08 21:14:57 +00:00
|
|
|
|
-- Currently, we are assuming the 'warmth' has the same min/max limits
|
|
|
|
|
-- as 'brightness'.
|
|
|
|
|
function FrontLightWidget:addWarmthWidgets(num_warmth, step, vertical_group)
|
|
|
|
|
local button_group_down = HorizontalGroup:new{ align = "center" }
|
|
|
|
|
local button_group_up = HorizontalGroup:new{ align = "center" }
|
|
|
|
|
local warmth_group = HorizontalGroup:new{ align = "center" }
|
2018-03-31 14:03:00 +00:00
|
|
|
|
local auto_nl_group = HorizontalGroup:new{ align = "center" }
|
2018-02-08 21:14:57 +00:00
|
|
|
|
local padding_span = VerticalSpan:new{ width = self.span }
|
|
|
|
|
local enable_button_plus = true
|
|
|
|
|
local enable_button_minus = true
|
2018-03-31 14:03:00 +00:00
|
|
|
|
local button_color = Blitbuffer.COLOR_WHITE
|
2018-02-08 21:14:57 +00:00
|
|
|
|
|
|
|
|
|
if self[1] then
|
2019-09-26 22:38:44 +00:00
|
|
|
|
--- @note Don't set the same value twice, to play nice with the update() sent by the swipe handler on the FL bar
|
|
|
|
|
if num_warmth ~= self.powerd.fl_warmth then
|
|
|
|
|
self.powerd:setWarmth(num_warmth)
|
|
|
|
|
end
|
2018-02-08 21:14:57 +00:00
|
|
|
|
end
|
|
|
|
|
|
2018-03-31 14:03:00 +00:00
|
|
|
|
if self.powerd.auto_warmth then
|
|
|
|
|
enable_button_plus = false
|
|
|
|
|
enable_button_minus = false
|
2019-03-14 19:58:45 +00:00
|
|
|
|
button_color = Blitbuffer.COLOR_DARK_GRAY
|
2018-03-31 14:03:00 +00:00
|
|
|
|
else
|
2018-12-28 03:32:42 +00:00
|
|
|
|
if math.floor(num_warmth / self.nl_scale) <= self.nl_min then enable_button_minus = false end
|
|
|
|
|
if math.ceil(num_warmth / self.nl_scale) >= self.nl_max then enable_button_plus = false end
|
2018-03-31 14:03:00 +00:00
|
|
|
|
end
|
|
|
|
|
|
2018-02-08 21:14:57 +00:00
|
|
|
|
if self.natural_light and num_warmth then
|
|
|
|
|
for i = 0, math.floor(num_warmth / step) do
|
|
|
|
|
table.insert(warmth_group, self.fl_prog_button:new{
|
|
|
|
|
text = "",
|
|
|
|
|
preselect = true,
|
2018-03-31 14:03:00 +00:00
|
|
|
|
enabled = not self.powerd.auto_warmth,
|
|
|
|
|
background = button_color,
|
2018-02-08 21:14:57 +00:00
|
|
|
|
callback = function()
|
|
|
|
|
self:setProgress(self.fl_cur, step, i * step)
|
|
|
|
|
end
|
|
|
|
|
})
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
for i = math.floor(num_warmth / step) + 1, self.steps - 1 do
|
|
|
|
|
table.insert(warmth_group, self.fl_prog_button:new{
|
|
|
|
|
text="",
|
2018-03-31 14:03:00 +00:00
|
|
|
|
enabled = not self.powerd.auto_warmth,
|
2018-02-08 21:14:57 +00:00
|
|
|
|
callback = function()
|
|
|
|
|
self:setProgress(self.fl_cur, step, i * step)
|
|
|
|
|
end
|
|
|
|
|
})
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local text_warmth = TextBoxWidget:new{
|
|
|
|
|
text = "\n" .. _("Warmth"),
|
|
|
|
|
face = self.medium_font_face,
|
|
|
|
|
bold = true,
|
|
|
|
|
alignment = "center",
|
|
|
|
|
width = self.screen_width * 0.95
|
|
|
|
|
}
|
|
|
|
|
local button_minus = Button:new{
|
2018-12-28 03:32:42 +00:00
|
|
|
|
text = "-" .. (1 * self.nl_scale),
|
2018-02-08 21:14:57 +00:00
|
|
|
|
margin = Size.margin.small,
|
|
|
|
|
radius = 0,
|
|
|
|
|
enabled = enable_button_minus,
|
|
|
|
|
width = self.screen_width * 0.20,
|
|
|
|
|
show_parent = self,
|
2018-12-28 03:32:42 +00:00
|
|
|
|
callback = function() self:setProgress(self.fl_cur, step, (num_warmth - (1 * self.nl_scale))) end,
|
2018-02-08 21:14:57 +00:00
|
|
|
|
}
|
|
|
|
|
local button_plus = Button:new{
|
2018-12-28 03:32:42 +00:00
|
|
|
|
text = "+" .. (1 * self.nl_scale),
|
2018-02-08 21:14:57 +00:00
|
|
|
|
margin = Size.margin.small,
|
|
|
|
|
radius = 0,
|
|
|
|
|
enabled = enable_button_plus,
|
|
|
|
|
width = self.screen_width * 0.20,
|
|
|
|
|
show_parent = self,
|
2018-12-28 03:32:42 +00:00
|
|
|
|
callback = function() self:setProgress(self.fl_cur, step, (num_warmth + (1 * self.nl_scale))) end,
|
2018-02-08 21:14:57 +00:00
|
|
|
|
}
|
|
|
|
|
local item_level = TextBoxWidget:new{
|
|
|
|
|
text = num_warmth,
|
|
|
|
|
face = self.medium_font_face,
|
|
|
|
|
alignment = "center",
|
|
|
|
|
width = self.screen_width * 0.95 - 1.275 * button_minus.width - 1.275 * button_plus.width,
|
|
|
|
|
}
|
|
|
|
|
local button_min = Button:new{
|
|
|
|
|
text = _("Min"),
|
|
|
|
|
margin = Size.margin.small,
|
|
|
|
|
radius = 0,
|
2018-03-31 14:03:00 +00:00
|
|
|
|
enabled = not self.powerd.auto_warmth,
|
2018-02-08 21:14:57 +00:00
|
|
|
|
width = self.screen_width * 0.20,
|
|
|
|
|
show_parent = self,
|
2018-12-28 03:32:42 +00:00
|
|
|
|
callback = function() self:setProgress(self.fl_cur, step, self.nl_min) end,
|
2018-02-08 21:14:57 +00:00
|
|
|
|
}
|
|
|
|
|
local button_max = Button:new{
|
|
|
|
|
text = _("Max"),
|
|
|
|
|
margin = Size.margin.small,
|
|
|
|
|
radius = 0,
|
2018-03-31 14:03:00 +00:00
|
|
|
|
enabled = not self.powerd.auto_warmth,
|
2018-02-08 21:14:57 +00:00
|
|
|
|
width = self.screen_width * 0.20,
|
|
|
|
|
show_parent = self,
|
2018-12-28 03:32:42 +00:00
|
|
|
|
callback = function() self:setProgress(self.fl_cur, step, (self.nl_max * self.nl_scale)) end,
|
2018-02-08 21:14:57 +00:00
|
|
|
|
}
|
|
|
|
|
local empty_space = HorizontalSpan:new{
|
|
|
|
|
width = (self.screen_width * 0.95 - 1.2 * button_minus.width - 1.2 * button_plus.width) / 2,
|
|
|
|
|
}
|
|
|
|
|
local button_table_up = HorizontalGroup:new{
|
|
|
|
|
align = "center",
|
|
|
|
|
button_minus,
|
|
|
|
|
item_level,
|
|
|
|
|
button_plus,
|
|
|
|
|
}
|
|
|
|
|
local button_table_down = HorizontalGroup:new{
|
|
|
|
|
align = "center",
|
|
|
|
|
button_min,
|
|
|
|
|
empty_space,
|
|
|
|
|
button_max,
|
|
|
|
|
}
|
2018-03-31 14:03:00 +00:00
|
|
|
|
local checkbutton_auto_nl = CheckButton:new({
|
2018-04-06 19:54:58 +00:00
|
|
|
|
text = _("Auto"),
|
2018-03-31 14:03:00 +00:00
|
|
|
|
checked = self.powerd.auto_warmth,
|
|
|
|
|
callback = function()
|
|
|
|
|
if self.powerd.auto_warmth then
|
|
|
|
|
self.powerd.auto_warmth = false
|
|
|
|
|
else
|
|
|
|
|
self.powerd.auto_warmth = true
|
|
|
|
|
self.powerd:calculateAutoWarmth()
|
|
|
|
|
end
|
|
|
|
|
self:setProgress(self.fl_cur, step)
|
|
|
|
|
end
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
local text_auto_nl = TextBoxWidget:new{
|
2019-08-23 17:53:53 +00:00
|
|
|
|
--- @todo Implement padding_right (etc.) on TextBoxWidget and remove the two-space hack.
|
2018-04-06 19:54:58 +00:00
|
|
|
|
text = _("Max. at:") .. " ",
|
2018-03-31 14:03:00 +00:00
|
|
|
|
face = self.larger_font_face,
|
|
|
|
|
alignment = "right",
|
|
|
|
|
fgcolor = self.powerd.auto_warmth and Blitbuffer.COLOR_BLACK or
|
2019-03-14 19:58:45 +00:00
|
|
|
|
Blitbuffer.COLOR_DARK_GRAY,
|
2018-03-31 14:03:00 +00:00
|
|
|
|
width = self.screen_width * 0.3
|
|
|
|
|
}
|
|
|
|
|
local text_hour = TextBoxWidget:new{
|
|
|
|
|
text = " " .. math.floor(self.powerd.max_warmth_hour) .. ":" ..
|
|
|
|
|
self.powerd.max_warmth_hour % 1 * 6 .. "0",
|
|
|
|
|
face = self.larger_font_face,
|
2018-04-06 20:13:18 +00:00
|
|
|
|
alignment = "center",
|
2018-03-31 14:03:00 +00:00
|
|
|
|
fgcolor =self.powerd.auto_warmth and Blitbuffer.COLOR_BLACK or
|
2019-03-14 19:58:45 +00:00
|
|
|
|
Blitbuffer.COLOR_DARK_GRAY,
|
2018-04-06 20:13:18 +00:00
|
|
|
|
width = self.screen_width * 0.15
|
2018-03-31 14:03:00 +00:00
|
|
|
|
}
|
|
|
|
|
local button_minus_one_hour = Button:new{
|
|
|
|
|
text = "−",
|
|
|
|
|
margin = Size.margin.small,
|
|
|
|
|
radius = 0,
|
|
|
|
|
enabled = self.powerd.auto_warmth,
|
|
|
|
|
width = self.screen_width * 0.1,
|
|
|
|
|
show_parent = self,
|
|
|
|
|
callback = function()
|
|
|
|
|
self.powerd.max_warmth_hour =
|
|
|
|
|
(self.powerd.max_warmth_hour - 1) % 24
|
|
|
|
|
self.powerd:calculateAutoWarmth()
|
|
|
|
|
self:setProgress(self.fl_cur, step)
|
|
|
|
|
end,
|
|
|
|
|
hold_callback = function()
|
|
|
|
|
self.powerd.max_warmth_hour =
|
|
|
|
|
(self.powerd.max_warmth_hour - 0.5) % 24
|
|
|
|
|
self.powerd:calculateAutoWarmth()
|
|
|
|
|
self:setProgress(self.fl_cur, step)
|
|
|
|
|
end,
|
|
|
|
|
}
|
|
|
|
|
local button_plus_one_hour = Button:new{
|
|
|
|
|
text = "+",
|
|
|
|
|
margin = Size.margin.small,
|
|
|
|
|
radius = 0,
|
|
|
|
|
enabled = self.powerd.auto_warmth,
|
|
|
|
|
width = self.screen_width * 0.1,
|
|
|
|
|
show_parent = self,
|
|
|
|
|
callback = function()
|
|
|
|
|
self.powerd.max_warmth_hour =
|
|
|
|
|
(self.powerd.max_warmth_hour + 1) % 24
|
|
|
|
|
self.powerd:calculateAutoWarmth()
|
|
|
|
|
self:setProgress(self.fl_cur, step)
|
|
|
|
|
end,
|
|
|
|
|
hold_callback = function()
|
|
|
|
|
self.powerd.max_warmth_hour =
|
|
|
|
|
(self.powerd.max_warmth_hour + 0.5) % 24
|
|
|
|
|
self.powerd:calculateAutoWarmth()
|
|
|
|
|
self:setProgress(self.fl_cur, step)
|
|
|
|
|
end,
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-28 03:32:42 +00:00
|
|
|
|
table.insert(vertical_group, text_warmth)
|
2018-02-08 21:14:57 +00:00
|
|
|
|
table.insert(button_group_up, button_table_up)
|
|
|
|
|
table.insert(button_group_down, button_table_down)
|
2018-03-31 14:03:00 +00:00
|
|
|
|
table.insert(auto_nl_group, checkbutton_auto_nl)
|
|
|
|
|
table.insert(auto_nl_group, text_auto_nl)
|
|
|
|
|
table.insert(auto_nl_group, button_minus_one_hour)
|
|
|
|
|
table.insert(auto_nl_group, text_hour)
|
|
|
|
|
table.insert(auto_nl_group, button_plus_one_hour)
|
|
|
|
|
|
2018-12-28 03:32:42 +00:00
|
|
|
|
table.insert(vertical_group, padding_span)
|
|
|
|
|
table.insert(vertical_group, button_group_up)
|
|
|
|
|
table.insert(vertical_group, padding_span)
|
|
|
|
|
table.insert(vertical_group, warmth_group)
|
|
|
|
|
table.insert(vertical_group, padding_span)
|
|
|
|
|
table.insert(vertical_group, button_group_down)
|
|
|
|
|
table.insert(vertical_group, padding_span)
|
|
|
|
|
table.insert(vertical_group, auto_nl_group)
|
2018-02-08 21:14:57 +00:00
|
|
|
|
end
|
|
|
|
|
|
2019-09-26 22:38:44 +00:00
|
|
|
|
function FrontLightWidget:setFrontLightIntensity(num)
|
|
|
|
|
self.fl_cur = num
|
|
|
|
|
local set_fl = math.min(self.fl_cur, self.fl_max)
|
|
|
|
|
-- Don't touch frontlight on first call (no self[1] means not yet out of update()),
|
|
|
|
|
-- so that we don't untoggle light.
|
|
|
|
|
if self[1] then
|
|
|
|
|
if set_fl == self.fl_min then -- fl_min (which is always 0) means toggle
|
|
|
|
|
self.powerd:toggleFrontlight()
|
|
|
|
|
else
|
|
|
|
|
self.powerd:setIntensity(set_fl)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
if not self.light_fallback and self.fl_cur >= 0 then
|
|
|
|
|
G_reader_settings:saveSetting("fl_last_level", self.fl_cur * 10)
|
|
|
|
|
elseif self.light_fallback then
|
|
|
|
|
G_reader_settings:saveSetting("fl_last_level", nil)
|
|
|
|
|
Device:setScreenBrightness(-1)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- get back the real level (different from set_fl if untoggle)
|
|
|
|
|
self.fl_cur = self.powerd:frontlightIntensity()
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2016-12-01 17:58:06 +00:00
|
|
|
|
function FrontLightWidget:update()
|
|
|
|
|
-- header
|
|
|
|
|
self.light_title = FrameContainer:new{
|
2017-10-16 15:51:56 +00:00
|
|
|
|
padding = Size.padding.default,
|
2017-09-13 14:56:20 +00:00
|
|
|
|
margin = Size.margin.title,
|
2016-12-01 17:58:06 +00:00
|
|
|
|
bordersize = 0,
|
|
|
|
|
TextWidget:new{
|
|
|
|
|
text = _("Frontlight"),
|
|
|
|
|
face = self.title_face,
|
|
|
|
|
bold = true,
|
|
|
|
|
width = self.screen_width * 0.95,
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
local light_level = FrameContainer:new{
|
2017-09-13 14:56:20 +00:00
|
|
|
|
padding = Size.padding.button,
|
|
|
|
|
margin = Size.margin.small,
|
2016-12-01 17:58:06 +00:00
|
|
|
|
bordersize = 0,
|
|
|
|
|
self:generateProgressGroup(self.screen_width * 0.95, self.screen_height * 0.20,
|
|
|
|
|
self.fl_cur, self.one_step)
|
|
|
|
|
}
|
|
|
|
|
local light_line = LineWidget:new{
|
|
|
|
|
dimen = Geom:new{
|
|
|
|
|
w = self.width,
|
2017-09-13 14:56:20 +00:00
|
|
|
|
h = Size.line.thick,
|
2016-12-01 17:58:06 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
self.light_bar = OverlapGroup:new{
|
|
|
|
|
dimen = {
|
|
|
|
|
w = self.width,
|
|
|
|
|
h = self.light_title:getSize().h
|
|
|
|
|
},
|
|
|
|
|
self.light_title,
|
2017-10-16 15:51:56 +00:00
|
|
|
|
CloseButton:new{ window = self, padding_top = Size.margin.title, },
|
2016-12-01 17:58:06 +00:00
|
|
|
|
}
|
|
|
|
|
self.light_frame = FrameContainer:new{
|
2017-09-13 14:56:20 +00:00
|
|
|
|
radius = Size.radius.window,
|
|
|
|
|
bordersize = Size.border.window,
|
2016-12-01 17:58:06 +00:00
|
|
|
|
padding = 0,
|
|
|
|
|
margin = 0,
|
|
|
|
|
background = Blitbuffer.COLOR_WHITE,
|
|
|
|
|
VerticalGroup:new{
|
|
|
|
|
align = "left",
|
|
|
|
|
self.light_bar,
|
|
|
|
|
light_line,
|
|
|
|
|
CenterContainer:new{
|
|
|
|
|
dimen = Geom:new{
|
|
|
|
|
w = light_line:getSize().w,
|
|
|
|
|
h = light_level:getSize().h,
|
|
|
|
|
},
|
|
|
|
|
light_level,
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
self[1] = WidgetContainer:new{
|
|
|
|
|
align = "center",
|
|
|
|
|
dimen =Geom:new{
|
|
|
|
|
x = 0, y = 0,
|
|
|
|
|
w = self.screen_width,
|
|
|
|
|
h = self.screen_height,
|
|
|
|
|
},
|
|
|
|
|
FrameContainer:new{
|
|
|
|
|
bordersize = 0,
|
|
|
|
|
self.light_frame,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function FrontLightWidget:onCloseWidget()
|
|
|
|
|
UIManager:setDirty(nil, function()
|
2018-06-02 16:10:55 +00:00
|
|
|
|
return "flashpartial", self.light_frame.dimen
|
2016-12-01 17:58:06 +00:00
|
|
|
|
end)
|
|
|
|
|
return true
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function FrontLightWidget:onShow()
|
2018-06-02 16:10:55 +00:00
|
|
|
|
-- NOTE: Keep this one as UI, it'll get coalesced...
|
2016-12-01 17:58:06 +00:00
|
|
|
|
UIManager:setDirty(self, function()
|
|
|
|
|
return "ui", self.light_frame.dimen
|
|
|
|
|
end)
|
|
|
|
|
return true
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function FrontLightWidget:onAnyKeyPressed()
|
|
|
|
|
UIManager:close(self)
|
|
|
|
|
return true
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function FrontLightWidget:onClose()
|
|
|
|
|
UIManager:close(self)
|
|
|
|
|
return true
|
|
|
|
|
end
|
|
|
|
|
|
2018-03-08 21:23:05 +00:00
|
|
|
|
-- This is called when natural light configuration is shown
|
|
|
|
|
function FrontLightWidget:naturalLightConfigOpen()
|
|
|
|
|
-- Remove the close button
|
|
|
|
|
table.remove(self.light_bar)
|
|
|
|
|
-- Disable the 'configure' button
|
|
|
|
|
self.configure_button:disable()
|
|
|
|
|
self.nl_configure_open = true
|
|
|
|
|
-- Move to the bottom to make place for the new widget
|
|
|
|
|
self[1].align="bottom"
|
Enable HW dithering in a few key places (#4541)
* Enable HW dithering on supported devices (Clara HD, Forma; Oasis 2, PW4)
* FileManager and co. (where appropriate, i.e., when covers are shown)
* Book Status
* Reader, where appropriate:
* CRe: on pages whith image content (for over 7.5% of the screen area, should hopefully leave stuff like bullet points or small scene breaks alone).
* Other engines: on user-request (in the gear tab of the bottom menu), via the new "Dithering" knob (will only appear on supported devices).
* ScreenSaver
* ImageViewer
* Minimize repaints when flash_ui is enabled (by, almost everywhere, only repainting the flashing element, and not the toplevel window which hosts it).
(The first pass of this involved fixing a few Button instances whose show_parent was wrong, in particular, chevrons in the FM & TopMenu).
* Hunted down a few redundant repaints (unneeded setDirty("all") calls),
either by switching the widget to nil when only a refresh was needed, and not a repaint,
or by passing the appropritate widget to setDirty.
(Note to self: Enable *verbose* debugging to catch broken setDirty calls via its post guard).
There were also a few instances of 'em right behind a widget close.
* Don't repaint the underlying widget when initially showing TopMenu & ConfigDialog.
We unfortunately do need to do it when switching tabs, because of their variable heights.
* On Kobo, disabled the extra and completely useless full refresh before suspend/reboot/poweroff, as well as on resume. No more double refreshes!
* Fix another debug guard in Kobo sysfs_light
* Switch ImageWidget & ImageViewer mostly to "ui" updates, which will be better suited to image content pretty much everywhere, REAGL or not.
PS: (Almost :100: commits! :D)
2019-02-07 00:14:37 +00:00
|
|
|
|
UIManager:setDirty(self, "ui")
|
2018-03-08 21:23:05 +00:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function FrontLightWidget:naturalLightConfigClose()
|
|
|
|
|
table.insert(self.light_bar,
|
|
|
|
|
CloseButton:new{window = self,
|
|
|
|
|
padding_top = Size.margin.title})
|
|
|
|
|
self.configure_button:enable()
|
|
|
|
|
self.nl_configure_open = false
|
|
|
|
|
self[1].align="center"
|
Enable HW dithering in a few key places (#4541)
* Enable HW dithering on supported devices (Clara HD, Forma; Oasis 2, PW4)
* FileManager and co. (where appropriate, i.e., when covers are shown)
* Book Status
* Reader, where appropriate:
* CRe: on pages whith image content (for over 7.5% of the screen area, should hopefully leave stuff like bullet points or small scene breaks alone).
* Other engines: on user-request (in the gear tab of the bottom menu), via the new "Dithering" knob (will only appear on supported devices).
* ScreenSaver
* ImageViewer
* Minimize repaints when flash_ui is enabled (by, almost everywhere, only repainting the flashing element, and not the toplevel window which hosts it).
(The first pass of this involved fixing a few Button instances whose show_parent was wrong, in particular, chevrons in the FM & TopMenu).
* Hunted down a few redundant repaints (unneeded setDirty("all") calls),
either by switching the widget to nil when only a refresh was needed, and not a repaint,
or by passing the appropritate widget to setDirty.
(Note to self: Enable *verbose* debugging to catch broken setDirty calls via its post guard).
There were also a few instances of 'em right behind a widget close.
* Don't repaint the underlying widget when initially showing TopMenu & ConfigDialog.
We unfortunately do need to do it when switching tabs, because of their variable heights.
* On Kobo, disabled the extra and completely useless full refresh before suspend/reboot/poweroff, as well as on resume. No more double refreshes!
* Fix another debug guard in Kobo sysfs_light
* Switch ImageWidget & ImageViewer mostly to "ui" updates, which will be better suited to image content pretty much everywhere, REAGL or not.
PS: (Almost :100: commits! :D)
2019-02-07 00:14:37 +00:00
|
|
|
|
UIManager:setDirty(self, "ui")
|
2018-03-08 21:23:05 +00:00
|
|
|
|
end
|
|
|
|
|
|
2019-09-26 22:38:44 +00:00
|
|
|
|
function FrontLightWidget:onTapProgress(arg, ges_ev)
|
|
|
|
|
if ges_ev.pos:intersectWith(self.fl_group.dimen) then
|
|
|
|
|
-- Unschedule any pending updates.
|
|
|
|
|
UIManager:unschedule(self.update)
|
|
|
|
|
|
|
|
|
|
local width = self.fl_group.dimen.w
|
|
|
|
|
local pos = ges_ev.pos.x - self.fl_group.dimen.x
|
|
|
|
|
local perc = pos / width
|
|
|
|
|
local num = Math.round(perc * self.fl_max)
|
|
|
|
|
|
|
|
|
|
-- Always set the frontlight intensity.
|
|
|
|
|
self:setFrontLightIntensity(num)
|
|
|
|
|
|
|
|
|
|
-- But limit the widget update frequency on E Ink.
|
|
|
|
|
if Screen.low_pan_rate then
|
|
|
|
|
local current_time = TimeVal:now()
|
|
|
|
|
local last_time = self.last_time or TimeVal:new{}
|
|
|
|
|
if current_time - last_time > TimeVal:new{usec = 1000000 / self.rate} then
|
|
|
|
|
self.last_time = current_time
|
|
|
|
|
else
|
|
|
|
|
-- Schedule a final update after we stop panning.
|
|
|
|
|
UIManager:scheduleIn(0.075, self.update, self)
|
|
|
|
|
return true
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
self:update()
|
|
|
|
|
elseif not ges_ev.pos:intersectWith(self.light_frame.dimen) and ges_ev.ges == "tap" then
|
|
|
|
|
-- close if tap outside
|
|
|
|
|
self:onClose()
|
|
|
|
|
end
|
|
|
|
|
-- otherwise, do nothing (it's easy missing taping a button)
|
|
|
|
|
return true
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
FrontLightWidget.onPanProgress = FrontLightWidget.onTapProgress
|
|
|
|
|
|
2016-12-01 17:58:06 +00:00
|
|
|
|
return FrontLightWidget
|