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
-
#cached_draw_image ⇒ Object
Returns the value of attribute cached_draw_image.
-
#container_element ⇒ Object
Returns the value of attribute container_element.
-
#container_gesture_recognizers ⇒ Object
Returns the value of attribute container_gesture_recognizers.
Instance Method Summary collapse
- #bind_gesture_on_container_for(element, action, receiver = nil) ⇒ Object
- #clear_gesture_for_receiver(receiver) ⇒ Object
- #draw_in(rect, state = :normal) ⇒ Object
- #prerender_elements_for_state(state = :normal) ⇒ Object
- #prerender_enabled? ⇒ Boolean
Methods included from SectionWithContainerMixin
#container_view, #init_container_element, #load_container_with_elements
Methods included from FrameCalculatorMixin
Methods included from HasStyles
Instance Attribute Details
#cached_draw_image ⇒ Object
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_element ⇒ Object
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_recognizers ⇒ Object
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
#bind_gesture_on_container_for(element, action, receiver = nil) ⇒ Object
31 32 33 34 35 36 37 |
# File 'motion-prime/sections/_draw_section_mixin.rb', line 31 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
39 40 41 42 43 44 |
# File 'motion-prime/sections/_draw_section_mixin.rb', line 39 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
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'motion-prime/sections/_draw_section_mixin.rb', line 46 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
63 64 65 |
# File 'motion-prime/sections/_draw_section_mixin.rb', line 63 def prerender_enabled? self.class.prerender_enabled end |