use of org.graphstream.ui.graphicGraph.stylesheet.Values in project gs-ui-javafx by graphstream.
the class DefaultCamera method isNodeIn.
/**
* Is the given node visible in the given area.
*
* @param node
* The node to check.
* @param X1
* The min abscissa of the area.
* @param Y1
* The min ordinate of the area.
* @param X2
* The max abscissa of the area.
* @param Y2
* The max ordinate of the area.
* @return True if the node lies in the given area.
*/
protected boolean isNodeIn(GraphicNode node, double X1, double Y1, double X2, double Y2) {
Values size = node.getStyle().getSize();
double w2 = metrics.lengthToPx(size, 0) / 2;
double h2 = size.size() > 1 ? metrics.lengthToPx(size, 1) / 2 : w2;
Point2D src = new Point2D(node.getX(), node.getY());
boolean vis = true;
Point2D dst = Tx.transform(src.getX(), src.getY());
double x1 = dst.getX() - w2;
double x2 = dst.getX() + w2;
double y1 = dst.getY() - h2;
double y2 = dst.getY() + h2;
if (x2 < X1)
vis = false;
else if (y2 < Y1)
vis = false;
else if (x1 > X2)
vis = false;
else if (y1 > Y2)
vis = false;
return vis;
}
use of org.graphstream.ui.graphicGraph.stylesheet.Values in project gs-ui-javafx by graphstream.
the class DefaultCamera method isEdgeIn.
/**
* Is the given sprite visible in the given area.
*
* @param edge
* The edge to check.
* @param X1
* The min abscissa of the area.
* @param Y1
* The min ordinate of the area.
* @param X2
* The max abscissa of the area.
* @param Y2
* The max ordinate of the area.
* @return True if the edge lies in the given area.
*/
protected boolean isEdgeIn(GraphicEdge edge, double X1, double Y1, double X2, double Y2) {
Values size = edge.getStyle().getSize();
double w2 = metrics.lengthToPx(size, 0) / 2;
double h2 = size.size() > 1 ? metrics.lengthToPx(size, 1) / 2 : w2;
Point2D src = new Point2D(edge.getX(), edge.getY());
boolean vis = true;
Point2D dst = Tx.transform(src.getX(), src.getY());
double x1 = dst.getX() - w2;
double x2 = dst.getX() + w2;
double y1 = dst.getY() - h2;
double y2 = dst.getY() + h2;
if (x2 < X1)
vis = false;
else if (y2 < Y1)
vis = false;
else if (x1 > X2)
vis = false;
else if (y1 > Y2)
vis = false;
return vis;
}
use of org.graphstream.ui.graphicGraph.stylesheet.Values in project gs-ui-javafx by graphstream.
the class DefaultCamera method nodeContains.
/**
* Check if a node contains the given point (x,y).
*
* @param elt
* The node.
* @param x
* The point abscissa.
* @param y
* The point ordinate.
* @return True if (x,y) is in the given element.
*/
protected boolean nodeContains(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 abstract double getAscentDescent();
/**
* Factory companion object for text boxes.
*/
// static FontRenderContext defaultFontRenderContext = new FontRenderContext(new AffineTransform(), true, true);
public static TextBox apply(DefaultCamera2D camera, Style style) {
String fontName = style.getTextFont();
TextStyle fontStyle = style.getTextStyle();
Value fontSize = style.getTextSize();
Color textColor = ColorManager.getTextColor(style, 0);
Color bgColor = null;
boolean rounded = false;
switch(style.getTextBackgroundMode()) {
case NONE:
break;
case PLAIN:
rounded = false;
bgColor = ColorManager.getTextBackgroundColor(style, 0);
break;
case ROUNDEDBOX:
rounded = true;
bgColor = ColorManager.getTextBackgroundColor(style, 0);
break;
default:
break;
}
Values padding = style.getTextPadding();
double padx = camera.getMetrics().lengthToPx(padding, 0);
double pady = padx;
if (padding.size() > 1)
camera.getMetrics().lengthToPx(padding, 1);
return TextBox.apply(fontName, fontStyle, (int) fontSize.value, textColor, bgColor, rounded, padx, pady);
}
use of org.graphstream.ui.graphicGraph.stylesheet.Values in project gs-ui-javafx by graphstream.
the class DefaultCamera method spriteContains.
/**
* Check if a sprite contains the given point (x,y).
*
* @param elt
* The sprite.
* @param x
* The point abscissa.
* @param y
* The point ordinate.
* @return True if (x,y) is in the given element.
*/
protected boolean spriteContains(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;
// new
Point2D dst = spritePositionPx((GraphicSprite) elt);
// Point2D.Double(
// elt.getX(),
// elt.getY()
// );
// Point2D.Double dst = new Point2D.Double();
// Tx.transform( src, dst );
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;
}
Aggregations