use of java.awt.geom.GeneralPath in project platform_frameworks_base by android.
the class Path_Delegate method transform.
/**
* Transform the points in this path by matrix, and write the answer
* into dst. If dst is null, then the the original path is modified.
*
* @param matrix The matrix to apply to the path
* @param dst The transformed path is written here. If dst is null,
* then the the original path is modified
*/
public void transform(Matrix_Delegate matrix, Path_Delegate dst) {
if (matrix.hasPerspective()) {
assert false;
Bridge.getLog().fidelityWarning(LayoutLog.TAG_MATRIX_AFFINE, "android.graphics.Path#transform() only " + "supports affine transformations.", null, null);
}
GeneralPath newPath = new GeneralPath();
PathIterator iterator = mPath.getPathIterator(matrix.getAffineTransform());
newPath.append(iterator, false);
if (dst != null) {
dst.mPath = newPath;
} else {
mPath = newPath;
}
}
use of java.awt.geom.GeneralPath in project gephi by gephi.
the class ArrowRenderer method render.
@Override
public void render(final Item item, final RenderTarget target, final PreviewProperties properties) {
final Helper h = new Helper(item, properties);
final Color color = EdgeRenderer.getColor(item, properties);
if (target instanceof G2DTarget) {
Graphics2D graphics = ((G2DTarget) target).getGraphics();
graphics.setColor(color);
final GeneralPath gpath = new GeneralPath();
gpath.moveTo(h.p1.x, h.p1.y);
gpath.lineTo(h.p2.x, h.p2.y);
gpath.lineTo(h.p3.x, h.p3.y);
gpath.closePath();
graphics.fill(gpath);
} else if (target instanceof SVGTarget) {
final SVGTarget svgTarget = (SVGTarget) target;
final Element arrowElem = svgTarget.createElement("polyline");
arrowElem.setAttribute("points", String.format(Locale.ENGLISH, "%f,%f %f,%f %f,%f", h.p1.x, h.p1.y, h.p2.x, h.p2.y, h.p3.x, h.p3.y));
arrowElem.setAttribute("class", String.format("%s %s", ((Node) h.sourceItem.getSource()).getId(), ((Node) h.targetItem.getSource()).getId()));
arrowElem.setAttribute("fill", svgTarget.toHexString(color));
arrowElem.setAttribute("fill-opacity", (color.getAlpha() / 255f) + "");
arrowElem.setAttribute("stroke", "none");
svgTarget.getTopElement(SVGTarget.TOP_ARROWS).appendChild(arrowElem);
} else if (target instanceof PDFTarget) {
final PDFTarget pdfTarget = (PDFTarget) target;
final PdfContentByte cb = pdfTarget.getContentByte();
cb.moveTo(h.p1.x, -h.p1.y);
cb.lineTo(h.p2.x, -h.p2.y);
cb.lineTo(h.p3.x, -h.p3.y);
cb.closePath();
cb.setRGBColorFill(color.getRed(), color.getGreen(), color.getBlue());
if (color.getAlpha() < 255) {
cb.saveState();
float alpha = color.getAlpha() / 255f;
PdfGState gState = new PdfGState();
gState.setFillOpacity(alpha);
cb.setGState(gState);
}
cb.fill();
if (color.getAlpha() < 255) {
cb.restoreState();
}
}
}
use of java.awt.geom.GeneralPath in project processing by processing.
the class EditorHeader method paintComponent.
public void paintComponent(Graphics screen) {
if (screen == null)
return;
Sketch sketch = editor.getSketch();
// possible?
if (sketch == null)
return;
Dimension size = getSize();
if ((size.width != sizeW) || (size.height != sizeH)) {
if ((size.width > imageW) || (size.height > imageH)) {
// nix the image and recreate, it's too small
offscreen = null;
} else {
// if the image is larger than necessary, no need to change
sizeW = size.width;
sizeH = size.height;
}
}
if (offscreen == null) {
sizeW = size.width;
sizeH = size.height;
imageW = sizeW;
imageH = sizeH;
offscreen = Toolkit.offscreenGraphics(this, imageW, imageH);
}
Graphics g = offscreen.getGraphics();
// need to set this each time through
g.setFont(font);
if (fontAscent == 0) {
fontAscent = (int) Toolkit.getAscent(g);
}
Graphics2D g2 = Toolkit.prepareGraphics(g);
// Toolkit.dpiStroke(g2);
g.drawImage(gradient, 0, 0, imageW, imageH, this);
if (tabs.length != sketch.getCodeCount()) {
tabs = new Tab[sketch.getCodeCount()];
for (int i = 0; i < tabs.length; i++) {
tabs[i] = new Tab(i);
}
visitOrder = new Tab[sketch.getCodeCount() - 1];
}
int leftover = TAB_BETWEEN + ARROW_TAB_WIDTH;
int tabMax = getWidth() - leftover;
// reset all tab positions
for (Tab tab : tabs) {
SketchCode code = sketch.getCode(tab.index);
tab.textVisible = true;
tab.lastVisited = code.lastVisited();
// hide extensions for .pde files
boolean hide = editor.getMode().hideExtension(code.getExtension());
tab.text = hide ? code.getPrettyName() : code.getFileName();
// if modified, add the li'l glyph next to the name
// if (code.isModified()) {
// tab.text += " ยง";
// }
tab.textWidth = (int) font.getStringBounds(tab.text, g2.getFontRenderContext()).getWidth();
}
// try to make everything fit
if (!placeTabs(Editor.LEFT_GUTTER, tabMax, null)) {
// always show the tab with the sketch's name
int index = 0;
// stock the array backwards so the rightmost tabs are closed by default
for (int i = tabs.length - 1; i > 0; --i) {
visitOrder[index++] = tabs[i];
}
// sort on when visited
Arrays.sort(visitOrder);
// Keep shrinking the tabs one-by-one until things fit properly
for (int i = 0; i < visitOrder.length; i++) {
tabs[visitOrder[i].index].textVisible = false;
if (placeTabs(Editor.LEFT_GUTTER, tabMax, null)) {
break;
}
}
}
// now actually draw the tabs
if (!placeTabs(Editor.LEFT_GUTTER, tabMax - ARROW_TAB_WIDTH, g2)) {
// draw the dropdown menu target at the right of the window
menuRight = tabMax;
menuLeft = menuRight - ARROW_TAB_WIDTH;
} else {
// draw the dropdown menu target next to the tabs
menuLeft = tabs[tabs.length - 1].right + TAB_BETWEEN;
menuRight = menuLeft + ARROW_TAB_WIDTH;
}
// draw the two pixel line that extends left/right below the tabs
g.setColor(tabColor[SELECTED]);
// can't be done with lines, b/c retina leaves tiny hairlines
g.fillRect(Editor.LEFT_GUTTER, TAB_BOTTOM, editor.getTextArea().getWidth() - Editor.LEFT_GUTTER, Toolkit.zoom(2));
// draw the tab for the menu
g.setColor(tabColor[UNSELECTED]);
drawTab(g, menuLeft, menuRight, false, true);
// draw the arrow on the menu tab
g.setColor(arrowColor);
GeneralPath trianglePath = new GeneralPath();
float x1 = menuLeft + (ARROW_TAB_WIDTH - ARROW_WIDTH) / 2f;
float x2 = menuLeft + (ARROW_TAB_WIDTH + ARROW_WIDTH) / 2f;
trianglePath.moveTo(x1, ARROW_TOP);
trianglePath.lineTo(x2, ARROW_TOP);
trianglePath.lineTo((x1 + x2) / 2, ARROW_BOTTOM);
trianglePath.closePath();
g2.fill(trianglePath);
screen.drawImage(offscreen, 0, 0, imageW, imageH, null);
}
use of java.awt.geom.GeneralPath in project processing by processing.
the class PdeTextAreaPainter method drawDiamond.
private static void drawDiamond(Graphics g, float x, float y, float w, float h) {
Graphics2D g2 = (Graphics2D) g;
GeneralPath path = new GeneralPath();
path.moveTo(x + w / 2, y);
path.lineTo(x + w, y + h / 2);
path.lineTo(x + w / 2, y + h);
path.lineTo(x, y + h / 2);
path.closePath();
g2.fill(path);
}
use of java.awt.geom.GeneralPath in project android_frameworks_base by ParanoidAndroid.
the class Path_Delegate method transform.
/**
* Transform the points in this path by matrix, and write the answer
* into dst. If dst is null, then the the original path is modified.
*
* @param matrix The matrix to apply to the path
* @param dst The transformed path is written here. If dst is null,
* then the the original path is modified
*/
public void transform(Matrix_Delegate matrix, Path_Delegate dst) {
if (matrix.hasPerspective()) {
assert false;
Bridge.getLog().fidelityWarning(LayoutLog.TAG_MATRIX_AFFINE, "android.graphics.Path#transform() only " + "supports affine transformations.", null, null);
}
GeneralPath newPath = new GeneralPath();
PathIterator iterator = mPath.getPathIterator(matrix.getAffineTransform());
newPath.append(iterator, false);
if (dst != null) {
dst.mPath = newPath;
} else {
mPath = newPath;
}
}
Aggregations