Sha256: ada79d686ad1eb99ebb8200902425404429aed7ebd20ef82a85fc2d229e7e8a4

Contents?: true

Size: 1.14 KB

Versions: 4

Compression:

Stored size: 1.14 KB

Contents

# frozen_string_literal: true
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

4 entries across 4 versions & 1 rubygems

Version Path
shoes-swt-4.0.0.pre12 lib/shoes/swt/animation.rb
shoes-swt-4.0.0.pre11 lib/shoes/swt/animation.rb
shoes-swt-4.0.0.pre10 lib/shoes/swt/animation.rb
shoes-swt-4.0.0.pre9 lib/shoes/swt/animation.rb