<?xml version="1.0"?><?xml-stylesheet type="text/xsl" href="http://www.codeplex.com/rss.xsl"?><rss version="2.0"><channel><title>wsx Wiki &amp; Documentation Rss Feed</title><link>http://www.codeplex.com/wsx/Wiki/View.aspx?title=Home</link><description>wsx Wiki Rss Description</description><item><title>Updated Wiki: Overview</title><link>http://www.codeplex.com/wsx/Wiki/View.aspx?title=Overview&amp;version=1</link><description>&lt;div class="wikidoc"&gt;
&lt;h1&gt;
Overview
&lt;/h1&gt; &lt;br /&gt;The WSX library has become fairly large and complex, and many of you have struggled to begin using it without guidance. This overview is intended to explain how the  library works internally, so that you can use it, derive classes, and make modifications. Before starting however, I would like to point out that the source code is comprehensively documented.&lt;br /&gt; &lt;br /&gt;&lt;h2&gt;
GUIManager
&lt;/h2&gt; &lt;br /&gt;The obvious place to start is with the GUIManager class. This class is at the base of the control hierarchy, but is not actually a control as it doesn't derive from UIComponent. It's main purpose is to act as the DrawableGameComponent that gets updated and drawn by the framework. On top of that, it tracks which control has focus, and draws the mouse cursor on top of all the controls.&lt;br /&gt;
&lt;/div&gt;</description><author>cdmac</author><pubDate>Mon, 08 Sep 2008 20:31:20 GMT</pubDate><guid isPermaLink="false">Updated Wiki: Overview 20080908083120P</guid></item><item><title>Updated Wiki: Tutorials</title><link>http://www.codeplex.com/wsx/Wiki/View.aspx?title=Tutorials&amp;version=2</link><description>&lt;div class="wikidoc"&gt;
&lt;h1&gt;
Tutorials
&lt;/h1&gt; &lt;br /&gt;&lt;ul&gt;
&lt;li&gt;&lt;a href="http://www.codeplex.com/wsx/Wiki/View.aspx?title=Tutorial%201&amp;amp;referringTitle=Tutorials"&gt;Tutorial 1&lt;/a&gt; - Setting up and handling events&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.codeplex.com/wsx/Wiki/View.aspx?title=Tutorial%202&amp;amp;referringTitle=Tutorials"&gt;Tutorial 2&lt;/a&gt; - Creating a dialog window&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;</description><author>cdmac</author><pubDate>Mon, 08 Sep 2008 20:09:20 GMT</pubDate><guid isPermaLink="false">Updated Wiki: Tutorials 20080908080920P</guid></item><item><title>Updated Wiki: Tutorial 2</title><link>http://www.codeplex.com/wsx/Wiki/View.aspx?title=Tutorial 2&amp;version=3</link><description>&lt;div class="wikidoc"&gt;
&lt;h1&gt;
Tutorial 2
&lt;/h1&gt; &lt;br /&gt;This next tutorial will cover how to create a class that inherits from Dialog, and retrieve some useful information from it. This method of using windows was developed while putting together my tile map editor application. It is the best way of using the GUI that I have discovered so far, and is pretty closely based on other window systems I've used in the past. I'm sure some other techniques will expose themselves in the future.&lt;br /&gt; &lt;br /&gt;&lt;h2&gt;
Setting Up The Project
&lt;/h2&gt; &lt;br /&gt;I have already covered setting up a new project, and setting up the GUIManager in &lt;a href="http://www.codeplex.com/wsx/Wiki/View.aspx?title=Tutorial%201&amp;amp;referringTitle=Tutorial%202"&gt;Tutorial 1&lt;/a&gt;, so you can go back and look it up there if necessary. Simply follow Tutorial 1 up until the Adding Controls heading, and you'll be ready to go.&lt;br /&gt; &lt;br /&gt;&lt;h2&gt;
Creating The Dialog
&lt;/h2&gt; &lt;br /&gt;We will create a Dialog box, where the user can enter their name into a textbox. It will have OK and Cancel buttons, so that the dialog can return a result.&lt;br /&gt; &lt;br /&gt;The first thing to do is to create a new class called UserDetailsDialog, which is inherited from Dialog. Dialog is inherited from Window, and the only addition is that it returns a result, which can be queried after the Dialog is closed.&lt;br /&gt; &lt;br /&gt;&lt;div style="color:#000000;background-color:#FFFFFF;"&gt;&lt;pre&gt;
&lt;span style="color:#0000FF;"&gt;using&lt;/span&gt; System;
&lt;span style="color:#0000FF;"&gt;using&lt;/span&gt; Microsoft.Xna.Framework;
&lt;span style="color:#0000FF;"&gt;using&lt;/span&gt; WindowSystem;
&lt;span style="color:#0000FF;"&gt;namespace&lt;/span&gt; WindowSystemTestbed
{
    &lt;span style="color:#0000FF;"&gt;public&lt;/span&gt; &lt;span style="color:#0000FF;"&gt;class&lt;/span&gt; UserDetailsDialog : Dialog
    {
    }
}
&lt;/pre&gt;&lt;/div&gt; &lt;br /&gt;Next we can add a few fields to our new class.&lt;br /&gt; &lt;br /&gt;&lt;div style="color:#000000;background-color:#FFFFFF;"&gt;&lt;pre&gt;
&lt;span style="color:#0000FF;"&gt;private&lt;/span&gt; &lt;span style="color:#0000FF;"&gt;const&lt;/span&gt; &lt;span style="color:#0000FF;"&gt;int&lt;/span&gt; LargeSeparation = 10;
&lt;span style="color:#0000FF;"&gt;private&lt;/span&gt; &lt;span style="color:#0000FF;"&gt;const&lt;/span&gt; &lt;span style="color:#0000FF;"&gt;int&lt;/span&gt; SmallSeparation = 5;
&lt;span style="color:#0000FF;"&gt;private&lt;/span&gt; TextButton OKButton;
&lt;span style="color:#0000FF;"&gt;private&lt;/span&gt; TextButton cancelButton;
&lt;span style="color:#0000FF;"&gt;private&lt;/span&gt; TextBox nameTextBox;
&lt;/pre&gt;&lt;/div&gt; &lt;br /&gt;The LargeSeparation and SmallSeparation constants are something I add to all my dialogs. They allow me to control the spacing between the window edge and between dialog controls. I use LargeSeparation for the window edge, and between unrelated controls. SmallSeparation is used for the space between related controls, like between a textbox and it's label.&lt;br /&gt; &lt;br /&gt;The rest of the fields are controls that we will need to keep track of after they are set up. We will need to get the text from nameTextBox for example. Other controls like labels can just be added without keeping a reference if they don't need to change, or we don't need to query them after events are triggered.&lt;br /&gt; &lt;br /&gt;Next we should add a property, so that the user's name can be queried from outside the class.&lt;br /&gt; &lt;br /&gt;&lt;div style="color:#000000;background-color:#FFFFFF;"&gt;&lt;pre&gt;
&lt;span style="color:#0000FF;"&gt;public&lt;/span&gt; &lt;span style="color:#0000FF;"&gt;string&lt;/span&gt; Name
{
    get { &lt;span style="color:#0000FF;"&gt;return&lt;/span&gt; &lt;span style="color:#0000FF;"&gt;this&lt;/span&gt;.nameTextBox.Text; }
}
&lt;/pre&gt;&lt;/div&gt; &lt;br /&gt;The constructor sets the control properties and adds them as child controls, as well as settings it's own properties.&lt;br /&gt; &lt;br /&gt;&lt;div style="color:#000000;background-color:#FFFFFF;"&gt;&lt;pre&gt;
&lt;span style="color:#0000FF;"&gt;public&lt;/span&gt; UserDetailsDialog(Game game, GUIManager guiManager)
    : &lt;span style="color:#0000FF;"&gt;base&lt;/span&gt;(game, guiManager)
{
    &lt;span style="color:#008000;"&gt;// Name label&lt;/span&gt;
    Label nameLabel = &lt;span style="color:#0000FF;"&gt;new&lt;/span&gt; Label(game, guiManager);
    Add(nameLabel);
    nameLabel.Text = &lt;span style="color:#A31515;"&gt;&amp;quot;Name:&amp;quot;&lt;/span&gt;;
    nameLabel.X = LargeSeperation;
    nameLabel.Y = LargeSeperation;
    nameLabel.Width = 75;
    nameLabel.Height = nameLabel.TextHeight;
    &lt;span style="color:#008000;"&gt;// Name textbox&lt;/span&gt;
    &lt;span style="color:#0000FF;"&gt;this&lt;/span&gt;.nameTextBox = &lt;span style="color:#0000FF;"&gt;new&lt;/span&gt; TextBox(game, guiManager);
    Add(&lt;span style="color:#0000FF;"&gt;this&lt;/span&gt;.nameTextBox);
    &lt;span style="color:#0000FF;"&gt;this&lt;/span&gt;.nameTextBox.Initialize();
    &lt;span style="color:#0000FF;"&gt;this&lt;/span&gt;.nameTextBox.X = nameLabel.X;
    &lt;span style="color:#0000FF;"&gt;this&lt;/span&gt;.nameTextBox.Y = nameLabel.Y + nameLabel.Height + SmallSeperation;
    &lt;span style="color:#008000;"&gt;// Set the window width to the default textbox width&lt;/span&gt;
    ClientWidth = nameTextBox.Width + (2 * LargeSeperation);
    &lt;span style="color:#008000;"&gt;// Cancel button&lt;/span&gt;
    &lt;span style="color:#0000FF;"&gt;this&lt;/span&gt;.cancelButton = &lt;span style="color:#0000FF;"&gt;new&lt;/span&gt; TextButton(game, guiManager);
    Add(&lt;span style="color:#0000FF;"&gt;this&lt;/span&gt;.cancelButton);
    &lt;span style="color:#0000FF;"&gt;this&lt;/span&gt;.cancelButton.Text = &lt;span style="color:#A31515;"&gt;&amp;quot;Cancel&amp;quot;&lt;/span&gt;;
    &lt;span style="color:#0000FF;"&gt;this&lt;/span&gt;.cancelButton.X = ClientWidth - &lt;span style="color:#0000FF;"&gt;this&lt;/span&gt;.cancelButton.Width - LargeSeperation;
    &lt;span style="color:#0000FF;"&gt;this&lt;/span&gt;.cancelButton.Y = &lt;span style="color:#0000FF;"&gt;this&lt;/span&gt;.nameTextBox.Y + &lt;span style="color:#0000FF;"&gt;this&lt;/span&gt;.nameTextBox.Height + LargeSeperation;
    &lt;span style="color:#0000FF;"&gt;this&lt;/span&gt;.cancelButton.Click += &lt;span style="color:#0000FF;"&gt;new&lt;/span&gt; ClickHandler(OnButtonClicked);
    &lt;span style="color:#008000;"&gt;// OK button&lt;/span&gt;
    &lt;span style="color:#0000FF;"&gt;this&lt;/span&gt;.OKButton = &lt;span style="color:#0000FF;"&gt;new&lt;/span&gt; TextButton(game, guiManager);
    Add(&lt;span style="color:#0000FF;"&gt;this&lt;/span&gt;.OKButton);
    &lt;span style="color:#0000FF;"&gt;this&lt;/span&gt;.OKButton.Text = &lt;span style="color:#A31515;"&gt;&amp;quot;OK&amp;quot;&lt;/span&gt;;
    &lt;span style="color:#0000FF;"&gt;this&lt;/span&gt;.OKButton.X = &lt;span style="color:#0000FF;"&gt;this&lt;/span&gt;.cancelButton.X - SmallSeperation - &lt;span style="color:#0000FF;"&gt;this&lt;/span&gt;.OKButton.Width;
    &lt;span style="color:#0000FF;"&gt;this&lt;/span&gt;.OKButton.Y = &lt;span style="color:#0000FF;"&gt;this&lt;/span&gt;.cancelButton.Y;
    &lt;span style="color:#0000FF;"&gt;this&lt;/span&gt;.OKButton.Click += &lt;span style="color:#0000FF;"&gt;new&lt;/span&gt; ClickHandler(OnButtonClicked);
    &lt;span style="color:#008000;"&gt;// Set the window height to the amount needed to show all controls&lt;/span&gt;
    ClientHeight = &lt;span style="color:#0000FF;"&gt;this&lt;/span&gt;.OKButton.Y + &lt;span style="color:#0000FF;"&gt;this&lt;/span&gt;.OKButton.Height + LargeSeperation;
    &lt;span style="color:#008000;"&gt;// Set the window title&lt;/span&gt;
    TitleText = &lt;span style="color:#A31515;"&gt;&amp;quot;User Details&amp;quot;&lt;/span&gt;;
    &lt;span style="color:#008000;"&gt;// This dialog does not need to be resized by the user&lt;/span&gt;
    Resizable = &lt;span style="color:#0000FF;"&gt;false&lt;/span&gt;;
    CenterWindow();
}
&lt;/pre&gt;&lt;/div&gt; &lt;br /&gt;Note that I add child controls before setting their properties. This is because some controls don't become fully set up until they are initialised, which happens automatically when they are added to the GUI or another control. You could also just call Initialize() manually, but who needs the extra typing?&lt;br /&gt; &lt;br /&gt;Also notice that control positions are set in relation to each other. I find this keeps the layout quite dynamic, especially for resizeable windows. I will consider providing layout managers in a future release, perhaps similar to those found in the Java Swing library.&lt;br /&gt; &lt;br /&gt;The TextBox and TextButton controls don't have their Width or Height properties set. That's because some controls have useful default sizes, which allows some flexibility when modifying the default GUI settings.&lt;br /&gt; &lt;br /&gt;Next we will add an event handler to the class, which will be called whenever a button is clicked. The buttons had this event handler added for their Click events in the constructor.&lt;br /&gt; &lt;br /&gt;&lt;div style="color:#000000;background-color:#FFFFFF;"&gt;&lt;pre&gt;
&lt;span style="color:#0000FF;"&gt;protected&lt;/span&gt; &lt;span style="color:#0000FF;"&gt;void&lt;/span&gt; OnButtonClicked(UIComponent sender)
{
    &lt;span style="color:#0000FF;"&gt;if&lt;/span&gt; (sender == &lt;span style="color:#0000FF;"&gt;this&lt;/span&gt;.OKButton)
         SetDialogResult(DialogResult.OK);
    CloseWindow();}
&lt;/pre&gt;&lt;/div&gt; &lt;br /&gt;This method simply checks which button was clicked, and sets the result accordingly before closing the dialog. We don't bother checking for the Cancel button because cancel is the default result. This is because that is also the result when the user clicks on the window close button. If necessary the close button can be removed by setting the HasCloseButton property to false.&lt;br /&gt; &lt;br /&gt;&lt;h2&gt;
Using The Dialog
&lt;/h2&gt; &lt;br /&gt;Back to the main game class which I have called Tutorial2, and we're going to attempt to use our new dialog.&lt;br /&gt; &lt;br /&gt;The application will show an information message box, explaining how to use our simple program, then show our User Details dialog box when the user presses enter. If the user clicks on the OK button, a message box will display the name entered into the dialog textbox.&lt;br /&gt; &lt;br /&gt;Firstly, add a dialog reference to our Game class.&lt;br /&gt; &lt;br /&gt;&lt;div style="color:#000000;background-color:#FFFFFF;"&gt;&lt;pre&gt;
&lt;span style="color:#0000FF;"&gt;private&lt;/span&gt; UserDetailsDialog dialog;
&lt;/pre&gt;&lt;/div&gt; &lt;br /&gt;Next add an event handler that will be called when the user presses a key. In the constructor add the following code.&lt;br /&gt; &lt;br /&gt;&lt;div style="color:#000000;background-color:#FFFFFF;"&gt;&lt;pre&gt;
&lt;span style="color:#008000;"&gt;// Add a key down event handler&lt;/span&gt;
&lt;span style="color:#0000FF;"&gt;this&lt;/span&gt;.input.KeyDown += &lt;span style="color:#0000FF;"&gt;new&lt;/span&gt; KeyDownHandler(OnKeyDown);
&lt;/pre&gt;&lt;/div&gt; &lt;br /&gt;Then create the event handler method.&lt;br /&gt; &lt;br /&gt;&lt;div style="color:#000000;background-color:#FFFFFF;"&gt;&lt;pre&gt;
&lt;span style="color:#0000FF;"&gt;private&lt;/span&gt; &lt;span style="color:#0000FF;"&gt;void&lt;/span&gt; OnKeyDown(KeyEventArgs args)
{
    &lt;span style="color:#0000FF;"&gt;if&lt;/span&gt; (args.Key == Keys.Enter)
    {
        &lt;span style="color:#008000;"&gt;// Only create a new dialog if one isn't already shown&lt;/span&gt;
        &lt;span style="color:#0000FF;"&gt;if&lt;/span&gt; (&lt;span style="color:#0000FF;"&gt;this&lt;/span&gt;.gui.GetModal() == &lt;span style="color:#0000FF;"&gt;null&lt;/span&gt;)
        {
            &lt;span style="color:#008000;"&gt;// Create and show dialog&lt;/span&gt;
            &lt;span style="color:#0000FF;"&gt;this&lt;/span&gt;.dialog = &lt;span style="color:#0000FF;"&gt;new&lt;/span&gt; UserDetailsDialog(&lt;span style="color:#0000FF;"&gt;this&lt;/span&gt;, &lt;span style="color:#0000FF;"&gt;this&lt;/span&gt;.gui);
            &lt;span style="color:#0000FF;"&gt;this&lt;/span&gt;.dialog.Close += &lt;span style="color:#0000FF;"&gt;new&lt;/span&gt; CloseHandler(OnDialogClosed);
            &lt;span style="color:#0000FF;"&gt;this&lt;/span&gt;.dialog.Show(&lt;span style="color:#0000FF;"&gt;true&lt;/span&gt;);
         }
    }
}
&lt;/pre&gt;&lt;/div&gt; &lt;br /&gt;Basically this function just checks that no other modal window is already opened, if not then it pops up a new User Details dialog. Modal just means any window that has exclusive focus, such as a message box, or our dialog. To show a window as modal, pass true to the Window.Show() method, otherwise pass false.&lt;br /&gt; &lt;br /&gt;When your program calls a modal dialog in Windows, it takes full control of you're processing until the dialog is closed. Unfortunately, our system is a little different. We have to add an event handler to the window's Close event, that checks which window was closed, and acts accordingly.&lt;br /&gt; &lt;br /&gt;The following code is the method called when our dialog is closed.&lt;br /&gt; &lt;br /&gt;&lt;div style="color:#000000;background-color:#FFFFFF;"&gt;&lt;pre&gt;
&lt;span style="color:#0000FF;"&gt;private&lt;/span&gt; &lt;span style="color:#0000FF;"&gt;void&lt;/span&gt; OnDialogClosed(UIComponent sender)
{
    &lt;span style="color:#0000FF;"&gt;if&lt;/span&gt; (sender == &lt;span style="color:#0000FF;"&gt;this&lt;/span&gt;.dialog)
    {
        &lt;span style="color:#0000FF;"&gt;if&lt;/span&gt; (&lt;span style="color:#0000FF;"&gt;this&lt;/span&gt;.dialog.DialogResult == DialogResult.OK)
        {
            MessageBox message = &lt;span style="color:#0000FF;"&gt;new&lt;/span&gt; MessageBox(
                &lt;span style="color:#0000FF;"&gt;this&lt;/span&gt;,
                &lt;span style="color:#0000FF;"&gt;this&lt;/span&gt;.gui,
                &lt;span style="color:#A31515;"&gt;&amp;quot;Name: &amp;quot;&lt;/span&gt; + &lt;span style="color:#0000FF;"&gt;this&lt;/span&gt;.dialog.Name,
                &lt;span style="color:#A31515;"&gt;&amp;quot;User Name&amp;quot;&lt;/span&gt;,
                MessageBoxButtons.OK,
                MessageBoxType.Info
                );
                message.Show(&lt;span style="color:#0000FF;"&gt;true&lt;/span&gt;);
        }
        &lt;span style="color:#008000;"&gt;// Remove event handler so garbage collector will pick it up&lt;/span&gt;
        &lt;span style="color:#0000FF;"&gt;this&lt;/span&gt;.dialog.Close -= OnDialogClosed;
        &lt;span style="color:#0000FF;"&gt;this&lt;/span&gt;.dialog = &lt;span style="color:#0000FF;"&gt;null&lt;/span&gt;;
    }
}
&lt;/pre&gt;&lt;/div&gt; &lt;br /&gt;A message box is shown repeating the name entered by the user, only if the result was OK. Then the event handler is removed from the dialog and the dialog is set to null, to prevent it from lingering about in memory. This is very important to remember, especially in a real application. I've caught out by event handlers and the garbage collector on few occasions.&lt;br /&gt; &lt;br /&gt;The final things to add is a message box explaining how to use the application. This should be placed in the Game class Initialize() method, to ensure it's shown at the start of the program.&lt;br /&gt; &lt;br /&gt;&lt;div style="color:#000000;background-color:#FFFFFF;"&gt;&lt;pre&gt;
&lt;span style="color:#008000;"&gt;// Show a message box informing the user how to use the program&lt;/span&gt;
MessageBox info = &lt;span style="color:#0000FF;"&gt;new&lt;/span&gt; MessageBox(
    &lt;span style="color:#0000FF;"&gt;this&lt;/span&gt;,
    &lt;span style="color:#0000FF;"&gt;this&lt;/span&gt;.gui,
    &lt;span style="color:#A31515;"&gt;&amp;quot;Press enter to bring up the dialog.&amp;quot;&lt;/span&gt;,
    &lt;span style="color:#A31515;"&gt;&amp;quot;Info&amp;quot;&lt;/span&gt;,
    MessageBoxButtons.OK,
    MessageBoxType.Info
    );
info.Show(&lt;span style="color:#0000FF;"&gt;true&lt;/span&gt;);
&lt;/pre&gt;&lt;/div&gt; &lt;br /&gt;&lt;h2&gt;
Conclusion
&lt;/h2&gt; &lt;br /&gt;I hope this tutorial was helpful, it was definitely more difficult to write than the last one. I would really appreciate any feedback. I think in the next tutorial I will cover skinning and modifying the GUI.&lt;br /&gt; &lt;br /&gt;All tutorial source code is included in the WindowSystemTestbed project.&lt;br /&gt;
&lt;/div&gt;</description><author>cdmac</author><pubDate>Mon, 08 Sep 2008 20:07:01 GMT</pubDate><guid isPermaLink="false">Updated Wiki: Tutorial 2 20080908080701P</guid></item><item><title>Updated Wiki: Tutorial 1</title><link>http://www.codeplex.com/wsx/Wiki/View.aspx?title=Tutorial 1&amp;version=3</link><description>&lt;div class="wikidoc"&gt;
&lt;h1&gt;
Tutorial 1
&lt;/h1&gt; &lt;br /&gt;This first tutorial will cover setting up a GUIManager object, adding new controls, and handling their events.&lt;br /&gt; &lt;br /&gt;&lt;h2&gt;
Setting Up The Project
&lt;/h2&gt; &lt;br /&gt;The simplest way to begin is to use the WindowSystemTestbed project as a starting template. I simply created a new source file containing a class called Tutorial1, and set that as the startup Game object in Main. You can use this if you don't feel like starting a project from scratch.&lt;br /&gt; &lt;br /&gt;&lt;h2&gt;
Setting Up The GUIManager
&lt;/h2&gt; &lt;br /&gt;The first thing to do is to add a couple using statements for the InputEventSystem and WindowSystem namespaces.&lt;br /&gt; &lt;br /&gt;&lt;div style="color:#000000;background-color:#FFFFFF;"&gt;&lt;pre&gt;
&lt;span style="color:#0000FF;"&gt;using&lt;/span&gt; System;
&lt;span style="color:#0000FF;"&gt;using&lt;/span&gt; Microsoft.Xna.Framework;
...
&lt;span style="color:#0000FF;"&gt;using&lt;/span&gt; InputEventSystem;
&lt;span style="color:#0000FF;"&gt;using&lt;/span&gt; WindowSystem;
&lt;/pre&gt;&lt;/div&gt; &lt;br /&gt;Now add some fields.&lt;br /&gt; &lt;br /&gt;&lt;div style="color:#000000;background-color:#FFFFFF;"&gt;&lt;pre&gt;
&lt;span style="color:#0000FF;"&gt;private&lt;/span&gt; GraphicsDeviceManager graphics;
&lt;span style="color:#0000FF;"&gt;private&lt;/span&gt; InputEvents input;
&lt;span style="color:#0000FF;"&gt;private&lt;/span&gt; GUIManager gui;
&lt;/pre&gt;&lt;/div&gt; &lt;br /&gt;In the constructor we set up these objects, and add input and gui to the list of game components. It is important that the InputEvents object is created before the GUIManager object because it adds itself to the game services in the constructor, which the GUI will need access to. Not creating an InputEvents object at all will cause the program to crash.&lt;br /&gt; &lt;br /&gt;&lt;div style="color:#000000;background-color:#FFFFFF;"&gt;&lt;pre&gt;
&lt;span style="color:#0000FF;"&gt;public&lt;/span&gt; Tutorial1()
{
    &lt;span style="color:#0000FF;"&gt;this&lt;/span&gt;.graphics = &lt;span style="color:#0000FF;"&gt;new&lt;/span&gt; GraphicsDeviceManager(&lt;span style="color:#0000FF;"&gt;this&lt;/span&gt;);
    &lt;span style="color:#0000FF;"&gt;this&lt;/span&gt;.input = &lt;span style="color:#0000FF;"&gt;new&lt;/span&gt; InputEvents(&lt;span style="color:#0000FF;"&gt;this&lt;/span&gt;);
    Components.Add(&lt;span style="color:#0000FF;"&gt;this&lt;/span&gt;.input);
    &lt;span style="color:#0000FF;"&gt;this&lt;/span&gt;.gui = &lt;span style="color:#0000FF;"&gt;new&lt;/span&gt; GUIManager(&lt;span style="color:#0000FF;"&gt;this&lt;/span&gt;);
    Components.Add(&lt;span style="color:#0000FF;"&gt;this&lt;/span&gt;.gui);
    &lt;span style="color:#008000;"&gt;// GUI requires variable timing to function correctly&lt;/span&gt;
    IsFixedTimeStep = &lt;span style="color:#0000FF;"&gt;false&lt;/span&gt;;
    Window.Title = &lt;span style="color:#A31515;"&gt;&amp;quot;Window System Tutorial 1&amp;quot;&lt;/span&gt;;
}
&lt;/pre&gt;&lt;/div&gt; &lt;br /&gt;The GUIManager object should be initialised in the overriden Initialize() method, before any child controls are added. This is so that order of resource loading can be predicted.&lt;br /&gt; &lt;br /&gt;&lt;div style="color:#000000;background-color:#FFFFFF;"&gt;&lt;pre&gt;
&lt;span style="color:#0000FF;"&gt;protected&lt;/span&gt; &lt;span style="color:#0000FF;"&gt;override&lt;/span&gt; &lt;span style="color:#0000FF;"&gt;void&lt;/span&gt; Initialize()
{
    &lt;span style="color:#008000;"&gt;// Has to be initialised before child controls can be added&lt;/span&gt;
    &lt;span style="color:#0000FF;"&gt;this&lt;/span&gt;.gui.Initialize();
    &lt;span style="color:#0000FF;"&gt;base&lt;/span&gt;.Initialize();
}
&lt;/pre&gt;&lt;/div&gt; &lt;br /&gt;You will also want to override the Draw() method, to clear the screen each frame, although this probably doesn't affect the GUI as it handles drawing itself.&lt;br /&gt; &lt;br /&gt;&lt;h2&gt;
Adding Controls
&lt;/h2&gt; &lt;br /&gt;I'm going to use a menu bar with various menus and menu items as an example. This will show how to create controls, how to add them to the GUI, and how to handle their events.&lt;br /&gt; &lt;br /&gt;First we should add some fields, which are the menu bar and the menu items that the user will actually select. This means that we don't actually need to keep a reference to the 'File' menu for example, because it handles itself. We do need to keep references to child menu items that will actually be clicked, so that we can determine which one was selected. An example would be the 'New' or 'Save' menu items.&lt;br /&gt; &lt;br /&gt;&lt;div style="color:#000000;background-color:#FFFFFF;"&gt;&lt;pre&gt;
&lt;span style="color:#0000FF;"&gt;private&lt;/span&gt; MenuBar menuBar;
&lt;span style="color:#0000FF;"&gt;private&lt;/span&gt; MenuItem newMenuItem;
&lt;span style="color:#0000FF;"&gt;private&lt;/span&gt; MenuItem openMenuItem;
&lt;span style="color:#0000FF;"&gt;private&lt;/span&gt; MenuItem saveMenuItem;
&lt;span style="color:#0000FF;"&gt;private&lt;/span&gt; MenuItem saveAsMenuItem;
&lt;span style="color:#0000FF;"&gt;private&lt;/span&gt; MenuItem exitMenuItem;
&lt;span style="color:#0000FF;"&gt;private&lt;/span&gt; MenuItem undoMenuItem;
&lt;span style="color:#0000FF;"&gt;private&lt;/span&gt; MenuItem redoMenuItem;
&lt;/pre&gt;&lt;/div&gt; &lt;br /&gt;Next we have to actually set up the GUI objects, and add them to the GUI. This should take place in Initialize(), after the GUIManager has been initialised.&lt;br /&gt; &lt;br /&gt;&lt;div style="color:#000000;background-color:#FFFFFF;"&gt;&lt;pre&gt;
&lt;span style="color:#0000FF;"&gt;this&lt;/span&gt;.menuBar = &lt;span style="color:#0000FF;"&gt;new&lt;/span&gt; MenuBar(&lt;span style="color:#0000FF;"&gt;this&lt;/span&gt;, gui);
MenuItem fileMenu = &lt;span style="color:#0000FF;"&gt;new&lt;/span&gt; MenuItem(&lt;span style="color:#0000FF;"&gt;this&lt;/span&gt;, gui);
fileMenu.Text = &lt;span style="color:#A31515;"&gt;&amp;quot;File&amp;quot;&lt;/span&gt;;
&lt;span style="color:#0000FF;"&gt;this&lt;/span&gt;.newMenuItem = &lt;span style="color:#0000FF;"&gt;new&lt;/span&gt; MenuItem(&lt;span style="color:#0000FF;"&gt;this&lt;/span&gt;, gui);
&lt;span style="color:#0000FF;"&gt;this&lt;/span&gt;.newMenuItem.Text = &lt;span style="color:#A31515;"&gt;&amp;quot;New...&amp;quot;&lt;/span&gt;;
fileMenu.Add(&lt;span style="color:#0000FF;"&gt;this&lt;/span&gt;.newMenuItem);
&lt;span style="color:#0000FF;"&gt;this&lt;/span&gt;.openMenuItem = &lt;span style="color:#0000FF;"&gt;new&lt;/span&gt; MenuItem(&lt;span style="color:#0000FF;"&gt;this&lt;/span&gt;, gui);
&lt;span style="color:#0000FF;"&gt;this&lt;/span&gt;.openMenuItem.Text = &lt;span style="color:#A31515;"&gt;&amp;quot;Open...&amp;quot;&lt;/span&gt;;
fileMenu.Add(&lt;span style="color:#0000FF;"&gt;this&lt;/span&gt;.openMenuItem);
&lt;span style="color:#0000FF;"&gt;this&lt;/span&gt;.saveMenuItem = &lt;span style="color:#0000FF;"&gt;new&lt;/span&gt; MenuItem(&lt;span style="color:#0000FF;"&gt;this&lt;/span&gt;, gui);
&lt;span style="color:#0000FF;"&gt;this&lt;/span&gt;.saveMenuItem.Text = &lt;span style="color:#A31515;"&gt;&amp;quot;Save&amp;quot;&lt;/span&gt;;
&lt;span style="color:#0000FF;"&gt;this&lt;/span&gt;.saveMenuItem.IsEnabled = &lt;span style="color:#0000FF;"&gt;false&lt;/span&gt;;
fileMenu.Add(&lt;span style="color:#0000FF;"&gt;this&lt;/span&gt;.saveMenuItem);
&lt;span style="color:#0000FF;"&gt;this&lt;/span&gt;.saveAsMenuItem = &lt;span style="color:#0000FF;"&gt;new&lt;/span&gt; MenuItem(&lt;span style="color:#0000FF;"&gt;this&lt;/span&gt;, gui);
&lt;span style="color:#0000FF;"&gt;this&lt;/span&gt;.saveAsMenuItem.Text = &lt;span style="color:#A31515;"&gt;&amp;quot;Save As...&amp;quot;&lt;/span&gt;;
&lt;span style="color:#0000FF;"&gt;this&lt;/span&gt;.saveAsMenuItem.IsEnabled = &lt;span style="color:#0000FF;"&gt;false&lt;/span&gt;;
fileMenu.Add(&lt;span style="color:#0000FF;"&gt;this&lt;/span&gt;.saveAsMenuItem);
&lt;span style="color:#0000FF;"&gt;this&lt;/span&gt;.exitMenuItem = &lt;span style="color:#0000FF;"&gt;new&lt;/span&gt; MenuItem(&lt;span style="color:#0000FF;"&gt;this&lt;/span&gt;, gui);
&lt;span style="color:#0000FF;"&gt;this&lt;/span&gt;.exitMenuItem.Text = &lt;span style="color:#A31515;"&gt;&amp;quot;Exit&amp;quot;&lt;/span&gt;;
fileMenu.Add(&lt;span style="color:#0000FF;"&gt;this&lt;/span&gt;.exitMenuItem);
menuBar.Add(fileMenu);
MenuItem editMenu = &lt;span style="color:#0000FF;"&gt;new&lt;/span&gt; MenuItem(&lt;span style="color:#0000FF;"&gt;this&lt;/span&gt;, gui);
editMenu.Text = &lt;span style="color:#A31515;"&gt;&amp;quot;Edit&amp;quot;&lt;/span&gt;;
&lt;span style="color:#0000FF;"&gt;this&lt;/span&gt;.undoMenuItem = &lt;span style="color:#0000FF;"&gt;new&lt;/span&gt; MenuItem(&lt;span style="color:#0000FF;"&gt;this&lt;/span&gt;, gui);
&lt;span style="color:#0000FF;"&gt;this&lt;/span&gt;.undoMenuItem.Text = &lt;span style="color:#A31515;"&gt;&amp;quot;Undo&amp;quot;&lt;/span&gt;;
&lt;span style="color:#0000FF;"&gt;this&lt;/span&gt;.undoMenuItem.IsEnabled = &lt;span style="color:#0000FF;"&gt;false&lt;/span&gt;;
editMenu.Add(&lt;span style="color:#0000FF;"&gt;this&lt;/span&gt;.undoMenuItem);
&lt;span style="color:#0000FF;"&gt;this&lt;/span&gt;.redoMenuItem = &lt;span style="color:#0000FF;"&gt;new&lt;/span&gt; MenuItem(&lt;span style="color:#0000FF;"&gt;this&lt;/span&gt;, gui);
&lt;span style="color:#0000FF;"&gt;this&lt;/span&gt;.redoMenuItem.Text = &lt;span style="color:#A31515;"&gt;&amp;quot;Redo&amp;quot;&lt;/span&gt;;
&lt;span style="color:#0000FF;"&gt;this&lt;/span&gt;.redoMenuItem.IsEnabled = &lt;span style="color:#0000FF;"&gt;false&lt;/span&gt;;
editMenu.Add(&lt;span style="color:#0000FF;"&gt;this&lt;/span&gt;.redoMenuItem);
&lt;span style="color:#0000FF;"&gt;this&lt;/span&gt;.menuBar.Add(editMenu);
&lt;span style="color:#008000;"&gt;// Add menubar to gui&lt;/span&gt;
&lt;span style="color:#0000FF;"&gt;this&lt;/span&gt;.gui.Add(&lt;span style="color:#0000FF;"&gt;this&lt;/span&gt;.menuBar);
&lt;/pre&gt;&lt;/div&gt; &lt;br /&gt;You may notice that some of the menu items have a property called IsEnabled set to false. This basically makes the item grey and unclickable, just how Windows does it. This property only applies to MenuItem objects currently, but at some point in the future, I will probably make it apply to all controls.&lt;br /&gt; &lt;br /&gt;Now if you run the application, it should show a menu bar with all the new menus and menu items.&lt;br /&gt; &lt;br /&gt;&lt;h2&gt;
Control Events
&lt;/h2&gt; &lt;br /&gt;Next we will add event handlers that will be called whenever a menu item is clicked. The reason for holding references to menu items is for comparison with the clicked control, determining which one was actually clicked.&lt;br /&gt; &lt;br /&gt;So add the following code to the Initialize() method, probably after the menu bar is added to the GUI.&lt;br /&gt; &lt;br /&gt;&lt;div style="color:#000000;background-color:#FFFFFF;"&gt;&lt;pre&gt;
&lt;span style="color:#008000;"&gt;// Add event handlers&lt;/span&gt;
&lt;span style="color:#0000FF;"&gt;this&lt;/span&gt;.newMenuItem.Click += &lt;span style="color:#0000FF;"&gt;new&lt;/span&gt; ClickHandler(OnMenuItemClicked);
&lt;span style="color:#0000FF;"&gt;this&lt;/span&gt;.openMenuItem.Click += &lt;span style="color:#0000FF;"&gt;new&lt;/span&gt; ClickHandler(OnMenuItemClicked);
&lt;span style="color:#0000FF;"&gt;this&lt;/span&gt;.exitMenuItem.Click += &lt;span style="color:#0000FF;"&gt;new&lt;/span&gt; ClickHandler(OnMenuItemClicked);
&lt;span style="color:#0000FF;"&gt;this&lt;/span&gt;.undoMenuItem.Click += &lt;span style="color:#0000FF;"&gt;new&lt;/span&gt; ClickHandler(OnMenuItemClicked);
&lt;span style="color:#0000FF;"&gt;this&lt;/span&gt;.redoMenuItem.Click += &lt;span style="color:#0000FF;"&gt;new&lt;/span&gt; ClickHandler(OnMenuItemClicked);
&lt;/pre&gt;&lt;/div&gt; &lt;br /&gt;Finally we need to add a new method that is called whenever a menu item is clicked. We simply check which item was clicked, and act accordingly.&lt;br /&gt; &lt;br /&gt;&lt;div style="color:#000000;background-color:#FFFFFF;"&gt;&lt;pre&gt;
&lt;span style="color:#0000FF;"&gt;private&lt;/span&gt; &lt;span style="color:#0000FF;"&gt;void&lt;/span&gt; OnMenuItemClicked(UIComponent sender)
{
    &lt;span style="color:#0000FF;"&gt;if&lt;/span&gt; (sender == &lt;span style="color:#0000FF;"&gt;this&lt;/span&gt;.newMenuItem)
    {
        MessageBox messageBox = &lt;span style="color:#0000FF;"&gt;new&lt;/span&gt; MessageBox(
            &lt;span style="color:#0000FF;"&gt;this&lt;/span&gt;,
            gui,
            &lt;span style="color:#A31515;"&gt;&amp;quot;New clicked!&amp;quot;&lt;/span&gt;,
            &lt;span style="color:#A31515;"&gt;&amp;quot;Tutorial 1&amp;quot;&lt;/span&gt;,
            MessageBoxButtons.OK,
            MessageBoxType.Info
        );
        messageBox.Show(&lt;span style="color:#0000FF;"&gt;true&lt;/span&gt;);
    }
    &lt;span style="color:#0000FF;"&gt;else&lt;/span&gt; &lt;span style="color:#0000FF;"&gt;if&lt;/span&gt; (sender == &lt;span style="color:#0000FF;"&gt;this&lt;/span&gt;.openMenuItem)
    {
        MessageBox messageBox = &lt;span style="color:#0000FF;"&gt;new&lt;/span&gt; MessageBox(
            &lt;span style="color:#0000FF;"&gt;this&lt;/span&gt;,
            gui,
            &lt;span style="color:#A31515;"&gt;&amp;quot;Open clicked!&amp;quot;&lt;/span&gt;,
            &lt;span style="color:#A31515;"&gt;&amp;quot;Tutorial 1&amp;quot;&lt;/span&gt;,
            MessageBoxButtons.OK,
            MessageBoxType.Info
        );
        messageBox.Show(&lt;span style="color:#0000FF;"&gt;true&lt;/span&gt;);
    }
    &lt;span style="color:#0000FF;"&gt;else&lt;/span&gt; &lt;span style="color:#0000FF;"&gt;if&lt;/span&gt; (sender == &lt;span style="color:#0000FF;"&gt;this&lt;/span&gt;.undoMenuItem)
    {
        MessageBox messageBox = &lt;span style="color:#0000FF;"&gt;new&lt;/span&gt; MessageBox(
            &lt;span style="color:#0000FF;"&gt;this&lt;/span&gt;,
            gui,
            &lt;span style="color:#A31515;"&gt;&amp;quot;Undo clicked!&amp;quot;&lt;/span&gt;,
            &lt;span style="color:#A31515;"&gt;&amp;quot;Tutorial 1&amp;quot;&lt;/span&gt;,
            MessageBoxButtons.OK,
            MessageBoxType.Info
        );
        messageBox.Show(&lt;span style="color:#0000FF;"&gt;true&lt;/span&gt;);
    }
    &lt;span style="color:#0000FF;"&gt;else&lt;/span&gt; &lt;span style="color:#0000FF;"&gt;if&lt;/span&gt; (sender == &lt;span style="color:#0000FF;"&gt;this&lt;/span&gt;.redoMenuItem)
    {
        MessageBox messageBox = &lt;span style="color:#0000FF;"&gt;new&lt;/span&gt; MessageBox(
            &lt;span style="color:#0000FF;"&gt;this&lt;/span&gt;,
            gui,
            &lt;span style="color:#A31515;"&gt;&amp;quot;Redo clicked!&amp;quot;&lt;/span&gt;,
            &lt;span style="color:#A31515;"&gt;&amp;quot;Tutorial 1&amp;quot;&lt;/span&gt;,
            MessageBoxButtons.OK,
            MessageBoxType.Info
        );
        messageBox.Show(&lt;span style="color:#0000FF;"&gt;true&lt;/span&gt;);
    }
    &lt;span style="color:#0000FF;"&gt;else&lt;/span&gt; &lt;span style="color:#0000FF;"&gt;if&lt;/span&gt; (sender == &lt;span style="color:#0000FF;"&gt;this&lt;/span&gt;.exitMenuItem)
        Exit();
}
&lt;/pre&gt;&lt;/div&gt; &lt;br /&gt;&lt;h2&gt;
Summary
&lt;/h2&gt; &lt;br /&gt;This first tutorial was really simple, but should show you the basics of using the window system. It should be enough if all you want to do is add a couple buttons to your game. In the next tutorial I will show how to create a class that inherits from Window, to demonstrate how to begin to create a real application.&lt;br /&gt;
&lt;/div&gt;</description><author>cdmac</author><pubDate>Mon, 08 Sep 2008 20:04:43 GMT</pubDate><guid isPermaLink="false">Updated Wiki: Tutorial 1 20080908080443P</guid></item><item><title>Updated Wiki: Home</title><link>http://www.codeplex.com/wsx/Wiki/View.aspx?title=Home&amp;version=9</link><description>&lt;div class="wikidoc"&gt;
&lt;b&gt;Project Description&lt;/b&gt;&lt;br /&gt; &lt;br /&gt;Window System for XNA allows you to easily add GUI functionality to your games and tools that target the XNA Framework.
 It is being actively developed at the moment, so if anybody is interested in contributing to the project, then please leave a message in the forums.&lt;br /&gt; &lt;br /&gt;&lt;b&gt;Documentation&lt;/b&gt;&lt;br /&gt; &lt;br /&gt;&lt;ul&gt;
&lt;li&gt;&lt;a href="http://www.codeplex.com/wsx/Wiki/View.aspx?title=Overview&amp;amp;referringTitle=Home"&gt;Overview&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.codeplex.com/wsx/Wiki/View.aspx?title=Reference&amp;amp;referringTitle=Home"&gt;Reference&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.codeplex.com/wsx/Wiki/View.aspx?title=Tutorials&amp;amp;referringTitle=Home"&gt;Tutorials&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt; &lt;br /&gt;&lt;b&gt;News&lt;/b&gt; - 18th May 2008&lt;br /&gt; &lt;br /&gt;New release has the promised improved performance as well as various bug fixes. See release notes for more information.&lt;br /&gt; &lt;br /&gt;Aaron&lt;br /&gt; &lt;br /&gt;&lt;b&gt;News&lt;/b&gt; - 17th May 2008&lt;br /&gt; &lt;br /&gt;Last night I gave a demo of Window System for XNA to a group of XNA developers. The reception was good, and very much appreciated. The event was organised by XNA UK User Group (http://xna-uk.net), and sponsored by Microsoft. Thanks for all the food and drink!&lt;br /&gt; &lt;br /&gt;The other projects I saw were really cool, some of which I can't wait until they are finished. Make sure you check out the site, especially if you're from the UK.&lt;br /&gt; &lt;br /&gt;The evening also made me feel like working on my library again, so I've spent today bug fixing and thinking about new features. If you check out source control, you'll notice lot's of updates. The next thing I'll be working on it improving performance, by making my own implementation of SpriteFont, so I can do software clipping instead of using scissor rectangles.&lt;br /&gt; &lt;br /&gt;Aaron&lt;br /&gt; &lt;br /&gt;&lt;b&gt;News&lt;/b&gt; - 26th March 2008&lt;br /&gt; &lt;br /&gt;The promised release has finally been finished! The project has been updated to XNA 2.0, and adds XML skinning support.&lt;br /&gt; &lt;br /&gt;In order to add XNA 2.0 support, I removed the remnants of the old render target system from Label. Scissor rectangles are now used, which has affected performance, but I will be doing some optimization for the next major release.&lt;br /&gt; &lt;br /&gt;All the old static property calls have been removed, in favour of the new skinning system. During implementation I also cleaned up existing property interfaces and added new ones that were previously missing. These changes will likely break your current code, but it shouldn't be too difficult to fix.&lt;br /&gt; &lt;br /&gt;The other changes are minor bug fixes.&lt;br /&gt; &lt;br /&gt;I will be also adding full documentation to the wiki in the near future, with the possibility of new tutorials (if anybody suggests something). I also am looking for new team members to help contribute to the project.&lt;br /&gt; &lt;br /&gt;At the moment I am working on a 2D game framework in XNA with a friend, that should have an alpha release in two weeks or so. I will post a link here when it is published on CodePlex.&lt;br /&gt; &lt;br /&gt;&lt;b&gt;News&lt;/b&gt; - 9th February 2008&lt;br /&gt; &lt;br /&gt;There have been a lack of updates lately. Unfortunately I haven't really had time to work with XNA lately because of my job. I get to work on the PlayStation 3 every day, so I can't really complain!&lt;br /&gt; &lt;br /&gt;The good news is that I have a release ready today! The bad news is that something seems wrong with the CodePlex site, so I can't upload the project. Below I've posted some information about the release. I'll try again later today.&lt;br /&gt; &lt;br /&gt;&amp;quot;This release adds support for XML skin definitions. This method replaces the previous method of static properties to change GUI defaults, and is far more flexible. A skin definition can be applied to all subsequent controls, all existing controls, and also to individual controls.&lt;br /&gt; &lt;br /&gt;I will add a short tutorial soon to explain the usage. For now check out the WindowSystemTestbed project that is included in the download, in particular DefaultSkin.skin, which is an XML skin featuring all possible properties set to their defaults.&lt;br /&gt; &lt;br /&gt;Please note that many of the control properties have been changed, removed, or added to accommodate this new skinning system. It is likely that your existing code will break upon first compilation. It shouldn't be too difficult to go through the new class definitions to update your code.&lt;br /&gt; &lt;br /&gt;Additionally, while implementing this I noticed some existing bugs that I had previously missed. I fixed most of them, but the ones remaining may prevent certain control skins from appearing as expected. Please submit all bugs to this site.&amp;quot;&lt;br /&gt; &lt;br /&gt;&lt;b&gt;News&lt;/b&gt; - 5th November 2007&lt;br /&gt; &lt;br /&gt;Sorry about the delay in uploading a new release, but it's finally ready! If anybody is thinking about a broadband provider in the UK, don't use Tiscali!&lt;br /&gt; &lt;br /&gt;As promised, anti-aliased fonts are supported, and XNAExtras has been replaced with XNA SpriteFont. There is a chance it could break some code, as DrawableUIComponent has been removed, because it is now redundant with the new rendering code.&lt;br /&gt; &lt;br /&gt;Now that these long-running problems have been fixed, look forward to new features in the near future.&lt;br /&gt; &lt;br /&gt;&lt;b&gt;News&lt;/b&gt; - 21st September 2007&lt;br /&gt; &lt;br /&gt;Just to let everybody know that there should be a new release within the next week, basically when my internet connection is back up. The reason for the sudden release is because I've finally managed to fix the GUI rendering, with correct alpha values. The most important impact is that anti-aliased SpriteFont will be used from now on, and the old XNAExtras stuff is to be removed.&lt;br /&gt; &lt;br /&gt;If anyone is interested in what the problem was, and how I fixed it, then read on.&lt;br /&gt; &lt;br /&gt;In the old system, every control was rendered to its own texture using render targets. Each child control would have its texture combined with those of the other children, to make up the texture of the parent control (after drawing itself). It was quite efficient because only the top level controls (generally windows) actually get their textures drawn to the screen, with the textures only redrawn when necessary, such as when the mouse hovers over a button, and a different image must be displayed. Render targets were also an easy way to perform clipping of child controls within their parent, and allowed the alpha value of a control to affect all children as well.&lt;br /&gt; &lt;br /&gt;The problem with render targets was that control textures had to be drawn to a transparent texture, causing incorrect colour and alpha values to be produced during the alpha blending operation. In practical terms, it means that the edges of sprites with partial transparency and anti-aliased text would be mixed with white (or any other colour depending on the clear colour of the render target). This made either anti-aliased text unreadable, or made the edges of some controls the wrong colour. The reason I couldn't use SpriteFont, was because it created anti-aliased fonts. With XNAExtras I could make a simple font bitmap with colour keyed transparency, which made the text problem go away.&lt;br /&gt; &lt;br /&gt;After playing with render states and pre multiplied alpha for a long time, I finally got fed up and tried to find another way to get it working. I was advised to draw directly to the screen, and use scissor rectangles to handle clipping. This worked great, except performance was abysmal. With just 4 complex windows on the screen, the framerate would start to drop. That was without any game running in the background! The reason for the poor performance was because scissor rectangles must be the same until SpriteBatch.End() is called. This means that I had a SpriteBatch.Begin() and End()  call for every single control!&lt;br /&gt; &lt;br /&gt;Next I decided to implement my own texture clipping, which all worked great, but there wasn't an obvious way to clip text. When using scissor rectangles for just text, the performance was still really bad. The final method was to use a hybrid approach. I would clip sprites on the CPU, and render text to textures which would be cached to allow fast draw calls. The text texture can then be clipped in the same way as the rest of the GUI sprites. Of course there was still the problem of partial alpha pixels being blended with the transparent texture colour. Basically I set the render states to draw with pre multiplied alpha, and set the background clear colour of the texture to the text colour, with the alpha channel set to 0. This means that the blending still takes place, but it produces the correct results. The performance is good once again!&lt;br /&gt; &lt;br /&gt;So yeah, the project isn't dead, I've just had some big problems to deal with. Now that this is working, I will go back to adding more features like Xbox 360 support, and more widgets.&lt;br /&gt; &lt;br /&gt;Thanks,&lt;br /&gt;Aaron&lt;br /&gt;
&lt;/div&gt;</description><author>cdmac</author><pubDate>Mon, 08 Sep 2008 19:38:43 GMT</pubDate><guid isPermaLink="false">Updated Wiki: Home 20080908073843P</guid></item><item><title>UPDATED WIKI: Home</title><link>http://www.codeplex.com/wsx/Wiki/View.aspx?title=Home&amp;version=8</link><description>&lt;div class="wikidoc"&gt;
&lt;b&gt;Project Description&lt;/b&gt;&lt;br /&gt; &lt;br /&gt;Window System for XNA allows you to easily add GUI functionality to your games and tools that target the XNA Framework.
 It is being actively developed at the moment, so if anybody is interested in contributing to the project, then please leave a message in the forums.&lt;br /&gt; &lt;br /&gt;&lt;b&gt;Documentation&lt;/b&gt;&lt;br /&gt; &lt;br /&gt;&lt;ul&gt;
&lt;li&gt;&lt;a href="http://www.codeplex.com/wsx/Wiki/View.aspx?title=Reference&amp;amp;referringTitle=Home"&gt;Reference&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.codeplex.com/wsx/Wiki/View.aspx?title=Tutorials&amp;amp;referringTitle=Home"&gt;Tutorials&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt; &lt;br /&gt;&lt;b&gt;News&lt;/b&gt; - 18th May 2008&lt;br /&gt; &lt;br /&gt;New release has the promised improved performance as well as various bug fixes. See release notes for more information.&lt;br /&gt; &lt;br /&gt;Aaron&lt;br /&gt; &lt;br /&gt;&lt;b&gt;News&lt;/b&gt; - 17th May 2008&lt;br /&gt; &lt;br /&gt;Last night I gave a demo of Window System for XNA to a group of XNA developers. The reception was good, and very much appreciated. The event was organised by XNA UK User Group (http://xna-uk.net), and sponsored by Microsoft. Thanks for all the food and drink!&lt;br /&gt; &lt;br /&gt;The other projects I saw were really cool, some of which I can't wait until they are finished. Make sure you check out the site, especially if you're from the UK.&lt;br /&gt; &lt;br /&gt;The evening also made me feel like working on my library again, so I've spent today bug fixing and thinking about new features. If you check out source control, you'll notice lot's of updates. The next thing I'll be working on it improving performance, by making my own implementation of SpriteFont, so I can do software clipping instead of using scissor rectangles.&lt;br /&gt; &lt;br /&gt;Aaron&lt;br /&gt; &lt;br /&gt;&lt;b&gt;News&lt;/b&gt; - 26th March 2008&lt;br /&gt; &lt;br /&gt;The promised release has finally been finished! The project has been updated to XNA 2.0, and adds XML skinning support.&lt;br /&gt; &lt;br /&gt;In order to add XNA 2.0 support, I removed the remnants of the old render target system from Label. Scissor rectangles are now used, which has affected performance, but I will be doing some optimization for the next major release.&lt;br /&gt; &lt;br /&gt;All the old static property calls have been removed, in favour of the new skinning system. During implementation I also cleaned up existing property interfaces and added new ones that were previously missing. These changes will likely break your current code, but it shouldn't be too difficult to fix.&lt;br /&gt; &lt;br /&gt;The other changes are minor bug fixes.&lt;br /&gt; &lt;br /&gt;I will be also adding full documentation to the wiki in the near future, with the possibility of new tutorials (if anybody suggests something). I also am looking for new team members to help contribute to the project.&lt;br /&gt; &lt;br /&gt;At the moment I am working on a 2D game framework in XNA with a friend, that should have an alpha release in two weeks or so. I will post a link here when it is published on CodePlex.&lt;br /&gt; &lt;br /&gt;&lt;b&gt;News&lt;/b&gt; - 9th February 2008&lt;br /&gt; &lt;br /&gt;There have been a lack of updates lately. Unfortunately I haven't really had time to work with XNA lately because of my job. I get to work on the PlayStation 3 every day, so I can't really complain!&lt;br /&gt; &lt;br /&gt;The good news is that I have a release ready today! The bad news is that something seems wrong with the CodePlex site, so I can't upload the project. Below I've posted some information about the release. I'll try again later today.&lt;br /&gt; &lt;br /&gt;&amp;quot;This release adds support for XML skin definitions. This method replaces the previous method of static properties to change GUI defaults, and is far more flexible. A skin definition can be applied to all subsequent controls, all existing controls, and also to individual controls.&lt;br /&gt; &lt;br /&gt;I will add a short tutorial soon to explain the usage. For now check out the WindowSystemTestbed project that is included in the download, in particular DefaultSkin.skin, which is an XML skin featuring all possible properties set to their defaults.&lt;br /&gt; &lt;br /&gt;Please note that many of the control properties have been changed, removed, or added to accommodate this new skinning system. It is likely that your existing code will break upon first compilation. It shouldn't be too difficult to go through the new class definitions to update your code.&lt;br /&gt; &lt;br /&gt;Additionally, while implementing this I noticed some existing bugs that I had previously missed. I fixed most of them, but the ones remaining may prevent certain control skins from appearing as expected. Please submit all bugs to this site.&amp;quot;&lt;br /&gt; &lt;br /&gt;&lt;b&gt;News&lt;/b&gt; - 5th November 2007&lt;br /&gt; &lt;br /&gt;Sorry about the delay in uploading a new release, but it's finally ready! If anybody is thinking about a broadband provider in the UK, don't use Tiscali!&lt;br /&gt; &lt;br /&gt;As promised, anti-aliased fonts are supported, and XNAExtras has been replaced with XNA SpriteFont. There is a chance it could break some code, as DrawableUIComponent has been removed, because it is now redundant with the new rendering code.&lt;br /&gt; &lt;br /&gt;Now that these long-running problems have been fixed, look forward to new features in the near future.&lt;br /&gt; &lt;br /&gt;&lt;b&gt;News&lt;/b&gt; - 21st September 2007&lt;br /&gt; &lt;br /&gt;Just to let everybody know that there should be a new release within the next week, basically when my internet connection is back up. The reason for the sudden release is because I've finally managed to fix the GUI rendering, with correct alpha values. The most important impact is that anti-aliased SpriteFont will be used from now on, and the old XNAExtras stuff is to be removed.&lt;br /&gt; &lt;br /&gt;If anyone is interested in what the problem was, and how I fixed it, then read on.&lt;br /&gt; &lt;br /&gt;In the old system, every control was rendered to its own texture using render targets. Each child control would have its texture combined with those of the other children, to make up the texture of the parent control (after drawing itself). It was quite efficient because only the top level controls (generally windows) actually get their textures drawn to the screen, with the textures only redrawn when necessary, such as when the mouse hovers over a button, and a different image must be displayed. Render targets were also an easy way to perform clipping of child controls within their parent, and allowed the alpha value of a control to affect all children as well.&lt;br /&gt; &lt;br /&gt;The problem with render targets was that control textures had to be drawn to a transparent texture, causing incorrect colour and alpha values to be produced during the alpha blending operation. In practical terms, it means that the edges of sprites with partial transparency and anti-aliased text would be mixed with white (or any other colour depending on the clear colour of the render target). This made either anti-aliased text unreadable, or made the edges of some controls the wrong colour. The reason I couldn't use SpriteFont, was because it created anti-aliased fonts. With XNAExtras I could make a simple font bitmap with colour keyed transparency, which made the text problem go away.&lt;br /&gt; &lt;br /&gt;After playing with render states and pre multiplied alpha for a long time, I finally got fed up and tried to find another way to get it working. I was advised to draw directly to the screen, and use scissor rectangles to handle clipping. This worked great, except performance was abysmal. With just 4 complex windows on the screen, the framerate would start to drop. That was without any game running in the background! The reason for the poor performance was because scissor rectangles must be the same until SpriteBatch.End() is called. This means that I had a SpriteBatch.Begin() and End()  call for every single control!&lt;br /&gt; &lt;br /&gt;Next I decided to implement my own texture clipping, which all worked great, but there wasn't an obvious way to clip text. When using scissor rectangles for just text, the performance was still really bad. The final method was to use a hybrid approach. I would clip sprites on the CPU, and render text to textures which would be cached to allow fast draw calls. The text texture can then be clipped in the same way as the rest of the GUI sprites. Of course there was still the problem of partial alpha pixels being blended with the transparent texture colour. Basically I set the render states to draw with pre multiplied alpha, and set the background clear colour of the texture to the text colour, with the alpha channel set to 0. This means that the blending still takes place, but it produces the correct results. The performance is good once again!&lt;br /&gt; &lt;br /&gt;So yeah, the project isn't dead, I've just had some big problems to deal with. Now that this is working, I will go back to adding more features like Xbox 360 support, and more widgets.&lt;br /&gt; &lt;br /&gt;Thanks,&lt;br /&gt;Aaron&lt;br /&gt;
&lt;/div&gt;</description><author>cdmac</author><pubDate>Sun, 18 May 2008 17:04:57 GMT</pubDate><guid isPermaLink="false">UPDATED WIKI: Home 20080518050457P</guid></item><item><title>UPDATED WIKI: Home</title><link>http://www.codeplex.com/wsx/Wiki/View.aspx?title=Home&amp;version=7</link><description>&lt;div class="wikidoc"&gt;
&lt;b&gt;Project Description&lt;/b&gt;&lt;br /&gt; &lt;br /&gt;Window System for XNA allows you to easily add GUI functionality to your games and tools that target the XNA Framework.
 It is being actively developed at the moment, so if anybody is interested in contributing to the project, then please leave a message in the forums.&lt;br /&gt; &lt;br /&gt;&lt;b&gt;Documentation&lt;/b&gt;&lt;br /&gt; &lt;br /&gt;&lt;ul&gt;
&lt;li&gt;&lt;a href="http://www.codeplex.com/wsx/Wiki/View.aspx?title=Reference&amp;amp;referringTitle=Home"&gt;Reference&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.codeplex.com/wsx/Wiki/View.aspx?title=Tutorials&amp;amp;referringTitle=Home"&gt;Tutorials&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt; &lt;br /&gt;&lt;b&gt;News&lt;/b&gt; - 17th May 2008&lt;br /&gt; &lt;br /&gt;Last night I gave a demo of Window System for XNA to a group of XNA developers. The reception was good, and very much appreciated. The event was organised by XNA UK User Group (http://xna-uk.net), and sponsored by Microsoft. Thanks for all the food and drink!&lt;br /&gt; &lt;br /&gt;The other projects I saw were really cool, some of which I can't wait until they are finished. Make sure you check out the site, especially if you're from the UK.&lt;br /&gt; &lt;br /&gt;The evening also made me feel like working on my library again, so I've spent today bug fixing and thinking about new features. If you check out source control, you'll notice lot's of updates. The next thing I'll be working on it improving performance, by making my own implementation of SpriteFont, so I can do software clipping instead of using scissor rectangles.&lt;br /&gt; &lt;br /&gt;Aaron&lt;br /&gt; &lt;br /&gt;&lt;b&gt;News&lt;/b&gt; - 26th March 2008&lt;br /&gt; &lt;br /&gt;The promised release has finally been finished! The project has been updated to XNA 2.0, and adds XML skinning support.&lt;br /&gt; &lt;br /&gt;In order to add XNA 2.0 support, I removed the remnants of the old render target system from Label. Scissor rectangles are now used, which has affected performance, but I will be doing some optimization for the next major release.&lt;br /&gt; &lt;br /&gt;All the old static property calls have been removed, in favour of the new skinning system. During implementation I also cleaned up existing property interfaces and added new ones that were previously missing. These changes will likely break your current code, but it shouldn't be too difficult to fix.&lt;br /&gt; &lt;br /&gt;The other changes are minor bug fixes.&lt;br /&gt; &lt;br /&gt;I will be also adding full documentation to the wiki in the near future, with the possibility of new tutorials (if anybody suggests something). I also am looking for new team members to help contribute to the project.&lt;br /&gt; &lt;br /&gt;At the moment I am working on a 2D game framework in XNA with a friend, that should have an alpha release in two weeks or so. I will post a link here when it is published on CodePlex.&lt;br /&gt; &lt;br /&gt;&lt;b&gt;News&lt;/b&gt; - 9th February 2008&lt;br /&gt; &lt;br /&gt;There have been a lack of updates lately. Unfortunately I haven't really had time to work with XNA lately because of my job. I get to work on the PlayStation 3 every day, so I can't really complain!&lt;br /&gt; &lt;br /&gt;The good news is that I have a release ready today! The bad news is that something seems wrong with the CodePlex site, so I can't upload the project. Below I've posted some information about the release. I'll try again later today.&lt;br /&gt; &lt;br /&gt;&amp;quot;This release adds support for XML skin definitions. This method replaces the previous method of static properties to change GUI defaults, and is far more flexible. A skin definition can be applied to all subsequent controls, all existing controls, and also to individual controls.&lt;br /&gt; &lt;br /&gt;I will add a short tutorial soon to explain the usage. For now check out the WindowSystemTestbed project that is included in the download, in particular DefaultSkin.skin, which is an XML skin featuring all possible properties set to their defaults.&lt;br /&gt; &lt;br /&gt;Please note that many of the control properties have been changed, removed, or added to accommodate this new skinning system. It is likely that your existing code will break upon first compilation. It shouldn't be too difficult to go through the new class definitions to update your code.&lt;br /&gt; &lt;br /&gt;Additionally, while implementing this I noticed some existing bugs that I had previously missed. I fixed most of them, but the ones remaining may prevent certain control skins from appearing as expected. Please submit all bugs to this site.&amp;quot;&lt;br /&gt; &lt;br /&gt;&lt;b&gt;News&lt;/b&gt; - 5th November 2007&lt;br /&gt; &lt;br /&gt;Sorry about the delay in uploading a new release, but it's finally ready! If anybody is thinking about a broadband provider in the UK, don't use Tiscali!&lt;br /&gt; &lt;br /&gt;As promised, anti-aliased fonts are supported, and XNAExtras has been replaced with XNA SpriteFont. There is a chance it could break some code, as DrawableUIComponent has been removed, because it is now redundant with the new rendering code.&lt;br /&gt; &lt;br /&gt;Now that these long-running problems have been fixed, look forward to new features in the near future.&lt;br /&gt; &lt;br /&gt;&lt;b&gt;News&lt;/b&gt; - 21st September 2007&lt;br /&gt; &lt;br /&gt;Just to let everybody know that there should be a new release within the next week, basically when my internet connection is back up. The reason for the sudden release is because I've finally managed to fix the GUI rendering, with correct alpha values. The most important impact is that anti-aliased SpriteFont will be used from now on, and the old XNAExtras stuff is to be removed.&lt;br /&gt; &lt;br /&gt;If anyone is interested in what the problem was, and how I fixed it, then read on.&lt;br /&gt; &lt;br /&gt;In the old system, every control was rendered to its own texture using render targets. Each child control would have its texture combined with those of the other children, to make up the texture of the parent control (after drawing itself). It was quite efficient because only the top level controls (generally windows) actually get their textures drawn to the screen, with the textures only redrawn when necessary, such as when the mouse hovers over a button, and a different image must be displayed. Render targets were also an easy way to perform clipping of child controls within their parent, and allowed the alpha value of a control to affect all children as well.&lt;br /&gt; &lt;br /&gt;The problem with render targets was that control textures had to be drawn to a transparent texture, causing incorrect colour and alpha values to be produced during the alpha blending operation. In practical terms, it means that the edges of sprites with partial transparency and anti-aliased text would be mixed with white (or any other colour depending on the clear colour of the render target). This made either anti-aliased text unreadable, or made the edges of some controls the wrong colour. The reason I couldn't use SpriteFont, was because it created anti-aliased fonts. With XNAExtras I could make a simple font bitmap with colour keyed transparency, which made the text problem go away.&lt;br /&gt; &lt;br /&gt;After playing with render states and pre multiplied alpha for a long time, I finally got fed up and tried to find another way to get it working. I was advised to draw directly to the screen, and use scissor rectangles to handle clipping. This worked great, except performance was abysmal. With just 4 complex windows on the screen, the framerate would start to drop. That was without any game running in the background! The reason for the poor performance was because scissor rectangles must be the same until SpriteBatch.End() is called. This means that I had a SpriteBatch.Begin() and End()  call for every single control!&lt;br /&gt; &lt;br /&gt;Next I decided to implement my own texture clipping, which all worked great, but there wasn't an obvious way to clip text. When using scissor rectangles for just text, the performance was still really bad. The final method was to use a hybrid approach. I would clip sprites on the CPU, and render text to textures which would be cached to allow fast draw calls. The text texture can then be clipped in the same way as the rest of the GUI sprites. Of course there was still the problem of partial alpha pixels being blended with the transparent texture colour. Basically I set the render states to draw with pre multiplied alpha, and set the background clear colour of the texture to the text colour, with the alpha channel set to 0. This means that the blending still takes place, but it produces the correct results. The performance is good once again!&lt;br /&gt; &lt;br /&gt;So yeah, the project isn't dead, I've just had some big problems to deal with. Now that this is working, I will go back to adding more features like Xbox 360 support, and more widgets.&lt;br /&gt; &lt;br /&gt;Thanks,&lt;br /&gt;Aaron&lt;br /&gt;
&lt;/div&gt;</description><author>cdmac</author><pubDate>Sat, 17 May 2008 15:49:52 GMT</pubDate><guid isPermaLink="false">UPDATED WIKI: Home 20080517034952P</guid></item><item><title>UPDATED WIKI: Home</title><link>http://www.codeplex.com/wsx/Wiki/View.aspx?title=Home&amp;version=6</link><description>&lt;div class="wikidoc"&gt;
&lt;b&gt;Project Description&lt;/b&gt;&lt;br /&gt; &lt;br /&gt;Window System for XNA allows you to easily add GUI functionality to your games and tools that target the XNA Framework.
 It is being actively developed at the moment, so if anybody is interested in contributing to the project, then please leave a message in the forums.&lt;br /&gt; &lt;br /&gt;&lt;b&gt;Documentation&lt;/b&gt;&lt;br /&gt; &lt;br /&gt;&lt;ul&gt;
&lt;li&gt;&lt;a href="http://www.codeplex.com/wsx/Wiki/View.aspx?title=Reference&amp;amp;referringTitle=Home"&gt;Reference&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.codeplex.com/wsx/Wiki/View.aspx?title=Tutorials&amp;amp;referringTitle=Home"&gt;Tutorials&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt; &lt;br /&gt;&lt;b&gt;News&lt;/b&gt; - 26th March 2008&lt;br /&gt; &lt;br /&gt;The promised release has finally been finished! The project has been updated to XNA 2.0, and adds XML skinning support.&lt;br /&gt; &lt;br /&gt;In order to add XNA 2.0 support, I removed the remnants of the old render target system from Label. Scissor rectangles are now used, which has affected performance, but I will be doing some optimization for the next major release.&lt;br /&gt; &lt;br /&gt;All the old static property calls have been removed, in favour of the new skinning system. During implementation I also cleaned up existing property interfaces and added new ones that were previously missing. These changes will likely break your current code, but it shouldn't be too difficult to fix.&lt;br /&gt; &lt;br /&gt;The other changes are minor bug fixes.&lt;br /&gt; &lt;br /&gt;I will be also adding full documentation to the wiki in the near future, with the possibility of new tutorials (if anybody suggests something). I also am looking for new team members to help contribute to the project.&lt;br /&gt; &lt;br /&gt;At the moment I am working on a 2D game framework in XNA with a friend, that should have an alpha release in two weeks or so. I will post a link here when it is published on CodePlex.&lt;br /&gt; &lt;br /&gt;&lt;b&gt;News&lt;/b&gt; - 9th February 2008&lt;br /&gt; &lt;br /&gt;There have been a lack of updates lately. Unfortunately I haven't really had time to work with XNA lately because of my job. I get to work on the PlayStation 3 every day, so I can't really complain!&lt;br /&gt; &lt;br /&gt;The good news is that I have a release ready today! The bad news is that something seems wrong with the CodePlex site, so I can't upload the project. Below I've posted some information about the release. I'll try again later today.&lt;br /&gt; &lt;br /&gt;&amp;quot;This release adds support for XML skin definitions. This method replaces the previous method of static properties to change GUI defaults, and is far more flexible. A skin definition can be applied to all subsequent controls, all existing controls, and also to individual controls.&lt;br /&gt; &lt;br /&gt;I will add a short tutorial soon to explain the usage. For now check out the WindowSystemTestbed project that is included in the download, in particular DefaultSkin.skin, which is an XML skin featuring all possible properties set to their defaults.&lt;br /&gt; &lt;br /&gt;Please note that many of the control properties have been changed, removed, or added to accommodate this new skinning system. It is likely that your existing code will break upon first compilation. It shouldn't be too difficult to go through the new class definitions to update your code.&lt;br /&gt; &lt;br /&gt;Additionally, while implementing this I noticed some existing bugs that I had previously missed. I fixed most of them, but the ones remaining may prevent certain control skins from appearing as expected. Please submit all bugs to this site.&amp;quot;&lt;br /&gt; &lt;br /&gt;&lt;b&gt;News&lt;/b&gt; - 5th November 2007&lt;br /&gt; &lt;br /&gt;Sorry about the delay in uploading a new release, but it's finally ready! If anybody is thinking about a broadband provider in the UK, don't use Tiscali!&lt;br /&gt; &lt;br /&gt;As promised, anti-aliased fonts are supported, and XNAExtras has been replaced with XNA SpriteFont. There is a chance it could break some code, as DrawableUIComponent has been removed, because it is now redundant with the new rendering code.&lt;br /&gt; &lt;br /&gt;Now that these long-running problems have been fixed, look forward to new features in the near future.&lt;br /&gt; &lt;br /&gt;&lt;b&gt;News&lt;/b&gt; - 21st September 2007&lt;br /&gt; &lt;br /&gt;Just to let everybody know that there should be a new release within the next week, basically when my internet connection is back up. The reason for the sudden release is because I've finally managed to fix the GUI rendering, with correct alpha values. The most important impact is that anti-aliased SpriteFont will be used from now on, and the old XNAExtras stuff is to be removed.&lt;br /&gt; &lt;br /&gt;If anyone is interested in what the problem was, and how I fixed it, then read on.&lt;br /&gt; &lt;br /&gt;In the old system, every control was rendered to its own texture using render targets. Each child control would have its texture combined with those of the other children, to make up the texture of the parent control (after drawing itself). It was quite efficient because only the top level controls (generally windows) actually get their textures drawn to the screen, with the textures only redrawn when necessary, such as when the mouse hovers over a button, and a different image must be displayed. Render targets were also an easy way to perform clipping of child controls within their parent, and allowed the alpha value of a control to affect all children as well.&lt;br /&gt; &lt;br /&gt;The problem with render targets was that control textures had to be drawn to a transparent texture, causing incorrect colour and alpha values to be produced during the alpha blending operation. In practical terms, it means that the edges of sprites with partial transparency and anti-aliased text would be mixed with white (or any other colour depending on the clear colour of the render target). This made either anti-aliased text unreadable, or made the edges of some controls the wrong colour. The reason I couldn't use SpriteFont, was because it created anti-aliased fonts. With XNAExtras I could make a simple font bitmap with colour keyed transparency, which made the text problem go away.&lt;br /&gt; &lt;br /&gt;After playing with render states and pre multiplied alpha for a long time, I finally got fed up and tried to find another way to get it working. I was advised to draw directly to the screen, and use scissor rectangles to handle clipping. This worked great, except performance was abysmal. With just 4 complex windows on the screen, the framerate would start to drop. That was without any game running in the background! The reason for the poor performance was because scissor rectangles must be the same until SpriteBatch.End() is called. This means that I had a SpriteBatch.Begin() and End()  call for every single control!&lt;br /&gt; &lt;br /&gt;Next I decided to implement my own texture clipping, which all worked great, but there wasn't an obvious way to clip text. When using scissor rectangles for just text, the performance was still really bad. The final method was to use a hybrid approach. I would clip sprites on the CPU, and render text to textures which would be cached to allow fast draw calls. The text texture can then be clipped in the same way as the rest of the GUI sprites. Of course there was still the problem of partial alpha pixels being blended with the transparent texture colour. Basically I set the render states to draw with pre multiplied alpha, and set the background clear colour of the texture to the text colour, with the alpha channel set to 0. This means that the blending still takes place, but it produces the correct results. The performance is good once again!&lt;br /&gt; &lt;br /&gt;So yeah, the project isn't dead, I've just had some big problems to deal with. Now that this is working, I will go back to adding more features like Xbox 360 support, and more widgets.&lt;br /&gt; &lt;br /&gt;Thanks,&lt;br /&gt;Aaron&lt;br /&gt;
&lt;/div&gt;</description><author>cdmac</author><pubDate>Wed, 26 Mar 2008 22:34:43 GMT</pubDate><guid isPermaLink="false">UPDATED WIKI: Home 20080326103443P</guid></item><item><title>UPDATED WIKI: Home</title><link>http://www.codeplex.com/wsx/Wiki/View.aspx?title=Home&amp;version=5</link><description>&lt;div class="wikidoc"&gt;
&lt;b&gt;Project Description&lt;/b&gt;&lt;br /&gt; &lt;br /&gt;Window System for XNA allows you to easily add GUI functionality to your games and tools that target the XNA Framework.
 It is being actively developed at the moment, so if anybody is interested in contributing to the project, then please leave a message in the forums.&lt;br /&gt; &lt;br /&gt;&lt;b&gt;Documentation&lt;/b&gt;&lt;br /&gt; &lt;br /&gt;&lt;ul&gt;
&lt;li&gt;&lt;a href="http://www.codeplex.com/wsx/Wiki/View.aspx?title=Reference&amp;amp;referringTitle=Home"&gt;Reference&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.codeplex.com/wsx/Wiki/View.aspx?title=Tutorials&amp;amp;referringTitle=Home"&gt;Tutorials&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt; &lt;br /&gt;&lt;b&gt;News&lt;/b&gt; - 9th February 2008&lt;br /&gt; &lt;br /&gt;There have been a lack of updates lately. Unfortunately I haven't really had time to work with XNA lately because of my job. I get to work on the PlayStation 3 every day, so I can't really complain!&lt;br /&gt; &lt;br /&gt;The good news is that I have a release ready today! The bad news is that something seems wrong with the CodePlex site, so I can't upload the project. Below I've posted some information about the release. I'll try again later today.&lt;br /&gt; &lt;br /&gt;&amp;quot;This release adds support for XML skin definitions. This method replaces the previous method of static properties to change GUI defaults, and is far more flexible. A skin definition can be applied to all subsequent controls, all existing controls, and also to individual controls.&lt;br /&gt; &lt;br /&gt;I will add a short tutorial soon to explain the usage. For now check out the WindowSystemTestbed project that is included in the download, in particular DefaultSkin.skin, which is an XML skin featuring all possible properties set to their defaults.&lt;br /&gt; &lt;br /&gt;Please note that many of the control properties have been changed, removed, or added to accommodate this new skinning system. It is likely that your existing code will break upon first compilation. It shouldn't be too difficult to go through the new class definitions to update your code.&lt;br /&gt; &lt;br /&gt;Additionally, while implementing this I noticed some existing bugs that I had previously missed. I fixed most of them, but the ones remaining may prevent certain control skins from appearing as expected. Please submit all bugs to this site.&amp;quot;&lt;br /&gt; &lt;br /&gt;&lt;b&gt;News&lt;/b&gt; - 5th November 2007&lt;br /&gt; &lt;br /&gt;Sorry about the delay in uploading a new release, but it's finally ready! If anybody is thinking about a broadband provider in the UK, don't use Tiscali!&lt;br /&gt; &lt;br /&gt;As promised, anti-aliased fonts are supported, and XNAExtras has been replaced with XNA SpriteFont. There is a chance it could break some code, as DrawableUIComponent has been removed, because it is now redundant with the new rendering code.&lt;br /&gt; &lt;br /&gt;Now that these long-running problems have been fixed, look forward to new features in the near future.&lt;br /&gt; &lt;br /&gt;&lt;b&gt;News&lt;/b&gt; - 21st September 2007&lt;br /&gt; &lt;br /&gt;Just to let everybody know that there should be a new release within the next week, basically when my internet connection is back up. The reason for the sudden release is because I've finally managed to fix the GUI rendering, with correct alpha values. The most important impact is that anti-aliased SpriteFont will be used from now on, and the old XNAExtras stuff is to be removed.&lt;br /&gt; &lt;br /&gt;If anyone is interested in what the problem was, and how I fixed it, then read on.&lt;br /&gt; &lt;br /&gt;In the old system, every control was rendered to its own texture using render targets. Each child control would have its texture combined with those of the other children, to make up the texture of the parent control (after drawing itself). It was quite efficient because only the top level controls (generally windows) actually get their textures drawn to the screen, with the textures only redrawn when necessary, such as when the mouse hovers over a button, and a different image must be displayed. Render targets were also an easy way to perform clipping of child controls within their parent, and allowed the alpha value of a control to affect all children as well.&lt;br /&gt; &lt;br /&gt;The problem with render targets was that control textures had to be drawn to a transparent texture, causing incorrect colour and alpha values to be produced during the alpha blending operation. In practical terms, it means that the edges of sprites with partial transparency and anti-aliased text would be mixed with white (or any other colour depending on the clear colour of the render target). This made either anti-aliased text unreadable, or made the edges of some controls the wrong colour. The reason I couldn't use SpriteFont, was because it created anti-aliased fonts. With XNAExtras I could make a simple font bitmap with colour keyed transparency, which made the text problem go away.&lt;br /&gt; &lt;br /&gt;After playing with render states and pre multiplied alpha for a long time, I finally got fed up and tried to find another way to get it working. I was advised to draw directly to the screen, and use scissor rectangles to handle clipping. This worked great, except performance was abysmal. With just 4 complex windows on the screen, the framerate would start to drop. That was without any game running in the background! The reason for the poor performance was because scissor rectangles must be the same until SpriteBatch.End() is called. This means that I had a SpriteBatch.Begin() and End()  call for every single control!&lt;br /&gt; &lt;br /&gt;Next I decided to implement my own texture clipping, which all worked great, but there wasn't an obvious way to clip text. When using scissor rectangles for just text, the performance was still really bad. The final method was to use a hybrid approach. I would clip sprites on the CPU, and render text to textures which would be cached to allow fast draw calls. The text texture can then be clipped in the same way as the rest of the GUI sprites. Of course there was still the problem of partial alpha pixels being blended with the transparent texture colour. Basically I set the render states to draw with pre multiplied alpha, and set the background clear colour of the texture to the text colour, with the alpha channel set to 0. This means that the blending still takes place, but it produces the correct results. The performance is good once again!&lt;br /&gt; &lt;br /&gt;So yeah, the project isn't dead, I've just had some big problems to deal with. Now that this is working, I will go back to adding more features like Xbox 360 support, and more widgets.&lt;br /&gt; &lt;br /&gt;Thanks,&lt;br /&gt;Aaron&lt;br /&gt;
&lt;/div&gt;</description><author>cdmac</author><pubDate>Sat, 09 Feb 2008 10:23:20 GMT</pubDate><guid isPermaLink="false">UPDATED WIKI: Home 20080209102320A</guid></item><item><title>UPDATED WIKI: Home</title><link>http://www.codeplex.com/wsx/Wiki/View.aspx?title=Home&amp;version=4</link><description>&lt;div class="wikidoc"&gt;
&lt;b&gt;Project Description&lt;/b&gt;&lt;br /&gt; &lt;br /&gt;Window System for XNA allows you to easily add GUI functionality to your games and tools that target the XNA Framework.
 It is being actively developed at the moment, so if anybody is interested in contributing to the project, then please leave a message in the forums.&lt;br /&gt; &lt;br /&gt;&lt;b&gt;Documentation&lt;/b&gt;&lt;br /&gt; &lt;br /&gt;&lt;ul&gt;
&lt;li&gt;&lt;a href="http://www.codeplex.com/wsx/Wiki/View.aspx?title=Reference&amp;amp;referringTitle=Home"&gt;Reference&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.codeplex.com/wsx/Wiki/View.aspx?title=Tutorials&amp;amp;referringTitle=Home"&gt;Tutorials&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt; &lt;br /&gt;&lt;b&gt;News&lt;/b&gt; - 5th November 2007&lt;br /&gt; &lt;br /&gt;Sorry about the delay in uploading a new release, but it's finally ready! If anybody is thinking about a broadband provider in the UK, don't use Tiscali!&lt;br /&gt; &lt;br /&gt;As promised, anti-aliased fonts are supported, and XNAExtras has been replaced with XNA SpriteFont. There is a chance it could break some code, as DrawableUIComponent has been removed, because it is now redundant with the new rendering code.&lt;br /&gt; &lt;br /&gt;Now that these long-running problems have been fixed, look forward to new features in the near future.&lt;br /&gt; &lt;br /&gt;&lt;b&gt;News&lt;/b&gt; - 21st September 2007&lt;br /&gt; &lt;br /&gt;Just to let everybody know that there should be a new release within the next week, basically when my internet connection is back up. The reason for the sudden release is because I've finally managed to fix the GUI rendering, with correct alpha values. The most important impact is that anti-aliased SpriteFont will be used from now on, and the old XNAExtras stuff is to be removed.&lt;br /&gt; &lt;br /&gt;If anyone is interested in what the problem was, and how I fixed it, then read on.&lt;br /&gt; &lt;br /&gt;In the old system, every control was rendered to its own texture using render targets. Each child control would have its texture combined with those of the other children, to make up the texture of the parent control (after drawing itself). It was quite efficient because only the top level controls (generally windows) actually get their textures drawn to the screen, with the textures only redrawn when necessary, such as when the mouse hovers over a button, and a different image must be displayed. Render targets were also an easy way to perform clipping of child controls within their parent, and allowed the alpha value of a control to affect all children as well.&lt;br /&gt; &lt;br /&gt;The problem with render targets was that control textures had to be drawn to a transparent texture, causing incorrect colour and alpha values to be produced during the alpha blending operation. In practical terms, it means that the edges of sprites with partial transparency and anti-aliased text would be mixed with white (or any other colour depending on the clear colour of the render target). This made either anti-aliased text unreadable, or made the edges of some controls the wrong colour. The reason I couldn't use SpriteFont, was because it created anti-aliased fonts. With XNAExtras I could make a simple font bitmap with colour keyed transparency, which made the text problem go away.&lt;br /&gt; &lt;br /&gt;After playing with render states and pre multiplied alpha for a long time, I finally got fed up and tried to find another way to get it working. I was advised to draw directly to the screen, and use scissor rectangles to handle clipping. This worked great, except performance was abysmal. With just 4 complex windows on the screen, the framerate would start to drop. That was without any game running in the background! The reason for the poor performance was because scissor rectangles must be the same until SpriteBatch.End() is called. This means that I had a SpriteBatch.Begin() and End()  call for every single control!&lt;br /&gt; &lt;br /&gt;Next I decided to implement my own texture clipping, which all worked great, but there wasn't an obvious way to clip text. When using scissor rectangles for just text, the performance was still really bad. The final method was to use a hybrid approach. I would clip sprites on the CPU, and render text to textures which would be cached to allow fast draw calls. The text texture can then be clipped in the same way as the rest of the GUI sprites. Of course there was still the problem of partial alpha pixels being blended with the transparent texture colour. Basically I set the render states to draw with pre multiplied alpha, and set the background clear colour of the texture to the text colour, with the alpha channel set to 0. This means that the blending still takes place, but it produces the correct results. The performance is good once again!&lt;br /&gt; &lt;br /&gt;So yeah, the project isn't dead, I've just had some big problems to deal with. Now that this is working, I will go back to adding more features like Xbox 360 support, and more widgets.&lt;br /&gt; &lt;br /&gt;Thanks,&lt;br /&gt;Aaron&lt;br /&gt;
&lt;/div&gt;</description><author>cdmac</author><pubDate>Mon, 05 Nov 2007 23:30:09 GMT</pubDate><guid isPermaLink="false">UPDATED WIKI: Home 20071105113009P</guid></item><item><title>UPDATED WIKI: Home</title><link>http://www.codeplex.com/wsx/Wiki/View.aspx?title=Home&amp;version=3</link><description>&lt;div class="wikidoc"&gt;
&lt;b&gt;Project Description&lt;/b&gt;&lt;br /&gt; &lt;br /&gt;Window System for XNA allows you to easily add GUI functionality to your games and tools that target the XNA Framework.
 It is being actively developed at the moment, so if anybody is interested in contributing to the project, then please leave a message in the forums.&lt;br /&gt; &lt;br /&gt;&lt;b&gt;Documentation&lt;/b&gt;&lt;br /&gt; &lt;br /&gt;&lt;ul&gt;
&lt;li&gt;&lt;a href="http://www.codeplex.com/wsx/Wiki/View.aspx?title=Reference&amp;amp;referringTitle=Home"&gt;Reference&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.codeplex.com/wsx/Wiki/View.aspx?title=Tutorials&amp;amp;referringTitle=Home"&gt;Tutorials&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt; &lt;br /&gt;&lt;b&gt;News&lt;/b&gt; - 21st September 2007&lt;br /&gt; &lt;br /&gt;Just to let everybody know that there should be a new release within the next week, basically when my internet connection is back up. The reason for the sudden release is because I've finally managed to fix the GUI rendering, with correct alpha values. The most important impact is that anti-aliased SpriteFont will be used from now on, and the old XNAExtras stuff is to be removed.&lt;br /&gt; &lt;br /&gt;If anyone is interested in what the problem was, and how I fixed it, then read on.&lt;br /&gt; &lt;br /&gt;In the old system, every control was rendered to its own texture using render targets. Each child control would have its texture combined with those of the other children, to make up the texture of the parent control (after drawing itself). It was quite efficient because only the top level controls (generally windows) actually get their textures drawn to the screen, with the textures only redrawn when necessary, such as when the mouse hovers over a button, and a different image must be displayed. Render targets were also an easy way to perform clipping of child controls within their parent, and allowed the alpha value of a control to affect all children as well.&lt;br /&gt; &lt;br /&gt;The problem with render targets was that control textures had to be drawn to a transparent texture, causing incorrect colour and alpha values to be produced during the alpha blending operation. In practical terms, it means that the edges of sprites with partial transparency and anti-aliased text would be mixed with white (or any other colour depending on the clear colour of the render target). This made either anti-aliased text unreadable, or made the edges of some controls the wrong colour. The reason I couldn't use SpriteFont, was because it created anti-aliased fonts. With XNAExtras I could make a simple font bitmap with colour keyed transparency, which made the text problem go away.&lt;br /&gt; &lt;br /&gt;After playing with render states and pre multiplied alpha for a long time, I finally got fed up and tried to find another way to get it working. I was advised to draw directly to the screen, and use scissor rectangles to handle clipping. This worked great, except performance was abysmal. With just 4 complex windows on the screen, the framerate would start to drop. That was without any game running in the background! The reason for the poor performance was because scissor rectangles must be the same until SpriteBatch.End() is called. This means that I had a SpriteBatch.Begin() and End()  call for every single control!&lt;br /&gt; &lt;br /&gt;Next I decided to implement my own texture clipping, which all worked great, but there wasn't an obvious way to clip text. When using scissor rectangles for just text, the performance was still really bad. The final method was to use a hybrid approach. I would clip sprites on the CPU, and render text to textures which would be cached to allow fast draw calls. The text texture can then be clipped in the same way as the rest of the GUI sprites. Of course there was still the problem of partial alpha pixels being blended with the transparent texture colour. Basically I set the render states to draw with pre multiplied alpha, and set the background clear colour of the texture to the text colour, with the alpha channel set to 0. This means that the blending still takes place, but it produces the correct results. The performance is good once again!&lt;br /&gt; &lt;br /&gt;So yeah, the project isn't dead, I've just had some big problems to deal with. Now that this is working, I will go back to adding more features like Xbox 360 support, and more widgets.&lt;br /&gt; &lt;br /&gt;Thanks,&lt;br /&gt;Aaron&lt;br /&gt;
&lt;/div&gt;</description><author>cdmac</author><pubDate>Fri, 21 Sep 2007 17:10:34 GMT</pubDate><guid isPermaLink="false">UPDATED WIKI: Home 20070921051034P</guid></item><item><title>UPDATED WIKI: Home</title><link>http://www.codeplex.com/wsx/Wiki/View.aspx?title=Home&amp;version=2</link><description>&lt;div class="wikidoc"&gt;
&lt;b&gt;Project Description&lt;/b&gt;&lt;br /&gt; &lt;br /&gt;Window System for XNA allows you to easily add GUI functionality to your games and tools that target the XNA Framework.
 It is being actively developed at the moment, so if anybody is interested in contributing to the project, then please leave a message in the forums.&lt;br /&gt; &lt;br /&gt;&lt;b&gt;Documentation&lt;/b&gt;&lt;br /&gt; &lt;br /&gt;&lt;ul&gt;
&lt;li&gt;&lt;a href="http://www.codeplex.com/wsx/Wiki/View.aspx?title=Reference&amp;amp;referringTitle=Home"&gt;Reference&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.codeplex.com/wsx/Wiki/View.aspx?title=Tutorials&amp;amp;referringTitle=Home"&gt;Tutorials&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;</description><author>cdmac</author><pubDate>Sun, 26 Aug 2007 16:47:34 GMT</pubDate><guid isPermaLink="false">UPDATED WIKI: Home 20070826044734P</guid></item><item><title>UPDATED WIKI: Tutorial 2</title><link>http://www.codeplex.com/wsx/Wiki/View.aspx?title=Tutorial 2&amp;version=2</link><description>&lt;div class="wikidoc"&gt;
&lt;h1&gt;
Tutorial 2
&lt;/h1&gt; &lt;br /&gt;This next tutorial will cover how to create a class that inherits from Dialog, and retrieve some useful information from it. This method of using windows was developed while putting together my tile map editor application. It is the best way of using the GUI that I have discovered so far, and is pretty closely based on other window systems I've used in the past. I'm sure some other techniques will expose themselves in the future.&lt;br /&gt; &lt;br /&gt;&lt;h2&gt;
Setting Up The Project
&lt;/h2&gt; &lt;br /&gt;I have already covered setting up a new project, and setting up the GUIManager in &lt;a href="http://www.codeplex.com/wsx/Wiki/View.aspx?title=Tutorial%201&amp;amp;referringTitle=Tutorial%202"&gt;Tutorial 1&lt;/a&gt;, so you can go back and look it up there if necessary. Simply follow Tutorial 1 up until the Adding Controls heading, and you'll be ready to go.&lt;br /&gt; &lt;br /&gt;&lt;h2&gt;
Creating The Dialog
&lt;/h2&gt; &lt;br /&gt;We will create a Dialog box, where the user can enter their name into a textbox. It will have OK and Cancel buttons, so that the dialog can return a result.&lt;br /&gt; &lt;br /&gt;The first thing to do is to create a new class called UserDetailsDialog, which is inherited from Dialog. Dialog is inherited from Window, and the only addition is that it returns a result, which can be queried after the Dialog is closed.&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
using System;
using Microsoft.Xna.Framework;
using WindowSystem;
 
namespace WindowSystemTestbed
{
    public class UserDetailsDialog : Dialog
    {
    }
}
&lt;/pre&gt; &lt;br /&gt;Next we can add a few fields to our new class.&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
private const int LargeSeparation = 10;
private const int SmallSeparation = 5;
private TextButton OKButton;
private TextButton cancelButton;
private TextBox nameTextBox;
&lt;/pre&gt; &lt;br /&gt;The LargeSeparation and SmallSeparation constants are something I add to all my dialogs. They allow me to control the spacing between the window edge and between dialog controls. I use LargeSeparation for the window edge, and between unrelated controls. SmallSeparation is used for the space between related controls, like between a textbox and it's label.&lt;br /&gt; &lt;br /&gt;The rest of the fields are controls that we will need to keep track of after they are set up. We will need to get the text from nameTextBox for example. Other controls like labels can just be added without keeping a reference if they don't need to change, or we don't need to query them after events are triggered.&lt;br /&gt; &lt;br /&gt;Next we should add a property, so that the user's name can be queried from outside the class.&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
public string Name
{
    get { return this.nameTextBox.Text; }
}
&lt;/pre&gt; &lt;br /&gt;The constructor sets the control properties and adds them as child controls, as well as settings it's own properties.&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
public UserDetailsDialog(Game game, GUIManager guiManager)
    : base(game, guiManager)
{
    // Name label
    Label nameLabel = new Label(game, guiManager);
    Add(nameLabel);
    nameLabel.Text = &amp;quot;Name:&amp;quot;;
    nameLabel.X = LargeSeperation;
    nameLabel.Y = LargeSeperation;
    nameLabel.Width = 75;
    nameLabel.Height = nameLabel.TextHeight;
 
    // Name textbox
    this.nameTextBox = new TextBox(game, guiManager);
    Add(this.nameTextBox);
    this.nameTextBox.Initialize();
    this.nameTextBox.X = nameLabel.X;
    this.nameTextBox.Y = nameLabel.Y + nameLabel.Height + SmallSeperation;
 
    // Set the window width to the default textbox width
    ClientWidth = nameTextBox.Width + (2 * LargeSeperation);
 
    // Cancel button
    this.cancelButton = new TextButton(game, guiManager);
    Add(this.cancelButton);
    this.cancelButton.Text = &amp;quot;Cancel&amp;quot;;
    this.cancelButton.X = ClientWidth - this.cancelButton.Width - LargeSeperation;
    this.cancelButton.Y = this.nameTextBox.Y + this.nameTextBox.Height + LargeSeperation;
    this.cancelButton.Click += new ClickHandler(OnButtonClicked);
 
    // OK button
    this.OKButton = new TextButton(game, guiManager);
    Add(this.OKButton);
    this.OKButton.Text = &amp;quot;OK&amp;quot;;
    this.OKButton.X = this.cancelButton.X - SmallSeperation - this.OKButton.Width;
    this.OKButton.Y = this.cancelButton.Y;
    this.OKButton.Click += new ClickHandler(OnButtonClicked);
 
    // Set the window height to the amount needed to show all controls
    ClientHeight = this.OKButton.Y + this.OKButton.Height + LargeSeperation;
 
    // Set the window title
    TitleText = &amp;quot;User Details&amp;quot;;
 
    // This dialog does not need to be resized by the user
    Resizable = false;
    CenterWindow();
}
&lt;/pre&gt; &lt;br /&gt;Note that I add child controls before setting their properties. This is because some controls don't become fully set up until they are initialised, which happens automatically when they are added to the GUI or another control. You could also just call Initialize() manually, but who needs the extra typing?&lt;br /&gt; &lt;br /&gt;Also notice that control positions are set in relation to each other. I find this keeps the layout quite dynamic, especially for resizeable windows. I will consider providing layout managers in a future release, perhaps similar to those found in the Java Swing library.&lt;br /&gt; &lt;br /&gt;The TextBox and TextButton controls don't have their Width or Height properties set. That's because some controls have useful default sizes, which allows some flexibility when modifying the default GUI settings.&lt;br /&gt; &lt;br /&gt;Next we will add an event handler to the class, which will be called whenever a button is clicked. The buttons had this event handler added for their Click events in the constructor.&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
protected void OnButtonClicked(UIComponent sender)
{
    if (sender == this.OKButton)
         SetDialogResult(DialogResult.OK);
 
    CloseWindow();}
&lt;/pre&gt; &lt;br /&gt;This method simply checks which button was clicked, and sets the result accordingly before closing the dialog. We don't bother checking for the Cancel button because cancel is the default result. This is because that is also the result when the user clicks on the window close button. If necessary the close button can be removed by setting the HasCloseButton property to false.&lt;br /&gt; &lt;br /&gt;&lt;h2&gt;
Using The Dialog
&lt;/h2&gt; &lt;br /&gt;Back to the main game class which I have called Tutorial2, and we're going to attempt to use our new dialog.&lt;br /&gt; &lt;br /&gt;The application will show an information message box, explaining how to use our simple program, then show our User Details dialog box when the user presses enter. If the user clicks on the OK button, a message box will display the name entered into the dialog textbox.&lt;br /&gt; &lt;br /&gt;Firstly, add a dialog reference to our Game class.&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
private UserDetailsDialog dialog;
&lt;/pre&gt; &lt;br /&gt;Next add an event handler that will be called when the user presses a key. In the constructor add the following code.&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
// Add a key down event handler
this.input.KeyDown += new KeyDownHandler(OnKeyDown);
&lt;/pre&gt; &lt;br /&gt;Then create the event handler method.&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
private void OnKeyDown(KeyEventArgs args)
{
    if (args.Key == Keys.Enter)
    {
        // Only create a new dialog if one isn't already shown
        if (this.gui.GetModal() == null)
        {
            // Create and show dialog
            this.dialog = new UserDetailsDialog(this, this.gui);
            this.dialog.Close += new CloseHandler(OnDialogClosed);
            this.dialog.Show(true);
         }
    }
}
&lt;/pre&gt; &lt;br /&gt;Basically this function just checks that no other modal window is already opened, if not then it pops up a new User Details dialog. Modal just means any window that has exclusive focus, such as a message box, or our dialog. To show a window as modal, pass true to the Window.Show() method, otherwise pass false.&lt;br /&gt; &lt;br /&gt;When your program calls a modal dialog in Windows, it takes full control of you're processing until the dialog is closed. Unfortunately, our system is a little different. We have to add an event handler to the window's Close event, that checks which window was closed, and acts accordingly.&lt;br /&gt; &lt;br /&gt;The following code is the method called when our dialog is closed.&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
private void OnDialogClosed(UIComponent sender)
{
    if (sender == this.dialog)
    {
        if (this.dialog.DialogResult == DialogResult.OK)
        {
            MessageBox message = new MessageBox(
                this,
                this.gui,
                &amp;quot;Name: &amp;quot; + this.dialog.Name,
                &amp;quot;User Name&amp;quot;,
                MessageBoxButtons.OK,
                MessageBoxType.Info
                );
                message.Show(true);
        }
 
        // Remove event handler so garbage collector will pick it up
        this.dialog.Close -= OnDialogClosed;
        this.dialog = null;
    }
}
&lt;/pre&gt; &lt;br /&gt;A message box is shown repeating the name entered by the user, only if the result was OK. Then the event handler is removed from the dialog and the dialog is set to null, to prevent it from lingering about in memory. This is very important to remember, especially in a real application. I've caught out by event handlers and the garbage collector on few occasions.&lt;br /&gt; &lt;br /&gt;The final things to add is a message box explaining how to use the application. This should be placed in the Game class Initialize() method, to ensure it's shown at the start of the program.&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
// Show a message box informing the user how to use the program
MessageBox info = new MessageBox(
    this,
    this.gui,
    &amp;quot;Press enter to bring up the dialog.&amp;quot;,
    &amp;quot;Info&amp;quot;,
    MessageBoxButtons.OK,
    MessageBoxType.Info
    );
info.Show(true);
&lt;/pre&gt; &lt;br /&gt;&lt;h2&gt;
Conclusion
&lt;/h2&gt; &lt;br /&gt;I hope this tutorial was helpful, it was definitely more difficult to write than the last one. I would really appreciate any feedback. I think in the next tutorial I will cover skinning and modifying the GUI.&lt;br /&gt; &lt;br /&gt;All tutorial source code is included in the WindowSystemTestbed project.&lt;br /&gt;
&lt;/div&gt;</description><author>cdmac</author><pubDate>Sun, 26 Aug 2007 16:33:46 GMT</pubDate><guid isPermaLink="false">UPDATED WIKI: Tutorial 2 20070826043346P</guid></item><item><title>UPDATED WIKI: Tutorial 2</title><link>http://www.codeplex.com/wsx/Wiki/View.aspx?title=Tutorial 2&amp;version=1</link><description>&lt;div class="wikidoc"&gt;
&lt;h1&gt;
Tutorial 2
&lt;/h1&gt; &lt;br /&gt;This next tutorial will cover how to create a class that inherits from Dialog, and retrieve some useful information from it. This method of using windows was developed while putting together my tile map editor application. It is the best way of using the GUI that I have discovered so far, and is pretty closely based on other window systems I've used in the past. I'm sure some other techniques will expose themselves in the future.&lt;br /&gt; &lt;br /&gt;&lt;h2&gt;
Setting Up The Project
&lt;/h2&gt; &lt;br /&gt;I have already covered setting up a new project, and setting up the GUIManager in &lt;a href="http://www.codeplex.com/wsx/Wiki/View.aspx?title=Tutorial%201&amp;amp;referringTitle=Tutorial%202"&gt;Tutorial 1&lt;/a&gt;, so you can go back and look it up there if necessary. Simply follow Tutorial 1 up until the Adding Controls heading, and you'll be ready to go.&lt;br /&gt; &lt;br /&gt;&lt;h2&gt;
Creating The Dialog
&lt;/h2&gt; &lt;br /&gt;We will create a Dialog box, where the user can enter their name into a textbox. It will have OK and Cancel buttons, so that the dialog can return a result.&lt;br /&gt; &lt;br /&gt;The first thing to do is to create a new class called UserDetailsDialog, which is inherited from Dialog. Dialog is inherited from Window, and the only addition is that it returns a result, which can be queried after the Dialog is closed.&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
using System;
using Microsoft.Xna.Framework;
using WindowSystem;
 
namespace WindowSystemTestbed
{
    public class UserDetailsDialog : Dialog
    {
    }
}
&lt;/pre&gt; &lt;br /&gt;Next we can add a few fields to our new class.&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
private const int LargeSeparation = 10;
private const int SmallSeparation = 5;
private TextButton OKButton;
private TextButton cancelButton;
private TextBox nameTextBox;
&lt;/pre&gt; &lt;br /&gt;The LargeSeparation and SmallSeparation constants are something I add to all my dialogs. They allow me to control the spacing between the window edge and between dialog controls. I use LargeSeparation for the window edge, and between unrelated controls. SmallSeparation is used for the space between related controls, like between a textbox and it's label.&lt;br /&gt; &lt;br /&gt;The rest of the fields are controls that we will need to keep track of after they are set up. We will need to get the text from nameTextBox for example. Other controls like labels can just be added without keeping a reference if they don't need to change, or we don't need to query them after events are triggered.&lt;br /&gt; &lt;br /&gt;Next we should add a property, so that the user's name can be queried from outside the class.&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
public string Name
{
    get { return this.nameTextBox.Text; }
}
&lt;/pre&gt; &lt;br /&gt;The constructor sets the control properties and adds them as child controls, as well as settings it's own properties.&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
public UserDetailsDialog(Game game, GUIManager guiManager)
    : base(game, guiManager)
{
    // Name label
    Label nameLabel = new Label(game, guiManager);
    Add(nameLabel);
    nameLabel.Text = &amp;quot;Name:&amp;quot;;
    nameLabel.X = LargeSeperation;
    nameLabel.Y = LargeSeperation;
    nameLabel.Width = 75;
    nameLabel.Height = nameLabel.TextHeight;
 
    // Name textbox
    this.nameTextBox = new TextBox(game, guiManager);
    Add(this.nameTextBox);
    this.nameTextBox.Initialize();
    this.nameTextBox.X = nameLabel.X;
    this.nameTextBox.Y = nameLabel.Y + nameLabel.Height + SmallSeperation;
    // Set the window width to the default textbox width
 
    ClientWidth = nameTextBox.Width + (2 * LargeSeperation);
 
    // Cancel button
    this.cancelButton = new TextButton(game, guiManager);
    Add(this.cancelButton);
    this.cancelButton.Text = &amp;quot;Cancel&amp;quot;;
    this.cancelButton.X = ClientWidth - this.cancelButton.Width - LargeSeperation;
    this.cancelButton.Y = this.nameTextBox.Y + this.nameTextBox.Height + LargeSeperation;
    this.cancelButton.Click += new ClickHandler(OnButtonClicked);
    // OK button
 
    this.OKButton = new TextButton(game, guiManager);
    Add(this.OKButton);
    this.OKButton.Text = &amp;quot;OK&amp;quot;;
    this.OKButton.X = this.cancelButton.X - SmallSeperation - this.OKButton.Width;
    this.OKButton.Y = this.cancelButton.Y;
    this.OKButton.Click += new ClickHandler(OnButtonClicked);
 
    // Set the window height to the amount needed to show all controls
    ClientHeight = this.OKButton.Y + this.OKButton.Height + LargeSeperation;
 
    // Set the window title
    TitleText = &amp;quot;User Details&amp;quot;;
 
    // This dialog does not need to be resized by the user
    Resizable = false;
    CenterWindow();
}
 
Note that I add child controls before setting their properties. This is because some controls don't become fully set up until they are initialised, which happens automatically when they are added to the GUI or another control. You could also just call Initialize() manually, but who needs the extra typing?
 
Also notice that control positions are set in relation to each other. I find this keeps the layout quite dynamic, especially for resizeable windows. I will consider providing layout managers in a future release, perhaps similar to those found in the Java Swing library.
 
The TextBox and TextButton controls don't have their Width or Height properties set. That's because some controls have useful default sizes, which allows some flexibility when modifying the default GUI settings.
 
Next we will add an event handler to the class, which will be called whenever a button is clicked. The buttons had this event handler added for their Click events in the constructor.
 
{{
protected void OnButtonClicked(UIComponent sender)
{
    if (sender == this.OKButton)
         SetDialogResult(DialogResult.OK);
 
    CloseWindow();}
&lt;/pre&gt; &lt;br /&gt;This method simply checks which button was clicked, and sets the result accordingly before closing the dialog. We don't bother checking for the Cancel button because cancel is the default result. This is because that is also the result when the user clicks on the window close button. If necessary the close button can be removed by setting the HasCloseButton property to false.&lt;br /&gt; &lt;br /&gt;&lt;h2&gt;
Using The Dialog
&lt;/h2&gt; &lt;br /&gt;Back to the main game class which I have called Tutorial2, and we're going to attempt to use our new dialog.&lt;br /&gt; &lt;br /&gt;The application will show an information message box, explaining how to use our simple program, then show our User Details dialog box when the user presses enter. If the user clicks on the OK button, a message box will display the name entered into the dialog textbox.&lt;br /&gt; &lt;br /&gt;Firstly, add a dialog reference to our Game class.&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
private UserDetailsDialog dialog;
&lt;/pre&gt; &lt;br /&gt;Next add an event handler that will be called when the user presses a key. In the constructor add the following code.&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
// Add a key down event handler
this.input.KeyDown += new KeyDownHandler(OnKeyDown);
&lt;/pre&gt; &lt;br /&gt;Then create the event handler method.&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
private void OnKeyDown(KeyEventArgs args)
{
    if (args.Key == Keys.Enter)
    {
        // Only create a new dialog if one isn't already shown
        if (this.gui.GetModal() == null)
        {
            // Create and show dialog
            this.dialog = new UserDetailsDialog(this, this.gui);
            this.dialog.Close += new CloseHandler(OnDialogClosed);
            this.dialog.Show(true);
         }
    }
}
&lt;/pre&gt; &lt;br /&gt;Basically this function just checks that no other modal window is already opened, if not then it pops up a new User Details dialog. Modal just means any window that has exclusive focus, such as a message box, or our dialog. To show a window as modal, pass true to the Window.Show() method, otherwise pass false.&lt;br /&gt; &lt;br /&gt;When your program calls a modal dialog in Windows, it takes full control of you're processing until the dialog is closed. Unfortunately, our system is a little different. We have to add an event handler to the window's Close event, that checks which window was closed, and acts accordingly.&lt;br /&gt; &lt;br /&gt;The following code is the method called when our dialog is closed.&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
private void OnDialogClosed(UIComponent sender)
{
    if (sender == this.dialog)
    {
        if (this.dialog.DialogResult == DialogResult.OK)
        {
            MessageBox message = new MessageBox(
                this,
                this.gui,
                &amp;quot;Name: &amp;quot; + this.dialog.Name,
                &amp;quot;User Name&amp;quot;,
                MessageBoxButtons.OK,
                MessageBoxType.Info
                );
                message.Show(true);
        }
 
        // Remove event handler so garbage collector will pick it up
        this.dialog.Close -= OnDialogClosed;
        this.dialog = null;
    }
}
&lt;/pre&gt; &lt;br /&gt;A message box is shown repeating the name entered by the user, only if the result was OK. Then the event handler is removed from the dialog and the dialog is set to null, to prevent it from lingering about in memory. This is very important to remember, especially in a real application. I've caught out by event handlers and the garbage collector on few occasions.&lt;br /&gt; &lt;br /&gt;The final things to add is a message box explaining how to use the application. This should be placed in the Game class Initialize() method, to ensure it's shown at the start of the program.&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
// Show a message box informing the user how to use the program
MessageBox info = new MessageBox(
    this,
    this.gui,
    &amp;quot;Press enter to bring up the dialog.&amp;quot;,
    &amp;quot;Info&amp;quot;,
    MessageBoxButtons.OK,
    MessageBoxType.Info
    );
info.Show(true);
&lt;/pre&gt; &lt;br /&gt;&lt;h2&gt;
Conclusion
&lt;/h2&gt; &lt;br /&gt;I hope this tutorial was helpful, it was definitely more difficult to write than the last one. I would really appreciate any feedback. I think in the next tutorial I will cover skinning and modifying the GUI.&lt;br /&gt; &lt;br /&gt;All tutorial source code is included in the WindowSystemTestbed project.&lt;br /&gt;
&lt;/div&gt;</description><author>cdmac</author><pubDate>Sun, 26 Aug 2007 16:29:57 GMT</pubDate><guid isPermaLink="false">UPDATED WIKI: Tutorial 2 20070826042957P</guid></item><item><title>UPDATED WIKI: Tutorial 1</title><link>http://www.codeplex.com/wsx/Wiki/View.aspx?title=Tutorial 1&amp;version=2</link><description>&lt;div class="wikidoc"&gt;
&lt;h1&gt;
Tutorial 1
&lt;/h1&gt; &lt;br /&gt;This first tutorial will cover setting up a GUIManager object, adding new controls, and handling their events.&lt;br /&gt; &lt;br /&gt;&lt;h2&gt;
Setting Up The Project
&lt;/h2&gt; &lt;br /&gt;The simplest way to begin is to use the WindowSystemTestbed project as a starting template. I simply created a new source file containing a class called Tutorial1, and set that as the startup Game object in Main. You can use this if you don't feel like starting a project from scratch.&lt;br /&gt; &lt;br /&gt;&lt;h2&gt;
Setting Up The GUIManager
&lt;/h2&gt; &lt;br /&gt;The first thing to do is to add a couple using statements for the InputEventSystem and WindowSystem namespaces.&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
using System;
using Microsoft.Xna.Framework;
...
using InputEventSystem;
using WindowSystem;
&lt;/pre&gt; &lt;br /&gt;Now add some fields.&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
private GraphicsDeviceManager graphics;
private InputEvents input;
private GUIManager gui;
&lt;/pre&gt; &lt;br /&gt;In the constructor we set up these objects, and add input and gui to the list of game components. It is important that the InputEvents object is created before the GUIManager object because it adds itself to the game services in the constructor, which the GUI will need access to. Not creating an InputEvents object at all will cause the program to crash.&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
public Tutorial1()
{
    this.graphics = new GraphicsDeviceManager(this);
    this.input = new InputEvents(this);
    Components.Add(this.input);
    this.gui = new GUIManager(this);
    Components.Add(this.gui);
    // GUI requires variable timing to function correctly
    IsFixedTimeStep = false;
    Window.Title = &amp;quot;Window System Tutorial 1&amp;quot;;
}
&lt;/pre&gt; &lt;br /&gt;The GUIManager object should be initialised in the overriden Initialize() method, before any child controls are added. This is so that order of resource loading can be predicted.&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
protected override void Initialize()
{
    // Has to be initialised before child controls can be added
    this.gui.Initialize();
    base.Initialize();
}
&lt;/pre&gt; &lt;br /&gt;You will also want to override the Draw() method, to clear the screen each frame, although this probably doesn't affect the GUI as it handles drawing itself.&lt;br /&gt; &lt;br /&gt;&lt;h2&gt;
Adding Controls
&lt;/h2&gt; &lt;br /&gt;I'm going to use a menu bar with various menus and menu items as an example. This will show how to create controls, how to add them to the GUI, and how to handle their events.&lt;br /&gt; &lt;br /&gt;First we should add some fields, which are the menu bar and the menu items that the user will actually select. This means that we don't actually need to keep a reference to the 'File' menu for example, because it handles itself. We do need to keep references to child menu items that will actually be clicked, so that we can determine which one was selected. An example would be the 'New' or 'Save' menu items.&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
private MenuBar menuBar;
private MenuItem newMenuItem;
private MenuItem openMenuItem;
private MenuItem saveMenuItem;
private MenuItem saveAsMenuItem;
private MenuItem exitMenuItem;
private MenuItem undoMenuItem;
private MenuItem redoMenuItem;
&lt;/pre&gt; &lt;br /&gt;Next we have to actually set up the GUI objects, and add them to the GUI. This should take place in Initialize(), after the GUIManager has been initialised.&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
this.menuBar = new MenuBar(this, gui);
MenuItem fileMenu = new MenuItem(this, gui);
fileMenu.Text = &amp;quot;File&amp;quot;;
this.newMenuItem = new MenuItem(this, gui);
this.newMenuItem.Text = &amp;quot;New...&amp;quot;;
fileMenu.Add(this.newMenuItem);
this.openMenuItem = new MenuItem(this, gui);
this.openMenuItem.Text = &amp;quot;Open...&amp;quot;;
fileMenu.Add(this.openMenuItem);
this.saveMenuItem = new MenuItem(this, gui);
this.saveMenuItem.Text = &amp;quot;Save&amp;quot;;
this.saveMenuItem.IsEnabled = false;
fileMenu.Add(this.saveMenuItem);
this.saveAsMenuItem = new MenuItem(this, gui);
this.saveAsMenuItem.Text = &amp;quot;Save As...&amp;quot;;
this.saveAsMenuItem.IsEnabled = false;
fileMenu.Add(this.saveAsMenuItem);
this.exitMenuItem = new MenuItem(this, gui);
this.exitMenuItem.Text = &amp;quot;Exit&amp;quot;;
fileMenu.Add(this.exitMenuItem);
menuBar.Add(fileMenu);
MenuItem editMenu = new MenuItem(this, gui);
editMenu.Text = &amp;quot;Edit&amp;quot;;
this.undoMenuItem = new MenuItem(this, gui);
this.undoMenuItem.Text = &amp;quot;Undo&amp;quot;;
this.undoMenuItem.IsEnabled = false;
editMenu.Add(this.undoMenuItem);
this.redoMenuItem = new MenuItem(this, gui);
this.redoMenuItem.Text = &amp;quot;Redo&amp;quot;;
this.redoMenuItem.IsEnabled = false;
editMenu.Add(this.redoMenuItem);
this.menuBar.Add(editMenu);
// Add menubar to gui
this.gui.Add(this.menuBar);
&lt;/pre&gt; &lt;br /&gt;You may notice that some of the menu items have a property called IsEnabled set to false. This basically makes the item grey and unclickable, just how Windows does it. This property only applies to MenuItem objects currently, but at some point in the future, I will probably make it apply to all controls.&lt;br /&gt; &lt;br /&gt;Now if you run the application, it should show a menu bar with all the new menus and menu items.&lt;br /&gt; &lt;br /&gt;&lt;h2&gt;
Control Events
&lt;/h2&gt; &lt;br /&gt;Next we will add event handlers that will be called whenever a menu item is clicked. The reason for holding references to menu items is for comparison with the clicked control, determining which one was actually clicked.&lt;br /&gt; &lt;br /&gt;So add the following code to the Initialize() method, probably after the menu bar is added to the GUI.&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
// Add event handlers
this.newMenuItem.Click += new ClickHandler(OnMenuItemClicked);
this.openMenuItem.Click += new ClickHandler(OnMenuItemClicked);
this.exitMenuItem.Click += new ClickHandler(OnMenuItemClicked);
this.undoMenuItem.Click += new ClickHandler(OnMenuItemClicked);
this.redoMenuItem.Click += new ClickHandler(OnMenuItemClicked);
&lt;/pre&gt; &lt;br /&gt;Finally we need to add a new method that is called whenever a menu item is clicked. We simply check which item was clicked, and act accordingly.&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
private void OnMenuItemClicked(UIComponent sender)
{
    if (sender == this.newMenuItem)
    {
        MessageBox messageBox = new MessageBox(
            this,
            gui,
            &amp;quot;New clicked!&amp;quot;,
            &amp;quot;Tutorial 1&amp;quot;,
            MessageBoxButtons.OK,
            MessageBoxType.Info
        );
        messageBox.Show(true);
    }
    else if (sender == this.openMenuItem)
    {
        MessageBox messageBox = new MessageBox(
            this,
            gui,
            &amp;quot;Open clicked!&amp;quot;,
            &amp;quot;Tutorial 1&amp;quot;,
            MessageBoxButtons.OK,
            MessageBoxType.Info
        );
        messageBox.Show(true);
    }
    else if (sender == this.undoMenuItem)
    {
        MessageBox messageBox = new MessageBox(
            this,
            gui,
            &amp;quot;Undo clicked!&amp;quot;,
            &amp;quot;Tutorial 1&amp;quot;,
            MessageBoxButtons.OK,
            MessageBoxType.Info
        );
        messageBox.Show(true);
    }
    else if (sender == this.redoMenuItem)
    {
        MessageBox messageBox = new MessageBox(
            this,
            gui,
            &amp;quot;Redo clicked!&amp;quot;,
            &amp;quot;Tutorial 1&amp;quot;,
            MessageBoxButtons.OK,
            MessageBoxType.Info
        );
        messageBox.Show(true);
    }
    else if (sender == this.exitMenuItem)
        Exit();
}
&lt;/pre&gt; &lt;br /&gt;&lt;h2&gt;
Summary
&lt;/h2&gt; &lt;br /&gt;This first tutorial was really simple, but should show you the basics of using the window system. It should be enough if all you want to do is add a couple buttons to your game. In the next tutorial I will show how to create a class that inherits from Window, to demonstrate how to begin to create a real application.&lt;br /&gt;
&lt;/div&gt;</description><author>cdmac</author><pubDate>Sun, 26 Aug 2007 15:30:32 GMT</pubDate><guid isPermaLink="false">UPDATED WIKI: Tutorial 1 20070826033032P</guid></item><item><title>UPDATED WIKI: Tutorials</title><link>http://www.codeplex.com/wsx/Wiki/View.aspx?title=Tutorials&amp;version=1</link><description>&lt;div class="wikidoc"&gt;
&lt;h1&gt;
Tutorials
&lt;/h1&gt; &lt;br /&gt;&lt;ul&gt;
&lt;li&gt;&lt;a href="http://www.codeplex.com/wsx/Wiki/View.aspx?title=Tutorial%201&amp;amp;referringTitle=Tutorials"&gt;Tutorial 1&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.codeplex.com/wsx/Wiki/View.aspx?title=Tutorial%202&amp;amp;referringTitle=Tutorials"&gt;Tutorial 2&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;</description><author>cdmac</author><pubDate>Sun, 26 Aug 2007 15:30:11 GMT</pubDate><guid isPermaLink="false">UPDATED WIKI: Tutorials 20070826033011P</guid></item><item><title>UPDATED WIKI: Tutorial 1</title><link>http://www.codeplex.com/wsx/Wiki/View.aspx?title=Tutorial 1&amp;version=1</link><description>&lt;div class="wikidoc"&gt;
&lt;h1&gt;
Tutorial 1
&lt;/h1&gt; &lt;br /&gt;This first tutorial will cover setting up a GUIManager object, adding new controls, and handling their events.&lt;br /&gt; &lt;br /&gt;&lt;h2&gt;
Setting Up The Project
&lt;/h2&gt; &lt;br /&gt;The simplest way to begin is to use the WindowSystemTestbed project as a starting template. I simply created a new source file containing a class called Tutorial1, and set that as the startup Game object in Main. You can use this if you don't feel like starting a project from scratch.&lt;br /&gt; &lt;br /&gt;&lt;h2&gt;
Setting Up The GUIManager
&lt;/h2&gt; &lt;br /&gt;The first thing to do is to add a couple using statements for the InputEventSystem and WindowSystem namespaces.&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
using System;
using Microsoft.Xna.Framework;
...
using InputEventSystem;
using WindowSystem;
&lt;/pre&gt; &lt;br /&gt;Now add some fields.&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
private GraphicsDeviceManager graphics;
private InputEvents input;
private GUIManager gui;
&lt;/pre&gt; &lt;br /&gt;In the constructor we set up these objects, and add input and gui to the list of game components. It is important that the InputEvents object is created before the GUIManager object because it adds itself to the game services in the constructor, which the GUI will need access to. Not creating an InputEvents object at all will cause the program to crash.&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
public Tutorial1()
{
    this.graphics = new GraphicsDeviceManager(this);
    this.input = new InputEvents(this);
    Components.Add(this.input);
    this.gui = new GUIManager(this);
    Components.Add(this.gui);
    // GUI requires variable timing to function correctly
    IsFixedTimeStep = false;
    Window.Title = &amp;quot;Window System Tutorial 1&amp;quot;;
}
&lt;/pre&gt; &lt;br /&gt;The GUIManager object should be initialised in the overriden Initialize() method, before any child controls are added. This is so that order of resource loading can be predicted.&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
protected override void Initialize()
{
    // Has to be initialised before child controls can be added
    this.gui.Initialize();
    base.Initialize();
}
&lt;/pre&gt; &lt;br /&gt;You will also want to override the Draw() method, to clear the screen each frame, although this probably doesn't affect the GUI as it handles drawing itself.&lt;br /&gt; &lt;br /&gt;&lt;h2&gt;
Adding Controls
&lt;/h2&gt; &lt;br /&gt;I'm going to use a menu bar with various menus and menu items as an example. This will show how to create controls, how to add them to the GUI, and how to handle their events.&lt;br /&gt; &lt;br /&gt;First we should add some fields, which are the menu bar and the menu items that the user will actually select. This means that we don't actually need to keep a reference to the 'File' menu for example, because it handles itself. We do need to keep references to child menu items that will actually be clicked, so that we can determine which one was selected. An example would be the 'New' or 'Save' menu items.&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
private MenuBar menuBar;
private MenuItem newMenuItem;
private MenuItem openMenuItem;
private MenuItem saveMenuItem;
private MenuItem saveAsMenuItem;
private MenuItem exitMenuItem;
private MenuItem undoMenuItem;
private MenuItem redoMenuItem;
&lt;/pre&gt; &lt;br /&gt;Next we have to actually set up the GUI objects, and add them to the GUI. This should take place in Initialize(), after the GUIManager has been initialised.&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
this.menuBar = new MenuBar(this, gui);
MenuItem fileMenu = new MenuItem(this, gui);
fileMenu.Text = &amp;quot;File&amp;quot;;
this.newMenuItem = new MenuItem(this, gui);
this.newMenuItem.Text = &amp;quot;New...&amp;quot;;
fileMenu.Add(this.newMenuItem);
this.openMenuItem = new MenuItem(this, gui);
this.openMenuItem.Text = &amp;quot;Open...&amp;quot;;
fileMenu.Add(this.openMenuItem);
this.saveMenuItem = new MenuItem(this, gui);
this.saveMenuItem.Text = &amp;quot;Save&amp;quot;;
this.saveMenuItem.IsEnabled = false;
fileMenu.Add(this.saveMenuItem);
this.saveAsMenuItem = new MenuItem(this, gui);
this.saveAsMenuItem.Text = &amp;quot;Save As...&amp;quot;;
this.saveAsMenuItem.IsEnabled = false;
fileMenu.Add(this.saveAsMenuItem);
this.exitMenuItem = new MenuItem(this, gui);
this.exitMenuItem.Text = &amp;quot;Exit&amp;quot;;
fileMenu.Add(this.exitMenuItem);
menuBar.Add(fileMenu);
MenuItem editMenu = new MenuItem(this, gui);
editMenu.Text = &amp;quot;Edit&amp;quot;;
this.undoMenuItem = new MenuItem(this, gui);
this.undoMenuItem.Text = &amp;quot;Undo&amp;quot;;
this.undoMenuItem.IsEnabled = false;
editMenu.Add(this.undoMenuItem);
this.redoMenuItem = new MenuItem(this, gui);
this.redoMenuItem.Text = &amp;quot;Redo&amp;quot;;
this.redoMenuItem.IsEnabled = false;
editMenu.Add(this.redoMenuItem);
this.menuBar.Add(editMenu);
// Add menubar to gui
this.gui.Add(this.menuBar);
&lt;/pre&gt; &lt;br /&gt;You may notice that some of the menu items have a property called IsEnabled set to false. This basically makes the item grey and unclickable, just how Windows does it. This property only applies to MenuItem objects currently, but at some point in the future, I will probably make it apply to all controls.&lt;br /&gt; &lt;br /&gt;Now if you run the application, it should show a menu bar with all the new menus and menu items.&lt;br /&gt; &lt;br /&gt;&lt;h2&gt;
Control Events
&lt;/h2&gt; &lt;br /&gt;Next we will add event handlers that will be called whenever a menu item is clicked. The reason for holding references to menu items is for comparison with the clicked control, determining which one was actually clicked.&lt;br /&gt; &lt;br /&gt;So add the following code to the Initialize() method, probably after the menu bar is added to the GUI.&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
// Add event handlers
this.newMenuItem.Click += new ClickHandler(OnMenuItemClicked);
this.openMenuItem.Click += new ClickHandler(OnMenuItemClicked);
this.exitMenuItem.Click += new ClickHandler(OnMenuItemClicked);
this.undoMenuItem.Click += new ClickHandler(OnMenuItemClicked);
this.redoMenuItem.Click += new ClickHandler(OnMenuItemClicked);
&lt;/pre&gt; &lt;br /&gt;Finally we need to add a new method that is called whenever a menu item is clicked. We simply check which item was clicked, and act accordingly.&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
private void OnMenuItemClicked(UIComponent sender)
{
    if (sender == this.newMenuItem)
    {
        MessageBox messageBox = new MessageBox(
            this,
            gui,
            &amp;quot;New clicked!&amp;quot;,
            &amp;quot;Tutorial 1&amp;quot;,
            MessageBoxButtons.OK,
            MessageBoxType.Info
        );
        messageBox.Show(true);
    }
    else if (sender == this.openMenuItem)
    {
        MessageBox messageBox = new MessageBox(
            this,
            gui,
            &amp;quot;Open clicked!&amp;quot;,
            &amp;quot;Tutorial 1&amp;quot;,
            MessageBoxButtons.OK,
            MessageBoxType.Info
        );
        messageBox.Show(true);
    }
    else if (sender == this.undoMenuItem)
    {
        MessageBox messageBox = new MessageBox(
            this,
            gui,
            &amp;quot;Undo clicked!&amp;quot;,
            &amp;quot;Tutorial 1&amp;quot;,
            MessageBoxButtons.OK,
            MessageBoxType.Info
        );
        messageBox.Show(true);
    }
    else if (sender == this.redoMenuItem)
    {
        MessageBox messageBox = new MessageBox(
            this,
            gui,
            &amp;quot;Redo clicked!&amp;quot;,
            &amp;quot;Tutorial 1&amp;quot;,
            MessageBoxButtons.OK,
            MessageBoxType.Info
        );
        messageBox.Show(true);
    }
    else if (sender == this.exitMenuItem)
        Exit();
}
&lt;/pre&gt; &lt;br /&gt;&lt;h2&gt;
Summary
&lt;/h2&gt; &lt;br /&gt;This first tutorial was really simple, but should show you the basics of using the window system. It should be enough if all you want to do is add a couple buttons to your game. In the next tutorial I will show how to create a class that inherits from Window, to demonstrate how to begin to create a real application.&lt;br /&gt;
&lt;/div&gt;</description><author>cdmac</author><pubDate>Sun, 26 Aug 2007 15:27:13 GMT</pubDate><guid isPermaLink="false">UPDATED WIKI: Tutorial 1 20070826032713P</guid></item></channel></rss>