From 193315380ed9c714e5f78b7d1b1224cfc68ccaaa Mon Sep 17 00:00:00 2001 From: lstrzebinczyk Date: Wed, 29 Mar 2017 23:11:04 +0200 Subject: introduce Ruby2D::Renderable --- bin/ruby2d | 1 + lib/ruby2d.rb | 1 + lib/ruby2d/image.rb | 16 ++-------------- lib/ruby2d/quad.rb | 15 ++------------- lib/ruby2d/renderable.rb | 15 +++++++++++++++ lib/ruby2d/text.rb | 13 +------------ lib/ruby2d/triangle.rb | 13 +------------ 7 files changed, 23 insertions(+), 51 deletions(-) create mode 100644 lib/ruby2d/renderable.rb diff --git a/bin/ruby2d b/bin/ruby2d index d399479..c98b464 100755 --- a/bin/ruby2d +++ b/bin/ruby2d @@ -14,6 +14,7 @@ end # The Ruby 2D library files @lib_files = [ + 'renderable', 'exceptions', 'color', 'window', diff --git a/lib/ruby2d.rb b/lib/ruby2d.rb index f77d5f7..4c13dd9 100644 --- a/lib/ruby2d.rb +++ b/lib/ruby2d.rb @@ -1,5 +1,6 @@ # ruby2d.rb +require 'ruby2d/renderable' require 'ruby2d/exceptions' require 'ruby2d/color' require 'ruby2d/window' diff --git a/lib/ruby2d/image.rb b/lib/ruby2d/image.rb index dd18ac1..7938bea 100644 --- a/lib/ruby2d/image.rb +++ b/lib/ruby2d/image.rb @@ -2,7 +2,8 @@ module Ruby2D class Image - + include Renderable + attr_accessor :x, :y, :width, :height, :data attr_reader :path, :color @@ -25,18 +26,5 @@ module Ruby2D def color=(c) @color = Color.new(c) end - - def add - if Module.const_defined? :DSL - Application.add(self) - end - end - - def remove - if Module.const_defined? :DSL - Application.remove(self) - end - end - end end diff --git a/lib/ruby2d/quad.rb b/lib/ruby2d/quad.rb index 676fb2f..5175513 100644 --- a/lib/ruby2d/quad.rb +++ b/lib/ruby2d/quad.rb @@ -1,7 +1,8 @@ # quad.rb module Ruby2D - class Quad + class Quad + include Renderable # Coordinates in clockwise order, starting at top left: # x1,y1 == top left # x2,y2 == top right @@ -27,18 +28,6 @@ module Ruby2D update_color(@color) end - def add - if Module.const_defined? :DSL - Application.add(self) - end - end - - def remove - if Module.const_defined? :DSL - Application.remove(self) - end - end - private def update_color(c) diff --git a/lib/ruby2d/renderable.rb b/lib/ruby2d/renderable.rb new file mode 100644 index 0000000..3be6121 --- /dev/null +++ b/lib/ruby2d/renderable.rb @@ -0,0 +1,15 @@ +module Ruby2D + module Renderable + def add + if Module.const_defined? :DSL + Application.add(self) + end + end + + def remove + if Module.const_defined? :DSL + Application.remove(self) + end + end + end +end diff --git a/lib/ruby2d/text.rb b/lib/ruby2d/text.rb index 9f8da51..736c8a1 100644 --- a/lib/ruby2d/text.rb +++ b/lib/ruby2d/text.rb @@ -2,6 +2,7 @@ module Ruby2D class Text + include Renderable attr_accessor :x, :y, :data attr_reader :text, :size, :width, :height, :font, :color @@ -31,18 +32,6 @@ module Ruby2D @color = Color.new(c) end - def add - if Module.const_defined? :DSL - Application.add(self) - end - end - - def remove - if Module.const_defined? :DSL - Application.remove(self) - end - end - private def resolve_path(font) diff --git a/lib/ruby2d/triangle.rb b/lib/ruby2d/triangle.rb index 764787a..c6bac41 100644 --- a/lib/ruby2d/triangle.rb +++ b/lib/ruby2d/triangle.rb @@ -2,6 +2,7 @@ module Ruby2D class Triangle + include Renderable attr_accessor :x1, :y1, :c1, :x2, :y2, :c2, @@ -23,18 +24,6 @@ module Ruby2D update_color(@color) end - def add - if Module.const_defined? :DSL - Application.add(self) - end - end - - def remove - if Module.const_defined? :DSL - Application.remove(self) - end - end - private def update_color(c) -- cgit v1.2.3