2013-10-18 20:38:07 +00:00
|
|
|
local InputContainer = require("ui/widget/container/inputcontainer")
|
|
|
|
local ImageWidget = require("ui/widget/imagewidget")
|
|
|
|
local GestureRange = require("ui/gesturerange")
|
|
|
|
local UIManager = require("ui/uimanager")
|
2013-03-14 02:52:09 +00:00
|
|
|
|
|
|
|
--[[
|
|
|
|
Button with a big icon image! Designed for touch device
|
|
|
|
--]]
|
2013-10-18 20:38:07 +00:00
|
|
|
local IconButton = InputContainer:new{
|
2014-03-13 13:52:43 +00:00
|
|
|
icon_file = "resources/info-confirm.png",
|
|
|
|
dimen = nil,
|
|
|
|
-- show_parent is used for UIManager:setDirty, so we can trigger repaint
|
|
|
|
show_parent = nil,
|
2014-11-20 07:52:05 +00:00
|
|
|
autoscale = true,
|
2014-03-13 13:52:43 +00:00
|
|
|
callback = function() end,
|
2013-03-14 02:52:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function IconButton:init()
|
2014-03-13 13:52:43 +00:00
|
|
|
self.image = ImageWidget:new{
|
2014-11-20 07:52:05 +00:00
|
|
|
file = self.icon_file,
|
|
|
|
autoscale = self.autoscale,
|
2014-03-13 13:52:43 +00:00
|
|
|
}
|
2013-03-14 02:52:09 +00:00
|
|
|
|
2014-03-13 13:52:43 +00:00
|
|
|
self.show_parent = self.show_parent or self
|
|
|
|
self.dimen = self.image:getSize()
|
2013-03-14 02:52:09 +00:00
|
|
|
|
2014-03-13 13:52:43 +00:00
|
|
|
self:initGesListener()
|
2013-03-14 02:52:09 +00:00
|
|
|
|
2014-03-13 13:52:43 +00:00
|
|
|
self[1] = self.image
|
2013-03-14 02:52:09 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function IconButton:initGesListener()
|
2014-03-13 13:52:43 +00:00
|
|
|
self.ges_events = {
|
|
|
|
TapClickButton = {
|
|
|
|
GestureRange:new{
|
|
|
|
ges = "tap",
|
|
|
|
range = self.dimen,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
2013-03-14 02:52:09 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function IconButton:onTapClickButton()
|
2014-11-14 14:07:14 +00:00
|
|
|
UIManager:scheduleIn(0.0, function()
|
|
|
|
self.image.invert = true
|
2014-11-30 00:12:00 +00:00
|
|
|
UIManager:setDirty(self.show_parent, function()
|
2015-04-26 18:07:17 +00:00
|
|
|
return "ui", self[1].dimen
|
2014-11-30 00:12:00 +00:00
|
|
|
end)
|
2014-11-14 14:07:14 +00:00
|
|
|
end)
|
2014-03-13 13:52:43 +00:00
|
|
|
-- make sure button reacts before doing callback
|
|
|
|
UIManager:scheduleIn(0.1, function()
|
|
|
|
self.callback()
|
|
|
|
self.image.invert = false
|
2014-11-30 00:12:00 +00:00
|
|
|
UIManager:setDirty(self.show_parent, function()
|
2015-04-26 18:07:17 +00:00
|
|
|
return "ui", self[1].dimen
|
2014-11-30 00:12:00 +00:00
|
|
|
end)
|
2014-03-13 13:52:43 +00:00
|
|
|
end)
|
|
|
|
return true
|
2013-03-14 02:52:09 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function IconButton:onSetDimensions(new_dimen)
|
2014-03-13 13:52:43 +00:00
|
|
|
self.dimen = new_dimen
|
2013-03-14 02:52:09 +00:00
|
|
|
end
|
|
|
|
|
2013-10-18 20:38:07 +00:00
|
|
|
return IconButton
|