Class: Reight::SpriteEditor::Fill
- Defined in:
- lib/reight/app/sprite/fill.rb
Instance Attribute Summary
Attributes inherited from Tool
Attributes inherited from Button
Instance Method Summary collapse
- #canvas_clicked(x, y, button) ⇒ Object
- #canvas_pressed(x, y, button) ⇒ Object
-
#initialize(app, &block) ⇒ Fill
constructor
A new instance of Fill.
Methods inherited from Tool
#canvas, #canvas_dragged, #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
Methods included from Hookable
Methods included from Activatable
#activated, #activated!, #active=, #active?
Constructor Details
#initialize(app, &block) ⇒ Fill
Returns a new instance of Fill.
6 7 8 9 |
# File 'lib/reight/app/sprite/fill.rb', line 6 def initialize(app, &block) super app, icon: app.icon(2, 2, 8), &block set_help left: 'Fill', right: 'Pick Color' end |
Instance Method Details
#canvas_clicked(x, y, button) ⇒ Object
41 42 43 |
# File 'lib/reight/app/sprite/fill.rb', line 41 def canvas_clicked(x, y, ) pick_color x, y if == RIGHT end |
#canvas_pressed(x, y, button) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/reight/app/sprite/fill.rb', line 11 def canvas_pressed(x, y, ) return unless == LEFT x, y = [x, y].map &:to_i fx, fy, fw, = canvas.frame sx, sy, sw, sh = canvas.selection || canvas.frame sx -= fx sy -= fy return unless (sx...(sx + sw)).include?(x) && (sy...(sy + sh)).include?(y) canvas.begin_editing count = 0 canvas.update_pixels do |pixels| from = pixels[y * fw + x] to = color(*canvas.color) rest = [[x, y]] until rest.empty? xx, yy = rest.shift next if pixels[yy * fw + xx] == to pixels[yy * fw + xx] = to count += 1 _x, x_ = xx - 1, xx + 1 _y, y_ = yy - 1, yy + 1 rest << [_x, yy] if _x >= sx && pixels[yy * fw + _x] == from rest << [x_, yy] if x_ < sx + sw && pixels[yy * fw + x_] == from rest << [xx, _y] if _y >= sy && pixels[_y * fw + xx] == from rest << [xx, y_] if y_ < sy + sh && pixels[y_ * fw + xx] == from end end canvas.end_editing if count > 0 end |