Thursday, September 24, 2009

Failure Doesn't Preclude Success

This is a brilliant video on how failure doesn't preclude future success:



Tuesday, September 22, 2009

Touch Demo Part I

Over the next few posts I am going to walk you through building one of the touch demos I used in my CodeRage 4 Session. This demo demonstrates using Direct2D and the WM_TOUCH message. Before we get started here is a brief explanation of these two technologies.

Since Windows Vista GDI has become a legacy drawing API supported with software rendering on top of Direct3D. Direct3D is great but it is very raw. This is where Direct2D shines for applications. Direct2D has all the performance benefits of Direct3D and adds support for bitmaps and text and support for GDI Interop all with a much simpler API. And Delphi 2010 has made it even simpler by wrapping it up with a TDirect2DCanvas that is very similar to TCanvas. Direct2D supports remote rendering through Remote Desktop which is very cool.

WM_TOUCH is the raw multi-touch message that provides various states of contact with the input digitizer for hot sizzling touch applications.

Now that we got that out of the way, create yourself a VCL Application. We want to start painting with Direct2D so add Direct2D and D2D1 to the uses and a TDirect2DCanvas property to your form like this:


private
FCanvas: TDirect2DCanvas;
...
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;

property Canvas: TDirect2DCanvas read FCanvas
write FCanvas;
end;
...
constructor TTouchForm.Create(AOwner: TComponent);
begin
inherited;
FCanvas := TDirect2DCanvas.Create(Handle);
end;

destructor TTouchForm.Destroy;
begin
FCanvas.Free;
inherited;
end;

This creates a Direct2D surface (TDirect2DCanvas) that we can draw to instead of the traditional GDI surface (TCanvas).

Depending on the type of application you build you may experience some flicker. To avoid this handle the message WM_ERASEBKGND and returns true.

procedure TTouchForm.WMEraseBkgnd(
var Message: TWMEraseBkgnd);
begin
Message.Result := 1;
end;

Next override Paint and just draw a line:

procedure TTouchForm.Paint;
begin
Canvas.BeginDraw;
try
Canvas.Pen.Color := clRed;
Canvas.MoveTo(10, 10);
Canvas.LineTo(40, 40);
finally
Canvas.EndDraw;
end;
end;

If you run your application at this point and resize the form you will noticed that the line changes size. This is because the view port is resizing to scale to the window and your line will do the same. To prevent this override the Resize method and add the following:

procedure TTouchForm.Resize;
var
HwndTarget: ID2D1HwndRenderTarget;
begin
inherited;
if Supports(Canvas.RenderTarget,
ID2D1HwndRenderTarget, HwndTarget) then
HwndTarget.Resize(D2D1SizeU(ClientWidth, ClientHeight));
Invalidate;
end;

Now you have a form that renders everything drawn to the Canvas through a Direct2D surface.

UPDATE: Added Invalidate to Resize because when resizing the window larger it will force a redraw but smaller will not because typically a redraw isn't required.

Delphi 2010 - Touch and Pen added to TShiftState

While we were researching adding Touch and Gesturing to VCL we quickly realized it was important to detect what type of input produced the mouse messages. So we introduced some new elements to TShiftState: ssTouch and ssPen:


TShiftState = set of (ssShift, ssAlt, ssCtrl,
ssLeft, ssRight, ssMiddle, ssDouble, ssTouch, ssPen);

One of the key reasons this is so important is when handling WM_TOUCH messages the mouse messages are also fired. Chances are you only want to handle one of them. On a non-touch machine you want to handle the mouse. So this allows input to be filtered and handled independently.

Wednesday, September 16, 2009

September Photo of the Month



This is a photo of Cottonwood Lake in Inyo National Forest. This photo is a panorama stitched from 14 photos! And one of the most beautiful mornings I've ever had the pleasure to see.

Tuesday, September 15, 2009

Interactive Gestures 101

As promised at my CodeRage 4 session I will be blogging about Gestures and the Touch feature of Delphi 2010. So here is a quick set of steps to use interactive gestures. It will require a multi-touch system such as I described here (the mouse will not work here) and some context by watching my CodeRage 4 session from here.

1. File | New VCL Application
2. Drop a TPanel on your form (there is a known bug using interactive gestures on the form)
3. Select Panel1 and expand the Touch property
4. Check igoPanSinglerFingerHorizontal, and check igPan. I also like to turn off toPressandHold
5. Go to events and add the following code to the OnGesture event:


if EventInfo.GestureID = igiPan then
Caption := IntToStr(EventInfo.Location.X);

Now run the application and move your finger left and right on the panel.

Note: Interactive Gestures don't require a TGestureManage. Only Gestures require the Gesture Manager.

Update: Fixed the code and added links for touch hardware and my CodeRage 4 session.

Wednesday, September 2, 2009

CodeRage 4



Register for CodeRage4 and come check out the sessions. It's all free so why not, it should be a lot of fun.

I'll be at three talks answering questions:

Building Awesome Touch Enabled Applications by Chris Bensen
Tuesday, September 8, 2009 -- 11:00am - 11:45am PDT
Wednesday, September 9, 2009 -- 9:00am - 9:45am PDT

Hands-On: Gestures in the VCL by Seppy Bloom
Tuesday, September 8, 2009 -- 4:00pm - 4:45pm PDT

What's New in the VCL *
Tuesday, September 8, 2009 -- 3:00pm - 3:45pm PDT
Thursday, September 10, 2009 -- 8:00am - 8:45am PDT (I won't be here because I'll be on vacation!)

Thursday, August 20, 2009

RAD Studio 2010 - SOAP 1.2

Chris White here. This cycle around I have moved from working on the product's many areas that make up the IDE's Help experience to something that has been brand new to me, SOAP.

This posed quite a few challenges for me, one being I knew nothing about SOAP. So after familiarizing myself with SOAP, I started working on the largest feature request in the SOAP area, upgrading our SOAP client support to SOAP 1.2. So, I flew headlong into learning the differences between the specs for SOAP 1.1 and 1.2. With the new SOAP 1.2 client support, our ability to communicate with other SOAP Web Services has greatly increased.

Also since it had been a while, I gave the WSDL Importer Wizard a face lift. I simplified the UI greatly. There are only 3 dialogs (4 if you don't have a project open), all of which are in succession; as well as moved it to an easier to get to location (Component -> Import WSDL...). One nice thing about moving it to the Component menu, you can now import a WSDL without a project open. Hopefully this will be as useful to users as it has been to me; creating a project just to look at a WSDL got tiresome.









WSDLImp.exe also got sync'd up with the IDE's WSDL Importer Wizard. So now you can do everything with the commandline as you can with the IDE.

Monday, August 17, 2009

Touch Hardware

One of the first questions people ask about multi-touch is what hardware to get.

Everything is supported just at different levels. First you have touch screens that emulate the mouse such as most Point-of-Sale monitors. We have a Dell POS and a Planar PT 19. These are only good for big buttons. Any sort of dragging your finger across the screen is lost by the device/driver. The Planar doesn't loose the mouse as bad as the Dell.

Then you have the old school tablet laptops. These add pen and sometimes support touch with the finger as well. The pen resolution is equal to or better than the mouse. The finger with these older systems is an afterthought. Lenovo IBM X61 is an example of such a system.

Next you have all-in-one systems such as the Asus EeeTop which has better drivers/hardware than the Point-of-Sale monitors but they are still just a touch screen mouse. I.E. push the monitor with your finger and you get a left mouse click. The Asus has a pretty decent touch screen but still only supports one touch point and it is just emulating the mouse. The processor on the Asus is really slow.

Now enters multi-touch which only Windows 7 really supports. Some Vista systems support multi-touch but just go with Windows 7, you'll be much happier.

Building on the tablet there are currently two shipping multi-touch laptops. One by Dell and one by HP. These make touch a forethought and add multi-touch. The HP supports 2 touch points and with an updated driver 4. The Dell supports 10 touch points. They are the exact same display so it must be the driver or other components that allow the extra touch points on the Dell. A Dell is currently sitting on my desk and it is the nicest of the systems. It feels like a laptop that I would buy for myself. The Dell is priced a bit high but it is a nice slimline laptop. The HP feels a bit cheap and has some flowery patterns on it.

Lastly you have the all-in-one multi-touch systems such as the HP TouchSmart which features a large display and two touch points. We have purchased two batches of these. The first batch is pretty bad. I'm pretty sure these are the ones currently selling on Woot. The second batch is a lot better but the Dell and HP laptops I mentioned above are better. Update: If you buy one of these be sure to get the NVIDIA graphics card.

Thursday, August 13, 2009

Delphi 2010 - New Units

A lot of header translations and new units have been added. Here are just a few that are interesting:

Wincodec.pas
Enables TWICImage. Support for Tiff, CR2 or NEF anyone?

Cor.pas
.NET unmanaged compiler API. Always fun to crack open Assemblies from native code.

Direct3D.pas, D3DX9.pas, D2D1.pas
DirectX header translations.

Direct2D.pas
TDirect2DCanvas. Get to Direct2D using the same TCanvas methods you know and love.

Manipulations.pas
The inertia manipulators. Great for spinning and throwing things around your screen.

Gestures.pas, GestureMgr.pas, GestureCtrls.pas
Hot gesturing goodness.

Keyboard.pas, KeyboardTypes.pas
TTouchKeyboard for all your touchscreen input needs.

IOUtils.pas
A serious addition to the RTL with TDirectory, TPath, and TFile.

Update: I forgot one RTTI.pas
For some very cool runtime stuff.

Wednesday, August 12, 2009

RAD Studio 2010 - Gestures and Multi-Touch

One of the most exciting features in RAD Studio 2010 is Gestures and Multi-Touch (or what I like to call Interactive Gestures). I can't really show much here because it requires video, but if you've seen the videos or my Delphi Live! talk then you've seen some of what can be done.



Gestures takes full advantage of synthetic properties so you don't see much in the Object Inspector until a GestureManager is assigned. But Interactive Gestures and Tablet Options can be fully utilized without any setup, just check a few check boxes and add some code to the OnGesture event.

Gestures of all flavors can be added per control but different flavors of gestures are mutually exclusive. So you can have a panel with the Gestures and another panel with Interactive Gestures. It's pretty slick.

RAD Studio 2010 - Touch Keyboard



The Touch Keyboard (TTouchKeyboard) is a new component designed specifically for touch systems. It supports a pile of languages and multi-touch. You can see the multi-touch in action in the screen shot above where I was holding down shift and pressing G. The Touch Keyboard is supported on Windows 2000, XP, Vista and Windows 7, but only Windows 7 gets multi-touch.

The Touch Keyboard is designed to be embedded in your applications where you need input from the user. Notice there is no Windows key. After much thought we decided to take a different approach to the Touch Keyboard than Microsoft did with their on screen keyboard. Our focus was on touch systems without a physical keyboard, hence the name, where Microsoft emulated the hardware keyboard.

A lot of thought was given to the colors and the font used. Touch systems are probably more likely to be used in harsh light so there needed to be a lot of contrast between the keys and the background.

Tuesday, August 11, 2009

RAD Studio 2010 - Touch Preview Video

Watch the Touch and Gesturing preview video where David I and I did some serious acting. And then there was some serious editing by someone that isn't David I.



Update: Here is a Japanese version that was translated before the editing:



For those interested the songs used in the video are "I Touch Myself by Divinyls" and "Touch Me by The Doors". You can listen or buy them here (I wish Amazon would just let me put a little play button so you didn't have to go to their website):