use of org.graphstream.ui.graphicGraph.stylesheet.Values in project gs-ui-javafx by graphstream.
the class DefaultCamera method edgeContains.
/**
* Check if an edge contains the given point (x,y).
*
* @param elt
* The edge.
* @param x
* The point abscissa.
* @param y
* The point ordinate.
* @return True if (x,y) is in the given element.
*/
protected boolean edgeContains(GraphicElement elt, double x, double y) {
Values size = elt.getStyle().getSize();
double w2 = metrics.lengthToPx(size, 0) / 2;
double h2 = size.size() > 1 ? metrics.lengthToPx(size, 1) / 2 : w2;
Point2D src = new Point2D(elt.getX(), elt.getY());
Point2D dst = Tx.transform(src.getX(), src.getY());
double dstX = dst.getX() - metrics.viewport[0];
double dstY = dst.getY() - metrics.viewport[1];
dst = new Point2D(dstX, dstY);
double x1 = dst.getX() - w2;
double x2 = dst.getX() + w2;
double y1 = dst.getY() - h2;
double y2 = dst.getY() + h2;
if (x < x1)
return false;
if (y < y1)
return false;
if (x > x2)
return false;
if (y > y2)
return false;
return true;
}
use of org.graphstream.ui.graphicGraph.stylesheet.Values in project gs-ui-javafx by graphstream.
the class FxTextBox method apply.
public static IconAndText apply(Style style, DefaultCamera2D camera, GraphicElement element) {
Image icon = null;
TextBox text = TextBox.apply(camera, style);
Values padd = style.getPadding();
Values off = style.getTextOffset();
double padx = camera.getMetrics().lengthToPx(padd, 0);
double pady = padx;
if (padd.size() > 1)
pady = camera.getMetrics().lengthToPx(padd, 1);
double offx = camera.getMetrics().lengthToPx(off, 0);
double offy = padx;
if (padd.size() > 1)
offy = camera.getMetrics().lengthToPx(off, 1);
if (style.getIconMode() != IconMode.NONE) {
String url = style.getIcon();
if (url.equals("dynamic")) {
if (element.hasLabel("ui.icon"))
url = element.getLabel("ui.icon").toString();
else
url = null;
}
if (url != null) {
icon = ImageCache.loadImage(url);
}
}
if (icon == null) {
return new IconAndTextOnlyText(text, offx, offy, padx, pady);
} else {
switch(style.getIconMode()) {
case AT_LEFT:
return new IconAtLeftAndText(icon, text, offx, offy, padx, pady);
case AT_RIGHT:
return new IconAtLeftAndText(icon, text, offx, offy, padx, pady);
case ABOVE:
return new IconAtLeftAndText(icon, text, offx, offy, padx, pady);
case UNDER:
return new IconAtLeftAndText(icon, text, offx, offy, padx, pady);
default:
throw new RuntimeException("???");
}
}
}
Aggregations