Class: Reight::MapEditor::Rect
- Defined in:
- lib/reight/app/map/rect.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, fill:, &block) ⇒ Rect
constructor
A new instance of Rect.
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, fill:, &block) ⇒ Rect
Returns a new instance of Rect.
6 7 8 9 10 |
# File 'lib/reight/app/map/rect.rb', line 6 def initialize(app, fill:, &block) @fill = fill super app, icon: app.icon(fill ? 6 : 5, 2, 8), &block set_help left: "#{fill ? 'Fill' : 'Stroke'} #{name}", right: 'Pick Chip' end |
Instance Method Details
#brush(cursor_from, cursor_to, chip) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/reight/app/map/rect.rb', line 12 def brush(cursor_from, cursor_to, chip) result = false canvas.begin_editing do fromx, fromy = cursor_from[...2] tox, toy = cursor_to[...2] fromx, tox = tox, fromx if fromx > tox fromy, toy = toy, fromy if fromy > toy (fromy..toy).step(chip.h).each do |y| (fromx..tox).step(chip.w).each do |x| next if !@fill && fromx < x && x < tox && fromy < y && y < toy result |= put_or_remove_chip x, y, chip end end end result end |