TouchUI - Controls (part 8)

by Chris 28. November 2009 14:02

As I showed in a previous part of this series, I don't use any controls for the simpler dialog painting (i.e. for heading, line, etc). For more advanced painting and logic, the notion of controls is welcome, and is obviously a part of the TouchUI framework.

I started off in the traditional way, building WinForm controls, but soon realized that I really don't like all the overhead that comes with that. Also, I wanted the central control that is not natural when each control receive their own (mouse) events. So I ended up creating something new from scratch, and the root TouchUI control ended up being defined like this:

public class Control
{
   
public Rectangle Rectangle { get; set; }
   
public int ScreenFactor { get; set; }
   
public Color BackColor { get; set; }

    public virtual void Paint(Graphics g) { }
   
public virtual void MouseDown(Point p) { }
   
public virtual void MouseMove(Point p) { }
   
public virtual void MouseUp(Point p) { }
   
public virtual void Resize(Rectangle r) { }
   
public virtual void KeyDown(KeyEventArgs e) { }
   
public virtual void KeyUp(KeyEventArgs e) { }
}

Note that a rectangle is used for placement, and the important screen factor to handle painting on high-res devices. Also note how each event is actually a plain method reversing the "event bubbling" to push the "events" down the control hierarchy.

The pain is that each level explicitly need to forward the calls, but the gain is that none of the controls need to be aware of any events happening in the system. The end result is a few more calls and a minimum of overhead.

Currently rated 4.3 by 3 people

  • Currently 4.333333/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