Skip to content

Commit

Permalink
Fixed some issues with tool-tips.
Browse files Browse the repository at this point in the history
  • Loading branch information
bil-bas committed Aug 19, 2011
1 parent ccfbdf4 commit f7dceff
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 23 deletions.
4 changes: 3 additions & 1 deletion 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

Expand Down
1 change: 1 addition & 0 deletions lib/scenes/enter_control.rb
Expand Up @@ -35,6 +35,7 @@ def setup(previous_scene, message, current)
end

def clean_up
super
enable_event_group :game_keys
end

Expand Down
50 changes: 28 additions & 22 deletions lib/scenes/gui_scene.rb
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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|
Expand All @@ -96,7 +104,7 @@ def register

on :mouse_unhover do |control|
@mouse_moved_at = Time.now
@control_under_cursor = nil
unhover_control
end
end

Expand All @@ -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

Expand Down
1 change: 1 addition & 0 deletions lib/scenes/level.rb
Expand Up @@ -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" }
Expand Down

0 comments on commit f7dceff

Please sign in to comment.