<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-GB">
	<id>https://wiki.gideros.rocks/index.php?action=history&amp;feed=atom&amp;title=ButtonToggle_class</id>
	<title>ButtonToggle class - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.gideros.rocks/index.php?action=history&amp;feed=atom&amp;title=ButtonToggle_class"/>
	<link rel="alternate" type="text/html" href="https://wiki.gideros.rocks/index.php?title=ButtonToggle_class&amp;action=history"/>
	<updated>2026-11-17T15:56:49Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.11</generator>
	<entry>
		<id>https://wiki.gideros.rocks/index.php?title=ButtonToggle_class&amp;diff=23138&amp;oldid=prev</id>
		<title>MoKaLux at 01:33, 30 November 2023</title>
		<link rel="alternate" type="text/html" href="https://wiki.gideros.rocks/index.php?title=ButtonToggle_class&amp;diff=23138&amp;oldid=prev"/>
		<updated>2023-11-30T01:33:48Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en-GB&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 01:33, 30 November 2023&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l24&quot;&gt;Line 24:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 24:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;	self.toggled = false&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;	self.toggled = false&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;	-- set the visual state &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;as on (&quot;toggled&quot;)&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;	-- set the visual state&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;	self:updateVisualState(self.toggled)&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;	self:updateVisualState(self.toggled)&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l129&quot;&gt;Line 129:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 129:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;=== ButtonToggle &amp;#039;&amp;#039;&amp;#039;Demo&amp;#039;&amp;#039;&amp;#039; ===&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;=== ButtonToggle &amp;#039;&amp;#039;&amp;#039;Demo&amp;#039;&amp;#039;&amp;#039; ===&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;{{#widget:GApp|app=ButtonToggleDemo1.GApp|width=480|height=320}}&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;-- ButtonToggle Demo&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;-- ButtonToggle Demo&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l134&quot;&gt;Line 134:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 135:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;application:setBackgroundColor(0x6c6c6c)&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;application:setBackgroundColor(0x6c6c6c)&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;-- textures&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;-- textures&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;local texup = Texture.new(&quot;gfx/ui/&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;btn_off&lt;/del&gt;.png&quot;)&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;local texup = Texture.new(&quot;gfx/ui/&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;btn_01_off&lt;/ins&gt;.png&quot;)&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;local texdown = Texture.new(&quot;gfx/ui/&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;btn_on&lt;/del&gt;.png&quot;)&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;local texdown = Texture.new(&quot;gfx/ui/&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;btn_01_on&lt;/ins&gt;.png&quot;)&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;-- buttons&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;-- buttons&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;local btntoggle = ButtonToggle.new(Bitmap.new(texup), Bitmap.new(texdown))&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;local btntoggle = ButtonToggle.new(Bitmap.new(texup), Bitmap.new(texdown))&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>MoKaLux</name></author>
	</entry>
	<entry>
		<id>https://wiki.gideros.rocks/index.php?title=ButtonToggle_class&amp;diff=23136&amp;oldid=prev</id>
		<title>MoKaLux at 01:24, 30 November 2023</title>
		<link rel="alternate" type="text/html" href="https://wiki.gideros.rocks/index.php?title=ButtonToggle_class&amp;diff=23136&amp;oldid=prev"/>
		<updated>2023-11-30T01:24:08Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;a href=&quot;https://wiki.gideros.rocks/index.php?title=ButtonToggle_class&amp;amp;diff=23136&amp;amp;oldid=23102&quot;&gt;Show changes&lt;/a&gt;</summary>
		<author><name>MoKaLux</name></author>
	</entry>
	<entry>
		<id>https://wiki.gideros.rocks/index.php?title=ButtonToggle_class&amp;diff=23102&amp;oldid=prev</id>
		<title>MoKaLux: Created page with &quot;__TOC__  &#039;&#039;&#039;A Button you can toggle on and off&#039;&#039;&#039;  === ButtonToggle &#039;&#039;&#039;Class&#039;&#039;&#039; === &lt;syntaxhighlight lang=&quot;lua&quot;&gt; -- -- ButtonToggle v1.0 -- Free to modify and use! -- Matja...&quot;</title>
		<link rel="alternate" type="text/html" href="https://wiki.gideros.rocks/index.php?title=ButtonToggle_class&amp;diff=23102&amp;oldid=prev"/>
		<updated>2023-11-20T03:02:03Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;__TOC__  &amp;#039;&amp;#039;&amp;#039;A Button you can toggle on and off&amp;#039;&amp;#039;&amp;#039;  === ButtonToggle &amp;#039;&amp;#039;&amp;#039;Class&amp;#039;&amp;#039;&amp;#039; === &amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt; -- -- ButtonToggle v1.0 -- Free to modify and use! -- Matja...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;__TOC__&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;A Button you can toggle on and off&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
=== ButtonToggle &amp;#039;&amp;#039;&amp;#039;Class&amp;#039;&amp;#039;&amp;#039; ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
--[[&lt;br /&gt;
-- ButtonToggle v1.0&lt;br /&gt;
-- Free to modify and use!&lt;br /&gt;
-- Matjaž Bravc&lt;br /&gt;
v1.0 - 19.3.2013 Initial release&lt;br /&gt;
]]&lt;br /&gt;
&lt;br /&gt;
ButtonToggle = Core.class(Sprite)&lt;br /&gt;
&lt;br /&gt;
function ButtonToggle:init(upState, downState)&lt;br /&gt;
	self.upState = upState&lt;br /&gt;
	self.downState = downState&lt;br /&gt;
&lt;br /&gt;
	self.pressed = false&lt;br /&gt;
	self.focus = false&lt;br /&gt;
&lt;br /&gt;
	self:updateVisualState(self.pressed)&lt;br /&gt;
&lt;br /&gt;
	self:addEventListener(Event.MOUSE_DOWN, self.onMouseDown, self)&lt;br /&gt;
	self:addEventListener(Event.MOUSE_MOVE, self.onMouseMove, self)&lt;br /&gt;
	self:addEventListener(Event.MOUSE_UP, self.onMouseUp, self)&lt;br /&gt;
&lt;br /&gt;
	self:addEventListener(Event.TOUCHES_BEGIN, self.onTouchesBegin, self)&lt;br /&gt;
	self:addEventListener(Event.TOUCHES_MOVE, self.onTouchesMove, self)&lt;br /&gt;
	self:addEventListener(Event.TOUCHES_END, self.onTouchesEnd, self)&lt;br /&gt;
	self:addEventListener(Event.TOUCHES_CANCEL, self.onTouchesCancel, self)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function ButtonToggle:onMouseDown(event)&lt;br /&gt;
	if self:hitTestPoint(event.x, event.y) then&lt;br /&gt;
		self.focus = true&lt;br /&gt;
		event:stopPropagation()&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function ButtonToggle:onMouseMove(event)&lt;br /&gt;
	if self.focus then&lt;br /&gt;
		if not self:hitTestPoint(event.x, event.y) then&lt;br /&gt;
			self.focus = false&lt;br /&gt;
		end&lt;br /&gt;
		event:stopPropagation()&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function ButtonToggle:onMouseUp(event)&lt;br /&gt;
	if self.focus then&lt;br /&gt;
		self.focus = false&lt;br /&gt;
		self:updateVisualState(not self.pressed)&lt;br /&gt;
		self:dispatchEvent(Event.new(&amp;quot;clicked&amp;quot;))&lt;br /&gt;
		event:stopPropagation()&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- if button is on focus, stop propagation of touch events&lt;br /&gt;
function ButtonToggle:onTouchesBegin(event)&lt;br /&gt;
	if self.focus then&lt;br /&gt;
		event:stopPropagation()&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- if button is on focus, stop propagation of touch events&lt;br /&gt;
function ButtonToggle:onTouchesMove(event)&lt;br /&gt;
	if self.focus then&lt;br /&gt;
		event:stopPropagation()&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- if button is on focus, stop propagation of touch events&lt;br /&gt;
function ButtonToggle:onTouchesEnd(event)&lt;br /&gt;
	if self.focus then&lt;br /&gt;
		event:stopPropagation()&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- if touches are cancelled, reset the state of the button&lt;br /&gt;
function ButtonToggle:onTouchesCancel(event)&lt;br /&gt;
	if self.focus then&lt;br /&gt;
		self.focus = false&lt;br /&gt;
		self:updateVisualState(false)&lt;br /&gt;
		event:stopPropagation()&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- if state is true show downState else show upState&lt;br /&gt;
function ButtonToggle:updateVisualState(state)&lt;br /&gt;
	self.pressed = state&lt;br /&gt;
&lt;br /&gt;
	-- Modification to allow single state buttons (checkboxes etc)&lt;br /&gt;
	if not self.downState then&lt;br /&gt;
		if not self:contains(self.upState) then&lt;br /&gt;
			self:addChild(self.upState)&lt;br /&gt;
		end&lt;br /&gt;
		return&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	if self.pressed then&lt;br /&gt;
		if self:contains(self.upState) then&lt;br /&gt;
			self:removeChild(self.upState)&lt;br /&gt;
		end&lt;br /&gt;
		if not self:contains(self.downState) then&lt;br /&gt;
			self:addChild(self.downState)&lt;br /&gt;
		end&lt;br /&gt;
	else&lt;br /&gt;
		if self:contains(self.downState) then&lt;br /&gt;
			self:removeChild(self.downState)&lt;br /&gt;
		end&lt;br /&gt;
		if not self:contains(self.upState) then&lt;br /&gt;
			self:addChild(self.upState)&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function ButtonToggle:setPressed(xbool)&lt;br /&gt;
	self:updateVisualState(xbool)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function ButtonToggle:isPressed()&lt;br /&gt;
	return self.pressed&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ButtonToggle &amp;#039;&amp;#039;&amp;#039;Demo&amp;#039;&amp;#039;&amp;#039; ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
-- button Toggle&lt;br /&gt;
-- textures&lt;br /&gt;
local texoff = Texture.new(&amp;quot;gfx/ui/btn_01_disabled.png&amp;quot;)&lt;br /&gt;
local texon = Texture.new(&amp;quot;gfx/ui/btn_01_up.png&amp;quot;)&lt;br /&gt;
-- buttons&lt;br /&gt;
local btntoggle = ButtonToggle.new(Bitmap.new(texoff), Bitmap.new(texon))&lt;br /&gt;
local btntoggle2 = ButtonToggle.new(Bitmap.new(texoff), Bitmap.new(texon))&lt;br /&gt;
-- params&lt;br /&gt;
btntoggle:setScale(0.5, 0.5)&lt;br /&gt;
btntoggle:setPressed(true)&lt;br /&gt;
btntoggle2:setScale(0.5, 0.5)&lt;br /&gt;
btntoggle2:setPressed(false)&lt;br /&gt;
-- position&lt;br /&gt;
btntoggle:setPosition(16*1, 16*16)&lt;br /&gt;
btntoggle2:setPosition(16*6, 16*16)&lt;br /&gt;
-- order&lt;br /&gt;
stage:addChild(btntoggle)&lt;br /&gt;
stage:addChild(btntoggle2)&lt;br /&gt;
-- listeners&lt;br /&gt;
btntoggle:addEventListener(&amp;quot;clicked&amp;quot;, function()&lt;br /&gt;
	print(&amp;quot;button is: &amp;quot;, btntoggle:isPressed())&lt;br /&gt;
end)&lt;br /&gt;
btntoggle2:addEventListener(&amp;quot;clicked&amp;quot;, function()&lt;br /&gt;
	print(&amp;quot;button2 is: &amp;quot;, btntoggle2:isPressed())&lt;br /&gt;
end)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;[[UI Buttons]]&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
{{GIDEROS IMPORTANT LINKS}}&lt;/div&gt;</summary>
		<author><name>MoKaLux</name></author>
	</entry>
</feed>