Class: Processing::App
- Inherits:
-
PApplet
- Object
- PApplet
- Processing::App
- Includes:
- Math, HelperMethods
- Defined in:
- lib/ruby-processing/app.rb
Overview
This is the main Ruby-Processing class, and is what you’ll inherit from when you create a sketch. This class can call all of the methods available in Processing, and has two mandatory methods, ‘setup’ and ‘draw’, both of which you should define in your sketch. ‘setup’ will be called one time when the sketch is first loaded, and ‘draw’ will be called constantly, for every frame.
Constant Summary collapse
- @@library_loader =
LibraryLoader.new
Class Attribute Summary collapse
-
.sketch_class ⇒ Object
Returns the value of attribute sketch_class.
Class Method Summary collapse
-
.inherited(subclass) ⇒ Object
Keep track of what inherits from the Processing::App, because we’re going to want to instantiate one.
- .library_loaded?(library_name) ⇒ Boolean
- .load_java_library(*args) ⇒ Object
- .load_libraries(*args) ⇒ Object (also: load_library)
- .load_ruby_library(*args) ⇒ Object
-
.method_added(method_name) ⇒ Object
When certain special methods get added to the sketch, we need to let Processing call them by their expected Java names.
Instance Method Summary collapse
-
#close ⇒ Object
Cleanly close and shutter a running sketch.
-
#initialize(options = {}) ⇒ App
constructor
It is ‘NOT’ usually necessary to directly pass options to a sketch, it gets done automatically for you.
-
#inspect ⇒ Object
Provide a loggable string to represent this sketch.
- #library_loaded?(library_name) ⇒ Boolean
- #post_initialize(_args) ⇒ Object
- #size(*args) ⇒ Object
- #sketch_class ⇒ Object
-
#start ⇒ Object
Make sure we set the size if we set it before we start the animation thread.
Methods included from HelperMethods
#blend_color, #buffer, #color, #constrain, #dist, #find_method, #frame_count, #frame_rate, #grid, #java_self, #key, #key_code, #key_pressed?, #lerp, #lerp_color, #load_strings, #map, #map1d, #max, #min, #mouse_button, #mouse_pressed?, #mouse_x, #mouse_y, #norm, #pmouse_x, #pmouse_y, #proxy_java_fields, #save_strings, #set_sketch_path, #sketch_path, #thread
Constructor Details
#initialize(options = {}) ⇒ App
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)
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/ruby-processing/app.rb', line 106 def initialize( = {}) super() post_initialize() $app = self proxy_java_fields set_sketch_path # unless Processing.online? mix_proxy_into_inner_classes # @started = false java.lang.Thread.default_uncaught_exception_handler = proc do |_thread_, exception| puts(exception.class.to_s) puts(exception.) puts(exception.backtrace.map { |trace| '\t' + trace }) close end # For the list of all available args, see:- # http://processing.org/reference/, however not all convenience functions # are implemented in ruby-processing (you should in general prefer ruby # alternatives when available and methods using java reflection, are best # avoided entirely) args = [] @width, @height = [:width], [:height] if @full_screen || [:full_screen] @full_screen = true args << '--present' end @render_mode ||= JAVA2D xc = Processing::RP_CONFIG['X_OFF'] ||= 0 yc = Processing::RP_CONFIG['Y_OFF'] ||= 0 x = [:x] || xc y = [:y] || yc args << "--location=#{x},#{y}" # important no spaces here title = [:title] || File.basename(SKETCH_PATH).sub(/(\.rb)$/, '').titleize args << title PApplet.run_sketch(args, self) end |
Class Attribute Details
.sketch_class ⇒ Object
Returns the value of attribute sketch_class.
61 62 63 |
# File 'lib/ruby-processing/app.rb', line 61 def sketch_class @sketch_class end |
Class Method Details
.inherited(subclass) ⇒ Object
Keep track of what inherits from the Processing::App, because we’re going to want to instantiate one.
70 71 72 73 |
# File 'lib/ruby-processing/app.rb', line 70 def self.inherited(subclass) super(subclass) @sketch_class = subclass end |
.library_loaded?(library_name) ⇒ Boolean
82 83 84 |
# File 'lib/ruby-processing/app.rb', line 82 def library_loaded?(library_name) @@library_loader.library_loaded?(library_name) end |
.load_java_library(*args) ⇒ Object
90 91 92 |
# File 'lib/ruby-processing/app.rb', line 90 def load_java_library(*args) @@library_loader.load_java_library(*args) end |
.load_libraries(*args) ⇒ Object Also known as: load_library
77 78 79 |
# File 'lib/ruby-processing/app.rb', line 77 def load_libraries(*args) @@library_loader.load_library(*args) end |
.load_ruby_library(*args) ⇒ Object
86 87 88 |
# File 'lib/ruby-processing/app.rb', line 86 def load_ruby_library(*args) @@library_loader.load_ruby_library(*args) end |
.method_added(method_name) ⇒ Object
When certain special methods get added to the sketch, we need to let Processing call them by their expected Java names.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/ruby-processing/app.rb', line 41 def self.method_added(method_name) #:nodoc: # Watch the definition of these methods, to make sure # that Processing is able to call them during events. methods_to_alias = { mouse_pressed: :mousePressed, mouse_dragged: :mouseDragged, mouse_clicked: :mouseClicked, mouse_moved: :mouseMoved, mouse_released: :mouseReleased, key_pressed: :keyPressed, key_released: :keyReleased, key_typed: :keyTyped } if methods_to_alias.key?(method_name) alias_method methods_to_alias[method_name], method_name end end |
Instance Method Details
#close ⇒ Object
Cleanly close and shutter a running sketch.
175 176 177 178 179 |
# File 'lib/ruby-processing/app.rb', line 175 def close control_panel.remove if respond_to?(:control_panel) dispose frame.dispose end |
#inspect ⇒ Object
Provide a loggable string to represent this sketch.
170 171 172 |
# File 'lib/ruby-processing/app.rb', line 170 def inspect "#<Processing::App:#{self.class}:#{@title}>" end |
#library_loaded?(library_name) ⇒ Boolean
95 96 97 |
# File 'lib/ruby-processing/app.rb', line 95 def library_loaded?(library_name) self.class.library_loaded?(library_name) end |
#post_initialize(_args) ⇒ Object
159 160 161 |
# File 'lib/ruby-processing/app.rb', line 159 def post_initialize(_args) nil end |
#size(*args) ⇒ Object
145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/ruby-processing/app.rb', line 145 def size(*args) w, h, mode = *args @width ||= w unless @width @height ||= h unless @height @render_mode ||= mode unless @render_mode if [P3D, P2D].include? @render_mode # Include some opengl processing 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 super(*args) end |
#sketch_class ⇒ Object
64 65 66 |
# File 'lib/ruby-processing/app.rb', line 64 def sketch_class self.class.sketch_class end |
#start ⇒ Object
Make sure we set the size if we set it before we start the animation thread.
164 165 166 167 |
# File 'lib/ruby-processing/app.rb', line 164 def start size(@width, @height) if @width && @height super() end |