panda_canvas 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -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.
@@ -1,6 +1,6 @@
1
- class PandaCanvas
1
+ module PandaCanvas
2
2
 
3
3
  # PandaCanvas version.
4
- VERSION = '0.4.0'
4
+ VERSION = '0.4.1'
5
5
 
6
6
  end # end PandaCanvas
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 4
8
- - 0
9
- version: 0.4.0
8
+ - 1
9
+ version: 0.4.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Dimitry Solovyov