public void OnResetDevice(object sender, EventArgs e) { // reset font Font.CreateDefaultFont(); // Now create the vertex buffer //vertexBuffer = new VertexBuffer( // typeof(CustomVertex.TransformedColored), 3, dev, 0, // CustomVertex.TransformedColored.Format, Pool.Default); //vertexBuffer.Created += // new System.EventHandler(this.OnCreateVertexBuffer); //this.OnCreateVertexBuffer(vb, null); // register our event handlers for lost devices _device.DeviceLost += new EventHandler(OnDeviceLost); _device.DeviceReset += new EventHandler(OnResetDevice); }
// Constructor public Label(IWidgetContainer container) : base(container) { AutoSize = true; Text = Name; Font = Font.Default; FontColor = Color.White; BackgroundColor = Color.Transparent; ShadowColor = Color.Gray; TextAlignment = TextAlignment.None; Width = Font.MeasureString(Text).Width; Height = Font.MeasureString(Text).Height; }
// Methods protected override void OnPaint() { if (string.IsNullOrEmpty(Text) || Font == null) { return; } var position = Position; if (!AutoSize) { var measure = Font.MeasureString(Text); if (TextAlignment == TextAlignment.Left) { position.Y = position.Y + (Height / 2) - (measure.Height / 2); } else if (TextAlignment == TextAlignment.Right) { position.X = position.X + (Width - measure.Width); position.Y = position.Y + (Height / 2) - (measure.Height / 2); } else if (TextAlignment == TextAlignment.Center) { position.X = position.X + (Width / 2) - (measure.Width / 2); position.Y = position.Y + (Height / 2) - (measure.Height / 2); } } if (Shadow) { GraphicsDevice.Gemoetry.DrawRectangle(Position.X, Position.Y, Size.X + 1, Size.Y, BackgroundColor); Font.Draw(Text, (int)position.X + 1, (int)position.Y + 1, ShadowColor); Font.Draw(Text, (int)position.X, (int)position.Y, FontColor); } else { GraphicsDevice.Gemoetry.DrawRectangle(Position.X, Position.Y, Size.X, Size.Y, BackgroundColor); Font.Draw(Text, (int)position.X, (int)position.Y, FontColor); } }
public override void LoadContent() { IsLoading = true; Container = new WidgetContainer(); Container.Widgets.Add(new Label(Container)); var label = (Label)Container.Widgets[0]; label.AutoSize = false; label.TextAlignment = TextAlignment.Center; label.Position = new GameLibrary.Math.Vector2(5, 200); label.Size = new GameLibrary.Math.Vector2(100, 25); label.BackgroundColor = System.Drawing.Color.FromArgb(50, 0,0,0); Container.Widgets.Add(new Box(Container)); var box = (Box)Container.Widgets[2]; box.Position = new GameLibrary.Math.Vector2(5, 240); box.Size = new GameLibrary.Math.Vector2(400, 100); box.MouseEnter += (sender, e) => { box.BackgroundColor = System.Drawing.Color.DimGray; }; box.MouseLeave += (sender, e) => { box.BackgroundColor = System.Drawing.Color.Black; }; box.MouseDown += (sender, e) => { box.BackgroundColor = System.Drawing.Color.LightGray; }; box.MouseUp += (sender, e) => { box.BackgroundColor = System.Drawing.Color.DimGray; }; Container.Widgets.Add(new Box(Container)); var boxx = (Box)Container.Widgets[4]; boxx.Position = new GameLibrary.Math.Vector2(5, 150); boxx.Size = new GameLibrary.Math.Vector2(40, 40); boxx.Click += (sender, e) => { box.ToggleVisibility(); }; Container.Widgets.Add(new Label(Container)); var labell = (Label)Container.Widgets[6]; labell.AutoSize = false; labell.Text = "Exit"; labell.TextAlignment = TextAlignment.Center; labell.Position = new GameLibrary.Math.Vector2(200, 200); labell.Size = new GameLibrary.Math.Vector2(100, 25); labell.BackgroundColor = System.Drawing.Color.FromArgb(50, 0, 0, 0); labell.MouseEnter += (sender, e) => { labell.BackgroundColor = System.Drawing.Color.FromArgb(75, 0, 0, 0); }; labell.MouseLeave += (sender, e) => { labell.BackgroundColor = System.Drawing.Color.FromArgb(50, 0, 0, 0); }; labell.Click += (sender, e) => { GraphicsDevice.Window.Close(); }; Container.Widgets.Add(new ContextMenu(Container)); var contextMenu = (ContextMenu)Container.Widgets[8]; contextMenu.Position = new GameLibrary.Math.Vector2(400, 400); contextMenu.Size = new GameLibrary.Math.Vector2(120, 20); LargeFont = new Font("Verdana", 24); MediumFont = new Font("Verdana", 18); PosX = 1000; PosY = 5; IsLoading = false; IsLoaded = true; }