Skip to content

Commit bfa36d0

Browse files
authored
Merge pull request #34 from ruby-processing/library_proxy
Library proxy
2 parents 917cbdc + bdce9a1 commit bfa36d0

File tree

7 files changed

+127
-105
lines changed

7 files changed

+127
-105
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
**v1.4.0.pre** Extended LibraryProxy to allow implementing libraries to register mouseEvent(e) and keyEvent(e) with Sketch instance
2+
13
**v1.3.3** Update for processing-3.3.5. Simplify control_panel library (replacing `c.title = 'PaneTitle'` with `c.title('PaneTitle')`) also enable use of `block` with `button's`.
24

35
**v1.3.2** Update for processing-3.3.3, jruby-9.1.12.0 and bump examples version to include glvideo library examples

lib/jruby_art/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# frozen_string_literal: true
22
# A wrapper for version
33
module JRubyArt
4-
VERSION = '1.3.3'.freeze
4+
VERSION = '1.4.0'.freeze
55
end
Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
java_import Java::MonkstoneCore::LibraryProxy
2+
java_import Java::ProcessingEvent::KeyEvent
3+
java_import Java::ProcessingEvent::MouseEvent
24

3-
4-
# classes that inherit from Library are expected to implement
5-
# the abstract methods of monkstone.core.LibraryProxy
6-
# def pre...
7-
# def draw...
8-
# def post...
9-
# def keyPressed...
10-
# def mousePressed...
11-
# NOOP is fine...
5+
# classes that inherit from LibraryProxy are expected to implement
6+
# the abstract draw method of monkstone.core.LibraryProxy the other methods are
7+
# registered with PApplet instance in constructor ImplementingClass.new(app)
8+
#
9+
# def pre... NOOP can be overridden
10+
# def draw... Abstract Method should be implemented NOOP is OK
11+
# def post... NOOP can be overridden
12+
# def keyEvent(e)... NOOP can be overridden
13+
# def mouseEvent(e)... NOOP can be overridden
1214
# `app` can be called to get PApplet instance

pom.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
project 'rp5extras', 'https://github.com/ruby-processing/JRubyArt' do
33

44
model_version '4.0.0'
5-
id 'ruby-processing:rp5extras', '1.3.3'
5+
id 'ruby-processing:rp5extras', '1.4.0'
66
packaging 'jar'
77

88
description 'rp5extras for JRubyArt'

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ DO NOT MODIFIY - GENERATED CODE
1111
<modelVersion>4.0.0</modelVersion>
1212
<groupId>ruby-processing</groupId>
1313
<artifactId>rp5extras</artifactId>
14-
<version>1.3.3</version>
14+
<version>1.4.0</version>
1515
<name>rp5extras</name>
1616
<description>rp5extras for JRubyArt</description>
1717
<url>https://github.com/ruby-processing/JRubyArt</url>
@@ -56,7 +56,7 @@ DO NOT MODIFIY - GENERATED CODE
5656
<dependency>
5757
<groupId>org.processing</groupId>
5858
<artifactId>core</artifactId>
59-
<version>3.3.4</version>
59+
<version>3.3.5</version>
6060
</dependency>
6161
<dependency>
6262
<groupId>org.processing</groupId>

src/monkstone/core/LibraryProxy.java

Lines changed: 109 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -2,106 +2,124 @@
22

33
import processing.core.PApplet;
44
import static processing.core.PConstants.*;
5+
import processing.event.MouseEvent;
6+
import processing.event.KeyEvent;
57

68
/**
7-
* The purpose of this class is to enable
8-
* access to processing pre, draw and post loops in
9-
* ruby-processing as a regular java library class.
10-
* Also included background, fill and stroke methods.
11-
* PConstants should also be available from static import
12-
* @author Martin Prout
13-
*/
9+
* The purpose of this class is to enable
10+
* access to processing pre, draw and post loops in
11+
* ruby-processing as a regular java library class.
12+
* Also included background, fill and stroke methods.
13+
* PConstants should also be available from static import
14+
* @author Martin Prout
15+
*/
1416
public abstract class LibraryProxy {
1517

16-
private final PApplet app;
17-
18-
/**
19-
* Useful accessors
20-
*/
21-
public int width, height;
22-
23-
/**
24-
*
25-
* @param app PApplet
26-
*/
27-
public LibraryProxy(PApplet app) {
28-
this.app = app;
29-
this.width = app.width;
30-
this.height = app.height;
31-
setActive(true);
32-
}
18+
private final PApplet app;
3319

34-
/**
35-
* Extending classes must implement this gives access to, by reflection,
36-
* processing PApplet pre loop (called before draw)
37-
*/
38-
public abstract void pre();
39-
40-
/**
41-
* Extending classes must implement this gives access to processing PApplet
42-
* draw loop
43-
*/
44-
public abstract void draw();
45-
46-
/**
47-
* Extending classes must implement this gives access to, by reflection,
48-
* processing PApplet post loop (called after draw)
49-
*/
50-
public abstract void post();
51-
52-
/**
53-
* Register or unregister reflection methods
54-
* @param active
55-
*/
56-
final void setActive(boolean active) {
57-
if (active) {
58-
this.app.registerMethod("pre", this);
59-
this.app.registerMethod("draw", this);
60-
this.app.registerMethod("post", this);
61-
this.app.registerMethod("dispose", this);
62-
} else {
63-
this.app.unregisterMethod("pre", this);
64-
this.app.unregisterMethod("draw", this);
65-
this.app.unregisterMethod("post", this);
66-
}
67-
}
20+
/**
21+
* Useful accessors
22+
*/
23+
public int width, height;
6824

69-
/**
70-
* Simple signature for background hides need to call app
71-
* @param col int
72-
*/
73-
public void background(int col) {
74-
this.app.background(col);
75-
}
25+
/**
26+
*
27+
* @param app PApplet
28+
*/
29+
public LibraryProxy(PApplet app) {
30+
this.app = app;
31+
this.width = app.width;
32+
this.height = app.height;
33+
setActive(true);
34+
}
7635

77-
/**
78-
* Simple signature for fill hides need to call app
79-
* @param col int
80-
*/
81-
public void fill(int col) {
82-
this.app.fill(col);
83-
}
36+
/**
37+
* Extending classes can override this, gives access to, by reflection,
38+
* processing PApplet pre loop (called before draw)
39+
*/
40+
public void pre(){}
8441

85-
/**
86-
* Simple signature for stroke hides need to call app
87-
* @param col int
88-
*/
89-
public void stroke(int col) {
90-
this.app.stroke(col);
91-
}
42+
/**
43+
* Extending classes must implement this gives access to processing PApplet
44+
* draw loop
45+
*/
46+
public abstract void draw();
9247

93-
/**
94-
* Access applet if we must
95-
* @return applet PApplet
96-
*/
97-
public PApplet app() {
98-
return this.app;
99-
}
48+
/**
49+
* Extending classes can override this, gives access to, by reflection,
50+
* processing PApplet post loop (called after draw)
51+
*/
52+
public void post(){}
53+
54+
/**
55+
* Extending classes can override this, gives access to, by reflection,
56+
* processing PApplet post loop (called after draw)
57+
*/
58+
public void keyEvent(KeyEvent e){}
10059

101-
/**
102-
* required for processing
103-
*/
104-
public void dispose() {
105-
setActive(false);
60+
/**
61+
* Extending classes can override this, gives access to, by reflection,
62+
* processing PApplet post loop (called after draw)
63+
*/
64+
public void mouseEvent(MouseEvent e){}
65+
66+
/**
67+
* Register or unregister reflection methods
68+
* @param active
69+
*/
70+
final void setActive(boolean active) {
71+
if (active) {
72+
this.app.registerMethod("pre", this);
73+
this.app.registerMethod("draw", this);
74+
this.app.registerMethod("post", this);
75+
this.app.registerMethod("mouseEvent", this);
76+
this.app.registerMethod("keyEvent", this);
77+
this.app.registerMethod("dispose", this);
78+
} else {
79+
this.app.unregisterMethod("pre", this);
80+
this.app.unregisterMethod("draw", this);
81+
this.app.unregisterMethod("post", this);
82+
this.app.unregisterMethod("mouseEvent", this);
83+
this.app.unregisterMethod("keyEvent", this);
10684
}
85+
}
86+
87+
/**
88+
* Simple signature for background hides need to call app
89+
* @param col int
90+
*/
91+
public void background(int col) {
92+
this.app.background(col);
93+
}
94+
95+
/**
96+
* Simple signature for fill hides need to call app
97+
* @param col int
98+
*/
99+
public void fill(int col) {
100+
this.app.fill(col);
101+
}
102+
103+
/**
104+
* Simple signature for stroke hides need to call app
105+
* @param col int
106+
*/
107+
public void stroke(int col) {
108+
this.app.stroke(col);
109+
}
110+
111+
/**
112+
* Access applet if we must
113+
* @return applet PApplet
114+
*/
115+
public PApplet app() {
116+
return this.app;
117+
}
118+
119+
/**
120+
* required for processing
121+
*/
122+
public void dispose() {
123+
setActive(false);
124+
}
107125
}

vendors/Rakefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ EOS
1111

1212
JRUBYC_VERSION = '9.1.12.0'
1313

14-
EXAMPLES = '2.3'
14+
EXAMPLES = '2.4'
1515
HOME_DIR = ENV['HOME']
1616
MAC_OR_LINUX = /linux|mac|darwin/ =~ RbConfig::CONFIG['host_os']
1717

0 commit comments

Comments
 (0)