<?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=ButtonDisabled_class</id>
	<title>ButtonDisabled 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=ButtonDisabled_class"/>
	<link rel="alternate" type="text/html" href="https://wiki.gideros.rocks/index.php?title=ButtonDisabled_class&amp;action=history"/>
	<updated>2026-11-17T15:01:41Z</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=ButtonDisabled_class&amp;diff=23143&amp;oldid=prev</id>
		<title>MoKaLux at 03:13, 30 November 2023</title>
		<link rel="alternate" type="text/html" href="https://wiki.gideros.rocks/index.php?title=ButtonDisabled_class&amp;diff=23143&amp;oldid=prev"/>
		<updated>2023-11-30T03:13:29Z</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 03:13, 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-l136&quot;&gt;Line 136:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 136:&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;=== ButtonDisabled &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;=== ButtonDisabled &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=ButtonDisabledDemo1.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;-- ButtonDisabled 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;-- ButtonDisabled DEMO&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=ButtonDisabled_class&amp;diff=23141&amp;oldid=prev</id>
		<title>MoKaLux: Created page with &quot;__TOC__  This button takes three bitmaps as argument. 1 bitmap for each state: &#039;&#039;Up&#039;&#039;, &#039;&#039;Down&#039;&#039;, &#039;&#039;Disabled&#039;&#039;.  === ButtonDisabled &#039;&#039;&#039;Class&#039;&#039;&#039; === &lt;syntaxhighlight lang=&quot;lua&quot;&gt;...&quot;</title>
		<link rel="alternate" type="text/html" href="https://wiki.gideros.rocks/index.php?title=ButtonDisabled_class&amp;diff=23141&amp;oldid=prev"/>
		<updated>2023-11-30T02:27:53Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;__TOC__  This button takes three bitmaps as argument. 1 bitmap for each state: &amp;#039;&amp;#039;Up&amp;#039;&amp;#039;, &amp;#039;&amp;#039;Down&amp;#039;&amp;#039;, &amp;#039;&amp;#039;Disabled&amp;#039;&amp;#039;.  === ButtonDisabled &amp;#039;&amp;#039;&amp;#039;Class&amp;#039;&amp;#039;&amp;#039; === &amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;...&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;
This button takes three bitmaps as argument. 1 bitmap for each state: &amp;#039;&amp;#039;Up&amp;#039;&amp;#039;, &amp;#039;&amp;#039;Down&amp;#039;&amp;#039;, &amp;#039;&amp;#039;Disabled&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
=== ButtonDisabled &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;
-- ButtonDisabled&lt;br /&gt;
-- A Button class with: an Image, Up state, Down state, Disabled state (IUDD)&lt;br /&gt;
v 0.1.1: 2023-11-30 changed addChild to setVisible&lt;br /&gt;
v 0.1.0: 2011 init (based on the initial generic Gideros Button class)&lt;br /&gt;
]]&lt;br /&gt;
&lt;br /&gt;
ButtonDisabled = Core.class(Sprite)&lt;br /&gt;
&lt;br /&gt;
function ButtonDisabled:init(upState, downState, disabledState)&lt;br /&gt;
	self.upState = upState&lt;br /&gt;
	self.downState = downState&lt;br /&gt;
	self.disabledState = disabledState&lt;br /&gt;
	self:addChild(self.upState)&lt;br /&gt;
	if self.downState then self:addChild(self.downState) end&lt;br /&gt;
	if self.disabledState then self:addChild(self.disabledState) end&lt;br /&gt;
&lt;br /&gt;
	self.focus = false&lt;br /&gt;
	self.disabled = false&lt;br /&gt;
&lt;br /&gt;
	-- set the visual state as &amp;quot;up&amp;quot;&lt;br /&gt;
	self:updateVisualState(false)&lt;br /&gt;
&lt;br /&gt;
	-- register to all mouse and touch events&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 ButtonDisabled:onMouseDown(ev)&lt;br /&gt;
	if self:hitTestPoint(ev.x, ev.y) then&lt;br /&gt;
		self.focus = true&lt;br /&gt;
		self:updateVisualState(true)&lt;br /&gt;
		ev:stopPropagation()&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function ButtonDisabled:onMouseMove(ev)&lt;br /&gt;
	if self.focus then&lt;br /&gt;
		if not self:hitTestPoint(ev.x, ev.y) then&lt;br /&gt;
			self.focus = false&lt;br /&gt;
			self:updateVisualState(false)&lt;br /&gt;
		end&lt;br /&gt;
		ev:stopPropagation()&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function ButtonDisabled:onMouseUp(ev)&lt;br /&gt;
	if self.focus then&lt;br /&gt;
		self.focus = false&lt;br /&gt;
		self:updateVisualState(false)&lt;br /&gt;
		if not self.disabled then&lt;br /&gt;
			self:dispatchEvent(Event.new(&amp;quot;clicked&amp;quot;)) -- button is clicked, dispatch &amp;quot;clicked&amp;quot; event&lt;br /&gt;
		end&lt;br /&gt;
		ev: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 ButtonDisabled:onTouchesBegin(ev)&lt;br /&gt;
	if self.focus then&lt;br /&gt;
		ev: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 ButtonDisabled:onTouchesMove(ev)&lt;br /&gt;
	if self.focus then&lt;br /&gt;
		ev: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 ButtonDisabled:onTouchesEnd(ev)&lt;br /&gt;
	if self.focus then&lt;br /&gt;
		ev: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 ButtonDisabled:onTouchesCancel(ev)&lt;br /&gt;
	if self.focus then&lt;br /&gt;
		self.focus = false&lt;br /&gt;
		self:updateVisualState(false)&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 ButtonDisabled:updateVisualState(state)&lt;br /&gt;
	self.upState:setVisible(false)&lt;br /&gt;
	if self.downState then self.downState:setVisible(false) end&lt;br /&gt;
	if self.disabledState then self.disabledState:setVisible(false) end&lt;br /&gt;
&lt;br /&gt;
	if self.disabled then -- button is Disabled&lt;br /&gt;
		if self.disabledState then&lt;br /&gt;
			self.disabledState:setVisible(true)&lt;br /&gt;
		else&lt;br /&gt;
			self.upState:setVisible(true)&lt;br /&gt;
		end&lt;br /&gt;
	else&lt;br /&gt;
		if state then -- button is Down&lt;br /&gt;
			if self.downState then&lt;br /&gt;
				self.downState:setVisible(true)&lt;br /&gt;
			else&lt;br /&gt;
				self.upState:setVisible(true)&lt;br /&gt;
			end&lt;br /&gt;
		else -- button is Up&lt;br /&gt;
			self.upState:setVisible(true)&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function ButtonDisabled:setDisabled(disabled)&lt;br /&gt;
	if self.disabled == disabled then return end&lt;br /&gt;
&lt;br /&gt;
	self.disabled = disabled&lt;br /&gt;
	self.focus = false&lt;br /&gt;
	self:updateVisualState(false)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function ButtonDisabled:getDisabled()&lt;br /&gt;
	return self.disabled&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ButtonDisabled &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;
-- ButtonDisabled DEMO&lt;br /&gt;
-- bg&lt;br /&gt;
application:setBackgroundColor(0x6c6c6c)&lt;br /&gt;
-- textures&lt;br /&gt;
local texbtnup = Texture.new(&amp;quot;gfx/ui/btn_01_up.png&amp;quot;)&lt;br /&gt;
local texbtndown = Texture.new(&amp;quot;gfx/ui/btn_01_down.png&amp;quot;)&lt;br /&gt;
local texbtndisable = Texture.new(&amp;quot;gfx/ui/btn_01_disabled.png&amp;quot;)&lt;br /&gt;
-- buttons&lt;br /&gt;
local btniudd = ButtonDisabled.new(Bitmap.new(texbtnup), Bitmap.new(texbtndown), Bitmap.new(texbtndisable))&lt;br /&gt;
local btniudd2 = ButtonDisabled.new(Bitmap.new(texbtnup), Bitmap.new(texbtndown), Bitmap.new(texbtndisable))&lt;br /&gt;
local btniudd3 = ButtonDisabled.new(Bitmap.new(texbtnup), Bitmap.new(texbtndown), Bitmap.new(texbtndisable))&lt;br /&gt;
-- params&lt;br /&gt;
btniudd:setScale(0.5)&lt;br /&gt;
btniudd2:setScale(0.5)&lt;br /&gt;
btniudd3:setScale(0.5)&lt;br /&gt;
-- position&lt;br /&gt;
btniudd:setPosition(16*4, 16*1)&lt;br /&gt;
btniudd2:setPosition(16*9, 16*1)&lt;br /&gt;
btniudd3:setPosition(16*14, 16*1)&lt;br /&gt;
-- order&lt;br /&gt;
stage:addChild(btniudd)&lt;br /&gt;
stage:addChild(btniudd2)&lt;br /&gt;
stage:addChild(btniudd3)&lt;br /&gt;
-- listeners&lt;br /&gt;
btniudd:addEventListener(&amp;quot;clicked&amp;quot;, function()&lt;br /&gt;
	print(&amp;quot;button is disabled&amp;quot;, btniudd:getDisabled())&lt;br /&gt;
	btniudd2:setDisabled(not btniudd2:getDisabled())&lt;br /&gt;
end)&lt;br /&gt;
btniudd2:addEventListener(&amp;quot;clicked&amp;quot;, function()&lt;br /&gt;
	print(&amp;quot;button2 is disabled&amp;quot;, btniudd2:getDisabled())&lt;br /&gt;
	btniudd3:setDisabled(not btniudd3:getDisabled())&lt;br /&gt;
end)&lt;br /&gt;
btniudd3:addEventListener(&amp;quot;clicked&amp;quot;, function()&lt;br /&gt;
	print(&amp;quot;button3 is disabled&amp;quot;, btniudd3:getDisabled())&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>