/// <summary> /// Called when graphics resources need to be loaded. /// Use this for the usage of : /// - creation of the internal embedded controls. /// - setting of the variables and resources in this control /// - to load any game-specific graphics resources /// - take over the config width and height and use it into State /// - overriding how this item looks like , by settings its texture or theme /// Call base.LoadContent before you do your override code, this will cause : /// - State.SourceRectangle to be reset to the Config.Size /// </summary> public override void LoadContent() { // load the base dialog - making it load the form base.LoadContent(); // make the button this.OkButton = new Button(Name + "-YesButton") { ConfigText = "OK", Config = { Width = this.Theme.ControlWidth, Height = this.Theme.ControlHeight, PositionX = this.Config.Width - this.Theme.ControlWidth - this.Theme.ControlLargeSpacing, PositionY = this.Config.Height - this.Theme.ControlHeight - this.Theme.ControlLargeSpacing } }; this.AddControl(this.OkButton); // make the text this.Text = new Label(Name + "-Text") { ConfigText = this.DialogText, Config = { Width = this.Config.Width - (this.Theme.ControlLargeSpacing * 2), Height = this.Config.Height - (this.Theme.ControlLargeSpacing * 2), PositionX = this.Theme.ControlLargeSpacing } }; Text.Config.PositionY = Theme.ControlLargeSpacing; this.AddControl(this.Text); }
/// <summary> /// Populates the grid with controls. /// </summary> private void MakeGridControls() { for (var x = 0; x < this.ConfigColumnCount; x++) { for (var y = 0; y < this.ConfigRowCount; y++) { // if no fill type , then continue if (this.configFillType == GridFillType.None) { continue; } var gridPosition = this.GridPosition(x, y); switch (this.configFillType) { case GridFillType.Button: var buttonname = Name + string.Format(" {0}, {1}", x, y); var button = new Button(buttonname) { Config = { PositionX = gridPosition.X, PositionY = gridPosition.Y, Width = this.cellWidth, Height = this.cellHeight, }, ConfigText = string.Format("{0}, {1}", x, y), Theme = this.Theme }; button.Initialize(); this.controlArray[x][y] = button; this.AddControl(button); break; case GridFillType.Text: var textname = Name + string.Format(" {0}, {1}", x, y); var text = new Label(textname) { Config = { PositionX = gridPosition.X + (this.cellWidth / 2f), PositionY = gridPosition.Y + (this.cellHeight / 2f), Width = this.cellWidth, Height = this.cellHeight, }, ConfigText = string.Format("{0}, {1}", x, y), ConfigHorizontalAlignment = HorizontalAlignment.Center, ConfigVerticalAlignment = VerticalAlignment.Center, }; text.Initialize(); this.controlArray[x][y] = text; this.AddControl(text); break; } } } }
/// <summary> /// Create buttons in the given control. /// </summary> /// <param name="parentControl">The parent control.</param> public void CreateButtonsInControl(Control parentControl) { var y = this.theme.ControlLargeSpacing + (this.theme.ControlHeight * 2); foreach (var testWindow in this.Windows) { // create a button to go and show the window var btn = new Button(testWindow.Title) { ConfigText = testWindow.Name, Tag = testWindow.GetType().FullName, Config = { PositionY = y, PositionX = this.theme.ControlLargeSpacing } }; btn.Clicked += this.OnButtonClicked; y = y + this.theme.ControlHeight + this.theme.ControlSmallSpacing; // add the button to the window parentControl.AddControl(btn); } }
/// <summary> /// Called when graphics resources need to be loaded. /// Use this for the usage of : /// - creation of the internal embedded controls. /// - setting of the variables and resources in this control /// - to load any game-specific graphics resources /// - take over the config width and height and use it into State /// - overriding how this item looks like , by settings its texture or theme /// Call base.LoadContent before you do your override code, this will cause : /// - State.SourceRectangle to be reset to the Config.Size /// </summary> public override void LoadContent() { base.LoadContent(); // the list-box this.ListBox = new ListBox("MyListBox") { Config = { PositionX = Theme.ControlLargeSpacing, PositionY = Theme.ControlLargeSpacing + Theme.ControlHeight, Visible = true }, }; this.AddControl(this.ListBox); // the add-button this.ButtonAdd = new Button("AddButton"); this.ButtonAdd.Clicked += this.AddClicked; this.AddControl(this.ButtonAdd); // the remove-button this.ButtonRemove = new Button("RemoveButton"); this.ButtonRemove.Clicked += this.RemoveClicked; this.AddControl(this.ButtonAdd); // now add dynamic items this.ListBox.AddListItem(new ListBoxItem("Test 1", "MyListItem")); this.ListBox.AddListItem(new ListBoxItem("Test 2", "MyListItem2")); this.ListBox.AddListItem(new ListBoxItem("Test 1", "MyListItem3")); this.ListBox.AddListItem(new ListBoxItem("Test 2", "MyListItem4")); this.ListBox.AddListItem(new ListBoxItem("Test 1", "MyListItem5")); this.ListBox.AddListItem(new ListBoxItem("Test 2", "MyListItem6")); Config.Width = this.ListBox.Config.Width + (Theme.ControlLargeSpacing * 2); Config.Height = this.ListBox.Config.Height + (Theme.ControlHeight * 2); }