PageRenderTime 19ms CodeModel.GetById 12ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/src/gosu/DrawOp.java

http://jgosu.googlecode.com/
Java | 41 lines | 27 code | 10 blank | 4 comment | 1 complexity | 02ee95618c987c252981f1b142ac94d8 MD5 | raw file
 1package gosu;
 2
 3public abstract class DrawOp implements Comparable {
 4  // Gosu assumes that the drawOps will be ordered by the
 5  // z value first and secondly by the drawing order.
 6  // Since Java's PriorityQueue throws insertion order to the
 7  // wind, I have this counter hack to keep track of it.
 8  private static long counter = 0;
 9
10  protected int _clipX;
11  protected int _clipY;
12  protected int _clipWidth;
13  protected int _clipHeight;
14  private boolean _clipped;
15
16  private long _id;
17
18  public DrawOp() {
19    _id = counter++;
20  }
21
22  public abstract double getZ();
23  public abstract void execute();
24  
25  public int compareTo(Object o) {
26    int result = Double.valueOf(getZ()).compareTo(((DrawOp) o).getZ());
27    return (result != 0) ? result : Long.valueOf(_id).compareTo(((DrawOp) o)._id);
28  }
29
30
31  void clip(int x, int y, int width, int height) {
32    _clipped = true;
33    _clipX = x;
34    _clipY = y;
35    _clipWidth = width;
36    _clipHeight = height;
37  }
38
39
40  boolean isClipped() { return _clipped; }
41}