diff --git a/lib/dxruby_sdl/image.rb b/lib/dxruby_sdl/image.rb index d7ca73e..b7877fa 100644 --- a/lib/dxruby_sdl/image.rb +++ b/lib/dxruby_sdl/image.rb @@ -114,6 +114,10 @@ def box_fill(x1, y1, x2, y2, color) return self end + def draw(x, y, image, x1 = 0, y1 = 0, width = image.width, height = image.height) + SDL.blitSurface(image, x1, y1, width, height, self, x, y) + end + def draw_font(x, y, string, font, color = [255, 255, 255]) if string.empty? return diff --git a/spec/lib/dxruby_sdl/image_spec.rb b/spec/lib/dxruby_sdl/image_spec.rb index f1df429..2f4113e 100644 --- a/spec/lib/dxruby_sdl/image_spec.rb +++ b/spec/lib/dxruby_sdl/image_spec.rb @@ -196,6 +196,43 @@ end end + shared_context 'Source and Destination Images' do + let(:source_image) { DXRubySDL::Image.new(640, 480) } + let(:dest_image) { DXRubySDL::Image.new(640, 480) } + end + + describe '#draw' do + context 'nothing argumet' do + include_context 'Source and Destination Images' + + subject { source_image.draw(0, 0, dest_image) } + + before do + allow(SDL).to receive(:blitSurface) + subject + end + + describe SDL do + it { expect(SDL).to have_received(:blitSurface).with( dest_image, 0, 0, dest_image.width, dest_image.height, source_image, 0, 0).once } + end + end + + context 'Specify argument' do + include_context 'Source and Destination Images' + + subject { source_image.draw(0, 0, dest_image, 100, 200, 300, 400) } + + before do + allow(SDL).to receive(:blitSurface) + subject + end + + describe SDL do + it { expect(SDL).to have_received(:blitSurface).with(dest_image, 100, 200, 300, 400, source_image, 0, 0).once } + end + end + end + shared_context '#draw_font' do let!(:font) { DXRubySDL::Font.new(32) } let(:args) { [0, 0, 'やあ', font] }