-
February 3rd, 2012, 08:22 PM
#1
connecting GUI to program
So I have my GUI far along enough to start incorporating my program, but I am hesitant to start because I want to be careful to do it in an effective and easy to manage way.
The code so far for the GUI alone is about 2100 lines, and I estimate it will be about 8000-10000 lines long when the program is complete. The code for the actual program (without GUI), is about 6000 lines long so far, and will probably get up to about 10,000 when I've added most of what I intend.
Is it a good idea to have the GUI portion, or at least some of it in a separate source file? If you were to do this, how would you? Obviously you can only have one main function. Would you have a file just for the main function, a header file with all the necessary includes and global variables, and put different portions of the rest in separate files.
Concerning the GUI; In my main function, if you click a button, a function connected to that button is called. Inside that function, I may have code to hide many other buttons while this button is selected; Also to manage effects which help you see visually which button is selected. My program so far has like 70 different GUI objects which all get modified, hidden, shown, etc in different circumstances, and multiple menus.
My question; what's the most reasonable way to do this? Right now all my buttons, and their associated objects are all global. Is this reasonable? Is there an exception to the globals are bad rule in cases like this?
Last edited by wl3; February 3rd, 2012 at 08:28 PM.
-
February 4th, 2012, 07:37 AM
#2
Re: connecting GUI to program
Originally Posted by wl3
...
My question; what's the most reasonable way to do this? Right now all my buttons, and their associated objects are all global. Is this reasonable?
No. In the most of cases it is NOT reasonable.
BTW, on and for what platform are you going to develop your GUI?
Victor Nijegorodov
-
February 4th, 2012, 01:18 PM
#3
Re: connecting GUI to program
Originally Posted by VictorN
No. In the most of cases it is NOT reasonable.
BTW, on and for what platform are you going to develop your GUI?
I'm using clutter as the basis.
http://www.clutter-project.org/
Here is an example of what I am talking about. This is just the GUI portion so far of what happens when the Go Back button is clicked. The actors are all inside a single container, the stage, which is basically your window.
Code:
void GoBack_Clicked (ClutterClickAction *action, ClutterActor *actor, gpointer user_data) {
for (int i=0; i < 18; ++i)
clutter_actor_hide (Actor_Notes_Text[i]);
SomethingHasBeen_Selected=false;
clutter_actor_set_size (Actor_Title, 600, 110);
clutter_actor_show (Actor_NewProject);
clutter_actor_show (Actor_LoadProject);
clutter_actor_show (Actor_DeleteProject);
clutter_actor_show (Actor_About);
clutter_actor_hide (Actor_Text);
clutter_actor_hide (Actor_Text_Box);
clutter_actor_hide (Actor_Enter);
clutter_actor_hide (Actor_Project_Title_Text);
clutter_actor_hide (Actor_Blank_Screen);
clutter_actor_hide (Actor_Line);
clutter_actor_hide (Actor_Line2);
clutter_actor_hide (Actor_Line3);
clutter_actor_hide (Actor_Line4);
clutter_actor_hide (Actor_Run);
clutter_actor_hide (Actor_Settings);
clutter_actor_hide (Actor_Files);
clutter_actor_hide (Actor_Results);
clutter_actor_hide (Actor_Exit);
clutter_actor_hide (Actor_ProjectTitle);
clutter_actor_hide (Actor_Notes);
clutter_actor_hide (Actor_Help);
clutter_actor_hide (Actor_Stop);
clutter_actor_hide (Actor_PlayPause);
clutter_actor_hide (Actor_PlayPauseAll);
clutter_actor_hide (Actor_Add);
clutter_actor_hide (Actor_AddAll);
clutter_actor_hide (Actor_Remove);
clutter_actor_hide (Actor_RemoveAll);
clutter_actor_hide (Actor_Info);
clutter_actor_hide (Actor_Blank);
clutter_actor_hide (Actor_Line5);
clutter_timeline_stop (TimeLine_Run);
clutter_actor_set_z_rotation_from_gravity (Actor_Run, 0.0, CLUTTER_GRAVITY_CENTER);
clutter_timeline_stop (TimeLine_Settings);
clutter_actor_set_z_rotation_from_gravity (Actor_Settings, 0.0, CLUTTER_GRAVITY_CENTER);
clutter_timeline_stop (TimeLine_Files);
clutter_actor_set_z_rotation_from_gravity (Actor_Files, 0.0, CLUTTER_GRAVITY_CENTER);
clutter_timeline_stop (TimeLine_Results);
clutter_actor_set_z_rotation_from_gravity (Actor_Results, 0.0, CLUTTER_GRAVITY_CENTER);
clutter_desaturate_effect_set_factor(CLUTTER_DESATURATE_EFFECT(DSRun), Saturation);
clutter_desaturate_effect_set_factor(CLUTTER_DESATURATE_EFFECT(DSSettings), Saturation);
clutter_desaturate_effect_set_factor(CLUTTER_DESATURATE_EFFECT(DSResults), Saturation);
clutter_desaturate_effect_set_factor(CLUTTER_DESATURATE_EFFECT(DSFiles), Saturation);
}
Last edited by wl3; February 4th, 2012 at 01:21 PM.
-
February 4th, 2012, 04:00 PM
#4
Re: connecting GUI to program
Originally Posted by wl3
You still didn't answer what platform you're using. Windows, Linux, ?
Right now all my buttons, and their associated objects are all global. Is this reasonable?
In general, global variables should be avoided as much as possible, regardless of what type of application you're developing.
Regards,
Paul McKenzie
-
February 4th, 2012, 04:21 PM
#5
Re: connecting GUI to program
Originally Posted by Paul McKenzie
You still didn't answer what platform you're using. Windows, Linux, ?
In general, global variables should be avoided as much as possible, regardless of what type of application you're developing.
Regards,
Paul McKenzie
I'm using visual studio 10, but my application is written to be portable to mac and linux.
They have a solution using a "json" script which you can somehow use to give access to all your clutter objects to all your signal handling functions.
I'm going to try and put my GUI objects all inside a struct, and then pass it with every signal handling function. Clutter seams to only let you pass one argument as user data for signal handling functions. The problem might be that such a structure will need to contain like 50 or so variables.
-
February 4th, 2012, 04:41 PM
#6
Re: connecting GUI to program
Is there something wrong with this? I'm having trouble passing a structure as an argument.
Code:
void Check (struct Button Test) {
clutter_actor_hide ( Test.T1);
}
int main (int argc, char *argv[]) {
clutter_init (&argc, &argv);
struct Button {
ClutterActor *T1;
ClutterActor *T2;
} Test;
Test.T1 = clutter_texture_new_from_file("c://Clutter Files//New2.png", NULL);
Test.T2 = clutter_texture_new_from_file("c://Clutter Files//New2.png", NULL);
clutter_actor_set_size (Test.T1, 600, 110);
clutter_actor_set_size (Test.T2, 600, 110);
clutter_actor_set_position (Test.T2, 0, 300);
clutter_actor_set_position (Test.T2, 0, 400);
Check(Test);
I get the following errors.
-Use of undeclared type, "Button"
-left of .T1 must have class/struct/union
-check cannot convert from main::Button to Button
-
February 4th, 2012, 04:52 PM
#7
Re: connecting GUI to program
Originally Posted by wl3
Is there something wrong with this? I'm having trouble passing a structure as an argument.
Yes there is "something wrong with this", thus the compiler complains!
Your declaration of void Check(...) uses struct Button Test but struct Button Test is defined some lines lower...
Try to move struct Button definition to be on top... or, at least before the void Check declaration
Victor Nijegorodov
-
February 4th, 2012, 05:08 PM
#8
Re: connecting GUI to program
Originally Posted by VictorN
Yes there is "something wrong with this", thus the compiler complains!
Your declaration of void Check(...) uses struct Button Test but struct Button Test is defined some lines lower...
Try to move struct Button definition to be on top... or, at least before the void Check declaration
Ahh yeah, thanks.
Is there a maximum number of members for a struct? Is it rediculous to put say 200 members in a single struct? At this point what is the advantage over using globals?
-
February 4th, 2012, 05:22 PM
#9
Re: connecting GUI to program
Originally Posted by wl3
Is there a maximum number of members for a struct?
Sorry I don't know!
Originally Posted by wl3
Is it rediculous to put say 200 members in a single struct?
I don't see anything wrong here. But, as usual, it depends...
Originally Posted by wl3
At this point what is the advantage over using globals?
Just to not use globals!
Besides, it is more preferable to pass struct Button by reference:
Code:
void Check (struct Button &Test)
Victor Nijegorodov
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|