kiza
YaBB Newbies
Offline
Posts: 24
Re: PGraphics text problem
Reply #2 - Dec 27th , 2008, 9:42pm
This is what I refered to as class B above. Draws a rectangle if it has no text, otherwise it displays text. In the end, the problem only happens when it does have some text as that's the only time it calls text functions.. class TextBox extends Window { String infoText; void display() { if (infoText.equals("")) { // the box is empty - draw a border to give a clue to its position noFill(); stroke(100); w = h; rect(x, y, w, h); } else { textFont(infoFont); textSize(fontSize); fill(160); text(infoText, x, y, w, h); textFont(font); } } } Here I save as an image: IMG2Save = createGraphics(ww, wh, JAVA2D); IMG2Save.beginDraw(); IMG2Save.colorMode(HSB, 360, 100, 100); IMG2Save.background(100, 0, 100); IMG2Save.strokeWeight(1); IMG2Save.smooth(); IMG2Save.stroke(strokeColor); IMG2Save.textAlign(CENTER, CENTER); IMG2Save.rectMode(CENTER); IMG2Save.imageMode(CENTER); // export connections for(int i = 0; i < numCons; i++) connections[i].exportIMG(); // export nodes IMG2Save.textFont(font); for(int i = 0; i < num; i++) nodes[i].exportIMG(); IMG2Save.endDraw(); IMG2Save.save("filename"); Each node in the exportIMG() function amongst other things does IMG2Save.textSize(currentFontSize); IMG2Save.fill(0); IMG2Save.text(string.getString(), x, y); if (underlined) IMG2Save.line(x - textWidth(text)/2, y + textAscent()/1.3, x + textWidth(text)/2, y + textAscent()/1.3); So the class A is the node.. So the problem is when I try to export when there is a TextBox instance with text being displayed. I don't see how it can influence IMG2Save.. For example, for textWidth(text) and textAscent() of the node, without and with a TextBox object on export I get 56 11.2 80 16 The fontsize of the text in TextBox is 10 and 14 for the node.. Sorry for not being clearer last time, hope it's better this time.. A lot longer read thought :)