/** @param e */ protected void drawTitleBackground(PaintEvent e) { Rectangle bounds = getClientArea(); Point tsize = null; Point labelSize = null; int twidth = bounds.width - marginWidth - marginWidth; if (label != null) { labelSize = label.computeSize(SWT.DEFAULT, SWT.DEFAULT, true); } if (labelSize != null) { twidth -= labelSize.x + 4; } int tvmargin = 4; int theight = getHeight(); if (tsize != null) { theight += Math.max(theight, tsize.y); } if (labelSize != null) { theight = Math.max(theight, labelSize.y); } theight += tvmargin + tvmargin; int midpoint = (theight * 66) / 100; int rem = theight - midpoint; GC gc = e.gc; gc.setForeground(bg); gc.setBackground(gbg); gc.fillGradientRectangle( marginWidth, marginHeight, bounds.width - 1 - marginWidth - marginWidth, midpoint - 1, true); gc.setForeground(gbg); gc.setBackground(getBackground()); gc.fillGradientRectangle( marginWidth, marginHeight + midpoint - 1, bounds.width - 1 - marginWidth - marginWidth, rem - 1, true); gc.setForeground(border); gc.drawLine(marginWidth, marginHeight + 2, marginWidth, marginHeight + theight - 1); gc.drawLine(marginWidth, marginHeight + 2, marginWidth + 2, marginHeight); gc.drawLine(marginWidth + 2, marginHeight, bounds.width - marginWidth - 3, marginHeight); gc.drawLine( bounds.width - marginWidth - 3, marginHeight, bounds.width - marginWidth - 1, marginHeight + 2); gc.drawLine( bounds.width - marginWidth - 1, marginHeight + 2, bounds.width - marginWidth - 1, marginHeight + theight - 1); }
void drawItem(GC gc, boolean drawFocus) { int headerHeight = parent.getBandHeight(); Display display = getDisplay(); gc.setForeground(display.getSystemColor(SWT.COLOR_TITLE_BACKGROUND)); gc.setBackground(display.getSystemColor(SWT.COLOR_TITLE_BACKGROUND_GRADIENT)); gc.fillGradientRectangle(x, y, width, headerHeight, true); if (expanded) { gc.setForeground(display.getSystemColor(SWT.COLOR_TITLE_BACKGROUND_GRADIENT)); gc.drawLine(x, y + headerHeight, x, y + headerHeight + height - 1); gc.drawLine(x, y + headerHeight + height - 1, x + width - 1, y + headerHeight + height - 1); gc.drawLine(x + width - 1, y + headerHeight + height - 1, x + width - 1, y + headerHeight); } int drawX = x; if (image != null) { drawX += ExpandItem.TEXT_INSET; if (imageHeight > headerHeight) { gc.drawImage(image, drawX, y + headerHeight - imageHeight); } else { gc.drawImage(image, drawX, y + (headerHeight - imageHeight) / 2); } drawX += imageWidth; } if (text.length() > 0) { drawX += ExpandItem.TEXT_INSET; Point size = gc.stringExtent(text); gc.setForeground(parent.getForeground()); gc.drawString(text, drawX, y + (headerHeight - size.y) / 2, true); } int chevronSize = ExpandItem.CHEVRON_SIZE; drawChevron(gc, x + width - chevronSize, y + (headerHeight - chevronSize) / 2); if (drawFocus) { gc.drawFocus(x + 1, y + 1, width - 2, headerHeight - 2); } }
void resize() { Point size = comp.getSize(); Image oldBackgroundImage = backgroundImage; backgroundImage = new Image(comp.getDisplay(), size.x, size.y); GC gc = new GC(backgroundImage); comp.getParent().drawBackground(gc, 0, 0, size.x, size.y, 0, 0); Color background = comp.getBackground(); Color border = comp.getDisplay().getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW); RGB backgroundRGB = background.getRGB(); // TODO naive and hard coded, doesn't deal with high contrast, etc. Color gradientTop = new Color( comp.getDisplay(), backgroundRGB.red + 12, backgroundRGB.green + 10, backgroundRGB.blue + 10); int h = size.y; int curveStart = 0; int curve_width = 5; int[] curve = new int[] { 0, h, 1, h, 2, h - 1, 3, h - 2, 3, 2, 4, 1, 5, 0, }; int[] line1 = new int[curve.length + 4]; int index = 0; int x = curveStart; line1[index++] = x + 1; line1[index++] = h; for (int i = 0; i < curve.length / 2; i++) { line1[index++] = x + curve[2 * i]; line1[index++] = curve[2 * i + 1]; } line1[index++] = x + curve_width; line1[index++] = 0; int[] line2 = new int[line1.length]; index = 0; for (int i = 0; i < line1.length / 2; i++) { line2[index] = line1[index++] - 1; line2[index] = line1[index++]; } // custom gradient gc.setForeground(gradientTop); gc.setBackground(background); gc.drawLine(4, 0, size.x, 0); gc.drawLine(3, 1, size.x, 1); gc.fillGradientRectangle(2, 2, size.x - 2, size.y - 3, true); gc.setForeground(background); gc.drawLine(2, size.y - 1, size.x, size.y - 1); gradientTop.dispose(); gc.setForeground(border); gc.drawPolyline(line2); gc.dispose(); comp.setBackgroundImage(backgroundImage); if (oldBackgroundImage != null) oldBackgroundImage.dispose(); }
@Override public void paintCell(ILayerCell cell, GC gc, Rectangle bounds, IConfigRegistry configRegistry) { Color foregroundColor = getForeGroundColour(cell, configRegistry); Color backgroundColor = getBackgroundColour(cell, configRegistry); if (backgroundColor != null && foregroundColor != null) { Color originalForeground = gc.getForeground(); Color originalBackground = gc.getBackground(); gc.setForeground(foregroundColor); gc.setBackground(backgroundColor); gc.fillGradientRectangle(bounds.x, bounds.y, bounds.width, bounds.height, vertical); gc.setForeground(originalForeground); gc.setBackground(originalBackground); } super.paintCell(cell, gc, bounds, configRegistry); }
/** @param e */ protected void drawTitleBackground(PaintEvent e) { Rectangle bounds = getClientArea(); // label.setBackground(new Color[] { // factory.getColors().getColor(IFormColors.H_GRADIENT_END), // factory.getColors().getColor(IFormColors.H_GRADIENT_START) }, // new int[] { 100 }, true); Color bg = factory.getColors().getColor(IFormColors.H_GRADIENT_END); Color gbg = factory.getColors().getColor(IFormColors.H_GRADIENT_START); GC gc = e.gc; gc.setForeground(bg); gc.setBackground(gbg); gc.fillGradientRectangle(bounds.x, bounds.y, bounds.width, bounds.height, true); // background bottom separator gc.setForeground(factory.getColors().getColor(IFormColors.H_BOTTOM_KEYLINE1)); gc.drawLine(bounds.x, bounds.height - 2, bounds.x + bounds.width - 1, bounds.height - 2); gc.setForeground(factory.getColors().getColor(IFormColors.H_BOTTOM_KEYLINE2)); gc.drawLine(bounds.x, bounds.height - 1, bounds.x + bounds.width - 1, bounds.height - 1); }
/** Draw the background (a gradient+a separator) */ private void drawBackground() { final Display display = this.getDisplay(); final Rectangle rect = this.getClientArea(); final Image newImage = new Image(display, Math.max(1, rect.width), Math.max(1, rect.height)); final GC gc = new GC(newImage); gc.setForeground(this.gradientStart); gc.setBackground(this.gradientEnd); gc.fillGradientRectangle(rect.x, rect.y, rect.width, rect.height, false); gc.setForeground(this.separatorColor); gc.drawLine(rect.x, rect.y + rect.height - 1, rect.x + rect.width, rect.y + rect.height - 1); gc.dispose(); this.setBackgroundImage(newImage); if (this.previousGeneratedImage != null) { this.previousGeneratedImage.dispose(); } this.previousGeneratedImage = newImage; }
/* (non-Javadoc) * @see org.eclipse.vtp.desktop.editors.themes.attraction.AttractionComponentFrame#renderFrame(org.eclipse.swt.graphics.GC, int, int, java.util.Map) */ public void renderFrame(GC gc, int renderingPhase, int options, Map<String, Object> resourceMap) { Font originalFont = gc.getFont(); Color foreground = gc.getForeground(); Color background = gc.getBackground(); Color selectedColor = getColor(gc, resourceMap, "attraction.selection.color", 0, 0, 255); Color elementBlue = getColor(gc, resourceMap, "attraction.element.color", 201, 229, 255); Color elementGradBlue = getColor(gc, resourceMap, "attraction.element.color.gradient", 153, 206, 255); Font nameFont = getFont(gc, resourceMap, "attraction.element.font", "Arial", 10, SWT.NORMAL); gc.setFont(nameFont); if (upperLeft == null) { initializeGraphics(gc, resourceMap); } int width = lowerRight.x - upperLeft.x; int height = lowerRight.y - upperLeft.y; gc.setBackground(elementBlue); gc.fillRoundRectangle(upperLeft.x, upperLeft.y, width - 1, height - 1, 12, 12); if ((options & Theme.RENDER_FLAG_PRINTING) == 0) { gc.setBackground(elementGradBlue); gc.fillRoundRectangle( upperLeft.x, upperLeft.y + ((lowerRight.y - upperLeft.y) / 2), lowerRight.x - upperLeft.x, ((lowerRight.y - upperLeft.y) / 2), 12, 12); gc.setForeground(elementBlue); gc.fillGradientRectangle( upperLeft.x, upperLeft.y + ((lowerRight.y - upperLeft.y) / 3), lowerRight.x - upperLeft.x, (((lowerRight.y - upperLeft.y) / 3) * 2) - 5, true); } gc.setForeground(foreground); gc.setBackground(background); // draw connector hot spot if (uiElement.hasConnectors()) { gc.drawLine(lowerRight.x - 17, lowerRight.y - 10, lowerRight.x - 3, lowerRight.y - 10); gc.drawLine(lowerRight.x - 8, lowerRight.y - 15, lowerRight.x - 3, lowerRight.y - 10); gc.drawLine(lowerRight.x - 8, lowerRight.y - 5, lowerRight.x - 3, lowerRight.y - 10); } if (selected && (options & Theme.RENDER_FLAG_NO_SELECTION) == 0) { gc.setForeground(selectedColor); } gc.drawRoundRectangle(upperLeft.x, upperLeft.y, width - 1, height - 1, 12, 12); if ((options & Theme.RENDER_FLAG_NO_ICONS) == 0) { gc.drawImage(icon, upperLeft.x + 10, upperLeft.y + 12); } int curX = upperLeft.x + 30; int curY = upperLeft.y + 15; String[] parts = this.getDesignElement().getName().split(" "); Point stringExtent = gc.stringExtent(parts[0]); int ew = stringExtent.x; gc.drawString(parts[0], curX, curY, true); curX += stringExtent.x; for (int i = 1; i < parts.length; i++) { stringExtent = gc.stringExtent(" " + parts[i]); boolean wrapped = false; if (ew + stringExtent.x > 110) // wrap it { stringExtent = gc.stringExtent(parts[i]); ew = stringExtent.x; curY += 3 + stringExtent.y; curX = upperLeft.x + 30; wrapped = true; } else ew += stringExtent.x; gc.drawString((wrapped ? "" : " ") + parts[i], curX, curY, true); curX += stringExtent.x; } if (selected) { gc.setForeground(foreground); } gc.setFont(originalFont); if ((options & Theme.RENDER_FLAG_NO_MARKERS) == 0) { if (uiElement.hasErrors()) gc.drawImage( org.eclipse.vtp.desktop.core.Activator.getDefault() .getImageRegistry() .get("ICON_ERROR"), lowerRight.x - 17, upperLeft.y); else if (uiElement.hasWarnings()) gc.drawImage( org.eclipse.vtp.desktop.core.Activator.getDefault() .getImageRegistry() .get("ICON_WARNING"), lowerRight.x - 16, upperLeft.y); else if (uiElement.hasTodo()) gc.drawImage( org.eclipse.vtp.desktop.core.Activator.getDefault().getImageRegistry().get("ICON_TASK"), lowerRight.x - 18, upperLeft.y + 2); } }
void onPaint(PaintEvent event) { Rectangle rect = getClientArea(); if (rect.width == 0 || rect.height == 0) return; boolean shortenText = false; String t = text; Image img = image; int availableWidth = Math.max(0, rect.width - (leftMargin + rightMargin)); Point extent = getTotalSize(img, t); if (extent.x > availableWidth) { img = null; extent = getTotalSize(img, t); if (extent.x > availableWidth) { shortenText = true; } } GC gc = event.gc; String[] lines = text == null ? null : splitString(text); // shorten the text if (shortenText) { extent.x = 0; for (int i = 0; i < lines.length; i++) { Point e = gc.textExtent(lines[i], DRAW_FLAGS); if (e.x > availableWidth) { lines[i] = shortenText(gc, lines[i], availableWidth); extent.x = Math.max(extent.x, getTotalSize(null, lines[i]).x); } else { extent.x = Math.max(extent.x, e.x); } } if (appToolTipText == null) { super.setToolTipText(text); } } else { super.setToolTipText(appToolTipText); } // determine horizontal position int x = rect.x + leftMargin; if (align == SWT.CENTER) { x = (rect.width - extent.x) / 2; } if (align == SWT.RIGHT) { x = rect.width - rightMargin - extent.x; } // draw a background image behind the text try { if (backgroundImage != null) { // draw a background image behind the text Rectangle imageRect = backgroundImage.getBounds(); // tile image to fill space gc.setBackground(getBackground()); gc.fillRectangle(rect); int xPos = 0; while (xPos < rect.width) { int yPos = 0; while (yPos < rect.height) { gc.drawImage(backgroundImage, xPos, yPos); yPos += imageRect.height; } xPos += imageRect.width; } } else if (gradientColors != null) { // draw a gradient behind the text final Color oldBackground = gc.getBackground(); if (gradientColors.length == 1) { if (gradientColors[0] != null) gc.setBackground(gradientColors[0]); gc.fillRectangle(0, 0, rect.width, rect.height); } else { final Color oldForeground = gc.getForeground(); Color lastColor = gradientColors[0]; if (lastColor == null) lastColor = oldBackground; int pos = 0; for (int i = 0; i < gradientPercents.length; ++i) { gc.setForeground(lastColor); lastColor = gradientColors[i + 1]; if (lastColor == null) lastColor = oldBackground; gc.setBackground(lastColor); if (gradientVertical) { final int gradientHeight = (gradientPercents[i] * rect.height / 100) - pos; gc.fillGradientRectangle(0, pos, rect.width, gradientHeight, true); pos += gradientHeight; } else { final int gradientWidth = (gradientPercents[i] * rect.width / 100) - pos; gc.fillGradientRectangle(pos, 0, gradientWidth, rect.height, false); pos += gradientWidth; } } if (gradientVertical && pos < rect.height) { gc.setBackground(getBackground()); gc.fillRectangle(0, pos, rect.width, rect.height - pos); } if (!gradientVertical && pos < rect.width) { gc.setBackground(getBackground()); gc.fillRectangle(pos, 0, rect.width - pos, rect.height); } gc.setForeground(oldForeground); } gc.setBackground(oldBackground); } else { if (background != null || (getStyle() & SWT.DOUBLE_BUFFERED) == 0) { gc.setBackground(getBackground()); gc.fillRectangle(rect); } } } catch (SWTException e) { if ((getStyle() & SWT.DOUBLE_BUFFERED) == 0) { gc.setBackground(getBackground()); gc.fillRectangle(rect); } } // draw border int style = getStyle(); if ((style & SWT.SHADOW_IN) != 0 || (style & SWT.SHADOW_OUT) != 0) { paintBorder(gc, rect); } /* * Compute text height and image height. If image height is more than * the text height, draw image starting from top margin. Else draw text * starting from top margin. */ Rectangle imageRect = null; int lineHeight = 0, textHeight = 0, imageHeight = 0; if (img != null) { imageRect = img.getBounds(); imageHeight = imageRect.height; } if (lines != null) { lineHeight = gc.getFontMetrics().getHeight(); textHeight = lines.length * lineHeight; } int imageY = 0, midPoint = 0, lineY = 0; if (imageHeight > textHeight) { if (topMargin == DEFAULT_MARGIN && bottomMargin == DEFAULT_MARGIN) imageY = rect.y + (rect.height - imageHeight) / 2; else imageY = topMargin; midPoint = imageY + imageHeight / 2; lineY = midPoint - textHeight / 2; } else { if (topMargin == DEFAULT_MARGIN && bottomMargin == DEFAULT_MARGIN) lineY = rect.y + (rect.height - textHeight) / 2; else lineY = topMargin; midPoint = lineY + textHeight / 2; imageY = midPoint - imageHeight / 2; } // draw the image if (img != null) { gc.drawImage( img, 0, 0, imageRect.width, imageHeight, x, imageY, imageRect.width, imageHeight); x += imageRect.width + GAP; extent.x -= imageRect.width + GAP; } // draw the text if (lines != null) { gc.setForeground(getForeground()); for (int i = 0; i < lines.length; i++) { int lineX = x; if (lines.length > 1) { if (align == SWT.CENTER) { int lineWidth = gc.textExtent(lines[i], DRAW_FLAGS).x; lineX = x + Math.max(0, (extent.x - lineWidth) / 2); } if (align == SWT.RIGHT) { int lineWidth = gc.textExtent(lines[i], DRAW_FLAGS).x; lineX = Math.max(x, rect.x + rect.width - rightMargin - lineWidth); } } gc.drawText(lines[i], lineX, lineY, DRAW_FLAGS); lineY += lineHeight; } } }