2013-03-12 17:18:53 +00:00
|
|
|
require "ui/widget/container"
|
|
|
|
require "ui/widget/toggleswitch"
|
2012-12-19 15:45:51 +00:00
|
|
|
|
2012-12-23 23:54:44 +00:00
|
|
|
MenuBarItem = InputContainer:new{}
|
|
|
|
function MenuBarItem:init()
|
|
|
|
self.dimen = self[1]:getSize()
|
|
|
|
-- we need this table per-instance, so we declare it here
|
2012-12-14 10:20:04 +00:00
|
|
|
if Device:isTouchDevice() then
|
|
|
|
self.ges_events = {
|
|
|
|
TapSelect = {
|
|
|
|
GestureRange:new{
|
|
|
|
ges = "tap",
|
|
|
|
range = self.dimen,
|
|
|
|
},
|
2013-04-08 07:29:23 +00:00
|
|
|
doc = _("Select Menu Item"),
|
2012-12-14 10:20:04 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
else
|
|
|
|
self.active_key_events = {
|
2013-04-08 07:29:23 +00:00
|
|
|
Select = { {"Press"}, doc = _("chose selected item") },
|
2012-12-14 10:20:04 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-12-23 23:54:44 +00:00
|
|
|
function MenuBarItem:onTapSelect()
|
2013-01-15 09:24:38 +00:00
|
|
|
self[1].invert = true
|
|
|
|
self.config:onShowConfigPanel(self.index)
|
2013-01-15 11:11:16 +00:00
|
|
|
UIManager:scheduleIn(0.5, function() self:invert(false) end)
|
2012-12-14 10:20:04 +00:00
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2013-01-15 09:24:38 +00:00
|
|
|
function MenuBarItem:invert(invert)
|
|
|
|
self[1].invert = invert
|
|
|
|
UIManager:setDirty(self.config, "partial")
|
|
|
|
end
|
|
|
|
|
2012-12-23 23:54:44 +00:00
|
|
|
OptionTextItem = InputContainer:new{}
|
|
|
|
function OptionTextItem:init()
|
|
|
|
local text_widget = self[1]
|
|
|
|
self.dimen = text_widget:getSize()
|
|
|
|
self[1] = UnderlineContainer:new{
|
|
|
|
text_widget,
|
|
|
|
padding = self.padding,
|
|
|
|
color = self.color,
|
|
|
|
}
|
|
|
|
-- we need this table per-instance, so we declare it here
|
|
|
|
if Device:isTouchDevice() then
|
|
|
|
self.ges_events = {
|
|
|
|
TapSelect = {
|
|
|
|
GestureRange:new{
|
|
|
|
ges = "tap",
|
|
|
|
range = self.dimen,
|
|
|
|
},
|
2013-04-08 07:29:23 +00:00
|
|
|
doc = _("Select Option Item"),
|
2012-12-23 23:54:44 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
else
|
|
|
|
self.active_key_events = {
|
2013-04-08 07:29:23 +00:00
|
|
|
Select = { {"Press"}, doc = _("chose selected item") },
|
2012-12-23 23:54:44 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function OptionTextItem:onTapSelect()
|
|
|
|
for _, item in pairs(self.items) do
|
|
|
|
item[1].color = 0
|
|
|
|
end
|
|
|
|
self[1].color = 15
|
|
|
|
local option_value = nil
|
2013-01-07 17:07:06 +00:00
|
|
|
local option_arg = nil
|
2013-02-02 20:42:59 +00:00
|
|
|
if self.values then
|
|
|
|
self.values = self.values or {}
|
2012-12-23 23:54:44 +00:00
|
|
|
option_value = self.values[self.current_item]
|
2013-02-02 20:42:59 +00:00
|
|
|
self.config:onConfigChoice(self.name, option_value)
|
|
|
|
end
|
|
|
|
if self.event then
|
|
|
|
self.args = self.args or {}
|
2013-01-07 17:07:06 +00:00
|
|
|
option_arg = self.args[self.current_item]
|
2013-02-02 20:42:59 +00:00
|
|
|
self.config:onConfigEvent(self.event, option_arg)
|
|
|
|
end
|
|
|
|
if self.events then
|
|
|
|
for i=0,#self.events do
|
|
|
|
self.events[i].args = self.events[i].args or {}
|
|
|
|
option_arg = self.events[i].args[self.current_item]
|
|
|
|
self.config:onConfigEvent(self.events[i].event, option_arg)
|
|
|
|
end
|
2012-12-23 23:54:44 +00:00
|
|
|
end
|
2013-01-15 04:35:37 +00:00
|
|
|
UIManager.repaint_all = true
|
2012-12-23 23:54:44 +00:00
|
|
|
return true
|
|
|
|
end
|
2012-12-14 10:20:04 +00:00
|
|
|
|
2013-02-03 03:26:14 +00:00
|
|
|
OptionIconItem = InputContainer:new{}
|
|
|
|
function OptionIconItem:init()
|
|
|
|
self.dimen = self.icon:getSize()
|
|
|
|
self[1] = UnderlineContainer:new{
|
|
|
|
self.icon,
|
|
|
|
padding = self.padding,
|
|
|
|
color = self.color,
|
|
|
|
}
|
|
|
|
-- we need this table per-instance, so we declare it here
|
|
|
|
if Device:isTouchDevice() then
|
|
|
|
self.ges_events = {
|
|
|
|
TapSelect = {
|
|
|
|
GestureRange:new{
|
|
|
|
ges = "tap",
|
|
|
|
range = self.dimen,
|
|
|
|
},
|
2013-04-08 07:29:23 +00:00
|
|
|
doc = _("Select Option Item"),
|
2013-02-03 03:26:14 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function OptionIconItem:onTapSelect()
|
|
|
|
for _, item in pairs(self.items) do
|
|
|
|
--item[1][1].invert = false
|
|
|
|
item[1].color = 0
|
|
|
|
end
|
|
|
|
--self[1][1].invert = true
|
|
|
|
self[1].color = 15
|
|
|
|
local option_value = nil
|
|
|
|
local option_arg = nil
|
|
|
|
if type(self.values) == "table" then
|
|
|
|
option_value = self.values[self.current_item]
|
|
|
|
self.config:onConfigChoice(self.name, option_value, self.event)
|
|
|
|
elseif type(self.args) == "table" then
|
|
|
|
option_arg = self.args[self.current_item]
|
|
|
|
self.config:onConfigChoice(self.name, option_arg, self.event)
|
|
|
|
end
|
|
|
|
UIManager.repaint_all = true
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2013-01-25 15:53:00 +00:00
|
|
|
--[[
|
|
|
|
Dummy Widget that reserves vertical and horizontal space
|
|
|
|
]]
|
|
|
|
RectSpan = Widget:new{
|
|
|
|
width = 0,
|
|
|
|
hright = 0,
|
|
|
|
}
|
|
|
|
|
|
|
|
function RectSpan:getSize()
|
|
|
|
return {w = self.width, h = self.height}
|
|
|
|
end
|
|
|
|
|
2013-01-14 16:33:03 +00:00
|
|
|
ConfigOption = CenterContainer:new{}
|
2012-12-19 15:45:51 +00:00
|
|
|
function ConfigOption:init()
|
2013-02-05 10:15:45 +00:00
|
|
|
local default_name_font_size = 20
|
|
|
|
local default_item_font_size = 16
|
|
|
|
local default_items_spacing = 30
|
|
|
|
local default_option_height = 50
|
|
|
|
local default_option_padding = 15
|
2012-12-19 15:45:51 +00:00
|
|
|
local vertical_group = VerticalGroup:new{}
|
2013-03-16 00:03:50 +00:00
|
|
|
table.insert(vertical_group, VerticalSpan:new{
|
|
|
|
width = scaleByDPI(default_option_padding),
|
|
|
|
})
|
2012-12-19 15:45:51 +00:00
|
|
|
for c = 1, #self.options do
|
2012-12-23 23:54:44 +00:00
|
|
|
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
|
|
|
|
local item_align = self.options[c].item_align_center and self.options[c].item_align_center or 0.66
|
2013-02-02 21:16:19 +00:00
|
|
|
local name_font_face = self.options[c].name_font_face and self.options[c].name_font_face or "cfont"
|
2012-12-23 23:54:44 +00:00
|
|
|
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
|
2013-03-16 00:03:50 +00:00
|
|
|
local option_height = scaleByDPI(self.options[c].height and self.options[c].height or default_option_height)
|
2013-03-12 17:18:53 +00:00
|
|
|
local items_spacing = HorizontalSpan:new{
|
2013-03-16 00:03:50 +00:00
|
|
|
width = scaleByDPI(self.options[c].spacing and self.options[c].spacing or default_items_spacing)
|
2013-02-25 13:59:10 +00:00
|
|
|
}
|
2012-12-23 23:54:44 +00:00
|
|
|
local horizontal_group = HorizontalGroup:new{}
|
|
|
|
if self.options[c].name_text then
|
|
|
|
local option_name_container = RightContainer:new{
|
|
|
|
dimen = Geom:new{ w = Screen:getWidth()*name_align, h = option_height},
|
|
|
|
}
|
|
|
|
local option_name = TextWidget:new{
|
|
|
|
text = self.options[c].name_text,
|
|
|
|
face = Font:getFace(name_font_face, name_font_size),
|
|
|
|
}
|
|
|
|
table.insert(option_name_container, option_name)
|
|
|
|
table.insert(horizontal_group, option_name_container)
|
|
|
|
end
|
2013-03-12 17:18:53 +00:00
|
|
|
|
2012-12-23 23:54:44 +00:00
|
|
|
if self.options[c].widget == "ProgressWidget" then
|
|
|
|
local widget_container = CenterContainer:new{
|
|
|
|
dimen = Geom:new{w = Screen:getWidth()*self.options[c].widget_align_center, h = option_height}
|
|
|
|
}
|
|
|
|
local widget = ProgressWidget:new{
|
|
|
|
width = self.options[c].width,
|
|
|
|
height = self.options[c].height,
|
|
|
|
percentage = self.options[c].percentage,
|
|
|
|
}
|
|
|
|
table.insert(widget_container, widget)
|
|
|
|
table.insert(horizontal_group, widget_container)
|
|
|
|
end
|
2013-03-12 17:18:53 +00:00
|
|
|
|
2012-12-23 23:54:44 +00:00
|
|
|
local option_items_container = CenterContainer:new{
|
|
|
|
dimen = Geom:new{w = Screen:getWidth()*item_align, h = option_height}
|
2012-12-19 15:45:51 +00:00
|
|
|
}
|
2012-12-23 23:54:44 +00:00
|
|
|
local option_items_group = HorizontalGroup:new{}
|
|
|
|
local option_items_fixed = false
|
|
|
|
local option_items = {}
|
|
|
|
if type(self.options[c].item_font_size) == "table" then
|
|
|
|
option_items_group.align = "bottom"
|
|
|
|
option_items_fixed = true
|
|
|
|
end
|
|
|
|
-- make current index according to configurable table
|
|
|
|
local current_item = nil
|
2013-07-19 18:46:51 +00:00
|
|
|
local function value_diff(val1, val2, name)
|
|
|
|
if type(val1) ~= type(val2) then
|
|
|
|
error("different data types in option", name)
|
|
|
|
end
|
|
|
|
if type(val1) == "number" then
|
|
|
|
return math.abs(val1 - val2)
|
|
|
|
elseif type(val1) == "string" then
|
|
|
|
return val1 == val2 and 0 or 1
|
|
|
|
end
|
|
|
|
end
|
2012-12-23 23:54:44 +00:00
|
|
|
if self.options[c].name then
|
2013-01-07 17:07:06 +00:00
|
|
|
if self.options[c].values then
|
2013-02-10 12:52:44 +00:00
|
|
|
-- check if current value is stored in configurable or calculated in runtime
|
|
|
|
local val = self.options[c].current_func and self.options[c].current_func()
|
|
|
|
or self.config.configurable[self.options[c].name]
|
2013-06-28 09:08:10 +00:00
|
|
|
local min_diff = nil
|
|
|
|
if type(val) == "table" then
|
2013-07-19 18:46:51 +00:00
|
|
|
min_diff = value_diff(val[1], self.options[c].values[1][1])
|
2013-06-28 09:08:10 +00:00
|
|
|
else
|
2013-07-19 18:46:51 +00:00
|
|
|
min_diff = value_diff(val, self.options[c].values[1])
|
2013-06-28 09:08:10 +00:00
|
|
|
end
|
|
|
|
|
2013-01-07 17:07:06 +00:00
|
|
|
local diff = nil
|
|
|
|
for index, val_ in pairs(self.options[c].values) do
|
2013-06-28 09:08:10 +00:00
|
|
|
local diff = nil
|
|
|
|
if type(val) == "table" then
|
2013-07-19 18:46:51 +00:00
|
|
|
diff = value_diff(val[1], val_[1])
|
2013-06-28 09:08:10 +00:00
|
|
|
else
|
2013-07-19 18:46:51 +00:00
|
|
|
diff = value_diff(val, val_)
|
2013-06-28 09:08:10 +00:00
|
|
|
end
|
2013-01-07 17:07:06 +00:00
|
|
|
if val == val_ then
|
|
|
|
current_item = index
|
|
|
|
break
|
|
|
|
end
|
|
|
|
if diff <= min_diff then
|
|
|
|
min_diff = diff
|
|
|
|
current_item = index
|
|
|
|
end
|
2012-12-23 23:54:44 +00:00
|
|
|
end
|
2013-01-07 17:07:06 +00:00
|
|
|
elseif self.options[c].args then
|
2013-02-10 12:52:44 +00:00
|
|
|
-- check if current arg is stored in configurable or calculated in runtime
|
|
|
|
local arg = self.options[c].current_func and self.options[c].current_func()
|
|
|
|
or self.config.configurable[self.options[c].name]
|
2013-01-07 17:07:06 +00:00
|
|
|
for idx, arg_ in pairs(self.options[c].args) do
|
|
|
|
if arg_ == arg then
|
|
|
|
current_item = idx
|
|
|
|
break
|
|
|
|
end
|
2012-12-23 23:54:44 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2013-03-12 17:18:53 +00:00
|
|
|
|
2013-01-25 15:53:00 +00:00
|
|
|
if self.options[c].item_text then
|
|
|
|
for d = 1, #self.options[c].item_text do
|
|
|
|
local option_item = nil
|
|
|
|
if option_items_fixed then
|
|
|
|
option_item = OptionTextItem:new{
|
|
|
|
FixedTextWidget:new{
|
|
|
|
text = self.options[c].item_text[d],
|
|
|
|
face = Font:getFace(item_font_face, item_font_size[d]),
|
|
|
|
},
|
|
|
|
padding = 3,
|
|
|
|
color = d == current_item and 15 or 0,
|
|
|
|
}
|
|
|
|
else
|
|
|
|
option_item = OptionTextItem:new{
|
|
|
|
TextWidget:new{
|
|
|
|
text = self.options[c].item_text[d],
|
|
|
|
face = Font:getFace(item_font_face, item_font_size),
|
|
|
|
},
|
|
|
|
padding = -3,
|
|
|
|
color = d == current_item and 15 or 0,
|
|
|
|
}
|
|
|
|
end
|
|
|
|
option_items[d] = option_item
|
|
|
|
option_item.items = option_items
|
|
|
|
option_item.name = self.options[c].name
|
|
|
|
option_item.values = self.options[c].values
|
|
|
|
option_item.args = self.options[c].args
|
|
|
|
option_item.event = self.options[c].event
|
|
|
|
option_item.current_item = d
|
|
|
|
option_item.config = self.config
|
|
|
|
table.insert(option_items_group, option_item)
|
|
|
|
if d ~= #self.options[c].item_text then
|
|
|
|
table.insert(option_items_group, items_spacing)
|
|
|
|
end
|
2012-12-24 08:55:10 +00:00
|
|
|
end
|
2012-12-23 23:54:44 +00:00
|
|
|
end
|
2013-03-12 17:18:53 +00:00
|
|
|
|
2013-02-03 03:26:14 +00:00
|
|
|
if self.options[c].item_icons then
|
|
|
|
for d = 1, #self.options[c].item_icons do
|
|
|
|
local option_item = OptionIconItem:new{
|
|
|
|
icon = ImageWidget:new{
|
|
|
|
file = self.options[c].item_icons[d]
|
|
|
|
},
|
|
|
|
padding = -2,
|
|
|
|
color = d == current_item and 15 or 0,
|
|
|
|
}
|
|
|
|
option_items[d] = option_item
|
|
|
|
option_item.items = option_items
|
|
|
|
option_item.name = self.options[c].name
|
|
|
|
option_item.values = self.options[c].values
|
|
|
|
option_item.args = self.options[c].args
|
|
|
|
option_item.event = self.options[c].event
|
|
|
|
option_item.current_item = d
|
|
|
|
option_item.config = self.config
|
|
|
|
table.insert(option_items_group, option_item)
|
|
|
|
if d ~= #self.options[c].item_icons then
|
|
|
|
table.insert(option_items_group, items_spacing)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2013-03-12 17:18:53 +00:00
|
|
|
|
2013-01-25 15:53:00 +00:00
|
|
|
if self.options[c].toggle then
|
|
|
|
local switch = ToggleSwitch:new{
|
|
|
|
name = self.options[c].name,
|
|
|
|
toggle = self.options[c].toggle,
|
2013-02-02 20:42:59 +00:00
|
|
|
alternate = self.options[c].alternate,
|
2013-01-25 15:53:00 +00:00
|
|
|
values = self.options[c].values,
|
|
|
|
args = self.options[c].args,
|
|
|
|
event = self.options[c].event,
|
2013-02-02 20:42:59 +00:00
|
|
|
events = self.options[c].events,
|
2013-01-25 15:53:00 +00:00
|
|
|
config = self.config,
|
|
|
|
}
|
|
|
|
local position = current_item
|
|
|
|
switch:setPosition(position)
|
|
|
|
table.insert(option_items_group, switch)
|
|
|
|
end
|
2013-03-12 17:18:53 +00:00
|
|
|
|
2012-12-23 23:54:44 +00:00
|
|
|
table.insert(option_items_container, option_items_group)
|
|
|
|
table.insert(horizontal_group, option_items_container)
|
|
|
|
table.insert(vertical_group, horizontal_group)
|
|
|
|
end -- if
|
|
|
|
end -- for
|
2013-01-14 16:33:03 +00:00
|
|
|
table.insert(vertical_group, VerticalSpan:new{ width = default_option_padding })
|
2012-12-19 15:45:51 +00:00
|
|
|
self[1] = vertical_group
|
2013-01-14 16:33:03 +00:00
|
|
|
self.dimen = vertical_group:getSize()
|
2012-12-19 15:45:51 +00:00
|
|
|
end
|
|
|
|
|
2013-01-15 09:24:38 +00:00
|
|
|
ConfigPanel = FrameContainer:new{ background = 0, bordersize = 0, }
|
2012-12-23 23:54:44 +00:00
|
|
|
function ConfigPanel:init()
|
2013-01-15 09:24:38 +00:00
|
|
|
local config_options = self.config_dialog.config_options
|
2013-03-12 17:18:53 +00:00
|
|
|
local default_option = config_options.default_options and config_options.default_options
|
2013-01-15 09:24:38 +00:00
|
|
|
or config_options[1].options
|
|
|
|
local panel = ConfigOption:new{
|
|
|
|
options = self.index and config_options[self.index].options or default_option,
|
|
|
|
config = self.config_dialog,
|
2012-12-23 23:54:44 +00:00
|
|
|
}
|
2013-01-15 09:24:38 +00:00
|
|
|
self.dimen = panel:getSize()
|
|
|
|
table.insert(self, panel)
|
|
|
|
end
|
|
|
|
|
|
|
|
MenuBar = FrameContainer:new{ background = 0, }
|
|
|
|
function MenuBar:init()
|
|
|
|
local config_options = self.config_dialog.config_options
|
2012-12-23 23:54:44 +00:00
|
|
|
local menu_items = {}
|
|
|
|
local icons_width = 0
|
|
|
|
local icons_height = 0
|
2013-01-15 09:24:38 +00:00
|
|
|
for c = 1, #config_options do
|
2012-12-23 23:54:44 +00:00
|
|
|
local menu_icon = ImageWidget:new{
|
2013-01-15 09:24:38 +00:00
|
|
|
file = config_options[c].icon
|
2012-12-23 23:54:44 +00:00
|
|
|
}
|
|
|
|
local icon_dimen = menu_icon:getSize()
|
|
|
|
icons_width = icons_width + icon_dimen.w
|
|
|
|
icons_height = icon_dimen.h > icons_height and icon_dimen.h or icons_height
|
2013-03-12 17:18:53 +00:00
|
|
|
|
2012-12-23 23:54:44 +00:00
|
|
|
menu_items[c] = MenuBarItem:new{
|
|
|
|
menu_icon,
|
2013-01-14 16:33:03 +00:00
|
|
|
index = c,
|
2012-12-23 23:54:44 +00:00
|
|
|
config = self.config_dialog,
|
2012-12-19 15:45:51 +00:00
|
|
|
}
|
|
|
|
end
|
2013-03-12 17:18:53 +00:00
|
|
|
|
2013-01-15 09:24:38 +00:00
|
|
|
local spacing = HorizontalSpan:new{
|
|
|
|
width = (Screen:getWidth() - icons_width) / (#menu_items+1)
|
|
|
|
}
|
2013-03-12 17:18:53 +00:00
|
|
|
|
2013-01-15 09:24:38 +00:00
|
|
|
local menu_bar = HorizontalGroup:new{}
|
2013-03-12 17:18:53 +00:00
|
|
|
|
2013-01-15 09:24:38 +00:00
|
|
|
for c = 1, #menu_items do
|
|
|
|
table.insert(menu_bar, spacing)
|
|
|
|
table.insert(menu_bar, menu_items[c])
|
|
|
|
end
|
|
|
|
table.insert(menu_bar, spacing)
|
2013-03-12 17:18:53 +00:00
|
|
|
|
2013-01-15 09:24:38 +00:00
|
|
|
self.dimen = Geom:new{ w = Screen:getWidth(), h = icons_height}
|
|
|
|
table.insert(self, menu_bar)
|
2013-01-14 16:33:03 +00:00
|
|
|
end
|
|
|
|
|
2012-12-14 10:20:04 +00:00
|
|
|
--[[
|
2013-01-15 09:24:38 +00:00
|
|
|
Widget that displays config menubar and config panel
|
|
|
|
|
|
|
|
+----------------+
|
|
|
|
| |
|
|
|
|
| |
|
|
|
|
| |
|
|
|
|
| |
|
|
|
|
| |
|
|
|
|
+----------------+
|
|
|
|
| |
|
|
|
|
| Config Panel |
|
|
|
|
| |
|
|
|
|
+----------------+
|
|
|
|
| Menu Bar |
|
|
|
|
+----------------+
|
2013-03-12 17:18:53 +00:00
|
|
|
|
2012-12-14 10:20:04 +00:00
|
|
|
--]]
|
2013-01-15 09:24:38 +00:00
|
|
|
|
2012-12-23 23:54:44 +00:00
|
|
|
ConfigDialog = InputContainer:new{
|
|
|
|
--is_borderless = false,
|
2013-07-16 06:15:22 +00:00
|
|
|
panel_index = 1,
|
2012-12-14 10:20:04 +00:00
|
|
|
}
|
|
|
|
|
2012-12-23 23:54:44 +00:00
|
|
|
function ConfigDialog:init()
|
|
|
|
------------------------------------------
|
|
|
|
-- start to set up widget layout ---------
|
|
|
|
------------------------------------------
|
2013-01-15 09:24:38 +00:00
|
|
|
self.config_panel = ConfigPanel:new{
|
|
|
|
config_dialog = self,
|
|
|
|
}
|
2013-03-12 17:18:53 +00:00
|
|
|
self.config_menubar = MenuBar:new{
|
2013-01-15 09:24:38 +00:00
|
|
|
config_dialog = self,
|
|
|
|
}
|
|
|
|
self:makeDialog()
|
2012-12-14 10:20:04 +00:00
|
|
|
------------------------------------------
|
|
|
|
-- start to set up input event callback --
|
|
|
|
------------------------------------------
|
|
|
|
if Device:isTouchDevice() then
|
|
|
|
self.ges_events.TapCloseMenu = {
|
|
|
|
GestureRange:new{
|
|
|
|
ges = "tap",
|
|
|
|
range = Geom:new{
|
|
|
|
x = 0, y = 0,
|
|
|
|
w = Screen:getWidth(),
|
|
|
|
h = Screen:getHeight(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
-- set up keyboard events
|
2013-04-08 07:29:23 +00:00
|
|
|
self.key_events.Close = { {"Back"}, doc = _("close config menu") }
|
2012-12-14 10:20:04 +00:00
|
|
|
-- we won't catch presses to "Right"
|
|
|
|
self.key_events.FocusRight = nil
|
|
|
|
end
|
2013-04-08 07:29:23 +00:00
|
|
|
self.key_events.Select = { {"Press"}, doc = _("select current menu item") }
|
2013-03-12 17:18:53 +00:00
|
|
|
|
2013-01-14 16:33:03 +00:00
|
|
|
UIManager:setDirty(self, "partial")
|
|
|
|
end
|
|
|
|
|
2013-01-15 09:24:38 +00:00
|
|
|
function ConfigDialog:updateConfigPanel(index)
|
2013-07-16 06:15:22 +00:00
|
|
|
self.panel_index = index
|
2013-01-15 09:24:38 +00:00
|
|
|
self.config_panel = ConfigPanel:new{
|
|
|
|
index = index,
|
2013-01-14 16:33:03 +00:00
|
|
|
config_dialog = self,
|
|
|
|
}
|
2013-01-15 09:24:38 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function ConfigDialog:makeDialog()
|
2013-07-21 06:13:51 +00:00
|
|
|
self.dialog_frame = FrameContainer:new{
|
|
|
|
background = 0,
|
|
|
|
VerticalGroup:new{
|
|
|
|
self.config_panel,
|
|
|
|
self.config_menubar,
|
|
|
|
},
|
2013-01-15 09:24:38 +00:00
|
|
|
}
|
2013-03-12 17:18:53 +00:00
|
|
|
|
2013-01-14 16:33:03 +00:00
|
|
|
self[1] = BottomContainer:new{
|
|
|
|
dimen = Screen:getSize(),
|
2013-07-21 06:13:51 +00:00
|
|
|
self.dialog_frame,
|
2013-03-12 17:18:53 +00:00
|
|
|
}
|
2012-12-14 10:20:04 +00:00
|
|
|
end
|
|
|
|
|
2013-01-15 09:24:38 +00:00
|
|
|
function ConfigDialog:onShowConfigPanel(index)
|
|
|
|
self:updateConfigPanel(index)
|
|
|
|
self:makeDialog()
|
2012-12-19 15:45:51 +00:00
|
|
|
UIManager.repaint_all = true
|
2012-12-14 10:20:04 +00:00
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2013-02-02 20:42:59 +00:00
|
|
|
function ConfigDialog:onConfigChoice(option_name, option_value)
|
2013-02-03 09:49:02 +00:00
|
|
|
--DEBUG("config option value", option_name, option_value)
|
2013-02-02 20:42:59 +00:00
|
|
|
self.configurable[option_name] = option_value
|
2013-04-21 08:54:59 +00:00
|
|
|
self.ui:handleEvent(Event:new("StartActivityIndicator"))
|
2013-02-02 20:42:59 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function ConfigDialog:onConfigEvent(option_event, option_arg)
|
2013-02-03 09:49:02 +00:00
|
|
|
--DEBUG("config option event", option_event, option_arg)
|
2013-02-02 20:42:59 +00:00
|
|
|
self.ui:handleEvent(Event:new(option_event, option_arg))
|
2013-07-19 19:33:58 +00:00
|
|
|
self:onShowConfigPanel(self.panel_index)
|
2013-02-02 20:42:59 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function ConfigDialog:closeDialog()
|
2012-12-14 10:20:04 +00:00
|
|
|
UIManager:close(self)
|
|
|
|
if self.close_callback then
|
|
|
|
self.close_callback()
|
|
|
|
end
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
function ConfigDialog:onTapCloseMenu(arg, ges_ev)
|
2013-07-21 06:13:51 +00:00
|
|
|
if ges_ev.pos:notIntersectWith(self.dialog_frame.dimen) then
|
2013-02-02 20:42:59 +00:00
|
|
|
self:closeDialog()
|
2012-12-14 10:20:04 +00:00
|
|
|
return true
|
|
|
|
end
|
2012-12-23 23:54:44 +00:00
|
|
|
end
|