<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>Next stop, how do i determine if my app loses focus?</title>
		<link>http://www.allegro.cc/forums/view/583627</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Sun, 07 May 2006 18:53:23 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>OK, next step on my way to being the ultimate newb programmer.. </p><p>If I have my app in windowed mode, how do I go about detecting if the application has lost focus, so that I can pause the game?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (cdxrd)</author>
		<pubDate>Sun, 07 May 2006 07:55:09 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>You don&#39;t need to do that manually. You can call <i>set_display_switch_mode(SWITCH_PAUSE);</i> and if it fails (returns != 0) use <i>set_display_switch_mode(SWITCH_AMNESIA);</i>. This pauses the game automatically when the window loses focus.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (ReyBrujo)</author>
		<pubDate>Sun, 07 May 2006 07:59:16 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Yes but it also pauses sound and music and stuff which tends to be annoying/weird/bad.</p><p>There&#39;s a method you can use to trigger callbacks when the app gains/loses focus.  I don&#39;t remember what it is, but looking in the manual is a good start. <img src="http://www.allegro.cc/forums/smileys/wink.gif" alt=";)" /></p><p>Marcello
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Marcello)</author>
		<pubDate>Sun, 07 May 2006 10:13:26 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Ill check the manual, but manuals confuse the daylights out of me. Give me some code or an example to look at, disect and play around with, and I&#39;ll learn it a million times better than looking in a manual. Hence, I ask here. Thanks for the replies so far. </p><p>If it loses focus, I&#39;m not sure if I would want to keep the music playing or not, so that will have to be a consideration. I can build my own pause routine if I can figure out when the app loses focus.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (cdxrd)</author>
		<pubDate>Sun, 07 May 2006 10:44:22 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>AFAIK Allegro programs pause by default when they lose focus so you only have to write extra code if you don&#39;t want that. You can do what ReyBrujo said to be extra certain though...</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
Ill check the manual, but manuals confuse the daylights out of me.
</p></div></div><p>
I suggest you get used to reading manuals very quickly otherwise there won&#39;t be long before people start being not very nice to you and reply with RTFM.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (miran)</author>
		<pubDate>Sun, 07 May 2006 11:16:45 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Ah well, I know it.. I do look at em, its just 100 times easier to look at a sample, than to dig through sometimes thousands of pages of docs. Time to dig out the books I suppose. </p><p>I&#39;ve always wondered why people do that too. They will write out a 1000 word post that sums up to RTFM, when had they just answered it, it would have been simpler and quicker.. heh.. who knows.. =)</p><p>I&#39;ll figure out how to trap it. It auto-pauses when it loses focus, but I want to be able to display a blank screen when it loses it, plus I dont want it to auto-resume upon regaining focus. I&#39;d rather have it wait for user input before it continued on. I&#39;ll do some more digging around on google.. There has to be a message sent that I can catch and process somehow..
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (cdxrd)</author>
		<pubDate>Sun, 07 May 2006 11:33:59 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Part of learning how to code is learning where to look for information. All you need to know is in the <b>Allegro manual</b> (assumnig you&#39;re using Allegro). Click on these functions and read the text:
</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">int</span> <a href="http://www.allegro.cc/manual/set_display_switch_mode" target="_blank"><span class="a">set_display_switch_mode</span></a><span class="k2">(</span><span class="k1">int</span> mode<span class="k2">)</span><span class="k2">;</span>
<span class="k1">int</span> <a href="http://www.allegro.cc/manual/get_display_switch_mode" target="_blank"><span class="a">get_display_switch_mode</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="k1">int</span> <a href="http://www.allegro.cc/manual/set_display_switch_callback" target="_blank"><span class="a">set_display_switch_callback</span></a><span class="k2">(</span><span class="k1">int</span> dir, <span class="k1">void</span> <span class="k2">(</span><span class="k3">*</span>cb<span class="k2">)</span><span class="k2">(</span><span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
<span class="k1">void</span> <a href="http://www.allegro.cc/manual/remove_display_switch_callback" target="_blank"><span class="a">remove_display_switch_callback</span></a><span class="k2">(</span><span class="k1">void</span> <span class="k2">(</span><span class="k3">*</span>cb<span class="k2">)</span><span class="k2">(</span><span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>
Some parts might be difficult to understand. If you have problems understanding the concepts, then ask here. But basically what you want to do is this:
</p><ul><li><p> set display switch mode to SWITCH_NONE (this isn&#39;t necessary, but it will make your music play in the background or whatever)</p></li><li><p> install a callback for the SWITCH_OUT event</p></li><li><p> in that function set a flag, something like GAME_PAUSED_AND_WAITING_FOR_USER_TO_PRESS_CONTINUE=true</p></li><li><p> in the main loop check if GAME_PAUSED_AND_WAITING_FOR_USER_TO_PRESS_CONTINUE==true, and if it is, don&#39;t do the game logic and all that, but instead display a &quot;Press this button to continue&quot; button or something like that. When the button is clicked (or a certain key is pressed or something), you set GAME_PAUSED_AND_WAITING_FOR_USER_TO_PRESS_CONTINUE=false and the game continues.</p></li></ul><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (miran)</author>
		<pubDate>Sun, 07 May 2006 12:11:12 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Also take note of the `Examples using this:&#39; in the docs that point you to the proper example programme.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Evert)</author>
		<pubDate>Sun, 07 May 2006 13:26:50 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
set display switch mode to SWITCH_NONE (this isn&#39;t necessary, but it will make your music play in the background or whatever)
</p></div></div><p>
No! That&#39;s the Abomination Mode, the Eater of UIs, The One Who Must Never Be Called. It&#39;s SWITCH_BACKGROUND or SWITCH_BACKAMNESIA that you want.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (gnolam)</author>
		<pubDate>Sun, 07 May 2006 17:27:58 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Oh yeah, that was a typo <img src="http://www.allegro.cc/forums/smileys/wink.gif" alt=";)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (miran)</author>
		<pubDate>Sun, 07 May 2006 18:53:23 +0000</pubDate>
	</item>
</rss>
