i did not give up,
esp as i noticed a potential mistake using
rect
and pa.text
in the registered class.
but learned that with or without pa.
there is no effect on CANVAS or PNG.
and tried a other way, just use a function from “main”
in all 3 draw situations. ( draw / class draw / reg class draw )
and had the same but noticed a other mistake:
i forget to use a background()
and now i have a code what reproduces that error i see with G4P
that save("data/snap.png")
can not catch the content drawn by a registered class.
the meaning why it works without background?
does it indicate a wrong “timing” / execution sequence of save()
is above my level.
but clear is now, that it is NOT a error produced by the library G4P !
( tested Win 7 / Win 10 / Raspbian )
// canvas_save_to_PNG_3
// reproduce this problem without G4P
// ( difference to last test (2) is that now use BACKGROUND !)
//
Textclass textclass;
RegTextclass regtextclass;
String outfile = "data/snap.png";
void setup() {
size(400, 200);
// size(400, 200,P2D);
// size(400, 200,P3D);
// size(400, 200,FX2D); //?? [p] not work
textclass = new Textclass();
regtextclass = new RegTextclass(this);
println("use: key [p] to save canvas to "+outfile);
}
void draw() {
background(0, 200, 0);
noStroke();
draw_something("-a- this is from draw", 5, 20);
textclass.draw();
fill(200, 200, 0);
rect(15, 0, 25, height); // check draw order: shows reg class ON TOP ? runs after draw() ?
}
public class Textclass {
public void draw() {
draw_something("-b- this is from class", 5, 50);
}
}
public class RegTextclass { // "registered draw class" aka "self drawing class"
PApplet pa;
public RegTextclass(PApplet pa) {
this.pa = pa;
pa.registerMethod("draw", this);
}
public void draw() {
draw_something("-c- this is a registered class", 5, 80);
}
}
void draw_something(String txt, int x, int y ) {
fill(0, 0, 200);
rect(x, y, 20, 20);
fill(0);
textSize(20);
text(txt, x+30, y+15);
}
void keyPressed() {
if ( key == 'p' ) {
save(outfile);
println("save to "+outfile);
}
}