public void Update(ClickableDecorator button) { if (IsMouseOver(button)) { if (Game1.previousState.LeftButton == ButtonState.Released && Game1.mouseState.LeftButton == ButtonState.Pressed) { Game1.states = button.StateToGo; } } }
private bool IsMouseOver(ClickableDecorator button) { int xMinBoundary = (int)button.GetPosition().X; int xMaxBoundary = (int)button.GetPosition().X + (int)button.WidthHeight.X; int yMinBoundary = (int)button.GetPosition().Y; int yMaxBoundary = (int)button.GetPosition().Y + (int)button.WidthHeight.Y; return (Game1.mousePosition.X > xMinBoundary && Game1.mousePosition.X < xMaxBoundary && Game1.mousePosition.Y > yMinBoundary && Game1.mousePosition.Y < yMaxBoundary); }
public void Draw(ClickableDecorator button) { spriteBatch.Begin(); Color[] colorData = new Color[button.Texture.Width * button.Texture.Height]; for (int i = 0; i < button.Texture.Height * button.Texture.Width; i++) { colorData[i] = button.BackgroundColor; } button.Texture.SetData(colorData); spriteBatch.Draw(button.Texture, new Rectangle((int)button.GetPosition().X, (int)button.GetPosition().Y, (int)button.Texture.Width, (int)button.Texture.Height), button.BackgroundColor); spriteBatch.End(); }
public void Draw(ClickableDecorator button) { spriteBatch.Begin(); Texture2D rect = new Texture2D(spriteBatch.GraphicsDevice, (int)button.WidthHeight.X, (int)button.WidthHeight.Y); Color[] colorData = new Color[rect.Width * rect.Height]; for (int i = 0; i < rect.Height * rect.Width; i++) { colorData[i] = button.Color; } rect.SetData(colorData); spriteBatch.Draw(rect, new Rectangle((int)button.GetPosition().X, (int)button.GetPosition().Y, (int)button.WidthHeight.X, (int)button.WidthHeight.Y), button.Color); spriteBatch.End(); }
public void Update(ClickableDecorator button) { IInputManager input = new InputManager(); if (!(input.GetMouseState().Position.X < (button.GetPosition().X + button.Texture.Width)) || !(input.GetMouseState().Position.X > button.GetPosition().X) || !(input.GetMouseState().Position.Y < (button.GetPosition().Y + button.Texture.Height)) || !(input.GetMouseState().Position.Y > button.GetPosition().Y)) { button.BackgroundColor = Color.Black; return; } button.BackgroundColor = button.HoverBackgroundColor; if (input.GetMouseState().LeftButton == ButtonState.Pressed) { Game1.CurrentScreen = button.GoToWindow; } }
public void Visit(ClickableDecorator button) { adapter.Update(button); }
public void Update(ClickableDecorator button) { throw new NotImplementedException(); }
public void Visit(ClickableDecorator button) { adapter.Draw(button); }