rubydraw 0.2.2 → 0.2.2.3

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.
@@ -3,7 +3,7 @@ require 'rubydraw'
3
3
 
4
4
  class GameWindow < Rubydraw::Window
5
5
  def initialize
6
- super(500, 500, Rubydraw::Color::White)
6
+ super(500, 500, false, Rubydraw::Color::White)
7
7
  @score = 0
8
8
  @score_text = Rubydraw::Text.new("", Rubydraw::Color::Black)
9
9
  @game_objects = []
@@ -40,5 +40,10 @@ module Rubydraw
40
40
  def height
41
41
  @sdl_image.h
42
42
  end
43
+
44
+ # Returns the sdl surface.
45
+ def to_sdl
46
+ @sdl_image
47
+ end
43
48
  end
44
49
  end
@@ -5,26 +5,31 @@ module Rubydraw
5
5
  # (which starts when Rubydraw::Window#open is called) is *not* forked! It will break
6
6
  # when Rubydraw::Window#close is called.
7
7
  class Window
8
- attr_reader(:width, :height)
8
+ attr_reader(:width, :height, :fullscreen, :bkg_color)
9
9
 
10
10
  # Create a new window.
11
- def initialize(width, height, bkg_color=Color::Black)
12
- @width = width
13
- @height = height
11
+ def initialize(width, height, fullscreen=false, bkg_color=Color::Black)
12
+ @width, @height = width, height
13
+ @fullscreen = fullscreen
14
+ @bkg_color = bkg_color
14
15
  @open = false
16
+ @flags =
17
+ if fullscreen
18
+ SDL::FULLSCREEN
19
+ else
20
+ 0
21
+ end
15
22
 
16
23
  @event_queue = EventQueue.new
17
24
 
18
25
  @registered_actions = {}
19
-
20
- @bkg_color = bkg_color
21
26
  end
22
27
 
23
28
  # Call this method to start updating and drawing.
24
29
  def show
25
30
  @open = true
26
31
  # Behold, the main loop. Drumroll!
27
- @screen = SDL::SetVideoMode(@width, @height, 0, 0)
32
+ @screen = SDL::SetVideoMode(@width, @height, 0, @flags)
28
33
  loop do
29
34
  handle_events
30
35
  if @open
@@ -62,6 +67,21 @@ module Rubydraw
62
67
 
63
68
  alias quit close
64
69
 
70
+ # Returns the window's current title.
71
+ def title
72
+ SDL.WM_GetCaption
73
+ end
74
+
75
+ # Sets the window title to +new+.
76
+ def title=(new)
77
+ SDL.WM_SetCaption(new, new)
78
+ end
79
+
80
+ # Sets the window's icon to +new+.
81
+ def icon=(new)
82
+ SDL.WM_SetIcon(new.to_sdl, nil)
83
+ end
84
+
65
85
  # Collect and handle new events by executing blocks in +@regestered_events+. See
66
86
  # Rubydraw::Window#register_action on how to use it.
67
87
  def handle_events
@@ -147,15 +167,17 @@ module Rubydraw
147
167
 
148
168
  # Draw an ellipse. Similar to Rubydraw::Window#draw_circle, except not all ellipses are circles.
149
169
  #
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?
170
+ # center: The center of the ellipse, should be a Rubydraw::Point object.
171
+ # dimensions: Determines the width and the height of the ellipse to be drawn; should be a Rubydraw::Point.
172
+ # color: The color to use when drawing; should be an instance of Rubydraw::Color.
173
+ # fill: Fill the ellipse with said color?
174
+ # anti_aliasing: When set to true, smoothing happens.
154
175
  def draw_ellipse(center, dimensions, color, mode=:fill)
155
176
  x, y = center.to_a
156
177
  width, height = (dimensions / 2).to_a
157
178
  r, g, b, a = color.to_a
158
179
  args = [@screen, x, y, width, height, r, g, b, a]
180
+
159
181
  if mode == :fill
160
182
  SDL::Gfx.filledEllipseRGBA(*args)
161
183
  return self
@@ -168,7 +190,8 @@ module Rubydraw
168
190
  SDL::Gfx.aaellipseRGBA(*args)
169
191
  return self
170
192
  end
171
- # Only gets here when +mode+ is not recognised.
193
+
194
+ # Only reaches this when +mode+ is not recognized.
172
195
  raise ArgumentError, "Unknown mode '#{mode}'"
173
196
  end
174
197
 
metadata CHANGED
@@ -1,13 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubydraw
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 81
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
9
  - 2
10
- version: 0.2.2
10
+ - 3
11
+ version: 0.2.2.3
11
12
  platform: ruby
12
13
  authors:
13
14
  - J. Wostenberg