<?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>Shazaml Design, LLC &#187; MagnifierOverBehavior</title>
	<atom:link href="http://www.shazaml.com/archives/tag/magnifieroverbehavior/feed" rel="self" type="application/rss+xml" />
	<link>http://www.shazaml.com</link>
	<description>Design and Development for Windows Phone 7</description>
	<lastBuildDate>Thu, 27 Oct 2011 19:33:42 +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>Video: Creating a Silverlight 3 Casual Game using Blend 3 and Triggers, Actions, and Behaviors</title>
		<link>http://www.shazaml.com/archives/video-silverlight-casual-game</link>
		<comments>http://www.shazaml.com/archives/video-silverlight-casual-game#comments</comments>
		<pubDate>Mon, 09 Nov 2009 15:19:11 +0000</pubDate>
		<dc:creator>Mark Tucker</dc:creator>
				<category><![CDATA[Hidden Object Game]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Action]]></category>
		<category><![CDATA[Behavior]]></category>
		<category><![CDATA[Blend]]></category>
		<category><![CDATA[ChangePropertyAction]]></category>
		<category><![CDATA[ContinuousPlayMediaBehavior]]></category>
		<category><![CDATA[games]]></category>
		<category><![CDATA[GlobalCounterMinReachedTrigger]]></category>
		<category><![CDATA[GoToStateAction]]></category>
		<category><![CDATA[IncrementGlobalCounterAction]]></category>
		<category><![CDATA[InvokeCommandAction]]></category>
		<category><![CDATA[MagnifierOverBehavior]]></category>
		<category><![CDATA[MouseCursorBehavior]]></category>
		<category><![CDATA[ParticlesBehavior]]></category>
		<category><![CDATA[PlaySoundAction]]></category>
		<category><![CDATA[RemoveElementAction]]></category>
		<category><![CDATA[SetGlobalCounterAction]]></category>
		<category><![CDATA[SetInteractionPropertyAction]]></category>
		<category><![CDATA[ShowGlobalCounterBehavior]]></category>
		<category><![CDATA[Trigger]]></category>
		<category><![CDATA[video]]></category>
		<category><![CDATA[Visual State Manager]]></category>
		<category><![CDATA[VSM]]></category>

		<guid isPermaLink="false">http://www.shazaml.com/?p=333</guid>
		<description><![CDATA[Video presentation from Desert Code Camp 2009 - Silverlight 3 Casual Game]]></description>
			<content:encoded><![CDATA[<p>On Saturday, November 7, 2009 at 9:00am I presented at the Desert Code Camp in Phoenix, AZ. The topic of my presentation was Silverlight casual game development. In less than an hour I demonstrated how to use triggers, actions, and behaviors in Blend 3 to create a hidden object game. Because all code was contained in the TABs (Triggers, Actions, and Behaviors) there was no code behind for the main UserControl.</p>
<p>Here is a link to the <a title="Video - Creating a Silverlight 3 Casual Game using Blend 3 and Triggers, Actions, and Behaviors" href="http://www.shazaml.com/downloads/DesertCodeCamp2009-Silverlight3CasualGame.wmv">presentation video</a> in WMV format.</p>
<p>If you like you can see <a href="http://www.shazaml.com/archives/creating-a-hidden-object-game-in-silverlight-3">all the episodes</a> and follow along with the tutorial.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.shazaml.com/archives/video-silverlight-casual-game/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
<enclosure url="http://www.shazaml.com/downloads/DesertCodeCamp2009-Silverlight3CasualGame.wmv" length="63294285" type="video/x-ms-wmv" />
		</item>
		<item>
		<title>Hidden Object: Episode 7 – Use an Action to Toggle the Magnifier Behavior</title>
		<link>http://www.shazaml.com/archives/hidden-object-episode-7</link>
		<comments>http://www.shazaml.com/archives/hidden-object-episode-7#comments</comments>
		<pubDate>Sat, 26 Sep 2009 13:03:42 +0000</pubDate>
		<dc:creator>Mark Tucker</dc:creator>
				<category><![CDATA[Hidden Object Game]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Action]]></category>
		<category><![CDATA[BaseBehavior]]></category>
		<category><![CDATA[Behavior]]></category>
		<category><![CDATA[Blend]]></category>
		<category><![CDATA[games]]></category>
		<category><![CDATA[MagnifierOverBehavior]]></category>
		<category><![CDATA[SetInteractionPropertyAction]]></category>
		<category><![CDATA[Trigger]]></category>

		<guid isPermaLink="false">http://www.shazaml.com/?p=186</guid>
		<description><![CDATA[Using the magnifier-styled CheckBox from the last episode along with the Behavior base classes and SetInteractionPropertyAction we finish the magnification feature.]]></description>
			<content:encoded><![CDATA[<p>This is episode 7 of <a href="http://www.shazaml.com/archives/creating-a-hidden-object-game-in-silverlight-3">Creating a Hidden Object Game is Silverlight 3</a>.</p>
<p>In the last few posts we have been working on the magnifier feature of the game which we will finish in this episode.</p>
<p>Please review the following posts:</p>
<ul>
<li><a href="http://www.shazaml.com/archives/hidden-object-episode-5">Episode 5 – Add a Magnifier Behavior</a></li>
<li><a href="http://www.shazaml.com/archives/base-classes-for-custom-behaviors">Base Classes for Custom Behaviors</a></li>
<li><a href="http://www.shazaml.com/archives/setinteractionpropertyaction">Creating an Action to set Properties on Actions &amp; Behaviors</a></li>
<li><a href="http://www.shazaml.com/archives/hidden-object-episode-6">Episode 6 – Create a CheckBox from an Image</a></li>
</ul>
<p>First we will add in the following files into the ClutteredCube project:</p>
<ul>
<li>
<div>Interactivity folder (from <a href="http://www.shazaml.com/archives/base-classes-for-custom-behaviors">Base Classes for Custom Behaviors</a>)</div>
<ul>
<li>BaseBehavior.cs</li>
<li>BaseBehaviorT.cs</li>
</ul>
</li>
<li>
<div>Interactivity\SetInteractionPropertyAction folder (from <a href="http://www.shazaml.com/archives/setinteractionpropertyaction">Creating an Action to set Properties on Actions &amp; Behaviors</a>)</div>
<ul>
<li>ConverterHelper.cs</li>
<li>SetInteractionPropertyAction.cs</li>
</ul>
</li>
</ul>
<p><img src="http://www.shazaml.com/wp-content/uploads/2009/09/092609_1303_HiddenObjec1.png" alt="" /></p>
<p>The first thing we want to do is to change MagnifierOverBehavior so that it inherits from our custom behavior base class thus inheriting the IsEnabled property:</p>
<pre class="brush: csharp; light: true; title: ; notranslate">
public class MagnifierOverBehavior : BaseBehavior&lt;FrameworkElement&gt;
</pre>
<p>The only other change we need to make this behavior is not set the Effect property on MouseEnter but instead in MouseMove based on the value of the IsEnabled property:</p>
<pre class="brush: csharp; light: true; title: ; notranslate">
private void AssociatedObject_MouseEnter( object sender, MouseEventArgs e )
{
  this.AssociatedObject.MouseMove += new MouseEventHandler( AssociatedObject_MouseMove );
  //this.AssociatedObject.Effect = this.magnifier;
}

private void AssociatedObject_MouseMove( object sender, MouseEventArgs e )
{
  if (IsEnabled)
  {
    if (this.AssociatedObject.Effect != this.magnifier)
    {
      this.AssociatedObject.Effect = this.magnifier;
    }
    ...
  }
}
</pre>
<p>In Blend, open the MainPage and select the MagnifierOverBehavior in the Object tree under <em>magnifierCanvas</em>. Name the behavior <em>magnifierBehavior</em> and set IsEnabled to false:</p>
<p><img src="http://www.shazaml.com/wp-content/uploads/2009/09/092609_1303_HiddenObjec2.png" alt="" /></p>
<p>From the Assets tab drag two instances of SetInteractionPropertyAction onto the CheckBox magnifier control:</p>
<p><img src="http://www.shazaml.com/wp-content/uploads/2009/09/092609_1303_HiddenObjec3.png" alt="" /></p>
<p>On the first one, set the properties as follows:</p>
<ul>
<li>EventName: Checked</li>
<li>TargetName: magnifierCanvas</li>
<li>ObjectName: magnifierBehavior</li>
<li>PropertyName: IsEnabled</li>
<li>Value: true</li>
</ul>
<p><img src="http://www.shazaml.com/wp-content/uploads/2009/09/092609_1303_HiddenObjec4.png" alt="" /></p>
<p>Set the second the same as the first, except:</p>
<ul>
<li>EventName: Unchecked</li>
<li>Value: false</li>
</ul>
<p><img src="http://www.shazaml.com/wp-content/uploads/2009/09/092609_1303_HiddenObjec5.png" alt="" /></p>
<p>Make sure that the CheckBox control IsChecked property is false to match the InEnabled value of false for <em>magniferBehavior</em>.</p>
<p>Run the game and verify that magnification is only turned on when the CheckBox is checked.</p>
<p>Let&#8217;s do one more thing to finish this episode. Notice that magnifier.png has a white background behind the glass part of the magnifying glass. The image should be on top of something white like a notepad. Import the notepad image and drop it at the bottom of LayoutRoot.</p>
<p><img src="http://www.shazaml.com/wp-content/uploads/2009/09/notepad.png" alt="notepad" /></p>
<p>Position it how you want it and move the magnifier CheckBox on top of it.</p>
<p><a href="http://www.shazaml.com/downloads/ClutteredCubeSource7.zip">Source Code</a></p>
<p><a href="http://www.shazaml.com/hidden-object-episode-7-demo">Demo</a></p>
<p>There are many features to add so I will keep the <a href="http://www.shazaml.com/archives/hidden-object-episode-8">next episode</a> contents a surprise.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.shazaml.com/archives/hidden-object-episode-7/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Hidden Object: Episode 5 – Add a Magnifier Behavior</title>
		<link>http://www.shazaml.com/archives/hidden-object-episode-5</link>
		<comments>http://www.shazaml.com/archives/hidden-object-episode-5#comments</comments>
		<pubDate>Sat, 19 Sep 2009 00:09:30 +0000</pubDate>
		<dc:creator>Mark Tucker</dc:creator>
				<category><![CDATA[Hidden Object Game]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Behavior]]></category>
		<category><![CDATA[Effect]]></category>
		<category><![CDATA[games]]></category>
		<category><![CDATA[MagnifierOverBehavior]]></category>

		<guid isPermaLink="false">http://www.shazaml.com/?p=107</guid>
		<description><![CDATA[The MagnifierOverBehavior and magnifier pixel shader effect gives us a closer look at the picture.]]></description>
			<content:encoded><![CDATA[<p> This is episode 5 in the series, <a href="http://www.shazaml.com/archives/creating-a-hidden-object-game-in-silverlight-3">Creating a Hidden Object Game in Silverlight 3</a>.</p>
<p>In this episode, we will add an existing MagnifierOverBehavior to our project to allow the user to get a closer look at areas of the picture.</p>
<p>On the <a href="http://www.silverlightshow.net/">SilverlightShow</a> site, there is an article titled, <a href="http://www.silverlightshow.net/items/Behaviors-and-Triggers-in-Silverlight-3.aspx">Behaviors and Triggers in Silverlight 3</a>, by Pencho Popadiyn. The article does a great job showing the base classes for Actions and Behaviors as well as shows some custom Behaviors. One of them is the MagnifierOverBehavior which magnifiers an oval area as you move the mouse around the image:</p>
<p><img src="http://www.shazaml.com/wp-content/uploads/2009/09/091909_0009_HiddenObjec1.png" alt="" /></p>
<p> </p>
<p>It does this by setting the Effect property on the AssociatedObject to a custom pixel shader effect.</p>
<p>Go to the <a href="http://www.silverlightshow.net/items/Behaviors-and-Triggers-in-Silverlight-3.aspx">Behaviors and Triggers in Silverlight 3</a> and download the source. Open Visual Studio and under the Interactivity folder create a folder called MagnifierOverBehavior. Into that folder copy the following files from the Behaviors and ShaderEffectsLibrary projects:</p>
<ul>
<li>MagnifierOverBehavior.cs</li>
<li>EffectLibrary.cs</li>
<li>Magnifier.cs</li>
<li>Magnifier.fx</li>
<li>Magnifier.ps</li>
<li>ShaderEffectBase.cs</li>
</ul>
<p> </p>
<p>Include the files into your project.</p>
<p>I have spent little time researching effects (classes derived from System.Windows.Media.Effects.Effect), but here is an introduction. Silverlight 3 ships with two concrete effects (BlurEffect &amp; DropShadowEffect) and one abstract effect (ShaderEffect). Any class that derives from UIElement has a single Effect property that can be set. To apply multiple effects, you need to use a hierarchy of UIElement-derived objects assigning the Effect property on different objects to get a composite effect. The pixel shader effect is software rendered in Silverlight and hardware rendered in WPF.</p>
<p>In our case, the Magnifier.cs file contains the Magnifier class that derives from ShaderEffectBase which derives from ShaderEffect which derives from Effect. A good article is <a href="http://www.silverlightshow.net/items/Pixel-Effects-in-Silverlight-3.aspx">Pixel Effects in Silverlight 3</a>. The next file to look at is Magnifier.fx which contains code in High Level Shading Language (HLSL). The important thing to know is that the fx file must be compiled into a ps file. Since we already have Magnifier.ps then we don&#8217;t have to worry about it.</p>
<p>More details on HLSL, can be found at the following links:</p>
<ul>
<li><a href="http://www.silverlightshow.net/items/Silverlight-Slide-Show-using-Pixel-Shader-effects.aspx">Silverlight Slide Show (using Pixel Shader effects)</a></li>
<li><a href="http://msdn.microsoft.com/en-us/library/bb509561%28VS.85%29.aspx">MSDN DirectX SDK – HLSL</a></li>
<li><a href="http://en.wikipedia.org/wiki/High_Level_Shader_Language">Wikipedia – High Level Shader Language</a></li>
<li><a href="http://timheuer.com/blog/archive/2009/09/02/silverlight-pixel-shader-compile-options.aspx">Compiling pixel shaders for Silverlight</a></li>
</ul>
<p>The EffectLibrary.cs file contains helper method, MakePackUri, which is used in line 42 of Magnifer.cs. We need to change the string to identify the correct location in our project of the pixel shader file. Change &#8220;Source/Magnifier.ps&#8221; to &#8220;Interactivity/MagnifierOverBehavior/Magnifier.ps&#8221; since the ps file resides in the MagnifierOverBehavior project folder under the Interactivty folder.</p>
<p>Compile and then open the solution in Blend 3.</p>
<p>We want the magnifier to show when over the main office picture. But if we attach the behavior to the image, then magnification will turn off when we mouse over one of the path objects. To solve this problem, we will group the office image and all paths into a canvas object which we will name <em>magnifierCanvas</em>. Now drag the MagnifierOverBehavior from the Assets panel to associate it with <em>magnifierCanvas</em>:</p>
<p><img src="http://www.shazaml.com/wp-content/uploads/2009/09/091909_0009_HiddenObjec2.png" alt="" /></p>
<p> </p>
<p>Run the game and now you will see that when mouse is over the image it shows a magnifier. You can click when in magnification mode and the items will be removed from the list:</p>
<p><a href="http://www.shazaml.com/wp-content/uploads/2009/09/091909_0009_HiddenObjec3.png"><img src="http://www.shazaml.com/wp-content/uploads/2009/09/091909_0009_HiddenObjec3.png" alt="" width="507" height="205" /></a></p>
<p> </p>
<p>We don&#8217;t want to always be in magnification mode, we need a way to toggle the magnifier on or off. We will tackle that in the <a href="http://www.shazaml.com/archives/hidden-object-episode-6">next episode</a> as we create an action that is able to set a property on an action or behavior that is associated to an object.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.shazaml.com/archives/hidden-object-episode-5/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

