Пример #1
0
 void drawRectangles(NSWindow window, Rectangle[] rects, boolean erase) {
   NSRect frame = window.frame();
   NSGraphicsContext context = window.graphicsContext();
   NSGraphicsContext.setCurrentContext(context);
   NSAffineTransform transform = NSAffineTransform.transform();
   context.saveGraphicsState();
   transform.scaleXBy(1, -1);
   transform.translateXBy(0, -frame.height);
   transform.concat();
   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);
   for (int i = 0; i < rects.length; i++) {
     Rectangle rect = rects[i];
     frame.x = rect.x + parentOrigin.x;
     frame.y = rect.y + parentOrigin.y;
     frame.width = rect.width;
     frame.height = rect.height;
     if (erase) {
       frame.width++;
       frame.height++;
       NSBezierPath.fillRect(frame);
     } else {
       frame.x += 0.5f;
       frame.y += 0.5f;
       NSBezierPath.strokeRect(frame);
     }
   }
   context.flushGraphics();
   context.restoreGraphicsState();
 }
Пример #2
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();
  }