Midstream on #8 : Grid drawing works as expected now, but the TilesetPropertiesChangedEvent is not bubbling up like it should, so the grid can't change

This commit is contained in:
2014-05-20 20:57:24 -07:00
parent 040af6e448
commit 684e5ff265
3 changed files with 61 additions and 18 deletions

View File

@@ -1,6 +1,23 @@
require "tailor/version" require "tailor/version"
require "tailor/GUI" require "tailor/GUI"
class SuperProxy
def initialize(obj)
@obj = obj
end
def method_missing(meth, *args, &blk)
@obj.class.superclass.instance_method(meth).bind(@obj).call(*args, &blk)
end
end
class Object
private
def _super
SuperProxy.new(self)
end
end
module Tailor module Tailor
# Your code goes here... # Your code goes here...
end end

View File

@@ -7,12 +7,22 @@ module Tailor
def initialize(*args) def initialize(*args)
super(*args) super(*args)
@imageGrid = nil
@padX = 0 @padX = 0
@padY = 0 @padY = 0
@pitchX = 0 @pitchX = 0
@pitchY = 0 @pitchY = 0
@gridX = 0 @gridX = 32
@gridY = 0 @gridY = 32
end
def set_image(image)
_super.set_image(image)
@imageGrid = Wx::Bitmap.new(@image.get_width(),
@image.get_height(),
32
)
set_grid(@padX, @padY, @pitchX, @pitchY, @gridX, @gridY)
end end
def set_grid(padX, padY, pitchX, pitchY, gridX, gridY) def set_grid(padX, padY, pitchX, pitchY, gridX, gridY)
@@ -22,25 +32,41 @@ module Tailor
@pitchY = pitchY @pitchY = pitchY
@gridX = gridX @gridX = gridX
@gridY = gridY @gridY = gridY
end
def on_draw(dc) @imageGrid.draw() { |dc|
super.on_draw(dc) dc.draw_bitmap(@image, 0, 0, true)
dc.set_pen(Wx::BLACK_DASHED_PEN) stepx = @gridX + @pitchX
rows = ( (@image.height - @padY) / (@gridY + @pitchY) ) stepx = 1 unless stepx != 0
columns = ( (@image.width - @padX) / (@gridX + @pitchX) ) stepy = @gridY + @pitchY
stepy = 1 unless stepy != 0
rows = ( (@image.height - @padY) / stepy )
columns = ( (@image.width - @padX) / stepx )
points = [] points = []
curX = @padX curX = @padX
curY = @padY curY = @padY
dc.set_brush(Wx::TRANSPARENT_BRUSH)
dc.set_pen(Wx::RED_PEN)
for row in 0..rows for row in 0..rows
for column in 0..columns for column in 0..columns
dc.draw_rectangle(curX, curY, @gridX, @gridY) dc.draw_rectangle(curX, curY, @gridX, @gridY)
curX += (@gridX + @pitchX) curX += stepx
end end
curX = @padX curX = @padX
curY += (@gridY + @pitchY) curY += stepy
end end
}
end end
def on_draw(dc)
_super.on_draw(dc)
tmp=@image
@image=@imageGrid
_super.on_draw(dc)
@image=tmp
end
end end
end end
end end

View File

@@ -12,7 +12,7 @@ module Tailor
attr_accessor :gridY attr_accessor :gridY
def initialize(*args) def initialize(*args)
super(*args) super(args[0])
@padX = args[2]['padX'] @padX = args[2]['padX']
@padY = args[2]['padY'] @padY = args[2]['padY']
@pitchX = args[2]['pitchX'] @pitchX = args[2]['pitchX']