Module: MotionPrime::DrawSectionMixin

Extended by:
MotionSupport::Concern
Includes:
FrameCalculatorMixin, HasStyles
Included in:
Section
Defined in:
motion-prime/sections/_draw_section_mixin.rb

Defined Under Namespace

Modules: ClassMethods

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from FrameCalculatorMixin

#calculate_frome_for

Methods included from HasStyles

#prepare_gradient

Instance Attribute Details

#cached_draw_imageObject

Returns the value of attribute cached_draw_image.



7
8
9
# File 'motion-prime/sections/_draw_section_mixin.rb', line 7

def cached_draw_image
  @cached_draw_image
end

#container_elementObject

Returns the value of attribute container_element.



7
8
9
# File 'motion-prime/sections/_draw_section_mixin.rb', line 7

def container_element
  @container_element
end

#container_gesture_recognizersObject

Returns the value of attribute container_gesture_recognizers.



7
8
9
# File 'motion-prime/sections/_draw_section_mixin.rb', line 7

def container_gesture_recognizers
  @container_gesture_recognizers
end

Instance Method Details

#bind_gesture_on_container_for(element, action, receiver = nil) ⇒ Object



47
48
49
50
51
52
53
# File 'motion-prime/sections/_draw_section_mixin.rb', line 47

def bind_gesture_on_container_for(element, action, receiver = nil)
  self.container_gesture_recognizers ||= begin
    set_container_gesture_recognizer
    []
  end
  self.container_gesture_recognizers << {element: element, action: action, receiver: receiver}
end

#container_viewObject



12
13
14
# File 'motion-prime/sections/_draw_section_mixin.rb', line 12

def container_view
  container_element.try(:view)
end

#draw_in(rect, state = :normal) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'motion-prime/sections/_draw_section_mixin.rb', line 33

def draw_in(rect, state = :normal)
  if cached_draw_image[state]
    context = UIGraphicsGetCurrentContext()
    CGContextDrawImage(context, container_bounds, cached_draw_image[state])
    render_image_elements
  elsif prerender_enabled?
    prerender_elements_for_state(state)
    draw_in(rect, state) if cached_draw_image[state]
  else
    draw_background_in_context(UIGraphicsGetCurrentContext(), rect)
    draw_elements(rect)
  end
end

#init_container_element(options = {}) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
# File 'motion-prime/sections/_draw_section_mixin.rb', line 16

def init_container_element(options = {})
  @container_element ||= begin
    options.merge!({
      screen: screen,
      section: self.weak_ref,
      has_drawn_content: true
    })
    options[:styles] ||= []
    MotionPrime::BaseElement.factory(:view_with_section, options)
  end
end

#load_container_element(options = {}) ⇒ Object



28
29
30
31
# File 'motion-prime/sections/_draw_section_mixin.rb', line 28

def load_container_element(options = {})
  init_container_element(options)
  @container_element.compute_options! unless @container_element.computed_options
end

#prerender_elements_for_state(state = :normal) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'motion-prime/sections/_draw_section_mixin.rb', line 55

def prerender_elements_for_state(state = :normal)
  scale = UIScreen.mainScreen.scale
  space = CGColorSpaceCreateDeviceRGB()
  bits_per_component = 8
  context = CGBitmapContextCreate(nil, container_bounds.size.width*scale, container_bounds.size.height*scale,
    bits_per_component, container_bounds.size.width*scale*4, space, KCGImageAlphaPremultipliedLast)

  CGContextScaleCTM(context, scale, scale)

  draw_background_in_context(context, container_bounds)
  elements_to_draw.each do |key, element|
    element.draw_in_context(context)
  end

  cached_draw_image[state] = CGBitmapContextCreateImage(context)
end

#prerender_enabled?Boolean

Returns:

  • (Boolean)


72
73
74
# File 'motion-prime/sections/_draw_section_mixin.rb', line 72

def prerender_enabled?
  self.class.prerender_enabled
end

#strong_referencesObject



80
81
82
# File 'motion-prime/sections/_draw_section_mixin.rb', line 80

def strong_references
  [self, screen.main_controller].map(&:strong_ref)
end