Class: Reight::SpriteEditor::Line

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

Instance Attribute Summary

Attributes inherited from Tool

#app

Attributes inherited from Button

#icon, #label, #name

Instance Method Summary collapse

Methods inherited from Tool

#canvas, #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

#help, #name, #set_help

Methods included from Hookable

#hook

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/sprite/line.rb', line 6

def initialize(app, &block)
  super app, icon: app.icon(4, 2, 8), &block
  set_help left: name, right: 'Pick Color'
end

Instance Method Details

#canvas_clicked(x, y, button) ⇒ Object



33
34
35
# File 'lib/reight/app/sprite/line.rb', line 33

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

#canvas_dragged(x, y, button) ⇒ Object



27
28
29
30
31
# File 'lib/reight/app/sprite/line.rb', line 27

def canvas_dragged(x, y, button)
  return unless button == LEFT
  app.undo flash: false
  draw_line x, y
end

#canvas_pressed(x, y, button) ⇒ Object



21
22
23
24
25
# File 'lib/reight/app/sprite/line.rb', line 21

def canvas_pressed(x, y, button)
  return unless button == LEFT
  @x, @y = x, y
  draw_line x, y
end

#draw_line(x, y) ⇒ Object



11
12
13
14
15
16
17
18
19
# File 'lib/reight/app/sprite/line.rb', line 11

def draw_line(x, y)
  canvas.begin_editing do
    canvas.paint do |g|
      g.stroke(*canvas.color)
      g.stroke_weight 0
      g.line @x, @y, x, y
    end
  end
end