Class: Moon::RenderContext

Constant Summary collapse

@@context_id =

Returns id counter.

Returns:

0

Instance Attribute Summary collapse

Attributes included from Moon::RenderPrimitive::DataAttributes

#data_attrs

Attributes included from Moon::RenderPrimitive::Containable

#parent

Instance Method Summary collapse

Methods included from Moon::RenderPrimitive::DataAttributes

#initialize_data_attrs

Methods included from Moon::RenderPrimitive::Rectangular

#align!, #bounds, #contains?, #cx, #cx=, #cy, #cy=, #move, #on_resize, #resize, #to_rect, #x, #x2, #x2=, #x=, #y, #y2, #y2=, #y=, #z, #z=

Methods included from Moon::RenderPrimitive::Containable

#containerize, #disown

Methods included from Moon::RenderPrimitive::Visibility

#hide, #invisible?, #show, #visible?

Methods included from Moon::RenderPrimitive::Renderable

#render

Methods included from Moon::RenderPrimitive::ScreenElement

#contains_pos?, #relative_contains_pos?, #relative_to_screen, #screen_to_relative

Methods included from Eventable

#allow_event?, #clear_events, #each_listener, #each_typed_listener, filter_from_options, #has_events?, #initialize_eventable, #off, #on, #ppd_ev, #trigger, #typing

Methods included from Transitionable

#key_transition, #remove_transitions, #transition

Methods included from TransitionHost

#add_transition, #finish_transitions, #remove_transition, #remove_transitions, #update_transitions

Constructor Details

#initialize(options = {}) ⇒ RenderContext

Returns a new instance of RenderContext.

Parameters:


35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/moon/packages/render_primitives/render_context.rb', line 35

def initialize(options = {})
  pre_initialize
  initialize_data_attrs

  initialize_members

  initialize_from_options(options)

  initialize_eventable
  initialize_content
  initialize_events
  init

  if block_given?
    yield self
  end

  post_initialize
  puts "Created a #{self.class}"
end

Instance Attribute Details

#idInteger (readonly)

Returns RenderContext id.

Returns:


30
31
32
# File 'lib/moon/packages/render_primitives/render_context.rb', line 30

def id
  @id
end

#visible=(value) ⇒ Boolean

Returns:


24
25
26
# File 'lib/moon/packages/render_primitives/render_context.rb', line 24

def visible=(value)
  @visible = value
end

Instance Method Details

#apply_position_modifier(vec3 = 0) ⇒ Moon::Vector3

Parameters:

Returns:


115
116
117
# File 'lib/moon/packages/render_primitives/render_context.rb', line 115

def apply_position_modifier(vec3 = 0)
  @position + vec3
end

#post_initializeObject


59
60
# File 'lib/moon/packages/render_primitives/render_context.rb', line 59

def post_initialize
end

#pre_initializeObject


56
57
# File 'lib/moon/packages/render_primitives/render_context.rb', line 56

def pre_initialize
end

#render?Boolean

Returns:


94
95
96
# File 'lib/moon/packages/render_primitives/render_context.rb', line 94

def render?
  visible?
end

#render_abs(x, y, z, options) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Renderable callback, this method applies the position_modifiers and finally cals #render_content

Parameters:


151
152
153
154
155
# File 'lib/moon/packages/render_primitives/render_context.rb', line 151

def render_abs(x, y, z, options)
  px, py, pz = *apply_position_modifier(Moon::Vector3.new(x, y, z))
  render_content(px, py, pz, options)
  super
end

#render_content(x, y, z, options) ⇒ Object

Overwrite this method to define your own rendering, the coordinates provided are transformed to be the final position on screen.

Parameters:


139
140
141
# File 'lib/moon/packages/render_primitives/render_context.rb', line 139

def render_content(x, y, z, options)
  #
end

#screen_boundsMoon::Rect

Returns:


88
89
90
91
# File 'lib/moon/packages/render_primitives/render_context.rb', line 88

def screen_bounds
  x, y = *screen_position
  Moon::Rect.new(x, y, w, h)
end

#screen_positionMoon::Vector3

Returns:


81
82
83
84
85
# File 'lib/moon/packages/render_primitives/render_context.rb', line 81

def screen_position
  pos = apply_position_modifier
  return pos unless parent
  pos + parent.screen_position
end

#update(delta) ⇒ Object

Parameters:


126
127
128
129
# File 'lib/moon/packages/render_primitives/render_context.rb', line 126

def update(delta)
  update_content(delta)
  update_transitions(delta)
end