Friday 19 June 2009

Sample code for NeoForce XNA 2D GUI controls

Sample code for NeoForce XNA 2D GUI controls

Normally goes inside:
protected override void Initialize()
of the game's game object which is subclassed from XNA Game class.

manager = new Manager(this(gameobject), this.GraphicsDeviceManager, "Default", true);

// Setting up the shared skins directory
manager.SkinDirectory = @"..\..\Skins\";

// Create and setup Window control.
window = new Window(manager);
window.Init();
window.Text = "Getting Started";
window.Width = 100;
window.Height = 124;
window.Center();
window.Visible = true;
window.BorderVisible = false;
window.MaximumHeight = 100;
window.MinimumHeight = 100;
window.MaximumWidth = 100;
window.MinimumWidth = 100;
window.Alpha = 128;

// Create Button control and set the previous window as its parent.
button = new TomShane.Neoforce.Controls.Button(manager);
button.Init();
button.Text = "OK";
button.Width = 72;
button.Height = 24;
button.Left = 0;
button.Top = 100;
//button.Left = (window.ClientWidth / 2) - (button.Width / 2);
//button.Top = window.ClientHeight - button.Height - 8;
button.Anchor = Anchors.Bottom;
button.Parent = window;

textbox = new TomShane.Neoforce.Controls.TextBox(manager);
textbox.Init();
textbox.Text = "Example";
textbox.Width = 100;
textbox.Height = 100;
textbox.Top = 0;
textbox.Left = 0;
textbox.BackColor = Color.TransparentWhite;
textbox.Parent = window;

// Add the window control to the manager processing queue.
manager.Add(window);

No comments: