The Button class from this chapter is rather simple. For many applications, it’s useful to have slightly “smarter” buttons that can respond to both press and release actions a. Extend the Button class...


The Button class from this chapter is rather simple. For many applications, it’s useful to have slightly “smarter” buttons that can respond to both press and release actions


a. Extend the Button class (e.g., by creating a subclass ExtendedButton) so that it does the following: • Instead of a single bool member variable, add an enum ButtonState with four states: Normal, Hover, Pressed, and Released. Give the Button class a member variable of that type. The default state should be Normal. • When the mouse pointer hovers over the button, the state should go to Hover. • When the player clicks the left mouse button while the mouse pointer is on the Button, the state should go to Pressed. • When the player releases the left mouse button, the Button class should check if the mouse pointer is still inside the button’s bounding box. If so, the state should go to Released. If not, the state should go to Normal. b. It’s common to show a different image for each button state. Allow your extended Button class to accept up to four different images, where the “normal” images is mandatory and the other images are optional. Change the class so that when the button’s state changes, the sprite gets updated as well. Make sure that your code still works if some of the sprites are missing. c. In many games, you’ll also want to disable a button temporarily. Extend the Button class with an Enabled property that other objects can get and set. When a button is not enabled, it should not respond to any mouse interaction, and it should (again) show a different sprite.

Nov 22, 2021
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here