Class: Rabbit::Theme::Applier

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
DirtyCount, Element, GetText, Searcher
Defined in:
lib/rabbit/theme/applier.rb

Constant Summary collapse

NORMALIZED_WIDTH =

Those constants are meaningless. :p

130.0 * 96
NORMALIZED_HEIGHT =
97.5 * 96

Constants included from GetText

GetText::DOMAIN

Constants included from DirtyCount

DirtyCount::TOO_DIRTY

Instance Method Summary collapse

Methods included from GetText

included

Methods included from DirtyCount

#bit_dirty, #dirty, #dirty?, #dirty_count_clean, #very_dirty

Methods included from Searcher

_collect_theme, absolute_path?, #add_image_path, collect_all_theme, collect_image_theme, collect_theme, find_file, find_theme, image_dir, image_load_path, #in_theme, #pop_theme, #push_theme, theme_dir, theme_load_path

Constructor Details

#initialize(theme, &callback) ⇒ Applier

Returns a new instance of Applier.



247
248
249
250
251
252
253
254
255
256
257
258
259
# File 'lib/rabbit/theme/applier.rb', line 247

def initialize(theme, &callback)
  super()
  @theme = theme
  @callback = callback
  dirty_count_clean
  @match_cache = {}
  @current_target = nil
  class << slides
    def elements
      self
    end
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args, &block) ⇒ Object (private)



469
470
471
472
473
474
475
# File 'lib/rabbit/theme/applier.rb', line 469

def method_missing(meth, *args, &block)
  if @current_target
    @current_target.__send__(meth, *args, &block)
  else
    super
  end
end

Instance Method Details

#[](name) ⇒ Object



332
333
334
# File 'lib/rabbit/theme/applier.rb', line 332

def [](name)
  instance_variable_get("@#{name}")
end

#apply_theme(name) ⇒ Object



261
262
263
264
265
266
267
268
269
# File 'lib/rabbit/theme/applier.rb', line 261

def apply_theme(name)
  entry = find_theme(name)
  src = File.open(entry.theme_file, "r:utf-8") do |f|
    f.read
  end
  in_theme(entry) do
    instance_eval(normalize_source(src), entry.theme_file)
  end
end

#font_size(size) ⇒ Object



307
308
309
310
311
312
313
314
# File 'lib/rabbit/theme/applier.rb', line 307

def font_size(size)
  # TODO: Convert to point from pixel
  if wide_aspect_ratio?
    ((canvas.height * size) / normalized_height)
  else
    ((canvas.width * size) / normalized_width)
  end
end

#make_container(ary) ⇒ Object



271
272
273
# File 'lib/rabbit/theme/applier.rb', line 271

def make_container(ary)
  ElementContainer.new(self, ary)
end

#normalized_heightObject



287
288
289
# File 'lib/rabbit/theme/applier.rb', line 287

def normalized_height
  NORMALIZED_HEIGHT / Canvas::INTERNAL_DPI
end

#normalized_size(s) ⇒ Object



291
292
293
294
295
296
297
# File 'lib/rabbit/theme/applier.rb', line 291

def normalized_size(s)
  if wide_aspect_ratio?
    normalized_y(s)
  else
    normalized_x(s)
  end
end

#normalized_widthObject



283
284
285
# File 'lib/rabbit/theme/applier.rb', line 283

def normalized_width
  NORMALIZED_WIDTH / Canvas::INTERNAL_DPI
end

#normalized_x(sx) ⇒ Object



299
300
301
# File 'lib/rabbit/theme/applier.rb', line 299

def normalized_x(sx)
  ((sx / canvas.width.to_f) * normalized_width).ceil
end

#normalized_y(sy) ⇒ Object



303
304
305
# File 'lib/rabbit/theme/applier.rb', line 303

def normalized_y(sy)
  ((sy / canvas.height.to_f) * normalized_height).ceil
end

#screen_size(n) ⇒ Object



316
317
318
319
320
321
322
# File 'lib/rabbit/theme/applier.rb', line 316

def screen_size(n)
  if wide_aspect_ratio?
    screen_y(n)
  else
    screen_x(n)
  end
end

#screen_x(nx) ⇒ Object



324
325
326
# File 'lib/rabbit/theme/applier.rb', line 324

def screen_x(nx)
  ((canvas.width * nx) / normalized_width).ceil
end

#screen_y(ny) ⇒ Object



328
329
330
# File 'lib/rabbit/theme/applier.rb', line 328

def screen_y(ny)
  ((canvas.height * ny) / normalized_height).ceil
end

#to_container(obj) ⇒ Object



275
276
277
278
279
280
281
# File 'lib/rabbit/theme/applier.rb', line 275

def to_container(obj)
  if obj.is_a?(ElementContainer)
    obj
  else
    make_container([obj])
  end
end