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

The following examples show how to use processing.core.PGraphics#text() . 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: UIButton.java    From haxademic with MIT License 6 votes vote down vote up
public void draw(PGraphics pg) {
	PG.setDrawCorner(pg);

	// outline
	pg.noStroke();
	if(over || pressed) pg.fill(ColorsHax.BUTTON_OUTLINE_HOVER);
	else pg.fill(ColorsHax.BUTTON_OUTLINE);
	pg.rect(rect.x, rect.y, rect.width, rect.height);

	// background
	if(over && value == 0 && !pressed) pg.fill(ColorsHax.BUTTON_BG_HOVER);
	else if(pressed) pg.fill(ColorsHax.BUTTON_BG_PRESS);
	else if(toggles && value == 1) pg.fill(ColorsHax.WHITE);
	else pg.fill(ColorsHax.BUTTON_BG);
	pg.rect(rect.x+1, rect.y+1, rect.width-2, rect.height-2);

	// text label
	IUIControl.setFont(pg);
	if(toggles && value == 1) pg.fill(ColorsHax.BLACK);
	else pg.fill(ColorsHax.BUTTON_TEXT);
	pg.text(label, rect.x + TEXT_INDENT, rect.y, rect.width, rect.height);
	
	// set active if drawing
	activeTime = P.p.millis();
}
 
Example 2
Source File: UITitle.java    From haxademic with MIT License 6 votes vote down vote up
public void draw(PGraphics pg) {
	PG.setDrawCorner(pg);

	// outline
	pg.noStroke();
	pg.fill(ColorsHax.BUTTON_OUTLINE);
	pg.rect(rect.x, rect.y, rect.width, rect.height);

	// background
	pg.fill(ColorsHax.TITLE_BG);
	pg.rect(rect.x+1, rect.y+1, rect.width-2, rect.height-2);

	// text label
	IUIControl.setFont(pg);
	pg.fill(ColorsHax.BUTTON_TEXT);
	pg.text(label, rect.x + TEXT_INDENT, rect.y);
}
 
Example 3
Source File: Polygon.java    From haxademic with MIT License 6 votes vote down vote up
protected void drawNeighborDebug(PGraphics pg) {
	for (int i = 0; i < edges.size(); i++) {
		Edge edge = edges.get(i);
		if(neighbors.containsKey(edge)) {
			pg.fill(0, 255, 0);
		} else {
			pg.fill(255, 0, 0);
		}
		pg.noStroke();
		PVector almostEdge = midPoint(center, edge.midPoint());
		pg.circle(almostEdge.x, almostEdge.y, 5);
	}
	// draw area calc
	PFont font = FontCacher.getFont(DemoAssets.fontOpenSansPath, 10);
	FontCacher.setFontOnContext(pg, font, P.p.color(255), 1f, PTextAlign.LEFT, PTextAlign.TOP);
	pg.text(P.round(area), center.x, center.y);
}
 
Example 4
Source File: UISlider.java    From haxademic with MIT License 5 votes vote down vote up
public void draw(PGraphics pg) {
		pg.pushMatrix();
		PG.setDrawCorner(pg);
		
		// outline
		pg.noStroke();
		pg.fill(ColorsHax.BUTTON_OUTLINE);
		pg.rect(x, y, w, h);
		
		// background
		if(mouseHovered) pg.fill(ColorsHax.BUTTON_BG_HOVER);
		else pg.fill(ColorsHax.BUTTON_BG);
		pg.rect(x+1, y+1, w-2, h-2);
		
		// draw current value
		pg.noStroke();
		if(mousePressed) pg.fill(ColorsHax.WHITE, 180);
		else pg.fill(0, 127, 0);
//		else pg.fill(ColorsHax.WHITE, 120);
		float handleW = 4;
		float mappedX = P.map(value, valueMin, valueMax, x+1, x + w - handleW);
		pg.rect(mappedX - 0.5f, y+1, handleW, h-2);
		
		// text label
		IUIControl.setFont(pg);
		pg.fill(ColorsHax.BUTTON_TEXT);
		pg.text(id + ": " + MathUtil.roundToPrecision(value, 5), P.round(x + TEXT_INDENT), y, w, h*2);
		uiRect.setBounds(x, y, w, h);
		
		// set active if drawing
		activeTime = P.p.millis();
		pg.popMatrix();
	}
 
Example 5
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 6
Source File: LightBar.java    From haxademic with MIT License 5 votes vote down vote up
protected void drawNumberValue(PGraphics pg, int val) {
	// channel info text
	pg.push();
	pg.translate(0, 0);
	pg.fill(255);
	pg.noStroke();
	float ellipseW = (val > 99) ? 30 : 20;	// make wider for 3 digits
	pg.ellipse(midPoint.x, midPoint.y, ellipseW, 20);

	PFont font = FontCacher.getFont(DemoAssets.fontOpenSansPath, 12);
	FontCacher.setFontOnContext(pg, font, P.p.color(0), 1f, PTextAlign.CENTER, PTextAlign.CENTER);
	pg.text(val+"", midPoint.x, midPoint.y - 2, 30, 20);
	pg.pop();

}
 
Example 7
Source File: StrokeText.java    From haxademic with MIT License 5 votes vote down vote up
public static void draw(PGraphics pg, String str, float x, float y, float w, float h, int strokeColor, int fillColor, float thickness, int resolution) {
	// translate
	pg.pushMatrix();
	pg.translate(x, y);
	
	// draw text around in a circle 
	pg.fill(strokeColor);
	float segmentRads = P.TWO_PI / resolution;
	for (int i = 0; i < resolution; i++) {
		float outlineX = P.cos(segmentRads * i);
		float outlineY = P.sin(segmentRads * i);
		if(w == -1) {
			pg.text(str, thickness * outlineX, thickness * outlineY);
		} else {
			pg.text(str, thickness * outlineX, thickness * outlineY, w, h);
		}
	}
	
	// fill in center
	pg.fill(fillColor);
	if(w == -1) {
		pg.text(str, 0, 0);
	} else {
		pg.text(str, 0, 0, w, h);
	}
	
	// pop
	pg.popMatrix();
}
 
Example 8
Source File: PShaderHotSwap.java    From haxademic with MIT License 5 votes vote down vote up
public void showShaderStatus(PGraphics pg) {
	if(compiledShader.isValid() == false) {
		FontCacher.setFontOnContext(pg, FontCacher.getFont(DemoAssets.fontInterPath, 14), P.p.color(255, 0, 0), 1, PTextAlign.LEFT, PTextAlign.TOP);
		pg.text("Shader error:" + compiledShader.compileMessage(), 20, 20);
	} else {
		FontCacher.setFontOnContext(pg, FontCacher.getFont(DemoAssets.fontInterPath, 14), P.p.color(0, 255, 0), 1, PTextAlign.LEFT, PTextAlign.TOP);
		pg.text("Shader compiled!", 20, 20);
	}
}
 
Example 9
Source File: SavedRectangle.java    From haxademic with MIT License 5 votes vote down vote up
public void drawDebugToPG(PGraphics pg, boolean drawInPlace) {
	int x = (drawInPlace == true) ? 0 : x();
	int y = (drawInPlace == true) ? 0 : y();
	if(isDragging() == true) 
		pg.fill(255, 100); 
	else 
		pg.fill(0,100,0, 100);
	pg.rect(x, y, width(), height());
	pg.fill(255);
	pg.text(""+x()+", "+y()+", "+width()+", "+height(), x + 10, y + 20);
}
 
Example 10
Source File: DebugView.java    From haxademic with MIT License 5 votes vote down vote up
protected void drawHighlightedValue() {
	if(highlightedText != null) {
		PGraphics pg = P.p.g;

		// draw bg rect
		int fill = P.p.color(0, 100, 0);
		PG.drawStrokedRect(pg, pg.width, controlH, 1, fill, ColorsHax.BUTTON_OUTLINE);

		// text label
		pg.fill(ColorsHax.BUTTON_TEXT);
		pg.text(highlightedText, IUIControl.TEXT_INDENT, 1f); // , IUIControl.controlW, controlH
	}
}
 
Example 11
Source File: DebugView.java    From haxademic with MIT License 5 votes vote down vote up
protected void drawTextLine(String textLine, boolean isTitle) {
	PGraphics pg = P.p.g;
	PG.setDrawCorner(pg);

	// set context
	pg.pushMatrix();
	pg.translate(controlX, controlY);
	
	// draw bg rect
	int fill = (isTitle) ? P.p.color(ColorsHax.TITLE_BG, BG_ALPHA) : P.p.color(ColorsHax.BUTTON_BG, BG_ALPHA);
	PG.drawStrokedRect(pg, IUIControl.controlW, controlH, 1, fill, ColorsHax.BUTTON_OUTLINE);

	// text label
	pg.fill(ColorsHax.BUTTON_TEXT);
	pg.text(textLine, IUIControl.TEXT_INDENT, 1f); // , IUIControl.controlW, controlH

	// if mouse hover, draw big afterwards
	if(!isTitle && CollisionUtil.rectangleContainsPoint(Mouse.x, Mouse.y, controlX, controlY, IUIControl.controlW, controlH)) {
		highlightedText = textLine;
	}
	
	// reset context
	pg.popMatrix();

	// move to next box
	controlY += controlH - 1;
	if(controlY > P.p.height - controlH) nextCol();
}
 
Example 12
Source File: StringBufferLog.java    From haxademic with MIT License 5 votes vote down vote up
public void printToScreen(PGraphics pg, float x, float y) {
	PFont font = FontCacher.getFont(DemoAssets.fontOpenSansPath, fontSize);
	FontCacher.setFontOnContext(pg, font, P.p.color(255), 1f, PTextAlign.LEFT, PTextAlign.TOP);
	
	String outputStr = "";
	for (int i = 0; i < lines.length; i++) {
		int loopedIndx = (curIndex + i) % lines.length;
		outputStr += lines[loopedIndx] + "\n";
	}
	
	pg.text(outputStr, x, y);
}
 
Example 13
Source File: SlideTitle.java    From haxademic with MIT License 5 votes vote down vote up
public void update(PGraphics pg) {
	showProgress.update();
	
	if(titleQueued != null && showProgress.value() == 0) {
		title = titleQueued;
		titleQueued = null;
		showProgress.setTarget(1);	
	}
	
	if(title != null) {
		PG.setDrawCorner(pg);
		pg.noStroke();
		
		// get eased y
		float easedProgress = Penner.easeInOutCubic(showProgress.value());
		
		pg.pushMatrix();
		
		// draw bg
		pg.fill(0, opacity * easedProgress);
		pg.rect(0, 0, pg.width, pg.height); 

		// draw text
		// buffer.textLeading(font.getSize() * 0.75f);
		pg.fill(255, 255 * easedProgress);
		pg.textAlign(P.CENTER, P.CENTER);
		pg.textFont(font);
		pg.text(title, 0, 0, pg.width, pg.height);
		
		pg.popMatrix();
		PG.setDrawCenter(pg);
	}
}
 
Example 14
Source File: SlideCaption.java    From haxademic with MIT License 5 votes vote down vote up
public void update(PGraphics pg) {
	showProgress.update();
	
	if(captionQueued != null && showProgress.value() == 0) {
		caption = captionQueued;
		captionQueued = null;
		showProgress.setTarget(1);	
	}
	
	if(caption != null) {
		PG.setDrawCorner(pg);
		pg.noStroke();
		
		// get eased y
		float easedProgress = Penner.easeInOutCubic(showProgress.value());
		float curY = pg.height - height * easedProgress;
		
		pg.pushMatrix();
		
		// draw bg
		pg.fill(0, 127);
		pg.rect(0, curY, pg.width, height); // curY

		// draw text
		// buffer.textLeading(font.getSize() * 0.75f);
		pg.fill(255);
		pg.textAlign(P.CENTER, P.CENTER);
		pg.textFont(font);
		pg.text(caption, textOffsetY * 5f, curY - textOffsetY, pg.width - 50, height);
		
		pg.popMatrix();
		PG.setDrawCenter(pg);
	}
}
 
Example 15
Source File: MoireProposal.java    From haxademic with MIT License 5 votes vote down vote up
public void drawNumberToTexture(String str, PGraphics tex) {
	tex.beginDraw();
	tex.fill(0);
	tex.textFont(font);
	tex.textAlign(P.CENTER, P.TOP);
	tex.text(str, 0, p.height * 0.2f, p.width, p.height * 0.8f);
	tex.endDraw();
}
 
Example 16
Source File: Demo_MultichannelAudio_BeadsJack.java    From haxademic with MIT License 5 votes vote down vote up
public void update(PGraphics pg) {
	// draw
	pg.push();
	pg.noFill();
	pg.stroke(0, 255, 0);
	PG.setDrawCenter(pg);
	PG.setCenterScreen(pg);
	pg.ellipse(position.x, position.y, 20, 20);
	pg.pop();
	
	// set gains
	for (int i = 0; i < outputs; i++) {
		// get dist to speaker
		PVector speakerPos = stage.getSpeaker(i).position();
		float dist = speakerPos.dist(position);
		float distToGain = P.map(dist, 0, stage.radius() * 2, 1, 0);
		distToGain = P.constrain(distToGain, 0, 1);
		gains[i].setGain(distToGain);
		
		// draw debug to speakers
		pg.push();
		pg.noFill();
		pg.stroke(0, 255 * distToGain, 0);
		PG.setDrawCenter(pg);
		PG.setCenterScreen(pg);
		pg.line(position.x, position.y, speakerPos.x, speakerPos.y);
		float midX = (position.x + speakerPos.x) / 2f;
		float midY = (position.y + speakerPos.y) / 2f;
		pg.text(distToGain, midX, midY);
		pg.pop();
	}
}
 
Example 17
Source File: Demo_SpatialLighting.java    From haxademic with MIT License 5 votes vote down vote up
protected void drawLight(PGraphics pg) {
	PG.push(pg);
	pg.fill(color.colorInt());
	pg.translate(position.x * roomW, position.y * roomH, position.z * roomD);
	pg.sphere(20);
	// draw debug channel text
	pg.translate(25, 0, 0);
	pg.fill(0, 255, 0);
	pg.text(name, 0, 0);
	// pop
	PG.pop(pg);
}
 
Example 18
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();
}
 
Example 19
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 20
Source File: UITextInput.java    From haxademic with MIT License 4 votes vote down vote up
public void draw( PGraphics pg ) {
	pg.pushMatrix();
	PG.setDrawCorner(pg);
	
	// outline
	pg.noStroke();
	pg.fill(ColorsHax.BUTTON_OUTLINE);
	pg.rect(rect.x, rect.y, rect.width, rect.height);

	// draw input background
	if( pressed == true || focused == true ) {
		pg.fill(ColorsHax.BUTTON_BG_PRESS);
	} else if( over == true ) {
		pg.fill(ColorsHax.BUTTON_BG_HOVER);
	} else {
		pg.fill(ColorsHax.BUTTON_BG);
	}
	pg.rect(rect.x+1, rect.y+1, rect.width-2, rect.height-2);

	// set font on context
	boolean isUIComponent = (rect.height == IUIControl.controlH);
	if(isUIComponent) {  	// lock to UI size if we're a UI component
		IUIControl.setFont(pg);
		pg.fill(ColorsHax.BUTTON_TEXT);
	} else {
		PFont font = FontCacher.getFont(fontFile, fontSize);
		FontCacher.setFontOnContext(pg, font, ColorsHax.BUTTON_TEXT, 1f, align, PTextAlign.CENTER);
	}
	
	// get text width for cursor and to "scroll" text
	String displayText = value;
	float textW = pg.textWidth(displayText);
	int maxTextW = rect.width - padX * 2;
	while(textW > maxTextW) {
		displayText = displayText.substring(1);	// shift chars off the front of the text
		textW = pg.textWidth(displayText);
	}
	if(isUIComponent) {
		pg.text(displayText, rect.x + TEXT_INDENT, rect.y, rect.width, rect.height);
	} else {
		pg.text(displayText, rect.x + padX, rect.y - rect.height * 0.05f, rect.width, rect.height);
	}

	// draw blinking cursor
	cursorX = rect.x + padX + textW + cursorPadding;
	if(isUIComponent) cursorX -= 3;
	if(align == PTextAlign.CENTER) cursorX = rect.x + rect.width/2 + textW/2 + cursorPadding * 3f;
	if(focused == true) {
		pg.noStroke();
		pg.fill(ColorsHax.BUTTON_TEXT);
		if( P.p.millis() % 1000f > 500 ) pg.rect( cursorX, rect.y + rect.height * 0.25f, 2f, fontSize );
	}
	pg.popMatrix();
}