ruby-processing 1.0.10.1 → 1.0.11

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,8 @@
1
+ v1.0.11 Fixing broken stuffs...
2
+ * JRuby upgraded to 1.6.5
3
+ * applet export fixed
4
+ * application export fixed
5
+
1
6
  v1.0.10 Solidifying before Processing 2.0 ...
2
7
  * JRuby upgraded to 1.6.4
3
8
  * Processing upgraded to 1.5.1
Binary file
@@ -14,7 +14,7 @@ require 'ruby-processing/helpers/numeric'
14
14
 
15
15
  # The top-level namespace, a home for all Ruby-Processing classes.
16
16
  module Processing
17
- VERSION = "1.0.10" unless defined? Processing::VERSION
17
+ VERSION = "1.0.11" unless defined? Processing::VERSION
18
18
 
19
19
  # Are we online -- inside an applet?
20
20
  def self.online?
@@ -126,12 +126,14 @@ module Processing
126
126
  set_sketch_path unless Processing.online?
127
127
  mix_proxy_into_inner_classes
128
128
  @started = false
129
-
130
- java.lang.Thread.default_uncaught_exception_handler = proc do |thread, exception|
131
- puts(exception.class.to_s)
132
- puts(exception.message)
133
- puts(exception.backtrace.collect { |trace| "\t" + trace })
134
- close
129
+
130
+ unless Processing.online?
131
+ java.lang.Thread.default_uncaught_exception_handler = proc do |thread, exception|
132
+ puts(exception.class.to_s)
133
+ puts(exception.message)
134
+ puts(exception.backtrace.collect { |trace| "\t" + trace })
135
+ close
136
+ end
135
137
  end
136
138
 
137
139
  # for the list of all available args, see
@@ -147,13 +149,24 @@ module Processing
147
149
 
148
150
  @render_mode ||= JAVA2D
149
151
 
150
- x = options[:x] || 0
151
- y = options[:y] || 0
152
- args << "--location=#{x},#{y}"
152
+ if Processing.online?
153
+ JRUBY_APPLET.background_color = nil
154
+ JRUBY_APPLET.double_buffered = false
155
+ JRUBY_APPLET.add self
156
+ JRUBY_APPLET.validate
157
+ # Add the callbacks to peacefully expire.
158
+ JRUBY_APPLET.on_stop { self.stop }
159
+ JRUBY_APPLET.on_destroy { self.destroy }
160
+ init
161
+ else
162
+ x = options[:x] || 0
163
+ y = options[:y] || 0
164
+ args << "--location=#{x},#{y}"
153
165
 
154
- title = options[:title] || File.basename(SKETCH_PATH).sub(/(\.rb|\.pde)$/, '').titleize
155
- args << title
156
- PApplet.run_sketch(args, self)
166
+ title = options[:title] || File.basename(SKETCH_PATH).sub(/(\.rb|\.pde)$/, '').titleize
167
+ args << title
168
+ PApplet.run_sketch(args, self)
169
+ end
157
170
  end
158
171
 
159
172
  def started?
@@ -235,15 +248,6 @@ module Processing
235
248
  end
236
249
  end
237
250
 
238
- def display_in_an_applet
239
- JRUBY_APPLET.background_color = nil
240
- JRUBY_APPLET.double_buffered = false
241
- JRUBY_APPLET.add self
242
- JRUBY_APPLET.validate
243
- # Add the callbacks to peacefully expire.
244
- JRUBY_APPLET.on_stop { self.stop }
245
- JRUBY_APPLET.on_destroy { self.destroy }
246
- end
247
251
  end # Processing::App
248
252
 
249
253
 
@@ -255,18 +259,18 @@ module Processing
255
259
 
256
260
  # Generate the list of method names that we'd like to proxy for inner classes.
257
261
  # Nothing camelCased, nothing __internal__, just the Processing API.
258
- def self.desired_method_names
262
+ def self.desired_method_names(inner_class)
259
263
  bad_method = /__/ # Internal JRuby methods.
260
264
  unwanted = PApplet.superclass.instance_methods + Object.instance_methods
261
265
  unwanted -= ['width', 'height', 'cursor', 'create_image', 'background', 'size', 'resize']
262
266
  methods = Processing::App.public_instance_methods
263
- methods.reject {|m| unwanted.include?(m) || bad_method.match(m) }
267
+ methods.reject {|m| unwanted.include?(m) || bad_method.match(m) || inner_class.method_defined?(m) }
264
268
  end
265
269
 
266
270
 
267
271
  # Proxy methods through to the sketch.
268
- def self.proxy_methods
269
- code = desired_method_names.inject('') do |code, method|
272
+ def self.proxy_methods(inner_class)
273
+ code = desired_method_names(inner_class).inject('') do |code, method|
270
274
  code << <<-EOS
271
275
  def #{method}(*args, &block) # def rect(*args, &block)
272
276
  if block_given? # if block_given?
@@ -277,24 +281,23 @@ module Processing
277
281
  end # end
278
282
  EOS
279
283
  end
280
- module_eval(code, "Processing::Proxy", 1)
284
+ inner_class.class_eval(code)
281
285
  end
282
286
 
283
287
 
284
288
  # Proxy the sketch's constants on to the inner classes.
285
- def self.proxy_constants
289
+ def self.proxy_constants(inner_class)
286
290
  Processing::App.constants.each do |name|
287
- Processing::Proxy.const_set(name, Processing::App.const_get(name))
291
+ next if inner_class.const_defined?(name)
292
+ inner_class.const_set(name, Processing::App.const_get(name))
288
293
  end
289
294
  end
290
295
 
291
296
 
292
297
  # Don't do all of the work unless we have an inner class that needs it.
293
298
  def self.included(inner_class)
294
- return if @already_defined
295
- proxy_methods
296
- proxy_constants
297
- @already_defined = true
299
+ proxy_methods(inner_class)
300
+ proxy_constants(inner_class)
298
301
  end
299
302
 
300
303
  end # Processing::Proxy
@@ -7,8 +7,8 @@ module Processing
7
7
  USAGE = <<-EOS
8
8
 
9
9
  The applet generator will generate a web-ready applet for you.
10
- Usage: script/applet <path_to_sketch>
11
- Example: script/applet samples/jwishy.rb
10
+ Usage: rp5 applet <path_to_sketch>
11
+ Example: rp5 applet samples/jwishy.rb
12
12
 
13
13
  EOS
14
14
 
@@ -33,7 +33,7 @@ module Processing
33
33
  end
34
34
 
35
35
  def compute_destination_name
36
- @dest = "#{@main_file.sub(".rb", "")}"
36
+ @dest = "#{@main_file.sub(".rb", "")}_applet"
37
37
  end
38
38
 
39
39
  def copy_over_necessary_files
@@ -75,4 +75,4 @@ module Processing
75
75
  end
76
76
 
77
77
  end
78
- end
78
+ end
@@ -1,5 +1,6 @@
1
1
  require 'fileutils'
2
2
  require 'erb'
3
+ require 'ruby-processing/library_loader'
3
4
 
4
5
  module Processing
5
6
 
@@ -53,6 +54,7 @@ module Processing
53
54
  size_match = source.match(/^[^#]*size\(?\s*(\d+)\s*,\s*(\d+)\s*\)?/)
54
55
  return match[1] if match
55
56
  return (dimension == 'width' ? size_match[1] : size_match[2]) if size_match
57
+ warn "using default dimensions for export, please use constants integer values in size() call instead of computed ones"
56
58
  DEFAULT_DIMENSIONS[dimension]
57
59
  end
58
60
 
@@ -64,22 +66,14 @@ module Processing
64
66
 
65
67
  # Searches the source for any libraries that have been loaded.
66
68
  def extract_libraries(source)
67
- libs = []
68
- code = source.dup
69
- loop do
70
- matchdata = code.match(/^[^#]*load_librar(y|ies)\s+(.+)\n/)
71
- break unless matchdata
72
- candidates = matchdata[2].gsub(/[:"'\s]/, '').split(/,/)
73
- candidates.each do |cand|
74
- @opengl = true if cand.match(/opengl/i)
75
- local_path = "#{local_dir}/library/#{cand}"
76
- rp5_path = "#{RP5_ROOT}/library/#{cand}"
77
- libs << rp5_path if File.exists?(rp5_path)
78
- libs << local_path if File.exists?(local_path)
69
+ lines = source.split("\n")
70
+ libs = lines.grep(/^[^#]*load_(?:java_|ruby_)?librar(?:y|ies)\s+(.+)/) do
71
+ $1.split(/\s*,\s*/).collect do |raw_library_name|
72
+ raw_library_name.tr("\"':\r\n", '')
79
73
  end
80
- code = matchdata.post_match
81
- end
82
- libs
74
+ end.flatten
75
+ lib_loader = LibraryLoader.new
76
+ libs.map { |lib| lib_loader.get_library_paths(lib) }.flatten.compact
83
77
  end
84
78
 
85
79
  # Looks for all of the codes require or load commands, checks
@@ -95,10 +89,14 @@ module Processing
95
89
  line = matchdata[0].gsub('__FILE__', "'#{@main_file_path}'")
96
90
  line = line.gsub(/\b(require|load)\b/, 'partial_paths << ')
97
91
  eval(line)
98
- requirements += Dir["{#{local_dir}/,}{#{partial_paths.join(',')}}.{rb,jar}"]
92
+ where = "{#{local_dir}/,}{#{partial_paths.join(',')}}"
93
+ unless line =~ /\.[^.]+$/
94
+ where += ".{rb,jar}"
95
+ end
96
+ requirements += Dir[where]
99
97
  code = matchdata.post_match
100
98
  end
101
- return requirements
99
+ requirements
102
100
  end
103
101
 
104
102
 
@@ -136,4 +134,4 @@ module Processing
136
134
  end
137
135
 
138
136
  end
139
- end
137
+ end
@@ -31,12 +31,31 @@ module Processing
31
31
  def color(*args)
32
32
  a = args[0]
33
33
  # convert to signed int
34
- if args.length == 1 && a.is_a?(Fixnum) && a >= 2**31
35
- args = [ a - 2**32 ]
34
+ if args.length == 1
35
+ if a.is_a?(Fixnum) && a >= 2**31
36
+ args = [ a - 2**32 ]
37
+ elsif a.is_a?(String) && a[0] == ?#
38
+ h = a[1..-1]
39
+ # add opaque alpha channel
40
+ if h.size <= 6
41
+ h = "ff" + "0"*(6-h.size) + h
42
+ end
43
+ return color(h.hex)
44
+ end
36
45
  end
37
46
  super(*args)
38
47
  end
39
48
 
49
+ def loop(&block)
50
+ if block_given?
51
+ while true do
52
+ yield
53
+ end
54
+ else
55
+ super
56
+ end
57
+ end
58
+
40
59
  # There's just so many functions in Processing,
41
60
  # Here's a convenient way to look for them.
42
61
  def find_method(method_name)
@@ -38,9 +38,9 @@ module Processing
38
38
  return false
39
39
  end
40
40
  else
41
- path = get_library_path(library_name, "rb")
41
+ path = get_library_paths(library_name, "rb").first
42
42
  return false unless path
43
- return @loaded_libraries[library_name] = (require "#{path}/#{library_name}")
43
+ return @loaded_libraries[library_name] = (require path)
44
44
  end
45
45
  end
46
46
 
@@ -57,8 +57,8 @@ module Processing
57
57
  if Processing.online?
58
58
  return @loaded_libraries[library_name] = !!(JRUBY_APPLET.get_parameter("archive").match(%r(#{library_name})))
59
59
  end
60
- path = get_library_path(library_name, "jar")
61
- jars = Dir["#{path}/*.jar"]
60
+ path = get_library_directory_path(library_name, "jar")
61
+ jars = get_library_paths(library_name, "jar")
62
62
  return false if jars.empty?
63
63
  jars.each {|jar| require jar }
64
64
 
@@ -96,8 +96,30 @@ module Processing
96
96
  [ platform, platform+bits ].collect { |p| File.join(basename, p) }
97
97
  end
98
98
 
99
+ def get_library_paths(library_name, extension = nil)
100
+ dir = get_library_directory_path(library_name, extension)
101
+ Dir.glob("#{dir}/*.{rb,jar}")
102
+ end
103
+
99
104
  protected
100
105
 
106
+ def get_library_directory_path(library_name, extension = nil)
107
+ extensions = extension ? [extension] : %w{jar rb}
108
+ extensions.each do |ext|
109
+ [ "#{SKETCH_ROOT}/library/#{library_name}",
110
+ "#{RP5_ROOT}/library/#{library_name}/library",
111
+ "#{RP5_ROOT}/library/#{library_name}",
112
+ "#{@sketchbook_library_path}/#{library_name}/library",
113
+ "#{@sketchbook_library_path}/#{library_name}"
114
+ ].each do |path|
115
+ if File.exists?(path) && !Dir.glob(path + "/*.#{ext}").empty?
116
+ return path
117
+ end
118
+ end
119
+ end
120
+ nil
121
+ end
122
+
101
123
  def find_sketchbook_path
102
124
  preferences_paths = []
103
125
  sketchbook_paths = []
@@ -126,15 +148,5 @@ module Processing
126
148
  end
127
149
  end
128
150
 
129
- def get_library_path(library_name, extension)
130
- [ "#{SKETCH_ROOT}/library/#{library_name}",
131
- "#{RP5_ROOT}/library/#{library_name}/library",
132
- "#{RP5_ROOT}/library/#{library_name}",
133
- "#{@sketchbook_library_path}/#{library_name}/library",
134
- "#{@sketchbook_library_path}/#{library_name}"
135
- ].detect do |path|
136
- File.exists?("#{path}/#{library_name}.#{extension}")
137
- end
138
- end
139
151
  end
140
152
  end
@@ -5,7 +5,6 @@ SKETCH_ROOT = File.dirname(SKETCH_PATH) unless defined? SKETCH_ROOT
5
5
  require 'ruby-processing'
6
6
  require 'ruby-processing/app'
7
7
 
8
-
9
8
  module Processing
10
9
 
11
10
  # For use with "bare" sketches that don't want to define a class or methods
@@ -46,9 +45,9 @@ module Processing
46
45
  if Processing.online?
47
46
  # Fuck the following lines. Fucking Java can go sit on broken glass.
48
47
  source = ''
49
- url = java.net.URL.new(JRUBY_APPLET.get_code_base, SKETCH_PATH)
50
- input = java.io.BufferedReader.new(java.io.InputStreamReader.new(url.open_stream))
51
- while line = input.read_line do
48
+ url = java.net.URL.new(JRUBY_APPLET.java_send(:getCodeBase), SKETCH_PATH)
49
+ input = java.io.BufferedReader.new(java.io.InputStreamReader.new(url.java_send(:openStream)))
50
+ while line = input.java_send(:readLine) do
52
51
  source << (line + "\n") if line
53
52
  end
54
53
  input.close
@@ -97,7 +97,7 @@
97
97
  <a href="http://wiki.github.com/jashkenas/ruby-processing">
98
98
  <img src="images/built_with.jpg" alt="Ruby-Processing" />
99
99
  </a>
100
- Via <a href="http://jruby.codehaus.org/">JRuby</a> and <a href="http://processing.org/">Processing</a><br />
100
+ Via <a href="http://jruby.org/">JRuby</a> and <a href="http://processing.org/">Processing</a><br />
101
101
  Source: <a href="<%= @main_file %>"><%= @main_file %></a>
102
102
  </div>
103
103
 
@@ -110,4 +110,4 @@
110
110
 
111
111
  </div>
112
112
  </body>
113
- </html>
113
+ </html>
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-processing
3
3
  version: !ruby/object:Gem::Version
4
- hash: 117
4
+ hash: 1
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
- - 10
10
- - 1
11
- version: 1.0.10.1
9
+ - 11
10
+ version: 1.0.11
12
11
  platform: ruby
13
12
  authors:
14
13
  - Jeremy Ashkenas
@@ -62,21 +61,21 @@ extra_rdoc_files:
62
61
  - LICENSE
63
62
  files:
64
63
  - bin/rp5
65
- - lib/ruby-processing/exporters/applet_exporter.rb
66
64
  - lib/ruby-processing/exporters/application_exporter.rb
67
- - lib/ruby-processing/exporters/base_exporter.rb
68
65
  - lib/ruby-processing/exporters/creator.rb
66
+ - lib/ruby-processing/exporters/applet_exporter.rb
67
+ - lib/ruby-processing/exporters/base_exporter.rb
69
68
  - lib/ruby-processing/helpers/numeric.rb
70
69
  - lib/ruby-processing/helpers/string.rb
71
- - lib/ruby-processing/runners/base.rb
72
70
  - lib/ruby-processing/runners/live.rb
73
71
  - lib/ruby-processing/runners/run.rb
74
72
  - lib/ruby-processing/runners/watch.rb
73
+ - lib/ruby-processing/runners/base.rb
75
74
  - lib/ruby-processing/helper_methods.rb
76
- - lib/ruby-processing/app.rb
77
75
  - lib/ruby-processing/config.rb
78
- - lib/ruby-processing/library_loader.rb
79
76
  - lib/ruby-processing/runner.rb
77
+ - lib/ruby-processing/app.rb
78
+ - lib/ruby-processing/library_loader.rb
80
79
  - lib/templates/applet/images/built_with.jpg
81
80
  - lib/templates/applet/images/top.png
82
81
  - lib/templates/applet/images/ruby.jpg
@@ -93,9 +92,9 @@ files:
93
92
  - lib/templates/application/run.exe
94
93
  - lib/templates/create/bare_sketch.rb.erb
95
94
  - lib/templates/create/blank_sketch.rb.erb
96
- - lib/ruby-processing.rb
97
95
  - lib/core/jruby-complete.jar
98
96
  - lib/core/core.jar
97
+ - lib/ruby-processing.rb
99
98
  - library/boids/boids.rb
100
99
  - library/control_panel/control_panel.rb
101
100
  - library/dxf/library/dxf.jar