Game Development Reference
In-Depth Information
Handling Custom User Events
The various notifications raised by the thumbnail and texture browser controls are
going to need a way to reach the application consuming them, so we need to pro-
vide events that the consuming application can tie into.
Basically, all of the events provided by the controls will send the same information,
so we can define a single class to hold the event arguments that will be sent to the
various event delegates. The different events will be covered in the next section
when the viewer control is discussed.
The event arguments class only tracks a single texture handle instance, which is a
reference to the texture handle associated to the event being executed.
The following code defines the event arguments class for the controls.
public class TextureBrowserEventArgs : EventArgs
{
private TextureHandle _texture;
public TextureHandle Texture
{
get { return _texture; }
set { _texture = value; }
}
public TextureBrowserEventArgs(TextureHandle texture)
{
_texture = texture;
}
}
Building the Viewer Control
The viewer control is fairly straightforward. It is basically a user control with a panel
that contains the thumbnail controls. This control determines the spacing and posi-
tioning of the thumbnails, handles notification events, and exposes appearance and
functional settings. It also manages the loading, displaying, and caching of thumb-
nails using the appropriate loader. The following source code describes the texture
browser control in its entirety. The source code listing is somewhat lengthy, one
reason why I will not comment much on each piece individually, but the full source
is needed to fully enable you to understand the control without referring to the
Companion Web site. The source code on the Web site is fully commented if there
is a specific piece that you wish to fully investigate.
Search Nedrilad ::




Custom Search