Thanks calsign, I've been struggling with this matter for some time now. I know about ControlFont. But what i need is to have a TextField receiving user input with latin characters. And I only got ControlFont to work on captions labels. In Text Fields, it's is giving me squares each time i press "option+n" ( or any other combination) which is mac way for making those characters. After the squares some letters came with the accent, some others no. Have a look as u can see labels are ok, but not the input field. It looks like is more an input thing than a font thing... Below the image, the code. It is just the example for TextField combined with the example for ControlFont.
- /**
- * ControlP5 controlFont.
- *
- * this example shows how to create a button with controlP5 (1), how to
- * load and use a PFont with controlP5 (2), apply a ControlFont to
- * the caption label of a button (3), and adjust the location of a
- * caption label using the style() property of a controller.
- *
- * by andreas schlegel, 2012
- */
- import controlP5.*;
- ControlP5 cp5;
- controlP5.Button b;
- String textValue = "";
- int buttonValue = 1;
- boolean isOpen;
- int myColorBackground = color(0,0,0);
- void setup() {
- size(700,400);
- smooth();
-
- cp5 = new ControlP5(this);
- // (1)
- // create some controllers
- cp5.addButton("button")
- .setValue(10)
- .setPosition(20,20)
- .setSize(100,30)
- .setId(1);
-
- b = cp5.addButton("buttonValue")
- .setValue(4)
- .setPosition(100,190)
- .setSize(200,200)
- .setId(2);
-
- // (2)
- // load a new font. ControlFont is a wrapper for processing's PFont
- // with processing 1.1 ControlFont.setSmooth() is not supported anymore.
- // to display a font as smooth or non-smooth, use true/false as 3rd parameter
- // when creating a PFont:
-
- PFont pfont = createFont("Arial",20,true); // use true/false for smooth/no-smooth
- ControlFont font = new ControlFont(pfont,30);
-
-
- // (3)
- // change the font and content of the captionlabels
- // for both buttons create earlier.
- cp5.getController("button")
- .getCaptionLabel()
- .setFont(font)
- .toUpperCase(false)
- .setSize(24)
- ;
-
- b.captionLabel()
- .setFont(font)
- .setSize(50)
- .toUpperCase(false)
- .setText("Çãéî")
- ;
- //
- cp5.addTextfield("input")
- .setPosition(20,100)
- .setSize(200,40)
- .setFont(font)
- .setFocus(true)
- .setColor(color(255,0,0))
- ;
- // (4)
- // adjust the location of a catiption label using the
- // style property of a controller.
- b.captionLabel().getStyle().marginLeft = 4;
- b.captionLabel().getStyle().marginTop = 36;
-
-
- }
- void draw() {
- background(buttonValue*10);
- // animate button b
- b.position().x += ((isOpen==true ? 0:-200) - b.position().x) * 0.2;
- text(cp5.get(Textfield.class,"input").getText(), 360,130);
- text(textValue, 360,180);
- }
- public void controlEvent(ControlEvent theEvent) {
- println(theEvent.controller().id());
- }
- public void button(float theValue) {
- println("a button event. "+theValue);
- isOpen = !isOpen;
- cp5.controller("button").setCaptionLabel((isOpen==true) ? "îüêçõ":"open");
- }