summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--ext/ruby2d/ruby2d.c1
-rw-r--r--lib/ruby2d/text.rb8
-rw-r--r--tests/testcard.rb8
3 files changed, 10 insertions, 7 deletions
diff --git a/ext/ruby2d/ruby2d.c b/ext/ruby2d/ruby2d.c
index 6971565..e426f0d 100644
--- a/ext/ruby2d/ruby2d.c
+++ b/ext/ruby2d/ruby2d.c
@@ -243,6 +243,7 @@ static void render() {
data->txt->x = NUM2DBL(rb_iv_get(el, "@x"));
data->txt->y = NUM2DBL(rb_iv_get(el, "@y"));
+ S2D_SetText(data->txt, RSTRING_PTR(rb_iv_get(el, "@text")));
S2D_DrawText(data->txt);
}
break;
diff --git a/lib/ruby2d/text.rb b/lib/ruby2d/text.rb
index a695b31..9ba4e41 100644
--- a/lib/ruby2d/text.rb
+++ b/lib/ruby2d/text.rb
@@ -2,11 +2,11 @@
module Ruby2D
class Text
-
+
attr_accessor :x, :y, :size, :text
def initialize(x=0, y=0, size=20, msg="Hello World!", font="Arial", c="white")
-
+
if File.exists? font
@font = font
else
@@ -29,7 +29,7 @@ module Ruby2D
end
def text=(t)
-
+ @text = t
end
def remove
@@ -43,7 +43,7 @@ module Ruby2D
def resolve_path(font)
if RUBY_PLATFORM =~ /darwin/
font_path = "/Library/Fonts/#{font}.ttf"
- else
+ else
# Linux
font_path = "/usr/share/fonts/truetype/#{font}.ttf"
end
diff --git a/tests/testcard.rb b/tests/testcard.rb
index e96c217..c9204cc 100644
--- a/tests/testcard.rb
+++ b/tests/testcard.rb
@@ -135,9 +135,11 @@ Image.new(590, 400, "media/image.bmp")
# Text
Text.new(0, 250) # Default message
-t = Text.new(0, 275, 30, "Hello Ruby 2D!", "media/bitstream_vera/vera.ttf")
-t.color = 'red' # Doesn't work yet
-fps = Text.new(0, 325, 20)
+t1 = Text.new(0, 275, 30, "Hello Ruby 2D!", "media/bitstream_vera/vera.ttf")
+t1.color = 'red' # Doesn't work yet
+t2 = Text.new(0, 325, 20) # Default message
+t2.text = "Text can be changed"
+fps = Text.new(0, 375, 20)
# Pointer for mouse
pointer = Square.new(0, 0, 10, 'white')