From f7dceffeee945270870d5ca681725b8fe09c8b9b Mon Sep 17 00:00:00 2001 From: "Bil Bas (Spooner)" Date: Fri, 19 Aug 2011 18:35:03 +0100 Subject: [PATCH] Fixed some issues with tool-tips. --- lib/gui/tool_tip.rb | 4 ++- lib/scenes/enter_control.rb | 1 + lib/scenes/gui_scene.rb | 50 +++++++++++++++++++++---------------- lib/scenes/level.rb | 1 + 4 files changed, 33 insertions(+), 23 deletions(-) diff --git a/lib/gui/tool_tip.rb b/lib/gui/tool_tip.rb index c90a3d1..7fea521 100644 --- a/lib/gui/tool_tip.rb +++ b/lib/gui/tool_tip.rb @@ -1,7 +1,9 @@ class ToolTip include Registers + TEXT_COLOR = Color.white - BACKGROUND_COLOR = Color.new(0, 0, 150) + BACKGROUND_COLOR = Color.new(0, 0, 100) + DELAY = 0.75 def shown?; not @text.string.empty?; end diff --git a/lib/scenes/enter_control.rb b/lib/scenes/enter_control.rb index 3d29305..3d036db 100644 --- a/lib/scenes/enter_control.rb +++ b/lib/scenes/enter_control.rb @@ -35,6 +35,7 @@ def setup(previous_scene, message, current) end def clean_up + super enable_event_group :game_keys end diff --git a/lib/scenes/gui_scene.rb b/lib/scenes/gui_scene.rb index 9328691..091a55f 100644 --- a/lib/scenes/gui_scene.rb +++ b/lib/scenes/gui_scene.rb @@ -13,7 +13,6 @@ class GuiScene < GameScene LABEL_X = 6 BUTTON_X = 35 BOTTOM_BUTTONS_Y = 55 - TOOL_TIP_DELAY = 0.5 def cursor_shown?; @cursor_shown; end @@ -56,18 +55,26 @@ def cursor_shown=(shown) protected def run_scene(*args) - - # Ensure that hovering is removed entering a dialog. - if @control_under_cursor - @control_under_cursor.unhover - @control_under_cursor = nil - @control_under_cursor_at = nil - @@tool_tip.string = '' - end + unhover_control super *args end + public + def clean_up + unhover_control + + super + end + + protected + def unhover_control + @control_under_cursor.unhover if @control_under_cursor + @control_under_cursor = nil + @control_under_cursor_at = nil + @@tool_tip.string = '' + end + public def register super @@ -77,16 +84,17 @@ def register @left_with_cursor_shown = cursor_shown? self.cursor_shown = false - - @@tool_tip.string = '' - @mouse_moved_at = Time.now - @control_under_cursor = nil + unhover_control end on :mouse_motion do |pos| - @@cursor.pos = pos / user_data.scaling - @mouse_moved_at = Time.now - @@tool_tip.string = '' + # Ensure that we ignore events where pos hasn't changed. + pos = pos / user_data.scaling + if pos != @@cursor.pos + @@cursor.pos = pos + @mouse_moved_at = Time.now + @@tool_tip.string = '' + end end on :mouse_hover do |control| @@ -96,7 +104,7 @@ def register on :mouse_unhover do |control| @mouse_moved_at = Time.now - @control_under_cursor = nil + unhover_control end end @@ -109,11 +117,9 @@ def register def update super - if @control_under_cursor and (Time.now - @mouse_moved_at > TOOL_TIP_DELAY) - if @control_under_cursor.tip - @@tool_tip.string = @control_under_cursor.tip - @@tool_tip.position = @@cursor.pos + [0, @@cursor.image.height / 2.0] - end + if @control_under_cursor and (Time.now - @mouse_moved_at > ToolTip::DELAY) and @control_under_cursor.tip + @@tool_tip.string = @control_under_cursor.tip + @@tool_tip.position = @@cursor.pos + [0, @@cursor.image.height / 2.0] end end diff --git a/lib/scenes/level.rb b/lib/scenes/level.rb index 1811639..6bc487b 100644 --- a/lib/scenes/level.rb +++ b/lib/scenes/level.rb @@ -108,6 +108,7 @@ def setup(level_number, player_data, hardcore, inversion) end def clean_up + super if defined? RubyProf RubyProf.pause log.debug { "Profiling paused" }