class Processing::App
All sketches extend this class
Attributes
Handy getters and setters on the class go here:
Handy getters and setters on the class go here:
Public Class Methods
Keep track of what inherits from the Processing::App
, because we're going to want to instantiate one.
# File lib/ruby-processing/app.rb, line 58 def self.inherited(subclass) super(subclass) @sketch_class = subclass end
# File lib/ruby-processing/app.rb, line 73 def library_loaded?(library_name) library_loader.library_loaded?(library_name) end
# File lib/ruby-processing/app.rb, line 81 def load_java_library(*args) library_loader.load_java_library(*args) end
# File lib/ruby-processing/app.rb, line 67 def load_libraries(*args) library_loader ||= LibraryLoader.new library_loader.load_library(*args) end
# File lib/ruby-processing/app.rb, line 77 def load_ruby_library(*args) library_loader.load_ruby_library(*args) end
It is 'NOT' usually necessary to directly pass options to a sketch, it gets done automatically for you. Since processing-2.0 you should prefer setting the sketch width and height and renderer using the size method, in the sketch (as with vanilla processing), which should be the first argument in setup. Sensible options to pass are x and y to locate sketch on the screen, or full_screen: true (prefer new hash syntax)
# File lib/ruby-processing/app.rb, line 104 def initialize(options = {}) super() post_initialize(options) $app = self proxy_java_fields set_sketch_path # unless Processing.online? mix_proxy_into_inner_classes java.lang.Thread.default_uncaught_exception_handler = proc do |_thread_, exception| puts(exception.class.to_s) puts(exception.message) puts(exception.backtrace.map { |trace| "\t#{trace}" }) close end run_sketch(options) end
Public Instance Methods
Cleanly close and shutter a running sketch.
# File lib/ruby-processing/app.rb, line 146 def close control_panel.remove if respond_to?(:control_panel) dispose frame.dispose end
Provide a loggable string to represent this sketch.
# File lib/ruby-processing/app.rb, line 141 def inspect "#<Processing::App:#{self.class}:#{@title}>" end
# File lib/ruby-processing/app.rb, line 93 def library_loaded?(library_name) self.class.library_loaded?(library_name) end
# File lib/ruby-processing/app.rb, line 130 def post_initialize(_args) nil end
# File lib/ruby-processing/app.rb, line 121 def size(*args) w, h, mode = *args @width ||= w @height ||= h @render_mode ||= mode import_opengl if /opengl/ =~ mode super(*args) end
# File lib/ruby-processing/app.rb, line 52 def sketch_class self.class.sketch_class end
Set the size if we set it before we start the animation thread.
# File lib/ruby-processing/app.rb, line 135 def start size(@width, @height) if @width && @height super() end
Private Instance Methods
# File lib/ruby-processing/app.rb, line 165 def import_opengl # Include processing opengl classes that we'd like to use: %w(FontTexture FrameBuffer LinePath LineStroker PGL PGraphics2D PGraphics3D PGraphicsOpenGL PShader PShapeOpenGL Texture).each do |klass| java_import "processing.opengl.#{klass}" end end
Mix the Processing::Proxy
into any inner classes defined for the sketch, attempting to mimic the behavior of Java's inner classes.
# File lib/ruby-processing/app.rb, line 156 def mix_proxy_into_inner_classes klass = Processing::App.sketch_class klass.constants.each do |name| const = klass.const_get name next if const.class != Class || const.to_s.match(/^Java::/) const.class_eval('include Processing::Proxy') end end
# File lib/ruby-processing/app.rb, line 174 def run_sketch(options = {}) args = [] @width, @height = options[:width], options[:height] if options[:full_screen] present = true args << '--full-screen' args << "--bgcolor=#{options[:bgcolor]}" if options[:bgcolor] end xc = Processing::RP_CONFIG['X_OFF'] ||= 0 yc = Processing::RP_CONFIG['Y_OFF'] ||= 0 x = options.fetch(:x, xc) y = options.fetch(:y, yc) args << "--location=#{x},#{y}" # important no spaces here string_extra = StringExtra.new(File.basename(SKETCH_PATH).sub(/(\.rb)$/, '')) title = options.fetch(:title, string_extra.titleize) args << title PApplet.run_sketch(args.to_java(:string), self) end