Sha256: 45f64035c168772c5288fc59442a8df18b690923efb2f2c00ece42096d74120a

Contents?: true

Size: 1.11 KB

Versions: 6

Compression:

Stored size: 1.11 KB

Contents

class Shoes
  module Swt
    class Animation
      attr_reader :task

      # An Swt animation implementation
      #
      # @param [Shoes::Animation] dsl The Shoes DSL Animation this represents
      # @param [Shoes::Swt::App] app The Swt representation of the current app
      # @param [Proc] blk The block of code to execute for each animation frame
      def initialize(dsl, app)
        @dsl = dsl
        @app = app

        # Wrap the animation block so we can count frames.
        # Note that the task re-calls itself on each run.
        @task = proc do
          unless animation_removed?
            run_animation unless @dsl.stopped?
            schedule_next_animation
          end
        end
        schedule_next_animation
      end

      def eval_block
        @dsl.blk.call(@dsl.current_frame)
      end

      private

      def animation_removed?
        @app.real.disposed? || @dsl.removed?
      end

      def schedule_next_animation
        ::Swt.display.timer_exec(1000 / @dsl.framerate, @task)
      end

      def run_animation
        eval_block
        @dsl.increment_frame
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
shoes-swt-4.0.0.pre8 lib/shoes/swt/animation.rb
shoes-swt-4.0.0.pre7 lib/shoes/swt/animation.rb
shoes-swt-4.0.0.pre6 lib/shoes/swt/animation.rb
shoes-swt-4.0.0.pre5 lib/shoes/swt/animation.rb
shoes-swt-4.0.0.pre4 lib/shoes/swt/animation.rb
shoes-swt-4.0.0.pre3 lib/shoes/swt/animation.rb