Microsoft Surface – Installing an App on V2

Previously, I wrote about porting my Surface Craps application from Surface v1 to v2.  Now that the app has been upgraded, here’s a short post on how to update the installer to work with v2.

There is not much different about the makeup of an application that is registered on the Surface between v1 and v2.  Your program binaries go in a directory, and then (new to v2) a SHORTCUT points the Surface shell to that directory.

Program Files

Unlike v1 that required you to install your program files in a specific “Program Data” sub directory, now you can install your program files to a directory of your choice – usually %ProgramFiles(x86)%.

CropperCapture113

Program Data Shortcut

Next, make your installer create a SHORTCUT to the directory where you install your program files, and place the shortcut in the Surface v2 directory:  C:\ProgramData\Microsoft\Surface\v2.0\Programs.

It’s important that this shortcut is to the DIRECTORY where your program files are, not a shortcut directly to the application .xml file.

Here’s how the Surface programs directory and shortcut properties should look.

CropperCapture115

That’s it – you should now see your application in the chooser when you run the shell.

Microsoft Surface – Porting from v1 to v2

A couple years ago, I wrote Surface Craps during RECESS to explore the Microsoft Surface table and APIs.  Now that Surface 2 is out, it’s time to upgrade the software to run on the new hardware.  This is the first in a series of blog posts about the process in upgrading from Surface v1 to v2.

Obviously this first requires that you have the Surface 2 SDK installed.  To start, I branched the project tree in TFS to make a v2 copy.

Open the project in VS 2010.  Update the project references.  The new referenced assemblies are in C:\Program Files (x86)\Microsoft SDKs\Surface\v2.0\Reference Assemblies.

  • Microsoft.Surface.dll
  • Microsoft.Surface.Presentation.dll
  • Microsoft.Surface.Presentation.Generic.dll

I was using Visual State Manager from the WPF Toolkit, and now it’s included in WPF 4, so I removed that reference as well.

Now we start the brute force process of fixing code that doesn’t compile.  Here’s a list of what I found.  Many of these changes are moving to WPF 4 in general, since it’s where we get most of the touch functionality in the Surface 2 environment.

Control Name Changes

Surface v1 Surface v2
SurfaceUserControl UserControl
SurfaceContentControl ContentControl

Event Handling Changes

Surface v1 Surface v2
ContactDown event use TouchDown
(Preview)ContactUp/Down use (Preview)TouchUp/Down
ContactDown event use TouchDown
(Preview)ContactUp/Down (Preview)TouchUp/Down
ContactChanged TouchMove
ContactEventHandler EventHandler<TouchEventArgs>
ApplicationActivated, etc. OnWindowInteractive, Noninteractive, Unavailable (see a default new Surface 2 project for an example of these event handlers)
ApplicationLauncher.Orientation ApplicationServices.InitialOrientation

Property / Method Changes

Surface v1 Surface v2
e.Contact.IsTagRecognized e.TouchDevice.GetIsTagRecognized( ). (add using statement for Microsoft.Surface.Presentation.Input to get the extension method)
e.Contact.Tag.Byte.Value e.TouchDevice.GetTagData().Series & .Value
e.Contact.GetPosition( ) e.TouchDevice.GetPosition( )
e.Contact.GetOrientation( ) e.TouchDevice.GetOrientation( )
ScatterViewItem.IsActive ScatterViewItem.IsContainerActive

Manipulation Processing

In Surface v1, you would use the Affine2DManipulationProcessor to handle gestures such as flick, rotation, scale, etc.  In v2, you just use the manipulation processing that’s provided by the WPF 4 UIElement.

Surface v1 Surface v2
On any elements that you want to track manipulations on, set IsManipuliationEnabled = true
BeginTrack( ) nothing to do in v2
Affine2DManipulationCompleted, … events UIElement.ManipulationCompleted, … events
e.Velocity.Length e.FinalVelocities.LinearVelocity.Length
e.TotalTranslation.X e.TotalManipulation.Translation.X

Resolution

That’s all I had to as far as API differences.  Next came the resolution differences. The Surface v2 display runs at 1920 x 1080, so if you have any UI that does not stretch or any hardcoded coordinate-based math in your software, it will have to be updated.

Tags

Surface v2 does not support Identity tags, but it does support Byte tags.  See the tag-related methods above for the API differences.

For Surface Craps specifically, I ran into a problem with the transparent dice we got from Microsoft for Surface v1. The dice have byte tags on them that are practically transparent, but have enough IR reflectivity to be picked up by the Surface v1 infrared cameras.  In Surface v2, the tags are recognized by interpreting the contact information using PixelSense technology, and something in that processing is not recognizing the mostly transparent tags on the dice.  I will continue to investigate this issue and write another post if I have any update.  For now – it’s a bummer that the physical dice do not work.

Installation

In a future post I will talk about the differences in what it takes to install your application in Surface v2…

 
 
 

Disable SurfaceKeyboard for a Particular Application

We are working on a Surface 2 based application that runs on Windows 7, but is going to be running on very large touch-based wall mounted displays.   These displays will allow multiple users to be interacting with the UI at the same time, making heavy use of multi-touch.

The built-in keyboard in Windows 7 is plugged into the Surface SDK, such that it shows whenever the focus goes to a SurfaceTextBox.   This is great for most uses … but we want to allow multiple users to be typing simultaneously.  For this reason, we wrote our own software keyboard that we can attach to any (Surface)TextBox using an attached property.  The keyboard shows up below or above (depending on available application real estate) the referenced control and supports any number of keyboards at a time.

The problem is – since a SurfaceTextBox is wired up to automatically show the built-in Windows 7 software keyboard, it ALSO shows automatically (or at least the small thumbnail button to allow the user to bring up the full keyboard) when the SurfaceTextBox gets focus.

I have been hunting all over the web for a couple days on how to disable the built-in Windows 7 keyboard.  I know you can turn it off at the OS level, but our users want to be able to flip to other applications and HAVE the keyboard available to them.  I found all kinds of posts about watching for SurfaceKeyboard events, hiding it immediately upon show, a couple static methods to try, etc.  All to no avail.

Finally I found an MSDN article about disabling the keyboard on a Tablet PC on a per-application basis.  Thought for sure this was not “related enough” to Surface, but gave it a whirl.  It works!

Unfortunately, it’s based on a registry key setting, so it’s not a programmatic solution – we’ll have to add this setting into our installer.

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\TabletTIP\DisableInPlace]
"C:\Program Files\My App\MyApp.exe"="1"

Original MSDN article

Update: here’s a screenshot of the registry with the setting in place.
Image: Disable Keyboard - Registry

Happy keyboarding…

What is RECESS ?

Here at InterKnowlogy, as a Microsoft Gold Partner, we pride ourselves on being able to keep up with the latest and greatest technologies, and to bring that breadth of knowledge and experience to the table for our customers.  As an example, the latest projects we’re working on are based on WPF, Silverlight, Surface, Windows Phone 7, and even iPad development.  As we all know, the pace at which new technologies come out of Microsoft and other industry leaders these days is crazy, so it becomes difficult to keep up. 

At IK, we have a perk we call RECESS

Research (and)
Experimental
Coding (to)
Enhance
Software
Skills

The company gives us some time each week to work on whatever we want – learn a new technology, write an app for a different platform, investigate the feasibility of some new pattern, catch up on new language features, etc.  It’s a great investment that IK makes in us to spend a few hours away from our current project, doing something completely different, and then share that knowledge amongst the rest of the company.  We got the idea from one of our devs working at Microsoft a couple years ago – that team had a similar program.

We don’t always end up with a finished “product”, maybe we just cut some sample code, read some articles, etc. but once in a while, we end up with some very cool stuff.  As an example, some of the actual software we’ve created during RECESS:

  • Surface Craps
  • Surface JukeBox
  • Wish 43
  • Surface Curling
  • Firebrick
  • Atlas (Virtual Earth on Surface)
  • 3D Boxes (Surface physics engine display)
  • Surface PixMatch (child picture matching game)
  • Surface YouTube viewer
  • Blackjack
  • . . .

Anyway, thought the RECESS concept is worth mentioning – I think it’s a very cool “feature” of working here. 

Well, … this afternoon is RECESS, so I have to get busy learning something new…

Surface Craps

Disclaimer:  InterKnowlogy is not in the business of writing gambling or casino games.  This application was only written for research, with no intention of using it in a real gaming situation.

VIDEO

Here at InterKnowlogy, we have a program called RECESS (Research and Experimental Coding to Enhance Software Skills) – where we get to spend Wednesday afternoons working on whatever we want, to further our skill set, maybe in a technology area we don’t touch on our everyday projects.  crapsbasic_61F83FBC

We’ve been writing apps for the Microsoft Surface table for a while, and I decided it would be cool to write a Craps game. One of the main ideas of the Surface table is to encourage multiple people to use an application simultaneously while sitting around the table.  What better way to do that than to place bets, “roll” dice, and win “money”?

Before we get too far, check out the video of the game in action.

Now I’ll get into some of the cool design and implementation aspects of the application.

Tag Recognition

Obviously, you need to place bets to play craps.  At a real craps table, you place bets with your chips on CrapsChipsAndDice_6A87B0D4the table, so in Surface Craps you do the same. We use a stack of chips taped together just so they’re easier to hold, and we use “object tags” stuck onto the bottom of the stack to uniquely identify you as a player.  The Surface has cameras inside the case that recognize the object tag patterns and wake us up in event handlers with information about the tag that was placed.  When your chip stack touches the table in a “bettable area” the bet is recorded, and a visual indication of your bet is added to the table.  Up to 4 players can play at the same time, each having their unique stack of chips and placing bets on the table simultaneously.

Bettable Areas

I came up with a UserControl that I call a BettableArea that allows me to know if a tag (stack of chips) is placed somewhere on the table that allows bets (as opposed to dead space around the table, etc).  This control’s content is a Path that defines the actual region that’s bettable (to allow for funny shapes) and also has 4 properties that are filled with the location where the virtual chips should be placed for each player in that region.  The screenshot below shows the BettableArea controls with their opacity turned up to show them at design time – notice the curved and angled paths used to follow the actual betting zones.

 

CrapsBettableAreas_19F20BA2 A quick aside: on a real craps table, the dealers will place the chips for a player at a spot on a bettable area that’s related to where they are standing around the table.  (if you’re at the right corner of the table, your bets will be at the right corner of the bettable area).  When a bet is placed on my Surface Craps table, the visual chips representing your bet show up at one CrapsPlaceOddsSmall_7DE08B0Fof the 4 spots defined in the BettableArea control depending on which player you are.

Many craps players know that the “Place Odds” bet behind the Pass Line is the best bet in all of Vegas.  So, YES, Surface Craps does support placing odds behind the pass line bet, and even enforces the fact that you can’t do it until a point has been established!

 

 

Ratchet Gesture

CrapsRachetBet_658D70F4After you place your initial bet with your chips, we had to come up with an easy way to change the amount you’re betting.  I came up with something I call the “Ratchet” gesture.  You place your chips back down on the table over the existing virtual chips and I show a couple arrows on each side with the bet amount.  While holding the chips down, you turn them left or right (say as if you’re unscrewing a bolt).  As you turn, the bet amount is adjusted up or down depending on the direction of the turn.

3D Dice

I also used this application as a way to learn WPF 3D.  Cubes are about the easiest object to make since they’re CrapsDiceMidSpin_5C5135B3square, and thus only require 2 triangles on each face.  They material is semi-translucent to be able to see through the dice faces to the back of the opposing face.  I use WPF animations to rotate the dice along 2 of the 3 axis when the user flicks the dice to “roll them”.  The dice spin at a rate consistent with the force of the flick detected by the Surface cameras.

Rules / Payout Engine

I came up with a pretty straight forward architecture to allow me to process bets and payouts after each role.  There is a BetLogicBase abstract class from which I derive a specific bet logic class for each type of bet (pass line, field, hardway, etc).  They all implement the virtual ProcessRollResult( ) method, applying their specific logic for that type of bet, and determine what they should do with the bet they’re attached to: payout (win), remove chips (lose), or nothing.  This design makes it super easy to generically process the bets after each roll.  I just loop through all the BettableAreas and call ProcessRollResult( ) on any bets in that area.

On-Table Help

Instead of On-line help, I came up with “On-Table Help”.  If you’re wondering how the hell to play cCrapsTableHelp_68067CE5raps, or can’t remember what the rules are for a particular bet, you just touch the faint question mark button next to that area, and up pops a ScatterViewItem with the information you’re looking for.  Among other things, it tells whether it’s a single roll bet, or multi-roll, and what the payout table is.

Acrylic Dice

Finally and definitely one of the coolest features of the game are the acrylic dice.  We only just got these dice in the last month, so until then you only play Surface Craps by flicking the virtual dice on the table.  We got these dice that are transparent, and have nearly transparent byte tags on them.  My understanding is that the IR sensitivity of the dots in the stickers on the dice is set so that the Surface cameras will recognize them.  VERY COOL! CrapsAcrylicDice_3B3E3FC5

So I recently went about implementing the ability to roll those physical dice on the table, and have it recognize which face they land on.  I show a visual of the correct face of the dice under each physical die, and process results just as if the user had flicked the virtual dice.

Whew – long winded I know, but I’m super stoked on how this game came out.  Take a look at the video if you haven’t already, and let me know what you think.  Any ideas for other options or functionality in the game?

Thanks to Kevin Kennedy for the graphic design of the UI – he’s one of the InterKnowlogy graphic design studs.  Another thanks to Joe Seymour who helped me with the betting/payout engine.

 

 

Disclaimer:  InterKnowlogy is not in the business of writing gambling or casino games.  This application was only written for research, with no intention of using it in a real gaming situation.