Class: Reight::MapEditor::Canvas
- Inherits:
-
Object
- Object
- Reight::MapEditor::Canvas
- Defined in:
- lib/reight/app/map/canvas.rb
Instance Attribute Summary collapse
-
#cursor ⇒ Object
readonly
Returns the value of attribute cursor.
-
#map ⇒ Object
Returns the value of attribute map.
-
#tool ⇒ Object
Returns the value of attribute tool.
-
#x ⇒ Object
Returns the value of attribute x.
-
#y ⇒ Object
Returns the value of attribute y.
Instance Method Summary collapse
- #begin_editing(&block) ⇒ Object
- #chip_at_cursor ⇒ Object
- #end_editing ⇒ Object
-
#initialize(app, map) ⇒ Canvas
constructor
A new instance of Canvas.
- #save ⇒ Object
- #set_cursor(x, y, w, h) ⇒ Object
- #sprite ⇒ Object
Constructor Details
#initialize(app, map) ⇒ Canvas
Returns a new instance of Canvas.
6 7 8 9 |
# File 'lib/reight/app/map/canvas.rb', line 6 def initialize(app, map) @app, @map = app, map @x, @y, @tool, @cursor = 0, 0, nil, nil, nil end |
Instance Attribute Details
#cursor ⇒ Object (readonly)
Returns the value of attribute cursor.
13 14 15 |
# File 'lib/reight/app/map/canvas.rb', line 13 def cursor @cursor end |
#map ⇒ Object
Returns the value of attribute map.
13 14 15 |
# File 'lib/reight/app/map/canvas.rb', line 13 def map @map end |
#tool ⇒ Object
Returns the value of attribute tool.
11 12 13 |
# File 'lib/reight/app/map/canvas.rb', line 11 def tool @tool end |
#x ⇒ Object
Returns the value of attribute x.
11 12 13 |
# File 'lib/reight/app/map/canvas.rb', line 11 def x @x end |
#y ⇒ Object
Returns the value of attribute y.
11 12 13 |
# File 'lib/reight/app/map/canvas.rb', line 11 def y @y end |
Instance Method Details
#begin_editing(&block) ⇒ Object
32 33 34 35 36 37 |
# File 'lib/reight/app/map/canvas.rb', line 32 def begin_editing(&block) @app.history.begin_grouping block.call if block ensure end_editing if block end |
#chip_at_cursor ⇒ Object
27 28 29 30 |
# File 'lib/reight/app/map/canvas.rb', line 27 def chip_at_cursor() x, y, = cursor map[@x + x, @y + y] end |
#end_editing ⇒ Object
39 40 41 42 |
# File 'lib/reight/app/map/canvas.rb', line 39 def end_editing() @app.history.end_grouping save end |
#save ⇒ Object
19 20 21 |
# File 'lib/reight/app/map/canvas.rb', line 19 def save() @app.project.save end |
#set_cursor(x, y, w, h) ⇒ Object
23 24 25 |
# File 'lib/reight/app/map/canvas.rb', line 23 def set_cursor(x, y, w, h) @cursor = correct_bounds x, y, w, h end |
#sprite ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/reight/app/map/canvas.rb', line 44 def sprite() @sprite ||= RubySketch::Sprite.new.tap do |sp| pos = -> {to_image sp.mouse_x, sp.mouse_y} sp.draw {draw} sp.mouse_pressed {mouse_pressed( *pos.call, sp.)} sp.mouse_released {mouse_released(*pos.call, sp.)} sp.mouse_moved {mouse_moved( *pos.call)} sp.mouse_dragged {mouse_dragged( *pos.call, sp.)} sp.mouse_clicked {mouse_clicked( *pos.call, sp.)} end end |