PageRenderTime 33ms CodeModel.GetById 14ms app.highlight 14ms RepoModel.GetById 1ms app.codeStats 1ms

/src/gosu/jruby/SampleInstanceProxy.java

http://jgosu.googlecode.com/
Java | 76 lines | 53 code | 23 blank | 0 comment | 0 complexity | 919af0ab9fa04b469d282f9e3d6f1643 MD5 | raw file
 1import gosu.SampleInstance;
 2
 3import org.jruby.*;
 4import org.jruby.runtime.*;
 5import org.jruby.runtime.builtin.IRubyObject;
 6import org.jruby.anno.JRubyMethod;
 7import static org.jruby.RubyNumeric.*;
 8
 9
10public class SampleInstanceProxy extends RubyObject {
11  private static ObjectAllocator ALLOCATOR = new ObjectAllocator() {
12    public IRubyObject allocate(Ruby runtime, RubyClass klass) {
13      return new SampleInstanceProxy(runtime, klass);
14    }
15  };
16
17  private SampleInstance _sampleInstance;
18
19  private final Ruby _runtime;
20
21  public static void createSampleInstanceClass(Ruby runtime) {
22    RubyModule mGosu = runtime.getModule("Gosu");
23    RubyClass cSampleInstance = mGosu.defineClassUnder("SampleInstance", runtime.getObject(), ALLOCATOR);
24
25    cSampleInstance.defineAnnotatedMethods(SampleInstanceProxy.class);
26  }
27
28
29  public SampleInstanceProxy(Ruby runtime, RubyClass type) {
30    super(runtime, type);
31    _runtime = runtime;
32  }
33
34
35  public SampleInstance getSampleInstance() { return _sampleInstance; }
36
37
38  public void setSampleInstance(SampleInstance si) { _sampleInstance = si; }
39
40
41  @JRubyMethod(name = "playing?")
42  public IRubyObject isPlaying() {
43    return _runtime.newBoolean(_sampleInstance.isPlaying());
44  }
45
46
47  @JRubyMethod(name = "stop")
48  public IRubyObject stop() {
49    _sampleInstance.stop();
50    return _runtime.getNil();
51  }
52               
53
54  @JRubyMethod(name = "volume=",
55               required = 1)
56  public IRubyObject setVolume(IRubyObject vol) {
57    _sampleInstance.setVolume((float) num2dbl(vol));
58    return vol;
59  }
60
61
62  @JRubyMethod(name = "pan=",
63               required = 1)
64  public IRubyObject setPan(IRubyObject pan) {
65    _sampleInstance.setPan((float) num2dbl(pan));
66    return pan;
67  }
68
69
70  @JRubyMethod(name = "speed=",
71               required = 1)
72  public IRubyObject setSpeed(IRubyObject speed) {
73    _sampleInstance.setSpeed((float) num2dbl(speed));
74    return speed;
75  }
76}