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.
Pages: 1 2 
Work on GUI Libary (Read 6386 times)
Work on GUI Libary
Jun 9th, 2005, 10:40pm
 
Philipp wrote on Jun 9th, 2005, 9:46pm:
Hey, I'm working on putting together a MyGUI library and wanted to understand the best way to access mouse events.

Hi Markavian! I've put the finishing touches on a first release of my own GUI library today, which is a wrapper over a lot of components found in the awt. I was going to release it this weekend, together with a redesigned version of my website. Now I'm feeling awkward about not having announced it beforehand. I've kept quiet about it because I didn't want to make any promises I can't keep.
Is there an etiquette for the library writing procedure or a precedent in this respect
Markavian, how far are you with your own library

Hi Phillip, the GUI class I've been working on (called MyGUI) is still in its early stages. I've been trying to find out whats possible and what is the easiest/best way to implement such as a class.
The version I'm working on at the moment is a test to get something working and then I was going to open up discussion for improving it and figuring out what components should be included.

I'd like to see the progress you've made to see if there's any similar ground or good ideas/features tha can be shared.

The structure I'm working towards at the moment is as follows:
MyGUI - A collection of compatable user inteface objects designed to work with processing.
MyGUIObject - An interface for creating GUI objects for processing that are to be used with the MyGUI collection class.
MyGUIStyle - A simple collection of colours and a font(s) that is used to give a constant look and feel to all elements drawn through processing.

The intention is that you create a MyGUI object, set a MyGUIStyle and then add MyGUIObjects to the MyGUI object and it will handle all the mouse states and draw functions with no extra commands in the main code.

e.g.: Code:

MyGUI gui;
MyGUIButton button1;

void setup() {
size(300, 200);
background(153);
gui = new MyGUI(this);
button1 = new MyGUIButton(50, 50, "Hello");
gui.add(button1);
}

void draw() {

}

void actionPerformed (MyGUIEvent e) {
print ("Component: " + e.getSource().getLabel());
print ("Message: " + e.getMessage());
}

Its still in early stages of development like I said. I'm hoping once the basic collection class is ready and I have the a button object sorted I can release it before developing new components.
Re: Work on GUI Libary
Reply #1 - Jun 10th, 2005, 12:58pm
 
Good morning!

My approach is similar, but less object-oriented:
I have a single SpringGUI object that keeps track of all GUI elements you add to your program. You can create new elements by calling methods like
Code:
gui.addButton(name, text, x, y, width, height); 


and query or change their attributes with methods like
Code:
gui.setEnabled(name, value); 


or
Code:
String type = gui.getElementType(name); 



Additionally you must implement a method named
Code:
void handleEvent(String[] parameters) 


that will be called whenever an event takes places. This method gives you an array of parameters containing information about the events that took place.


Technically, the SpringGUI library evolved because I wanted to migrate a few old java programs to Processing and looked for a way to hack in java.awt components.
The source code is available, but I must say that there is much to be streamlined about it. I didn't initially set out to include as many components as there are, and by the miracle of copy and paste, each of them creates their own listeners which was probably a bad idea. Also, Ben's reply about addMouseListener to your last thread applies to my code as well, so I'll have to rethink the code sooner than I thought.
But for what it's worth, everything seems to be working quite well. There are a few known MacOS issues, but I'm confident they'll get worked out as soon as I get prolonged access to a Mac system.

I have uploaded the library and documentation. (The menu links at the bottom of the page are not working yet, as this is part of a yet incomplete redesign)

http://www.repeatwhiletrue.com/SpringGUI/index.html
Re: Work on GUI Libary
Reply #2 - Jun 11th, 2005, 3:57am
 
Hi Phillip,

I'm really impressed by the examples on your website. I think you've done an excellent job to include AWT components in Processing which is far more then I could have hoped for.

My suggestions are as follows:
1) I think you should improve the handleEvent(String[] param) method to be more user friendly. Looking at accessing the different paramaters doesn't make for easy reading and if preferable you would want to make it as easy as possible for people to use SpringGUI.

2) Why aren't you using JavaX / Swing components? Those are lightweight versions (and often more featureful) then the heavyweight AWT components? If you find time to revise what you've done then I think you should implement those instead of the older AWT ones.

As for my project, the MyGUI class and MyGUI objects that I've set up use Processing's own drawing methods. I need to add more documentation to it before I can release but I'll be happy to put out the source code at an early stage so that people can write their own MyGUI objects.

In the mean time, I'll make sure I trial your system out, I really like what I see.

Best regards,
Re: Work on GUI Libary
Reply #3 - Jun 11th, 2005, 11:20am
 
Hi Markavian,

Thanks for the compliments!
I agree that the handleEvent method is not as user friendly as it could possibly be. I figured that my approach of not making it object-oriented would be best suited by passing the parameters as an array.
However, the first three parameters are always the same (type of component, name of component and name of event), so once you get the hang of it, it's not hard.

There are, in fact, methods that make handleEvent more user-friendly for beginners: these are getElementType(param), getElementName(param) and getEventType(param), and they extract the respective information from the array, potentially making the code more readable.
They're in the reference under
http://www.repeatwhiletrue.com/SpringGUI/beginner.html


As for why I didn't use Swing, that's actually a question in the FAQ: The answer is that Swing's lightweight components don't mix well with the Processing applet's heavyweight Panel container. The way I see it, the applet's background always gets drawn on top of the Swing components, resulting - at best - in flickering.


If you're going for a library that uses only Processing's drawing methods, I definitely think you should continue with that effort -: while I suspect that awt components gain some performance advantage by being OS native, they have a nasty tendency to have slightly different sizes over different platforms. Additionally, awt components' functionality is not easy to extend, they have an opaque background and they aren't all that versatile.
I'd really applaud a common framework for Processing widgets... apart of giving Processing applets a distinctive look and feel, it would also be an incentive to create more far out interface components with the same look and feel and familiar code structures. I'm sure the two libraries would happily coexist, each suitable for different applications.

cheers,
Philipp
Re: Work on GUI Libary
Reply #4 - Jun 13th, 2005, 2:43am
 
Hi Phillip,

If you haven't seen my other post in the Community Discussions section yet then I've released an early test version of the MyGUI classes.
You can find a working example here:
http://mkv25.net/applets/MyGUI_a2/  

The object orientated approach works very well in my opinion. I've tried to take full advantage of the integration with processing's drawing functions using _scale and _rotate variables to quickly modify the positioning of components.

If you look at the code for receiving events, although I've used guiObj1.setActionCommand() and event.getActionCommand(), you can also use if(event.getSource() == guiObj1) which looks and works very friendly.

The other very useful method is guiObj1.isDragged(); which returns true for a mouse activated state, used in my example to keep methods and values constantly updated.

I need to add documentation to this project, I'm hoping to add Javadoc comments, and make a website like yours. I like the documentation you published for SpringGUI.

Best regards,
- Markavian
Re: Work on GUI Libary
Reply #5 - Jun 13th, 2005, 1:01pm
 
Hi!

The scalable image-rollover buttons in your example are awesome and definitely very useful (looking forward to the first OS X Dock port to MyGUI. :) )! If I may make one suggestion, I think they'd look even better if their lighting would not become a bit inconsistent when they are rotated. Alternatively, there could be an option to render them completely flat (like they appear when they are not depressed and the mouse cursor is outside them).

I also like how you appear to be able to name your own action commands in MyGUI. This is definitely a feature that makes the code very readable.

I'm very curious about how much of a framework MyGUI actually provides, in terms of how much it handles for the user willing to extend it, and what it leaves to be done manually. A good example of what I mean may be how I would implement a text input field with MyGUI. Would it handle such things as focus and mouse-overs automatically? Would it delegate keyEvents to the MyGUI element currently in focus?
If you get around to writing your documentation, I think it would be awesome if you found the time to write a short programmer's guide on these issues and general points on how to extend MyGUI.

Great work so far,
Philipp
Re: Work on GUI Libary
Reply #6 - Jun 15th, 2005, 4:50am
 
Quote:
If I may make one suggestion, I think they'd look even better if their lighting would not become a bit inconsistent when they are rotated.

I thought about this and agree that flat shading is more suitable because of the rotation. If I wasn't going to include rotation features then I'd keep the lighting because I think it looks so much better. I have already updated my current components - below is my crib sheet that I refer to / update before programming the components:

...


Quote:
I'm very curious about how much of a framework MyGUI actually provides, in terms of how much it handles for the user willing to extend it.

If you look at the MyGUIObject class you get an idea of the features I think should be common in all objects.
To summarise, each MyGUIObject has all these variables available:
- public MyGUI _parent;
- public MyGUIStyle _style;
- public int _x, _y, _width, _height;
- public int _id;
- public float _rotation; // radians
- public float _scale = 1.0;
- public boolean _visible = true;
- public boolean _disabled = false;
- public String _actionCommand = "";
- protected int localMouseX, localMouseY;
- protected boolean dragged, hover, lastHover;

And all these methods:
- MyGUIObject()
- MyGUIObject(int x, int y)
- boolean hasFocus()
- boolean isDragged()
- void mousePressed()
- void mouseReleased()
- void mouseDragged()
- void draw()
- void drawStates()
- void setID(int newID)
- void setParent(MyGUI parent)
- void setActionCommand(String command)
- void setStyle(MyGUIStyle style)
- void enable()
- void disable()
- void rotateDegrees(float degs)
- void rotateRadians(float rads)
- boolean checkForHit()

And I'm still adding to them where I feel a common feature can be added. The MyGUI object automatically calls the mousePressed(), mouseReleased() etc. methods, and I've included basic logic for setting up and tracking the different states. checkForHit() is most important because it tracks the mouse position relative to the bounding box of the object (based on _x, _y, _width and _height).

Programmers wanting to extend MyGUI with their own objects will have to consider all the different draw states by using the methods and boolean values provided, and can write their own custom responses to mouse and key events by simply overriding methods in the parent class. A good example of this is the MyGUIDragButton which extends MyGUIButton, which in-turn extends MyGUIObject.

Quote:
A good example of what I mean may be how I would implement a text input field with MyGUI. Would it handle such things as focus and mouse-overs automatically?

This is something I will am considering, I just want to get some simpler objects done first. The default mouse methods of MyGUIObject already track things like when the object has focus, checkForHit is used to set the hover state directly, there is the isFocused() method to see if it has focus (as only one object can have focus at a time). a MyGUITextInput will be very similar to a MyGUIButton except it will have complex rendering logic for the positioning of the text as you type, positioning of the cursor and filtering of characters. Then I suppose I'd have to consider MyGUITextArea - a multiline version?

Quote:
I think it would be awesome if you found the time to write a short programmer's guide on these issues and general points on how to extend MyGUI.

I definitely will be writing lots of documentation for this project, I just need to improve/optimize the core so that its heading in the right direction.

Thanks for your input.
- Markavian
Re: Work on GUI Libary
Reply #7 - Jun 18th, 2005, 12:47am
 
Latest update:
http://mkv25.net/applets/MyGUI_a4/

I've written in support for MyGUIGroup objects. _visible and _disabled states now work.

Rotation system has been changed from radians to degrees to be more user friendly (its easier to round up to 90 degrees then PI).

Flat shading has been applied to all current components. A disabled draw state has been added. I wrote a more advanced tint function in MyGUIStyle so that tints can be applied at a % amount (between 0 min and 1 max tint).

There is a bug where multiple components in overlaying groups can both have focus at the same time, I couldn't program a fix for this, so dragging the button around may interact a bit funny - I'm not too concerned, people probably won't want to use that sort of feature too often (touch wood).

Next up I'm hoping to start programming the other objects/components on my list.
Re: Work on GUI Libary
Reply #8 - Jun 23rd, 2005, 12:52am
 
Latest update:

Quote:
Progress! I've figured out how to properly put together my library, so that it works as a library, and works with processing:

A dawn of a new age? Perhaps Smiley
Here I show my humble random squares applet which utilises the MyGUI class to give control of the squares over to the mouse, no more hidden key board commands I say!

http://mkv25.net/applets/guiRandomSquares/

If you want to use/play I've published the class here: Unzip into your processing-install/libraries/ folder
http://mkv25.net/MyGUI/

No documentation at all, tons of features. Email processing@mkv25.net for info.
Re: Work on GUI Libary
Reply #9 - Jun 27th, 2005, 4:31am
 
Latest update:

Quote:
Daa daa - the latest and greatest:

http://mkv25.net/MyGUI/
Download the latest version here.

I've also spent all of today typing away making Javadoc tags in eclipse. The joy!. Not quite finished with the documentation yet but I've uploaded what I've got.

I will be putting together an actual examples website for MyGUI at somepoint as well. For the moment, the javadoc doc is the best source of information for you.

Installation : unzip MyGUI_####.zip into processing-####/libraries/ so that it creates the document structure:
processing-####/libraries/MyGUI/libary/MyGUI.jar

Heres are test examples of implementing MyGUI:
http://mkv25.net/applets/baseConversion/
http://mkv25.net/applets/guiTest3/
http://mkv25.net/applets/guiRandomSquares/
Re: Work on GUI Libary
Reply #10 - Oct 12th, 2005, 12:19am
 
I've been trying to create an array of 14 sliders using MyGUI with some problems.  For some reason the last 3 sliders don't show up.  It seems like 12 is the max number of sliders possible.  Is this the case? and if so, is there any way around it?
Re: Work on GUI Libary
Reply #11 - Nov 3rd, 2005, 3:48am
 
Hey cheewee2000,

Sorry I've not been around in the past month to answer your question.

Yes, there is a basic limit to the number of MyGUI components you can add if you use the basic constructor.

To add more then 12 components, you need to use this constructor:
MyGUI gui = new MyGUI(this, 20);

Where 20 is the number of 'slots' you want the MyGUI handler to handle. I never got round to implementing a dynamicly expanding array. I assume that for larger projects the array could be increased.

Please give this a go, I'd be interested to see all those sliders in action.
Re: Work on GUI Libary
Reply #12 - Nov 3rd, 2005, 3:51am
 
For further information, please see:
http://www.mkv25.net/MyGUI/doc/mkv/MyGUI/MyGUI.html

Examples of the four MyGUI other constructors are:

MyGUI gui = new MyGUI(this);
MyGUI gui = new MyGUI(this, customSize);
MyGUI gui = new MyGUI(this, customSize, customMyGUIStyle);
MyGUI gui = new MyGUI(this, customMyGUIStyle);

I've tried to make all the possible combinations available for constructors.


Re: Work on GUI Libary
Reply #13 - Nov 29th, 2005, 8:36pm
 
THANK YOU!   you're a life saver.  I would like to show what I've got with 14 sliders, but we're not able to release it publicly at the moment.  We will soon!
Re: Work on GUI Libary
Reply #14 - Dec 3rd, 2005, 6:05pm
 
Note: MyGUI Version 0007 is incompatable with the latest versions of processing. It broke with 0093, and has a null pointer error with 0097.

I'm looking into this and hope to release a working version soon.
Pages: 1 2