Class: Reight::MapEditor::BrushBase

Inherits:
Tool show all
Defined in:
lib/reight/app/map/brush_base.rb

Direct Known Subclasses

Brush, Line, Rect

Instance Attribute Summary

Attributes inherited from Tool

#app

Attributes inherited from Button

#icon, #label, #name

Instance Method Summary collapse

Methods inherited from Tool

#canvas, #chips, #history, #initialize, #name, #pick_chip

Methods inherited from Button

#click, #disabled?, #disabled_icon, #draw, #enabled?, #hover, #initialize, #pressed, #pressing?, #released, #sprite

Methods included from HasHelp

#help, #initialize, #name, #set_help

Methods included from Hookable

#hook

Methods included from Activatable

#activated, #activated!, #active=, #active?, #initialize

Constructor Details

This class inherits a constructor from Reight::MapEditor::Tool

Instance Method Details

#brush(cursor_from, cursor_to, chip) ⇒ Object



6
# File 'lib/reight/app/map/brush_base.rb', line 6

def brush(cursor_from, cursor_to, chip) = nil

#canvas_clicked(x, y, button) ⇒ Object



46
47
48
# File 'lib/reight/app/map/brush_base.rb', line 46

def canvas_clicked(x, y, button)
  pick_chip x, y if button == RIGHT
end

#canvas_dragged(x, y, button) ⇒ Object



39
40
41
42
43
44
# File 'lib/reight/app/map/brush_base.rb', line 39

def canvas_dragged(x, y, button)
  update_cursor x, y
  return unless button == LEFT
  app.undo flash: false if @undo_prev
  @undo_prev = brush @cursor_from, canvas.cursor, chips.chip
end

#canvas_moved(x, y) ⇒ Object



35
36
37
# File 'lib/reight/app/map/brush_base.rb', line 35

def canvas_moved(x, y)
  update_cursor x, y
end

#canvas_pressed(x, y, button) ⇒ Object



25
26
27
28
29
# File 'lib/reight/app/map/brush_base.rb', line 25

def canvas_pressed(x, y, button)
  return unless button == LEFT
  @cursor_from, @deleting = canvas.cursor.dup, chips.chip.empty?
  @undo_prev              = brush @cursor_from, canvas.cursor, chips.chip
end

#canvas_released(x, y, button) ⇒ Object



31
32
33
# File 'lib/reight/app/map/brush_base.rb', line 31

def canvas_released(x, y, button)
  return unless button == LEFT
end

#put_or_remove_chip(x, y, chip) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/reight/app/map/brush_base.rb', line 8

def put_or_remove_chip(x, y, chip)
  return false unless x && y && chip
  m = canvas.map
  return false if !@deleting && m[x, y]&.id == chip.id

  result = false
  m.each_chip x, y, chip.w, chip.h do |ch|
    m.remove_chip ch
    result |= history.append [:remove_chip, ch.pos.x, ch.pos.y, ch.id]
  end
  unless @deleting
    m.put x, y, chip
    result |= history.append [:put_chip, x, y, chip.id]
  end
  result
end

#update_cursor(x, y) ⇒ Object



50
51
52
# File 'lib/reight/app/map/brush_base.rb', line 50

def update_cursor(x, y)
  canvas.set_cursor x, y, chips.size, chips.size
end