Class: Reight::MapEditor::Line
- Defined in:
- lib/reight/app/map/line.rb
Instance Attribute Summary
Attributes inherited from Tool
Attributes inherited from Button
Instance Method Summary collapse
- #brush(cursor_from, cursor_to, chip) ⇒ Object
-
#initialize(app, &block) ⇒ Line
constructor
A new instance of Line.
Methods inherited from BrushBase
#canvas_clicked, #canvas_dragged, #canvas_moved, #canvas_pressed, #canvas_released, #put_or_remove_chip, #update_cursor
Methods inherited from Tool
#canvas, #canvas_clicked, #canvas_dragged, #canvas_moved, #canvas_pressed, #canvas_released, #chips, #history, #name, #pick_chip
Methods inherited from Button
#click, #disabled?, #disabled_icon, #draw, #enabled?, #hover, #pressed, #pressing?, #released, #sprite
Methods included from HasHelp
Methods included from Hookable
Methods included from Activatable
#activated, #activated!, #active=, #active?
Constructor Details
#initialize(app, &block) ⇒ Line
Returns a new instance of Line.
6 7 8 9 |
# File 'lib/reight/app/map/line.rb', line 6 def initialize(app, &block) super app, icon: app.icon(4, 2, 8), &block set_help left: name, right: 'Pick Chip' end |
Instance Method Details
#brush(cursor_from, cursor_to, chip) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/reight/app/map/line.rb', line 11 def brush(cursor_from, cursor_to, chip) result = false canvas.begin_editing do fromx, fromy = cursor_from[...2] tox, toy = cursor_to[...2] dx = fromx < tox ? chip.w : -chip.w dy = fromy < toy ? chip.h : -chip.h if (tox - fromx).abs > (toy - fromy).abs (fromx..tox).step(dx).each do |x| y = fromy == toy ? toy : map(x, fromx, tox, fromy, toy) y = y / chip.h * chip.h result |= put_or_remove_chip x, y, chip end else (fromy..toy).step(dy).each do |y| x = fromx == tox ? tox : map(y, fromy, toy, fromx, tox) x = x / chip.w * chip.w result |= put_or_remove_chip x, y, chip end end end result end |