summaryrefslogtreecommitdiffhomepage
path: root/lib
diff options
context:
space:
mode:
authorlstrzebinczyk <[email protected]>2017-03-29 23:11:04 +0200
committerTom Black <[email protected]>2017-04-02 17:09:27 -0400
commit193315380ed9c714e5f78b7d1b1224cfc68ccaaa (patch)
tree5a59dfc011e5433bc3628fe32073b89f3f41e39f /lib
parent5247c3caa0091a77cce772de30cd44aaff484e16 (diff)
downloadruby2d-193315380ed9c714e5f78b7d1b1224cfc68ccaaa.tar.gz
ruby2d-193315380ed9c714e5f78b7d1b1224cfc68ccaaa.zip
introduce Ruby2D::Renderable
Diffstat (limited to 'lib')
-rw-r--r--lib/ruby2d.rb1
-rw-r--r--lib/ruby2d/image.rb16
-rw-r--r--lib/ruby2d/quad.rb15
-rw-r--r--lib/ruby2d/renderable.rb15
-rw-r--r--lib/ruby2d/text.rb13
-rw-r--r--lib/ruby2d/triangle.rb13
6 files changed, 22 insertions, 51 deletions
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)