Module: Interactive

Defined in:
lib/interactive.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#basisObject (readonly)

Returns the value of attribute basis.



4
5
6
# File 'lib/interactive.rb', line 4

def basis
  @basis
end

#indexObject (readonly)

Returns the value of attribute index.



4
5
6
# File 'lib/interactive.rb', line 4

def index
  @index
end

#screenObject (readonly)

Returns the value of attribute screen.



4
5
6
# File 'lib/interactive.rb', line 4

def screen
  @screen
end

Class Method Details

.included(base) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/interactive.rb', line 5

def self.included(base)
	base.class_eval do
		alias :old_setup :setup
		alias :old_draw :draw
		
		def setup
			old_setup
			@cache = Cache.new(self).refresh
			@index = @screen.build
		end
		
		def draw
			old_draw
			@screen.join = false
			@old_points ||= []
			@points_to_highlight ||= []
			@cache.restore if @old_points.count > 0
			@points_to_highlight.each do |p|
				@highlight_block.call(p[:original], p[:mapped], @screen) if @highlight_block
				@screen.draw_crosshairs(p[:original])
			end
			@old_points = @points_to_highlight
		end
	end
end

Instance Method Details

#mouseMoved(p) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/interactive.rb', line 31

def mouseMoved(p)
	p = {:x => p.getX(), :y => p.getY()}
	@old_points ||= []
	@points_to_highlight ||= []
	original_point = @screen.original(p)
	closest_point = @index.nearest([original_point[:x], original_point[:y]])
	closest = @screen.points[closest_point[:id]]
	return if closest.nil?
	closest_onscreen_point = @screen.transformed(closest)
	distance = (closest_onscreen_point[:x] - p[:x])**2 + (closest_onscreen_point[:y] - p[:y])**2
	if distance > 14.0
		@points_to_highlight = []
		redraw
		return
	end
	@points_to_highlight = [{:original => closest, :mapped => closest_onscreen_point}]
	@screen.write(closest)
	redraw
end