processing.core.PFont Java Examples

The following examples show how to use processing.core.PFont. 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: PtextFont.java    From warp10-platform with Apache License 2.0 6 votes vote down vote up
@Override
public Object apply(WarpScriptStack stack) throws WarpScriptException {
  
  List<Object> params = ProcessingUtil.parseParams(stack, 1, 2);
      
  PGraphics pg = (PGraphics) params.get(0);

  if (2 == params.size()) {
    pg.parent.textFont((PFont) params.get(1));
  } else if (3 == params.size()) {
    pg.parent.textFont((PFont) params.get(1),
        ((Number) params.get(2)).floatValue());
  }

  stack.push(pg);
  
  return stack;
}
 
Example #2
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 #3
Source File: Demo_SocketClient.java    From haxademic with MIT License 6 votes vote down vote up
protected void drawServerLocation() {
	String fontFile = DemoAssets.fontOpenSansPath;
	PFont font = FontCacher.getFont(fontFile, 30);
	FontCacher.setFontOnContext(pg, font, p.color(255), 1f, PTextAlign.LEFT, PTextAlign.TOP);
	pg.text(serverAddress, 20, 10);
	pg.rect(20, 60, pg.width - 40, 2);
	
	PFont fontSm = FontCacher.getFont(fontFile, 16);
	if(socketClient.isConnected()) {
		FontCacher.setFontOnContext(pg, fontSm, p.color(0, 255, 0), 1f, PTextAlign.RIGHT, PTextAlign.TOP);
		pg.text("Connected", 540, 24);
	} else {
		FontCacher.setFontOnContext(pg, fontSm, p.color(255, 0, 0), 1f, PTextAlign.RIGHT, PTextAlign.TOP);
		pg.text("Disconnected", 540, 24);
	}
	
	socketLog.printToScreen(pg, 20, 80);
}
 
Example #4
Source File: Demo_SocketServer_fancy.java    From haxademic with MIT License 6 votes vote down vote up
protected void drawServerLocation() {
	if(wsServerAddress != null && webServerAddress != null) {
		String fontFile = DemoAssets.fontOpenSansPath;
		PFont font = FontCacher.getFont(fontFile, 30);
		FontCacher.setFontOnContext(pg, font, p.color(255), 1f, PTextAlign.LEFT, PTextAlign.TOP);
		pg.text(wsServerAddress, 20, 10);
		pg.rect(20, 60, pg.width - 40, 2);
		pg.text(webServerAddress, 20, 460);
		pg.rect(20, 510, pg.width - 40, 2);
		
		PFont fontSm = FontCacher.getFont(fontFile, 16);
		FontCacher.setFontOnContext(pg, fontSm, p.color(0, 255, 0), 1f, PTextAlign.RIGHT, PTextAlign.TOP);
		int numConns = socketServerHandler.getConnections().size();
		pg.text(numConns + " connections", 540, 24);
		
		pg.image(qrImage, pg.width - qrImage.width - 20, 530);
		DebugView.setTexture("qr", qrImage);
	}
}
 
Example #5
Source File: Demo_MultichannelAudio_BeadsJack.java    From haxademic with MIT License 6 votes vote down vote up
protected void drawApp() {
	p.background(0);
	
	// auto trigger
	if (p.frameCount % 60 == 0) {
		// playAll();	
		sounds[0].play(false);
	}
	
	// update sounds' position
	for (int i = 0; i < sounds.length; i++) {
		float soundRads = p.frameCount * 0.05f * (i+1);
		sounds[i].updatePosition(P.cos(soundRads) * stage.radius() * (1-(i+1)*0.1f), P.sin(soundRads) * stage.radius() * (1-(i+1)*0.1f));
		if(i == 0) sounds[i].updatePosition(p.mouseX - p.width/2, p.mouseY - p.height/2); // mouse control
		sounds[i].update(p.g);
	}
	
	// draw stage
	stage.update(p.g);
	
	// set font
	PFont font = FontCacher.getFont(DemoAssets.fontOpenSansPath, 20);
	FontCacher.setFontOnContext(p.g, font, 255, 1, PTextAlign.LEFT, PTextAlign.TOP);
}
 
Example #6
Source File: Demo_MultichannelAudio_NativeMultipleSoundcard.java    From haxademic with MIT License 6 votes vote down vote up
protected void drawApp() {
		p.background(0);
		
		// set font
		PFont font = FontCacher.getFont(DemoAssets.fontOpenSansPath, 20);
		FontCacher.setFontOnContext(p.g, font, 255, 1, PTextAlign.LEFT, PTextAlign.TOP);
		
		// write cur lineInfo
//		int lineIndex = UI.valueInt(LINE_INDEX);
//		lineIndex = P.constrain(lineIndex, 0, linesOut.size() - 1);
		// p.g.text(""+linesOut.get(lineIndex) + FileUtil.NEWLINE + FileUtil.NEWLINE, 300, 100, 500, 1000);
		
		// show mixer info
		int mixerIndex = UI.valueInt(MIXER_INDEX);
		mixerIndex = P.constrain(mixerIndex, 0, mixers.size() - 1);
		p.g.text("Mixer:" + mixers.get(mixerIndex).getMixerInfo() + FileUtil.NEWLINE, 300, 100, 500, 1000);
	}
 
Example #7
Source File: Demo_ImageUtil_imageCroppedEmptySpace3.java    From haxademic with MIT License 6 votes vote down vote up
public void setup()	{

		
		croppedText = p.createImage(128, 128, P.ARGB);
		
		int fontSize = 100;
		PFont font = p.createFont( FileUtil.getPath("fonts/bitlow.ttf"), fontSize );
//		PFont font = p.createFont( FileUtil.getPath("fonts/HelveticaNeueLTStd-Blk.ttf"), fontSize );
		fitText = new FitTextBuffer(font, p.color(127));
		fitText.updateText("HEYO00");
	}
 
Example #8
Source File: DrawUtils.java    From PapARt with GNU Lesser General Public License v3.0 6 votes vote down vote up
static public void drawText(PGraphicsOpenGL pg3d, String text, PFont font, int x, int y) {
        
        pg3d.pushMatrix();
        pg3d.translate(x, y);
        pg3d.text(text, 0, 0);
        pg3d.popMatrix();
        
//        pg3d.pushMatrix();
//        pg3d.translate(x, y);
//        pg3d.scale(-1, 1, 1);
//        pg3d.rotate(PApplet.PI);
//        pg3d.textMode(PApplet.MODEL);
//        pg3d.textFont(font);
//        pg3d.text(text, 0, 0);
//        pg3d.popMatrix();
    }
 
Example #9
Source File: DrawUtils.java    From PapARt with GNU Lesser General Public License v3.0 6 votes vote down vote up
static public void drawText(PGraphicsOpenGL pg3d, String text, PFont font, int fontSize, int x, int y) {
        pg3d.pushMatrix();
        pg3d.translate(x, y);
        pg3d.textMode(PApplet.MODEL);
        pg3d.textFont(font, fontSize);
        pg3d.text(text, 0, 0);
        pg3d.popMatrix();

        
//        pg3d.pushMatrix();
//        pg3d.translate(x, y);
//        pg3d.scale(-1, 1, 1);
//        pg3d.rotate(PApplet.PI);
//        pg3d.textMode(PApplet.MODEL);
//        pg3d.textFont(font, fontSize);
//        pg3d.text(text, 0, 0);
//        pg3d.popMatrix();
    }
 
Example #10
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 #11
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 #12
Source File: AppGenerator.java    From haxademic with MIT License 5 votes vote down vote up
protected void drawApp() {
	p.background(0);
	
	// info
	String fontFile = DemoAssets.fontOpenSansPath;
	PFont font = FontCacher.getFont(fontFile, 20);
	FontCacher.setFontOnContext(p.g, font, p.color(255), 2f, PTextAlign.LEFT, PTextAlign.TOP);
	p.text("Press spacebar to generate project:" + FileUtil.NEWLINE + 
		   newProjectName + FileUtil.NEWLINE +
		   "Please be careful." + FileUtil.NEWLINE
		   , 20, 20);

	// print log
	log.printToScreen(p.g, 20, 200);
}
 
Example #13
Source File: Demo_DateUtil.java    From haxademic with MIT License 5 votes vote down vote up
protected void drawApp() {
	p.background(0);
	
	// set font
	PFont font = FontCacher.getFont(DemoAssets.fontOpenSansPath, 18);
	FontCacher.setFontOnContext(p.g, font, p.color(255), 1.2f, PTextAlign.LEFT, PTextAlign.TOP);
			
	// draw debug output
	p.text(
			"Processing date components :: " + P.year() + "/" + P.month() + "/" + P.day() + FileUtil.NEWLINE + 
			"Processing time components :: " + P.hour() + ":" + P.minute() + ":" + P.second() + FileUtil.NEWLINE +
			"Uptime (timeFromSeconds()) :: " + DateUtil.timeFromSeconds((int) DateUtil.uptimeSeconds(), true) + FileUtil.NEWLINE + 
			"DateUtil.todaySeconds() :: " + DateUtil.todaySeconds() + FileUtil.NEWLINE + 
			"DateUtil.todayHours() :: " + DateUtil.todayHours() + FileUtil.NEWLINE + 
			"DateUtil.dayOfWeek() :: " + DateUtil.dayOfWeek() + FileUtil.NEWLINE +
			"DateUtil.weekOfYear() :: " + DateUtil.weekOfYear() + FileUtil.NEWLINE +
			"Current time (currentTime(true, false, true)) :: " + DateUtil.currentTime(false, false, true) + FileUtil.NEWLINE + 
			"Current time (secondsToFormattedTime()) :: " + DateUtil.secondsToFormattedTime((int) DateUtil.todaySeconds(), false, false) + FileUtil.NEWLINE + 
			"uptimeHours() :: " + DateUtil.uptimeHours() + FileUtil.NEWLINE + 
			"DateUtil.timeIsBetweenHours() :: " + DateUtil.timeIsBetweenHours(23f, 9f) + FileUtil.NEWLINE + 
			"Millis.fmtLong() :: " + DateUtil.fmtLong(p.millis()) + FileUtil.NEWLINE +
			"Millis.fmtShort() :: " + DateUtil.fmtShort(p.millis()) + FileUtil.NEWLINE +
			"Millis.parse('1 second') :: " + DateUtil.parse("1 second") + FileUtil.NEWLINE +
			"Millis.parse('1 minute') :: " + DateUtil.parse("1 minute") + FileUtil.NEWLINE +
			"Millis.parse('1 day') :: " + DateUtil.parse("1 day") + FileUtil.NEWLINE +
			""
	, 40, 40);
}
 
Example #14
Source File: Demo_SocketClient_words.java    From haxademic with MIT License 5 votes vote down vote up
protected void drawText() {
		// do feedback
		FeedbackRadialFilter.instance(p).setAmp(0.1f);
		FeedbackRadialFilter.instance(p).applyTo(pg);
//		FeedbackMapFilter.instance(p).setMap(simplexNoise.texture());
//		FeedbackMapFilter.instance(p).setAmp(0.001f);
//		FeedbackMapFilter.instance(p).setBrightnessStep(-0.001f);
////		FeedbackMapFilter.instance(p).setAlphaStep(UI.value(feedbackAlphaStep));
////		FeedbackMapFilter.instance(p).setRadiansStart(UI.value(feedbackRadiansStart));
////		FeedbackMapFilter.instance(p).setRadiansRange(UI.value(feedbackRadiansRange));
//		FeedbackMapFilter.instance(p).applyTo(pg);
		
		BrightnessStepFilter.instance(p).setBrightnessStep(-0.001f);
		BrightnessStepFilter.instance(p).applyTo(pg);
		
		// only draw words one frame at a time
		if(curWord == null) return;
		
		// draw centered word
		int[] colorArray = ColorsHax.COLOR_GROUPS[5];
		int randomColor = colorArray[MathUtil.randIndex(colorArray.length)];
		pg.pushMatrix();
		PFont font = FontCacher.getFont(DemoAssets.fontOpenSansPath, 70);
		FontCacher.setFontOnContext(pg, font, randomColor, 1f, PTextAlign.CENTER, PTextAlign.CENTER);
		pg.noStroke();
		pg.text(curWord, MathUtil.randRangeDecimal(-pg.width/3, pg.width/3), MathUtil.randRangeDecimal(-pg.height/3, pg.height/3), pg.width, pg.height);
		pg.popMatrix();
		
		// clear word queue
		curWord = null;
	}
 
Example #15
Source File: FontCacher.java    From haxademic with MIT License 5 votes vote down vote up
public static PFont getFont(String fontPath, float fontSize) {
	String key = fontPath + "-" + fontSize;
	if(fonts.containsKey(key) == false) {
		fonts.put(key, P.p.createFont(FileUtil.getPath(fontPath), fontSize));
	}
	return fonts.get(key);
}
 
Example #16
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 #17
Source File: Demo_StrokeText.java    From haxademic with MIT License 5 votes vote down vote up
protected void drawApp() {
	p.background(0);
	
	// set font
	PFont font = FontCacher.getFont(DemoAssets.fontInterPath, 90);
	FontCacher.setFontOnContext(p.g, font, p.color(255), 1.4f, PTextAlign.LEFT, PTextAlign.TOP);
	
	// draw text
	StrokeText.draw(p.g, "Hello", 300, 100, p.color(0, 255, 0), p.color(0), UI.value(thickness), UI.valueInt(resolution));

	// draw text that wraps
	font = FontCacher.getFont(DemoAssets.fontInterPath, 20);
	FontCacher.setFontOnContext(p.g, font, p.color(255), 1.4f, PTextAlign.LEFT, PTextAlign.TOP);
	StrokeText.draw(p.g, "Hello this will wrap if we have enough text", 300, 300, 150 + FrameLoop.osc(0.02f, 0, 150), 1000, p.color(0, 255, 255), p.color(0), UI.value(thickness)/2f, UI.valueInt(resolution));
}
 
Example #18
Source File: Demo_FontCacher.java    From haxademic with MIT License 5 votes vote down vote up
protected void drawApp() {
	background(0);

	String fontFile = DemoAssets.fontOpenSansPath;
	PFont font = FontCacher.getFont(fontFile, 42);
	FontCacher.setFontOnContext(p.g, font, p.color(255), 1f, PTextAlign.LEFT, PTextAlign.TOP);
	p.text(fontFile, 20, 20);
	
	String fontFile2 = DemoAssets.fontDSEG7Path;
	font = FontCacher.getFont(fontFile2, 18);
	FontCacher.setFontOnContext(p.g, font, p.color(0, 255, 0), 1.8f, PTextAlign.LEFT, PTextAlign.TOP);
	p.text(fontFile2 + FileUtil.NEWLINE + fontFile2, 20, 100);
}
 
Example #19
Source File: Demo_StringUtil.java    From haxademic with MIT License 5 votes vote down vote up
protected void drawApp() {
	p.background(0);
	
	logOut.printToScreen(p.g, 20, 20);

	// print one-offs 
	PFont font = FontCacher.getFont(DemoAssets.fontOpenSansPath, 12);
	FontCacher.setFontOnContext(pg, font, P.p.color(255), 1f, PTextAlign.LEFT, PTextAlign.TOP);
	
	p.text(StringUtil.subStringByProgress("HELLOOOOOO", -1f + FrameLoop.count(0.02f) % 2f), 400, 20);
}
 
Example #20
Source File: _prtextfont.java    From mesh with MIT License 5 votes vote down vote up
/**
 * CAUTION not thread safe when called outside of setup/draw func
 */
public static Tuple invoke(final Object arg)
{
    if (Processing.INSTANCE != null)
    {
        final PFont font = (PFont)arg;
        if (font != null)
            Processing.INSTANCE.textFont(font);
    }

    return Tuple.UNIT;
}
 
Example #21
Source File: DemoAssets.java    From haxademic with MIT License 4 votes vote down vote up
public static PFont fontRaleway(float fontSize) {
	if(fontRaleway == null) fontRaleway = P.p.createFont( FileUtil.getPath(fontRalewayPath), fontSize );
	return fontRaleway;
}
 
Example #22
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();
}
 
Example #23
Source File: DemoAssets.java    From haxademic with MIT License 4 votes vote down vote up
public static PFont fontOpenSans(float fontSize) {
	if(fontOpenSans == null) fontOpenSans = P.p.createFont( FileUtil.getPath(fontOpenSansPath), fontSize );
	return fontOpenSans;
}
 
Example #24
Source File: IUIControl.java    From haxademic with MIT License 4 votes vote down vote up
public static void setFont(PGraphics pg) {
	PFont font = FontCacher.getFont(DemoAssets.fontOpenSansPath, 11);
	FontCacher.setFontOnContext(pg, font, P.p.color(255), 1f, PTextAlign.LEFT, PTextAlign.TOP);
}
 
Example #25
Source File: DemoAssets.java    From haxademic with MIT License 4 votes vote down vote up
public static PFont fontInter(float fontSize) {
	if(fontInter == null) fontInter = P.p.createFont( FileUtil.getPath(fontInterPath), fontSize );
	return fontInter;
}
 
Example #26
Source File: DemoAssets.java    From haxademic with MIT License 4 votes vote down vote up
public static PFont fontDebug() {
	if(fontDebug == null) fontDebug = P.p.createFont( FileUtil.getPath(fontInterPath), 11 );
	return fontDebug;
}
 
Example #27
Source File: FitTextSourceBuffer.java    From haxademic with MIT License 4 votes vote down vote up
public FitTextSourceBuffer(PFont font, int color) {
	this.font = font;
	this.color = color;
	buffer = P.p.createGraphics(4096, P.ceil(font.getSize() * 1.1f));
	buffer.smooth(8);
}
 
Example #28
Source File: DemoAssets.java    From haxademic with MIT License 4 votes vote down vote up
public static PFont fontBitlow(float fontSize) {
	if(fontBitlow == null) fontBitlow = P.p.createFont( FileUtil.getPath(fontBitlowPath), fontSize );
	return fontBitlow;
}
 
Example #29
Source File: DemoAssets.java    From haxademic with MIT License 4 votes vote down vote up
public static PFont fontHelloDenver(float fontSize) {
	if(fontHelloDenver == null) fontHelloDenver = P.p.createFont( FileUtil.getPath(fontHelloDenverPath), fontSize );
	return fontHelloDenver;
}
 
Example #30
Source File: DemoAssets.java    From haxademic with MIT License 4 votes vote down vote up
public static PFont fontOhmegaSans(float fontSize) {
	if(fontOhmegaSans == null) fontOhmegaSans = P.p.createFont( FileUtil.getPath(fontOhmegaSansPath), fontSize );
	return fontOhmegaSans;
}