rubydraw 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -9,12 +9,13 @@ for the inconvenience!
9
9
  HOW TO INSTALL
10
10
  To install this library which isn't on Rubygems.org YET, navigate to this directory in the command
11
11
  line tool and give "rubydraw/build_and_install" permissions to run. Then simply run it. Hooray, it
12
- should be working now! Test it in irb with "require 'rubydraw'". Also: I will upload this gem to
13
- rubygems when it is actually usable (if it ever is).
12
+ should be working now! Test it in irb with "require 'rubydraw'".
14
13
 
15
14
  HOW TO USE
16
15
  There isn't a proper guide yet, so just read the comments in the other files. Or you can fire up the
17
16
  gem server and read the RDoc.
18
17
 
19
18
  Thanks for checking this little project. I hope it doesn't give you headaches.
20
- Have fun!
19
+ Have fun!
20
+
21
+ NEW: Now you can install it from the RubyGems website! Hooray! :D
data/examples/image_ex.rb CHANGED
@@ -5,10 +5,10 @@ class MyWindow < Rubydraw::Window
5
5
  # Create a new window with an bug image inside it
6
6
  def initialize(width, height)
7
7
  super(width, height)
8
- @image = Rubydraw::Image.new(self, "media/bug.png")
8
+ @image = Rubydraw::Image.new("media/bug.png")
9
9
  @max = 100
10
10
 
11
- register_action(Rubydraw::Events::MouseMove) {|event| puts "Mouse moved! New position: #{event.position.x}, #{event.position.y}"}
11
+ register_action(Rubydraw::Events::MouseMove) {|event| @mouse_position = event.position}
12
12
  register_action(Rubydraw::Events::QuitRequest) {close}
13
13
  end
14
14
 
@@ -19,7 +19,7 @@ class MyWindow < Rubydraw::Window
19
19
 
20
20
  # Draw the image inside this window.
21
21
  def tick
22
- @image.draw(Rubydraw::Point[width / 2, height / 2])
22
+ @image.draw(self, @mouse_position)
23
23
  end
24
24
  end
25
25
 
File without changes
File without changes
File without changes
File without changes
@@ -7,11 +7,7 @@ module Rubydraw
7
7
  class Image
8
8
  # Create a new image in the given window and load the image from
9
9
  # +path.+
10
- def initialize(window, path)
11
- @window = window
12
- unless window.is_a?(Rubydraw::Window)
13
- raise Rubydraw::SDLError "Window cannot be nil"
14
- end
10
+ def initialize(path)
15
11
  # In case program is being run from a different directory,
16
12
  # provide the _full_ path. Nothing relative here.
17
13
  full_path = File.expand_path path
@@ -21,6 +17,8 @@ module Rubydraw
21
17
  # exist.
22
18
  raise Rubydraw::SDLError "Failed to load image from: '#{full_path}'"
23
19
  end
20
+ puts @sdl_image.class
21
+ puts @sdl_image.pointer.class
24
22
  end
25
23
 
26
24
  # Blit (copy) into the window at +position+ (see point.rb).
@@ -28,10 +26,10 @@ module Rubydraw
28
26
  #
29
27
  # Notice that you don't blit surfaces to other surfaces when using
30
28
  # Rubygame, but instead you draw things.
31
- def draw(position)
29
+ def draw(window, position)
32
30
  source_rect = SDL::Rect.new([0, 0, width, height])
33
- blit_rect = SDL::Rect.new([position.x, position.y, @window.width, @window.height])
34
- SDL::BlitSurface(@sdl_image, source_rect, @window.sdl_surface, blit_rect)
31
+ blit_rect = SDL::Rect.new([position.x, position.y, window.width, window.height])
32
+ SDL::BlitSurface(@sdl_image, source_rect, window.sdl_surface, blit_rect)
35
33
  end
36
34
 
37
35
  # Returns the image width
data/lib/rubydraw/keys.rb CHANGED
File without changes
File without changes
File without changes
@@ -29,6 +29,8 @@ module Rubydraw
29
29
  loop do
30
30
  handle_events
31
31
  if @open
32
+ # Clear the contents of the window
33
+ clear
32
34
  tick
33
35
  # Update the screen to show any changes.
34
36
  SDL::UpdateRect(@screen, 0, 0, 0, 0)
@@ -36,11 +38,15 @@ module Rubydraw
36
38
  # This is where the loop is broken after Rubydraw::Window#close is called.
37
39
  break
38
40
  end
39
- # Pause for a bit, so it's not such a tight loop.
40
- sleep 0.1
41
41
  end
42
42
  end
43
43
 
44
+ # Clear the window's contents by filling it with black. A bit of a cheat; I don't
45
+ # know if there is a better way to do this.
46
+ def clear
47
+ SDL::FillRect(@screen, nil, 0)
48
+ end
49
+
44
50
  # Call this method to tell SDL to quit drawing. The loop (started in
45
51
  # Rubydraw::Window#open) would continue if +close+ only stopped drawing, so
46
52
  # break the loop too.
@@ -59,11 +65,6 @@ module Rubydraw
59
65
  block.call(event) unless block.nil?}
60
66
  end
61
67
 
62
- # Redefine this in a subclass to use custom event handling. Does nothing by
63
- # default.
64
- def handle_event(event)
65
- end
66
-
67
68
  # This causes the main loop to exit. Use Rubydraw::Window#close to close the
68
69
  # window, not this.
69
70
  def break_main_loop
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubydraw
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 0
10
- version: 0.1.0
9
+ - 1
10
+ version: 0.1.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - J. Wostenberg