We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › frame around the applet / saving without a frame
Page Index Toggle Pages: 1
frame around the applet / saving without a frame (Read 457 times)
frame around the applet / saving without a frame
Jul 16th, 2008, 11:48pm
 
hello,
i have an applet, in which i want to draw and type. to get the drawings and typo right at the borderline of the window i want to draw a frame around the applet window which is not used for drawing, but which can i use to click and to set the typo right at the corners / borders of the applet window. is there a way to create a "dead zone" in my applet which is not affected by typing / drawing?

second: when saving my image i just want to save the area with the drawings and typo. the "dead zone" should be left outside of the window. so instead of saveFrame(); i need a restriction which area of the whole applet window i want to save. ...any suggestions how these two things could be realised?

thanks a lot!
Re: frame around the applet / saving without a fra
Reply #1 - Jul 17th, 2008, 10:21am
 
I think you must do your drawing in an off display PGraphics buffer.
On draw() calls, you update the buffer, then put it on display (with image() function). You can then use the saveFrame() function on this buffer to save only the useful part.
Re: frame around the applet / saving without a fra
Reply #2 - Jul 17th, 2008, 11:23am
 
void setup() {
 size (300,300);
 smooth();
background (0);
}

void draw() {
 rect (mouseX,mouseY,30,30);
}


this is my script an i need a "frame" around the applet where i can place buttons etc.
so how can i use the PGraphic? i tried it this way, but it does not work the way i want it (with a frame in which there will be no drawing and which is ignored by the mouse)

PGraphics drawing;
void setup() {
 size (300,300);
 smooth();
 drawing = createGraphics (200, 100, JAVA2D);
 drawing.beginDraw();
 drawing.background (0);
 drawing.endDraw();

}

void draw() {
 rect (mouseX,mouseY,30,30);
 drawing.beginDraw();
 drawing.rect (mouseX,mouseY,30,30);
 drawing.endDraw();
}

Re: frame around the applet / saving without a fra
Reply #3 - Jul 17th, 2008, 11:31am
 
There will be no drawing if you just don't call global functions like rect, only drawing.rect.
Or use the trick I saw elsewhere like:
screen = g;
g = drawing;

Mouse event: of course they happen over the whole displayed frame, but you can just ignore/reject these events if mouse coordinates are outside your rectangle.
Re: frame around the applet / saving without a fra
Reply #4 - Jul 17th, 2008, 11:44am
 
ok, and what sort of variable is "g" in screen = g?
i thought that i need to ignore the mouseEvents outside of my frame - which function do i have to use therefore?

Re: frame around the applet / saving without a fra
Reply #5 - Jul 18th, 2008, 1:29pm
 
g is the graphical context of Processing, but I couldn't make my trick working correctly...
The following code works:
Code:
PGraphics drawingArea;
int DA_X = 50, DA_Y = 10;
int DA_WIDTH = 200, DA_HEIGHT = 200;

void setup()
{
size(300, 300);
smooth();
background(0);
// Create a new graphical context
drawingArea = createGraphics(DA_WIDTH, DA_HEIGHT, JAVA2D);
drawingArea.beginDraw();
drawingArea.background(#00FF00);
drawingArea.endDraw();
}

void draw()
{
// Update display
image(drawingArea, DA_X, DA_Y);
}

void mousePressed()
{
if (mouseX < DA_X || mouseX >= DA_X + DA_WIDTH || mouseY < DA_Y || mouseY >= DA_Y + DA_HEIGHT)
return;
drawingArea.beginDraw();
for (int i = 0; i < 10; i++)
{
drawingArea.ellipse(random(DA_WIDTH), random(DA_HEIGHT), 5 + random(20), 5 + random(20));
}
drawingArea.endDraw();
}
Page Index Toggle Pages: 1