Exemplo n.º 1
0
        public Button(Game game)
            : base(game)
        {
            Bounds = new Rectangle(0, 0, 60, 30);
            Text = "OK";

            // mapeando os identificadores para seus respectivos estados
            States = new Dictionary<StateIds, IButtonState>();
            States[StateIds.Normal] = new Normal(this);
            States[StateIds.Hovered] = new Hovered(this);
            States[StateIds.Pressed] = new Pressed(this);

            // criando e configurando as transições para a máquina de estados
            StateMachine = new StateMachine<StateIds, Input>(StateIds.Normal);
            StateMachine.For(StateIds.Normal)
                .When(Input.CursorOnTop)    .GoTo(StateIds.Hovered);
            StateMachine.For(StateIds.Hovered)
                .When(Input.CursorOffTop)   .GoTo(StateIds.Normal)
                .When(Input.Pressed)        .GoTo(StateIds.Pressed);
            StateMachine.For(StateIds.Pressed)
                .When(Input.CursorOffTop)   .GoTo(StateIds.Normal)
                .When(Input.Released)       .GoTo(StateIds.Normal);

            SpriteBatch = new SpriteBatch(Game.GraphicsDevice);
            Font = Game.Content.Load<SpriteFont>("arial");
        }