From c4580e18a072e7453adf77c3cfea78a6e5b167da Mon Sep 17 00:00:00 2001 From: kawasakikou Date: Tue, 28 Jul 2015 14:12:52 +0900 Subject: [PATCH 1/2] Added Image#draw --- lib/dxruby_sdl/image.rb | 4 ++++ 1 file changed, 4 insertions(+) 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 From fac06c3d20a898c24fd3208959be267f982bfc2d Mon Sep 17 00:00:00 2001 From: kawasakikou Date: Tue, 28 Jul 2015 15:13:38 +0900 Subject: [PATCH 2/2] Added Image#draw spec test --- spec/lib/dxruby_sdl/image_spec.rb | 37 +++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) 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] }