From 684e5ff2652b8f39c1c8cbb1e84315e67b71786b Mon Sep 17 00:00:00 2001 From: Andrew Kesterson Date: Tue, 20 May 2014 20:57:24 -0700 Subject: [PATCH] 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 --- lib/tailor.rb | 17 ++++++++ lib/tailor/GUI/GridDisplay.rb | 60 +++++++++++++++++++++-------- lib/tailor/GUI/TilesetProperties.rb | 2 +- 3 files changed, 61 insertions(+), 18 deletions(-) diff --git a/lib/tailor.rb b/lib/tailor.rb index f22d547..c8bf24d 100644 --- a/lib/tailor.rb +++ b/lib/tailor.rb @@ -1,6 +1,23 @@ require "tailor/version" 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 # Your code goes here... end diff --git a/lib/tailor/GUI/GridDisplay.rb b/lib/tailor/GUI/GridDisplay.rb index baf0cd2..24bb1bb 100644 --- a/lib/tailor/GUI/GridDisplay.rb +++ b/lib/tailor/GUI/GridDisplay.rb @@ -7,12 +7,22 @@ module Tailor def initialize(*args) super(*args) + @imageGrid = nil @padX = 0 @padY = 0 @pitchX = 0 @pitchY = 0 - @gridX = 0 - @gridY = 0 + @gridX = 32 + @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 def set_grid(padX, padY, pitchX, pitchY, gridX, gridY) @@ -22,25 +32,41 @@ module Tailor @pitchY = pitchY @gridX = gridX @gridY = gridY + + @imageGrid.draw() { |dc| + dc.draw_bitmap(@image, 0, 0, true) + stepx = @gridX + @pitchX + stepx = 1 unless stepx != 0 + stepy = @gridY + @pitchY + stepy = 1 unless stepy != 0 + rows = ( (@image.height - @padY) / stepy ) + columns = ( (@image.width - @padX) / stepx ) + points = [] + curX = @padX + curY = @padY + + dc.set_brush(Wx::TRANSPARENT_BRUSH) + dc.set_pen(Wx::RED_PEN) + + for row in 0..rows + for column in 0..columns + dc.draw_rectangle(curX, curY, @gridX, @gridY) + curX += stepx + end + curX = @padX + curY += stepy + end + } end def on_draw(dc) - super.on_draw(dc) - dc.set_pen(Wx::BLACK_DASHED_PEN) - rows = ( (@image.height - @padY) / (@gridY + @pitchY) ) - columns = ( (@image.width - @padX) / (@gridX + @pitchX) ) - points = [] - curX = @padX - curY = @padY - for row in 0..rows - for column in 0..columns - dc.draw_rectangle(curX, curY, @gridX, @gridY) - curX += (@gridX + @pitchX) - end - curX = @padX - curY += (@gridY + @pitchY) - end + _super.on_draw(dc) + tmp=@image + @image=@imageGrid + _super.on_draw(dc) + @image=tmp end + end end end diff --git a/lib/tailor/GUI/TilesetProperties.rb b/lib/tailor/GUI/TilesetProperties.rb index 546839b..993723b 100644 --- a/lib/tailor/GUI/TilesetProperties.rb +++ b/lib/tailor/GUI/TilesetProperties.rb @@ -12,7 +12,7 @@ module Tailor attr_accessor :gridY def initialize(*args) - super(*args) + super(args[0]) @padX = args[2]['padX'] @padY = args[2]['padY'] @pitchX = args[2]['pitchX']