Sha256: 40b76a70b56dc960d3c62c8f1ac0e9db29a529d080410c0242ae566bce1f24f8

Contents?: true

Size: 1.49 KB

Versions: 8

Compression:

Stored size: 1.49 KB

Contents

# -*- coding: utf-8 -*-


require 'beeps'
require 'rays'
require 'reflex'


module Reflexion


  include Beeps, Rays, Reflex


  DEFAULTS = {
    title: 'Reflexion',
    frame: [100, 100, 512, 512]
  }


  def call_event (event, *args, &block)
    $event = event
    Xot::BlockUtil.instance_eval_or_block_call *args, &block if block
    $event = nil
  end


  class App < Application

    def on_motion (e)
      super
      call_event e, e, &$motion
    end

  end# App


  class MainWindow < Window

    attr_reader :event

    def initialize (*args, &block)
      super
      $window = self
      call_event nil, self, &$setup
    end

    def on_update (e)
      super
      redraw
      call_event e, e, &$update
    end

    def on_draw (e)
      super
      call_event e, e.painter, &$draw
    end

    def on_key (e)
      super
      call_event e, e, &$key
    end

    def on_pointer (e)
      super
      call_event e, e, &$pointer
    end

  end# MainWindow


  module_function

  def window ()
    $window ||= MainWindow.new DEFAULTS
  end

  def event ()
    $event
  end

  def setup (&block)
    $setup = block
  end

  def update (&block)
    $update = block
  end

  def draw (&block)
    $draw = block
  end

  def key (&block)
    $key = block
  end

  def pointer (&block)
    $pointer = block
  end

  def motion (&block)
    $motion = block
  end

  def start ()
    App.new {window.show}.start
  end

  def quit ()
    window.close
  end


end# Reflexion


at_exit do
  Reflexion.start unless $!
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
reflexion-0.1.21 lib/reflexion.rb
reflexion-0.1.20 lib/reflexion.rb
reflexion-0.1.19 lib/reflexion.rb
reflexion-0.1.17 lib/reflexion.rb
reflexion-0.1.16 lib/reflexion.rb
reflexion-0.1.15 lib/reflexion.rb
reflexion-0.1.14 lib/reflexion.rb
reflexion-0.1.13 lib/reflexion.rb