It seems I can only edit a post once, so sorry for the double post.
New modification: buttons activate when pressed down then up:
function TextButton:init(s, left, bottom, right, top)
Control.init(self, s, left, bottom, right, top)
self.controlName = "TextButton"
self.pressed = false
self.background = color(119, 158, 199, 255)
self.highlight = color(64, 192, 66, 255)
self.grabbed = false
end
function TextButton:touched(touch)
if self:ptIn(touch.x, touch.y) and touch.state == BEGAN then
self.grabbed = true
end
if self.grabbed then
if self:ptIn(touch.x, touch.y) then
self.pressed = true
else
self.pressed = false
end
if touch.state == ENDED then
if self.pressed then
return true
end
self.grabbed = false
end
end
return false
end
function IconButton:init(s, left, bottom, right, top, img)
Control.init(self, s, left, bottom, right, top)
self.controlName = "IconButton"
self.foreground = color(191, 191, 191, 255)
self.background = color(91, 91, 91, 255)
self.img = img
self.textAlign = CENTER
self.vertAlign = BOTTOM
self.grabbed = false
end
function IconButton:touched(touch)
if self:ptIn(touch.x, touch.y) and touch.state == BEGAN then
self.grabbed = true
end
if self.grabbed then
if touch.state == ENDED then
if self:ptIn(touch.x, touch.y) then
return true
end
self.grabbed = false
end
end
return false
end
Now dialogs!
function Dialog:init(t, left, bottom, right, top)
Control.init(self, t, left, bottom, right, top)
self.controlName = "Dialog"
self.text = t
self.inner = Frame(left + 4, bottom + 4, right - 4, top - 40)
self.background = color(255, 255, 255, 255)
self.grabbed = false
self.showing = false
end
function Dialog:touched(touch)
if self.showing and self:ptIn(touch.x, touch.y) then
if touch.state == BEGAN then
self.grabbed = true
end
end
if self.grabbed then
if touch.state == ENDED then
self.grabbed = false
if self:ptIn(touch.x, touch.y) then
return true
end
end
end
return false
end
function Dialog:show()
self.showing = true
end
function Dialog:hide()
self.showing = false
end
Notch slider:
function NotchSlider:init(s, left, bottom, right, top)
Control.init(self, s, left, bottom, right, top)
self.controlName = "NotchSlider"
self.itemText = {}
self:splitText()
self.grabbed = false
end
function NotchSlider:touched(touch)
local x, scale
if touch.state == BEGAN then
if self:ptIn(touch.x, touch.y) then
self.grabbed = true
else
self.grabbed = false
end
end
if self.grabbed then
if #self.itemText > 1 then
scale = self:width() / (#self.itemText - 1)
x = touch.x - self.left + 20
self.selected = math.floor(x / scale) + 1
end
return true
end
end
Text box:
function TextBox:touched(touch)
if touch.state == BEGAN then
if self:ptIn(touch.x, touch.y) then
CCActiveTextBox = self
if not isKeyboardShowing() then showKeyboard() end
return true
elseif CCActiveTextBox == self then
CCActiveTextBox = nil
end
else
return false
end
return true
end