lib/rabbit/renderer/display/base.rb in rabbit-2.2.1 vs lib/rabbit/renderer/display/base.rb in rabbit-3.0.0

- old
+ new

@@ -1,5 +1,21 @@ +# Copyright (C) 2006-2019 Kouhei Sutou <kou@cozmixng.org> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + require "rabbit/renderer/base" require "rabbit/renderer/display/hook-handler" module Rabbit module Renderer @@ -10,12 +26,10 @@ def initialize(*args, &block) @drawable = nil @size = nil @size_dirty = true - @default_size_ratio = nil - @size_ratio = nil super end def width refresh_size @@ -45,20 +59,13 @@ end def attach_to(window, container=nil) @window = window @container = container || @window - - set_configure_event end def detach - if !@window.destroyed? and @configure_signal_id - @window.signal_handler_disconnect(@configure_signal_id) - @configure_signal_id = nil - end - @window = nil @container = nil end def toggle_whiteout @@ -93,98 +100,100 @@ def update_title @canvas.update_title(@canvas.slide_title) end def draw_slide(slide, simulation) - set_size_ratio(slide.size_ratio || @default_size_ratio) + set_size_ratio(slide.size_ratio) if simulation super else save_context do + scale_context(*@size.logical_scale) 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) + save_context do + scale_context(*@size.logical_scale) + if @size.have_logical_margin_x? + draw_rectangle(true, + 0, + 0, + @size.logical_margin_left, + @size.logical_height, + margin_background) + draw_rectangle(true, + @size.logical_margin_left + @size.logical_width, + 0, + @size.logical_margin_right, + @size.logical_height, + margin_background) + end + if @size.have_logical_margin_y? + draw_rectangle(true, + 0, + 0, + @size.logical_width, + @size.logical_margin_top, + margin_background) + draw_rectangle(true, + 0, + @size.logical_margin_top + @size.logical_height, + @size.logical_width, + @size.logical_margin_bottom, + margin_background) + end 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 = @drawable.width - h = @drawable.height - @default_size_ratio = w.to_f / h.to_f - @size_ratio = @default_size_ratio - set_size(w, h) + set_default_size(@drawable.width, @drawable.height) end - def set_size(w, h) - @size = Size.new(w, h, @size_ratio) + def set_default_size(w, h) + @real_width = w + @real_height = h + ratio = @base_width.to_f / @base_height.to_f + set_size(w, h, ratio) end + def set_size(w, h, ratio) + @size = Size.new(@base_width, + @base_height, + w, + h, + ratio) + end + + def update_size(w, h) + @real_width = w + @real_height = h + @size_dirty = true + end + def set_size_ratio(ratio) + ratio ||= @base_width.to_f / @base_height.to_f return if @size.ratio == ratio w = @size.real_width h = @size.real_height - @size_ratio = ratio - @size = Size.new(w, h, @size_ratio) + set_size(w, h, ratio) end def refresh_size return unless @size_dirty - - @size = Size.new(@drawable.width, - @drawable.height, - @size.ratio) + set_size(@real_width, @real_height, @size.ratio) @size_dirty = false - 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) - @size_dirty = true end def queue_draw widget.queue_draw end