Module: Moon::RenderPrimitive::ScreenElement

Includes:
Rectangular
Included in:
Moon::RenderContext
Defined in:
lib/moon/packages/render_primitives/screen_element.rb

Overview

I can be shot for this afterwards…

Instance Attribute Summary

Attributes included from Rectangular

#h, #position, #w

Instance Method Summary collapse

Methods included from Rectangular

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

Instance Method Details

#contains_pos?(x, y) ⇒ Boolean #contains_pos?(vec2) ⇒ Boolean

Determines if position is inside the Container

Overloads:

Returns:


47
48
49
50
# File 'lib/moon/packages/render_primitives/screen_element.rb', line 47

def contains_pos?(*args)
  px, py = *Vector2.extract(args.size > 1 ? args : args.first)
  px.between?(x, x2) && py.between?(y, y2)
end

#contains_pos?(x, y) ⇒ Boolean #contains_pos?(vec2) ⇒ Boolean

Determines if position is inside the Container relatively

Overloads:

Returns:


60
61
62
63
# File 'lib/moon/packages/render_primitives/screen_element.rb', line 60

def relative_contains_pos?(*args)
  px, py = *Vector2.extract(args.size > 1 ? args : args.first)
  px.between?(0, w) && py.between?(0, h)
end

#relative_to_screen(x, y) ⇒ Moon::Vector2 #relative_to_screen(vec2) ⇒ Moon::Vector2

Convert a relative position in the Container to a screen position

Overloads:

Returns:


32
33
34
35
36
37
# File 'lib/moon/packages/render_primitives/screen_element.rb', line 32

def relative_to_screen(*args)
  vec2 = Vector2[*args]
  vec2.x += x
  vec2.y += y
  vec2
end

#screen_to_relative(x, y) ⇒ Moon::Vector2 #screen_to_relative(vec2) ⇒ Moon::Vector2

Convert a screen position to a relative position in the Container

Overloads:

Returns:


17
18
19
20
21
22
# File 'lib/moon/packages/render_primitives/screen_element.rb', line 17

def screen_to_relative(*args)
  vec2 = Vector2[*args]
  vec2.x -= x
  vec2.y -= y
  vec2
end