Skip to content

Commit 762c64e

Browse files
authored
Merge pull request #13 from ruby-processing/post_initialize
Post initialize
2 parents 994143b + f098b93 commit 762c64e

7 files changed

Lines changed: 25 additions & 13 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
**v2.5.0** No need for `$app` we can replace with `Propane.app`
2+
3+
**v2.4.1** Add post_initialize hoop to app.rb.
4+
15
**v2.4.0** Extend LibraryProxy to include mouseEvent and keyEvent.
26

37
**v2.3.4** Simplify control_panel library (replacing `c.title = 'PaneTitle'` with `c.title('PaneTitle')`) also enable use of `block` with `button's`.

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
A slim layer to communicate with Processing from JRuby, features a polyglot maven build. We have created a configuration free version of ruby processing, for processing-3.3.5, where we include processing core (from a local maven repository and opengl etc from maven central). These jars are small enough to include in a gem distribution, and hence we do not require configuration. This has created a scriptable version, ie files get run direct from jruby, but you could use jruby-complete if you used the propane script (avoids need to give the absolute data path for the data folder, but would also be needed for a watch mode). See guide to [building ruby-processing projects][building].
55

6-
NB: The main reason for build failing is when the `core.jar` is not available from maven central, to install a local jar:-
6+
NB: The main reason for build failing is when the `core.jar` is not available from maven central, to install a local jar (_example for linux mint_):-
77
```bash
88

99
mvn install:install-file /home/tux/processing-3.3.5/core/library/core.jar -DgroupId=org.processing -DartifactId=core -Dversion=3.3.5
@@ -28,7 +28,7 @@ rake javadoc
2828
## Installation
2929
```bash
3030
jgem install propane # from rubygems
31-
jgem install propane-2.3.4-java.gem # for local install
31+
jgem install propane-2.5.0-java.gem # for local install
3232
```
3333

3434
## Usage

lib/propane/app.rb

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ module Render
4343
key_typed: :keyTyped
4444
}.freeze
4545

46+
class << self
47+
attr_accessor :app
48+
end
49+
4650
# All sketches extend this class
4751
class App < PApplet
4852
include Math, MathTool, HelperMethods, Render
@@ -110,7 +114,8 @@ def initialize(options = {}, arguments = [])
110114
raise TypeError unless arguments.is_a? Array
111115
# Set up the sketch.
112116
super()
113-
$app = self
117+
post_initialize(options)
118+
Propane.app = self
114119
@arguments = arguments
115120
@options = options
116121
run_sketch
@@ -125,6 +130,9 @@ def size(*args)
125130
super(*args)
126131
end
127132

133+
def post_initialize(_args)
134+
end
135+
128136
def sketch_title(title)
129137
surface.set_title(title)
130138
end
@@ -168,11 +176,11 @@ module Proxy
168176
include Java::ProcessingCore::PConstants
169177

170178
def respond_to_missing?(symbol, include_priv = false)
171-
$app.respond_to?(symbol, include_priv) || super
179+
Propane.app.respond_to?(symbol, include_priv) || super
172180
end
173181

174182
def method_missing(name, *args, &block)
175-
return $app.send(name, *args) if $app.respond_to? name
183+
return Propane.app.send(name, *args) if Propane.app.respond_to? name
176184
super
177185
end
178186
end # Processing::Proxy

lib/propane/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# frozen_string_literal: true
22
module Propane
3-
VERSION = '2.4.0'.freeze
3+
VERSION = '2.5.0'.freeze
44
end

library/control_panel/control_panel.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def initialize(control_panel, name, range, initial_value, proc = nil)
2121
label = control_panel.add_element(self, name)
2222
add_change_listener do
2323
update_label(label, name, value)
24-
$app.instance_variable_set("@#{name}", value) unless value.nil?
24+
Propane.app.instance_variable_set("@#{name}", value) unless value.nil?
2525
proc.call(value) if proc
2626
end
2727
set_value(initial_value ? initial_value * 100 : min)
@@ -46,7 +46,7 @@ def initialize(control_panel, name, elements, initial_value, proc = nil)
4646
set_preferred_size(java.awt.Dimension.new(190, 30))
4747
control_panel.add_element(self, name)
4848
add_action_listener do
49-
$app.instance_variable_set("@#{name}", value) unless value.nil?
49+
Propane.app.instance_variable_set("@#{name}", value) unless value.nil?
5050
proc.call(value) if proc
5151
end
5252
set_selected_index(initial_value ? elements.index(initial_value) : 0)
@@ -66,7 +66,7 @@ def initialize(control_panel, name, proc = nil)
6666
set_horizontal_alignment javax.swing.SwingConstants::CENTER
6767
control_panel.add_element(self, name, false)
6868
add_action_listener do
69-
$app.instance_variable_set("@#{name}", value)
69+
Propane.app.instance_variable_set("@#{name}", value)
7070
proc.call(value) if proc
7171
end
7272
end
@@ -83,7 +83,7 @@ def initialize(control_panel, name, proc = nil)
8383
set_preferred_size(java.awt.Dimension.new(170, 64))
8484
control_panel.add_element(self, name, false, true)
8585
add_action_listener do
86-
$app.send(name)
86+
Propane.app.send(name)
8787
proc.call(value) if proc
8888
end
8989
end
@@ -107,7 +107,7 @@ def display
107107
set_size 200, 30 + (64 * elements.size)
108108
set_default_close_operation javax.swing.JFrame::HIDE_ON_CLOSE
109109
set_resizable false
110-
set_location($app.width + 10, 0) unless $app.width + 10 > $app.displayWidth
110+
set_location(Propane.app.width + 10, 0) unless Propane.app.width + 10 > Propane.app.displayWidth
111111
panel.visible = true
112112
end
113113

pom.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
require 'fileutils'
22
project 'rp5extras', 'https://github.com/monkstone/propane' do
33
model_version '4.0.0'
4-
id 'propane:propane', '2.4.0'
4+
id 'propane:propane', '2.5.0'
55
packaging 'jar'
66
description 'rp5extras for propane'
77
organization 'ruby-processing', 'https://ruby-processing.github.io'

vendors/Rakefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ SOUND = 'sound.zip'.freeze
99
SOUND_VERSION = 'v1.3.2' # version 1.3.2
1010
VIDEO = 'video-2.zip'
1111
VIDEO_VERSION = '2' # version 1.0.1
12-
EXAMPLES = '1.4'.freeze
12+
EXAMPLES = '1.5'.freeze
1313
HOME_DIR = ENV['HOME']
1414
MAC_OR_LINUX = /linux|mac|darwin/ =~ RbConfig::CONFIG['host_os']
1515

0 commit comments

Comments
 (0)