Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/dxruby_sdl/image.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
37 changes: 37 additions & 0 deletions spec/lib/dxruby_sdl/image_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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] }
Expand Down