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_frame_for

Methods included from HasStyles

#prepare_gradient

Instance Attribute Details

#cached_draw_imageObject

Returns the value of attribute cached_draw_image.



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

def cached_draw_image
  @cached_draw_image
end

#container_elementObject

Returns the value of attribute container_element.



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

def container_element
  @container_element
end

#container_gesture_recognizersObject

Returns the value of attribute container_gesture_recognizers.



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

def container_gesture_recognizers
  @container_gesture_recognizers
end

Instance Method Details

#after_element_render(element) ⇒ Object



37
# File 'motion-prime/sections/_draw_section_mixin.rb', line 37

def after_element_render(element); end

#before_element_render(element) ⇒ Object



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

def before_element_render(element)
  return unless element == container_element
  self.container_gesture_recognizers = nil
  elements_to_draw.values.each(&:on_container_render)
end

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



39
40
41
42
43
44
45
# File 'motion-prime/sections/_draw_section_mixin.rb', line 39

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



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

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

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



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

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



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

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)


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

def prerender_enabled?
  self.class.prerender_enabled
end