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(); }
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(); }
void drawInteriorWithFrame_inView( long /*int*/ id, long /*int*/ sel, NSRect cellRect, long /*int*/ view) { /* * Feature in Cocoa. When the last column in a tree does not reach the * rightmost edge of the tree view, the cell that draws the rightmost- * column's header is also invoked to draw the header space between its * right edge and the tree's right edge. If this case is detected then * nothing should be drawn. */ int columnIndex = parent.indexOf(nsColumn); NSRect headerRect = parent.headerView.headerRectOfColumn(columnIndex); if (headerRect.x != cellRect.x || headerRect.width != cellRect.width) return; NSGraphicsContext context = NSGraphicsContext.currentContext(); context.saveGraphicsState(); int contentWidth = 0; NSSize stringSize = null, imageSize = null; NSAttributedString attrString = null; NSTableHeaderCell headerCell = nsColumn.headerCell(); if (displayText != null) { Font font = Font.cocoa_new(display, headerCell.font()); attrString = parent.createString( displayText, font, null, SWT.LEFT, false, (parent.state & DISABLED) == 0, false); stringSize = attrString.size(); contentWidth += Math.ceil(stringSize.width); if (image != null) contentWidth += MARGIN; /* space between image and text */ } if (image != null) { imageSize = image.handle.size(); contentWidth += Math.ceil(imageSize.width); } if (parent.sortColumn == this && parent.sortDirection != SWT.NONE) { boolean ascending = parent.sortDirection == SWT.UP; headerCell.drawSortIndicatorWithFrame(cellRect, new NSView(view), ascending, 0); /* remove the arrow's space from the available drawing width */ NSRect sortRect = headerCell.sortIndicatorRectForBounds(cellRect); cellRect.width = Math.max(0, sortRect.x - cellRect.x); } int drawX = 0; if ((style & SWT.CENTER) != 0) { drawX = (int) (cellRect.x + Math.max(MARGIN, ((cellRect.width - contentWidth) / 2))); } else if ((style & SWT.RIGHT) != 0) { drawX = (int) (cellRect.x + Math.max(MARGIN, cellRect.width - contentWidth - MARGIN)); } else { drawX = (int) cellRect.x + MARGIN; } if (image != null) { NSRect destRect = new NSRect(); destRect.x = drawX; destRect.y = cellRect.y; destRect.width = Math.min(imageSize.width, cellRect.width - 2 * MARGIN); destRect.height = Math.min(imageSize.height, cellRect.height); boolean isFlipped = new NSView(view).isFlipped(); if (isFlipped) { context.saveGraphicsState(); NSAffineTransform transform = NSAffineTransform.transform(); transform.scaleXBy(1, -1); transform.translateXBy(0, -(destRect.height + 2 * destRect.y)); transform.concat(); } NSRect sourceRect = new NSRect(); sourceRect.width = destRect.width; sourceRect.height = destRect.height; image.handle.drawInRect(destRect, sourceRect, OS.NSCompositeSourceOver, 1f); if (isFlipped) context.restoreGraphicsState(); drawX += destRect.width; } if (displayText != null && displayText.length() > 0) { if (image != null) drawX += MARGIN; /* space between image and text */ NSRect destRect = new NSRect(); destRect.x = drawX; destRect.y = cellRect.y; destRect.width = Math.min(stringSize.width, cellRect.x + cellRect.width - MARGIN - drawX); destRect.height = Math.min(stringSize.height, cellRect.height); attrString.drawInRect(destRect); } if (attrString != null) attrString.release(); context.restoreGraphicsState(); }