diff options
| -rw-r--r-- | ext/ruby2d/ruby2d.c | 6 | ||||
| -rw-r--r-- | lib/ruby2d/image.rb | 3 | ||||
| -rw-r--r-- | lib/ruby2d/sprite.rb | 4 | ||||
| -rw-r--r-- | lib/ruby2d/text.rb | 4 | ||||
| -rw-r--r-- | test/testcard.rb | 35 |
5 files changed, 41 insertions, 11 deletions
diff --git a/ext/ruby2d/ruby2d.c b/ext/ruby2d/ruby2d.c index 2705e03..c723e4f 100644 --- a/ext/ruby2d/ruby2d.c +++ b/ext/ruby2d/ruby2d.c @@ -328,6 +328,8 @@ static R_VAL ruby2d_image_ext_render(R_VAL self) { if (r_test(w)) img->width = NUM2INT(w); if (r_test(h)) img->height = NUM2INT(h); + S2D_RotateImage(img, NUM2DBL(r_iv_get(self, "@rotate")), S2D_CENTER); + R_VAL c = r_iv_get(self, "@color"); img->color.r = NUM2DBL(r_iv_get(c, "@r")); img->color.g = NUM2DBL(r_iv_get(c, "@g")); @@ -398,6 +400,8 @@ static R_VAL ruby2d_sprite_ext_render(R_VAL self) { R_VAL h = r_iv_get(self, "@flip_height"); if (r_test(h)) spr->height = NUM2DBL(h); + S2D_RotateSprite(spr, NUM2DBL(r_iv_get(self, "@rotate")), S2D_CENTER); + S2D_ClipSprite( spr, NUM2INT(r_iv_get(self, "@clip_x")), @@ -487,6 +491,8 @@ static R_VAL ruby2d_text_ext_render(R_VAL self) { txt->x = NUM2DBL(r_iv_get(self, "@x")); txt->y = NUM2DBL(r_iv_get(self, "@y")); + S2D_RotateText(txt, NUM2DBL(r_iv_get(self, "@rotate")), S2D_CENTER); + R_VAL c = r_iv_get(self, "@color"); txt->color.r = NUM2DBL(r_iv_get(c, "@r")); txt->color.g = NUM2DBL(r_iv_get(c, "@g")); diff --git a/lib/ruby2d/image.rb b/lib/ruby2d/image.rb index 3ac705d..5490d53 100644 --- a/lib/ruby2d/image.rb +++ b/lib/ruby2d/image.rb @@ -4,8 +4,8 @@ module Ruby2D class Image include Renderable - attr_accessor :x, :y, :width, :height, :data attr_reader :path, :color + attr_accessor :x, :y, :width, :height, :rotate, :data def initialize(opts = {}) @path = opts[:path] @@ -21,6 +21,7 @@ module Ruby2D @z = opts[:z] || 0 @width = opts[:width] || nil @height = opts[:height] || nil + @rotate = 0 self.color = opts[:color] || 'white' diff --git a/lib/ruby2d/sprite.rb b/lib/ruby2d/sprite.rb index f2d7075..68b6ace 100644 --- a/lib/ruby2d/sprite.rb +++ b/lib/ruby2d/sprite.rb @@ -4,8 +4,8 @@ module Ruby2D class Sprite include Renderable - attr_accessor :x, :y, :width, :height, :loop, - :clip_x, :clip_y, :clip_width, :clip_height, :data + attr_reader :x, :y, :width, :height + attr_accessor :rotate, :loop, :clip_x, :clip_y, :clip_width, :clip_height, :data def initialize(path, opts = {}) diff --git a/lib/ruby2d/text.rb b/lib/ruby2d/text.rb index 87fe4d3..9a66b6d 100644 --- a/lib/ruby2d/text.rb +++ b/lib/ruby2d/text.rb @@ -4,8 +4,8 @@ module Ruby2D class Text include Renderable - attr_accessor :x, :y, :data attr_reader :text, :size, :width, :height, :font, :color + attr_accessor :x, :y, :rotate, :data def initialize(opts = {}) @x = opts[:x] || 0 @@ -13,7 +13,7 @@ module Ruby2D @z = opts[:z] || 0 @text = (opts[:text] || "Hello World!").to_s @size = opts[:size] || 20 - + @rotate = 0 @font = opts[:font] unless RUBY_ENGINE == 'opal' diff --git a/test/testcard.rb b/test/testcard.rb index 7ae153f..876c5c4 100644 --- a/test/testcard.rb +++ b/test/testcard.rb @@ -199,10 +199,12 @@ Line.new( ] ); +rotate = false + # Images -Image.new(x: 590, y: 180, path: "#{media}/image.png") -Image.new(x: 590, y: 290, path: "#{media}/image.jpg") -Image.new(x: 590, y: 400, path: "#{media}/image.bmp") +img_png = Image.new(x: 590, y: 180, path: "#{media}/image.png") +img_jpg = Image.new(x: 590, y: 290, path: "#{media}/image.jpg") +img_bmp = Image.new(x: 590, y: 400, path: "#{media}/image.bmp") img_r = Image.new(x: 400, y: 200, width: 50, height: 25, path: "#{media}/colors.png") img_r.color = [1.0, 0.3, 0.3, 1.0] img_g = Image.new(x: 400, y: 225, path: "#{media}/colors.png") @@ -213,9 +215,9 @@ img_b.width, img_b.height = 25, 25 img_b.color = [0.3, 0.3, 1.0, 1.0] # Text -Text.new(x: 44, y: 202, text: "R", font: font, color: [1.0, 0.0, 0.0, 1.0]) -Text.new(x: 92, y: 202, text: "G", font: font, color: [0.0, 1.0, 0.0, 1.0]) -Text.new(x: 144, y: 202, text: "B", font: font, color: [0.0, 0.0, 1.0, 1.0]) +txt_r = Text.new(x: 44, y: 202, text: "R", font: font, color: [1.0, 0.0, 0.0, 1.0]) +txt_b = Text.new(x: 92, y: 202, text: "G", font: font, color: [0.0, 1.0, 0.0, 1.0]) +txt_g = Text.new(x: 144, y: 202, text: "B", font: font, color: [0.0, 0.0, 1.0, 1.0]) # Frames per second fps = Text.new(x: 10, y: 470, text: "", font: font) @@ -275,6 +277,10 @@ UPDATED_TEXT_OPTIONS = "of various size".split(" ") on :key_down do |event| close if event.key == 'escape' + + if event.key == 'r' + rotate = rotate ? false : true; + end end on :mouse_down do @@ -287,6 +293,23 @@ update do pointer.x = (get :mouse_x) - 5 pointer.y = (get :mouse_y) - 7 + if rotate + img_png.x = get :mouse_x + img_png.y = get :mouse_y + angle = (get :frames).to_f + img_png.rotate = angle + img_jpg.rotate = angle + img_bmp.rotate = angle + img_r.rotate = angle + img_g.rotate = angle + img_b.rotate = angle + spr.rotate = angle + txt_r.rotate = angle + txt_g.rotate = angle + txt_b.rotate = angle + fps.rotate = angle + end + if flash > 0 pointer_outline.color = [0, 1, 0, 1] flash -= 1 |
