lib/rabbit/renderer/display/base.rb in rabbit-2.1.3 vs lib/rabbit/renderer/display/base.rb in rabbit-2.1.4

- old
+ new

@@ -8,26 +8,31 @@ include Renderer::Base include HookHandler def initialize(*args, &block) @drawable = nil + @size = nil + @default_size_ratio = nil + @size_ratio = nil super end def width - if @drawable - @drawable.size[0] + if @size + @size.logical_width + else + nil end end - alias original_width width def height - if @drawable - @drawable.size[1] + if @size + @size.logical_height + else + nil end end - alias original_height height def redraw widget.queue_draw end @@ -79,19 +84,89 @@ def update_title @canvas.update_title(@canvas.slide_title) end + def draw_slide(slide, simulation) + set_size_ratio(slide.size_ratio || @default_size_ratio) + + if simulation + super + else + save_context do + translate_context(@size.logical_margin_left, + @size.logical_margin_top) + super + end + + unless @size.have_logical_margin? + return + end + + margin_background = make_color("black") + if @size.have_logical_margin_x? + draw_rectangle(true, + 0, + 0, + @size.logical_margin_left, + @size.real_height, + margin_background) + draw_rectangle(true, + @size.real_width - @size.logical_margin_right, + 0, + @size.logical_margin_right, + @size.real_height, + margin_background) + end + if @size.have_logical_margin_y? + draw_rectangle(true, + 0, + 0, + @size.real_width, + @size.logical_margin_top, + margin_background) + draw_rectangle(true, + 0, + @size.real_height - @size.logical_margin_bottom, + @size.real_width, + @size.logical_margin_bottom, + margin_background) + end + end + end + private + def set_drawable(drawable) + @drawable = drawable + w, h = @drawable.size + @default_size_ratio = w.to_f / h.to_f + @size_ratio = @default_size_ratio + set_size(w, h) + end + + def set_size(w, h) + @size = Size.new(w, h, @size_ratio) + end + + def set_size_ratio(ratio) + return if @size.ratio == ratio + + w = @size.real_width + h = @size.real_height + @size_ratio = ratio + @size = Size.new(w, h, @size_ratio) + end + def set_configure_event id = @window.signal_connect("configure_event") do |widget, event| configured(event.x, event.y, event.width, event.height) false end @configure_signal_id = id end def configured(x, y, w, h) + set_size(w, h) end def queue_draw widget.queue_draw end