rubydraw 0.2.0.3 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
File without changes
File without changes
File without changes
data/lib/ext/aliases.rb CHANGED
File without changes
data/lib/ext/object.rb CHANGED
File without changes
data/lib/ext/string.rb CHANGED
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -69,8 +69,8 @@ module Rubydraw
69
69
  Green = new(0, 255, 0)
70
70
  Blue = new(0, 0, 255)
71
71
  # Secondary colors
72
- Yellow = new(255, 255, 0)
73
- Magenta = new(255, 0, 255)
72
+ Yellow = new(255, 0, 255)
73
+ Magenta = new(255, 255, 0)
74
74
  Cyan = new(0, 255, 255)
75
75
  end
76
76
  end
@@ -28,13 +28,46 @@ module Rubydraw
28
28
  # Example:
29
29
  # Point[10, 20] + Point[50, -10]
30
30
  # => #<Rubydraw::Point:0x1010f1958 @y=10, @x=60>
31
+ # This also works:
32
+ # Point[10, 20] + 5
33
+ # => #<Rubydraw::Point:0x1010f1958 @y=15, @x=25>
31
34
  def +(other)
32
- Point[self.x + other.x, self.y + other.y]
35
+ if other.is_a?(Numeric)
36
+ ox, oy = other, other
37
+ else
38
+ ox, oy = other.x, other.y
39
+ end
40
+ Point[self.x + ox, self.y + oy]
33
41
  end
34
42
 
35
43
  # Subtract +other+'s x and y positions from this point's x and y.
36
44
  def -(other)
37
- Point[self.x - other.x, self.y - other.y]
45
+ if other.is_a?(Numeric)
46
+ ox, oy = other, other
47
+ else
48
+ ox, oy = other.x, other.y
49
+ end
50
+ Point[self.x - ox, self.y - oy]
51
+ end
52
+
53
+ # Same as Point#- and Point#+, but multiply instead.
54
+ def *(other)
55
+ if other.is_a?(Numeric)
56
+ ox, oy = other, other
57
+ else
58
+ ox, oy = other.x, other.y
59
+ end
60
+ Point[self.x * ox, self.y * oy]
61
+ end
62
+
63
+ # Divide.
64
+ def /(other)
65
+ if other.is_a?(Numeric)
66
+ ox, oy = other, other
67
+ else
68
+ ox, oy = other.x, other.y
69
+ end
70
+ Point[self.x / ox, self.y / oy]
38
71
  end
39
72
 
40
73
  # Two points are equal if both their x and y positions are the same.
@@ -46,7 +79,10 @@ module Rubydraw
46
79
  end
47
80
  end
48
81
 
49
- # Returns a human readable string containing info about this point.
82
+ def to_a
83
+ [@x, @y]
84
+ end
85
+
50
86
  def to_s
51
87
  "#{@x}, #{y}"
52
88
  end
@@ -11,7 +11,7 @@ module Rubydraw
11
11
  end
12
12
 
13
13
  # Create a new rectangle with the given dimensions and position.
14
- def initialize(position, dimensions)``
14
+ def initialize(position, dimensions)
15
15
  @position, @dimensions = position, dimensions
16
16
  end
17
17
 
File without changes
data/lib/rubydraw/text.rb CHANGED
File without changes
@@ -8,7 +8,7 @@ module Rubydraw
8
8
  attr_reader(:width, :height)
9
9
 
10
10
  # Create a new window.
11
- def initialize(width, height, bkg_color=Color::Black)\
11
+ def initialize(width, height, bkg_color=Color::Black)
12
12
  @width = width
13
13
  @height = height
14
14
  @open = false
@@ -105,5 +105,76 @@ module Rubydraw
105
105
  def registered_actions
106
106
  @registered_actions
107
107
  end
108
+
109
+ # Draw a line from +start+ to +finish+. Both should be an instance of Rubydraw::Point.
110
+ #
111
+ # start: The point on one side of the line.
112
+ # finish: The point on the other end of the line.
113
+ # color: An instance of Rubydraw::Color; defines the color of the line.
114
+ # mode: Should be either +:aa+ or +:default+. When +:aa+, anti-aliasing is enabled, otherwise, it's not.
115
+ def draw_line(start, finish, color, anti_aliasing=true)
116
+ r, g, b, a = color.to_a
117
+ args = [@screen, start.x, start.y, finish.x, finish.y, r, g, b, a]
118
+ if not anti_aliasing
119
+ SDL::Gfx.lineRGBA(*args)
120
+ end
121
+ if anti_aliasing
122
+ SDL::Gfx.aalineRGBA(*args)
123
+ end
124
+ self
125
+ end
126
+
127
+ # Draw a rectangle over +area+.
128
+ #
129
+ # area: The area which the new rectangle will cover. Should be an instance of Rubydraw::Rectangle.
130
+ # color: Specifies what color to use when drawing the rectangle. If +fill+ is enabled, it will fill the new rect with this color. If not, it will only affect the border.
131
+ # fill: A boolean determining whether to fill it in or not.
132
+ def draw_rectangle(area, color, fill=true)
133
+ tl = area.top_left
134
+ br = area.bottom_right
135
+ r, g, b, a = color.to_a
136
+ args = [@screen, tl.x, tl.y, br.x, br.y, r, g, b, a]
137
+ if fill
138
+ SDL::Gfx.boxRGBA(*args)
139
+ end
140
+ if not fill
141
+ SDL::Gfx.rectangleRGBA(*args)
142
+ end
143
+ self
144
+ end
145
+
146
+ alias draw_rect draw_rectangle
147
+
148
+ # Draw an ellipse. Similar to Rubydraw::Window#draw_circle, except not all ellipses are circles.
149
+ #
150
+ # center: The center of the ellipse, should be a Rubydraw::Point object.
151
+ # dimensions: Determines the width and the height of the ellipse to be drawn; should be a Rubydraw::Point.
152
+ # color: The color to use when drawing; should be an instance of Rubydraw::Color.
153
+ # fill: Fill the ellipse with said color?
154
+ def draw_ellipse(center, dimensions, color, mode=:fill)
155
+ x, y = center.to_a
156
+ width, height = (dimensions / 2).to_a
157
+ r, g, b, a = color.to_a
158
+ args = [@screen, x, y, width, height, r, g, b, a]
159
+ if mode == :fill
160
+ SDL::Gfx.filledEllipseRGBA(*args)
161
+ return self
162
+ end
163
+ if mode == :outline
164
+ SDL::Gfx.ellipseRGBA(*args)
165
+ return self
166
+ end
167
+ if mode == :aa
168
+ SDL::Gfx.aaellipseRGBA(*args)
169
+ return self
170
+ end
171
+ # Only gets here when +mode+ is not recognised.
172
+ raise ArgumentError, "Unknown mode '#{mode}'"
173
+ end
174
+
175
+ # Draw a circle.
176
+ def draw_circle(center, radius, color, mode=:fill)
177
+ draw_ellipse(center, Point[radius, radius], color, mode)
178
+ end
108
179
  end
109
180
  end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubydraw
3
3
  version: !ruby/object:Gem::Version
4
- hash: 89
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 0
10
- - 3
11
- version: 0.2.0.3
9
+ - 2
10
+ version: 0.2.2
12
11
  platform: ruby
13
12
  authors:
14
13
  - J. Wostenberg
@@ -16,7 +15,7 @@ autorequire:
16
15
  bindir: bin
17
16
  cert_chain: []
18
17
 
19
- date: 2011-11-22 00:00:00 -07:00
18
+ date: 2011-11-23 00:00:00 -07:00
20
19
  default_executable:
21
20
  dependencies:
22
21
  - !ruby/object:Gem::Dependency
@@ -64,7 +63,6 @@ files:
64
63
  - lib/rubydraw/rectangle.rb
65
64
  - examples/window_ex.rb
66
65
  - examples/image_ex.rb
67
- - examples/sound_ex.rb
68
66
  - examples/ball_catch_game.rb
69
67
  - examples/media/bug.png
70
68
  - examples/media/ball.png
data/examples/sound_ex.rb DELETED
@@ -1,21 +0,0 @@
1
- require 'rubygems'
2
- require 'rubydraw'
3
-
4
- class MyWindow < Rubydraw::Window
5
- def initialize
6
- super(300, 300)
7
- @sound = Rubydraw::Sound.new("media/hooray.ogg")
8
- @sound2 = Rubydraw::Sound.new("media/noise.o.ogg")
9
- whenever Rubydraw::Events::QuitRequest do
10
- close
11
- end
12
- whenever Rubydraw::Events::KeyPressed do
13
- @sound.play if @sound.stopped?
14
- end
15
- whenever Rubydraw::Events::FocusLoss do
16
- @sound2.play if @sound2.stopped?
17
- end
18
- end
19
- end
20
-
21
- MyWindow.new.show