public void Update() { CollisionRect.X = (int)Position.X; CollisionRect.Y = (int)Position.Y; byte State; //Mouse Check State = input.GuiMouseClick(CollisionRect); if (State == 1) Selected = this; hover = (Selected == this); if (State == 2) ClickMethod(); // Keyboard Selection Mode if (hover && input.Fire) ClickMethod(); }
public Menu(Game game,Dictionary<string,ImageButton.Callback> NameMethods,HLayout HorizonalLayout,VLayout VerticalLayout,Vector2 Offset, int VerticalPadding) { //Need to move Mouse visability and mouse nav to state manager. game.IsMouseVisible = true; input = ContentStorageManager.Get<InputController>("input"); int TotalHeight = -1 * VerticalPadding; foreach (string item in NameMethods.Keys) { ImageButton b = new ImageButton(item, Vector2.Zero, NameMethods[item]); Buttons.Add(b); b.Position.Y = TotalHeight + Offset.Y; TotalHeight += b.CollisionRect.Height + VerticalPadding; if (HorizonalLayout == HLayout.Left) b.Position.X = Offset.X; if (HorizonalLayout == HLayout.Center) b.Position.X -=b.CollisionRect.Width / 2 - game.GraphicsDevice.PresentationParameters.BackBufferWidth / 2; if (HorizonalLayout == HLayout.Right) b.Position.X -= b.CollisionRect.Width - game.GraphicsDevice.PresentationParameters.BackBufferWidth+(int)Offset.X; } switch (VerticalLayout) { case VLayout.Top: break; case VLayout.Middle: int mid = TotalHeight / 2 - game.GraphicsDevice.PresentationParameters.BackBufferHeight / 2; foreach (ImageButton item in Buttons) { item.Position.Y -= mid; } break; case VLayout.Bottom: int mid1 = TotalHeight - game.GraphicsDevice.PresentationParameters.BackBufferHeight+ (int)Offset.Y; foreach (ImageButton item in Buttons) { item.Position.Y -= mid1; } break; default: break; } }