Loading...
Logo
Processing Forum
Hello!

I have to do a presentation about Processing next week. The task is, to show the internal working-process of processing. So I have to understand all the internal processes and the concept of the class and inheritance hierarchy in detail.

I couldn't find any documentation about that (except the comments in the SRC-Files in PGraphics ect, but they didn't help me that much).

Where does PGraphics use Graphics (of AWT)?

I can find "PGraphics g" in the source code of PGraphics.java but i can't find the spot where Processing is using the original "Graphics"-Context of AWT.

I would appreciate your help very much!

I also couldn't find any documentation about the class and inheritance hierarchy. Are there any overview diagramms?

How does the Packages (PGraphics, PImage, ...) work together?

For example, if I want to draw a line. Which steps (in which classes) does Processing perform to translate the Processing Code into real Java (AWT) code?

Can I see the processed/translated Java Code somewhere?

What steps are performed to translate the Processing-Code into Java-Code in detail (which procedures/classes a called, where's / when's the AWT-Graphics context called)?


Thank you very much!


Greetings, jake

Replies(6)

Just some stuff to get you started
 
The main class in Processing is PApplet and a lot of info can be got from the comments in the source code this class inherits from the AWT Applet class so is the main link between Processing / Java AWT
 
Before the Proceesing sketch can be compiled using the Java compiler javac.exe it must convert the sjetch code into a Java class. The easiest way to see the changes made is to take a sketch and export it as applet/application and look at the files created you will see a file named after the sketch but with a .java extension.
 
PImage is the base class for PGraphics which is the base class for PGraphics2D, PGraphics3D and PGraphicsJava2D and these can be used to provide offscreen rendering contexts
 
Processing has its own animation loop see run() and handleDraw() methods in PApplet soure code, PApplet also adds mouse and key event listeners to the sketch and provides standard AWT mouse event handlers which call the equivalent handler in Processing e.g.
 
public void mousePressed(MouseEvent e) { } // this AWT method is handled in PApplet
                                           // and calls the method
void mousePressed(MouseEvent e) { }        // in your Processing sketch
 
HTH and I am sure others can give you more detail than I can
 
Ah, PGraphicsJava2D used to be a sub-class of PGraphics2D, but I see it has been promoted to be a direct descendant of PGraphics.
You can find the AWT Graphics2D in PGraphicsJava2D, for example
I recommend opening the core source in Eclipse, it would ease exploration, visualization of hierarchies, etc.
Hello quarks and phi.lho,

thanks for your replies.

I already imported the src-code files from http://code.google.com/p/processing/source/browse/#svn%2Ftrunk%2Fprocessing%2Fcore%2Fsrc%2Fprocessing%2Fcore into eclipse

But in none of these source-files I could find the spot where processing is finally calling the Graphic of AWT (most times its called Graphics g). Can anyone help me? I thought that Processing uses AWT behind the scenes. But where?

I would also appreciate further eplainations about the whole process behend the scenes. Does anyone have a overview diagramm about the class and inheritance hierarchy and how the work togehter and which functions are called in the whole process?

When I look at the "exported" version of my sketch I only see a few more lines of code but not the whole java code. Or i made something wrong...

Is it possible, that processing uses an Image (of AWT) to draw onto it and just never uses a Graphics (via getGraphics() of AWT)? Is this the solution? I'm I heading to the right direction?

is it that?...
Copy code
  1. image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
        if (primarySurface) {
    //      image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
    //      offscreen = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
          offscreen = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
          g2 = (Graphics2D) offscreen.getGraphics();
        } else {
    //      image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
          // if the buffer's offscreen anyway, no need for the extra offscreen buffer
          g2 = (Graphics2D) image.getGraphics();
        }

Thank you very very much again!

Greetings, jake
Again, look at PGraphicsJava2D: you have a declaration public Graphics2D g2; and g2 is used everywhere, in smooth(), fillShape(), rotate(), and so on.
PGraphics2D uses a different approach, playing with pixels in a MemoryImageSource object.
Hello phi.lho,

thanks for your reply.

I looked at PGraphicsJava2D, several times. I understand that it uses Graphics2D g2 to set up its graphical context. So PGraphicsJava2D is used to draw and it's using PGraphics2D internally.

And PGraphics2D does use g2 = (Graphics2D) image.getGraphics(); to get an graphical context from the AWT-Framework.

Did I get it right?

You also wrote "PGraphics2D uses a different approach, playing with pixels in a MemoryImageSource object.". I would apreciate it very much, if you'd explain me, how this works in detail.


Thank you very much again!

Greetings, jake
" PGraphicsJava2D is used to draw and it's using PGraphics2D internally"
Not at all. Not with the latest versions at least (you have the SVN version?).
Graphics2D != PGraphics2D! Graphics2D is a Java/AWT class...

" PGraphics2D does use g2 = (Graphics2D) image.getGraphics(); to get an graphical context from the AWT-Framework"
No. At least, not in my SVN version, post-1.5. PGraphics2D doesn't a g2 variable at all, nor Graphics2D.

And see MemoryImageSource for more details on PGraphics2D.