Class: Reight::SpriteEditor::Select
- Defined in:
- lib/reight/app/sprite/select.rb
Instance Attribute Summary
Attributes inherited from Tool
Attributes inherited from Button
Instance Method Summary collapse
- #canvas_clicked(x, y, button) ⇒ Object
- #canvas_dragged(x, y, button) ⇒ Object
- #canvas_pressed(x, y, button) ⇒ Object
- #canvas_released(x, y, button) ⇒ Object
-
#initialize(app, &block) ⇒ Select
constructor
A new instance of Select.
- #move_or_select(x, y) ⇒ Object
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
Methods included from Hookable
Methods included from Activatable
#activated, #activated!, #active=, #active?
Constructor Details
#initialize(app, &block) ⇒ Select
Returns a new instance of Select.
6 7 8 9 |
# File 'lib/reight/app/sprite/select.rb', line 6 def initialize(app, &block) super app, icon: app.icon(0, 2, 8), &block set_help left: 'Select or Move' end |
Instance Method Details
#canvas_clicked(x, y, button) ⇒ Object
45 46 47 48 |
# File 'lib/reight/app/sprite/select.rb', line 45 def canvas_clicked(x, y, ) app.undo flash: false canvas.deselect end |
#canvas_dragged(x, y, button) ⇒ Object
40 41 42 43 |
# File 'lib/reight/app/sprite/select.rb', line 40 def canvas_dragged(x, y, ) app.undo flash: false move_or_select x, y end |
#canvas_pressed(x, y, button) ⇒ Object
29 30 31 32 33 |
# File 'lib/reight/app/sprite/select.rb', line 29 def canvas_pressed(x, y, ) @press_pos = create_vector x, y @moving = == LEFT && is_in_selection?(x, y) move_or_select x, y end |
#canvas_released(x, y, button) ⇒ Object
35 36 37 38 |
# File 'lib/reight/app/sprite/select.rb', line 35 def canvas_released(x, y, ) @press_pos = nil @moving = false end |
#move_or_select(x, y) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/reight/app/sprite/select.rb', line 11 def move_or_select(x, y) x0, y0 = @press_pos&.to_a || return if @moving sx, sy, sw, sh = canvas.selection dx, dy = (x - x0).to_i, (y - y0).to_i history.group do canvas.begin_editing do image = canvas.capture_frame [sx, sy, sw, sh] app.clear_canvas sx, sy, sw, sh canvas.apply_frame image, sx + dx, sy + dy canvas.select sx + dx, sy + dy, sw, sh end end else canvas.select canvas.x + x0, canvas.y + y0, x - x0, y - y0 end end |