Esempio 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();
  }
Esempio n. 2
0
 void mouse(NSEvent nsEvent) {
   NSPoint location;
   if (nsEvent == null || nsEvent.type() == OS.NSMouseMoved) {
     location = NSEvent.mouseLocation();
   } else {
     location = nsEvent.locationInWindow();
     location = nsEvent.window().convertBaseToScreen(location);
   }
   location.y = display.getPrimaryFrame().height - location.y;
   int newX = (int) location.x, newY = (int) location.y;
   if (newX != oldX || newY != oldY) {
     Rectangle[] oldRectangles = rectangles;
     Rectangle[] rectsToErase = new Rectangle[rectangles.length];
     for (int i = 0; i < rectangles.length; i++) {
       Rectangle current = rectangles[i];
       rectsToErase[i] = new Rectangle(current.x, current.y, current.width, current.height);
     }
     Event event = new Event();
     event.x = newX;
     event.y = newY;
     if ((style & SWT.RESIZE) != 0) {
       boolean orientationInit = resizeRectangles(newX - oldX, newY - oldY);
       inEvent = true;
       sendEvent(SWT.Resize, event);
       inEvent = false;
       /*
        * It is possible (but unlikely), that application
        * code could have disposed the widget in the move
        * event.  If this happens, return false to indicate
        * that the tracking has failed.
        */
       if (isDisposed()) {
         cancelled = true;
         return;
       }
       boolean draw = false;
       /*
        * It is possible that application code could have
        * changed the rectangles in the resize event.  If this
        * happens then only redraw the tracker if the rectangle
        * values have changed.
        */
       if (rectangles != oldRectangles) {
         int length = rectangles.length;
         if (length != rectsToErase.length) {
           draw = true;
         } else {
           for (int i = 0; i < length; i++) {
             if (!rectangles[i].equals(rectsToErase[i])) {
               draw = true;
               break;
             }
           }
         }
       } else {
         draw = true;
       }
       if (draw) {
         drawRectangles(window, rectsToErase, true);
         drawRectangles(window, rectangles, false);
       }
       Point cursorPos = adjustResizeCursor(orientationInit);
       if (cursorPos != null) {
         newX = cursorPos.x;
         newY = cursorPos.y;
       }
     } else {
       moveRectangles(newX - oldX, newY - oldY);
       inEvent = true;
       sendEvent(SWT.Move, event);
       inEvent = false;
       /*
        * It is possible (but unlikely), that application
        * code could have disposed the widget in the move
        * event.  If this happens, return false to indicate
        * that the tracking has failed.
        */
       if (isDisposed()) {
         cancelled = true;
         return;
       }
       boolean draw = false;
       /*
        * It is possible that application code could have
        * changed the rectangles in the move event.  If this
        * happens then only redraw the tracker if the rectangle
        * values have changed.
        */
       if (rectangles != oldRectangles) {
         int length = rectangles.length;
         if (length != rectsToErase.length) {
           draw = true;
         } else {
           for (int i = 0; i < length; i++) {
             if (!rectangles[i].equals(rectsToErase[i])) {
               draw = true;
               break;
             }
           }
         }
       } else {
         draw = true;
       }
       if (draw) {
         drawRectangles(window, rectsToErase, true);
         drawRectangles(window, rectangles, false);
       }
     }
     oldX = newX;
     oldY = newY;
   }
   switch ((int) /*64*/ nsEvent.type()) {
     case OS.NSLeftMouseUp:
     case OS.NSRightMouseUp:
     case OS.NSOtherMouseUp:
       tracking = false;
   }
 }