├── .gitignore ├── Gemfile ├── README.md ├── Rakefile ├── lib ├── opal-pixi.rb └── opal │ ├── pixi.rb │ └── pixi │ ├── base.rb │ ├── canvas_renderer.rb │ ├── container.rb │ ├── core │ ├── display │ │ ├── container.rb │ │ └── display_object.rb │ ├── files.rb │ ├── graphics │ │ ├── graphics.rb │ │ ├── graphics_data.rb │ │ └── webgl │ │ │ ├── graphics_renderer.rb │ │ │ └── web_gl_graphics_data.rb │ ├── math │ │ ├── matrix.rb │ │ ├── point.rb │ │ └── shapes │ │ │ ├── circle.rb │ │ │ ├── ellipse.rb │ │ │ ├── polygon.rb │ │ │ ├── rectangle.rb │ │ │ └── rounded_rectangle.rb │ ├── renderers │ │ ├── canvas │ │ │ └── canvas_renderer.rb │ │ ├── system_renderer.rb │ │ └── webgl │ │ │ ├── filters │ │ │ └── abstract_filter.rb │ │ │ └── webgl_renderer.rb │ ├── sprites │ │ └── sprite.rb │ ├── text │ │ └── text.rb │ └── textures │ │ ├── render_texture.rb │ │ └── texture.rb │ ├── display_object.rb │ ├── extras │ ├── movie_clip.rb │ └── tiling_sprite.rb │ ├── graphics.rb │ ├── interaction │ └── interactive_target.rb │ ├── mesh │ ├── mesh.rb │ └── rope.rb │ ├── point.rb │ ├── setup.rb │ ├── sprite.rb │ ├── text.rb │ ├── texture.rb │ ├── version.rb │ └── web_gl_renderer.rb ├── opal-pixi.gemspec └── spec └── spec_helper.rb /.gitignore: -------------------------------------------------------------------------------- 1 | ## Documentation cache and generated files: 2 | /.yardoc/ 3 | /_yardoc/ 4 | /doc/ 5 | /rdoc/ 6 | 7 | ## Ignore editors, tools and such: 8 | .idea 9 | 10 | ## Ignore demo's Gemfile.lock 11 | *Gemfile.lock 12 | 13 | pkg 14 | build 15 | .bundle 16 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | gemspec 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Ruby wrapper for the Pixi.js graphical library 2 | 3 | [![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/orbitalimpact/opal-pixi?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) 4 | 5 | The goal of this project is to completely wrap the Pixi API in Opal, to allow developers to write HTML5 and WebGL rendering from Ruby. 6 | 7 | If you have not heard of Pixi, check out these links: 8 | 9 | * Pixi: https://github.com/GoodBoyDigital/pixi.js/ 10 | * Pixi Examples: https://github.com/pixijs/examples 11 | 12 | Also, to get examples of opal-pixi in action, check out the [opal-pixi-examples repository](https://github.com/ktec/opal-pixi-examples). 13 | 14 | ## Cloning this repository 15 | 16 | ``` 17 | $ git clone https://github.com/orbitalimpact/opal-pixi 18 | ``` 19 | 20 | ## Getting involved 21 | 22 | To contribute to this project, follow the steps below. 23 | 24 | 1. Fork the repo ( https://github.com/orbitalimpact/opal-pixi/fork ) 25 | 2. Create your feature branch (`git checkout -b new-branch`) 26 | 3. Commit your changes (`git commit -am 'description of commit'`) 27 | 4. Push to the branch (`git push origin new-branch`) 28 | 5. Create a Pull Request 29 | 30 | ## Licenses 31 | 32 | Phaser and all examples are released under the MIT License: http://opensource.org/licenses/MIT 33 | 34 | opal-pixi is released under the Berkeley Software Distribution (BSD) 3-Clause License: http://opensource.org/licenses/BSD-3-Clause 35 | 36 | Copyright (c) 2015, Orbital Impact 37 | All rights reserved. 38 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | require 'bundler' 2 | Bundler.require 3 | Bundler::GemHelper.install_tasks 4 | 5 | require 'opal/rspec/rake_task' 6 | Opal::RSpec::RakeTask.new(:default) do |s| 7 | s.index_path = 'spec/html/index.html.erb' 8 | end 9 | 10 | desc "Build build/opal-pixi.js" 11 | task :dist do 12 | require 'fileutils' 13 | FileUtils.mkdir_p 'build' 14 | 15 | src = Opal::Builder.build('opal-pixi') 16 | #min = uglify src 17 | #gzp = gzip min 18 | 19 | File.open('build/opal-pixi.js', 'w+') do |out| 20 | out << src 21 | end 22 | 23 | #puts "development: #{src.size}, minified: #{min.size}, gzipped: #{gzp.size}" 24 | end 25 | 26 | # Used for uglifying source to minify 27 | def uglify(str) 28 | IO.popen('uglifyjs', 'r+') do |i| 29 | i.puts str 30 | i.close_write 31 | return i.read 32 | end 33 | rescue Errno::ENOENT 34 | $stderr.puts '"uglifyjs" command not found (install with: "npm install -g uglify-js")' 35 | nil 36 | end 37 | 38 | # Gzip code to check file size 39 | def gzip(str) 40 | IO.popen('gzip -f', 'r+') do |i| 41 | i.puts str 42 | i.close_write 43 | return i.read 44 | end 45 | rescue Errno::ENOENT 46 | $stderr.puts '"gzip" command not found, it is required to produce the .gz version' 47 | nil 48 | end 49 | -------------------------------------------------------------------------------- /lib/opal-pixi.rb: -------------------------------------------------------------------------------- 1 | require 'opal/pixi' 2 | -------------------------------------------------------------------------------- /lib/opal/pixi.rb: -------------------------------------------------------------------------------- 1 | if RUBY_ENGINE == 'opal' 2 | require 'opal/pixi/setup' 3 | else 4 | require 'opal' 5 | require 'opal/pixi/version' 6 | 7 | Opal.append_path File.expand_path('../..', __FILE__).untaint 8 | end 9 | -------------------------------------------------------------------------------- /lib/opal/pixi/base.rb: -------------------------------------------------------------------------------- 1 | module PIXI 2 | module Base 3 | 4 | def self.included(base) 5 | base.class_eval do 6 | name = "window.#{self.name.split('::').join('.')}" 7 | code = "self._proto = #{name}.prototype, def = self._proto; #{name}.prototype._klass = self" 8 | # %x{ alert(code) } 9 | %x{ eval(code) } 10 | end 11 | end 12 | 13 | end 14 | end 15 | -------------------------------------------------------------------------------- /lib/opal/pixi/canvas_renderer.rb: -------------------------------------------------------------------------------- 1 | module PIXI 2 | class CanvasRenderer 3 | include Native 4 | 5 | def initialize(w_or_native, height, options) 6 | if native?(w_or_native) 7 | super(w_or_native) 8 | else 9 | super(`new PIXI.CanvasRenderer(w_or_native, height, #{ options.to_n })`) 10 | end 11 | end 12 | 13 | alias_native :width 14 | alias_native :height 15 | end 16 | end 17 | -------------------------------------------------------------------------------- /lib/opal/pixi/container.rb: -------------------------------------------------------------------------------- 1 | require 'native' 2 | require './base' 3 | require './display_object' 4 | 5 | module PIXI 6 | class Container < PIXI::DisplayObject 7 | include Native 8 | 9 | %x{ 10 | self._proto = window.PIXI.Container.prototype, def = self._proto; 11 | window.PIXI.Container.prototype._klass = self; 12 | } 13 | 14 | def self.new(color) 15 | `new window.PIXI.Container(color)` 16 | end 17 | 18 | def add_child(child) 19 | `self.addChild(child)` 20 | end 21 | 22 | def x 23 | `self.position.x` 24 | end 25 | 26 | def x=(x) 27 | `self.position.x = x` 28 | end 29 | 30 | def y 31 | `self.position.y` 32 | end 33 | 34 | def y=(y) 35 | `self.position.y = y` 36 | end 37 | 38 | 39 | end 40 | end 41 | -------------------------------------------------------------------------------- /lib/opal/pixi/core/display/container.rb: -------------------------------------------------------------------------------- 1 | require 'opal/pixi/core/display/display_object' 2 | require 'opal/pixi/interaction/interactive_target' 3 | 4 | module PIXI 5 | class Container 6 | include Native 7 | include PIXI::DisplayObject 8 | include PIXI::InteractiveTarget 9 | 10 | def initialize 11 | super(`new PIXI.Container()`) 12 | end 13 | 14 | alias_native :children 15 | 16 | alias_native :width 17 | alias_native :width= 18 | alias_native :height 19 | alias_native :height= 20 | 21 | alias_native :add_child, :addChild 22 | alias_native :add_child_at, :addChildAt 23 | alias_native :swap_children, :swapChildren 24 | alias_native :get_child_index, :getChildIndex 25 | alias_native :set_child_index, :setChildIndex 26 | alias_native :get_child_at, :getChildAt 27 | alias_native :remove_child, :removeChild 28 | alias_native :remove_child_at, :removeChildAt 29 | alias_native :remove_children, :removeChildren 30 | alias_native :generate_texture, :generateTexture # renderer, resolution, scaleMode 31 | alias_native :get_bounds, :getBounds 32 | alias_native :get_local_bounds, :getLocalBounds 33 | alias_native :render_webGL, :renderWebGL # WebGLRenderer 34 | alias_native :render_canvas, :renderCanvas # CanvasRenderer 35 | alias_native :destroy # destroyChildren=false 36 | 37 | end 38 | end 39 | -------------------------------------------------------------------------------- /lib/opal/pixi/core/display/display_object.rb: -------------------------------------------------------------------------------- 1 | require 'opal/pixi/core/math/point' 2 | 3 | module PIXI 4 | module DisplayObject 5 | include Native 6 | 7 | alias_native :x 8 | alias_native :x= 9 | alias_native :y 10 | alias_native :y= 11 | 12 | alias_native :position, :position, as: Point 13 | alias_native :position= 14 | alias_native :scale, :scale, as: Point 15 | alias_native :scale= 16 | alias_native :pivot, :pivot, as: Point 17 | alias_native :pivot= 18 | alias_native :rotation 19 | alias_native :rotation= 20 | alias_native :alpha 21 | alias_native :alpha= 22 | alias_native :visible 23 | alias_native :visible= 24 | alias_native :renderable 25 | alias_native :renderable= 26 | 27 | alias_native :parent 28 | alias_native :world_alpha, :worldAlpha 29 | alias_native :world_transform, :worldTransform 30 | 31 | alias_native :filter_area, :filterArea 32 | alias_native :filter_area= 33 | 34 | alias_native :world_visible, :worldVisible 35 | alias_native :mask 36 | alias_native :mask= 37 | 38 | alias_native :filters 39 | alias_native :filters= 40 | 41 | alias_native :destroy 42 | 43 | end 44 | end 45 | -------------------------------------------------------------------------------- /lib/opal/pixi/core/files.rb: -------------------------------------------------------------------------------- 1 | # These requires must be loaded in order of dependency: 2 | # TODO: look into why `puts File.dirname(__FILE__)` is not working for Opal 3 | 4 | require 'opal/pixi/core/display/container' 5 | require 'opal/pixi/core/display/display_object' 6 | require 'opal/pixi/core/renderers/webgl/filters/abstract_filter' 7 | require 'opal/pixi/core/renderers/webgl/webgl_renderer' 8 | #require 'opal/pixi/core/renderers/system_renderer' 9 | require 'opal/pixi/core/graphics/graphics' 10 | # require 'opal/pixi/core/math' 11 | # require 'opal/pixi/core/particles' 12 | # require 'opal/pixi/core/renderers' 13 | require 'opal/pixi/core/sprites/sprite' 14 | require 'opal/pixi/core/text/text' 15 | require 'opal/pixi/core/textures/texture' 16 | require 'opal/pixi/core/textures/render_texture' 17 | # require 'opal/pixi/core/ticker' 18 | # require 'opal/pixi/core/utils' 19 | -------------------------------------------------------------------------------- /lib/opal/pixi/core/graphics/graphics.rb: -------------------------------------------------------------------------------- 1 | require 'opal/pixi/core/display/display_object' 2 | 3 | module PIXI 4 | class Graphics < Container 5 | include Native 6 | 7 | def initialize 8 | super(`new PIXI.Graphics()`) 9 | end 10 | 11 | alias_native :fill_alpha, :fillAlpha 12 | alias_native :line_width, :lineWidth 13 | alias_native :line_color, :lineColor 14 | alias_native :tint 15 | alias_native :blend_mode, :blendMode 16 | alias_native :is_mask, :isMask 17 | alias_native :bounds_padding, :boundsPadding 18 | alias_native :clone 19 | alias_native :line_style, :lineStyle 20 | alias_native :move_to, :moveTo 21 | alias_native :line_to, :lineTo 22 | alias_native :quadratic_curve_to, :quadraticCurveTo 23 | alias_native :bezier_curve_to, :bezierCurveTo 24 | alias_native :arc_to, :arcTo 25 | alias_native :arc 26 | alias_native :begin_fill, :beginFill 27 | alias_native :end_fill, :endFill 28 | alias_native :draw_rect, :drawRect 29 | alias_native :draw_rounded_rect, :drawRoundedRect 30 | alias_native :draw_circle, :drawCircle 31 | alias_native :draw_ellipse, :drawEllipse 32 | alias_native :draw_polygon, :drawPolygon 33 | alias_native :clear 34 | alias_native :generate_texture, :generateTexture 35 | alias_native :get_bounds, :getBounds 36 | alias_native :contains_point, :containsPoint 37 | alias_native :update_local_bounds, :updateLocalBounds 38 | alias_native :draw_shape, :drawShape 39 | alias_native :destroy 40 | 41 | end 42 | end 43 | -------------------------------------------------------------------------------- /lib/opal/pixi/core/graphics/graphics_data.rb: -------------------------------------------------------------------------------- 1 | module PIXI 2 | class GraphicsData 3 | include Native 4 | 5 | def initialize(lineWidth, lineColor, lineAlpha, fillColor, fillAlpha, fill, shape) 6 | super(`new PIXI.GraphicsData(lineWidth, lineColor, lineAlpha, fillColor, fillAlpha, fill, shape)`) 7 | end 8 | 9 | alias_native :line_width, :lineWidth 10 | alias_native :line_color, :lineColor 11 | alias_native :line_alpha, :lineAlpha 12 | alias_native :fill_color, :fillColor 13 | alias_native :fill_alpha, :fillAlpha 14 | alias_native :fill 15 | alias_native :shape 16 | alias_native :type 17 | 18 | end 19 | end 20 | -------------------------------------------------------------------------------- /lib/opal/pixi/core/graphics/webgl/graphics_renderer.rb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/orbitalimpact/opal-pixi/33e7f6c8b8691d36a19a89f1241aa90d36a803a7/lib/opal/pixi/core/graphics/webgl/graphics_renderer.rb -------------------------------------------------------------------------------- /lib/opal/pixi/core/graphics/webgl/web_gl_graphics_data.rb: -------------------------------------------------------------------------------- 1 | module PIXI 2 | class WebGLGraphicsData 3 | include Native 4 | 5 | # alias_native :reset 6 | # alias_native :reset 7 | # alias_native :upload 8 | # alias_native :destroy 9 | 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /lib/opal/pixi/core/math/matrix.rb: -------------------------------------------------------------------------------- 1 | module PIXI 2 | class Matrix 3 | include Native 4 | 5 | def self.new(x_or_native, y) 6 | if native?(x_or_native) 7 | super(x_or_native) 8 | else 9 | super(`new PIXI.Matrix(x_or_native, y)`) 10 | end 11 | end 12 | 13 | alias_native :a 14 | alias_native :a= 15 | alias_native :b 16 | alias_native :b= 17 | alias_native :c 18 | alias_native :c= 19 | alias_native :d 20 | alias_native :d= 21 | alias_native :tx 22 | alias_native :tx= 23 | alias_native :ty 24 | alias_native :ty= 25 | 26 | alias_native :from_array, :fromArray 27 | alias_native :to_array, :toArray 28 | alias_native :apply 29 | alias_native :apply_inverse, :applyInverse 30 | alias_native :translate 31 | alias_native :scale 32 | alias_native :rotate 33 | alias_native :append 34 | alias_native :prepend 35 | alias_native :invert 36 | alias_native :identity 37 | 38 | 39 | end 40 | end 41 | -------------------------------------------------------------------------------- /lib/opal/pixi/core/math/point.rb: -------------------------------------------------------------------------------- 1 | module PIXI 2 | class Point 3 | include Native 4 | 5 | def self.new(x_or_native, y) 6 | if native?(x_or_native) 7 | super(x_or_native) 8 | else 9 | super(`new PIXI.Point(x_or_native, y)`) 10 | end 11 | end 12 | 13 | alias_native :x 14 | alias_native :x= 15 | alias_native :y 16 | alias_native :y= 17 | 18 | alias_native :clone 19 | alias_native :copy 20 | alias_native :equals 21 | alias_native :set 22 | 23 | end 24 | end 25 | -------------------------------------------------------------------------------- /lib/opal/pixi/core/math/shapes/circle.rb: -------------------------------------------------------------------------------- 1 | module PIXI 2 | class Circle 3 | include Native 4 | 5 | def self.new(x_or_native, y, radius) 6 | if native?(x_or_native) 7 | super(x_or_native) 8 | else 9 | super(`new PIXI.Circle(x_or_native, y, radius)`) 10 | end 11 | end 12 | 13 | alias_native :x 14 | alias_native :x= 15 | alias_native :y 16 | alias_native :y= 17 | alias_native :radius 18 | alias_native :radius= 19 | alias_native :type 20 | 21 | alias_native :clone 22 | alias_native :contains 23 | alias_native :get_bounds, :getBounds 24 | 25 | end 26 | end 27 | -------------------------------------------------------------------------------- /lib/opal/pixi/core/math/shapes/ellipse.rb: -------------------------------------------------------------------------------- 1 | module PIXI 2 | class Ellipse 3 | include Native 4 | 5 | def self.new(x_or_native, y, width, height) 6 | if native?(x_or_native) 7 | super(x_or_native) 8 | else 9 | super(`new PIXI.Ellipse(x_or_native, y, width, height)`) 10 | end 11 | end 12 | 13 | alias_native :x 14 | alias_native :x= 15 | alias_native :y 16 | alias_native :y= 17 | alias_native :width 18 | alias_native :width= 19 | alias_native :height 20 | alias_native :height= 21 | alias_native :type 22 | 23 | alias_native :clone 24 | alias_native :contains 25 | alias_native :get_bounds, :getBounds 26 | 27 | end 28 | end 29 | -------------------------------------------------------------------------------- /lib/opal/pixi/core/math/shapes/polygon.rb: -------------------------------------------------------------------------------- 1 | module PIXI 2 | class Polygon 3 | include Native 4 | 5 | def self.new(points_or_native) 6 | if native?(points_or_native) 7 | super(points_or_native) 8 | else 9 | super(`new PIXI.Polygon(points_or_native)`) 10 | end 11 | end 12 | 13 | alias_native :points 14 | alias_native :points= 15 | alias_native :closed 16 | alias_native :closed= 17 | alias_native :type 18 | 19 | alias_native :clone 20 | alias_native :contains 21 | 22 | end 23 | end 24 | -------------------------------------------------------------------------------- /lib/opal/pixi/core/math/shapes/rectangle.rb: -------------------------------------------------------------------------------- 1 | module PIXI 2 | class Rectange 3 | include Native 4 | 5 | def self.new(x_or_native, y, width, height) 6 | if native?(x_or_native) 7 | super(x_or_native) 8 | else 9 | super(`new PIXI.Rectangle(x_or_native, y, width, height)`) 10 | end 11 | end 12 | 13 | alias_native :x 14 | alias_native :x= 15 | alias_native :y 16 | alias_native :y= 17 | alias_native :width 18 | alias_native :width= 19 | alias_native :height 20 | alias_native :height= 21 | alias_native :type 22 | 23 | alias_native :clone 24 | alias_native :contains 25 | 26 | end 27 | end 28 | -------------------------------------------------------------------------------- /lib/opal/pixi/core/math/shapes/rounded_rectangle.rb: -------------------------------------------------------------------------------- 1 | module PIXI 2 | class RoundedRectangle < Rectange 3 | include Native 4 | 5 | def self.new(x_or_native, y, width, height, radius) 6 | if native?(x_or_native) 7 | super(x_or_native) 8 | else 9 | super(`new PIXI.Rectangle(x_or_native, y, width, height, radius)`) 10 | end 11 | end 12 | 13 | alias_native :x 14 | alias_native :x= 15 | alias_native :y 16 | alias_native :y= 17 | alias_native :width 18 | alias_native :width= 19 | alias_native :height 20 | alias_native :height= 21 | alias_native :radius 22 | alias_native :radius= 23 | alias_native :type 24 | 25 | alias_native :clone 26 | alias_native :contains 27 | 28 | end 29 | end 30 | -------------------------------------------------------------------------------- /lib/opal/pixi/core/renderers/canvas/canvas_renderer.rb: -------------------------------------------------------------------------------- 1 | module PIXI 2 | class CanvasRenderer 3 | include Native 4 | 5 | def initialize(w_or_native, height, options={}) 6 | if native?(w_or_native) 7 | super(w_or_native) 8 | else 9 | super(`new PIXI.CanvasRenderer(w_or_native, height, #{ options.to_n })`) 10 | end 11 | end 12 | 13 | alias_native :render 14 | alias_native :view 15 | alias_native :width 16 | alias_native :height 17 | 18 | end 19 | end 20 | -------------------------------------------------------------------------------- /lib/opal/pixi/core/renderers/system_renderer.rb: -------------------------------------------------------------------------------- 1 | module PIXI 2 | class SystemRenderer 3 | include Native 4 | 5 | alias_native :width 6 | alias_native :height 7 | 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /lib/opal/pixi/core/renderers/webgl/filters/abstract_filter.rb: -------------------------------------------------------------------------------- 1 | module PIXI 2 | class AbstractFilter 3 | include Native 4 | 5 | def initialize(vertexSrc, fragmentSrc, uniforms={}) 6 | super(`new PIXI.AbstractFilter(vertexSrc, fragmentSrc, #{uniforms.to_n})`) 7 | end 8 | 9 | alias_native :padding 10 | alias_native :uniforms 11 | alias_native :get_shader, :getShader 12 | alias_native :apply_filter, :applyFilter 13 | alias_native :sync_uniform, :syncUniform 14 | 15 | end 16 | end 17 | -------------------------------------------------------------------------------- /lib/opal/pixi/core/renderers/webgl/webgl_renderer.rb: -------------------------------------------------------------------------------- 1 | module PIXI 2 | class WebGLRenderer 3 | include Native 4 | 5 | def initialize(w_or_native, height, options={}) 6 | if native?(w_or_native) 7 | super(w_or_native) 8 | else 9 | super(`new PIXI.WebGLRenderer(w_or_native, height, #{ options.to_n })`) 10 | end 11 | end 12 | 13 | alias_native :render 14 | alias_native :destroy 15 | alias_native :view 16 | alias_native :width 17 | alias_native :height 18 | 19 | end 20 | end 21 | -------------------------------------------------------------------------------- /lib/opal/pixi/core/sprites/sprite.rb: -------------------------------------------------------------------------------- 1 | require 'opal/pixi/core/display/container' 2 | require 'opal/pixi/core/math/point' 3 | require 'opal/pixi/core/textures/texture' 4 | require 'opal/pixi/interaction/interactive_target' 5 | 6 | module PIXI 7 | class Sprite #< Container 8 | include Native 9 | include PIXI::DisplayObject 10 | include PIXI::InteractiveTarget 11 | 12 | def self.from_image(imageId, crossorigin=false, scaleMode='') 13 | new(`PIXI.Sprite.fromImage(imageId, crossorigin, scaleMode)`) 14 | end 15 | 16 | def self.from_frame(frameId) 17 | new(`PIXI.Sprite.fromFrame(frameId)`) 18 | end 19 | 20 | def initialize(native_or_texture) 21 | if native?(native_or_texture) 22 | super 23 | else 24 | super(`new PIXI.Sprite(#{native_or_texture.to_n})`) 25 | end 26 | end 27 | 28 | alias_native :anchor, :anchor, as: Point 29 | alias_native :anchor= 30 | alias_native :tint 31 | alias_native :tint= 32 | alias_native :blend_mode, :blendMode 33 | alias_native :blend_mode= 34 | alias_native :shader 35 | alias_native :shader= 36 | alias_native :cached_tint, :cachedTint 37 | alias_native :cached_tint= 38 | alias_native :texture, :texture, as: Texture 39 | alias_native :texture= 40 | 41 | alias_native :width 42 | alias_native :width= 43 | alias_native :height 44 | alias_native :height= 45 | 46 | end 47 | end 48 | -------------------------------------------------------------------------------- /lib/opal/pixi/core/text/text.rb: -------------------------------------------------------------------------------- 1 | require 'opal/pixi/core/sprites/sprite' 2 | 3 | module PIXI 4 | class Text < PIXI::Sprite 5 | include Native 6 | 7 | def initialize(text_or_native, style={}, resolution=1) 8 | if native?(text_or_native) 9 | super(text_or_native) 10 | else 11 | super(`new PIXI.Text(text_or_native, #{style.to_n}, resolution)`) 12 | end 13 | end 14 | 15 | alias_native :canvas 16 | alias_native :context 17 | alias_native :resolution 18 | alias_native :text 19 | alias_native :text= 20 | alias_native :style 21 | alias_native :style= 22 | 23 | alias_native :render_webGL, :renderWebGL 24 | alias_native :getBounds, :getBounds 25 | alias_native :destroy 26 | 27 | end 28 | end 29 | -------------------------------------------------------------------------------- /lib/opal/pixi/core/textures/render_texture.rb: -------------------------------------------------------------------------------- 1 | module PIXI 2 | class RenderTexture 3 | include Native 4 | 5 | def initialize(native_or_renderer, width=100, height=100, scaleMode=`CONST.SCALE_MODES.DEFAULT`, resolution=1) 6 | if native?(native_or_renderer) 7 | super 8 | else 9 | super(`new PIXI.RenderTexture(#{native_or_renderer.to_n}, width, height, scaleMode, resolution)`) 10 | end 11 | end 12 | 13 | 14 | alias_native :render 15 | 16 | end 17 | end 18 | -------------------------------------------------------------------------------- /lib/opal/pixi/core/textures/texture.rb: -------------------------------------------------------------------------------- 1 | module PIXI 2 | class Texture 3 | include Native 4 | 5 | def self.from_image(name) 6 | new(`PIXI.Texture.fromImage(name)`) 7 | end 8 | 9 | def self.from_frame(name) 10 | new(`PIXI.Texture.fromFrame(name)`) 11 | end 12 | 13 | def self.from_video(name) 14 | new(`PIXI.Texture.fromVideo(name)`) 15 | end 16 | 17 | end 18 | end 19 | -------------------------------------------------------------------------------- /lib/opal/pixi/display_object.rb: -------------------------------------------------------------------------------- 1 | require './base' 2 | 3 | module PIXI 4 | class DisplayObject 5 | #include PIXI::Base 6 | # class_name = self.name.split('::').last || '' 7 | # code = "self._proto = window.PIXI.#{class_name}.prototype, def = self._proto; window.PIXI.#{class_name}.prototype._klass = self" 8 | # # %x{ alert(code) } 9 | # %x{ eval(code) } 10 | 11 | %x{ 12 | self._proto = window.PIXI.DisplayObject.prototype, def = self._proto; 13 | window.PIXI.DisplayObject.prototype._klass = self; 14 | } 15 | 16 | def position 17 | `self.position` 18 | end 19 | 20 | def position=(point) 21 | `self.position = point` 22 | end 23 | 24 | def rotation 25 | `self.rotation` 26 | end 27 | 28 | def rotation=(r) 29 | `self.rotation = r` 30 | end 31 | 32 | def anchor=(a) 33 | `self.anchor = a` 34 | end 35 | 36 | def anchor 37 | Point.new `self.anchor.x`,`self.anchor.y` 38 | end 39 | 40 | end 41 | end 42 | -------------------------------------------------------------------------------- /lib/opal/pixi/extras/movie_clip.rb: -------------------------------------------------------------------------------- 1 | require 'opal/pixi/core/sprites/sprite' 2 | 3 | module PIXI::Extras 4 | class MovieClip < PIXI::Sprite 5 | include Native 6 | 7 | def initialize(textures) 8 | super(`new PIXI.extras.MovieClip(#{textures.to_n})`) 9 | end 10 | 11 | alias_native :animation_speed, :animationSpeed 12 | alias_native :animation_speed=, :animationSpeed= 13 | alias_native :play 14 | 15 | end 16 | end 17 | -------------------------------------------------------------------------------- /lib/opal/pixi/extras/tiling_sprite.rb: -------------------------------------------------------------------------------- 1 | require 'opal/pixi/core/sprites/sprite' 2 | require 'opal/pixi/core/math/point' 3 | 4 | module PIXI::Extras 5 | class TilingSprite < PIXI::Sprite 6 | include Native 7 | 8 | def initialize(texture, width, height) 9 | super(`new PIXI.extras.TilingSprite(#{texture.to_n},#{width},#{height})`) 10 | end 11 | 12 | alias_native :tile_scale, :tileScale, as: Point 13 | alias_native :tile_scale=, :tileScale= 14 | alias_native :tile_position, :tilePosition, as: Point 15 | alias_native :tile_position=, :tilePosition= 16 | 17 | end 18 | end 19 | -------------------------------------------------------------------------------- /lib/opal/pixi/graphics.rb: -------------------------------------------------------------------------------- 1 | module PIXI 2 | class Graphics #< `PIXI.Graphics` 3 | include Native 4 | 5 | def initialize 6 | super(`new PIXI.Graphics()`) 7 | end 8 | 9 | alias_native :height 10 | alias_native :isMask 11 | alias_native :lineColor 12 | alias_native :lineWidth 13 | 14 | alias_native :worldVisible 15 | alias_native :clear 16 | alias_native :beginFill 17 | alias_native :lineStyle 18 | 19 | alias_native :moveTo 20 | alias_native :quadraticCurveTo 21 | alias_native :drawRect 22 | alias_native :bezierCurveTo 23 | alias_native :lineTo 24 | 25 | alias_native :add_child, :addChild 26 | 27 | end 28 | end 29 | -------------------------------------------------------------------------------- /lib/opal/pixi/interaction/interactive_target.rb: -------------------------------------------------------------------------------- 1 | require 'opal/pixi/core/math/point' 2 | 3 | module PIXI 4 | module InteractiveTarget 5 | include Native 6 | 7 | alias_native :interactive 8 | alias_native :interactive= 9 | alias_native :interactive_children, :interactiveChildren 10 | alias_native :interactive_children=, :interactiveChildren= 11 | alias_native :default_cursor, :defaultCursor 12 | alias_native :default_cursor=, :defaultCursor= 13 | 14 | alias_native :on 15 | end 16 | end 17 | -------------------------------------------------------------------------------- /lib/opal/pixi/mesh/mesh.rb: -------------------------------------------------------------------------------- 1 | require 'opal/pixi/core/display/container' 2 | require 'opal/pixi/core/math/point' 3 | 4 | module PIXI::Mesh 5 | class Mesh < PIXI::Container 6 | include Native 7 | 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /lib/opal/pixi/mesh/rope.rb: -------------------------------------------------------------------------------- 1 | require 'opal/pixi/core/math/point' 2 | 3 | module PIXI::Mesh 4 | class Rope < PIXI::Mesh::Mesh 5 | include Native 6 | 7 | def initialize(texture, points) 8 | super(`new PIXI.mesh.Rope(#{texture.to_n}, #{points.to_n})`) 9 | end 10 | 11 | alias_native :position 12 | 13 | end 14 | end 15 | -------------------------------------------------------------------------------- /lib/opal/pixi/point.rb: -------------------------------------------------------------------------------- 1 | require './base' 2 | 3 | module PIXI 4 | class Point 5 | include Native 6 | 7 | %x{ 8 | self._proto = window.PIXI.Point.prototype, def = self._proto; 9 | window.PIXI.Point.prototype._klass = self; 10 | } 11 | 12 | def self.new(x,y) 13 | `new window.PIXI.Point(x,y)` 14 | end 15 | 16 | 17 | alias_native :set 18 | alias_native :x 19 | alias_native :y 20 | 21 | alias_native :x= 22 | alias_native :y= 23 | 24 | # just add another point to this one 25 | # return self for chaining 26 | def add point 27 | self.x += point.x 28 | self.y += point.y 29 | self 30 | end 31 | 32 | # add a point (the first arg), but "bounce" off the wall, second arg 33 | # second arg is a pint that defines a rectangle with 0,0 34 | # if the adding makes the point go beyond the rectangle it bounces off the wall back in 35 | def add_and_bounce distance , wall 36 | self.add(distance).bounce(wall) 37 | self 38 | end 39 | 40 | # check if the point is outside the rectangle spanned by the wall arg (a point) 41 | def bounce wall 42 | self.x = - self.x if self.x < 0 43 | self.x = wall.x - (self.x - wall.x) if self.x > wall.x 44 | self.y = -self.y if self.y < 0 45 | self.y = wall.y - (self.y - wall.y) if self.y > wall.y 46 | end 47 | 48 | # scale the point down by the given factor. 49 | # off course for factors smaller than 1 that means it gets bigger 50 | # try to avoid 0 division by applying a minimum of 0.0001 51 | def scale_by num 52 | min = 0.001 53 | num = min if num < min and num > -min 54 | self.x = self.x / num 55 | self.y = self.y / num 56 | self 57 | end 58 | 59 | # return new point with same x coordiante but the given y 60 | def at_y new_y 61 | PIXI::Point.new(self.x ,new_y) 62 | end 63 | 64 | # return new point with same y coordiante but the given x 65 | def at_x new_x 66 | PIXI::Point.new(new_x , self.y) 67 | end 68 | 69 | end 70 | end 71 | -------------------------------------------------------------------------------- /lib/opal/pixi/setup.rb: -------------------------------------------------------------------------------- 1 | # We need the Opal Native support library here: 2 | require 'native' 3 | 4 | # These requires must be loaded in order of dependency: 5 | require 'opal/pixi/core/files' 6 | require 'opal/pixi/extras/movie_clip' 7 | require 'opal/pixi/extras/tiling_sprite' 8 | require 'opal/pixi/interaction/interactive_target' 9 | require 'opal/pixi/mesh/mesh' 10 | require 'opal/pixi/mesh/rope' 11 | 12 | # TODO: This is odd here as it doesn't fit the files.rb require pattern... how can we clean this up? 13 | #require 'opal/pixi/core/game' 14 | -------------------------------------------------------------------------------- /lib/opal/pixi/sprite.rb: -------------------------------------------------------------------------------- 1 | require './base' 2 | 3 | module PIXI 4 | class Sprite < PIXI::DisplayObject 5 | include Native 6 | 7 | 8 | alias_native :anchor, :anchor, as: Point 9 | alias_native :rotation 10 | alias_native :interactive= 11 | alias_native :position, :position, as: Point 12 | alias_native :on 13 | alias_native :anchor= 14 | alias_native :position= 15 | alias_native :rotation= 16 | 17 | alias_native :x 18 | alias_native :y 19 | alias_native :x= 20 | alias_native :y= 21 | alias_native :z 22 | alias_native :z= 23 | 24 | alias_native :height 25 | alias_native :width 26 | 27 | alias_native :scale 28 | alias_native :visible= 29 | 30 | alias_native :destroy 31 | 32 | def crop(rect) 33 | `#@native.crop(#{rect.to_n})` 34 | end 35 | 36 | def smoothed=(bool) 37 | `#@native.smoothed = bool` 38 | end 39 | 40 | %x{ 41 | self._proto = window.PIXI.Sprite.prototype, def = self._proto; 42 | window.PIXI.Sprite.prototype._klass = self; 43 | } 44 | 45 | def self.new(texture) 46 | `new window.PIXI.Sprite(texture)` 47 | end 48 | 49 | end 50 | end 51 | -------------------------------------------------------------------------------- /lib/opal/pixi/text.rb: -------------------------------------------------------------------------------- 1 | module PIXI 2 | class Text 3 | include Native 4 | 5 | # options according to http://pixijs.github.io/docs/PIXI.Text.html 6 | def initialize(x_or_native, y) 7 | if native?(x_or_native) 8 | super(x_or_native) 9 | else 10 | super(`new PIXI.Text(x_or_native,y)`) 11 | end 12 | end 13 | 14 | alias_native :width 15 | alias_native :position, :position, as: Point 16 | 17 | alias_native :position= 18 | alias_native :text= 19 | 20 | 21 | end 22 | end 23 | -------------------------------------------------------------------------------- /lib/opal/pixi/texture.rb: -------------------------------------------------------------------------------- 1 | require './base' 2 | 3 | module PIXI 4 | class Texture 5 | include Native 6 | 7 | %x{ 8 | self._proto = window.PIXI.Texture.prototype, def = self._proto; 9 | window.PIXI.Texture.prototype._klass = self; 10 | } 11 | 12 | def self.from_image(name) 13 | new(`PIXI.Texture.fromImage(name)`) 14 | end 15 | end 16 | end 17 | -------------------------------------------------------------------------------- /lib/opal/pixi/version.rb: -------------------------------------------------------------------------------- 1 | module Opal 2 | module PIXI 3 | VERSION = '0.3.6' 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /lib/opal/pixi/web_gl_renderer.rb: -------------------------------------------------------------------------------- 1 | #require './base' 2 | 3 | module PIXI 4 | class WebGLRenderer 5 | include Native 6 | 7 | %x{ 8 | self._proto = window.PIXI.WebGLRenderer.prototype, def = self._proto; 9 | window.PIXI.WebGLRenderer.prototype._klass = self; 10 | } 11 | 12 | def self.new(width, height, options) 13 | %x{new window.PIXI.WebGLRenderer(width, height, { backgroundColor : #{options[:background_color]} })} 14 | end 15 | 16 | def render(object) 17 | `self.render(object)` 18 | end 19 | 20 | def destroy(removeView) 21 | `self.destroy(removeView)` 22 | end 23 | 24 | alias_native :render 25 | alias_native :view 26 | alias_native :width 27 | alias_native :height 28 | 29 | end 30 | end 31 | -------------------------------------------------------------------------------- /opal-pixi.gemspec: -------------------------------------------------------------------------------- 1 | # -*- encoding: utf-8 -*- 2 | require File.expand_path('../lib/opal/pixi/version', __FILE__) 3 | 4 | Gem::Specification.new do |s| 5 | s.name = 'opal-pixi' 6 | s.version = Opal::PIXI::VERSION 7 | s.authors = [ 'George D. Plymale II', 'Gabriel Rios', 'Keith Salisbury' ] 8 | s.email = [ 'gabrielfalcaorios@gmail.com', 'keith.salisbury@alliants.com'] 9 | s.homepage = 'http://github.com/orbitalimpact/opal-pixi' 10 | s.summary = 'Opal access to pixi' 11 | s.description = 'Opal DOM library for pixi' 12 | 13 | s.files = `git ls-files`.split("\n") 14 | s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) } 15 | s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") 16 | s.require_paths = ['lib'] 17 | 18 | s.add_runtime_dependency 'opal', '~> 0.10.0' 19 | s.add_development_dependency 'opal-rspec' 20 | s.add_development_dependency 'yard' 21 | s.add_development_dependency 'rake' 22 | end 23 | -------------------------------------------------------------------------------- /spec/spec_helper.rb: -------------------------------------------------------------------------------- 1 | require 'opal-rspec' 2 | require 'opal-pixi' 3 | --------------------------------------------------------------------------------