We are about to switch to a new forum software. Until then we have removed the registration on this forum.
hello,
i need help. :-S the programm should change the font, while i'm hovering about the list-Items.
import controlP5.*;
ControlP5 cp5;
DropdownList l;
PFont myFont;
void setup() {
size(1000, 500);
cp5 = new ControlP5(this);
l = cp5.addDropdownList("myList")
.setPosition(100, 100)
;
String[] fontList = PFont.list();
for (int i=0; i<fontList.length; i++) {
l.addItem(fontList[i], i);
}
myFont = createFont("Arial", 20);
}
void draw() {
background(90);
fill(l.isMouseOver() ? color (255, 255, 0) : 200);
if (l.isMouseOver()) {
//println(l.getItem((int)l.value()).getName());
myFont = createFont(l.getItem((int)l.value()).getName(), 20);
}
textFont(myFont);
text("Hellou i'm a text here..", 20, 30);
}
void controlEvent(ControlEvent theEvent) {
if (theEvent.isFrom("myList")) {
myFont = createFont(l.getItem((int)theEvent.value()).getName(), 20);
}
}
Answers
The problem is that you do createFont() with the name of the currently active list item (i.e. the item you clicked on). You'll need to figure out which one the mouse hovers over instead. ControlP5 has a method getMouseOverList() for that. This is my working solution, others might suggest a more elegant one.
thank you! ;)
but it doesn't fall back to the last font, when i go out. that means only when i klick a font it should save.
..yes, it shouldn't do it in each draw()
Then use two global Strings: one where you store the mouseover font and another where you store the original font. If you're hovering over the Dropdownlist, use the one font and when you're no longer over the list, use the original font. Assign the original font in the controlEvent() method. I'll leave the coding to you ;)
Yes" ^:)^ thanx colouredmirrorball !!: here my best try: