rubydraw 0.2.2.5 → 0.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.
@@ -5,9 +5,26 @@ module Rubydraw
5
5
  # read the documentation for Image#draw), call it's #draw method
6
6
  # and pass it the +x+ and +y+ coordinates.
7
7
  class Image
8
- # Create a new image in the given window and load the image from
9
- # +path.+
10
- def initialize(path)
8
+ # Create a new image and load the file from a path. Or, load it using
9
+ # an SDL surface.
10
+ def initialize(arg)
11
+ if arg.is_a?(String)
12
+ # This must mean to load from a path.
13
+ load_from_path(arg)
14
+ elsif arg.is_a?(SDL::Surface)
15
+ load_from_surface(arg)
16
+ else
17
+ raise TypeError, "Failed to load image: Expected String or SDL::Surface but got #{arg}"
18
+ end
19
+ self
20
+ end
21
+
22
+ def load_from_path(path) #:nodoc:
23
+ # Check if this image has already been initialize. If it has, raise
24
+ # an error.
25
+ unless @sdl_image.nil?
26
+ raise SDLError, "Images may only be loaded once"
27
+ end
11
28
  # In case program is being run from a different directory,
12
29
  # provide the _full_ path. Nothing relative here.
13
30
  full_path = File.expand_path path
@@ -19,6 +36,15 @@ module Rubydraw
19
36
  end
20
37
  end
21
38
 
39
+ def load_from_surface(surface) #:nodoc:
40
+ # Check if this image has already been initialized. If it has, raise
41
+ # an error.
42
+ unless @sdl_image.nil?
43
+ raise SDLError, "Images may only be loaded once"
44
+ end
45
+ @sdl_image = surface
46
+ end
47
+
22
48
  # Blit (copy) into the window at +position+ (see Rubydraw::Point).
23
49
  # No graphical effects are applied.
24
50
  #
@@ -27,10 +53,34 @@ module Rubydraw
27
53
  def draw(window, position)
28
54
  source_rect = Rectangle[Point[0, 0], Point[width, height]]
29
55
  blit_rect = Rectangle[position, Point[window.width, window.height]]
56
+ #source_rect = Rectangle[Point[0, 0], Point[window.width, window.height]]
57
+ #blit_rect = Rectangle[position, Point[window.width, window.height]]
30
58
  SDL::BlitSurface(@sdl_image, source_rect.to_sdl, window.sdl_surface, blit_rect.to_sdl)
31
59
  self
32
60
  end
33
61
 
62
+ # Rotates and/or expands the image. Note that this modifies the image
63
+ # itself.
64
+ def rotozoom!(angle, zoom, smooth=false)
65
+ smooth =
66
+ if smooth
67
+ 1
68
+ else
69
+ 0
70
+ end
71
+
72
+ @sdl_image = SDL::Gfx.rotozoomSurface(@sdl_image, angle, zoom, smooth)
73
+ raise SDLError, "Filed to perform rotozoom: #{SDL.GetError}" if @sdl_image.pointer.null?
74
+ return self
75
+ end
76
+
77
+ # Returns a rotated and/or expanded image, without modifying the
78
+ # reciever.
79
+ def rotozoom(angle, zoom, smooth=false)
80
+ new_image = self.class.new(@sdl_image)
81
+ new_image.rotozoom!(angle, zoom, smooth)
82
+ end
83
+
34
84
  # Returns the image width
35
85
  def width
36
86
  @sdl_image.w
data/lib/rubydraw/text.rb CHANGED
@@ -4,6 +4,7 @@ module Rubydraw
4
4
  # screen.
5
5
  class Text
6
6
  attr_accessor(:contents, :font, :color, :size)
7
+
7
8
  # Create a new drawable Text object with the given font and contents.
8
9
  def initialize(contents, color, font_name="Times New Roman", size = 25)
9
10
  @font, @contents, @size, @color = font_name, contents, size, color
@@ -5,7 +5,7 @@ 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, :fullscreen, :bkg_color)
8
+ attr_reader(:fullscreen, :bkg_color)
9
9
 
10
10
  # Create a new window.
11
11
  def initialize(width, height, fullscreen=false, bkg_color=Color::Black)
@@ -25,6 +25,14 @@ module Rubydraw
25
25
  @registered_actions = {}
26
26
  end
27
27
 
28
+ def width
29
+ @screen.w
30
+ end
31
+
32
+ def height
33
+ @screen.h
34
+ end
35
+
28
36
  # Call this method to start updating and drawing.
29
37
  def show
30
38
  @open = true
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: 93
4
+ hash: 17
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 2
10
- - 5
11
- version: 0.2.2.5
9
+ - 3
10
+ version: 0.2.3
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-23 00:00:00 -07:00
18
+ date: 2011-11-25 00:00:00 -07:00
20
19
  default_executable:
21
20
  dependencies:
22
21
  - !ruby/object:Gem::Dependency