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.
IndexProcessing DevelopmentLibraries,  Tool Development › G4P - GUI Inteface Library - latest release
Pages: 1 2 
G4P - GUI Inteface Library - latest release (Read 12433 times)
G4P - GUI Inteface Library - latest release
Jun 8th, 2009, 2:57pm
 
G4P is a newish library which provides a range of useful widgets (buttons, sliders, option buttons, checkboxes etc.) to control your sketch. It has a number of built in color schemes and the ability to create your own. The font used can be any font on your computer. The user can also change the transparency of the controls. It supports simple event handling with the ability to define separate event handlers for each control.

This latest release of G4P (V1.4) has a number of enhancements including:
  • cursor change over controls
  • multiple windows that can be used for output or controllers or both


Examples of these can be found at
http://gui4processing.lagers.org.uk/examples.html
it is also possible to download the library from this site.
Re: G4P - GUI Inteface Library - latest release
Reply #1 - Jun 10th, 2009, 9:28pm
 
This is great! Saves all the trouble of constantly changing your code just to see what happens when one constant changes.

I am having trouble with 3D, tho. I'm getting the following error:

Quote:
vertex() with x, y, and z coordinates can only be used with a renderer that supports 3D, such as P3D or OPENGL. Use a version without a z-coordinate instead.


even tho the GWindow object was created with OPENGL. It worked the other way around, doing the 3D on the main window, and having a spare window for controls, but I thought I'd mention it.
Re: G4P - GUI Inteface Library - latest release
Reply #2 - Jun 11th, 2009, 5:49am
 
If the program is short enough could you post your code here or send it as a personal message and I see what I can do about it.
Smiley

Edit:
Don't post the code I have been able to reproduce the error and I think I have found the bug in the code so will try and fix it tonight. : Cheesy
Re: G4P - GUI Inteface Library - latest release
Reply #3 - Jun 11th, 2009, 9:02am
 
Very nice. I've been working on a Lorenz Attractor viewer, it's not such a small program to post the code here, but I think I'll upload it somewhere and put it in the showcase. It's not complete, but it made me a proud nerd already.

I'm still trying to get the handlers, tho. Must the first parameter on addDrawHandler always be the applet? I'm trying to encapsulate a control panel on a class extended from GWindow, and I was hoping the drawMe function could be encapsulated, too. But if i try to set "this" as the "object to handle the event", as the reference puts it, I get a null pointer.

Anyway, your work has helped me a lot. I'll see about showcasing my application soon  Wink

This caffinated emoticon rocks.  Cheesy Wheeeeeeeeeeeeee.
Re: G4P - GUI Inteface Library - latest release
Reply #4 - Jun 11th, 2009, 12:36pm
 
The OPENGL in second window problem is now fixed V1.4.1 is now available for download either from the website or GoogleCode. Cheesy

addDrawHandler should work with any class. Lets assume the object to handle the draw method is called 'sketcher' and the method to do the drawing is called drawMe.

Things to watch out for:
  • the object sketcher must have been instantiated before calling this method
  • the drawMe method (in the sketcher class)  must have the signature
        void drawMe(GWinApplet app, GWinData data){    }
        If you are doing this in Eclipse then make it public void drawMe...

If you get these wrong then you will get an error message in Processing output panel under the code editor panel saying something like non existent method.

I assume you want to extend GWindow to get additional attributes for the Lorenz Attractor viewer.

If you do this then in the child class you should create a constructor than matches the one used in GWindow to create the window. In this constructor the first statement should call the GWindow ctor with the appropriate arguments and then does your stuff. Make sure that the child class has the drawMe method. Create an object of the child class e.g. sktcher and call

sketcher.addDrawHandler(sketcher, "drawMe");

When I added multiple windows to this library I envisioned that someone might create multiple GWindow objects but that each window needed it's own data so I created the GWinData class that could be extended and each window would have its own (child of) GWinData object. You can see this approach in the Mandelbrot example.

Anyway I am working on a new library for handling sprites (using bitmap images) so I think I will do some work on that now.

If you have problems I suggest that you post a message on the Syntax Questions thread as I look there on a regular basis.

Good luck Smiley


Re: G4P - GUI Inteface Library - latest release
Reply #5 - Jun 11th, 2009, 9:18pm
 
Quote:
The OPENGL in second window problem is now fixed V1.4.1 is now available for download either from the website or GoogleCode.


Great success!

Quote:
I assume you want to extend GWindow to get additional attributes for the Lorenz Attractor viewer.


Actually, the viewer is the main program. The child class is the control panel, and the main reason I wanted to encapsulate it was to get rid of all the slider and label code on my setup() function. So I made a LorenzController class, and in my constructor I have:

Code:

   super(_theApplet, "Visualizer", 650, 100, 600, 275, false, null); //that's the first line of code
   this.addData(new GWinData());
   
   // init stuff...
   
   this.addDrawHandler(this, "test"); //no such function
   this.addDrawHandler(o, "visualizerDraw"); //uninitialized object
   this.addDrawHandler(this, "visualizerDraw"); //correct?


first two lines compile fine, although they give me the "non existent method" warning. The third one is the killer.
Visualizer draw is simple as this:

Code:

 public void visualizerDraw(GWinApplet appc, GWinData data){
   appc.background(192, 220, 192);
 }


I'm now using state of the art technology in search of the null pointer. Obviously, that means setting println's all over the code with very descriptive messages such as "Did it happen?" and commenting out code I think bugs my app.

I found I'm getting the errors everywhere. It gets past the addDrawHandler just fine, but from there on pretty much anything else gives me a null pointer exception  Sad

First one is on GComponent.globalFont. Then when I create all my sliders and labels. Finally at some point I can't locate, after the constructor runs (possibly when it calls the drawing function? It never gets to run).

Anyway, it works fine if I set the drawing function outside the LorenzController class. Making it a method is probably nitpicky of me, but I just wish I would understand what was going on :/

Still, thanks for the help. I bet I'll be using your GUI lib for whatever project I come up with, it's very useful during development and it makes the final project much more useable, plus it's easy to set up.
Re: G4P - GUI Inteface Library - latest release
Reply #6 - Jun 12th, 2009, 2:24am
 
Quote:
Actually, the viewer is the main program. The child class is the control panel, and the main reason I wanted to encapsulate it was to get rid of all the slider and label code on my setup() function. So I made a LorenzController class, and in my constructor I have:


It would probaly be easier the other way round it would then be possible to have a single control panel that can control different views of the Lorenz Attractor in separate windows. Look at how  the Manelbrot code is used, but what you want to do is not impossible.

If you want the control panel to be sub window then the following might make it clearer how G4P works.

First consider a single window Processing sketch the main window is based on the PApplet class which contains a graphics context to draw on - all the commands such as stroke(), pushMatrix() etc use  the methods in PApplet and the graphics context.

When you create a GUI object such as GSlider the first attribute is always a reference to the PApplet object responsible for drawing the GUI component.

In the examples the GUI components are created in the main window and then added to the GWindow using the GWindow add() method - this changes the PApplet responsible for drawing the object to the one in the GWindow.

When you create a GWindow you are creating an object that extends the java.awt.Frame class to get the actual window  but the GWindow ctor also creates a new GWinApplet object which is a subclass of PApplet to get the drawing area.

Ok so going to your child class ctor

Code:
    super(_theApplet, "Visualizer", 650, 100, 600, 275, false, null); //that's the first line of code
   this.addData(new GWinData());
   
   // init stuff...

   this.addDrawHandler(this, "visualizerDraw"); //correct?



After the call to the GWindow ctor using super(....) the GWinApplet will have been created, it should be possible to use this in your GWindow subclass to create and add GUI components. The name of the GWinApplet object is 'embed' so in your ctor you could do something like

Code:
    super(_theApplet, "Visualizer", 650, 100, 600, 275, false, null); //that's the first line of code
   this.addData(new GWinData());
   
   // init stuff...
slider = new GSlider(embed, ...);
   this.addDrawHandler(this, "visualizerDraw"); //correct?



Where slider is a GSlider attribute of your child class. The event handlers for GSlider would also be in your child class.

Hope this helps.
Re: G4P - GUI Inteface Library - latest release
Reply #7 - Jun 12th, 2009, 11:05pm
 
It didn't Sad I mean, you gave a very good explanation and I learned from it, but amazingly I can't get it to work. But oh well, I think I'll crack my own head for awhile before bothering you again with that, thanks a lot Smiley

Just a last question: Do sliders send more than one event (something along "clicked", "released", etc)? I ask that because I am having some feedback trouble.

I want my sliders to respond to the attractor updates while playing, but the same sliders control the attractor. And when they are updated via setValue(), it forces an update on the attractor too. And since the sliders are ints, not floats, they kinda mess the whole thing. Is there a way to detect that the slider was updated by the user versus setValue()?

By the way, as soon as I fix this last thing I'll upload it to OpenProcessing.org, so you can see what use I'm making of your work! It's not complete as I picture it, but it's good enough to share.

edit - Found the eventType field. Unfortunately, when I change the slider, it gives the same CHANGED event as from setValue() Sad


isValueChanging() Cheesy I knew I should crack my own head for awhile
Re: G4P - GUI Inteface Library - latest release
Reply #8 - Jun 13th, 2009, 12:15am
 
Hm, exported the applet and index.html runs fine on my machine, but when I upload it to OpenProcessing, it can't find the G4P classes Sad Do I need to do export the library somehow?
Re: G4P - GUI Inteface Library - latest release
Reply #9 - Jun 13th, 2009, 11:43am
 
When I looked at Open Processing the other day I am sure there was a notice saying that it did not support OpenGL Processing sketches Undecided

Sorry misread the question will look into it tomorrow.
Re: G4P - GUI Inteface Library - latest release
Reply #10 - Jun 13th, 2009, 1:18pm
 
Yeah, I saw the OpenGL issue too. But that was OK, P3D didn't make it much uglier ^^
Re: G4P - GUI Inteface Library - latest release
Reply #11 - Jun 14th, 2009, 3:56am
 
When you export the sketch the guicomponents.jar file is included in the Applet folder so it should be in the zip file.

I have just tried it with the Mandelbrot example - no problems. Have a look here.

http://www.openprocessing.org/visuals/?visualID=2360

Make sure you zip the actual applet folder not just its contents.
Smiley
Re: G4P - GUI Inteface Library - latest release
Reply #12 - Jun 14th, 2009, 10:38am
 
Duh. I set the mode to P3D but forgot to erase the OpenGL import line.

Uploaded a new one (since I wasn't logged in when I uploaded the first Sad )

http://openprocessing.org/visuals/?visualID=2362 so there. Again, thanks for the lib and help, it would just be uninteractive eyecandy without it.
Re: G4P - GUI Inteface Library - latest release
Reply #13 - Jun 14th, 2009, 10:56am
 
Glad you managed to get it to work and I have been and had a look - looks great might have made the control window narrower though.

I have 2 monitors so I just moved the control window, having the Window as a Panel so they can both be in the same webpage sounds a good idea. (mmm.... I wonder if a Frame can be embedded in a Panel)

I might think about creating a GWebPanel class to complement GWindow class.

You might put a link to on the exhibition thread as you will get more viewers for your work there, although open processing seems to be popular too.  Cheesy
Re: G4P - GUI Inteface Library - latest release
Reply #14 - Jun 14th, 2009, 6:46pm
 
Control panel has blank space intended for future functionality, but I agree I could make it narrow while I don't implement it. There is a link on exhibtions already Cheesy
Pages: 1 2