use of org.eclipse.swt.graphics.Transform in project netxms by netxms.
the class ObjectStatusRadialWidget method drawParts.
/**
* Draw sectors for all objects
*
* @param object the root object
*/
private float drawParts(GC gc, AbstractObject object, int lvl, float degree) {
gc.setAlpha(255);
float objectSize = 0;
for (AbstractObject obj : object.getChildsAsArray()) {
float currObjsize = 0;
if (AbstractObjectStatusMap.isContainerObject(obj)) {
currObjsize = drawParts(gc, obj, lvl + 1, degree);
if (currObjsize == 0) {
if (objects != null)
continue;
currObjsize = leafObjectSize;
}
} else {
if (objects != null && !objects.containsKey(obj.getObjectId()))
continue;
currObjsize = leafObjectSize;
}
// compensate for rounding errors by either extending or shrinking current object by one degree
int compensation = Integer.signum(Math.round(degree + currObjsize) - (Math.round(degree) + Math.round(currObjsize)));
// white circle before each level
gc.setBackground(getDisplay().getSystemColor(SWT.COLOR_WHITE));
gc.fillArc(centerX - (diameter * lvl) / 2 - 3, centerY - (diameter * lvl) / 2 - 3, diameter * lvl + 6, diameter * lvl + 6, Math.round(degree), Math.round(currObjsize) + compensation);
gc.setBackground(StatusDisplayInfo.getStatusColor(obj.getStatus()));
gc.fillArc(centerX - (diameter * lvl) / 2, centerY - (diameter * lvl) / 2, diameter * lvl, diameter * lvl, Math.round(degree), Math.round(currObjsize) - 1 + compensation);
objectMap.add(new ObjectPosition(degree, degree + currObjsize, lvl, obj));
Transform oldTransform = new Transform(gc.getDevice());
gc.getTransform(oldTransform);
// draw text
String text = obj.getObjectName();
Transform tr = new Transform(getDisplay());
tr.translate(centerX, centerY);
// text centering
float rotate = 0;
float middle = degree + currObjsize / 2;
if (middle >= 90 && middle < 180)
rotate = 90 - (middle - 90);
if (middle >= 270 && middle <= 360)
rotate = 90 - (middle - 270);
if (middle >= 0 && middle < 90)
rotate = -middle;
if (middle >= 180 && middle < 270)
rotate = -(middle - 180);
tr.rotate(rotate);
gc.setTransform(tr);
// cut text function
int l = gc.textExtent(text).x;
int h = gc.textExtent(text).y;
// high of sector
int high = (int) ((Math.tan(currObjsize / 2)) * ((diameter * lvl) / 2) * 2) - 6;
int lineNum = high / (h + 13);
if (lineNum < 0 || lineNum > 3)
lineNum = 3;
if (l > diameter / 2 - 6) {
text = substring(text, gc, lineNum);
}
h = gc.textExtent(text).y;
gc.setForeground(ColorConverter.selectTextColorByBackgroundColor(StatusDisplayInfo.getStatusColor(obj.getStatus()), cCache));
if (middle >= 90 && middle <= 180 || middle > 180 && middle < 270) {
l = gc.textExtent(text).x;
gc.drawText(text, -(diameter * (lvl - 1)) / 2 - 6 - l, -h / 2, SWT.DRAW_TRANSPARENT | SWT.DRAW_DELIMITER);
} else
gc.drawText(text, (diameter * (lvl - 1)) / 2 + 5, -h / 2, SWT.DRAW_TRANSPARENT | SWT.DRAW_DELIMITER);
gc.setTransform(oldTransform);
tr.dispose();
oldTransform.dispose();
degree += currObjsize;
objectSize += currObjsize;
}
return objectSize;
}
use of org.eclipse.swt.graphics.Transform in project n4js by eclipse.
the class GraphCanvas method doPaint.
protected void doPaint(GC gc, PaintEvent event) {
gc.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_WHITE));
gc.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_BLACK));
gc.fillRectangle(event.x, event.y, event.width, event.height);
if (graph == null)
return;
final Transform tf = new Transform(gc.getDevice());
tf.translate(-offsetX, -offsetY);
tf.scale(scale, scale);
gc.setTransform(tf);
if (graphNeedsLayout) {
graph.layout(gc);
graphNeedsLayout = false;
}
for (Edge e : graph.getEdges()) {
Stream<Node> eNodes = e.getNodes().stream();
boolean paintIt = false;
paintIt |= !e.isCrossLink();
paintIt |= e.isCrossLink() && (showAllCrossLinks || eNodes.anyMatch(n -> n == hoveredNode || selectedNodes.contains(n)));
if (paintIt) {
e.paint(gc);
}
}
for (Node n : graph.getNodes()) {
n.paint(gc);
}
gc.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_BLUE));
for (Node sn : selectedNodes) {
float x = sn.getX() - 2;
float y = sn.getY() - 2;
float width = sn.getWidth() + 4;
float height = sn.getHeight() + 4;
GraphUtils.drawRectangle(gc, x, y, width, height);
}
gc.setTransform(null);
tf.dispose();
if (hawkEye_active && hawkEye_target != null) {
final int w = Math.round(getSize().x / hawkEye_oldScale * scale);
final int h = Math.round(getSize().y / hawkEye_oldScale * scale);
final int x = (int) hawkEye_target.x - w / 2;
final int y = (int) hawkEye_target.y - h / 2;
gc.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_BLUE));
gc.setAlpha(64);
gc.fillRectangle(x, y, w, h);
gc.setAlpha(255);
}
}
use of org.eclipse.swt.graphics.Transform in project n4js by eclipse.
the class VisualisationCanvas method doPaint.
protected void doPaint(GC gc, PaintEvent event) {
gc.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_WHITE));
gc.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_BLACK));
gc.fillRectangle(event.x, event.y, event.width, event.height);
if (graph != null) {
final Transform tf = new Transform(gc.getDevice());
tf.translate(-offsetX, -offsetY);
tf.scale(scale, scale);
gc.setTransform(tf);
if (graphNeedsLayout) {
graph.layout();
graphNeedsLayout = false;
}
graph.getNodes().forEach(n -> n.paint(gc));
gc.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_BLUE));
gc.setTransform(null);
tf.dispose();
if (hawkEye_active && hawkEye_target != null) {
final int w = Math.round(getSize().x / hawkEye_oldScale * scale);
final int h = Math.round(getSize().y / hawkEye_oldScale * scale);
gc.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_BLUE));
gc.setAlpha(64);
gc.fillRectangle((int) hawkEye_target.x - w / 2, (int) hawkEye_target.y - h / 2, w, h);
gc.setAlpha(255);
}
}
}
use of org.eclipse.swt.graphics.Transform in project SIMVA-SoS by SESoS.
the class SWTGraphics2D method setTransform.
/**
* Sets the current transform.
*
* @param t the transform.
*/
public void setTransform(AffineTransform t) {
Transform transform = getSwtTransformFromPool(t);
this.gc.setTransform(transform);
}
use of org.eclipse.swt.graphics.Transform in project SIMVA-SoS by SESoS.
the class SWTGraphics2D method transform.
/**
* Concatenates the specified transform to the existing transform.
*
* @param t the transform.
*/
public void transform(AffineTransform t) {
Transform swtTransform = new Transform(this.gc.getDevice());
this.gc.getTransform(swtTransform);
swtTransform.multiply(getSwtTransformFromPool(t));
this.gc.setTransform(swtTransform);
swtTransform.dispose();
}
Aggregations