Module: Shoes::DSL::Art

Included in:
Shoes::DSL
Defined in:
shoes-core/lib/shoes/dsl/art.rb

Overview

DSL methods for drawing in Shoes applications.

See Also:

Instance Method Summary collapse

Instance Method Details

#arc(left = 0, top = 0, width = 0, height = 0, angle1 = 0, angle2 = 0, opts) ⇒ Shoes::Arc

Creates an arc. Params are optional and may be passed by name in opts hash instead.

Parameters:

  • left (Integer) (defaults to: 0)

    the x-coordinate of the top-left corner

  • top (Integer) (defaults to: 0)

    the y-coordinate of the top-left corner

  • width (Integer) (defaults to: 0)

    width of the arc’s ellipse

  • height (Integer) (defaults to: 0)

    height of the arc’s ellipse

  • angle1 (Float) (defaults to: 0)

    angle in radians marking the beginning of the arc segment

  • angle2 (Float) (defaults to: 0)

    angle in radians marking the end of the arc segment

  • opts (Hash)

Options Hash (opts):

  • wedge (Boolean) — default: false
  • center (Boolean) — default: false

    is (left, top) the center of the rectangle?

Returns:

Raises:

  • (ArgumentError)


50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'shoes-core/lib/shoes/dsl/art.rb', line 50

def arc(*args, &blk)
  opts = style_normalizer.normalize pop_style(args)

  left, top, width, height, angle1, angle2, *leftovers = args

  message = <<~EOS
    Too many arguments. Must be one of:
      - arc(left, top, width, height, angle1, angle2, [opts])
      - arc(left, top, width, height, angle1, [opts])
      - arc(left, top, width, height, [opts])
      - arc(left, top, width, [opts])
      - arc(left, top, [opts])
      - arc(left, [opts])
      - arc([opts])
EOS
  raise ArgumentError, message if leftovers.any?

  create Shoes::Arc, left, top, width, height, angle1, angle2, opts, blk
end

#arrow(left = 0, top = 0, width = 0, opts) ⇒ Shoes::Arrow

Creates an arrow. Params are optional and may be passed by name in opts hash instead.

Parameters:

  • left (Integer) (defaults to: 0)

    the x-coordinate of the element center

  • top (Integer) (defaults to: 0)

    the y-coordinate of the element center

  • width (Integer) (defaults to: 0)

    the width of the arrow

  • opts (Hash)

Options Hash (opts):

  • rotate (Integer) — default: false

Returns:

Raises:

  • (ArgumentError)


19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'shoes-core/lib/shoes/dsl/art.rb', line 19

def arrow(*args, &blk)
  opts = style_normalizer.normalize pop_style(args)

  left, top, width, *leftovers = args

  message = <<~EOS
    Too many arguments. Must be one of:
      - arrow(left, top, width, [opts])
      - arrow(left, top, [opts])
      - arrow(left, [opts])
      - arrow([opts])
EOS
  raise ArgumentError, message if leftovers.any?

  create Shoes::Arrow, left, top, width, opts, blk
end

#line(x1 = 0, y1 = 0, x2 = 0, y2 = 0, opts) ⇒ Shoes::Line

Draws a line from point A (x1,y1) to point B (x2,y2). Params are optional and may be passed by name in opts hash instead.

Parameters:

  • x1 (Integer) (defaults to: 0)

    The x-value of point A

  • y1 (Integer) (defaults to: 0)

    The y-value of point A

  • x2 (Integer) (defaults to: 0)

    The x-value of point B

  • y2 (Integer) (defaults to: 0)

    The y-value of point B

  • opts (Hash)

Returns:

Raises:

  • (ArgumentError)


80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'shoes-core/lib/shoes/dsl/art.rb', line 80

def line(*args, &blk)
  opts = style_normalizer.normalize pop_style(args)

  x1, y1, x2, y2, *leftovers = args

  message = <<~EOS
    Too many arguments. Must be one of:
      - line(x1, y1, x2, y2, [opts])
      - line(x1, y1, x2, [opts])
      - line(x1, y1, [opts])
      - line(x1, [opts])
      - line([opts])
EOS
  raise ArgumentError, message if leftovers.any?

  create Shoes::Line, x1, y1, x2, y2, opts, blk
end

#mask(*_) ⇒ Object

Deprecated.

Raises kinder error message for method Shoes 4 doesn’t support. See github.com/shoes/shoes4/issues/527.



220
221
222
223
224
225
226
# File 'shoes-core/lib/shoes/dsl/art.rb', line 220

def mask(*_)
  raise Shoes::NotImplementedError,
        <<~EOS
          Sorry mask is not supported currently in Shoes 4!
          Check out github issue #527 for any changes/updates or if you want to help :)
        EOS
end

#oval(left = 0, top = 0, width = 0, height = width, opts) ⇒ Shoes::Oval

Creates an oval. Params are optional and may be passed by name in opts hash instead.

Parameters:

  • left (Integer) (defaults to: 0)

    the x-coordinate of the top-left corner

  • top (Integer) (defaults to: 0)

    the y-coordinate of the top-left corner

  • width (Integer) (defaults to: 0)

    the width

  • height (Integer) (defaults to: width)

    the height

  • opts (Hash)

Options Hash (opts):

  • center (Boolean) — default: false

    is (left, top) the center of the oval

Returns:

Raises:

  • (ArgumentError)


109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'shoes-core/lib/shoes/dsl/art.rb', line 109

def oval(*args, &blk)
  opts = style_normalizer.normalize pop_style(args)

  left, top, width, height, *leftovers = args

  message = <<~EOS
    Wrong number of arguments. Must be one of:
      - oval(left, top, width, height, [opts])
      - oval(left, top, diameter, [opts])
      - oval(left, top, [opts])
      - oval(left, [opts])
      - oval(styles)
EOS
  raise ArgumentError, message if leftovers.any?

  create Shoes::Oval, left, top, width, height, opts, blk
end

#rect(left = 0, top = 0, width = 0, height = height, rounded = 0, opts) ⇒ Shoes::Rect

Creates a rectangle. Params are optional and may be passed by name in opts hash instead.

Parameters:

  • left (Integer) (defaults to: 0)

    the x-coordinate of the top-left corner

  • top (Integer) (defaults to: 0)

    the y-coordinate of the top-left corner

  • width (Integer) (defaults to: 0)

    the width

  • height (Integer) (defaults to: height)

    the height

  • rounded (Integer) (defaults to: 0)

    curve amount to apply to corners

  • opts (Hash)

Options Hash (opts):

  • center (Boolean) — default: false

    is (left, top) the center of the rectangle?

Returns:

Raises:

  • (ArgumentError)


139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'shoes-core/lib/shoes/dsl/art.rb', line 139

def rect(*args, &blk)
  opts = style_normalizer.normalize pop_style(args)

  left, top, width, height, curve, *leftovers = args
  opts[:curve] = curve if curve

  message = <<~EOS
    Wrong number of arguments. Must be one of:
      - rect(left, top, width, height, curve, [opts])
      - rect(left, top, width, height, [opts])
      - rect(left, top, side, [opts])
      - rect(left, top, [opts])
      - rect(left, [opts])
      - rect(styles)
EOS

  raise ArgumentError, message if leftovers.any?

  create Shoes::Rect, left, top, width, height, style.merge(opts), blk
end

#shape(left = 0, top = 0, styles, &block) ⇒ Shoes::Shape

Creates an arbitrary shape. Params are optional and may be passed by name in opts hash instead.

Parameters:

  • left (Integer) (defaults to: 0)

    the x-coordinate of the top-left corner

  • top (Integer) (defaults to: 0)

    the y-coordinate of the top-left corner

  • blk (Proc)

    code describing how to draw the shape

  • opts (Hash)

Returns:

Raises:

  • (ArgumentError)


199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
# File 'shoes-core/lib/shoes/dsl/art.rb', line 199

def shape(*args, &blk)
  opts = style_normalizer.normalize pop_style(args)

  left, top, *leftovers = args

  message = <<~EOS
    Wrong number of arguments. Must be one of:
      - shape(left, top, [opts])
      - shape(left, [opts])
      - shape([opts])
EOS

  raise ArgumentError, message if leftovers.any?

  create Shoes::Shape, left, top, opts, blk
end

#star(left = 0, top = 0, points = 10, outer = 100, inner = 50, opts) ⇒ Shoes::Star

Creates a star. Params are optional and may be passed by name in opts hash instead.

Parameters:

  • left (Integer) (defaults to: 0)

    the x-coordinate of the top-left corner

  • top (Integer) (defaults to: 0)

    the y-coordinate of the top-left corner

  • points (Integer) (defaults to: 10)

    count of points on the star

  • outer (Integer) (defaults to: 100)

    outer radius of star

  • inner (Integer) (defaults to: 50)

    inner radius of star

  • opts (Hash)

Returns:

Raises:

  • (ArgumentError)


171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
# File 'shoes-core/lib/shoes/dsl/art.rb', line 171

def star(*args, &blk)
  styles = style_normalizer.normalize pop_style(args)

  left, top, points, outer, inner, *leftovers = args

  message = <<~EOS
    Wrong number of arguments. Must be one of:
      - star([styles])
      - star(left, [styles])
      - star(left, top, [styles])
      - star(left, top, points, [styles])
      - star(left, top, points, outer, [styles])
      - star(left, top, points, outer, inner, [styles])
EOS
  raise ArgumentError, message if leftovers.any?

  create Shoes::Star, left, top, points, outer, inner, styles, blk
end