class Rabbit::Element::IndexSlide

Constants

COLUMN_NUMBER
ROW_NUMBER

Public Class Methods

make_index_slides(canvas) click to toggle source
# File lib/rabbit/element/index-slide.rb, line 48
def make_index_slides(canvas)
  width = canvas.width.to_f / (COLUMN_NUMBER + 1)
  height = canvas.height.to_f / (ROW_NUMBER + 1)
  default_margin_top = (height / (ROW_NUMBER + 1) / 2).ceil
  default_margin_bottom = default_margin_top
  default_margin_left = (width / (COLUMN_NUMBER + 1) / 2).ceil
  default_margin_right = default_margin_left

  thumbnails = make_thumbnails(canvas, width, height)
  return [] unless thumbnails

  max_per_slide = ROW_NUMBER * COLUMN_NUMBER
  thumbnail_rows_set = []
  thumbnails.each_with_index do |thumbnail, slide_number|
    if slide_number.remainder(max_per_slide).zero?
      thumbnail_rows_set << []
    end
    if slide_number.remainder(ROW_NUMBER).zero?
      row = IndexThumbnailRow.new
      row.default_margin_top = default_margin_top
      row.default_margin_bottom = default_margin_bottom
      row.default_margin_left = default_margin_left
      row.default_margin_right = default_margin_right
      row.clear_theme
      thumbnail_rows_set.last << row
    end
    thumbnail_rows_set.last.last << thumbnail
  end

  thumbnail_rows_set.collect do |rows|
    index_slide = new(rows)
    index_slide.default_margin_top = default_margin_top
    index_slide.default_margin_bottom = default_margin_bottom
    index_slide.default_margin_left = default_margin_left
    index_slide.default_margin_right = default_margin_right
    index_slide.clear_theme
    index_slide
  end
end
make_thumbnails(canvas, width, height) click to toggle source
# File lib/rabbit/element/index-slide.rb, line 15
def make_thumbnails(canvas, width, height)
  maker = make_thumbnail_maker(canvas, width, height)
  maker.apply_theme(canvas.theme_name) if canvas.theme_name

  canvas.source_force_modified(true) do |source|
    maker.parse(source)
  end

  thumbnails = []
  number_of_slide = maker.slide_size - 1
  canvas.renderer.pre_to_pixbuf(number_of_slide)
  canceled = false
  maker.each_slide_pixbuf do |slide, pixbuf, slide_number|
    if canvas.renderer.to_pixbufing(slide_number)
      thumbnails << IndexThumbnail.new(pixbuf,
                                       maker.slide_title(slide_number),
                                       slide_number,
                                       number_of_slide)
    else
      canceled = true
    end
    !canceled
  end
  canvas.renderer.post_to_pixbuf(canceled)
  maker.quit

  if canceled
    nil
  else
    thumbnails
  end
end

Private Class Methods

make_thumbnail_maker(canvas, width, height) click to toggle source
# File lib/rabbit/element/index-slide.rb, line 89
def make_thumbnail_maker(canvas, width, height)
  new_canvas = Canvas.new(canvas.logger, Renderer::Offscreen)
  new_canvas.width = width
  new_canvas.height = height
  new_canvas.pango_context = canvas.create_pango_context
  new_canvas.use_gl = canvas.use_gl?
  def new_canvas.quit
    nil
  end
  new_canvas
end

Public Instance Methods

slide_number(canvas, x, y) click to toggle source
# File lib/rabbit/element/index-slide.rb, line 106
def slide_number(canvas, x, y)
  column = (COLUMN_NUMBER * (x / canvas.width)).to_i
  row = (ROW_NUMBER * (y / canvas.height)).to_i
  thumb = self[row] && self[row][column]
  if thumb
    thumb.number
  else
    nil
  end
end
title() click to toggle source
# File lib/rabbit/element/index-slide.rb, line 102
def title
  _("Index")
end
to_html(generator) click to toggle source
# File lib/rabbit/element/index-slide.rb, line 117
def to_html(generator)
  "<div class=\"index-slide\">\n#{super}\n</div>"
end