Skip to content

Commit b08fc6e

Browse files
committed
Now no need for local import of KeyEvent / MouseEvent
1 parent 4baf7b3 commit b08fc6e

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

processing_app/library/library_proxy/key_event.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# A simple demonstration of vanilla processing 'reflection' methods using
2-
# JRubyArt :library_proxy.
2+
# JRubyArt :library_proxy.
33
# See library/my_library/my_library.rb code for the guts.
44
load_libraries :library_proxy, :my_library
55

@@ -15,7 +15,7 @@ def setup
1515
MyLibrary.new self
1616
end
1717

18-
def hide(val)
18+
def hide(val) # we call this method from my_library
1919
@visible = !val
2020
end
2121

processing_app/library/library_proxy/library/my_library/my_library.rb

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
# we can access 'keyEvent' and 'draw' (Note we need a draw method even
33
# though can be empty)
44
class MyLibrary < LibraryProxy
5-
java_import 'processing.event.KeyEvent'
65

76
attr_reader :app
87

@@ -11,15 +10,15 @@ def initialize(parent)
1110
end
1211

1312
def draw # optional
14-
fill app.color(200, 0, 0, 100)
13+
fill app.color(200, 0, 0, 100) # partially transparent
1514
app.rect 100, 100, 60, 90
1615
end
1716

1817
# favor guard clause no_op unless key pressed
19-
# and no_op unless ascii key
18+
# and no_op unless ascii key else we can't use :chr
2019
def keyEvent(e) # NB: need camel case for reflection to work
2120
return unless e.get_action == KeyEvent::PRESS
22-
return if e.get_key > 122 # else we can't use :chr
21+
return if e.get_key >= 'z'.ord
2322
case e.get_key.chr.upcase
2423
when 'S'
2524
app.send :hide, false

0 commit comments

Comments
 (0)