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.
Page Index Toggle Pages: 1
myGUI (Read 1609 times)
myGUI
Sep 14th, 2006, 3:44pm
 
hi,
ive been using the myGUI class to generate some basic buttons for a user interface.

all the buttons have the same font and the same blue coloring.

can someone tell me how i can change the color of the buttons. i have around 10 buttons in total and would like to color each differently, and if possible, change the font type.

thanks
Re: myGUI
Reply #1 - Sep 14th, 2006, 4:22pm
 
Hey Mitchell,

You should check out the documentation for MyGUI:
http://www.mkv25.net/MyGUI/doc/

Particularly, you should look at the MyGUIStyle and MyGUIButton sections.

In your program you could define different styles, for example:

MyGUIStyle style1 = new MyGUIStyle(this);
MyGUIStyle style2 = new MyGUIStyle(this);
..
MyGUIStyle styleN = new MyGUIStyle(this);

Then, set different color schemes and fonts for each. Check out this thread for help on setting styles: http://processing.org/discourse/yabb_beta/YaBB.cgi?board=Contribution_Responsive;action=display;num=1153688981

Afterwards, you can assign values to your buttons, say something like:

Button1.background = style1.background;
Button2.background = style2.background;
..
ButtonN.background = styleN.background;

I hope that helps.

Cheers,
kirton
Re: myGUI
Reply #2 - Sep 15th, 2006, 4:36pm
 
Thankyou Kirton,

You have described this in an easy to follow way. i will try it out tomorrow and let you know the results.

I did check out the documentation and had a slight trouble understanding it, but after reading your post it makes much more sense.

thanks
Re: myGUI
Reply #3 - Sep 17th, 2006, 4:15am
 
having some problems. ive had a go but i guess for now im just a noob atm.

Code:

//import GUI class
import mkv.MyGUI.*;

//button setup
MyGUI gui;
MyGUIButton butFoul1, butFoul2, butFoul3, butFoul4;

//vars
char previousData = 0;
char currentData = 0;

void setup()
{

//set up window
size(340, 400);
framerate(30);

//Initiate buttons
gui = new MyGUI(this);
MyGUIStyle style1 = new MyGUIStyle(this);
style1.buttonFace = color(144,133,255);
style2.buttonFace = color(100,77,255);
style3.buttonFace = color(50,156,255);
style4.buttonFace = color(12,123,255);

/*Buttons*/
//first button
butFoul1 = new MyGUIButton(this, 40, 20, "Foul 1 ON", 60, 26);
butFoul1.buttonFace = style1.buttonFace;
gui.add(butFoul1);

//second button
butFoul2 = new MyGUIButton(this, 40, 55, "Foul 2 ON", 60, 26);
butFoul2.buttonFace = style2.buttonFace;
gui.add(butFoul2);

//third button
butFoul3 = new MyGUIButton(this, 40, 90, "Foul 3 ON", 60, 26);
butFoul3.buttonFace = style3.buttonFace;
gui.add(butFoul3);

//fourth button
butFoul4 = new MyGUIButton(this, 40, 125, "Foul 4 ON", 60, 26);
butFoul4.buttonFace = style4.buttonFace;
gui.add(butFoul4);
}

void draw()
{
background(55,100,34);
}

// React if the button object was pressed
void actionPerformed(ActionEvent e) {

/*FOULS ON*/
if(e.getSource() == butFoul1) { //ERROR switches on automatically
currentData = 140;
}
else if(e.getSource() == butFoul2) {
currentData = 141;
}
else if(e.getSource() == butFoul3) {
currentData = 142;
}
else if(e.getSource() == butFoul4) { //ERROR switches on automatically
currentData = 145;
}

//Check if data to send
if (currentData != previousData) {
if (currentData != 0) {
port.write(currentData);
}
previousData = currentData;
}
}



Re: myGUI
Reply #4 - Sep 17th, 2006, 9:07am
 
hey mitcho,

i made a mistake in my first post... sorry i was tired when i did that and was on another computer without processing (so i couldn't check).

-- i wrote --
Button1.background = style1.background;
Button2.background = style2.background;
..
ButtonN.background = styleN.background;
--

which should have been

Button1.setStyle(style1);
Button2.setStyle(style2);
..
ButtonN.setStyle(styleN);
Re: myGUI
Reply #5 - Sep 17th, 2006, 9:08am
 
Here's a bit of code that should help you out.

import mkv.MyGUI.*;

MyGUI gui;
MyGUIStyle style1, style2, style3;
MyGUIButton b1, b2, b3;

void setup(){
 gui = new MyGUI(this);
 MyGUIStyle style1 = new MyGUIStyle(this);
 MyGUIStyle style2 = new MyGUIStyle(this);
 MyGUIStyle style3 = new MyGUIStyle(this);
 MyGUIButton b1 = new MyGUIButton(this,20,10,"one",30,10);
 MyGUIButton b2 = new MyGUIButton(this,20,30,"two",30,10);
 MyGUIButton b3 = new MyGUIButton(this,20,50,"three",30,10);
 
 style1.background = color(0,0,0);
 style1.buttonFace = color(255,255,255);
 style1.buttonHighlight = color(33,66,99);
 style2.background = color(66,66,66);
 style2.buttonFace = color(188,188,188);
 style2.buttonHighlight = color(99,66,33);
 style3.background = color(128,128,128);
 style3.buttonFace = color(255,0,0);
 style3.buttonHighlight = color(66,99,66);

 b1.setStyle(style1);
 b2.setStyle(style2);
 b3.setStyle(style3);  
 
 gui.add(b1);
 gui.add(b2);
 gui.add(b3);
}

void draw(){
}
Re: myGUI
Reply #6 - Sep 24th, 2006, 1:13pm
 
Thanks kirton, everything is working great now. i understand the whole workings of it alot better now!
Page Index Toggle Pages: 1