class Processing::App

All sketches extend this class

Attributes

library_loader[R]

Handy getters and setters on the class go here:

sketch_class[R]

Handy getters and setters on the class go here:

Public Class Methods

inherited(subclass) click to toggle source

Keep track of what inherits from the Processing::App, because we're going to want to instantiate one.

Calls superclass method
# File lib/jruby_art/app.rb, line 60
def self.inherited(subclass)
  super(subclass)
  @sketch_class = subclass
end
library_loaded?(library_name) click to toggle source
# File lib/jruby_art/app.rb, line 75
def library_loaded?(library_name)
  library_loader.library_loaded?(library_name)
end
load_java_library(*args) click to toggle source
# File lib/jruby_art/app.rb, line 83
def load_java_library(*args)
  library_loader.load_java_library(*args)
end
load_libraries(*args) click to toggle source
# File lib/jruby_art/app.rb, line 69
def load_libraries(*args)
  @library_loader ||= LibraryLoader.new
  library_loader.load_library(*args)
end
Also aliased as: load_library
load_library(*args)
Alias for: load_libraries
load_ruby_library(*args) click to toggle source
# File lib/jruby_art/app.rb, line 79
def load_ruby_library(*args)
  library_loader.load_ruby_library(*args)
end
new(options = {}) click to toggle source

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)

Calls superclass method
# 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() click to toggle source

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
data_path(dat) click to toggle source
# 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
exit() click to toggle source
Calls superclass method
# File lib/jruby_art/app.rb, line 175
def exit
  control_panel.remove if respond_to?(:control_panel)
  super()
end
library_loaded?(library_name) click to toggle source
# File lib/jruby_art/app.rb, line 96
def library_loaded?(library_name)
  self.class.library_loaded?(library_name)
end
on_top(arg = true) click to toggle source
# File lib/jruby_art/app.rb, line 156
def on_top(arg = true)
  surface.set_always_on_top(arg)
end
post_initialize(_args) click to toggle source
# File lib/jruby_art/app.rb, line 160
def post_initialize(_args)
  nil
end
resizable(arg = true) click to toggle source
# File lib/jruby_art/app.rb, line 152
def resizable(arg = true)
  surface.set_resizable(arg)
end
size(*args) click to toggle source
Calls superclass method
# 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
sketch_class() click to toggle source
# File lib/jruby_art/app.rb, line 54
def sketch_class
  self.class.sketch_class
end
sketch_path(spath = '') click to toggle source
Calls superclass method
# File lib/jruby_art/app.rb, line 136
def sketch_path(spath = '')
  return super() if spath.empty?

  super(spath)
end
sketch_size(x, y) click to toggle source
# File lib/jruby_art/app.rb, line 148
def sketch_size(x, y)
  surface.set_size(x, y)
end
sketch_title(title) click to toggle source
# File lib/jruby_art/app.rb, line 132
def sketch_title(title)
  surface.set_title(title)
end

Private Instance Methods

import_opengl() click to toggle source
# 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_proxy_into_inner_classes() click to toggle source

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