The basics of Silvermoon

Silvermoon is a UI framework for Windows Mobile 6.x to build hardware accelerated user interfaces with OpenGL ES 1.1 as kernel. When I started development, I planned to make Silvermoon independent from the hardware layer, so that the OpenGL rendering engine could easily be replaced by ActiveX. But since development progressed, I recognized that this abstraction leads to several restrictions and so from beta 2 to beta 3 I dropped this feature completely.

Silvermoon has currently no design time supports. This is because Silvermoon is not a windows form application. As for Silverlight, a separate designer is required, but for now it doesn’t exist yet. The name “Silvermoon” is a derivation from “Silverlight” and “Moonlight” and in fact, I was orientating on Silverlight to design Silvermoon. But although similar, it has nothing to do with it.

Introduction

Before I go into the details, I give a brief introduction of the elements of Silvermoon.

Shape

Shapes are primitive classes which are used by controls to render its appearance. Generally spoken, a shape is a rectangle with an image. The image can be a rectangle (RectangleShape) or it can be a Circle (RoundShape) or any other image. A shape can even contain other shapes (MultiShape) to build complex images. But more about shapes later…

Control

Controls are the heart of Silvermoon. Controls have properties that describe the current characteristics and appearance of a control. For instance a button control has a IsPressed property, or almost every Control has a Color property. Controls use shapes to render their appearance. Therefore every control has a protected Shapes class which is a linked list of shapes (I prefer linked lists over lists, as they are about 20% faster for enumeration and consume only the storage they required). A Control can also host one (Decorator) or more (ContainerControl) controls. For instance a ListBox contains Items. There are controls which don’t have any appearance and are supposed to be used as container only, like Panel, and some have, like Button. Visual controls (or ChromeControl) have a Background and a Chrome property which is of type shape. The background is the shape which is rendered as first of all other shapes and child controls. Chrome is the opposite and it is rendered after all other shapes and child controls. For instance, the picker makes use of the chrome to render a lens.
Some controls have additional shapes, and you can always change the default shape directly by changing the property to another shape.

VisualStateManager

A control does not directly (or should not) change it’s appearance when a property changes it’s value. The only thing it does is to change the state. So the button sets it’s state to “Pressed” when IsPressed changes to true, and back to “Normal” when it returns to false. And this is the moment where a VisualStateManager comes into the play:
VisualStateManager is a description of how the control appears when a control has a distinct state. Of course it can happen that a control has more than one state, e.g. a radio button can be selected and disabled. Therefore VisualStateManager is divided into groups. Every group can contain a state and they are mutually exclusive. But it’s also possible that one state is included in more than one group. Each state finally contains a collection of properties and their values for that state. They also describe how to transition to the new value instead of simply change to the new value on sudden. VisualsStateManager can either be applied to all controls of a distinct class (VisualStateManager.SetClassManager) or for an explicit control only (Control.VisualStateManager).

PropertyAccessor

Property accessors are the Silvermoon equivalent of dependency properties. Property accessors allow access the value of a property from a class without knowledge of the class itself. This feature is required to describe animations for properties (see VisualStateManager) and later how to bind them. Unless dependency properties, they are no sparse properties who only consume storage when they are assigned. That because a dependency property is slower in access (70xwrite, 20xread) than a direct property due to boxing/unboxing value types and maintaining the dictionary. Therefore I decided to create something new, which allows to access a property from outside but does not slow down accessing a property. A property accessor also allows to remember the value of the property before an animation/transition is applied on it. A property accessor also ensures that there is only one animation of the property at one time.

Style and StyleDictionary

Principally spoken, a style is a class which changes properties of a control. Instead of writing a custom class which overrides the default shapes of a control, styles can do this more elegant. As soon as a control initializes itself (this is when shortly before it gets rendered for the very first time), it looks for a style to use. This can be a named style (Control.StyleName) or a class style. The style comes from the first ancestor control, which contains a StyleDictionary. This is a control of type ContainerControl. For instance, a window is a container control and therefore has a StyleDictionary. Therefore, you can give all buttons on a distinct window another appearance as for a second window. You can also change the style of controls embedded in a panel. As an example, ToolBar contains a Style in is dictionary for any button control to render it different from its default style. But it’s also possible, to override this default style again.

Transformation

Transformations can be attached to controls as well as to shapes and their intention is – as the name applies – to transform the control or shape. There are transformations to translate the location as well as to scale, or rotate in 3d space. Transformations are mostly used for transitions.

Command

Commands are used to notify ancestor controls about an event that occured. The ancestor (parent) can analyze the command and decide whether to do something or not. The command is then bubbled down to the next parent. If and when a command is raised, depends of the class of the control. For instance, a button command raises a command when the button is tapped. However, it is possible to raise any command at any time with RaiseCommand. The explorer example in the demo uses commands to decouple child controls from their parents.

 

SparseEvent

Many events in Silvermoon are SparseEvents. SparseEvents, as the name implies are events which don't consume any storage unless they are used. You can register own sparse events by creating a new static instance, and use AddHandler/RemoveHandler/RaiseEvent to add/remove/raise the event.

 

 

System Requirements

For Use

  • .NET CF 6.x
  • OpenGL hardware acceleration capable device
  • Resolution of 192dpi (800x480). (96dpi possible, but not completely tested)

For Development

  • Visual Studio 2008
  • .NET CF 3.5
  • Emulator is NOT recommended since it does not support OpenGL acceleration.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值