<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Scott Logic</title>
	<atom:link href="http://www.scottlogic.co.uk/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.scottlogic.co.uk</link>
	<description>Financial Software Development</description>
	<lastBuildDate>Sat, 04 Feb 2012 06:01:56 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Software Tester</title>
		<link>http://www.scottlogic.co.uk/2012/02/software-tester/</link>
		<comments>http://www.scottlogic.co.uk/2012/02/software-tester/#comments</comments>
		<pubDate>Wed, 01 Feb 2012 14:24:58 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Vacancies]]></category>

		<guid isPermaLink="false">http://www.scottlogic.co.uk/?p=143102</guid>
		<description><![CDATA[Very competitive salary + bonus + benefits; Newcastle Upon Tyne]]></description>
			<content:encoded><![CDATA[<p><strong>Very competitive salary + bonus + benefits; Newcastle Upon Tyne</strong></p>
<p>Scott Logic is a growing software consultancy which provides the very best in bespoke financial software for leading financial institutions.</p>
<p>We have recently won a number of exciting projects and have new tester roles available. You must have commercial experience of testing software in an enterprise application or web environment. It is highly desirable that you will hold a relevant degree from a reputable university and be ISEB certified. The ideal candidate will have the following skill set:</p>
<ul>
<li>Essential: Solid understanding of testing life cycle in an agile enterprise application development context (large scale systems, real time, multi user etc.)</li>
<li>Essential: Ability to define test cases from business requirements which meet test coverage criteria</li>
<li>Essential: Ability to produce test artefacts &#038; documentation</li>
<li>Highly Desirable: Enterprise web application / portal testing including browser compatibility</li>
<li>Highly Desirable: Automated front end testing experience</li>
<li>Desirable: Mobile platform testing experience (Android, iOS, Windows 7)</li>
</ul>
<p>All roles are very hands on and at least 90% of your time will be spent testing software &#8211; either on client projects or internal R&#038;D initiatives. You will report to the project lead or test lead as appropriate. This role is based in Newcastle upon Tyne. All our offices are in city centre locations enabling an easy, car-free commute.</p>
<p>We offer a highly competitive salary and benefits package, including:</p>
<ul>
<li>Performance and profit related bonus scheme</li>
<li>25 days holiday per year, growing with length of service up to 30 days</li>
<li>Life assurance</li>
<li>Referral programme – payable to anyone who refers a successful candidate</li>
</ul>
<p>To apply, email your latest CV and a brief cover note to <a href="mailto: applications@scottlogic.co.uk">applications@scottlogic.co.uk</a> quoting reference number SLT12D.</p>
<p>Preference will be given to direct applicants.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.scottlogic.co.uk/2012/02/software-tester/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Communications Manager</title>
		<link>http://www.scottlogic.co.uk/2012/02/communications-manager/</link>
		<comments>http://www.scottlogic.co.uk/2012/02/communications-manager/#comments</comments>
		<pubDate>Wed, 01 Feb 2012 14:14:36 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Vacancies]]></category>

		<guid isPermaLink="false">http://www.scottlogic.co.uk/?p=143092</guid>
		<description><![CDATA[Up to £40k + bonus + benefits; Newcastle Upon Tyne]]></description>
			<content:encoded><![CDATA[<p><strong>Up to £40k + bonus + benefits; Newcastle Upon Tyne</strong></p>
<p>Scott Logic is a leading UK-based software consultancy with international clients in the financial services sector. The company has also launched a number of technology products in new sectors, which require further development and which represent an exciting growth opportunity for the company.</p>
<p>To date, all external communications have been managed through a combination of inhouse efforts and external consultants. The company now seeks a full-time Communications Manager to look after all aspects of marketing and public relations – for Scott Logic and its product families. </p>
<p>This is an outstanding opportunity to help take a brand that already commands a strong market position and international reputation, and grow it into a truly world-leading brand. It should be assumed that support will be available for the development of long-term brand and marketing strategies; but this role will hold full responsibility for successful delivery of all or most marketing tactics.</p>
<p>We would ideally like candidates to have at least five years marketing / PR experience in the technology sector, but all levels will be considered. Exceptional communication and writing skills are essential, to cover both the online marketing and face-to-face aspects of the role. Key responsibilities are as follows &#8211; please note that it may be possible to outsource a small number of these &#8211; but candidates should display skills and experience of as many as possible:</p>
<ul>
<li>Digital marketing delivery: some or all aspects of SEO, PPC, CRO (inc. A/B testing) blogging and social media management.</li>
<li>Content development and management for websites and marketing materials, (eg white papers) including the evolution of key messages and USPs.</li>
<li>Developing and managing relationships with relevant media and blogs (tech and trade), and writing press releases and / or blog articles.</li>
<li>Development and management of wider relationships for the promotion of Scott Logic and products – such as user groups, tech platforms.</li>
<li>Managing prospect and early-stage client relationships for both the consultancy business and those trialling products – including telephone as well as face-to-face meetings, some of which may be overseas.</li>
<li>Improving communications (inc feedback and cross-selling) with existing clients (e.g. newsletters / feedback systems). This again may involve some overseas meetings with clients and prospects in Europe and US.</li>
<li>Managing and attending international exhibitions to represent Scott Logic and product brands – approx 6 – 8 exhibitions per year.</li>
<li>Managing supplier relationships as needed – e.g. designers, web developers.</li>
<p>The role will be based at Scott Logic HQ in Newcastle upon Tyne, and will share a proportion of overall targets for engagement and conversion of new clients, to be discussed with shortlisted candidates. The role will report directly to the Head of Consulting, with regular updates to the MD and senior management team</p>
<p>Interested candidates should apply with CV and covering letter stating current salary and salary expectations, by 29th February 2012 to <a href="mailto: applications@scottlogic.co.uk ">applications@scottlogic.co.uk</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.scottlogic.co.uk/2012/02/communications-manager/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WP7 PhoneGap Backbutton Support Re-visited</title>
		<link>http://www.scottlogic.co.uk/blog/colin/2012/01/wp7-phonegap-backbutton-support-re-visited/</link>
		<comments>http://www.scottlogic.co.uk/blog/colin/2012/01/wp7-phonegap-backbutton-support-re-visited/#comments</comments>
		<pubDate>Thu, 19 Jan 2012 11:03:11 +0000</pubDate>
		<dc:creator>Colin Eberhardt</dc:creator>
				<category><![CDATA[Blog]]></category>

		<guid isPermaLink="false">http://www.scottlogic.co.uk/blog/colin/?p=1950</guid>
		<description><![CDATA[About a month ago I published an article which demonstrated how to create a WP7 application using static HTML pages and PhoneGap. Whilst PhoneGap makes the packaging of HTML / JavaScript / CSS and images into a breeze, one thing it doesn&#8217;t do is provide correct back-button support. Correct back-button support is a mandatory requirement [...]]]></description>
			<content:encoded><![CDATA[
<p>About a month ago I published an article which demonstrated how to <a href="http://www.scottlogic.co.uk/blog/colin/2011/12/a-simple-multi-page-windows-phone-7-phonegap-example/" title="A Simple Multi-Page Windows Phone 7 PhoneGap Example">create a WP7 application using static HTML pages and PhoneGap</a>. Whilst PhoneGap makes the packaging of HTML / JavaScript / CSS and images into a breeze, one thing it doesn&#8217;t do is provide correct back-button support. Correct back-button support is a mandatory requirement for marketplace certification. Hitting the back button should navigate back through the various screens of an application. Hitting the back-button on the first screen should terminate the application. </p>
<p>The solution I published previously handles the WP7 back keypress in order to keep track of the back-stack depth. When the back-stack depth is just one, a back-button press exits the application. This works fine if backwards navigation is always controlled via the hardware back-button, however if your application has HTML anchor elements that navigate back to a previous page, or you use code such as <code>javascript:history.go(-1)</code>, this back-stack handling code will not detect that a backwards navigation has occurred.</p>
<p><em>As an aside, WP7 applications really should use the hardware back-button for navigation. If you are writing a cross-platform PhoneGap application consider adapting your UI for each platform. This means removing the back-button you woudl have in your iOS version when &#8216;skinning&#8217; for WP7.</em></p>
<p>In order to solve this issue I have updated the code to inspect the URL that the browser control is navigating to in order to detect backwards navigation. The class now maintains a list of URLs, which represent the navigation stack. This allows it to detect a backwards navigation.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
<span style="color: #008080; font-style: italic;">/// Handles the back-button for a PhoneGap application. When the back-button</span>
<span style="color: #008080; font-style: italic;">/// is pressed, the browser history is navigated. If no history is present,</span>
<span style="color: #008080; font-style: italic;">/// the application will exit.</span>
<span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">class</span> BackButtonHandler
<span style="color: #008000;">&#123;</span>
  <span style="color: #0600FF; font-weight: bold;">private</span> WebBrowser _browser<span style="color: #008000;">;</span>
&nbsp;
  <span style="color: #0600FF; font-weight: bold;">private</span> List<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&gt;</span> _backStack <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> List<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
  <span style="color: #0600FF; font-weight: bold;">public</span> BackButtonHandler<span style="color: #008000;">&#40;</span>PhoneApplicationPage page, PGView phoneGapView<span style="color: #008000;">&#41;</span>
  <span style="color: #008000;">&#123;</span>
    <span style="color: #008080; font-style: italic;">// subscribe to the hardware back-button</span>
    page<span style="color: #008000;">.</span><span style="color: #0000FF;">BackKeyPress</span> <span style="color: #008000;">+=</span> Page_BackKeyPress<span style="color: #008000;">;</span>
&nbsp;
    _browser <span style="color: #008000;">=</span> phoneGapView<span style="color: #008000;">.</span><span style="color: #0000FF;">Browser</span><span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #008080; font-style: italic;">// handle navigation events</span>
    _browser<span style="color: #008000;">.</span><span style="color: #0000FF;">Navigated</span> <span style="color: #008000;">+=</span> Browser_Navigated<span style="color: #008000;">;</span>
&nbsp;
  <span style="color: #008000;">&#125;</span>
&nbsp;
  <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
  <span style="color: #008080; font-style: italic;">/// Handle navigation in order to update our back-stack</span>
  <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
  <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">void</span> Browser_Navigated<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">object</span> sender, NavigationEventArgs e<span style="color: #008000;">&#41;</span>
  <span style="color: #008000;">&#123;</span>
    <span style="color: #6666cc; font-weight: bold;">string</span> url <span style="color: #008000;">=</span> _browser<span style="color: #008000;">.</span><span style="color: #0000FF;">Source</span><span style="color: #008000;">.</span><span style="color: #0000FF;">OriginalString</span><span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #008080; font-style: italic;">// ensure all slashes are the same</span>
    <span style="color: #008080; font-style: italic;">// app\www/index.html</span>
    <span style="color: #008080; font-style: italic;">// see: https://issues.apache.org/jira/browse/CB-184</span>
    url <span style="color: #008000;">=</span> url<span style="color: #008000;">.</span><span style="color: #0000FF;">Replace</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;<span style="color: #008080; font-weight: bold;">\\</span>&quot;</span>, <span style="color: #666666;">&quot;/&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>_backStack<span style="color: #008000;">.</span><span style="color: #0000FF;">Count</span> <span style="color: #008000;">&lt;</span> <span style="color: #FF0000;">2</span><span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
      _backStack<span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span>url<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span>
    <span style="color: #0600FF; font-weight: bold;">else</span>
    <span style="color: #008000;">&#123;</span>
      <span style="color: #008080; font-style: italic;">// check whether the URL represents a backwards navigation</span>
      <span style="color: #6666cc; font-weight: bold;">string</span> previousPage <span style="color: #008000;">=</span> _backStack<span style="color: #008000;">&#91;</span>_backStack<span style="color: #008000;">.</span><span style="color: #0000FF;">Count</span> <span style="color: #008000;">-</span> <span style="color: #FF0000;">2</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span>
      <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>previousPage <span style="color: #008000;">==</span> url<span style="color: #008000;">&#41;</span>
      <span style="color: #008000;">&#123;</span>
        _backStack<span style="color: #008000;">.</span><span style="color: #0000FF;">RemoveAt</span><span style="color: #008000;">&#40;</span>_backStack<span style="color: #008000;">.</span><span style="color: #0000FF;">Count</span> <span style="color: #008000;">-</span> <span style="color: #FF0000;">1</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
      <span style="color: #008000;">&#125;</span>
    <span style="color: #008000;">&#125;</span>
  <span style="color: #008000;">&#125;</span>
&nbsp;
  <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
  <span style="color: #008080; font-style: italic;">/// Handle the hardware back-button</span>
  <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
  <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">void</span> Page_BackKeyPress<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">object</span> sender, CancelEventArgs e<span style="color: #008000;">&#41;</span>
  <span style="color: #008000;">&#123;</span>
    <span style="color: #008080; font-style: italic;">// if we have items in the back-stack, route this event</span>
    <span style="color: #008080; font-style: italic;">// to the browser</span>
    <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>_backStack<span style="color: #008000;">.</span><span style="color: #0000FF;">Count</span> <span style="color: #008000;">&gt;</span> <span style="color: #FF0000;">1</span><span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
      _browser<span style="color: #008000;">.</span><span style="color: #0000FF;">InvokeScript</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;eval&quot;</span>, <span style="color: #666666;">&quot;history.go(-1)&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
      e<span style="color: #008000;">.</span><span style="color: #0000FF;">Cancel</span> <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span>
  <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>Note: There use of <code>url.Replace("\\", "/")</code>, this is due to a minor issue with the PhoneGap WP7 native code, which I have raised in the Callback JIRA (<a href="https://issues.apache.org/jira/browse/CB-184">CB-184</a>).</p>
<p>To use this code simply create an instance of the class, passing the PGView (the PhoneGap user control) into teh constructor:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> MainPage<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
  InitializeComponent<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
  <span style="color: #008000;">new</span> BackButtonHandler<span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span>, PGView<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>Because back-button handling is a mandatory requirement for WP7 applications, hopefully Nitobi will incorporate this code (or similar) into the <a href="https://build.phonegap.com/apps">PhoneGap Build service</a> (which I tried earlier this week &#8211; it is pretty amazing!)</p>
<p>You can download a working example here: <a href='http://www.scottlogic.co.uk/blog/colin/wp-content/uploads/2012/01/HTML5SandwichFlow1.zip'>HTML5SandwichFlow.zip</a></p>
<p>(The first three recipe pages have &#8216;back&#8217; anchor elements, two use the URL, one uses JavaScript)</p>
<p>Regards,<br />
Colin E.</p>

]]></content:encoded>
			<wfw:commentRss>http://www.scottlogic.co.uk/blog/colin/2012/01/wp7-phonegap-backbutton-support-re-visited/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Windows Phone 7 – Browsing your Photos via Bing Maps</title>
		<link>http://www.scottlogic.co.uk/blog/colin/2012/01/windows-phone-7-browsing-your-photos-via-bing-maps/</link>
		<comments>http://www.scottlogic.co.uk/blog/colin/2012/01/windows-phone-7-browsing-your-photos-via-bing-maps/#comments</comments>
		<pubDate>Mon, 16 Jan 2012 08:27:56 +0000</pubDate>
		<dc:creator>Colin Eberhardt</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[codeproject]]></category>

		<guid isPermaLink="false">http://www.scottlogic.co.uk/blog/colin/?p=1925</guid>
		<description><![CDATA[The Windows Phone 7 camera gives you the option to record the location where a picture was taken (under Settings =&#62; applications =&#62; pictures+camera). With this feature turned on, each application has their latitude, longitude and altitude stored as part of the standard EXIF data. I thought it would be fun to combine the previous [...]]]></description>
			<content:encoded><![CDATA[
<p>The Windows Phone 7 camera gives you the option to record the location where a picture was taken (under Settings => applications => pictures+camera). With this feature turned on, each application has their latitude, longitude and altitude stored as part of the standard <a href="http://en.wikipedia.org/wiki/Exchangeable_image_file_format">EXIF data</a>. I thought it would be fun to combine the previous blog post I wrote on <a href="http://www.scottlogic.co.uk/blog/colin/2011/11/pushpin-clustering-with-the-windows-phone-7-bing-map-control/" title="Pushpin Clustering with the Windows Phone 7 Bing Map control">pushpin clustering</a> with the photos on my camera, to allow me to explore them via a Bing Maps control. With not much more than 100 lines of code I came up with an application which I think is a lot of fun to use. </p>
<table>
<tr>
<td width="300" >
<img style="margin:5px" src="http://www.scottlogic.co.uk/blog/colin/wp-content/uploads/2012/01/screenshot.jpg" alt="" title="screenshot4" width="300" height="188" class="aligncenter size-full wp-image-1931" />
</td>
<td width="300">
<img style="margin:5px" src="http://www.scottlogic.co.uk/blog/colin/wp-content/uploads/2012/01/screenshot2.jpg" alt="" title="screenshot4" width="300" height="188" class="aligncenter size-full wp-image-1931" />
</td>
</tr>
<tr>
<td>
<p  style="margin:5px">Here are all the photos on my phone, note the way the pushpins are clustered.</p>
</td>
<td>
<p  style="margin:5px">Here are a few pictures I took in New York, of the <a href="http://en.wikipedia.org/wiki/One_World_Trade_Center">One World Trade Centre</a> and the <a href="http://en.wikipedia.org/wiki/New_York_Stock_Exchange">Stock Exchange</a>.</p>
</td>
</tr>
<tr>
<td>
<img style="margin:5px" src="http://www.scottlogic.co.uk/blog/colin/wp-content/uploads/2012/01/screenshot3.jpg" alt="" title="screenshot4" width="300" height="188" class="aligncenter size-full wp-image-1931" />
</td>
<td>
<img style="margin:5px" src="http://www.scottlogic.co.uk/blog/colin/wp-content/uploads/2012/01/screenshot4.jpg" alt="" title="screenshot4" width="300" height="188" class="aligncenter size-full wp-image-1931" />
</td>
</tr>
<tr>
<td>
<p  style="margin:5px">Here are some pictures around Europe, including one of <a href="https://twitter.com/GergelyOrosz">Gergely Orosz</a> waiting for his turn in the Edinburgh Marathon Relay.</p>
</td>
<td>
<p  style="margin:5px">And finally, some pictures I took whilst running around <a href="http://en.wikipedia.org/wiki/Kielder_Water">Kielder Water</a> during Kielder marathon.</p>
</td>
</tr>
</table>
<h2>Accessing the EXIF data</h2>
<p>You can access the photos on a WP7 device via the XNA <a href="http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.media.medialibrary.aspx">MediaLibrary</a> class. The interface that this class provides gives you access to <a href="http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.media.picture.aspx">Picture</a> instances which have properties that allow you to access the width / height and a few other basic attributes. They also have methods that return streams which can be used to read the thumbnail and image data, however, they do not expose the picture location. This is &#8216;hidden&#8217; within the EXIF data.</p>
<p>Fortunately there is a C# implementation of an <a href="http://www.codeproject.com/KB/silverlight/Exif_Data.aspx">EXIF decoder available on codeproject</a>, which, <a href="http://timheuer.com/blog/archive/2010/09/23/working-with-pictures-in-camera-tasks-in-windows-phone-7-orientation-rotation.aspx">with a few tweaks by Tim Heuer</a> works just fine within Silverlight for Windows Phone 7.</p>
<p>With this library, accessing the EXIF data is a one-liner:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">JpegInfo info <span style="color: #008000;">=</span> ExifReader<span style="color: #008000;">.</span><span style="color: #0000FF;">ReadJpeg</span><span style="color: #008000;">&#40;</span>picture<span style="color: #008000;">.</span><span style="color: #0000FF;">GetImage</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>, picture<span style="color: #008000;">.</span><span style="color: #0000FF;">Name</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></pre></div></div>

<p>The JpegInfo class exposes the raw EXIF geolocation data, which is detailed in the <a href="http://www.exif.org/Exif2-2.PDF">EXIF specification</a> as being expressed as separate components of degrees, minutes and seconds together with a reference direction (North / South, East / West). We can convert from the <a href="http://en.wikipedia.org/wiki/Sexagesimal">sexagesimal</a> numeric system used in EXIF, to the decimal system as follows:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">double</span> DecodeLatitude<span style="color: #008000;">&#40;</span>JpegInfo info<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
  <span style="color: #6666cc; font-weight: bold;">double</span> degrees <span style="color: #008000;">=</span> ToDegrees<span style="color: #008000;">&#40;</span>info<span style="color: #008000;">.</span><span style="color: #0000FF;">GpsLatitude</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
  <span style="color: #0600FF; font-weight: bold;">return</span> info<span style="color: #008000;">.</span><span style="color: #0000FF;">GpsLatitudeRef</span> <span style="color: #008000;">==</span> ExifGpsLatitudeRef<span style="color: #008000;">.</span><span style="color: #0000FF;">North</span> <span style="color: #008000;">?</span> degrees <span style="color: #008000;">:</span> <span style="color: #008000;">-</span>degrees<span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">double</span> DecodeLongitude<span style="color: #008000;">&#40;</span>JpegInfo info<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
  <span style="color: #6666cc; font-weight: bold;">double</span> degrees <span style="color: #008000;">=</span> ToDegrees<span style="color: #008000;">&#40;</span>info<span style="color: #008000;">.</span><span style="color: #0000FF;">GpsLongitude</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
  <span style="color: #0600FF; font-weight: bold;">return</span> info<span style="color: #008000;">.</span><span style="color: #0000FF;">GpsLongitudeRef</span> <span style="color: #008000;">==</span> ExifGpsLongitudeRef<span style="color: #008000;">.</span><span style="color: #0000FF;">East</span> <span style="color: #008000;">?</span> degrees <span style="color: #008000;">:</span> <span style="color: #008000;">-</span>degrees<span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">double</span> ToDegrees<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">double</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> data<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
  <span style="color: #0600FF; font-weight: bold;">return</span> data<span style="color: #008000;">&#91;</span><span style="color: #FF0000;">0</span><span style="color: #008000;">&#93;</span> <span style="color: #008000;">+</span> data<span style="color: #008000;">&#91;</span><span style="color: #FF0000;">1</span><span style="color: #008000;">&#93;</span> <span style="color: #008000;">/</span> <span style="color: #FF0000;">60.0</span> <span style="color: #008000;">+</span> data<span style="color: #008000;">&#91;</span><span style="color: #FF0000;">2</span><span style="color: #008000;">&#93;</span> <span style="color: #008000;">/</span> <span style="color: #008000;">&#40;</span><span style="color: #FF0000;">60.0</span> <span style="color: #008000;">*</span> <span style="color: #FF0000;">60.0</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<h2>Analysing the images</h2>
<p>When the application starts a <code>BackgroundWorker</code> is used to read the EXIF data for all of the pictures in the phone&#8217;s media library, with those that have geolocation data available being stored in a separate list:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">BackgroundWorker bw <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> BackgroundWorker<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
bw<span style="color: #008000;">.</span><span style="color: #0000FF;">WorkerReportsProgress</span> <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #008080; font-style: italic;">// analyse the pictures that reside in the Media Library in a background thread</span>
bw<span style="color: #008000;">.</span><span style="color: #0000FF;">DoWork</span> <span style="color: #008000;">+=</span> <span style="color: #008000;">&#40;</span>s, e<span style="color: #008000;">&#41;</span> <span style="color: #008000;">=&gt;</span>
<span style="color: #008000;">&#123;</span>
  var ml <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> MediaLibrary<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
  <span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008000;">&#40;</span>var pics <span style="color: #008000;">=</span> ml<span style="color: #008000;">.</span><span style="color: #0000FF;">Pictures</span><span style="color: #008000;">&#41;</span>
  <span style="color: #008000;">&#123;</span>
    <span style="color: #6666cc; font-weight: bold;">int</span> total <span style="color: #008000;">=</span> pics<span style="color: #008000;">.</span><span style="color: #0000FF;">Count</span><span style="color: #008000;">;</span>
    <span style="color: #6666cc; font-weight: bold;">int</span> index <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span>
    <span style="color: #0600FF; font-weight: bold;">foreach</span> <span style="color: #008000;">&#40;</span>Picture picture <span style="color: #0600FF; font-weight: bold;">in</span> pics<span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
      <span style="color: #008080; font-style: italic;">// read the EXIF data for this image</span>
      JpegInfo info <span style="color: #008000;">=</span> ExifReader<span style="color: #008000;">.</span><span style="color: #0000FF;">ReadJpeg</span><span style="color: #008000;">&#40;</span>picture<span style="color: #008000;">.</span><span style="color: #0000FF;">GetImage</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>, picture<span style="color: #008000;">.</span><span style="color: #0000FF;">Name</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
      <span style="color: #008080; font-style: italic;">// check if we have co-ordinates</span>
      <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>info<span style="color: #008000;">.</span><span style="color: #0000FF;">GpsLatitude</span><span style="color: #008000;">.</span><span style="color: #0000FF;">First</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">!=</span> <span style="color: #FF0000;">0.0</span><span style="color: #008000;">&#41;</span>
      <span style="color: #008000;">&#123;</span>
        _images<span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">new</span> LocatedImage<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
          Picture <span style="color: #008000;">=</span> picture,
          Lat <span style="color: #008000;">=</span> DecodeLatitude<span style="color: #008000;">&#40;</span>info<span style="color: #008000;">&#41;</span>,
          <span style="color: #6666cc; font-weight: bold;">Long</span> <span style="color: #008000;">=</span> DecodeLongitude<span style="color: #008000;">&#40;</span>info<span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#125;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
      <span style="color: #008000;">&#125;</span>
&nbsp;
      <span style="color: #008080; font-style: italic;">// report progress back to the UI thread</span>
      <span style="color: #6666cc; font-weight: bold;">string</span> progress <span style="color: #008000;">=</span> <span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Format</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;{0} / {1}&quot;</span>, index, total<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
      bw<span style="color: #008000;">.</span><span style="color: #0000FF;">ReportProgress</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>index <span style="color: #008000;">*</span> <span style="color: #FF0000;">100</span> <span style="color: #008000;">/</span> total<span style="color: #008000;">&#41;</span>, progress<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
      index<span style="color: #008000;">++;</span>
    <span style="color: #008000;">&#125;</span>
  <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #008080; font-style: italic;">// update progress on the UI thread</span>
bw<span style="color: #008000;">.</span><span style="color: #0000FF;">ProgressChanged</span> <span style="color: #008000;">+=</span> <span style="color: #008000;">&#40;</span>s, e<span style="color: #008000;">&#41;</span> <span style="color: #008000;">=&gt;</span>
  <span style="color: #008000;">&#123;</span>
    <span style="color: #6666cc; font-weight: bold;">string</span> title <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&#41;</span>e<span style="color: #008000;">.</span><span style="color: #0000FF;">UserState</span><span style="color: #008000;">;</span>
    ApplicationTitle<span style="color: #008000;">.</span><span style="color: #0000FF;">Text</span> <span style="color: #008000;">=</span> title<span style="color: #008000;">;</span>
  <span style="color: #008000;">&#125;</span><span style="color: #008000;">;</span>
&nbsp;
bw<span style="color: #008000;">.</span><span style="color: #0000FF;">RunWorkerAsync</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #008080; font-style: italic;">// when analysis is complete, add the pushpins</span>
bw<span style="color: #008000;">.</span><span style="color: #0000FF;">RunWorkerCompleted</span> <span style="color: #008000;">+=</span> <span style="color: #008000;">&#40;</span>s, e<span style="color: #008000;">&#41;</span> <span style="color: #008000;">=&gt;</span>
  <span style="color: #008000;">&#123;</span>
    ApplicationTitle<span style="color: #008000;">.</span><span style="color: #0000FF;">Text</span> <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;&quot;</span><span style="color: #008000;">;</span>
    AddPushpins<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
  <span style="color: #008000;">&#125;</span><span style="color: #008000;">;</span></pre></div></div>

<p>When the pictures have all been analysed, a pushpin is created for each image which is then added to the <a href="http://www.scottlogic.co.uk/blog/colin/2011/11/pushpin-clustering-with-the-windows-phone-7-bing-map-control/" title="Pushpin Clustering with the Windows Phone 7 Bing Map control">clusterer described in my previous blog post</a>.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">void</span> AddPushpins<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
  List<span style="color: #008000;">&lt;</span>Pushpin<span style="color: #008000;">&gt;</span> pushPins <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> List<span style="color: #008000;">&lt;</span>Pushpin<span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
  <span style="color: #008080; font-style: italic;">// create a pushpin for each picture</span>
  <span style="color: #0600FF; font-weight: bold;">foreach</span> <span style="color: #008000;">&#40;</span>var image <span style="color: #0600FF; font-weight: bold;">in</span> _images<span style="color: #008000;">&#41;</span>
  <span style="color: #008000;">&#123;</span>
    Location location <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Location<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
      Latitude <span style="color: #008000;">=</span> image<span style="color: #008000;">.</span><span style="color: #0000FF;">Lat</span>,
      Longitude <span style="color: #008000;">=</span> image<span style="color: #008000;">.</span><span style="color: #6666cc; font-weight: bold;">Long</span>
    <span style="color: #008000;">&#125;</span><span style="color: #008000;">;</span>
&nbsp;
    Pushpin myPushpin <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Pushpin<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
      Location <span style="color: #008000;">=</span> location,
      DataContext <span style="color: #008000;">=</span> image,
      Content <span style="color: #008000;">=</span> image,
      ContentTemplate <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Resources</span><span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;MarkerTemplate&quot;</span><span style="color: #008000;">&#93;</span> <span style="color: #0600FF; font-weight: bold;">as</span> DataTemplate
    <span style="color: #008000;">&#125;</span><span style="color: #008000;">;</span>
&nbsp;
    pushPins<span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span>myPushpin<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
  <span style="color: #008000;">&#125;</span>
&nbsp;
  <span style="color: #008080; font-style: italic;">// add them to the map via a clusterer</span>
  var clusterer <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> PushpinClusterer<span style="color: #008000;">&#40;</span>map, pushPins, <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Resources</span><span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;ClusterTemplate&quot;</span><span style="color: #008000;">&#93;</span> <span style="color: #0600FF; font-weight: bold;">as</span> DataTemplate<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>The template used for the pushpins simply renders the image thumbnail:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;DataTemplate</span> <span style="color: #000066;">x:Key</span>=<span style="color: #ff0000;">&quot;MarkerTemplate&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Border</span> <span style="color: #000066;">BorderBrush</span>=<span style="color: #ff0000;">&quot;White&quot;</span> <span style="color: #000066;">BorderThickness</span>=<span style="color: #ff0000;">&quot;1&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Image</span> <span style="color: #000066;">Source</span>=<span style="color: #ff0000;">&quot;{Binding Picture, Converter={StaticResource PictureThumbnailConverter}}&quot;</span></span>
<span style="color: #009900;">            <span style="color: #000066;">Width</span>=<span style="color: #ff0000;">&quot;80&quot;</span> <span style="color: #000066;">Height</span>=<span style="color: #ff0000;">&quot;80&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Border<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/DataTemplate<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>This makes use of a simple value converter which takes a <code>Picture</code> instance and converts it into a <code>BitmapImage </code>which is used as the <code>Source </code>for the image:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">class</span> PictureThumbnailConverter <span style="color: #008000;">:</span> IValueConverter
<span style="color: #008000;">&#123;</span>
  <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">object</span> Convert<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">object</span> value, Type targetType, <span style="color: #6666cc; font-weight: bold;">object</span> parameter, <span style="color: #000000;">System.<span style="color: #0000FF;">Globalization</span></span><span style="color: #008000;">.</span><span style="color: #0000FF;">CultureInfo</span> culture<span style="color: #008000;">&#41;</span>
  <span style="color: #008000;">&#123;</span>
    Picture picture <span style="color: #008000;">=</span> value <span style="color: #0600FF; font-weight: bold;">as</span> Picture<span style="color: #008000;">;</span>
    BitmapImage src <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> BitmapImage<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    src<span style="color: #008000;">.</span><span style="color: #0000FF;">SetSource</span><span style="color: #008000;">&#40;</span>picture<span style="color: #008000;">.</span><span style="color: #0000FF;">GetThumbnail</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #0600FF; font-weight: bold;">return</span> src<span style="color: #008000;">;</span>
  <span style="color: #008000;">&#125;</span>
&nbsp;
  <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">object</span> ConvertBack<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">object</span> value, Type targetType, <span style="color: #6666cc; font-weight: bold;">object</span> parameter, <span style="color: #000000;">System.<span style="color: #0000FF;">Globalization</span></span><span style="color: #008000;">.</span><span style="color: #0000FF;">CultureInfo</span> culture<span style="color: #008000;">&#41;</span>
  <span style="color: #008000;">&#123;</span>
    <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">;</span>
  <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>The puhspin clusterer allows you to specify a separate template for clustered pushpins. The <code>DataContext</code> for this template is a list of the <code>DataContexts</code> of the clustered pins that it represents. For this application I created a template which renders what looks like a &#8216;stack&#8217; of images. The number of pictures in the cluster is rendered as a <code>TextBlock</code> and the last image in the cluster rendered.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;DataTemplate</span> <span style="color: #000066;">x:Key</span>=<span style="color: #ff0000;">&quot;ClusterTemplate&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Grid</span> <span style="color: #000066;">Width</span>=<span style="color: #ff0000;">&quot;75&quot;</span> <span style="color: #000066;">Height</span>=<span style="color: #ff0000;">&quot;75&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Canvas<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Border</span> <span style="color: #000066;">Style</span>=<span style="color: #ff0000;">&quot;{StaticResource FakePhoto}&quot;</span></span>
<span style="color: #009900;">              <span style="color: #000066;">Canvas.Left</span>=<span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #000066;">Canvas.Top</span>=<span style="color: #ff0000;">&quot;0&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Border</span> <span style="color: #000066;">Style</span>=<span style="color: #ff0000;">&quot;{StaticResource FakePhoto}&quot;</span></span>
<span style="color: #009900;">              <span style="color: #000066;">Canvas.Left</span>=<span style="color: #ff0000;">&quot;5&quot;</span> <span style="color: #000066;">Canvas.Top</span>=<span style="color: #ff0000;">&quot;5&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Border</span> <span style="color: #000066;">BorderBrush</span>=<span style="color: #ff0000;">&quot;White&quot;</span> <span style="color: #000066;">BorderThickness</span>=<span style="color: #ff0000;">&quot;1&quot;</span></span>
<span style="color: #009900;">              <span style="color: #000066;">Canvas.Left</span>=<span style="color: #ff0000;">&quot;10&quot;</span> <span style="color: #000066;">Canvas.Top</span>=<span style="color: #ff0000;">&quot;10&quot;</span></span>
<span style="color: #009900;">              <span style="color: #000066;">DataContext</span>=<span style="color: #ff0000;">&quot;{Binding Path=., Converter={StaticResource LastConverter}}&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Image</span> <span style="color: #000066;">Source</span>=<span style="color: #ff0000;">&quot;{Binding Picture, Converter={StaticResource PictureThumbnailConverter}}&quot;</span></span>
<span style="color: #009900;">                <span style="color: #000066;">Width</span>=<span style="color: #ff0000;">&quot;60&quot;</span> <span style="color: #000066;">Height</span>=<span style="color: #ff0000;">&quot;60&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Border<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;TextBlock</span> <span style="color: #000066;">Text</span>=<span style="color: #ff0000;">&quot;{Binding Count}&quot;</span></span>
<span style="color: #009900;">                  <span style="color: #000066;">Opacity</span>=<span style="color: #ff0000;">&quot;0.5&quot;</span></span>
<span style="color: #009900;">                  <span style="color: #000066;">Canvas.Left</span>=<span style="color: #ff0000;">&quot;25&quot;</span> <span style="color: #000066;">Canvas.Top</span>=<span style="color: #ff0000;">&quot;15&quot;</span></span>
<span style="color: #009900;">                  <span style="color: #000066;">FontSize</span>=<span style="color: #ff0000;">&quot;35&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Canvas<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Grid<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>      
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/DataTemplate<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Style</span> <span style="color: #000066;">TargetType</span>=<span style="color: #ff0000;">&quot;Border&quot;</span> <span style="color: #000066;">x:Key</span>=<span style="color: #ff0000;">&quot;FakePhoto&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Setter</span> <span style="color: #000066;">Property</span>=<span style="color: #ff0000;">&quot;Width&quot;</span> <span style="color: #000066;">Value</span>=<span style="color: #ff0000;">&quot;60&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Setter</span> <span style="color: #000066;">Property</span>=<span style="color: #ff0000;">&quot;Height&quot;</span> <span style="color: #000066;">Value</span>=<span style="color: #ff0000;">&quot;60&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Setter</span> <span style="color: #000066;">Property</span>=<span style="color: #ff0000;">&quot;BorderBrush&quot;</span> <span style="color: #000066;">Value</span>=<span style="color: #ff0000;">&quot;White&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Setter</span> <span style="color: #000066;">Property</span>=<span style="color: #ff0000;">&quot;Background&quot;</span> <span style="color: #000066;">Value</span>=<span style="color: #ff0000;">&quot;Black&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Setter</span> <span style="color: #000066;">Property</span>=<span style="color: #ff0000;">&quot;BorderThickness&quot;</span> <span style="color: #000066;">Value</span>=<span style="color: #ff0000;">&quot;1&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Style<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>The code that renders the last image is a bit cunning, it uses a value converter that performs a Linq style &#8216;last&#8217; operations, extracting the last items from a collection of objects:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">class</span> LastConverter <span style="color: #008000;">:</span> IValueConverter
<span style="color: #008000;">&#123;</span>
  <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">object</span> Convert<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">object</span> value, Type targetType, <span style="color: #6666cc; font-weight: bold;">object</span> parameter, <span style="color: #000000;">System.<span style="color: #0000FF;">Globalization</span></span><span style="color: #008000;">.</span><span style="color: #0000FF;">CultureInfo</span> culture<span style="color: #008000;">&#41;</span>
  <span style="color: #008000;">&#123;</span>
    IList enumerable <span style="color: #008000;">=</span> value <span style="color: #0600FF; font-weight: bold;">as</span> IList<span style="color: #008000;">;</span>
    <span style="color: #0600FF; font-weight: bold;">return</span> enumerable<span style="color: #008000;">.</span><span style="color: #0000FF;">Cast</span><span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">object</span><span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Last</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
  <span style="color: #008000;">&#125;</span>
&nbsp;
  <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">object</span> ConvertBack<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">object</span> value, Type targetType, <span style="color: #6666cc; font-weight: bold;">object</span> parameter, <span style="color: #000000;">System.<span style="color: #0000FF;">Globalization</span></span><span style="color: #008000;">.</span><span style="color: #0000FF;">CultureInfo</span> culture<span style="color: #008000;">&#41;</span>
  <span style="color: #008000;">&#123;</span>
    <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">;</span>
  <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>This feels quite neat to me <img src='http://www.scottlogic.co.uk/blog/colin/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>The clustered pins look like the following, which is a cluster of 5 images around Paris, with the stunning <a href="http://en.wikipedia.org/wiki/Grande_Arche">La Grande Arche de la Défense</a> as the image at the top of the cluster:</p>
<p><img src="http://www.scottlogic.co.uk/blog/colin/wp-content/uploads/2012/01/cluster.jpg" alt="" title="cluster" width="229" height="157" class="aligncenter size-full wp-image-1943" /></p>
<p>Despite its simplicity, I have had a lot of fun playing with this application. It has certainly encouraged me to take as many photos as possible whenever I go travelling.</p>
<p>You can download the full sourcecode here: <a href='http://www.scottlogic.co.uk/blog/colin/wp-content/uploads/2012/01/PhotoBrowser.zip'>PhotoBrowser.zip</a></p>
<p>Regards, Colin E.</p>

]]></content:encoded>
			<wfw:commentRss>http://www.scottlogic.co.uk/blog/colin/2012/01/windows-phone-7-browsing-your-photos-via-bing-maps/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>World-Beating Technical Expertise</title>
		<link>http://www.scottlogic.co.uk/2012/01/codeproject-mvp-award/</link>
		<comments>http://www.scottlogic.co.uk/2012/01/codeproject-mvp-award/#comments</comments>
		<pubDate>Tue, 10 Jan 2012 10:39:25 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Latest News Widget]]></category>
		<category><![CDATA[News]]></category>

		<guid isPermaLink="false">http://www.scottlogic.co.uk/?p=140968</guid>
		<description><![CDATA[Colin Eberhardt has been named as one of the top 40 contributors in the world by CodeProject, a leading developer community site.]]></description>
			<content:encoded><![CDATA[<p>Colin Eberhardt, a Senior Technical Architect at Scott Logic, has been <a href="http://www.scottlogic.co.uk/blog/colin/2012/01/proud-to-be-a-codeproject-mvp-2012/">awarded MVP status</a> by <a href="http://www.codeproject.com">CodeProject</a>, a leading community site that enables software developers to share expertise.  Colin is one of only forty developers worldwide to be given this accolade.</p>
<p>The MVP (Most Valued Professional) awards are given to the best and brightest from technology communities around the world.  Colin&#8217;s MVP status reflects his outstanding contribution to CodeProject over the past year, including high-quality articles on a variety of topics such as HTML5, Silverlight and Windows Phone 7. Colin also has his own blog, which you can read <a href="http://www.scottlogic.co.uk/blog/colin/">here</a>.</p>
<p>Scott Logic prides itself on the expertise of its consultants, and is very pleased to see this acknowledged by such a prestigious award.  Many congratulations Colin!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.scottlogic.co.uk/2012/01/codeproject-mvp-award/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Proud to be a CodeProject MVP 2012</title>
		<link>http://www.scottlogic.co.uk/blog/colin/2012/01/proud-to-be-a-codeproject-mvp-2012/</link>
		<comments>http://www.scottlogic.co.uk/blog/colin/2012/01/proud-to-be-a-codeproject-mvp-2012/#comments</comments>
		<pubDate>Mon, 09 Jan 2012 20:48:46 +0000</pubDate>
		<dc:creator>Colin Eberhardt</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[News]]></category>

		<guid isPermaLink="false">http://www.scottlogic.co.uk/blog/colin/?p=1919</guid>
		<description><![CDATA[I have just received an email from Chris Maunder, co-founder of CodeProject, informing me that I have been awarded CodeProject MVP status for 2012. I am very pleased to have received this award, which is given to a small handful of individuals each year. What I like about CodeProject is the fantastic quality of the [...]]]></description>
			<content:encoded><![CDATA[
<p>I have just received an email from Chris Maunder, co-founder of CodeProject, informing me that I have been awarded CodeProject MVP status for 2012. I am very pleased to have received this award, which is <a href="http://www.codeproject.com/script/Awards/MVPWinners.aspx">given to a small handful of individuals</a> each year.</p>
<p><a href="http://www.codeproject.com/Members/Colin-Eberhardt"><img src="http://www.scottlogic.co.uk/blog/colin/wp-content/uploads/2009/04/codeproject.gif" alt="" title="codeproject" width="225" height="72" class="aligncenter size-full wp-image-283" /></a></p>
<p>What I like about CodeProject is the fantastic quality of the articles submitted by the thousands of authors that participate in this site, with the only payment being their own please in the writing.</p>
<p>I have not written that many articles throughout the year, just four of them. However, I have put a lot of effort into each one of them &#8211; and thankfully they have been very well received. It is great that CodeProject favours quality over quantity. My articles for 2011 were:</p>
<ul>
<li><a href="http://www.codeproject.com/KB/codegen/CodeSnippetAutomation.aspx">Declarative Codesnippet Automation with T4 Templates</a></li>
<li><a href="http://www.codeproject.com/KB/windows-phone-7/WindowsPhone7JumpLIst.aspx">Developing a Windows Phone 7 JumpList Control</a></li>
<li><a href="http://www.codeproject.com/KB/scripting/SilverlightToHTML5.aspx">From Silverlight to HTML5</a></li>
<li><a href="http://www.codeproject.com/KB/windows-phone-7/XAMLFinance.aspx">XAMLFinance – A Cross-platform WPF, Silverlight &#038; WP7 Application</a></li>
</ul>
<p>I do also circulate some of my blog posts via the CodeProject Associate program..</p>
<p>On that note, it is almost three months since I last wrote an article &#8230; fortunately I do have an idea for the next article, so I had better get on with writting it &#8230;</p>
<p>Regards, Colin E.</p>

]]></content:encoded>
			<wfw:commentRss>http://www.scottlogic.co.uk/blog/colin/2012/01/proud-to-be-a-codeproject-mvp-2012/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>iPad / iPhone Controls Launched</title>
		<link>http://www.scottlogic.co.uk/2012/01/ipad-iphone-controls-launched/</link>
		<comments>http://www.scottlogic.co.uk/2012/01/ipad-iphone-controls-launched/#comments</comments>
		<pubDate>Sun, 08 Jan 2012 14:34:42 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Latest News Widget]]></category>
		<category><![CDATA[Press Releases]]></category>

		<guid isPermaLink="false">http://www.scottlogic.co.uk/?p=142689</guid>
		<description><![CDATA[Scott Logic’s product division has released Shinobi Controls, a suite of very high quality native iOS controls for iPad and iPhone.  

]]></description>
			<content:encoded><![CDATA[<p>Scott Logic’s product division has launched ShinobiControls, a suite of very high quality native <a href="http://www.shinobicontrols.com">iOS controls for iPad and iPhone</a>.</p>
<p style="text-align: center"><a href="http://www.scottlogic.co.uk/wp-content/uploads/2012/01/shinobicharts.png"><img src="http://www.scottlogic.co.uk/wp-content/uploads/2012/01/shinobicharts.png" alt="" title="shinobicharts" width="375" height="265" class="aligncenter size-full wp-image-142707" /></a></p>
<p><a href="http://www.shinobicharts.com">ShinobiCharts</a> is the charting consituent of ShinobiControls, and features a wide range of chart types to choose from, so you can choose the best way to present your data. A fully customizable look and feel means you can choose from Shinobi styles or create your own branded charts. ShinobiCharts maintain high levels of interactivity and performance in the face of really big data sets.</p>
<p>If you would like a free trial, you can sign up at <a href="http://www.shinobicontrols.com">ShinobiControls.</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.scottlogic.co.uk/2012/01/ipad-iphone-controls-launched/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>FastClick for WP7 – Improving Browser Responsiveness for PhoneGap Apps</title>
		<link>http://www.scottlogic.co.uk/blog/colin/2012/01/fastclick-for-wp7-improving-browser-responsiveness-for-phonegap-apps/</link>
		<comments>http://www.scottlogic.co.uk/blog/colin/2012/01/fastclick-for-wp7-improving-browser-responsiveness-for-phonegap-apps/#comments</comments>
		<pubDate>Thu, 05 Jan 2012 10:23:50 +0000</pubDate>
		<dc:creator>Colin Eberhardt</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Windows Phone 7]]></category>

		<guid isPermaLink="false">http://www.scottlogic.co.uk/blog/colin/?p=1907</guid>
		<description><![CDATA[I recently released an update of the HTML5 / PhoneGap application I wrote a few months ago to the marketplace. This update fixed the location detection issue, where the marketplace certification process failed to detect that the application was using geolocation data via the browser (this issue has been fixed in PhoneGap 1.2), plus a [...]]]></description>
			<content:encoded><![CDATA[
<p>I recently released an update of the HTML5 / PhoneGap application I wrote a few months ago to the marketplace. This update fixed the location detection issue, where the marketplace certification process failed to detect that the application was using geolocation data via the browser (this issue <a href="https://issues.apache.org/jira/browse/CB-138">has been fixed in PhoneGap 1.2</a>), plus a few cosmetic improvements.</p>
<p>This application still exhibits a few UI quirks that make it fairly obvious that this is not a native application, the first is the <a href="http://stackoverflow.com/questions/6378008/windows-phone-7-browser-turn-off-the-gray-shading-when-links-are-clicked">gray box that appears whenever a link is clicked</a>, the second is the overall responsiveness &#8211; there is a short delay between clicking on links / buttons and the application responding. It is this responsiveness that I would like to tackle in this blog post. This delay unfortunately gives the impression that your application is less responsive than it actually is!</p>
<p><strong><em>So where does this delay come from?</em></strong></p>
<p>Despite the rise in popularity of touch interfaces, much of the web is still designed for interaction with a mouse and keyboard, with the DOM exposing events for mouse-up, mouse-down and click user interactions. The Windows Phone 7 browser control captures touch interactions and translates these into the required mouse events, firing them on the DOM element being interacted with. However, the browser itself also needs to support gestures such as pan, pinch-zoom and double-tap zoom.</p>
<p>If we consider for example the pinch-zoom feature, where the user places two fingers on the screen and moves them apart in order to zoom in. It is highly unlikely they will place both fingers on the screen simultaneously. If, when the first finger was placed, a mouse-down event was fired on the relevant DOM element, there would be no way to &#8216;cancel&#8217; this event when the user&#8217;s second finger made contact with the screen shortly afterwards. For this reason the WP7 mobile browser does not properly support mouse-down / mouse-up events. You will find that mousedown, mouseup then click are always fired immediately in that order regardless of how long you hold your finger on the screen for. Clearly the need to add gesture support to the browser interferes with the way in which native touch events are translated into JavaScript mouse events.</p>
<p>Now consider the double-tap zoom feature, where the user taps twice in quick succession to zoom the web page by some fixed amount. If the DOM click event were fired on the first tap, this would cause a navigation to occur if an anchor element were tapped. This is certainly not the desired behaviour! Again, there is no way to &#8216;cancel&#8217; an event once it is fired, so the only solution to this problem is, when the user first taps the screen, pause for a few hundred milliseconds to see if they tap a second time. Only after this pause is it safe to pass the interaction onto the DOM, firing a click event on the relevant DOM element.</p>
<p><img src="http://www.scottlogic.co.uk/blog/colin/wp-content/uploads/2012/01/the_fence.jpg" alt="" title="the_fence" width="300" height="244" class="aligncenter size-full wp-image-1910" /></p>
<p><small>Stock image courtesy of <a href="http://www.sxc.hu/photo/313551">lovetheson</a></small></p>
<p>The need to handle gestures in the native layer causes numerous issues for the browser event handling. Thankfully these issues are relatively minor for most websites, but if your aim is to create a HTML-based application with a native look and feel, these issues become quite major.</p>
<p><strong>Improving responsiveness</strong></p>
<p>The problem I want to tackle in this blog post is that of the click DOM event firing delay to support the double-tap gesture. With HTML5-based applications you will typically want to disable pinch zoom, double-tap zoom and (optionally) scrolling <a href="http://www.scottlogic.co.uk/blog/colin/2011/11/suppressing-zoom-and-scroll-interactions-in-the-windows-phone-7-browser-control/" title="Suppressing Zoom and Scroll interactions in the Windows Phone 7 WebBrowser Control">as I described in a previous blog post</a>. As a result your application has no need for the double-tap and pinch gestures and we are safe to short-circuit this behaviour, immediately raising DOM click events when the user taps the screen.</p>
<p>My solution follows a similar approach to the utility class I wrote for suppressing pan / zoom, where event handlers are added to the <code>Border </code>that sits within the <code>WebBrowser </code>control visual tree:</p>
<pre>
\-WebBrowser
  \-Border
    \-Border
      \-PanZoomContainer
        \-Grid
          \-Border (*)
            \-ContentPresenter
              \-TileHost
</pre>
<p>In order to forward Tap gestures to the browser, we can add event handlers to the Border element, then use <code>InvokeScript</code> to pass this onto the DOM rendered within the <code>TileHost</code>.</p>
<p>The JavaScript code to achieve this is very simple, the DOM exposes an <code>elementFromPoint</code> function which allows you to hit test the DOM. The IE9 DOM interface also exposes a non-standard <code>click</code> function which invokes any click event handlers, this will cause an anchor element to navigate. Putting it together, if you have an anchor element at <code>(x=100, y=100)</code>, you can cause it to navigate using the following simple code:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">document.<span style="color: #660066;">elementFromPoint</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">100</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">100</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span></pre></div></div>

<p>Calling this JavaScript from our native C# code in response to Tap events is very easy. I have wrapped it up into a simple utility class:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
<span style="color: #008080; font-style: italic;">/// Captures mouse left button up events, triggering an immediate</span>
<span style="color: #008080; font-style: italic;">/// click event on the clicked DOM element.</span>
<span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">class</span> BrowserFastClick
<span style="color: #008000;">&#123;</span>
  <span style="color: #0600FF; font-weight: bold;">private</span> WebBrowser _browser<span style="color: #008000;">;</span>
&nbsp;
  <span style="color: #0600FF; font-weight: bold;">private</span> Border _border<span style="color: #008000;">;</span>
&nbsp;
  <span style="color: #0600FF; font-weight: bold;">public</span> BrowserFastClick<span style="color: #008000;">&#40;</span>WebBrowser browser<span style="color: #008000;">&#41;</span>
  <span style="color: #008000;">&#123;</span>
    _browser <span style="color: #008000;">=</span> browser<span style="color: #008000;">;</span>
    browser<span style="color: #008000;">.</span><span style="color: #0000FF;">Loaded</span> <span style="color: #008000;">+=</span> <span style="color: #008000;">new</span> RoutedEventHandler<span style="color: #008000;">&#40;</span>Browser_Loaded<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
  <span style="color: #008000;">&#125;</span>
&nbsp;
  <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">void</span> Browser_Loaded<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">object</span> sender, RoutedEventArgs e<span style="color: #008000;">&#41;</span>
  <span style="color: #008000;">&#123;</span>
    <span style="color: #008080; font-style: italic;">// locate the element used to capture mouse events</span>
    _border <span style="color: #008000;">=</span> _browser<span style="color: #008000;">.</span><span style="color: #0000FF;">Descendants</span><span style="color: #008000;">&lt;</span>Border<span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Last</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #0600FF; font-weight: bold;">as</span> Border<span style="color: #008000;">;</span>
    _border<span style="color: #008000;">.</span><span style="color: #0000FF;">Tap</span> <span style="color: #008000;">+=</span> Border_Tap<span style="color: #008000;">;</span>
  <span style="color: #008000;">&#125;</span>
&nbsp;
  <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">void</span> Border_Tap<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">object</span> sender, GestureEventArgs e<span style="color: #008000;">&#41;</span>
  <span style="color: #008000;">&#123;</span>
    <span style="color: #008080; font-style: italic;">//determine the click location</span>
    var pos <span style="color: #008000;">=</span> e<span style="color: #008000;">.</span><span style="color: #0000FF;">GetPosition</span><span style="color: #008000;">&#40;</span>_border<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #008080; font-style: italic;">// forward to the browser</span>
    _browser<span style="color: #008000;">.</span><span style="color: #0000FF;">InvokeScript</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;eval&quot;</span>,
      <span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Format</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;document.elementFromPoint({0},{1}).click()&quot;</span>, pos<span style="color: #008000;">.</span><span style="color: #0000FF;">X</span>, pos<span style="color: #008000;">.</span><span style="color: #0000FF;">Y</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>      
  <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>To use it within a PhoneGap application, simply create an instance as follows:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008000;">new</span> BrowserFastClick<span style="color: #008000;">&#40;</span>PGView<span style="color: #008000;">.</span><span style="color: #0000FF;">Browser</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></pre></div></div>

<p>The net result is that your application becomes more responsive, with the browser immediately navigating links when they are first tapped.</p>
<p>I have updated the HTML5 SandwichFlow application I blogged about a few weeks ago to use this FastClick code. You can download the complete example here: <a href='http://www.scottlogic.co.uk/blog/colin/wp-content/uploads/2012/01/HTML5SandwichFlow.zip'>HTML5SandwichFlow.zip</a></p>
<p>Regards, Colin E.</p>

]]></content:encoded>
			<wfw:commentRss>http://www.scottlogic.co.uk/blog/colin/2012/01/fastclick-for-wp7-improving-browser-responsiveness-for-phonegap-apps/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A Festive and Fun Windows Phone 7 Maze Game</title>
		<link>http://www.scottlogic.co.uk/blog/colin/2011/12/a-festive-and-fun-windows-phone-7-maze-game/</link>
		<comments>http://www.scottlogic.co.uk/blog/colin/2011/12/a-festive-and-fun-windows-phone-7-maze-game/#comments</comments>
		<pubDate>Thu, 22 Dec 2011 10:01:19 +0000</pubDate>
		<dc:creator>Colin Eberhardt</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Windows Phone 7]]></category>

		<guid isPermaLink="false">http://www.scottlogic.co.uk/blog/colin/?p=1899</guid>
		<description><![CDATA[Last night, with my Christmas presents all wrapped and a lack of any decent programmes (festive or otherwise) on television, I had a few hours to kill, so decided to create a festive-themed WP7 game &#8230; Ever since I first started writing code for Windows Phone 7 I have wanted to do something involving physics [...]]]></description>
			<content:encoded><![CDATA[
<p>Last night, with my Christmas presents all wrapped and a lack of any decent programmes (festive or otherwise) on television, I had a few hours to kill, so decided to create a festive-themed WP7 game &#8230;</p>
<p>Ever since I first started writing code for Windows Phone 7 I have wanted to do something involving physics and the accelerometer. I finally found a few hours to spare to give it a go. This blog post doesn’t go into too much detail about <a href="http://farseerphysics.codeplex.com/">Farseer</a>, the Physics Engine that I used, I didn’t really have time to learn it in any great detail. This post is more about how quickly you can put together something really quite cool in quite a short space of time using libraries and code grabbed from the internet.</p>
<p>The simple app I created renders a maze that you ‘roll’ a small ball around by tilting your phone:</p>
<p><img src="http://www.scottlogic.co.uk/blog/colin/wp-content/uploads/2011/12/MazeGame.png" alt="" title="MazeGame" width="200" height="363" class="aligncenter size-full wp-image-1900" /></p>
<p>This works well in the new 7.1 emulator where you can tilt the emulator via the extended controls. However, it works best on a real device, where you can control tilt far more easily. See the video below:</p>
<p><iframe width="480" height="360" src="http://www.youtube.com/embed/Xkhh9P-Y45k" frameborder="0" allowfullscreen></iframe></p>
<h2>Farseer Physics Engine</h2>
<p>The game makes use of the popular <a href="http://farseerphysics.codeplex.com/">Farseer Physics Engine</a>. This library allows you to create a world populated with physics bodies, supporting features such as friction, joints, motors and much much more. As I am a Silverlight developer I made use of the <a href="http://physicshelper.codeplex.com/">Physics Helper</a> library which allows you to use the Farseer engine within a Silvelight application with very little effort. With the Physics Helper you simply make the Physics Engine ‘aware’ of the objects you wish it to control and it does the rest, animating them as they are subjected to gravity and other interactions.</p>
<p>The simplest way to use Physics Helper is via behaviours, this allows you to create a fully functioning ‘world’ without writing a single line of C# code. For example, you can create a ball and a surface that it will fall towards, eventually coming to rest, with just a few lines of XAML:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008000;">&lt;</span>Canvas x<span style="color: #008000;">:</span>Name<span style="color: #008000;">=</span><span style="color: #666666;">&quot;canvas&quot;</span><span style="color: #008000;">&gt;</span>
  <span style="color: #008000;">&lt;!--</span> create our <span style="color: #666666;">'world'</span> <span style="color: #008000;">--&gt;</span>
  <span style="color: #008000;">&lt;</span>i<span style="color: #008000;">:</span>Interaction<span style="color: #008000;">.</span><span style="color: #0000FF;">Behaviors</span><span style="color: #008000;">&gt;</span>
    <span style="color: #008000;">&lt;</span>pb<span style="color: #008000;">:</span>PhysicsControllerBehavior<span style="color: #008000;">/&gt;</span>
  <span style="color: #008000;">&lt;/</span>i<span style="color: #008000;">:</span>Interaction<span style="color: #008000;">.</span><span style="color: #0000FF;">Behaviors</span><span style="color: #008000;">&gt;</span>
&nbsp;
  <span style="color: #008000;">&lt;</span>Ellipse Width<span style="color: #008000;">=</span><span style="color: #666666;">&quot;100&quot;</span> Height<span style="color: #008000;">=</span><span style="color: #666666;">&quot;100&quot;</span> Fill<span style="color: #008000;">=</span><span style="color: #666666;">&quot;Red&quot;</span>
            Canvas<span style="color: #008000;">.</span><span style="color: #0000FF;">Left</span><span style="color: #008000;">=</span><span style="color: #666666;">&quot;80&quot;</span> Canvas<span style="color: #008000;">.</span><span style="color: #0000FF;">Top</span><span style="color: #008000;">=</span><span style="color: #666666;">&quot;100&quot;</span><span style="color: #008000;">&gt;</span>
    <span style="color: #008000;">&lt;!--</span> make the engine aware of <span style="color: #0600FF; font-weight: bold;">this</span> element <span style="color: #008000;">--&gt;</span>
    <span style="color: #008000;">&lt;</span>i<span style="color: #008000;">:</span>Interaction<span style="color: #008000;">.</span><span style="color: #0000FF;">Behaviors</span><span style="color: #008000;">&gt;</span>
      <span style="color: #008000;">&lt;</span>pb<span style="color: #008000;">:</span>PhysicsObjectBehavior <span style="color: #008000;">/&gt;</span>
    <span style="color: #008000;">&lt;/</span>i<span style="color: #008000;">:</span>Interaction<span style="color: #008000;">.</span><span style="color: #0000FF;">Behaviors</span><span style="color: #008000;">&gt;</span>
  <span style="color: #008000;">&lt;/</span>Ellipse<span style="color: #008000;">&gt;</span>
&nbsp;
&nbsp;
  <span style="color: #008000;">&lt;</span>Rectangle Width<span style="color: #008000;">=</span><span style="color: #666666;">&quot;500&quot;</span> Height<span style="color: #008000;">=</span><span style="color: #666666;">&quot;10&quot;</span> Fill<span style="color: #008000;">=</span><span style="color: #666666;">&quot;Blue&quot;</span>
              Canvas<span style="color: #008000;">.</span><span style="color: #0000FF;">Top</span><span style="color: #008000;">=</span><span style="color: #666666;">&quot;500&quot;</span><span style="color: #008000;">&gt;</span>
    <span style="color: #008000;">&lt;!--</span> make the engine aware of <span style="color: #0600FF; font-weight: bold;">this</span> <span style="color: #0600FF; font-weight: bold;">STATIC</span> element <span style="color: #008000;">--&gt;</span>
    <span style="color: #008000;">&lt;</span>i<span style="color: #008000;">:</span>Interaction<span style="color: #008000;">.</span><span style="color: #0000FF;">Behaviors</span><span style="color: #008000;">&gt;</span>
      <span style="color: #008000;">&lt;</span>pb<span style="color: #008000;">:</span>PhysicsObjectBehavior IsStatic<span style="color: #008000;">=</span><span style="color: #666666;">&quot;True&quot;</span><span style="color: #008000;">/&gt;</span>
    <span style="color: #008000;">&lt;/</span>i<span style="color: #008000;">:</span>Interaction<span style="color: #008000;">.</span><span style="color: #0000FF;">Behaviors</span><span style="color: #008000;">&gt;</span>
  <span style="color: #008000;">&lt;/</span>Rectangle<span style="color: #008000;">&gt;</span>
<span style="color: #008000;">&lt;/</span>Canvas<span style="color: #008000;">&gt;</span></pre></div></div>

<p><img src="http://www.scottlogic.co.uk/blog/colin/wp-content/uploads/2011/12/SimpleExample.png" alt="" title="SimpleExample" width="600" height="256" class="aligncenter size-full wp-image-1901" /></p>
<p>I find this pretty amazing! </p>
<p>Physics Helper will do much more, it can handle complex paths and geometries, explosions and collisions with minimal effort. For a greater insight into just how much is possible, I would recommend <a href="http://channel9.msdn.com/coding4fun/articles/Creating-a-Pinball-Game-in-Silverlight-Using-the-Physics-Helper-Library--Farseer-Physics">Andy Beaulieu’s Channel 9 article</a>. Andy is the creator of Farseer, so really knows his stuff!</p>
<p>My maze is generated in C# code, so despite the elegance of using Physics Helper via behaviours, I need to add elements to my canvas programmatically. This means that I have to make the physics engine aware of their existence in code also. To achieve this, I add the behaviour in code as follows:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
<span style="color: #008080; font-style: italic;">/// Uses Physics Helper to create a physics body for the given element</span>
<span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
<span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">void</span> AddPhysicsBody<span style="color: #008000;">&#40;</span>FrameworkElement element, <span style="color: #6666cc; font-weight: bold;">bool</span> isStatic<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
  var behaviorCollection <span style="color: #008000;">=</span> Interaction<span style="color: #008000;">.</span><span style="color: #0000FF;">GetBehaviors</span><span style="color: #008000;">&#40;</span>element<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
  behaviorCollection<span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">new</span> PhysicsObjectBehavior<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
  <span style="color: #008000;">&#123;</span>
    IsStatic <span style="color: #008000;">=</span> isStatic
  <span style="color: #008000;">&#125;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
  var physicsObject <span style="color: #008000;">=</span> element<span style="color: #008000;">.</span><span style="color: #0000FF;">GetValue</span><span style="color: #008000;">&#40;</span>PhysicsObjectMain<span style="color: #008000;">.</span><span style="color: #0000FF;">PhysicsObjectProperty</span><span style="color: #008000;">&#41;</span> <span style="color: #0600FF; font-weight: bold;">as</span> PhysicsObjectMain<span style="color: #008000;">;</span>
  _physicsController<span style="color: #008000;">.</span><span style="color: #0000FF;">AddPhysicsBody</span><span style="color: #008000;">&#40;</span>physicsObject<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<h2>Creating a Maze</h2>
<p>I found numerous C# maze algorithms on the internet, most of them based on the same random-walk concept. There is a great description of this approach, with <a href="http://weblog.jamisbuck.org/2011/1/20/maze-generation-wilson-s-algorithm">animated examples on this blog</a>. Unfortunately every C# implementation I came across was tightly coupled to a specific UI framework, often WinForms or XNA (tut-tut remember to separate your concerns!). So, I took a simple maze algorithm <a href="http://www.techpowerup.com/forums/showthread.php?t=109739">from a software forum</a> and ripped-out the WinForms / GDI rendering code. A new maze is constructed simply by creating an instance of the <code>Maze</code> class, passing it the number of rows and columns.</p>
<p>In order to render the maze using Silverlight elements, I simply took the original maze graphics code:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">void</span> CreateMaze<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
  <span style="color: #008080; font-style: italic;">// compute the number of rows / cols</span>
  <span style="color: #6666cc; font-weight: bold;">double</span> ratio <span style="color: #008000;">=</span> mazeContainer<span style="color: #008000;">.</span><span style="color: #0000FF;">ActualHeight</span> <span style="color: #008000;">/</span> mazeContainer<span style="color: #008000;">.</span><span style="color: #0000FF;">ActualWidth</span><span style="color: #008000;">;</span>
  <span style="color: #6666cc; font-weight: bold;">int</span> cols <span style="color: #008000;">=</span> _mazeSize<span style="color: #008000;">;</span>
  <span style="color: #6666cc; font-weight: bold;">int</span> rows <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">double</span><span style="color: #008000;">&#41;</span>cols <span style="color: #008000;">*</span> ratio<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
  <span style="color: #6666cc; font-weight: bold;">double</span> cellWidth <span style="color: #008000;">=</span> mazeContainer<span style="color: #008000;">.</span><span style="color: #0000FF;">ActualWidth</span> <span style="color: #008000;">/</span> cols<span style="color: #008000;">;</span>
&nbsp;
  <span style="color: #008080; font-style: italic;">// create the maze</span>
  Maze maze <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Maze<span style="color: #008000;">&#40;</span>rows, cols<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
  <span style="color: #008080; font-style: italic;">// render the maze</span>
  <span style="color: #0600FF; font-weight: bold;">for</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span> i <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span> i <span style="color: #008000;">&lt;</span> cols<span style="color: #008000;">;</span> <span style="color: #008000;">++</span>i<span style="color: #008000;">&#41;</span>
  <span style="color: #008000;">&#123;</span>
    <span style="color: #0600FF; font-weight: bold;">for</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span> j <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span> j <span style="color: #008000;">&lt;</span> rows<span style="color: #008000;">;</span> <span style="color: #008000;">++</span>j<span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
      var room <span style="color: #008000;">=</span> maze<span style="color: #008000;">.</span><span style="color: #0000FF;">cells</span><span style="color: #008000;">&#91;</span>i, j<span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span>
      <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>room <span style="color: #008000;">&amp;</span> Maze<span style="color: #008000;">.</span><span style="color: #0000FF;">UP</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">!=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">&#41;</span>
        DrawLine<span style="color: #008000;">&#40;</span>i <span style="color: #008000;">*</span> cellWidth <span style="color: #008000;">+</span> cellWidth <span style="color: #008000;">/</span> <span style="color: #FF0000;">2</span>,
                j <span style="color: #008000;">*</span> cellWidth,
                i <span style="color: #008000;">*</span> cellWidth <span style="color: #008000;">+</span> cellWidth <span style="color: #008000;">/</span> <span style="color: #FF0000;">2</span>,
                j <span style="color: #008000;">*</span> cellWidth <span style="color: #008000;">+</span> cellWidth <span style="color: #008000;">/</span> <span style="color: #FF0000;">2</span> <span style="color: #008000;">-</span> <span style="color: #FF0000;">1</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
      <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>room <span style="color: #008000;">&amp;</span> Maze<span style="color: #008000;">.</span><span style="color: #0000FF;">DOWN</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">!=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">&#41;</span>
        DrawLine<span style="color: #008000;">&#40;</span>i <span style="color: #008000;">*</span> cellWidth <span style="color: #008000;">+</span> cellWidth <span style="color: #008000;">/</span> <span style="color: #FF0000;">2</span>,
              j <span style="color: #008000;">*</span> cellWidth <span style="color: #008000;">+</span> cellWidth <span style="color: #008000;">/</span> <span style="color: #FF0000;">2</span>,
              i <span style="color: #008000;">*</span> cellWidth <span style="color: #008000;">+</span> cellWidth <span style="color: #008000;">/</span> <span style="color: #FF0000;">2</span>,
              j <span style="color: #008000;">*</span> cellWidth <span style="color: #008000;">+</span> cellWidth <span style="color: #008000;">-</span> <span style="color: #FF0000;">1</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
      <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>room <span style="color: #008000;">&amp;</span> Maze<span style="color: #008000;">.</span><span style="color: #0000FF;">RIGHT</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">!=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">&#41;</span>
        DrawLine<span style="color: #008000;">&#40;</span>i <span style="color: #008000;">*</span> cellWidth <span style="color: #008000;">+</span> cellWidth <span style="color: #008000;">/</span> <span style="color: #FF0000;">2</span>,
              j <span style="color: #008000;">*</span> cellWidth <span style="color: #008000;">+</span> cellWidth <span style="color: #008000;">/</span> <span style="color: #FF0000;">2</span>,
              i <span style="color: #008000;">*</span> cellWidth <span style="color: #008000;">+</span> cellWidth <span style="color: #008000;">-</span> <span style="color: #FF0000;">1</span>,
              j <span style="color: #008000;">*</span> cellWidth <span style="color: #008000;">+</span> cellWidth <span style="color: #008000;">/</span> <span style="color: #FF0000;">2</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
      <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>room <span style="color: #008000;">&amp;</span> Maze<span style="color: #008000;">.</span><span style="color: #0000FF;">LEFT</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">!=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">&#41;</span>
        DrawLine<span style="color: #008000;">&#40;</span>i <span style="color: #008000;">*</span> cellWidth,
              j <span style="color: #008000;">*</span> cellWidth <span style="color: #008000;">+</span> cellWidth <span style="color: #008000;">/</span> <span style="color: #FF0000;">2</span>,
              i <span style="color: #008000;">*</span> cellWidth <span style="color: #008000;">+</span> cellWidth <span style="color: #008000;">/</span> <span style="color: #FF0000;">2</span> <span style="color: #008000;">-</span> <span style="color: #FF0000;">1</span>,
              j <span style="color: #008000;">*</span> cellWidth <span style="color: #008000;">+</span> cellWidth <span style="color: #008000;">/</span> <span style="color: #FF0000;">2</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span>
  <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>And created a method that mimics the behaviour of the <code>System.Drawing.Graphics.DrawLine</code> method which the original maze code depended on:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">void</span> DrawLine<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">double</span> x1, <span style="color: #6666cc; font-weight: bold;">double</span> y1, <span style="color: #6666cc; font-weight: bold;">double</span> x2, <span style="color: #6666cc; font-weight: bold;">double</span> y2<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
  <span style="color: #6666cc; font-weight: bold;">double</span> width <span style="color: #008000;">=</span> x2 <span style="color: #008000;">-</span> x1 <span style="color: #008000;">+</span> <span style="color: #FF0000;">2.0</span><span style="color: #008000;">;</span>
  <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>width <span style="color: #008000;">==</span> <span style="color: #FF0000;">0.0</span><span style="color: #008000;">&#41;</span> width <span style="color: #008000;">=</span> <span style="color: #FF0000;">2.0</span><span style="color: #008000;">;</span>
&nbsp;
  <span style="color: #6666cc; font-weight: bold;">double</span> height <span style="color: #008000;">=</span>  y2 <span style="color: #008000;">-</span> y1<span style="color: #008000;">+</span> <span style="color: #FF0000;">2.0</span><span style="color: #008000;">;</span>
  <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>height <span style="color: #008000;">==</span> <span style="color: #FF0000;">0.0</span><span style="color: #008000;">&#41;</span> height <span style="color: #008000;">=</span> <span style="color: #FF0000;">2.0</span><span style="color: #008000;">;</span>
&nbsp;
  var rec <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> <span style="color: #000000;">System</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Windows</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Shapes</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Rectangle</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
  <span style="color: #008000;">&#123;</span>
    Fill <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> SolidColorBrush<span style="color: #008000;">&#40;</span>Colors<span style="color: #008000;">.</span><span style="color: #0000FF;">Red</span><span style="color: #008000;">&#41;</span>,
    Width <span style="color: #008000;">=</span> width,
    Height <span style="color: #008000;">=</span> height
  <span style="color: #008000;">&#125;</span><span style="color: #008000;">;</span>
  Canvas<span style="color: #008000;">.</span><span style="color: #0000FF;">SetLeft</span><span style="color: #008000;">&#40;</span>rec, x1<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
  Canvas<span style="color: #008000;">.</span><span style="color: #0000FF;">SetTop</span><span style="color: #008000;">&#40;</span>rec, y1<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
  mazeContainer<span style="color: #008000;">.</span><span style="color: #0000FF;">Children</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span>rec<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
  AddPhysicsBody<span style="color: #008000;">&#40;</span>rec, <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>A bit messy, but gets the job done!</p>
<p>The above code creates a maze comprised of static physics objects, where the<code> _mazeSize</code> field dictates the scale of the maze:</p>
<p><img src="http://www.scottlogic.co.uk/blog/colin/wp-content/uploads/2011/12/Mazes.png" alt="" title="Mazes" width="500" height="454" class="aligncenter size-full wp-image-1902" /></p>
<h2>Adding a Rolling Ball</h2>
<p>Adding a ball to the maze is simply a matter of creating an ellipse and adding it at the maze entrance. Note, this physics-body is not static, so will move under the influence of gravity:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">Ellipse ball <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Ellipse<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
  Width <span style="color: #008000;">=</span> cellWidth <span style="color: #008000;">*</span> <span style="color: #FF0000;">0.7</span>,
  Height <span style="color: #008000;">=</span> cellWidth <span style="color: #008000;">*</span> <span style="color: #FF0000;">0.7</span>,
  Fill <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Resources</span><span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;brush&quot;</span><span style="color: #008000;">&#93;</span> <span style="color: #0600FF; font-weight: bold;">as</span> Brush
<span style="color: #008000;">&#125;</span><span style="color: #008000;">;</span>
Canvas<span style="color: #008000;">.</span><span style="color: #0000FF;">SetLeft</span><span style="color: #008000;">&#40;</span>ball, <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>cols <span style="color: #008000;">/</span> <span style="color: #FF0000;">2</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">+</span> <span style="color: #FF0000;">0.7</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">*</span> cellWidth<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
Canvas<span style="color: #008000;">.</span><span style="color: #0000FF;">SetTop</span><span style="color: #008000;">&#40;</span>ball, <span style="color: #FF0000;">0</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
mazeContainer<span style="color: #008000;">.</span><span style="color: #0000FF;">Children</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span>ball<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
AddPhysicsBody<span style="color: #008000;">&#40;</span>ball, <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></pre></div></div>

<p>By default, the ‘world’ has gravity with a fixed Y component and no X component. This causes all non-static bodies to fall downwards as you might expect. In order to guide the ball around the maze by tilting the phone, we need to adjust gravity based on accelerometer readings. This is achieved by the following code:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">void</span> HandleAccelerometer<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
  _sensor <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Accelerometer<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
  _sensor<span style="color: #008000;">.</span><span style="color: #0000FF;">Start</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
  <span style="color: #008080; font-style: italic;">// 10 times a second, update the gravity</span>
  var gtimer <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> DispatcherTimer<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
  gtimer<span style="color: #008000;">.</span><span style="color: #0000FF;">Interval</span> <span style="color: #008000;">=</span> TimeSpan<span style="color: #008000;">.</span><span style="color: #0000FF;">FromSeconds</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">0.1</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
  gtimer<span style="color: #008000;">.</span><span style="color: #0000FF;">Tick</span> <span style="color: #008000;">+=</span> <span style="color: #008000;">&#40;</span>s, e<span style="color: #008000;">&#41;</span> <span style="color: #008000;">=&gt;</span>
  <span style="color: #008000;">&#123;</span>
    <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>_physicsController<span style="color: #008000;">.</span><span style="color: #0000FF;">Simulator</span> <span style="color: #008000;">!=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
      _physicsController<span style="color: #008000;">.</span><span style="color: #0000FF;">Simulator</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Gravity</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Y</span> <span style="color: #008000;">=</span> <span style="color: #FF0000;">5</span> <span style="color: #008000;">*</span> <span style="color: #008000;">-</span>_sensor<span style="color: #008000;">.</span><span style="color: #0000FF;">CurrentValue</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Acceleration</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Y</span><span style="color: #008000;">;</span>
      _physicsController<span style="color: #008000;">.</span><span style="color: #0000FF;">Simulator</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Gravity</span><span style="color: #008000;">.</span><span style="color: #0000FF;">X</span> <span style="color: #008000;">=</span> <span style="color: #FF0000;">5</span> <span style="color: #008000;">*</span> _sensor<span style="color: #008000;">.</span><span style="color: #0000FF;">CurrentValue</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Acceleration</span><span style="color: #008000;">.</span><span style="color: #0000FF;">X</span><span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span>
  <span style="color: #008000;">&#125;</span><span style="color: #008000;">;</span>
  gtimer<span style="color: #008000;">.</span><span style="color: #0000FF;">Start</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p><strong>Note</strong>: this uses a timer, rather than updating the simulator every time the accelerometer reading changes. I found that without the timer, I was repeatedly seeing the generic “Element is already a child of another element” exception. You will also notice in the code that the maze is built after a pause of a couple of seconds, again in order to avoid this issue. There’s something funny going on inside the Physics Helper!</p>
<p>Finally, we handle collisions in order to play a simple sounds effect a the ball bounces off each wall:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008080; font-style: italic;">// locate the physics controller</span>
_physicsController <span style="color: #008000;">=</span> mazeContainer<span style="color: #008000;">.</span><span style="color: #0000FF;">GetValue</span><span style="color: #008000;">&#40;</span>PhysicsControllerMain<span style="color: #008000;">.</span><span style="color: #0000FF;">PhysicsControllerProperty</span><span style="color: #008000;">&#41;</span> <span style="color: #0600FF; font-weight: bold;">as</span> PhysicsControllerMain<span style="color: #008000;">;</span>
&nbsp;
<span style="color: #008080; font-style: italic;">// load the WAV file</span>
Stream stream <span style="color: #008000;">=</span> TitleContainer<span style="color: #008000;">.</span><span style="color: #0000FF;">OpenStream</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;boing1.wav&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
_effect <span style="color: #008000;">=</span> SoundEffect<span style="color: #008000;">.</span><span style="color: #0000FF;">FromStream</span><span style="color: #008000;">&#40;</span>stream<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
FrameworkDispatcher<span style="color: #008000;">.</span><span style="color: #0000FF;">Update</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #008080; font-style: italic;">// play on each collision</span>
_physicsController<span style="color: #008000;">.</span><span style="color: #0000FF;">Collision</span> <span style="color: #008000;">+=</span> <span style="color: #008000;">&#40;</span>s,e<span style="color: #008000;">&#41;</span> <span style="color: #008000;">=&gt;</span> _effect<span style="color: #008000;">.</span><span style="color: #0000FF;">Play</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></pre></div></div>

<p>And there we have it, a simple maze game powered by the Farseer Physics engine. The whole thing only took about an hour to create, with code grabbed from the internet &#8211; a bit rough and ready, but I was impressed with how easy it was to create this game. There is much more that could be done, for example detecting when the ball reaches the end of the maze, advancing to a more difficult level, however, my time has run out on this bit of fun &#8230; Also, if I were to take this idea further, I would probably use XNA rather than Silverlight. The Physics Helper is great for simple XAML-only physics models, but I feel that it wasn’t really built for programmatic creation of bodies.</p>
<p>You can download the code here: <a href='http://www.scottlogic.co.uk/blog/colin/wp-content/uploads/2011/12/WP7MazeGame.zip'>WP7MazeGame.zip</a></p>
<p>Note, you will have to download and install Physics Helper to run this code.</p>
<p>On another note, Farseer is clearly the result of hundreds of hours of development effort, which makes it easy to create realistic physics-based applications and games. Farseer is free to use under the MS-PL licence. However, I would urge anyone who has used this great library to create a WP7 game to donate via the <a href="http://farseerphysics.codeplex.com/">Farseer codeplex site</a> (scroll to the bottom).</p>
<p>Regards, Colin E.</p>

]]></content:encoded>
			<wfw:commentRss>http://www.scottlogic.co.uk/blog/colin/2011/12/a-festive-and-fun-windows-phone-7-maze-game/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A Metro Themed PowerPoint Template</title>
		<link>http://www.scottlogic.co.uk/blog/colin/2011/12/a-metro-themed-powerpoint-template/</link>
		<comments>http://www.scottlogic.co.uk/blog/colin/2011/12/a-metro-themed-powerpoint-template/#comments</comments>
		<pubDate>Mon, 19 Dec 2011 17:10:57 +0000</pubDate>
		<dc:creator>Colin Eberhardt</dc:creator>
				<category><![CDATA[Blog]]></category>

		<guid isPermaLink="false">http://www.scottlogic.co.uk/blog/colin/?p=1889</guid>
		<description><![CDATA[Over the weekend I mentioned on Twitter that I had created a Metro-style PowerPoint template. There were a few requests to share, so hence this blog post. Scroll to the bottom to download the PowerPoint file. So why create a Metro-style PowerPoint presentation? A couple of reasons, firstly, the templates that come with PowerPoint are [...]]]></description>
			<content:encoded><![CDATA[
<p>Over the weekend I mentioned on Twitter that I had created a Metro-style PowerPoint template. There were a few requests to share, so hence this blog post. Scroll to the bottom to download the PowerPoint file.</p>
<p><img src="http://www.scottlogic.co.uk/blog/colin/wp-content/uploads/2011/12/MetroPP.png" alt="" title="MetroPP" width="506" height="378" class="aligncenter size-full wp-image-1890" /></p>
<p>So why create a Metro-style PowerPoint presentation? A couple of reasons, firstly, the templates that come with PowerPoint are absolutely awful!</p>
<p><img src="http://www.scottlogic.co.uk/blog/colin/wp-content/uploads/2011/12/PPTemplates.png" alt="" title="PPTemplates" width="571" height="282" class="aligncenter size-full wp-image-1891" /></p>
<p>They look very dated (to put it politely). Secondly, with the Metro Design Language, which was introduced with Windows Phone 7, Microsoft have come up with something surprisingly stylish. Metro is about clarity, readability, simplicity &#8211; concepts that map very well to presentations. </p>
<p>The &#8216;classic&#8217; Metro look, which I have tried to re-produce with this template, includes highly legible san-serif fonts (from the Segoe family), a lack of chrome (i.e. shadows, gradient) and fluid motions. Many metro applications do include background imagery to add &#8216;warmth&#8217;, as I have done here also.</p>
<p>I have created a template with a master and a number of layouts. Each layout includes a number of sequenced animations, mimicking the &#8216;fast and fluid&#8217; Metro interface:</p>
<p><img src="http://www.scottlogic.co.uk/blog/colin/wp-content/uploads/2011/12/Animations.png" alt="" title="Animations" width="600" height="347" class="aligncenter size-full wp-image-1892" /></p>
<p>PowerPoint can be used to create some rather neat sequenced animations, if you ignore the rather garish defaults.</p>
<p>To get a better feel for this template, have a look at it in motion (the quality here is rather poor, I haven&#8217;t managed to find a screen capture tool that works well for subtle colours):</p>
<p><iframe width="480" height="360" src="http://www.youtube.com/embed/Nmtu5vSYrn8" frameborder="0" allowfullscreen></iframe></p>
<p>If you want to use this template, you might want to change the background image. You can do this via the &#8216;slide master view&#8217;. The background I included is one I found on the free stock imagery site stock.xcnhg, by the user <a href="http://www.sxc.hu/photo/1246725">fangol</a>. There are numerous other free images on that site. Please remember to attribute your usage of free stock images.</p>
<p>You might also find that you need to add new layouts based on your content. Again, this is easy to do via the master view.</p>
<p>Anyhow, here is the template, enjoy: <a href='http://www.scottlogic.co.uk/blog/colin/wp-content/uploads/2011/12/MetroStyle.pptx'>MetroStyle.pptx</a></p>
<p><b>NOTE:</b> Until I get the mime-types sorted out you might have to right click and select &#8220;save as&#8221; to save the above PowerPoint file.</p>
<p>Regards, Colin E.</p>

]]></content:encoded>
			<wfw:commentRss>http://www.scottlogic.co.uk/blog/colin/2011/12/a-metro-themed-powerpoint-template/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

