opal-pixi 0.2.1 → 0.3.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +0 -1
  3. data/README.md +22 -30
  4. data/Rakefile +45 -0
  5. data/lib/opal/pixi.rb +1 -8
  6. data/lib/opal/pixi/base.rb +14 -0
  7. data/lib/opal/pixi/container.rb +32 -4
  8. data/lib/opal/pixi/core/display/container.rb +38 -0
  9. data/lib/opal/pixi/core/display/display_object.rb +44 -0
  10. data/lib/opal/pixi/core/files.rb +18 -0
  11. data/lib/opal/pixi/core/graphics/graphics.rb +42 -0
  12. data/lib/opal/pixi/core/graphics/graphics_data.rb +19 -0
  13. data/lib/opal/pixi/core/graphics/webgl/graphics_renderer.rb +0 -0
  14. data/lib/opal/pixi/core/graphics/webgl/web_gl_graphics_data.rb +11 -0
  15. data/lib/opal/pixi/core/math/matrix.rb +40 -0
  16. data/lib/opal/pixi/core/math/point.rb +24 -0
  17. data/lib/opal/pixi/core/math/shapes/circle.rb +26 -0
  18. data/lib/opal/pixi/core/math/shapes/ellipse.rb +28 -0
  19. data/lib/opal/pixi/core/math/shapes/polygon.rb +23 -0
  20. data/lib/opal/pixi/core/math/shapes/rectangle.rb +27 -0
  21. data/lib/opal/pixi/core/math/shapes/rounded_rectangle.rb +29 -0
  22. data/lib/opal/pixi/core/renderers/canvas/canvas_renderer.rb +19 -0
  23. data/lib/opal/pixi/core/renderers/system_renderer.rb +9 -0
  24. data/lib/opal/pixi/core/renderers/webgl/filters/abstract_filter.rb +16 -0
  25. data/lib/opal/pixi/core/renderers/webgl/webgl_renderer.rb +20 -0
  26. data/lib/opal/pixi/core/sprites/sprite.rb +47 -0
  27. data/lib/opal/pixi/core/text/text.rb +28 -0
  28. data/lib/opal/pixi/core/textures/render_texture.rb +17 -0
  29. data/lib/opal/pixi/core/textures/texture.rb +18 -0
  30. data/lib/opal/pixi/display_object.rb +41 -0
  31. data/lib/opal/pixi/extras/movie_clip.rb +16 -0
  32. data/lib/opal/pixi/extras/tiling_sprite.rb +18 -0
  33. data/lib/opal/pixi/interaction/interactive_target.rb +16 -0
  34. data/lib/opal/pixi/mesh/mesh.rb +9 -0
  35. data/lib/opal/pixi/mesh/rope.rb +14 -0
  36. data/lib/opal/pixi/point.rb +10 -6
  37. data/lib/opal/pixi/setup.rb +13 -0
  38. data/lib/opal/pixi/sprite.rb +37 -11
  39. data/lib/opal/pixi/texture.rb +7 -1
  40. data/lib/opal/pixi/version.rb +1 -1
  41. data/lib/opal/pixi/web_gl_renderer.rb +18 -7
  42. data/opal-pixi.gemspec +11 -9
  43. data/spec/spec_helper.rb +2 -0
  44. metadata +70 -18
  45. data/demo/Gemfile +0 -3
  46. data/demo/app/main.rb +0 -49
  47. data/demo/bunny.png +0 -0
  48. data/demo/config.ru +0 -11
  49. data/demo/index.html +0 -19
  50. data/demo/pixi.js +0 -27488
  51. data/demo/pixi.js.map +0 -1
  52. data/demo/pixi.min.js +0 -11
  53. data/demo/pixi.min.js.map +0 -1
  54. data/demo/pixi_main.js +0 -36
  55. data/demo/style.css +0 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3055d4f96ee99fa36d6f73183eab9b8dd0da805e
4
- data.tar.gz: 1afd47322358c97e4a53715d7f72e73fa51dc019
3
+ metadata.gz: a99f57549d2d962eae3275ed573faa53a93d7350
4
+ data.tar.gz: 99bebe3f31dc09fbfcf7f2a34aab53930738f442
5
5
  SHA512:
6
- metadata.gz: 7e1d4a965bb75304b0516ce139c4637a36e8e6c89d4d8824a2a0a753b7936e7b11a2a6d9c3b8ff94e1694bb55ed16e8f6971c9692d61ec0810d7be12eb812366
7
- data.tar.gz: 70b2b30beca29c7fc50465724d4da8d7362ae9e5cb6fcfd8f114bf1ebba3ef898e281bb90d8638c3ab82e0c7c93d5a818b9c225a3fcbe495d669c8303f34edd7
6
+ metadata.gz: 5657530b7bd0aa53ca5c8c96b3a148377ee9712ac4073e9f9f3ffe662b667e5537b4833b7dc9539559e7cd57d4e373da911cbda2b77fc39e873223e34e1ef40c
7
+ data.tar.gz: d4ae86ccf458287e1e130e60b4d228a340fed9fa7529e9d59087fcfbe15910f5a9ff20ec272f150af99aeaae18f2cba99b50924b0230cc040bbc0dd1b54b3a3b
data/.gitignore CHANGED
@@ -8,7 +8,6 @@
8
8
  .idea
9
9
 
10
10
  ## Ignore demo's Gemfile.lock
11
- demo/Gemfile.lock
12
11
  *Gemfile.lock
13
12
 
14
13
  pkg
data/README.md CHANGED
@@ -1,45 +1,37 @@
1
1
  ## Ruby wrapper for the Pixi.js graphical library
2
2
 
3
- ### Pixi.js - A 2D JavaScript Renderer
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
4
 
5
- - WebGl renderer with canvas fallback
6
- - "it's fast. Really fast"
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.
7
6
 
8
- Pixie has a nice set of features to bake graphics and even move them around.
9
- It's low-ish level, but very useful and **fast** .
7
+ If you have not heard of Pixi, check out these links:
10
8
 
11
- See the [Pixi's docs](http://pixijs.github.io/docs/) or a post about
12
- [Version 3](http://www.goodboydigital.com/pixi-js-v3/)
9
+ * Pixi: https://github.com/GoodBoyDigital/pixi.js/
10
+ * Pixi Examples: https://github.com/pixijs/examples
13
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).
14
13
 
15
- ### Ruby wrapper
14
+ ## Cloning this repository
16
15
 
17
- The wrapper is off course done with Opal, but there are no further dependencies.
18
-
19
- The project is quite jung, so better to help than expect.
20
-
21
- ### Usage
22
-
23
- Check out the [demo code](https://github.com/orbitalimpact/opal-pixi/blob/master/demo/app/main.rb)
24
- and read the [pixi resources](https://github.com/GoodBoyDigital/pixi.js/wiki/Resources)
16
+ ```
17
+ $ git clone https://github.com/orbitalimpact/opal-pixi
18
+ ```
25
19
 
26
- Two main components are needed, a Container and a Renderer.
27
- You can add things to display to a container,
28
- like Sprites (with texture) and all sorts of objects and collections thereof.
20
+ ## Getting involved
29
21
 
30
- And then you can get the view element from the renderer and add it to your dom.
22
+ To contribute to this project, follow the steps below.
31
23
 
32
- And render the container with the [requestAnimationFrame](https://developer.mozilla.org/en-US/docs/Web/API/window/requestAnimationFrame)
33
- method. There are some links there about the new async way to render.
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
34
29
 
35
- ### Demo
30
+ ## Licenses
36
31
 
37
- There is a small demo in the demo directory. To run it clone the repository,
32
+ Phaser and all examples are released under the MIT License: http://opensource.org/licenses/MIT
38
33
 
39
- ```
40
- cd demo
41
- bundle
42
- bundle exec rackup
43
- ```
34
+ opal-pixi is released under the Berkeley Software Distribution (BSD) 3-Clause License: http://opensource.org/licenses/BSD-3-Clause
44
35
 
45
- and go to localhost:9292
36
+ Copyright (c) 2015, Orbital Impact
37
+ All rights reserved.
data/Rakefile CHANGED
@@ -1,3 +1,48 @@
1
1
  require 'bundler'
2
2
  Bundler.require
3
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
data/lib/opal/pixi.rb CHANGED
@@ -1,12 +1,5 @@
1
1
  if RUBY_ENGINE == 'opal'
2
- require 'native'
3
- require 'opal/pixi/container'
4
- require 'opal/pixi/graphics'
5
- require 'opal/pixi/web_gl_renderer'
6
- require 'opal/pixi/sprite'
7
- require 'opal/pixi/text'
8
- require 'opal/pixi/point'
9
- require 'opal/pixi/texture'
2
+ require 'opal/pixi/setup'
10
3
  else
11
4
  require 'opal'
12
5
  require 'opal/pixi/version'
@@ -0,0 +1,14 @@
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
@@ -1,12 +1,40 @@
1
+ require 'native'
2
+ require './base'
3
+ require './display_object'
4
+
1
5
  module PIXI
2
- class Container #< `PIXI.Container`
6
+ class Container < PIXI::DisplayObject
3
7
  include Native
4
8
 
5
- def initialize
6
- super(`new PIXI.Container()`)
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`
7
36
  end
8
37
 
9
- alias_native :add_child, :addChild
10
38
 
11
39
  end
12
40
  end
@@ -0,0 +1,38 @@
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
@@ -0,0 +1,44 @@
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
@@ -0,0 +1,18 @@
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'
@@ -0,0 +1,42 @@
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
@@ -0,0 +1,19 @@
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
@@ -0,0 +1,11 @@
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
@@ -0,0 +1,40 @@
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
@@ -0,0 +1,24 @@
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