Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Into the Future : Page 3

Mobile PCs and Tablet PCs are a growing market segment and are of the utmost strategic importance to Microsoft. New developments in hardware, software, developer tools, and SDKs give developers many new opportunities.


advertisement
The Windows Presentation Foundation
With WinFX, Microsoft introduces a successor to the Win32 API. The public API surface of WinFX is completely managed (written in .NET) and includes technologies such as the Windows Presentation Foundation (WPF, formerly known as Avalon), Windows Communication Foundation (WCF, formerly known as Indigo), and the Windows Workflow Foundation (WWF), among others. Tablet PC-related functionality focuses almost exclusively on user interfaces. For this reason, WPF is most important for our purposes. WPF was originally conceived as a display technology specific to Windows Vista. However, based on user feedback, Microsoft has made the decision to make WinFX (including WPF) available on Windows XP as well. This includes all the Ink features discussed in this article, such as the InkCanvas control.

In the past, all versions of Windows (including Windows XP), created almost all graphical output using a technology known as GDI (Graphics Device Interface). Although this technology has served us well for a long time, it has its problems. GDI is completely pixel-based. Everything drawn on the screen is created by pixel-based drawing operations that take place on the PC's main CPU. Unfortunately, pixel-based drawings do not scale well, which means that pixel-based output can not easily adjust to various display resolutions. Also, modern displays have a lot of pixels, which puts a significant burden on the CPU, while advanced graphics accelerator cards that are present in almost all computers these days often lie dormant.

Some of the downsides of GDI become apparent in applications that require high-performance graphics output, such as games or multi-media applications (videos). For this reason, these kinds of applications do not use GDI; they use DirectX, a high-performance interface capable of accessing graphics hardware directly, including the utilization of graphics accelerators known as GPUs (Graphics Processing Units), which are secondary processors optimized towards processing graphics.

The problem with using both approaches is that they do not mix very well. The issue is most easily demonstrated with videos on Web pages. Whenever a Web page with a video is viewed in a browser and the browser window is moved, the video lags behind, although the rest of the window moves very smoothly. This is a result of the combination of two rather different technologies. For Tablet PC developers, the effects also become obvious in the support for Inking. It is possible to collect and render Ink in GDI and it is also possible to collect and render Ink in DirectX. However, it is very difficult to Ink annotate a video and then write beyond the edge of the video and continue the annotation on a GDI-rendered area of the screen.

WPF takes a completely different approach. From the ground up, it was built to be a unified, high-performance graphics API. All output in WPF is based on vector graphics instead of pixels. This has the advantage of resolution independence. All graphical output can be resized or transformed in other ways at a very high level of quality. WPF also utilizes graphics hardware if it is present, making all the CPU power available for other processing.

WPF doesn't draw screen output in the same way GDI or even DirectX did; instead, it "composes" output. Typical WPF user interfaces are composed of windows, buttons, textboxes, lines, and other WPF controls, such as videos. These controls are themselves composed of primitives defined as vectors (such as lines). The composition engine allows for great flexibility. For instance, a button control can itself be composed of a text label and a video. The same video can be used to compose the contents of a drop-down list, a menu, or any other WPF control.

What is particularly important for Tablet PC developers is that Ink is a native component of WPF. Therefore, every WPF application can support Ink natively, without the need for any additional components. Of course, because Ink is based on vectors, it is a perfect match for WPF's composition engine and can be drawn very quickly at a high level of quality.

Before you look at your first WPF Ink example, I should discuss one more technology introduced by WinFX: XAML.

XAML is a declarative language that supplements the conventional programmatic languages. In programmatic languages, you instantiate objects, set properties, and call methods in a language such as C# or Visual Basic .NET. In a declarative environment, you use some sort of markup language (XML in this case) to specify the desired result. For instance, the following could be a programmatic approach for creating WinForms UI (as it is found in the designer-generated code region):

Button btn1 = new Button(); btn1.Top = 100; Form.Controls.Add(btn1);

In XAML, the same idea could be expressed as follows:

<Button Name="btn1" Top="100"/>

In many cases, the declarative approach is simpler and more efficient, because you only worry about the "what" and not the "how." In the programmatic example, the button object had to be instantiated and the developer had to know whether or not the object received constructor parameters. The developer also had to know to add the button to the form's Controls collection for the form to become functional. In the declarative approach, all of this is left up to the XAML compiler and the developer is concerned only with the desired outcome.

XAML is a great addition to the developer's toolbox, with advantages so compelling that practically all WPF examples are based on it. However, it is important to point out that XAML is entirely optional in WinFX, and developers are free to use the more conventional programmatic approach if they so desire.

XAML, although entirely optional, is so convenient that practically all WPF examples are written in this language.
As a simple XAML example, a window containing a few controls can be defined in the following fashion:



<Window x:Class="_2_LayoutExamples.Window3" xmlns = http://schemas.microsoft.com/winfx/avalon/2005 xmlns:x = http://schemas.microsoft.com/winfx/xaml/2005 Text="_2_LayoutExamples" > <Canvas Width="500" Height="500"> <Rectangle Width="100" Height="100" Canvas.Top="100" Canvas.Left="100" Fill="blue"/> <Rectangle Width="100" Height="100" Canvas.Top="150" Canvas.Left="150" Fill="yellow"/> <Rectangle Width="100" Height="100" Canvas.Top="200" Canvas.Left="200" Fill="green"/> <Rectangle Width="100" Height="100" Canvas.Top="300" Canvas.Left="200" Fill="green"/>

 
Figure 9. Simple XAML Window: A simple XAML window showing rectangles positioned on a Canvas.
<Rectangle Width="100" Height="100" Canvas.Top="350" Canvas.Left="150" Fill="yellow"/> <Rectangle Width="100" Height="100" Canvas.Top="400" Canvas.Left="100" Fill="blue"/> </Canvas> </Window>
The result of this is shown in Figure 9. This code may appear a bit confusing for people unfamiliar with XAML or WPF, but it is actually pretty straightforward. The root tag defines a window as well as some namespaces used by XAML. The window contains a canvas element/control, which means that you want to create a drawing area in your window that is 500x500 pixels—in "logical" pixels (1/96th of an inch)—that you can place other controls on (or in). The nature of this control is such that you can position other controls (rectangles in this case, but it could be anything) within it, providing absolute positions and dimensions.

At this point, you may be wondering why you needed a Canvas, rather than just positioning other controls on the window. The reason is that WPF supports many different ways of positioning controls. The Canvas that contains controls with absolute positions and dimensions is only one example (this is also known as grid layout). Another example is flow layout. Within a flow layout control, all other elements are positioned left-to-right and top-to-bottom, similar to Web pages.

What does it take to add Ink functionality to this example? Not a lot! All you need to do is add an InkCanvas object to your composition (or replace the regular Canvas with an InkCanvas). The following example shows a modified version that supports Ink:

<Window x:Class="_2_LayoutExamples.Window3" xmlns = http://schemas.microsoft.com/winfx/avalon/2005 xmlns:x = http://schemas.microsoft.com/winfx/xaml/2005 Text="_2_LayoutExamples" > <Grid> <InkCanvas Width="500" Height="500"> <Rectangle Width="100" Height="100" Canvas.Top="100" Canvas.Left="100" Fill="blue"/> <Rectangle Width="100" Height="100" Canvas.Top="150" Canvas.Left="150" Fill="yellow"/> <Rectangle Width="100" Height="100" Canvas.Top="200" Canvas.Left="200" Fill="green"/>

 
Figure 10. Modified XAML: A modified version of the simple XAML window.
<Rectangle Width="100" Height="100" Canvas.Top="300" Canvas.Left="200" Fill="green"/> <Rectangle Width="100" Height="100" Canvas.Top="350" Canvas.Left="150" Fill="yellow"/> <Rectangle Width="100" Height="100" Canvas.Top="400" Canvas.Left="100" Fill="blue"/> </InkCanvas> </Grid> </Window>
The result can be seen in Figure 10.

It is important to note that although it is possible to write XAML by hand, most people will be using visual designers, such as the recently announced Sparkle designer that is part of Microsoft's Expression series of products. Because Ink controls are part of the native WPF control set, interactive designers like Sparkle support Ink controls (such as the InkCanvas) natively.

Pushing Forward
Microsoft is pushing very hard on Tablet PC and Mobile PC technologies as the market for these technologies gains importance. For users, this means new and better devices and software, and new ways to interact with them. For developers, the push provides lots of opportunities. Because the new versions of the Tablet PC SDKs are more sophisticated, in many ways they are easier to use, and, in the case of WinFX and Windows Vista, they are more integrated in all versions of the platform.

To sum it all up: the future for Tablet PC and Mobile PC developers and users looks very bright.



Markus Egger is president of EPS Software Corporation, located in Houston, Texas. He is also the founder of EPS Software Austria, located in Salzburg. He concentrates on consulting in COM-based, object-oriented development and Internet applications. He is an international author and speaker, and is co-publisher of Component Developer Magazine. He is also the author of "Advanced Object-Oriented Programming with Visual FoxPro," from Hentzenwerke Publishing. For the past several years, Markus has received the Microsoft MVP award. Several applications he has worked on (mostly as project manager) have received Microsoft Excellence Award nominations. He is the author of several tools, such as GenRepoX (public domain), the Fox Extension Classes, and Visual WebBuilder.
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date