Class: Reight::SpriteEditor::Brush

Inherits:
Tool show all
Defined in:
lib/reight/app/sprite/brush.rb

Instance Attribute Summary collapse

Attributes inherited from Tool

#app

Attributes inherited from Button

#icon, #label, #name

Instance Method Summary collapse

Methods inherited from Tool

#canvas, #canvas_moved, #history, #pick_color

Methods inherited from Button

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

Methods included from HasHelp

#help, #name, #set_help

Methods included from Hookable

#hook

Methods included from Activatable

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

Constructor Details

#initialize(app, &block) ⇒ Brush

Returns a new instance of Brush.



6
7
8
9
10
# File 'lib/reight/app/sprite/brush.rb', line 6

def initialize(app, &block)
  super app, icon: app.icon(1, 2, 8), &block
  @size = 1
  set_help left: 'Brush', right: 'Pick Color'
end

Instance Attribute Details

#sizeObject

Returns the value of attribute size.



12
13
14
# File 'lib/reight/app/sprite/brush.rb', line 12

def size
  @size
end

Instance Method Details

#brush(x, y, button) ⇒ Object



14
15
16
17
18
19
20
21
# File 'lib/reight/app/sprite/brush.rb', line 14

def brush(x, y, button)
  canvas.paint do |g|
    g.no_fill
    g.stroke(*canvas.color)
    g.stroke_weight size
    g.point x, y
  end
end

#canvas_clicked(x, y, button) ⇒ Object



39
40
41
# File 'lib/reight/app/sprite/brush.rb', line 39

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

#canvas_dragged(x, y, button) ⇒ Object



34
35
36
37
# File 'lib/reight/app/sprite/brush.rb', line 34

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

#canvas_pressed(x, y, button) ⇒ Object



23
24
25
26
27
# File 'lib/reight/app/sprite/brush.rb', line 23

def canvas_pressed(x, y, button)
  return unless button == LEFT
  canvas.begin_editing
  brush x, y, button
end

#canvas_released(x, y, button) ⇒ Object



29
30
31
32
# File 'lib/reight/app/sprite/brush.rb', line 29

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