Class: Reight::MapEditor::Canvas

Inherits:
Object
  • Object
show all
Defined in:
lib/reight/app/map/canvas.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#cursorObject (readonly)

Returns the value of attribute cursor.



13
14
15
# File 'lib/reight/app/map/canvas.rb', line 13

def cursor
  @cursor
end

#mapObject

Returns the value of attribute map.



13
14
15
# File 'lib/reight/app/map/canvas.rb', line 13

def map
  @map
end

#toolObject

Returns the value of attribute tool.



11
12
13
# File 'lib/reight/app/map/canvas.rb', line 11

def tool
  @tool
end

#xObject

Returns the value of attribute x.



11
12
13
# File 'lib/reight/app/map/canvas.rb', line 11

def x
  @x
end

#yObject

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_cursorObject



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_editingObject



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

def end_editing()
  @app.history.end_grouping
  save
end

#saveObject



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

#spriteObject



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.mouse_button)}
    sp.mouse_released {mouse_released(*pos.call, sp.mouse_button)}
    sp.mouse_moved    {mouse_moved(   *pos.call)}
    sp.mouse_dragged  {mouse_dragged( *pos.call, sp.mouse_button)}
    sp.mouse_clicked  {mouse_clicked( *pos.call, sp.mouse_button)}
  end
end