/src/gosu/jruby/SampleInstanceProxy.java
http://jgosu.googlecode.com/ · Java · 76 lines · 53 code · 23 blank · 0 comment · 0 complexity · 919af0ab9fa04b469d282f9e3d6f1643 MD5 · raw file
- import gosu.SampleInstance;
- import org.jruby.*;
- import org.jruby.runtime.*;
- import org.jruby.runtime.builtin.IRubyObject;
- import org.jruby.anno.JRubyMethod;
- import static org.jruby.RubyNumeric.*;
- public class SampleInstanceProxy extends RubyObject {
- private static ObjectAllocator ALLOCATOR = new ObjectAllocator() {
- public IRubyObject allocate(Ruby runtime, RubyClass klass) {
- return new SampleInstanceProxy(runtime, klass);
- }
- };
- private SampleInstance _sampleInstance;
- private final Ruby _runtime;
- public static void createSampleInstanceClass(Ruby runtime) {
- RubyModule mGosu = runtime.getModule("Gosu");
- RubyClass cSampleInstance = mGosu.defineClassUnder("SampleInstance", runtime.getObject(), ALLOCATOR);
- cSampleInstance.defineAnnotatedMethods(SampleInstanceProxy.class);
- }
- public SampleInstanceProxy(Ruby runtime, RubyClass type) {
- super(runtime, type);
- _runtime = runtime;
- }
- public SampleInstance getSampleInstance() { return _sampleInstance; }
- public void setSampleInstance(SampleInstance si) { _sampleInstance = si; }
- @JRubyMethod(name = "playing?")
- public IRubyObject isPlaying() {
- return _runtime.newBoolean(_sampleInstance.isPlaying());
- }
- @JRubyMethod(name = "stop")
- public IRubyObject stop() {
- _sampleInstance.stop();
- return _runtime.getNil();
- }
-
- @JRubyMethod(name = "volume=",
- required = 1)
- public IRubyObject setVolume(IRubyObject vol) {
- _sampleInstance.setVolume((float) num2dbl(vol));
- return vol;
- }
- @JRubyMethod(name = "pan=",
- required = 1)
- public IRubyObject setPan(IRubyObject pan) {
- _sampleInstance.setPan((float) num2dbl(pan));
- return pan;
- }
- @JRubyMethod(name = "speed=",
- required = 1)
- public IRubyObject setSpeed(IRubyObject speed) {
- _sampleInstance.setSpeed((float) num2dbl(speed));
- return speed;
- }
- }