summaryrefslogtreecommitdiffhomepage
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/ruby2d/dsl.rb4
-rw-r--r--lib/ruby2d/text.rb27
-rw-r--r--lib/ruby2d/version.rb2
-rw-r--r--lib/ruby2d/window.rb36
4 files changed, 26 insertions, 43 deletions
diff --git a/lib/ruby2d/dsl.rb b/lib/ruby2d/dsl.rb
index ef8f384..93fedb3 100644
--- a/lib/ruby2d/dsl.rb
+++ b/lib/ruby2d/dsl.rb
@@ -1,10 +1,6 @@
# dsl.rb
module Ruby2D::DSL
- def hello
- puts "hi"
- end
-
def get(sym)
Ruby2D::Application.get(sym)
end
diff --git a/lib/ruby2d/text.rb b/lib/ruby2d/text.rb
index 2dd36e9..93c2862 100644
--- a/lib/ruby2d/text.rb
+++ b/lib/ruby2d/text.rb
@@ -5,20 +5,17 @@ module Ruby2D
attr_accessor :x, :y, :size, :text
- def initialize(x=0, y=0, size=20, text="Hello World!", font="Arial", c="white")
- if font.include? '.'
- unless File.exists? font
- raise Error, "Cannot find font file!"
- else
- @font = font
- end
+ def initialize(x=0, y=0, size=20, msg="Hello World!", font="Arial", c="white")
+
+ if File.exists? font
+ @font = font
else
@font = resolve_path(font)
end
@type_id = 4
@x, @y, @size = x, y, size
- @text, @color = text, c
+ @text, @color = msg, c
update_color(c)
if defined? Ruby2D::DSL
@@ -44,14 +41,18 @@ module Ruby2D
private
def resolve_path(font)
- # TODO: Consider CSS names, like 'serif', 'san-serif', 'monospace'
if RUBY_PLATFORM =~ /darwin/
font_path = "/Library/Fonts/#{font}.ttf"
- unless File.exists? font_path
- raise Error, "Cannot find system font!"
- end
+ else
+ # Linux
+ font_path = "/usr/share/fonts/truetype/#{font}.ttf"
+ end
+
+ unless File.exists? font_path
+ raise Error, "Cannot find system font"
+ else
+ font_path
end
- font_path
end
def update_color(c)
diff --git a/lib/ruby2d/version.rb b/lib/ruby2d/version.rb
index c5011e0..eede3ba 100644
--- a/lib/ruby2d/version.rb
+++ b/lib/ruby2d/version.rb
@@ -1,5 +1,5 @@
# version.rb
module Ruby2D
- VERSION = '0.2.0'
+ VERSION = '0.2.1'
end
diff --git a/lib/ruby2d/window.rb b/lib/ruby2d/window.rb
index 1b3698e..5889c5d 100644
--- a/lib/ruby2d/window.rb
+++ b/lib/ruby2d/window.rb
@@ -10,7 +10,6 @@ module Ruby2D
@fps_cap = fps
@fps = 60
@vsync = vsync
-
@objects = []
@keys = {}
@keys_down = {}
@@ -20,34 +19,21 @@ module Ruby2D
def get(sym)
case sym
- when :window
- return self
- when :title
- return @title
- when :width
- return @width
- when :height
- return @height
- when :fps
- return @fps
- when :mouse_x
- return @mouse_x
- when :mouse_y
- return @mouse_y
+ when :window; self
+ when :title; @title
+ when :width; @width
+ when :height; @height
+ when :fps; @fps
+ when :mouse_x; @mouse_x
+ when :mouse_y; @mouse_y
end
end
def set(opts)
- valid_keys = [:title, :width, :height]
- valid_opts = opts.reject { |k| !valid_keys.include?(k) }
- if !valid_opts.empty?
- @title = valid_opts[:title]
- @width = valid_opts[:width]
- @height = valid_opts[:height]
- return true
- else
- return false
- end
+ # Store new window attributes, or ignore if nil
+ @title = opts[:title] || @title
+ @width = opts[:width] || @width
+ @height = opts[:height] || @height
end
def add(o)