TouchUI - GDI (part 4)

by Chris 30. October 2009 13:57

The technology that makes the main requirement for the TouchUI framework (see part 3) come true is GDI, which also has a managed wrapper. The main player in that API is the Graphics class, and here are a couple of its methods:

  • Clear()
  • DrawEllipse()
  • DrawImage()
  • DrawLine()
  • DrawPolygon()
  • DrawRectangle()
  • DrawString()
  • FillEllipse()
  • FillPolygon()
  • FillRectangle()
  • MeasureString()

This is actually most of its methods, but still this is all we need to create any graphics that we want. Also, since it's not that extensive, it's not too difficult to learn GDI. Here's some code:

Graphics g;
...
Pen bluePen =
new Pen(Color.Blue, 3); // 3 pixels thick
g.DrawRectangle(bluePen, 0, 0, 50, 50); // x, y, width, height
Pen redPen = new Pen(Color.Red, 2);
g.DrawEllipse(redPen, 0, 50, 80, 60);

Let's not bother with how the graphics instance (g) is created, and assume it is, then the result would look something like this:

image

That's what I like with GDI: get whatever graphics you want with just a few lines of code! In the coming posts in this series I will not explain the details about the different GDI methods used, but there are many good resources to find on the Web if you want to learn more about GDI.

GDI is actually the way that the core operating system (Windows CE) is drawing things to the screen, and if you are interested in knowing more about how this technology performs on a device, you should check out the article Native vs. Managed Code: GDI Performance by Chris Tacke. As you will see, there are some performance gain to be made by calling the native APIs instead of using the managed wrappers. But since I had a goal of pure managed code for the TouchUI framework, I will stick with the managed wrappers in this series.

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Chris | Compact Framework | Windows Mobile | User Interface

Comments

Add comment


(Will show your Gravatar icon)  

  Country flag

biuquote
  • Comment
  • Preview
Loading



Powered by BlogEngine.NET 1.4.5.0
Theme by Mads Kristensen