Module: Glimmer::LibUI::PerfectShaped

Extended by:
Forwardable
Included in:
ControlProxy::PathProxy, ControlProxy::TextProxy, Shape
Defined in:
lib/glimmer/libui/perfect_shaped.rb

Overview

GUI View objects that can be represented by PerfectShape objects

Instance Method Summary collapse

Instance Method Details

#bounding_boxObject

Returns bounding box Array consisting of

minx, miny, width, height


35
36
37
38
39
40
41
42
43
44
# File 'lib/glimmer/libui/perfect_shaped.rb', line 35

def bounding_box
  perfect_shape_bounding_box = perfect_shape&.bounding_box
  return if perfect_shape_bounding_box.nil?
  [
    perfect_shape_bounding_box.x,
    perfect_shape_bounding_box.y,
    perfect_shape_bounding_box.width,
    perfect_shape_bounding_box.height,
  ]
end

#contain?(*point, outline: false, distance_tolerance: 0) ⇒ Boolean

Returns if shape contains point on the inside when outline is false (default) or if point is on the outline when outline is true distance_tolerance is used when outline is true to enable a fuzz factor in determining if a point lies on the outline (e.g. makes it easier to select a shape by mouse)

Returns:

  • (Boolean)


17
18
19
20
# File 'lib/glimmer/libui/perfect_shaped.rb', line 17

def contain?(*point, outline: false, distance_tolerance: 0)
  # TODO inverse transform point with `uiDrawMatrixTransformPoint` before checking containment
  perfect_shape&.contain?(*point, outline: outline, distance_tolerance: distance_tolerance)
end

#include?(*point) ⇒ Boolean

Returns if shape includes point on the inside when filled or if shape includes point on the outline when stroked

Returns:

  • (Boolean)


24
25
26
27
28
29
30
31
# File 'lib/glimmer/libui/perfect_shaped.rb', line 24

def include?(*point)
  if respond_to?(:fill) && fill.empty?
    # TODO check if distance_tolerance should be half the thickness in case it is checked against both sides of out and in
    contain?(*point, outline: true, distance_tolerance: ((stroke[:thickness] || 1) - 1))
  else
    contain?(*point)
  end
end

#move(x, y) ⇒ Object



52
53
54
55
56
# File 'lib/glimmer/libui/perfect_shaped.rb', line 52

def move(x, y)
  x_delta = x - perfect_shape.min_x
  y_delta = y - perfect_shape.min_y
  move_by(x_delta, y_delta)
end

#move_by(x_delta, y_delta) ⇒ Object Also known as: translate

moves by x delta and y delta. Classes must implement



47
48
49
# File 'lib/glimmer/libui/perfect_shaped.rb', line 47

def move_by(x_delta, y_delta)
  # No Op
end

#perfect_shapeObject

Returns PerfectShape object matching this shape to enable executing computational geometry algorithms

Including classes must implement



62
63
64
# File 'lib/glimmer/libui/perfect_shaped.rb', line 62

def perfect_shape
  # No Op
end

#perfect_shape_dependenciesObject

Returns PerfectShape object dependencies to determine if the PerfectShape object changed or not for caching purposes. Every shape/path implements this uniquely for its own PerfectShape attribute dependencies



69
70
71
# File 'lib/glimmer/libui/perfect_shaped.rb', line 69

def perfect_shape_dependencies
  # No Op
end