Skip to content

Commit

Permalink
Merge pull request rubymotion-community#59 from meganemura/add-layer-…
Browse files Browse the repository at this point in the history
…gradient

Adds:
=> `Joybox::Core::LayerGradient`
  • Loading branch information
Juan Jose Karam committed Nov 12, 2013
2 parents e516051 + f1731c0 commit 0b3fe8f
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 0 deletions.
9 changes: 9 additions & 0 deletions motion/joybox-ios/core/layer_gradient.rb
@@ -0,0 +1,9 @@
module Joybox
module Core

class LayerGradient < CCLayerGradient
include TouchEvent
end

end
end
13 changes: 13 additions & 0 deletions motion/joybox-osx/core/layer_gradient.rb
@@ -0,0 +1,13 @@
module Joybox
module Core

class LayerGradient < CCLayerGradient

include MouseEvent
include KeyboardEvent
include GestureEvent

end

end
end
45 changes: 45 additions & 0 deletions motion/joybox/core/layer_gradient.rb
@@ -0,0 +1,45 @@
module Joybox
module Core

class LayerGradient < CCLayerGradient

include Joybox::Common

def self.scene
define_singleton_method(:scene) do |options = {}|
scene = CCScene.new
layer = self.new(options)
scene << layer
end
end

def self.defaults
{
vector: [0, -1]
}
end

def initialize(options = {})
options = self.class.defaults.merge(options)

layer = self.initWithColor(options[:start],
fadingTo: options[:end],
alongVector: options[:vector])

layer.position = options[:position] if options[:position]
end

def onEnter
super
on_enter if defined? (on_enter)
end

def onExit
super
on_exit if defined? (on_exit)
end

end

end
end
24 changes: 24 additions & 0 deletions spec/motion/joybox/core/layer_gradient_spec.rb
@@ -0,0 +1,24 @@
describe Joybox::Core::LayerGradient do

describe "LayerGradient.new" do
it "should initialize" do
layer = Joybox::Core::LayerGradient.new(
start: [1, 2, 3, 4],
end: [1, 2, 3, 4],
vector: [1, 2])
layer.should.not == nil
layer.visible.should == true
layer.class.should == Joybox::Core::LayerGradient
end
end

describe "LayerGradient.scene" do
it "should define singleton method and return CCScene with LayerGradient" do
Joybox::Core::LayerGradient.scene
scene = Joybox::Core::LayerGradient.scene(start: [1, 2, 3, 4], end: [5, 6, 7, 8], vector: [1, 2])
scene.class.should == CCScene
scene.children.first.class.should == Joybox::Core::LayerGradient
end
end

end

0 comments on commit 0b3fe8f

Please sign in to comment.