Java Code Examples for processing.core.PGraphics#textSize()

The following examples show how to use processing.core.PGraphics#textSize() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ConstellationAbstractMarker.java    From constellation with Apache License 2.0 6 votes vote down vote up
@Override
public void draw(final UnfoldingMap map) {
    final PGraphics graphics = map.mapDisplay.getOuterPG();
    final List<MapPosition> positions = locations.stream()
            .map(location -> new MapPosition(map.mapDisplay.getObjectFromLocation(location)))
            .collect(Collectors.toList());

    final boolean validMarker = draw(graphics, positions, map);

    // draw label
    if (validMarker && getId() != null) {
        final MapPosition center = new MapPosition();
        positions.forEach(position -> {
            center.add(position);
        });
        center.div(positions.size());
        graphics.fill(FONT_COLOR);
        graphics.textSize(FONT_SIZE);
        graphics.text(id, center.x - (CHAR_WIDTH * id.length() * 0.6f), center.y + (FONT_SIZE * 0.35f));
    }
}
 
Example 2
Source File: FontCacher.java    From haxademic with MIT License 5 votes vote down vote up
public static void setFontOnContext(PGraphics pg, PFont font, int color, float leadingMult, int alignX, int alignY) {
	pg.fill(color);
	pg.textFont(font);
	pg.textSize(font.getSize());
	pg.textLeading(font.getSize() * leadingMult);
	pg.textAlign(alignX, alignY);
}
 
Example 3
Source File: LeapRegion.java    From haxademic with MIT License 5 votes vote down vote up
public void drawDebug(PGraphics debugGraphics) {
	if( _blockColor == -1 ) return;
	
	// set box color for (in)active states
	debugGraphics.strokeWeight(5f);
	if(_isActive == true) {
		debugGraphics.stroke(_blockColor, 255);
		debugGraphics.noFill();
	} else {
		debugGraphics.stroke(255, 127);
		debugGraphics.noFill();
	}
	debugGraphics.pushMatrix();
	
	// move to center of box location & draw box
	debugGraphics.translate(P.lerp(_right, _left, 0.5f), P.lerp(_top, _bottom, 0.5f), -1f * P.lerp(_far, _near, 0.5f));
	debugGraphics.box(_right - _left, _top - _bottom, _far - _near);
	
	// draw text control values
	if(_isActive == true) {
		debugGraphics.noStroke();
		debugGraphics.fill(255);
		debugGraphics.textSize(24);
		debugGraphics.text(MathUtil.roundToPrecision(_controlX, 2)+", "+MathUtil.roundToPrecision(_controlY, 2)+", "+MathUtil.roundToPrecision(_controlZ, 2), -50, 0);
	}
	
	debugGraphics.popMatrix();
}
 
Example 4
Source File: ConstellationClusterMarker.java    From constellation with Apache License 2.0 4 votes vote down vote up
@Override
protected boolean draw(final PGraphics graphics, final List<MapPosition> positions, final UnfoldingMap map) {
    if (positions.isEmpty() || isHidden()) {
        return false;
    }

    clusterCenter = new MapPosition();
    positions.forEach(position -> {
        clusterCenter.add(position);
    });
    clusterCenter.div(positions.size());

    double diameter = 0;
    if (positions.size() > 1) {
        final MapPosition minPosition = new MapPosition(
                new float[]{Float.MAX_VALUE, Float.MAX_VALUE, Float.MAX_VALUE});
        final MapPosition maxPosition = new MapPosition(
                new float[]{Float.MIN_VALUE, Float.MIN_VALUE, Float.MIN_VALUE});
        positions.forEach(position -> {
            minPosition.x = Math.min(position.x, minPosition.x);
            minPosition.y = Math.min(position.y, minPosition.y);
            maxPosition.x = Math.max(position.x, maxPosition.x);
            maxPosition.y = Math.max(position.y, maxPosition.y);
        });
        diameter = Math.sqrt(Math.pow((maxPosition.x - minPosition.x), 2)
                + Math.pow((maxPosition.y - minPosition.y), 2));
    }
    clusterRadius = Math.max((float) diameter / 2, MIN_RADIUS);

    graphics.strokeWeight(size == MarkerUtilities.DEFAULT_SIZE ? strokeWeight : size);
    graphics.stroke(strokeColor);
    graphics.fill(getFillColor());
    graphics.ellipseMode(PConstants.RADIUS);
    graphics.ellipse(clusterCenter.x, clusterCenter.y, clusterRadius, clusterRadius);

    final String clusterLabel = String.valueOf(clusterSize);
    graphics.fill(FONT_COLOR);
    graphics.textSize(FONT_SIZE);
    graphics.text(clusterLabel,
            clusterCenter.x - (CHAR_WIDTH * clusterLabel.length() * 0.6f),
            clusterCenter.y + (FONT_SIZE * 0.35f));

    return true;
}
 
Example 5
Source File: BezierSurface.java    From sketch-mapper with MIT License 4 votes vote down vote up
/**
 * Renders the grid in the surface. (useful in calibration mode)
 *
 * @param g
 */
private void renderGrid(PGraphics g) {
    g.beginDraw();


    g.fill(ccolor);

    g.noStroke();
    for (int i = 0; i < GRID_RESOLUTION; i++) {
        for (int j = 0; j < GRID_RESOLUTION; j++) {

            g.beginShape();
            g.vertex(vertexPoints[i][j].x, vertexPoints[i][j].y);
            g.vertex(vertexPoints[i + 1][j].x, vertexPoints[i + 1][j].y);
            g.vertex(vertexPoints[i + 1][j + 1].x, vertexPoints[i + 1][j + 1].y);
            g.vertex(vertexPoints[i][j + 1].x, vertexPoints[i][j + 1].y);
            g.endShape();

        }
    }

    g.textFont(sm.getIdFont());
    g.fill(255);
    g.textAlign(PApplet.CENTER, PApplet.CENTER);
    g.textSize(20);
    g.text("" + this.getSurfaceName(), (float) (this.getCenter().x), (float) this.getCenter().y);
    if (isLocked) {
        g.textSize(12);
        g.text("Surface locked", (float) this.getCenter().x, (float) this.getCenter().y + 26);
    }
    if (sketch != null) {
        g.textSize(10);
        g.text(sketch.getName(), (float) this.getCenter().x, (float) this.getCenter().y + 40);
    }


    g.noFill();
    g.stroke(BezierSurface.GRID_LINE_COLOR);
    g.strokeWeight(2);
    if (isSelected)
        g.stroke(BezierSurface.GRID_LINE_SELECTED_COLOR);

    if (!isLocked) {
        for (int i = 0; i <= GRID_RESOLUTION; i++) {
            for (int j = 0; j <= GRID_RESOLUTION; j++) {
                g.point(vertexPoints[i][j].x, vertexPoints[i][j].y, vertexPoints[i][j].z);
            }
        }
    }

    if (isSelected) {
        g.strokeWeight(4);
        g.stroke(BezierSurface.GRID_LINE_SELECTED_COLOR);

        //draw the outline here
        for (int i = 0; i < poly.npoints - 1; i++) {
            g.line(poly.xpoints[i], poly.ypoints[i], poly.xpoints[i + 1], poly.ypoints[i + 1]);
            if (i == poly.npoints - 2)
                g.line(poly.xpoints[i + 1], poly.ypoints[i + 1], poly.xpoints[0], poly.ypoints[0]);
        }
    }

    g.strokeWeight(1);
    g.stroke(SELECTED_OUTLINE_INNER_COLOR);
    //draw the outline here
    for (int i = 0; i < poly.npoints - 1; i++) {
        g.line(poly.xpoints[i], poly.ypoints[i], poly.xpoints[i + 1], poly.ypoints[i + 1]);
        if (i == poly.npoints - 2)
            g.line(poly.xpoints[i + 1], poly.ypoints[i + 1], poly.xpoints[0], poly.ypoints[0]);
    }


    if (!isLocked) {
        // Draw the control points.
        for (int i = 0; i < this.cornerPoints.length; i++) {
            this.renderCornerPoint(g, this.cornerPoints[i].x, this.cornerPoints[i].y, (this.activePoint == i), i);

        }

        for (int i = 0; i < this.bezierPoints.length; i++) {
            this.renderBezierPoint(g, this.bezierPoints[i].x, this.bezierPoints[i].y, (this.selectedBezierControl == i), i);
            g.strokeWeight(1);
            g.stroke(255);
            g.line(this.bezierPoints[i].x, this.bezierPoints[i].y, this.cornerPoints[(int) (i / 2)].x, this.cornerPoints[(int) (i / 2)].y);
        }

    }

    g.endDraw();
}