use of org.eclipse.draw2d.ScaledGraphics in project cogtool by cogtool.
the class ScalableFrameFigure method paintClientArea.
/**
* Draw the figure to the screen. If the scale is not 1.0, then resize it
* using a scaled graphics object.
*
* Checks with the AView to determine if it should actually draw.
*/
@Override
protected void paintClientArea(Graphics graphics) {
if (View.isDrawingOK()) {
double myScale = getScale();
// Scale factor is actual size, so no need to scale
if (myScale == 1.0) {
super.paintClientArea(graphics);
paintTempFigure(graphics);
} else // Scaling of the canvas needs to be performed
if (OSUtils.MACOSX) {
ScaledGraphics g = new ScaledGraphics(graphics);
if ((getBorder() != null) && !getBorder().isOpaque()) {
g.clipRect(getBounds().getCropped(getInsets()));
}
// This path causes a couple of bugs -- if the view is zoomed
// and the contents are scaled (as in the Design Editor),
// it applies the latter scale first while drawing, then
// it applies the zoom scale. This causes thin things to
// disappear and widget locations to be off in the design view.
// TODO: eliminate this clause in favor of below when
// SWT is fixed on MACOS
g.scale(myScale);
g.pushState();
try {
paintChildren(g);
paintTempFigure(g);
} finally {
g.dispose();
}
} else {
// This is simpler and works on the PC
graphics.scale(myScale);
graphics.pushState();
super.paintClientArea(graphics);
graphics.popState();
paintTempFigure(graphics);
graphics.scale(1.0 / myScale);
}
}
}
use of org.eclipse.draw2d.ScaledGraphics in project archi by archimatetool.
the class CachedLabel method paintFigure.
@Override
protected void paintFigure(Graphics graphics) {
if (graphics.getClass() == ScaledGraphics.class) {
if (((ScaledGraphics) graphics).getAbsoluteScale() < 0.30) {
return;
}
}
if (!cacheLabel) {
if (isOpaque()) {
super.paintFigure(graphics);
}
Rectangle bounds = getBounds();
graphics.translate(bounds.x, bounds.y);
if (getIcon() != null) {
graphics.drawImage(getIcon(), getIconLocation());
}
if (!isEnabled()) {
graphics.translate(1, 1);
graphics.setForegroundColor(ColorConstants.buttonLightest);
graphics.drawText(getSubStringText(), getTextLocation());
graphics.translate(-1, -1);
graphics.setForegroundColor(ColorConstants.buttonDarker);
}
graphics.drawText(getText(), getTextLocation());
graphics.translate(-bounds.x, -bounds.y);
return;
}
if (isOpaque()) {
graphics.fillRectangle(getBounds());
}
Rectangle bounds = getBounds();
graphics.translate(bounds.x, bounds.y);
Image icon = getIcon();
if (icon != null) {
graphics.drawImage(icon, getIconLocation());
}
int width = getSubStringTextSize().width;
int height = getSubStringTextSize().height;
if (cachedImage == null || shouldInvalidateCache()) {
invalidationRequired = false;
cleanImage();
cachedImage = new Image(Display.getCurrent(), width, height);
// @tag TODO : Dispose of the image properly
// ZestPlugin.getDefault().addImage(cachedImage.toString(), cachedImage);
GC gc = new GC(cachedImage);
Graphics graphics2 = new SWTGraphics(gc);
graphics2.setBackgroundColor(getBackgroundTextColor());
graphics2.fillRectangle(0, 0, width, height);
graphics2.setForegroundColor(getForegroundColor());
// graphics2.drawText(getSubStringText(), new Point(0, 0));
graphics2.drawText(getText(), new Point(0, 0));
gc.dispose();
}
graphics.drawImage(cachedImage, getTextLocation());
graphics.translate(-bounds.x, -bounds.y);
this.paintBorder(graphics);
}
use of org.eclipse.draw2d.ScaledGraphics in project archi by archimatetool.
the class GraphLabel method paint.
/*
* (non-Javadoc)
*
* @see org.eclipse.draw2d.Label#paintFigure(org.eclipse.draw2d.Graphics)
*/
@Override
public void paint(Graphics graphics) {
int blue = getBackgroundColor().getBlue();
blue = (int) (blue - (blue * 0.20));
blue = blue > 0 ? blue : 0;
int red = getBackgroundColor().getRed();
red = (int) (red - (red * 0.20));
red = red > 0 ? red : 0;
int green = getBackgroundColor().getGreen();
green = (int) (green - (green * 0.20));
green = green > 0 ? green : 0;
Color lightenColor = new Color(Display.getCurrent(), new RGB(red, green, blue));
graphics.setForegroundColor(lightenColor);
graphics.setBackgroundColor(getBackgroundColor());
int safeBorderWidth = borderWidth > 0 ? borderWidth : 1;
graphics.pushState();
double scale = 1;
if (graphics instanceof ScaledGraphics) {
scale = ((ScaledGraphics) graphics).getAbsoluteScale();
}
// Top part inside the border (as fillGradient does not allow to fill a rectangle with round corners).
Rectangle rect = getBounds().getCopy();
rect.height /= 2;
graphics.setForegroundColor(getBackgroundColor());
graphics.setBackgroundColor(getBackgroundColor());
graphics.fillRoundRectangle(rect, arcWidth * safeBorderWidth, arcWidth * 2 * safeBorderWidth);
// Bottom part inside the border.
rect.y = rect.y + rect.height;
// Not sure why it is needed, but it is needed ;-)
rect.height += 1;
graphics.setForegroundColor(lightenColor);
graphics.setBackgroundColor(lightenColor);
graphics.fillRoundRectangle(rect, arcWidth * safeBorderWidth, arcWidth * 2 * safeBorderWidth);
// Now fill the middle part of top and bottom part with a gradient.
rect = bounds.getCopy();
rect.height -= 2;
rect.y += (safeBorderWidth) / 2;
rect.y += (arcWidth / 2);
rect.height -= arcWidth / 2;
rect.height -= safeBorderWidth;
graphics.setBackgroundColor(lightenColor);
graphics.setForegroundColor(getBackgroundColor());
graphics.fillGradient(rect, true);
// Paint the border
if (borderWidth > 0) {
rect = getBounds().getCopy();
rect.x += safeBorderWidth / 2;
rect.y += safeBorderWidth / 2;
rect.width -= safeBorderWidth;
rect.height -= safeBorderWidth;
graphics.setForegroundColor(borderColor);
graphics.setBackgroundColor(borderColor);
graphics.setLineWidth((int) (safeBorderWidth * scale));
graphics.drawRoundRectangle(rect, arcWidth, arcWidth);
}
super.paint(graphics);
graphics.popState();
}
Aggregations