Module: Shoes::Basic

Defined in:
lib/shoes.rb

Instance Method Summary collapse

Instance Method Details

#tween(opts, &blk) ⇒ Object



457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
# File 'lib/shoes.rb', line 457

def tween opts, &blk
  opts = opts.dup

  if opts[:upward]
    opts[:top] = self.top - opts.delete(:upward)
  elsif opts[:downward]
    opts[:top] = self.top + opts.delete(:downward)
  end
  
  if opts[:sideways]
    opts[:left] = self.left + opts.delete(:sideways)
  end
  
  @TWEEN.remove if @TWEEN
  @TWEEN = parent.animate(opts[:speed] || 20) do

    # figure out a coordinate halfway between here and there
    cont = opts.select do |k, v|
      if self.respond_to? k
        n, o = v, self.send(k)
        if n != o
          n = o + ((n - o) / 2)
          n = v if o == n
          self.send("#{k}=", n)
        end
        self.style[k] != v
      end
    end

    # if we're there, get rid of the animation
    if cont.empty?
      @TWEEN.remove
      @TWEEN = nil
      blk.call if blk
    end
  end
end