panda_canvas 0.4.0 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/panda_canvas/canvas.rb +20 -6
- data/lib/panda_canvas/clean_room.rb +1 -1
- data/lib/panda_canvas/version.rb +2 -2
- metadata +2 -2
data/lib/panda_canvas/canvas.rb
CHANGED
@@ -33,17 +33,31 @@ module PandaCanvas
|
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
|
+
# Returns a TexPlay predefined color for symbol +sym+.
|
37
|
+
def sym_color(sym)
|
38
|
+
rgb = TexPlay::Colors.const_get(sym.capitalize)[0..2].map! do |color|
|
39
|
+
color * 255
|
40
|
+
end
|
41
|
+
Gosu::Color.new(255, *rgb)
|
42
|
+
end
|
43
|
+
|
36
44
|
# Draws text +s+ in coordinates +x+ and +y+ with a given +color+.
|
37
45
|
def text(s, x, y, color)
|
38
|
-
if color.is_a? Symbol
|
39
|
-
rgb = TexPlay::Colors.const_get(color.capitalize)[0..2].map! do |c|
|
40
|
-
c * 255
|
41
|
-
end
|
42
|
-
color = Gosu::Color.new(255, *rgb)
|
43
|
-
end
|
46
|
+
color = sym_color(color) if color.is_a? Symbol
|
44
47
|
@font.draw(s, x, y, 0, 1, 1, color)
|
45
48
|
end
|
46
49
|
|
50
|
+
# Draws text +s+ in coordinates +x+ and +y+ with a given +color+.
|
51
|
+
# Text is aligned using +rel_x+ and +rel_y+.
|
52
|
+
# If the value of +rel_x+ is 0.0, the text will be to the right of +x+.
|
53
|
+
# If it is 1.0, the text will be to the left of +x+.
|
54
|
+
# If it is 0.5, it will be centered on +x+.
|
55
|
+
# The same applies to +rel_y+.
|
56
|
+
def text_rel(s, x, y, rel_x, rel_y, color)
|
57
|
+
color = sym_color(color) if color.is_a? Symbol
|
58
|
+
@font.draw_rel(s, x, y, 0, rel_x, rel_y, 1, 1, color)
|
59
|
+
end
|
60
|
+
|
47
61
|
# Runs a range of commands until the next flush.
|
48
62
|
def update
|
49
63
|
CleanRoom::CANVAS_UPDATE.each {|call| send call[0], *call[1..-1] }
|
@@ -11,7 +11,7 @@ module PandaCanvas
|
|
11
11
|
CANVAS_UPDATE = [[:font, Gosu::default_font_name, 12]]
|
12
12
|
|
13
13
|
# Names of calls that need to be sent directly to Canvas instead of the TexPlay image on draw.
|
14
|
-
CANVAS_CALLS = [:font, :text].freeze
|
14
|
+
CANVAS_CALLS = [:font, :text, :text_rel].freeze
|
15
15
|
|
16
16
|
# Returns an array of captured method calls.
|
17
17
|
# A +flush+ is appended at the end.
|
data/lib/panda_canvas/version.rb
CHANGED