/src/gosu/DrawOp.java

http://jgosu.googlecode.com/ · Java · 41 lines · 27 code · 10 blank · 4 comment · 1 complexity · 02ee95618c987c252981f1b142ac94d8 MD5 · raw file

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