propane 2.3.4-java → 2.4.0-java

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 40e07b8b28c5857b0f1738ddf80584a6c5f62764
4
- data.tar.gz: 67dc8538463955bd26073f52dad1d0bb74a706c3
3
+ metadata.gz: 2e995a9147ca9cfe877f299d8f2433eb9cf9fd16
4
+ data.tar.gz: a9056a9bbfbc5d20dd55356af0c3dc7ca02633a5
5
5
  SHA512:
6
- metadata.gz: 01683ec9729539dd4a279e19b8661f9b446968bcfece74c796c98d988cd177b41a03396fd11dccf8ce8c75dfced4bdc13e92f2ca7a4abf1a8b989bdb5c56e007
7
- data.tar.gz: bb8318aa7cbd0d5296027230db8eebc91a9cf1c03f2cdd9cd52e5411a8ba7be274e4bbcf5e0cc9ab23853db8888729d5ab8dda05093cff2362de58635f7fb561
6
+ metadata.gz: 0905fd0592209ce449d1e3f8973822a426461648d84a56996289ab75e94e8d4b788dddf7dff2725ec1dec999f46fd4c3cace0e7bfc1caff6fd1d5c583c42fe2a
7
+ data.tar.gz: a87e497ed4e336bdd07ae29a2a118453c07c8a143ef36983e2717a3ce5aa71d5537c7ba25f1e05dc0c3f05d3625fa439561922ea2fe43273a5c709658de8e593
@@ -1,5 +1,6 @@
1
1
  language: ruby
2
2
  sudo: false
3
+ dist: trusty
3
4
 
4
5
  rvm:
5
6
  - jruby-9.1.12.0
@@ -1,3 +1,5 @@
1
+ **v2.4.0** Extend LibraryProxy to include mouseEvent and keyEvent.
2
+
1
3
  **v2.3.4** Simplify control_panel library (replacing `c.title = 'PaneTitle'` with `c.title('PaneTitle')`) also enable use of `block` with `button's`.
2
4
 
3
5
  **v2.3.3** Update to processing-3.3.4, and upgrade jruby-9.1.12.0 last in 9.1 series?
@@ -1,4 +1,5 @@
1
- #frozen_string_literal: false
1
+ # frozen_string_literal: false
2
+
2
3
  # the sketch class
3
4
  class SketchClass
4
5
  attr_reader :name, :width, :height, :mode
@@ -24,7 +25,7 @@ class SketchClass
24
25
  end
25
26
 
26
27
  def size
27
- return format(' size %d, %d', width.to_i, height.to_i) if mode.nil?
28
+ return format(' size %d, %d', width.to_i, height.to_i) unless mode
28
29
  format(' size %d, %d, %s', width.to_i, height.to_i, mode.upcase)
29
30
  end
30
31
 
@@ -33,8 +34,8 @@ class SketchClass
33
34
  format(" sketch_title '%s'", human)
34
35
  end
35
36
 
36
- def method_lines(name, content = '')
37
- return [format(' def %s', name), content, ' end'] if content.empty?
37
+ def method_lines(name, content = nil)
38
+ return [format(' def %s', name), '', ' end'] unless content
38
39
  [format(' def %s', name), content, ' end', '']
39
40
  end
40
41
 
@@ -50,6 +51,7 @@ class SketchClass
50
51
  lines.concat method_lines('setup', sketch_title)
51
52
  lines.concat method_lines('draw')
52
53
  lines << 'end'
54
+ lines << ''
53
55
  lines << sketch_new
54
56
  end
55
57
  end
@@ -50,6 +50,11 @@ module Propane
50
50
  options[:create] = true
51
51
  end
52
52
 
53
+ options[:example] = false
54
+ opts.on('-e', '--example', 'Create new sketch outline') do
55
+ options[:example] = true
56
+ end
57
+
53
58
  # This displays the help screen, all programs are
54
59
  # assumed to have this option.
55
60
  opts.on('-h', '--help', 'Display this screen') do
@@ -63,6 +68,11 @@ module Propane
63
68
 
64
69
  def create
65
70
  require_relative 'creators/sketch_writer'
71
+ SketchFactory.new(argc).write
72
+ end
73
+
74
+ def examples
75
+ require_relative 'creators/sketch_factory'
66
76
  SketchWriter.new(File.basename(filename, '.rb'), argc).write
67
77
  end
68
78
 
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Propane
3
- VERSION = '2.3.4'.freeze
3
+ VERSION = '2.4.0'.freeze
4
4
  end
@@ -1,8 +1,8 @@
1
1
  ### Using the LibraryProxy in your sketches
2
2
  LibraryProxy is a [abstract java class](https://github.com/ruby-processing/JRubyArt/blob/master/src/monkstone/core/LibraryProxy.java) so that you can acccess vanilla processing library reflection methods in your sketches using ruby.
3
3
 
4
- In the sketch you should `load_library :library_proxy` and your library class should inherit
5
- from LibraryProxy and implement pre(), draw() and post() methods (can be empty method if not
4
+ In the sketch you should `load_library :library_proxy` and your library class should inherit
5
+ from LibraryProxy and implement the draw() method (can be empty method if not
6
6
  required). For simplicity initialize your `processing library` in the sketch `setup`.
7
7
 
8
8
  ### Example library
@@ -1,12 +1,14 @@
1
1
  java_import Java::MonkstoneCore::LibraryProxy
2
+ java_import Java::ProcessingEvent::KeyEvent
3
+ java_import Java::ProcessingEvent::MouseEvent
2
4
 
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
12
14
  # `app` can be called to get PApplet instance
data/pom.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  require 'fileutils'
2
2
  project 'rp5extras', 'https://github.com/monkstone/propane' do
3
3
  model_version '4.0.0'
4
- id 'propane:propane', '2.3.4'
4
+ id 'propane:propane', '2.4.0'
5
5
  packaging 'jar'
6
6
  description 'rp5extras for propane'
7
7
  organization 'ruby-processing', 'https://ruby-processing.github.io'
data/pom.xml CHANGED
@@ -11,7 +11,7 @@ DO NOT MODIFIY - GENERATED CODE
11
11
  <modelVersion>4.0.0</modelVersion>
12
12
  <groupId>propane</groupId>
13
13
  <artifactId>propane</artifactId>
14
- <version>2.3.4</version>
14
+ <version>2.4.0</version>
15
15
  <name>rp5extras</name>
16
16
  <description>rp5extras for propane</description>
17
17
  <url>https://github.com/monkstone/propane</url>
@@ -2,106 +2,124 @@ package monkstone.core;
2
2
 
3
3
  import processing.core.PApplet;
4
4
  import static processing.core.PConstants.*;
5
+ import processing.event.MouseEvent;
6
+ import processing.event.KeyEvent;
5
7
 
6
8
  /**
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
+ */
14
16
  public abstract class LibraryProxy {
15
17
 
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;
33
19
 
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;
68
24
 
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
+ }
76
35
 
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(){}
84
41
 
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();
92
47
 
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){}
100
59
 
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);
106
84
  }
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
+ }
107
125
  }
@@ -0,0 +1,37 @@
1
+ #!/usr/bin/env jruby
2
+ require 'propane'
3
+
4
+
5
+ class CustomProxySketch < Propane::App
6
+
7
+ # A simple demonstration of vanilla processing 'reflection' methods using
8
+ # propane :library_proxy. See my_library.rb code for the guts.
9
+ load_libraries :library_proxy, :my_library
10
+
11
+ attr_reader :visible
12
+
13
+ def settings
14
+ size 300, 200
15
+ @visible = false
16
+ end
17
+
18
+ def setup
19
+ sketch_title 'Reflection Voodoo Proxy'
20
+ MyLibrary.new self
21
+ end
22
+
23
+ def hide(val)
24
+ @visible = !val
25
+ end
26
+
27
+ def draw
28
+ if visible
29
+ fill(0, 0, 200)
30
+ ellipse(170, 115, 70, 100)
31
+ else
32
+ background 0
33
+ end
34
+ end
35
+ end
36
+
37
+ CustomProxySketch.new
@@ -0,0 +1,32 @@
1
+ # This class demonstrates how by inheriting from the abstract class LibraryProxy
2
+ # we can access 'keyEvent' and 'draw' (Note we need a draw method even
3
+ # though can be empty)
4
+ class MyLibrary < LibraryProxy
5
+ java_import 'processing.event.KeyEvent'
6
+
7
+ attr_reader :app
8
+
9
+ def initialize(parent)
10
+ @app = parent
11
+ end
12
+
13
+ def draw # optional
14
+ fill app.color(200, 0, 0, 100)
15
+ app.rect 100, 100, 60, 90
16
+ end
17
+
18
+ # favor guard clause no_op unless key pressed
19
+ # and no_op unless ascii key
20
+ def keyEvent(e) # NB: need camel case for reflection to work
21
+ return unless e.get_action == KeyEvent::PRESS
22
+ return if e.get_key > 122 # else we can't use :chr
23
+ case e.get_key.chr.upcase
24
+ when 'S'
25
+ app.send :hide, false
26
+ when 'H'
27
+ app.send :hide, true
28
+ else
29
+ puts e.get_key.chr
30
+ end
31
+ end
32
+ end
@@ -9,7 +9,7 @@ SOUND = 'sound.zip'.freeze
9
9
  SOUND_VERSION = 'v1.3.2' # version 1.3.2
10
10
  VIDEO = 'video-2.zip'
11
11
  VIDEO_VERSION = '2' # version 1.0.1
12
- EXAMPLES = '1.3'.freeze
12
+ EXAMPLES = '1.4'.freeze
13
13
  HOME_DIR = ENV['HOME']
14
14
  MAC_OR_LINUX = /linux|mac|darwin/ =~ RbConfig::CONFIG['host_os']
15
15
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: propane
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.4
4
+ version: 2.4.0
5
5
  platform: java
6
6
  authors:
7
7
  - monkstone
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-07-19 00:00:00.000000000 Z
11
+ date: 2017-08-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -141,6 +141,8 @@ files:
141
141
  - test/helper_methods_test.rb
142
142
  - test/math_tool_test.rb
143
143
  - test/respond_to_test.rb
144
+ - test/sketches/key_event.rb
145
+ - test/sketches/library/my_library/my_library.rb
144
146
  - test/test_helper.rb
145
147
  - test/vecmath_spec_test.rb
146
148
  - vendors/Rakefile
@@ -175,5 +177,7 @@ test_files:
175
177
  - test/helper_methods_test.rb
176
178
  - test/math_tool_test.rb
177
179
  - test/respond_to_test.rb
180
+ - test/sketches/key_event.rb
181
+ - test/sketches/library/my_library/my_library.rb
178
182
  - test/test_helper.rb
179
183
  - test/vecmath_spec_test.rb