Module: MotionPrime::DrawSectionMixin

Extended by:
MotionSupport::Concern
Includes:
FrameCalculatorMixin, HasStyles, SectionWithContainerMixin
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 SectionWithContainerMixin

#container_view, #init_container_element, #load_container_with_elements

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.



9
10
11
# File 'motion-prime/sections/_draw_section_mixin.rb', line 9

def cached_draw_image
  @cached_draw_image
end

#container_elementObject

Returns the value of attribute container_element.



9
10
11
# File 'motion-prime/sections/_draw_section_mixin.rb', line 9

def container_element
  @container_element
end

#container_gesture_recognizersObject

Returns the value of attribute container_gesture_recognizers.



9
10
11
# File 'motion-prime/sections/_draw_section_mixin.rb', line 9

def container_gesture_recognizers
  @container_gesture_recognizers
end

Instance Method Details

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



30
31
32
33
34
35
36
# File 'motion-prime/sections/_draw_section_mixin.rb', line 30

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

#clear_gesture_for_receiver(receiver) ⇒ Object



38
39
40
41
# File 'motion-prime/sections/_draw_section_mixin.rb', line 38

def clear_gesture_for_receiver(receiver)
  return unless self.container_gesture_recognizers
  self.container_gesture_recognizers.delete_if { |recognizer| recognizer[:receiver] == receiver }
end

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



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

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

#prerender_elements_for_state(state = :normal) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'motion-prime/sections/_draw_section_mixin.rb', line 43

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)


60
61
62
# File 'motion-prime/sections/_draw_section_mixin.rb', line 60

def prerender_enabled?
  self.class.prerender_enabled
end