CodeBetter.Com
CodeBetter.Com
RSS 2.0 via Feedburner
           Do you Twitter? Follow us @CodeBetter

Peter's Gekko

public Blog MyNotepad : Imho { }

February 2005 - Posts

  • Exploring stylus input with the Tablet PC API

    When you write with a pen on a tablet PC a lot of things are happening between the moment you move the stylus and the drawing of visible ink on the screen. The tablet PC’s API gives you great control over that. It does separate the stylus input from the actual ink being rendered on the display. In this post I will dive in more detail into the input data. All this code is used in the tablet inspector which runs in your browser (provided you have a tablet (SDK installed)). As the demo is a windows user control it can also be hosted by a WinForm, an installer for (an earlier version of that is) here.

    Stylus input is collected from a tablet device. This device can also be an externally attached one. The API has the Tablets class, its constructor provides an enumeration of all tablet devices found. The Tablet class describes a single tablet. The inspector fills a ComboBox with devices found.

    Tablets tb = new Tablets();
    foreach (Tablet t in tb)
    {
       comboBoxTablets.Items.Add(t.Name);
    }

    Even when you do not have an external tablet attached you will find more than one tablet listed. One is the display device, where the mouse acts as a stylus. It is always present, also on a non tablet PC. The other is the actual digitizer built in the screen of the tablet.

    Every tablet has its properties; these can be listed with the API. The TabletHardwareCapabilities enumeration lists all properties recognized, the Tablet’s class HardwareCapabilities property combines the capabilities supported by the specific tablet.

    Tablets tb = new Tablets();
    Tablet t = tb[comboBoxTablets.SelectedIndex];

    foreach (TabletHardwareCapabilities thc in TabletHardwareCapabilities.GetValues(typeof(TabletHardwareCapabilities)))
    {
       if ((t.HardwareCapabilities & thc) == thc)
          listBoxTablet.Items.Add(thc.ToString());
    }

    The display and the digitizer have quite different properties. The display has CursorMustTouch, the mouse pointer alway touches the display surface. The digitizer lists Integrated and HardProximity. When the stylus is in the proximity of the tablet its movements are also detected. An external tablet will only list HardProximity.

    Stylus input is collected with an InkOverlay object. The constructor of this class is overloaded, some versions take the windows handle of the control to scribble on others take the control itself. When you are going to host the inkcollector in a browser (as the demo does) the choice of the parameter is quite important as it influences the Code Access Security settings of the applet. Choosing a Windows handle will request a level which is higher than most hosting browsers allow. When you choose a control your applet will be accepted by most browsers (provided it is IE 5.5+ running on a tablet :)). I am highly indebted to Julie Lerman pointing this out at Windows AnyWhere.

    private InkOverlay io;

    In the usercontrol’s constructor the overlay is initialized.

    io = new InkOverlay(panel1);

    An inkcollector is an umanaged resource so it has to be explicitly disposed of. In a Winform app you have the Dispose method to hook into but hosting the usercontrol in a webform takes some extra fiddling. A method to dispose the collector is published by the usercontrol

    public void DisposeResources()
    {
       if (io != null)
          io.Dispose();
    }

    This method is called from the script of the webform hosting.

    <html><head>
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
    <title>The online Tablet PC inspector</title>
    <SCRIPT language=jscript>
      // Release inkoverlay resources
            function OnUnload()
            {
                Watcher.DisposeResources();
            }
      </SCRIPT>
    </HEAD>
    <body>
    <OBJECT id=Watcher
    title="You need a (PC with the) tablet PC (API installed) to view this page."
    height="90%" width="100%"
    classid=TabletLib.dll#TabletLib.TabletWatcher  VIEWASTEXT
    ></OBJECT>
    </body></html>

    By default an inkoverlay collects data from all devices, you select a specific input tablet with the inkcollector's SetSingleTabletIntegratedMode method. In the demo checking a checkbox toggles this

    private void checkBox1_CheckedChanged(object sender, System.EventArgs e)
    {
       while (io.CollectingInk);

       io.Enabled = false;
       Tablets tb = new Tablets();
       Tablet t = tb[comboBoxTablets.SelectedIndex];

       if (checkBox1.Checked)
          io.SetSingleTabletIntegratedMode(t);
       else
          io.SetAllTabletsMode(true);

       io.Enabled = true;
    }

    Before manipulating the collector you should wait until it is finished with all pending input; that’s what the Inkcollector’s CollectingInk flag tells you. The loop keeps interrogating the property until it reads false. You cannot change the setting with the collector enabled.

    The actual stylus input data comes in packages. When new packets of data arrive the stylus fires an event. An NewInAirPackets event is fired when the stylus just hovers over the tablet, a NewPackets event is fired when the stylus actually touches the tablet.

    io = new InkOverlay(panel1);

    io.NewInAirPackets+= new InkCollectorNewInAirPacketsEventHandler(MyNewInAirPackets);
    io.NewPackets+= new InkCollectorNewPacketsEventHandler(MyNewPackets);

    SetStyle(ControlStyles.DoubleBuffer, true);

    Two event-handlers now subscribe to the inkcollector. The doublebuffer style prevents display flicker when scribbling. The event-handlers receive data of the stylus in packets. But what is inside these packets ? Well, that’s actually up to you. In theory the digitizer can transmit a lot of different data, like the position of the stylus, the pressure  applied to the tip, the tilt of the pen and a whole lot more. The API has the PacketProperty enumeration which sums up all data which can be collected:

     

    In the real world a digitizer provides only a subset of these. A Tablet object can be interrogated whether it supports a property. To inspect properties I am using a helper class which wraps up the property name and the values found for the property.

    public class PacketPropertyWatch
    {
       public string name;
       public int MinValue;
       public int MaxValue;
       public int CurValue;
    }

    The selected tablet is interrogated for the supported properties. The actual value of the property is a guid. All supported properties are collected in an arraylist

    Tablet t = tb[comboBoxTablets.SelectedIndex];

    // Available packetproperties
    ArrayList desiredProperties = new ArrayList();

    foreach (FieldInfo fi in typeof(PacketProperty).GetFields())
    {
       if (fi.IsStatic && fi.IsPublic)
      {
          Guid g = (Guid) fi.GetValue(fi);
          if (t.IsPacketPropertySupported(g))
          {
             // Add the packet property to the arraylist
             PacketPropertyWatch ppw = new PacketPropertyWatch();
             ppw.name = fi.Name;
             ppw.MinValue = 0;
             ppw.MaxValue = 0;
             ppw.CurValue = 0;
             watchedProps.Add(ppw);

             desiredProperties.Add(g);
          }
       }
    }

    This array of desired properties is now passed to the inkoverlay.

    io.DesiredPacketDescription = (Guid[]) desiredProperties.ToArray(typeof(Guid));

    In this scenario the inkcollector will collect data of all the properties supported by the tablet it is collecting from. It’s up to you to limit the data collected.

    The handlers of the NewPacktes and NewInAirPAckets events receive the actual packet data. Both events have the same signature and can be handled by the same handler.

    private void inspectPackets(int packetCnt, int[] packetData)
    {
       int packetLenght = packetData.GetLength(0);
       int offSet = packetLenght * (packetCnt -1);

       for (int i=0; i< watchedProps.Count; i++)
       {
          int propValue = packetData[offSet + i];
          PacketPropertyWatch ppw = (PacketPropertyWatch) watchedProps[i];

          if (propValue < ppw.MinValue)
             ppw.MinValue = propValue;

          if (propValue > ppw.MaxValue)
             ppw.MaxValue = propValue;

          ppw.CurValue = propValue;

       }
    }

    The packets are actually one huge array of integers. This array is a chain of the values of properties collected. The sampling rate of the digitizer is pretty high, something in the order of 130 samples a second. The event is not fired on each sample What this eventhandler does is take the last packet set of the packets received and iterate it to read the actual values of the properties. In case less properties were in the inkcollector’s DesiredPacketDescriptor less packet data will arrive in the event handler. So you can limit the amount of digitizer data to the data you are really interested in.

    The demo, full source code here, will display package data found on your tablet. A small discussion of packet data found so far:

    • X The X position of the stylus. This is in the digitizer’s coordinates, which is far more detailed than screen-pixels.
    • Y The Y position of the stylus.
    • PacketStatus. Used by the internal part of the API.
    • TimerTick The amount of time passed since the stroke was started.
    • NormalPressure The pressure applied on the stylus tip. Usually varies between 0 and 255, can vary between 0 and 16 and can have a range up to 1024 on luxury tablets
    • XTiltOrientation. The property is claimed to be supported by (afaik) Acer, Motion and Wacom. But (afaik) the property value always returns 0.
    • YTiltOrientation. Like Xtiltorientation

    You can test your tablet online over here. In case it supports more properties than this you do have a luxury tablet. The API reserves a lot of room for future hardware improvements, right now it is already incredible what you can do with the working properties. I wonder what ArtRage would feel like on a lux tablet.

    This part of the API only covers collecting data from the stylus. The inkcollector object used to collect these will render Ink on the screen using the values found. The position for the location, the pressure for line thickness and a Bezier smoothing algorithm to make the strokes flow. But there are more places you can intercept what is going on. Not every movement of the stylus has to be translated to a visible stroke, in a next post I will take a closer look at the API support of gestures. And not every stroke has to be drawn on the default location in the default line-thickness. In more later posts I will dive in the real-time stylus where you can completely separate collecting stylus data and rendering ink.

     

  • Blogfeed Arcs of Fire

    Yesterdays remarks on the online info on the Tablet game SDK did ring some bells. Their blogfeed has three new post. Good, do subscribe. But I still have two remarks.
    • The arcs of fire signature directs you to about:blank. The website is here.
    • One post recomends the documentation. No link (hey guys, that's what browsers are for :)). The docs are here.

    The presentatation may have its rough edges but the content is absolutely worthwile.

  • My .NET articles on line

    My online articles are scattered over a diversity of sites. Some of these lilke to move their stuff around, links to the articles are broken before you know it. I maintain an index to my online .net material and will keep this up to date. The link is alsso on my blog home-page. Please yell if something has disappeared again.

    Happy reading.

  • Tablet game SDK, not just for fun

    A tablet PC is also quit a nice platform for games. Imagine using a pen to pull a specific handle in your flightsim cockpit or imagine using a pen to draw a circle around the neighbourhood you want your Sim family to pick a house. In every game I can imagine a good use of the stylus. The “Windows XP Tablet PC edition” (anybody know an easier moniker ?) does even include an ink-specific game : InkBall. Which is installed on every tablet but it took me seeing someone play it at Windows Anywhere to get aware of its existence. It is a nicely animated game in which colored balls bounce against pen strokes. Which can be pretty difficult, the risk is finding out what tablet RSI feels like. Change often, imho a mix of keyboard, pen and mouse make you less sensitive to RSI.

    Anyway, the beta of the tablet game SDK is now released. It comes with Arcs of Fire, a demo game. Altough the game uses DirectX (it even requires the feb. 2005 update) don’t expect anything visual spectacular. It’s a classic 2–d game where you hurl objects (in this case artilery shells, on the Atari it was a gorrila throwing bananas) at your opponent. You shoot the shell with the stylus. The angle of the stroke determines the angle under which is fired, the speed drawing the stroke determine the shell’s velocity.

    The demo focuses on animating the game. See the shell fly through the air and watch the explosion when it hits something. The demo covers most parts of the Microsoft.Ink.GameSDK dll. For which no source code is included. Despite its name this namespace has a lot of classes which are very handy for any tablet (or even mobile) app. To mention some:

    • The Power class wraps up battery life
    • The Rotation class wraps up screen rotation
    • The Stylus class leverages the pen stylus as programming target. In the existing API you can get very detailed data from the pen. I did some investigation of these in the tablet explorer (background article is still in the making). With the Stylus class you access the pen on a higher level. It has properties like CurrentPosition, IsStylusDown and LastDownPosition

    Expect some hurdles for the classes to work. Fi: the demo game only works in landscape mode, no rotation yet.

    Worth mentioning is the ArcsOfFire blogfeed. No link, as it’s not really worth subscribing. Is this is the group Scoble meant ? No content, mainly messages to go to the website, and many a link present points to things like about:blank. The website is Ok but most of the info is available as downloadable Word documents. Also the doc’s of the gameSDK are a downloadable doc. It’s content is quite Ok, a story which mixes the history of the tablet with the history of artillery games. It contains some quite nostalgic illustrations. But the layout just doesn’t look right. Oh my hands and pen are itching to do some work there. A little Frontpaging (or whatever other tool) could make this great content so much more accesible.

  • Nice security feature of ASP.NET textbox

    The AspNET textbox has a TextMode property which can be single-line, multi-line or password. The contents of a textbox can be in the markup as well, it is between the textbox tags. Take this :

             <asp:TextBox id="TextBoxUserName" runat="server" Width="140px">ThisIsMyUserName</asp:TextBox><BR>
             <asp:TextBox id="TextBoxPassWord" runat="server" TextMode="Password" Width="140px">ThisIsMyPassWord</asp:TextBox></P>

    The good thing is that the contents of a password textbox cannnot be set from markup. In the example the password is still empty. I consider it good because it prevents tampering with a password from markup (The aspx file). The passsword can be set from code-behind

    TextBoxPassWord.Text = "ThisMyRealPassword";

    A line to delete before rolling out the app.

  • The cutest Windows Anywhere goodies

    The cutest goodie I took home from Windows Anywhere is the Channel 9 guy I caught.

    Worth mentioning as well is the conference pen. It's a 4 stylus thing, the ultimate goodie when I was a kid (born '57). The special thing about this one is the grey stylus. It's pure plastic, no ink. Perfect for a Pocket PC. Will next year's model include a magnetic tip for a tablet ?

  • Small Wacom tablets: the good, the bad and the integrated

    Recently I had been playing with a small external Wacom Volito tablet. I wasn't too pleased with it, mainly because its build was too sloppy. As it's rubber feet were slipping away all the time it wasn't possible to use it with any accuracy. On the Windows Anywhere conference they handed out Wacom Saphire tablets as a reward for trying a tablet PC in the hands on lab. That tablet has the same digitizer surface (4 by 5 inch) but is far more robust. It's heavier and has 4 rubber feet instead of just 2. The result is heaven compared to hell: this one is stable and really works. As a bonus the pen has an extra (eraser) stylus on its back end.

    Wacom also makes a lot of the digitizers built into tablet PC's. As an experiment I attached both external tablets to my tablet PC, fired up the tablet analyzer and scribbled away. The API reports three tablets: the display, an internal and an external one. It could not distinguish the two external ones. Both claim to report X and Y pen-tilt but alway return 0. Without any drivers installed the external tablets are mouse substitutions, with the saphire driver installed pen-pressure is reported from both external tablets. You cannot install the Volito driver and the Saphire driver at the same time. The pen of the Volito works slightly on the tablet PC, the saphire pen works only on the saphire.

    What did I learn from this ? Wacom makes a lot of tablets, just one of them (the Volito) spoils their good name. The tablets are indistinguishable by the software, except for some API reported properties like integrated. The three tablet pens are not compatible on the hardware level.

    Chaos as usual but I'm happy with my hardware upgrade.

     

  • Real geeks (don't) code WideScreen ;)

    As this seems to be pretty popular, another shot at what I like about a widescreen

     

    its 1200px high

  • Hosting .net winforms in IE (the tabletinspector goes online)

    Thanks to Julia Lerman's talk at Windows Anywhere I've got my tabletinspector online.

    The original application was a .net winforms thing. It's a form containing one big windows-usercontrol. The user control itself is in a dll. Internet Explorer can host .net usercontrols provided the .net framework is installed on the client machine. The containing page does not have to be an ASP.NET page, any html page will do. In fact this inspector is served by my providers's Unix box.

    The usercontrol is specified in a pair of <Object> tags.

    <OBJECT id=Watcher
    title="You need a (PC with the) tablet PC (API installed) to view this page."
    height=
    "90%" width="100%"
    classid=
    TabletLib.dll#TabletLib.TabletWatcher VIEWASTEXT
    </OBJECT>

    The classId of the object points to the TabletLib.dll, which houses the usercontrol. The name of the dll is followed by a # and the qualified name of the usercontrol class: TabletLib.TabletWatcher. The browser expects the dll in the same directory as the webpage on the server. It does not have to be there, this makes up a valid object as well:

    classid=http://MyAppSerever/TabletStuff/TabletLib.dll#TabletLib.TabletWatcher

    Now the browser will look for the dll on quite a different server. For this to work right you will hit some security issues. The trust level of the other server will be different than that of the site you're visiting and as a result the runtime might refuse to load the dll.

    Note the height and width properties of the object. These are relative. As the controls in the usercontrol have their anchors set to multiple borders they do size with the browser.

    The result can be found here. If you have a tablet go there and check out the capabilities of its digitizers.

  • On line doodling with a tablet PC

    In her talk at Windows Anywhere Julia Lerman showed a tablet doodling app running inside IE. It's online here.

    Doodle away !

  • Future directions for the Tablet PC OS

    One of the core parts of the tablets's OS, Windows XP tablet PC edition, is the handwriting recognition. At this moment it takes any handwriting as is and translates this using a language specific recognizer pack. The number of languages supported is limited to English, Spanish, French, German, Italian, Japanese, Chines and Korean. The good news is that Microsoft is working on a Dutch recognizer. I don't hope the guy who said this didn't do that just to please me; being Dutch :) They are working on another one as well. I'm sorry which language slipped from my mind; I was to excited about the foresight to see my "hanepoten" turn into real text.

    A structural improvement will be that the future versions of the recognizers can be personalized. You can teach it how you write your letters. Rumour has it that this is because the current recognizers don't understand the way Bill Gates scribbles a "4". My tablet doesn't understand the way I write an "l".

    The future of Windows will be Longhorn. Shawn van Ness, who did some advanced presentations at Windows Anywhere just announced in his blog he's joining MS to work on  integrating the tablet into Avalon and WinFx.

  • Widescreen monitor for development ? Love it !

    As a response to a post by Kimberly Trip Sahil questioned the usablity of a widescreen monitor. Darell suggest working with a dual monitor is a better alternative. Untill recently I did the latter, untill I got myself a 1920*1200 screen. First I still used the old monitor as a secondary one to that, but I gave up on that. Didn't give it any looks any longer. Totally agree with Paul, imho nothing beats a widescreen, especially for development. Why ? Well a picture says more than a thousand words:

  • Windows Anywhere, what was it like ?

    After couple of thousands of miles and some 10 time-zones to the west I'm back from the Windows Anywhere conference cluster. Everything is up and running again and as a starting post of the many things learned I've put up a gallery with some snapshots of the events.

    The main event was VSlive which hosted a couple of other conferences. All held in the same building, the Moscone convention center. On the outside this building looks nice, but I was not that pleased by the interior. Very high rooms, all in dull colors, disturbing aircos and sometimes the sessions were more or less in the hallway. The atmosphere generated by the visitors and speakers was pretty laid back. It was good to meet fellow blogger Blaire Jennings. Just like me he was exploring the world of the tablet PC. Lots of tablets around, the most inspiring talk was by no-one less than Charles Petzold. Amongst the hosted conferences were the .NET day and the Indigo day. On the latter Yasser Shohoud gave a great keynote presenting an overview of Indigo. 

    The keynote hall had the best atmosphere. It was there the Midnight Madness party was held. As a pre-launch the Visual Studio Tools for Office team navigated a blimp (radio controlled balloon) through the hall. Which was in danger of all t-shirts and Channel-9 guys being shot into the audience, all to willing to catch whatever came flying by. Best thrower was Billy Hollis, inspired by the superbowl and his own hilaric preaching on the dangers of code addiction his t-shirts made it almost to the other end of the hall.

  • Windows Anywhere / VS-Live

    Well, that was it. The Windows Anywhere / VS-Live conference is over. It was nice, although the conferences missed the vibrance of something like the PDC. But the Tablet was very much present and a great success. Never seen so many of them together. Yes, it has a great future. Heard a lot of things I'll transform into blog-posts in the coming week. But first of all I'm going to be a San Fransisco tourist for a day and take a long journey home.
  • Oracle rock(s)

    Maybe Vs  does a strange job when you drop a sql datatable on a form. But what Oracle is showing in the Vs-live keynote is even worse. The grid binds straight to a table of the Oracle data-adapter. Not even a dataset inbetween. The Sql server makes a monolithic app. But this is pure granite.
    Posted Feb 09 2005, 03:55 PM by pvanooijen with no comments
    Filed under:
More Posts Next page »

Our Sponsors

Free Tech Publications

This Blog

Syndication

News