Sha256: 79b65007203e218a58fa8da68ed5ad924229ce85ce426b4198f5dd6327534366

Contents?: true

Size: 1.7 KB

Versions: 1

Compression:

Stored size: 1.7 KB

Contents

module Joybox
  module Debug
    module Node

      def self.included(base)
        base.send(:attr_accessor, :proxy_view)
        base.send(:attr_accessor, :bounding_box_layer)
      end

      def initialize
        @proxy_view = ProxyView.alloc.initWithFrame(translated_bounding_box)
        @proxy_view.userInteractionEnabled = false
        @proxy_view.node = self
        Joybox.director.view.addSubview(@proxy_view)

        initialize_bounding_box_layer if Joybox::Debug.bounding_box
      end

      def initialize_bounding_box_layer
        @bounding_box_layer = CALayer.layer
        @bounding_box_layer.borderColor = UIColor.greenColor.CGColor
        @bounding_box_layer.borderWidth = 2
        @bounding_box_layer.frame = translated_bounding_box

        @proxy_view.layer.addSublayer(@bounding_box_layer)
      end

      def cleanup
        @proxy_view.removeFromSuperview
        super
      end

      def translated_bounding_box
        bounding_box = boundingBox
        bounding_box.origin = bounding_box.origin.from_opengl_coordinates
        bounding_box.origin.y = bounding_box.origin.y - bounding_box.size.height
        bounding_box
      end

      def setPosition(position)
        super
        update_bounding_box
      end

      def setContentSize(size)
        super
        @proxy_view.removeFromSuperview if boundingBox.size.width == Screen.width
        update_bounding_box
      end

      def nodeToParentTransform
        update_bounding_box
        super
      end


      private

      def update_bounding_box
        @proxy_view.frame = translated_bounding_box unless @proxy_view.nil?
        @bounding_box_layer.frame = @proxy_view.bounds unless @bounding_box_layer.nil?
      end

    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
joybox-1.0.0 motion/joybox-ios/debug/node.rb