Ejemplo n.º 1
0
  void drawRectangles(NSWindow window, Rectangle[] rects, boolean erase) {
    NSGraphicsContext context = window.graphicsContext();
    NSGraphicsContext.static_saveGraphicsState();
    NSGraphicsContext.setCurrentContext(context);
    context.saveGraphicsState();
    Point parentOrigin;
    if (parent != null) {
      parentOrigin = display.map(parent, null, 0, 0);
    } else {
      parentOrigin = new Point(0, 0);
    }
    context.setCompositingOperation(erase ? OS.NSCompositeClear : OS.NSCompositeSourceOver);
    NSRect rectFrame = new NSRect();
    NSPoint globalPoint = new NSPoint();
    double /*float*/ screenHeight = display.getPrimaryFrame().height;
    for (int i = 0; i < rects.length; i++) {
      Rectangle rect = rects[i];
      rectFrame.x = rect.x + parentOrigin.x;
      rectFrame.y = screenHeight - (int) ((rect.y + parentOrigin.y) + rect.height);
      rectFrame.width = rect.width;
      rectFrame.height = rect.height;
      globalPoint.x = rectFrame.x;
      globalPoint.y = rectFrame.y;
      globalPoint = window.convertScreenToBase(globalPoint);
      rectFrame.x = globalPoint.x;
      rectFrame.y = globalPoint.y;

      if (erase) {
        rectFrame.width++;
        rectFrame.height++;
        NSBezierPath.fillRect(rectFrame);
      } else {
        rectFrame.x += 0.5f;
        rectFrame.y += 0.5f;
        NSBezierPath.strokeRect(rectFrame);
      }
    }
    if (!erase) context.flushGraphics();
    context.restoreGraphicsState();
    NSGraphicsContext.static_restoreGraphicsState();
  }