diff --git a/lib/dxruby_sdl.rb b/lib/dxruby_sdl.rb index eeac44f..005936a 100644 --- a/lib/dxruby_sdl.rb +++ b/lib/dxruby_sdl.rb @@ -223,5 +223,6 @@ module DXRubySDL require 'dxruby_sdl/sound' require 'dxruby_sdl/sound_effect' require 'dxruby_sdl/sprite' +require 'dxruby_sdl/render_target' SDL.init(SDL::INIT_EVERYTHING) diff --git a/lib/dxruby_sdl/render_target.rb b/lib/dxruby_sdl/render_target.rb new file mode 100644 index 0000000..a1055dc --- /dev/null +++ b/lib/dxruby_sdl/render_target.rb @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- + +require 'forwardable' + +module DXRubySDL + class RenderTarget + extend Forwardable + + attr_reader :_surface + + def initialize(width, height, color) + @image = Image.new(width, height, color) + @_surface = @image._surface + end + + def_delegators :@image, :draw + + def draw_font(x, y, string, font, option = {}) + color = option[:color] || [255, 255, 255] + @image.draw_font(x, y, string, font, color) + end + + alias_method :drawFont, :draw_font + end +end diff --git a/lib/dxruby_sdl/window.rb b/lib/dxruby_sdl/window.rb index 80a9a75..d1e320d 100644 --- a/lib/dxruby_sdl/window.rb +++ b/lib/dxruby_sdl/window.rb @@ -74,6 +74,16 @@ def draw(x, y, image, z = 0) screen.put(image._surface, x, y) end + def draw_scale(x, y, image, scalex, scaley, centerx = nil, centery = nil, z = 0) + opt = { + scale_x: scalex, + scale_y: scaley, + center_x: centerx, + center_y: centery, + } + draw_ex(x, y, image, opt) + end + def draw_ex(x, y, image, hash = {}) if hash[:z] && hash[:z] != 0 raise NotImplementedError, 'Window.draw_ex(x, y, image, z: != 0)' @@ -145,6 +155,7 @@ class << self attr_writer :height attr_writer :scale + alias_method :drawScale, :draw_scale alias_method :drawEx, :draw_ex alias_method :drawFont, :draw_font alias_method :openFilename, :open_filename