module Rabbit::Renderer::Display::Spotlight
Public Class Methods
Source
# File lib/rabbit/renderer/display/spotlight.rb, line 21 def initialize(canvas) super init_spotlight end
Calls superclass method
Public Instance Methods
Source
# File lib/rabbit/renderer/display/spotlight.rb, line 40 def spotlighting? @spotlighting end
Source
# File lib/rabbit/renderer/display/spotlight.rb, line 26 def toggle_spotlight @spotlighting = !@spotlighting if spotlighting? grab @spotlight_center_x ||= 0 @spotlight_center_y ||= 0 else ungrab @spotlight_center_x = nil @spotlight_center_y = nil end queue_draw end
Private Instance Methods
Source
# File lib/rabbit/renderer/display/spotlight.rb, line 103 def draw_spotlight return unless spotlighting? radius = width * @spotlight_radius_ratio base = [ @spotlight_center_x - radius / 8, @spotlight_center_y, radius / 6, @spotlight_center_x + radius / 8, @spotlight_center_y, radius, ] color_stops = [ [0, 1, 1, 1, 0], [0.7, 0, 0, 0, 0.8], [1, 0, 0, 0, 0.8], ] params = { :pattern => { :type => :radial, :base => base, :color_stops => color_stops, } } draw_rectangle(true, 0, 0, size.real_width, size.real_height, nil, params) end
Source
# File lib/rabbit/renderer/display/spotlight.rb, line 45 def init_spotlight @spotlighting = false @spotlight_radius_ratio = 0.1 @spotlight_center_x = nil @spotlight_center_y = nil add_button_press_hook do |event| is_target = lambda do return false unless event.button == 3 if Gdk::EventType.const_defined?(:BUTTON2_PRESS) event.event_type == Gdk::EventType::BUTTON2_PRESS else event.event_type == Gdk::EventType::BUTTON_PRESS and event.n_presses == 2 end end if is_target.call add_button_handler do @spotlight_center_x = event.x @spotlight_center_y = event.y @canvas.activate("ToggleSpotlight") clear_button_handler true end end false end add_motion_notify_hook do |x, y| if spotlighting? @spotlight_center_x = x @spotlight_center_y = y queue_draw true else false end end add_scroll_hook do |event| if spotlighting? case event.direction when Gdk::ScrollDirection::UP @spotlight_radius_ratio = [0.1, @spotlight_radius_ratio - 0.1].max when Gdk::ScrollDirection::DOWN @spotlight_radius_ratio = [1, @spotlight_radius_ratio + 0.1].min end queue_draw true else false end end end