From d51e06639340b2752019ee6c33a355e8e8b687f8 Mon Sep 17 00:00:00 2001 From: kawasakikou Date: Fri, 31 Jul 2015 10:05:15 +0900 Subject: [PATCH 1/5] Add RenderTarget deligate to the image --- lib/dxruby_sdl.rb | 1 + lib/dxruby_sdl/render_target.rb | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 lib/dxruby_sdl/render_target.rb 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..a7439f1 --- /dev/null +++ b/lib/dxruby_sdl/render_target.rb @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- + +require 'forwardable' + +module DXRubySDL + class RenderTarget + extend Forwardable + + def initialize(width, height, color) + @image = Image.new(width, height, color) + end + + def draw_font(x, y, string, font, option = {}) + color = option[:color] || [255, 255, 255] + @image.drawFont(x, y, string, font, color) + end + + def_delegators :@image, :draw + alias_method :drawFont, :draw_font + end + +end From af4c77a7ebc7ea9c84557de3e78f9b608374e552 Mon Sep 17 00:00:00 2001 From: kawasakikou Date: Fri, 31 Jul 2015 10:49:28 +0900 Subject: [PATCH 2/5] Added read _surface --- lib/dxruby_sdl/render_target.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/dxruby_sdl/render_target.rb b/lib/dxruby_sdl/render_target.rb index a7439f1..bcc5a59 100644 --- a/lib/dxruby_sdl/render_target.rb +++ b/lib/dxruby_sdl/render_target.rb @@ -6,8 +6,11 @@ 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 draw_font(x, y, string, font, option = {}) From 7526ed02e457ba26b90848a07e07155f5a9ea84f Mon Sep 17 00:00:00 2001 From: kawasakikou Date: Fri, 31 Jul 2015 13:12:06 +0900 Subject: [PATCH 3/5] fix line of def_deligators and to draw_font --- lib/dxruby_sdl/render_target.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/dxruby_sdl/render_target.rb b/lib/dxruby_sdl/render_target.rb index bcc5a59..59514e1 100644 --- a/lib/dxruby_sdl/render_target.rb +++ b/lib/dxruby_sdl/render_target.rb @@ -12,14 +12,15 @@ 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.drawFont(x, y, string, font, color) + @image.draw_font(x, y, string, font, color) end - def_delegators :@image, :draw alias_method :drawFont, :draw_font - end + end end From 658074a3c456fd2b57718daad15ba1bd1f1500ad Mon Sep 17 00:00:00 2001 From: kawasakikou Date: Fri, 31 Jul 2015 14:12:44 +0900 Subject: [PATCH 4/5] Remove unnecessary blank line --- lib/dxruby_sdl/render_target.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/dxruby_sdl/render_target.rb b/lib/dxruby_sdl/render_target.rb index 59514e1..a1055dc 100644 --- a/lib/dxruby_sdl/render_target.rb +++ b/lib/dxruby_sdl/render_target.rb @@ -21,6 +21,5 @@ def draw_font(x, y, string, font, option = {}) end alias_method :drawFont, :draw_font - end end From fa7fb4df417787e29e5bb8e0cdf1a60621d4db37 Mon Sep 17 00:00:00 2001 From: kawasakikou Date: Fri, 31 Jul 2015 11:24:00 +0900 Subject: [PATCH 5/5] Add window drawScale --- lib/dxruby_sdl/window.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) 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