Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Make the following corrections to the program hover _ button _ test.rb: - The button should have a black border around it when the mouse
Make the following corrections to the program hoverbuttontest.rb:
The button should have a black border around it when the mouse is moved over it to highlight it
At the bottom of the screen there should be a display of the mouse x and y locations at all times not just when the mouse is clicked
When the button is clicked the background should change to yellow, if the window area outside the button is clicked the background should change to white.
Make sure the button works as per the test data below: Description
The screen should look as follows
when the mouse is NOT over the
button:
The screen should look as follows
when the mouse IS over the button:
end
WINWIDTH
WINHEIGHT
class DemoWindow Gosu::Window
def initialize
superWINWIDTH, WINHEIGHT, false
@background Gosu::Color::WHITE
@buttonfont Gosu::Font.new
@infofont Gosu::Font.new
@buttonhighlight Gosu::Color.rgb
@buttonnormal Gosu::Color::GREEN
@buttonborder Gosu::Color::BLACK
@buttonhovered false
@buttonrect Rectangle.new
end
def draw
Gosu.drawrect WINWIDTH, WINHEIGHT, @background, ZOrder::BA
# Draw the rectangle that provides the background
if @buttonhovered
homehoverbuttontest.rb : Spaces: Auto
require 'rubygems'
require 'gosu'
module ZOrder
BACKGROUND, MIDDLE, TOP
end
WINWIDTH
WINHEIGHT
class DemoWindow Gosu::Window
def initialize
superWINWIDTH, WINHEIGHT, false
@background Gosu::Color::WHITE
@buttonfont Gosu::Font.new
@infofont Gosu::Font.new
@buttonhighlight Gosu::Color.rgb
@buttonnormal Gosu::Color::GREEN
@buttonborder Gosu::Color::BLACK
@buttonhovered false
@buttonrect Rectangle.new
end
def draw
Gosu.drawrect WINWIDTH, WINHEIGHT, @background, ZOrder::BACKGROUND, mode:default
# Draw the rectangle that provides the background
if @buttonhovered
Gosu.drawrect@buttonrect.x @buttonrect.y @buttonrect.width @buttonrect.height @buttonborder, ZOrder::TOP, mode:default
end
# Draw the button
color @buttonhovered @buttonhighlight : @buttonnormal
Gosu.drawrect@buttonrect.x @buttonrect.y @buttonrect.width, @buttonrect.height, color, ZOrder::TOP, mode:default
# Draw the button text
@buttonfont.drawClick me ZOrder::MIDDLE, Gosu::Color::BLACK
# Draw the mousex position
@infofont.drawmousex: #mousex ZOrder::TOP, Gosu::Color::BLACK
# Draw the mousey position
@infofont.drawmousey: #mousey ZOrder::TOP, Gosu::Color::BLACK
end
def needscursor?
true
end
def mouseoverbutton?mousex mousey
@buttonrect.include?mousex mousey
end
def buttondownid
case id
when Gosu::MsLeft
if mouseoverbutton?mousex mousey
@background Gosu::Color::YELLOW
else
@background Gosu::Color::WHITE
end
end
end
def update
if mouseoverbutton?mousex mousey
@buttonhovered true
else
@buttonhovered false
end
end
end
DemoWindow.new.show
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started