Class: Shoes::Star

Inherits:
Common::ArtElement show all
Defined in:
shoes-core/lib/shoes/star.rb

Constant Summary collapse

STYLES =
{ fill: Shoes::COLORS[:black] }.freeze
REDRAW_OFFSET_FACTOR =

Redrawing needs a bit of extra room. We offset by this factor, then extend our size by twice that to evenly surround the whole thing.

4
REDRAW_SIZING_FACTOR =
REDRAW_OFFSET_FACTOR * 2

Constants included from Common::Style

Common::Style::DEFAULT_STYLES, Common::Style::STYLE_GROUPS

Instance Attribute Summary

Attributes included from Common::Clickable

#pass_coordinates

Attributes inherited from Common::UIElement

#app, #dimensions, #gui, #parent

Instance Method Summary collapse

Methods inherited from Common::ArtElement

#painted?

Methods included from Common::Translate

#clear_translate, #translate_left, #translate_top

Methods included from Common::Stroke

#update_stroke

Methods included from Common::Rotate

#needs_rotate?

Methods included from Common::Fill

#update_fill

Methods included from Common::Clickable

#click, #pass_coordinates?, #register_click, #release

Methods inherited from Common::UIElement

#add_to_parent, #after_initialize, #before_initialize, #create_backend, #handle_block, #initialize, #needs_rotate?, #painted?, #update_fill, #update_stroke

Methods included from Common::Style

#applicable_app_styles, #create_style_hash, included, #style, #style_init

Methods included from Common::SafelyEvaluate

#safely_evaluate

Methods included from Common::Remove

#remove

Methods included from Common::Positioning

#_position, #displace, #move

Methods included from Common::Visibility

#hidden?, #hidden_from_view?, #hide, #outside_parent_view?, #show, #toggle, #visible?

Methods included from Common::Inspect

#inspect, #to_s

Methods included from Common::Attachable

#attached_to

Constructor Details

This class inherits a constructor from Shoes::Common::UIElement

Instance Method Details

#center_pointObject



67
68
69
70
71
72
73
74
75
# File 'shoes-core/lib/shoes/star.rb', line 67

def center_point
  if style[:center]
    Point.new(left, top)
  else
    center_x = left + (element_width * 0.5).to_i
    center_y = top + (element_height * 0.5).to_i
    Point.new(center_x, center_y)
  end
end

#center_point=(point) ⇒ Object



77
78
79
80
81
82
83
84
85
# File 'shoes-core/lib/shoes/star.rb', line 77

def center_point=(point)
  if style[:center]
    self.left = point.x
    self.top = point.y
  else
    self.left = point.x - (width * 0.5).to_i
    self.top = point.y - (height * 0.5).to_i
  end
end

#create_dimensions(left, top, points, outer, inner) ⇒ Object

Don’t use param defaults as DSL explicit passes nil for missing params



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'shoes-core/lib/shoes/star.rb', line 9

def create_dimensions(left, top, points, outer, inner)
  left ||= @style[:left] || 0
  top  ||= @style[:top] || 0

  points ||= @style[:points] || 10
  outer  ||= @style[:outer] || 100.0
  inner  ||= @style[:inner] || 50.0

  # Careful not to turn Fixnum to Float, lest Dimensions make you relative!
  width = outer * 2

  # Ignore calculated height on Dimensions--will force to match width
  @dimensions = AbsoluteDimensions.new left, top, width, 0
  @dimensions.height = @dimensions.width

  # Calculate the inner dimensions, which might be relative too
  inner_dimensions = AbsoluteDimensions.new 0, 0, inner * 2, 0

  # Get actual outer/inner from the dimension to handle relative values
  style[:outer]  = @dimensions.width / 2
  style[:inner]  = inner_dimensions.width / 2
  style[:points] = points
end

#in_bounds?(x, y) ⇒ Boolean

Returns:

  • (Boolean)


33
34
35
36
37
38
# File 'shoes-core/lib/shoes/star.rb', line 33

def in_bounds?(x, y)
  dx = width / 2.0
  dy = height / 2.0
  element_left - dx <= x && x <= element_right - dx &&
    element_top - dy <= y && y <= element_bottom - dy
end

#redraw_heightObject



63
64
65
# File 'shoes-core/lib/shoes/star.rb', line 63

def redraw_height
  element_height + strokewidth.ceil * REDRAW_SIZING_FACTOR
end

#redraw_leftObject



45
46
47
48
49
50
# File 'shoes-core/lib/shoes/star.rb', line 45

def redraw_left
  return 0 unless element_left
  calculated_left = element_left
  calculated_left -= width * 0.5 if center
  calculated_left - strokewidth.ceil * REDRAW_OFFSET_FACTOR
end

#redraw_topObject



52
53
54
55
56
57
# File 'shoes-core/lib/shoes/star.rb', line 52

def redraw_top
  return 0 unless element_top
  calculated_top = element_top
  calculated_top -= width * 0.5 if center
  calculated_top - strokewidth.ceil * REDRAW_OFFSET_FACTOR
end

#redraw_widthObject



59
60
61
# File 'shoes-core/lib/shoes/star.rb', line 59

def redraw_width
  element_width + strokewidth.ceil * REDRAW_SIZING_FACTOR
end