class Rabbit::Renderer::Scene
Attributes
include Display::Magnifier
Public Class Methods
Source
# File lib/rabbit/renderer/scene.rb, line 88 def initialize(canvas) super @filename = nil @snapshots = [] @base_xys = [] init_ui end
Calls superclass method
Rabbit::Renderer::Display::Spotlight::new
Public Instance Methods
Source
# File lib/rabbit/renderer/scene.rb, line 101 def attach_to(window, container=nil) super if container container.add(@stack) else @window.child = @stack end @stack.show set_default_size(window.default_width, window.default_height) update_size(window.default_width, window.default_height) init_menu attach_menu(@window) end
Calls superclass method
Rabbit::Renderer::Display::Base#attach_to
Source
# File lib/rabbit/renderer/scene.rb, line 138 def clear_slide super compile_slides end
Calls superclass method
Rabbit::Renderer::Base#clear_slide
Source
# File lib/rabbit/renderer/scene.rb, line 274 def create_stroke(params) stroke = Gsk::Stroke.new(params[:line_width] || 1) [:line_cap, :line_join].each do |name| value = params[name] stroke.__send__("#{name}=", value) if value end # TODO: dash stroke end
Source
# File lib/rabbit/renderer/scene.rb, line 228 def current_base_xy @base_xys.last end
Source
# File lib/rabbit/renderer/scene.rb, line 224 def current_snapshot @snapshots.last end
Source
# File lib/rabbit/renderer/scene.rb, line 115 def detach detach_menu(@window) @stack.hide super end
Calls superclass method
Rabbit::Renderer::Display::Base#detach
Source
# File lib/rabbit/renderer/scene.rb, line 341 def draw_arc(filled, x, y, w, h, start_degree, length_degree, color=nil, params={}) radius = w * 0.5 draw_arc_by_radius(filled, x + w * 0.5, y + h * 0.5, radius, start_degree, length_degree, color, params) end
<--w--> 90 degree +-+ - / \ |
180 degree | | 0 degree h
\ / | p +-+ -
p: (x,y)
Source
# File lib/rabbit/renderer/scene.rb, line 369 def draw_arc_by_radius(filled, center_x, center_y, radius, start_degree, length_degree, color=nil, params={}) center_x, center_y = adjust_xy(center_x, center_y) snapshot = current_snapshot snapshot.save do builder = Gsk::PathBuilder.new if length_degree == 360 builder.add_circle([center_x, center_y], radius) else end_degree = start_degree + length_degree # Convert to the HTML arcTo command: # https://www.w3.org/TR/SVG11/paths.html#PathDataEllipticalArcCommands # # 90 degree # +-+ # / \ # 180 degree | c | 0 degree # end degree \ / start degree # +-+ # -> # +-+ # end (x,y) / \ # 180 degree | c | 0 degree # \ / start (x0,y0) # +-+ # 90 degree x_axis_rotation = 0 large_arc = length_degree >= 180 positive_sweep = false start_radian = -start_degree * (Math::PI / 180.0) end_radian = -end_degree * (Math::PI / 180.0) start_x = center_x + (radius * Math.cos(start_radian)) start_y = center_y + (radius * Math.sin(start_radian)) end_x = center_x + (radius * Math.cos(end_radian)) end_y = center_y + (radius * Math.sin(end_radian)) if filled builder.move_to(center_x, center_y) builder.line_to(start_x, start_y) else builder.move_to(start_x, start_y) end builder.svg_arc_to(radius, radius, x_axis_rotation, large_arc, positive_sweep, center_x + (radius * Math.cos(end_radian)), center_y + (radius * Math.sin(end_radian))) builder.close if filled end path = builder.to_path rgba = make_color(color).to_gdk_rgba if filled snapshot.append_fill(path, :winding, rgba) else snapshot.append_stroke(path, create_stroke(params), rgba) end end end
90 degree +-+ / \
180 degree | c | 0 degree
\ / +-+
c: center (center_x, center_y)
Source
# File lib/rabbit/renderer/scene.rb, line 262 def draw_layout(layout, x, y, color=nil, params={}) return if params[:stroke] # TODO x, y = adjust_xy(x, y) snapshot = current_snapshot snapshot.save do snapshot.translate([x, y]) rgba = make_color(color).to_gdk_rgba snapshot.append_layout(layout, rgba) end end
Source
# File lib/rabbit/renderer/scene.rb, line 284 def draw_line(x1, y1, x2, y2, color=nil, params={}) return if params[:line_width] == 0 x1, y1 = adjust_xy(x1, y1) x2, y2 = adjust_xy(x2, y2) snapshot = current_snapshot snapshot.save do rgba = make_color(color).to_gdk_rgba builder = Gsk::PathBuilder.new builder.move_to(x1, y1) builder.line_to(x2, y2) stroke = create_stroke(params) snapshot.append_stroke(builder.to_path, stroke, rgba) end end
Source
# File lib/rabbit/renderer/scene.rb, line 232 def draw_pixbuf(pixbuf, x, y, params={}) x, y = adjust_xy(x, y) width = (params[:width] || pixbuf.width).to_f height = (params[:height] || pixbuf.height).to_f draw_scaled_pixbuf = params[:draw_scaled_pixbuf] draw_scaled_pixbuf = @draw_scaled_image if draw_scaled_pixbuf.nil? snapshot = current_snapshot snapshot.save do # TODO: clip snapshot.translate([x, y]) if width == pixbuf.width and height == pixbuf.height need_scale = false elsif draw_scaled_pixbuf need_scale = true else need_scale = false end if need_scale snapshot.append_scale_texture(Gdk::Texture.new(pixbuf), :linear, [0, 0, width, height]) else snapshot.append_texture(Gdk::Texture.new(pixbuf), [0, 0, width, height]) end end end
Source
# File lib/rabbit/renderer/scene.rb, line 435 def draw_poppler_page(page, x, y, params={}) x, y = adjust_xy(x, y) w, h = page.size width = (params[:width] || w).to_f height = (params[:height] || h).to_f snapshot = current_snapshot snapshot.save do # TODO: clip snapshot.scale(width / w, height / h) context = snapshot.append_cairo([x, y, w, h]) context.render_poppler_page(page) end end
Source
# File lib/rabbit/renderer/scene.rb, line 300 def draw_rectangle(filled, x, y, w, h, color=nil, params={}) x, y = adjust_xy(x, y) snapshot = current_snapshot snapshot.save do rgba = make_color(color).to_gdk_rgba if filled snapshot.append_color(rgba, [x, y, w, h]) else builder = Gsk::PathBuilder.new builder.add_rect([x, y, w, h]) stroke = create_stroke(params) snapshot.append_stroke(builder.to_path, stroke, rgba) end end end
Source
# File lib/rabbit/renderer/scene.rb, line 316 def draw_rounded_rectangle(filled, x, y, w, h, radius, color=nil, params={}) x, y = adjust_xy(x, y) snapshot = current_snapshot snapshot.save do rgba = make_color(color).to_gdk_rgba builder = Gsk::PathBuilder.new builder.add_rounded_rect([[x, y, w, h], radius]) path = builder.to_path if filled snapshot.append_fill(path, :winding, rgba) else stroke = create_stroke(params) snapshot.append_stroke(path, stroke, rgba) end end end
Source
# File lib/rabbit/renderer/scene.rb, line 203 def index_mode_off restore_cursor(:index) end
Source
# File lib/rabbit/renderer/scene.rb, line 198 def index_mode_on keep_cursor(:index) update_cursor(nil, true) end
Source
# File lib/rabbit/renderer/scene.rb, line 157 def post_apply_theme clear_slide queue_draw update_menu end
Source
# File lib/rabbit/renderer/scene.rb, line 143 def post_fullscreen update_cursor(:blank, true) update_menu end
Source
# File lib/rabbit/renderer/scene.rb, line 153 def post_iconify update_menu end
Source
# File lib/rabbit/renderer/scene.rb, line 163 def post_move(old_index, index) @stack.visible_child_name = index.to_s update_title update_menu end
Source
# File lib/rabbit/renderer/scene.rb, line 169 def post_move_in_slide(old_index, index) queue_draw update_menu end
Source
# File lib/rabbit/renderer/scene.rb, line 195 def post_to_pixbuf(canceled) end
Source
# File lib/rabbit/renderer/scene.rb, line 184 def post_toggle_index_mode queue_draw end
Source
# File lib/rabbit/renderer/scene.rb, line 148 def post_unfullscreen update_cursor(nil, true) update_menu end
Source
# File lib/rabbit/renderer/scene.rb, line 188 def pre_to_pixbuf(n_slides) end
Source
# File lib/rabbit/renderer/scene.rb, line 181 def pre_toggle_index_mode end
Source
# File lib/rabbit/renderer/scene.rb, line 211 def push_snapshot(snapshot, base_x, base_y) @snapshots << snapshot @base_xys << [base_x, base_y] begin snapshot.save do yield end ensure @base_xys.pop @snapshots.pop end end
Source
# File lib/rabbit/renderer/scene.rb, line 125 def queue_draw @stack.queue_draw queue_draw_recursive = lambda do |widget| widget.queue_draw if widget.respond_to?(:children) widget.children.each do |child| queue_draw_recursive.call(child) end end end queue_draw_recursive.call(@stack.visible_child) end
Source
# File lib/rabbit/renderer/scene.rb, line 96 def update_size(width, height) super compile_slides end
Calls superclass method
Rabbit::Renderer::Display::Base#update_size
Private Instance Methods
Source
# File lib/rabbit/renderer/scene.rb, line 487 def adjust_xy(x, y) base_x, base_y = current_base_xy [x - base_x, y - base_y] end
For backward compatibility. Legacy DrawingArea based renderer. Legacy DrawingAare based renderer uses uses {x: 0, y: 0, width: @canvas.width, height: @canvas.height} coordinate for all elements. Scene based renderer uses {x: element.x, y: element.y, width: element.width, height: element.height} for each element.
Source
# File lib/rabbit/renderer/scene.rb, line 461 def compile_slides visible_child_name = @stack.visible_child_name @stack.pages.to_a.each do |page| @stack.remove(page.child) end @canvas.slides.each_with_index do |slide, i| set_size_ratio(slide.size_ratio || @default_size_ratio) fixed = Gtk::Fixed.new scene_widget = SceneWidget.new(fixed, size) background = SceneBackgroundWidget.new(@canvas, self, size) w = size.logical_width h = size.logical_height scene_widget.put(background, 0, 0, w, h) slide.setup_scene(@canvas, scene_widget, 0, 0, w, h) @stack.add_named(fixed, i.to_s) end @stack.visible_child_name = visible_child_name if visible_child_name redraw end
Source
# File lib/rabbit/renderer/scene.rb, line 451 def init_ui @stack = Gtk::Stack.new if ENV["RABBIT_SLIDE_TRANSITION"] == "yes" @stack.transition_type = :rotate_left_right end set_button_event(@stack) set_motion_event(@stack) set_scroll_event(@stack) end
Source
# File lib/rabbit/renderer/scene.rb, line 496 def reload_theme(&callback) callback ||= Utils.process_pending_events_proc @canvas.activate("ReloadTheme", &callback) end