Class: Reight::SpriteEditor::Shape
- Inherits:
-
Tool
show all
- Defined in:
- lib/reight/app/sprite/shape.rb
Instance Attribute Summary
Attributes inherited from Tool
#app
Attributes inherited from Button
#icon, #label
Instance Method Summary
collapse
-
#canvas_clicked(x, y, button) ⇒ Object
-
#canvas_dragged(x, y, button) ⇒ Object
-
#canvas_pressed(x, y, button) ⇒ Object
-
#draw_shape(x, y) ⇒ Object
-
#initialize(app, shape, fill, &block) ⇒ Shape
constructor
-
#name ⇒ Object
Methods inherited from Tool
#canvas, #canvas_moved, #canvas_released, #history, #pick_color
Methods inherited from Button
#click, #disabled?, #disabled_icon, #draw, #enabled?, #hover, #pressed, #pressing?, #released, #sprite
Methods included from HasHelp
#help, #set_help
Methods included from Hookable
#hook
#activated, #activated!, #active=, #active?
Constructor Details
#initialize(app, shape, fill, &block) ⇒ Shape
Returns a new instance of Shape.
6
7
8
9
10
11
|
# File 'lib/reight/app/sprite/shape.rb', line 6
def initialize(app, shape, fill, &block)
@shape, @fill = shape, fill
icon_index = [:rect, :ellipse].product([false, true]).index([shape, fill])
super app, icon: app.icon(icon_index + 5, 2, 8), &block
set_help left: name, right: 'Pick Color'
end
|
Instance Method Details
#canvas_clicked(x, y, button) ⇒ Object
39
40
41
|
# File 'lib/reight/app/sprite/shape.rb', line 39
def canvas_clicked(x, y, button)
pick_color x, y if button == RIGHT
end
|
#canvas_dragged(x, y, button) ⇒ Object
33
34
35
36
37
|
# File 'lib/reight/app/sprite/shape.rb', line 33
def canvas_dragged(x, y, button)
return unless button == LEFT
app.undo flash: false
draw_shape x, y
end
|
#canvas_pressed(x, y, button) ⇒ Object
27
28
29
30
31
|
# File 'lib/reight/app/sprite/shape.rb', line 27
def canvas_pressed(x, y, button)
return unless button == LEFT
@x, @y = x, y
draw_shape x, y
end
|
#draw_shape(x, y) ⇒ Object
15
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/reight/app/sprite/shape.rb', line 15
def draw_shape(x, y)
canvas.begin_editing do
canvas.paint do |g|
@fill ? g.fill(*canvas.color) : g.no_fill
g.stroke(*canvas.color)
g.rect_mode CORNER
g.ellipse_mode CORNER
g.send @shape, @x, @y, x - @x, y - @y
end
end
end
|
#name ⇒ Object
13
|
# File 'lib/reight/app/sprite/shape.rb', line 13
def name = "#{@fill ? :Fill : :Stroke} #{@shape.capitalize}"
|