What steps will reproduce the problem? 1. Sketch the includes text with size 30 font 2. Create control with new ControlFont, size 8 PFont 3. Text drawn in the sketch gets set to the size 8 PFont
What is the expected output? What do you see instead?
The control's font should not effect the font specified in the sketch.
Please provide any additional information below.
It looks like the issue is in the PFontLabel in ControlFont.java. In the instance of a PFont, it sets theApplet.textFont(), but this never gets reset. It appears you can get the current PFont from theApplet like this:
PFont loadedFont = theApplet.g.textFont;
float loadedSize = theApplet.g.textSize;
So whenever PFontLabel sets the textFont, it needs to change it back when it's done.
I haven't tested the performance impact on doing this at a label level, might be best done before / after the controller draws (since a control could have hundreds of labels), perhaps checking isControlFont and the instance PFontLabel.
But, here is what it might look like if directly applied to the draw of the label:
@Override
public void draw(PApplet theApplet, Label theLabel) {
PFont loadedFont = theApplet.g.textFont;
float loadedSize = theApplet.g.textSize;
theApplet.textFont(pfont, size);
theApplet.fill(0xffff0000); //theLabel.getColor()
if (theLabel.isMultiline()) {
// theApplet.fill(255, 128, 0);
// theApplet.rect(0, 0, theLabel.getWidth(), theLabel.getHeight());
theApplet.fill(theLabel.getColor());
theApplet.textLeading(theLabel.getLineHeight());
theApplet.text(s, 0, 0, theLabel.getWidth(), theLabel.getHeight());
} else {
theApplet.translate(0, -top + 1);
debug(theApplet, theLabel);
theApplet.fill(theLabel.getColor());
theApplet.text(theLabel.getTextFormatted(), 0, 0);
if (RENDER_2X) {
theApplet.text(theLabel.getTextFormatted(), 0, 0);
}
}
theApplet.textFont(loadedFont, loadedSize);
}
This would prevent the PFont loaded in the ControlP5 control from overriding the sketch's font.
Comment #1
Posted on Aug 23, 2012 by Swift HippoProbably should also grab and set the alignment. If the user has the textAlign set to CENTER, the label is going to be in the wrong place.
PFont loadedFont = theApplet.g.textFont;
float loadedSize = theApplet.g.textSize;
int loadedAlign = theApplet.g.textAlign;
theApplet.textAlign(theApplet.LEFT);
....
theApplet.textFont(loadedFont, loadedSize);
theApplet.textAlign(loadedAlign);
Don't know if mode would also be needed. Not sure that get's changed much.
Comment #2
Posted on Aug 23, 2012 by Swift HippoFound out you also have to check to make sure the PFont is not null. I did this, which will force the "defaultFontOrDeath()" to run if it's null. Looks like this (file attached):
PFont loadedFont = theApplet.g.textFont;
float loadedSize = theApplet.g.textSize;
if (loadedFont == null) {
theApplet.textSize(loadedSize); //forces default font
loadedFont = theApplet.g.textFont;
}
- ControlFont.java 14.66KB
Comment #3
Posted on Aug 26, 2012 by Happy Rhinoimplemented with 0.7.6
Status: Fixed
Labels:
Type-Defect
Priority-Medium