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/jruby_art/app.rb, line 60 def self.inherited(subclass) super(subclass) @sketch_class = subclass end
# File lib/jruby_art/app.rb, line 75 def library_loaded?(library_name) library_loader.library_loaded?(library_name) end
# File lib/jruby_art/app.rb, line 83 def load_java_library(*args) library_loader.load_java_library(*args) end
# File lib/jruby_art/app.rb, line 69 def load_libraries(*args) @library_loader ||= LibraryLoader.new library_loader.load_library(*args) end
# File lib/jruby_art/app.rb, line 79 def load_ruby_library(*args) library_loader.load_ruby_library(*args) end
Since processing-3.0 you should prefer setting the sketch width and height and renderer using the size method in the settings loop of the sketch (as with vanilla processing) but is hidden see created java. Options are no longer relevant, define post_initialize
method to use custom options (see Sandi Metz POODR)
# File lib/jruby_art/app.rb, line 106 def initialize(options = {}) super() Processing.app = self post_initialize(options) proxy_java_fields 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 @surface = get_surface # NB: this is the processing runSketch() method as used by processing.py run_sketch end
Public Instance Methods
Close and shutter a running sketch. But don't exit. @HACK seems to work with watch until we find a better way of disposing of sketch window…
# File lib/jruby_art/app.rb, line 167 def close control_panel.remove if respond_to?(:control_panel) surface.stopThread surface.setVisible(false) if surface.isStopped dispose Processing.app = nil end
# File lib/jruby_art/app.rb, line 142 def data_path(dat) dat_root = File.join(SKETCH_ROOT, 'data') Dir.mkdir(dat_root) unless File.exist?(dat_root) File.join(dat_root, dat) end
# File lib/jruby_art/app.rb, line 175 def exit control_panel.remove if respond_to?(:control_panel) super() end
# File lib/jruby_art/app.rb, line 96 def library_loaded?(library_name) self.class.library_loaded?(library_name) end
# File lib/jruby_art/app.rb, line 156 def on_top(arg = true) surface.set_always_on_top(arg) end
# File lib/jruby_art/app.rb, line 160 def post_initialize(_args) nil end
# File lib/jruby_art/app.rb, line 152 def resizable(arg = true) surface.set_resizable(arg) end
# File lib/jruby_art/app.rb, line 123 def size(*args) width, height, mode = *args @width ||= width @height ||= height @render_mode ||= mode import_opengl if /opengl/.match?(mode) super(*args) end
# File lib/jruby_art/app.rb, line 54 def sketch_class self.class.sketch_class end
# File lib/jruby_art/app.rb, line 136 def sketch_path(spath = '') return super() if spath.empty? super(spath) end
# File lib/jruby_art/app.rb, line 148 def sketch_size(x, y) surface.set_size(x, y) end
# File lib/jruby_art/app.rb, line 132 def sketch_title(title) surface.set_title(title) end
Private Instance Methods
# File lib/jruby_art/app.rb, line 194 def import_opengl # Include processing opengl classes that we'd like to use: opengl = 'processing.opengl.%s' %w[FontTexture FrameBuffer LinePath LineStroker PGL PGraphics2D PGraphics3D PGraphicsOpenGL PShader PShapeOpenGL Texture].each do |klass| java_import format(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/jruby_art/app.rb, line 184 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 || /^Java::/.match?(const.to_s) const.class_eval 'include Processing::Proxy', __FILE__, __LINE__ end end