class Processing::App

All sketches extend this class

Attributes

library_loader[RW]

Handy getters and setters on the class go here:

sketch_class[RW]

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/ruby-processing/app.rb, line 58
def self.inherited(subclass)
  super(subclass)
  @sketch_class = subclass
end
library_loaded?(library_name) click to toggle source
# File lib/ruby-processing/app.rb, line 73
def library_loaded?(library_name)
  library_loader.library_loaded?(library_name)
end
load_java_library(*args) click to toggle source
# File lib/ruby-processing/app.rb, line 81
def load_java_library(*args)
  library_loader.load_java_library(*args)
end
load_libraries(*args) click to toggle source
# File lib/ruby-processing/app.rb, line 67
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/ruby-processing/app.rb, line 77
def load_ruby_library(*args)
  library_loader.load_ruby_library(*args)
end
new(options = {}) click to toggle source

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)

Calls superclass method
# 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

close() click to toggle source

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
inspect() click to toggle source

Provide a loggable string to represent this sketch.

# File lib/ruby-processing/app.rb, line 141
def inspect
  "#<Processing::App:#{self.class}:#{@title}>"
end
library_loaded?(library_name) click to toggle source
# File lib/ruby-processing/app.rb, line 93
def library_loaded?(library_name)
  self.class.library_loaded?(library_name)
end
post_initialize(_args) click to toggle source
# File lib/ruby-processing/app.rb, line 130
def post_initialize(_args)
  nil
end
size(*args) click to toggle source
Calls superclass method
# 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
sketch_class() click to toggle source
# File lib/ruby-processing/app.rb, line 52
def sketch_class
  self.class.sketch_class
end
start() click to toggle source

Set the size if we set it before we start the animation thread.

Calls superclass method
# File lib/ruby-processing/app.rb, line 135
def start
  size(@width, @height) if @width && @height
  super()
end

Private Instance Methods

import_opengl() click to toggle source
# 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_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/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
run_sketch(options = {}) click to toggle source
# 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