In memory of Ben “bushing” Byer, who passed away on Monday, February 8th, 2016.

Changes

Jump to navigation Jump to search
3,203 bytes added ,  03:24, 10 July 2009
Line 902: Line 902:     
== Program Flow ==
 
== Program Flow ==
Now that you know a little more about buttons and images, you need to understand how a libwiigui project should be set up. One thing that is confusing for people trying to use libwiigui (or at least it was for me) is that there seem to be two different libraries. This is not true. The bare library is only what is in your libwiigui folder. Everything else (menu.cpp, video.h) is not part of the libwiigui library. They simply lay down the recommended way to effectively use the library. You will not need to worry much about any files except for ''menu.cpp'', ''menu.h'', and ''demo.cpp''. ''demo.cpp'' is your main cpp file, where your program starts in. If you want, you can rename this to ''main.cpp'' or something you see fitting. This file will just call a couple functions to initialize things, maybe set a few variables for you, and then calls your MainMenu() function, which takes care of everything else for you (unless you stop the gui for something else). ''menu.h'' is what declares a couple of functions, and "enum's" the variables that will "describe" your menus (not exactly, but close enough for us). So both of those files are simple, just a few function calls, and a few declarations. ''menu.cpp'' is what contains your entire gui. This is the only file (other than ''filebrowser.cpp'') that actually uses libwiigui. All of this sort of "wraps" libwiigui into a usable form. ''menu.cpp'' will contain your UpdateGui() function. This is what Draw()s any changes you've made, draws the cursor(s) on the screen, and checks if you want to exit (so that it can fade out). UpdateGui() is used by creating a thread that runs UpdateGui(). Threads are what allow two different functions to execute simultaneously (not really, but it gives the illusion of it), so regardless of what you are doing elsewhere, your gui will still be displayed as long as the thread is running. However, threads can cause quite a few problems, one being when a variable is being written to and read from at the same time. To avoid this, you must call HaltGui() before Append()ing anything to the mainWindow. After your done Appending, call ResumeGui() to start the gui back up.
+
Now that you know a little more about buttons and images, you need to understand how a libwiigui project should be set up. One thing that is confusing for people trying to use libwiigui (or at least it was for me) is that there seem to be two different libraries. This is not true. The bare library is only what is in your libwiigui folder. Everything else (menu.cpp, video.h) is not part of the libwiigui library. They simply lay down the recommended way to effectively use the library. You will not need to worry much about any files except for ''menu.cpp'', ''menu.h'', and ''demo.cpp''.
   −
''Not finished''
+
''demo.cpp'' is your main cpp file, where your program starts in. If you want, you can rename this to ''main.cpp'' or something you see fitting. This file will just call a couple functions to initialize things, maybe set a few variables for you, and then calls your MainMenu() function, which takes care of everything else for you (unless you stop the gui for something else).
 +
 
 +
''menu.h'' is what declares a couple of functions, and "enum's" the variables that will "describe" your menus (not exactly, but close enough for us). So both of those files are simple, just a few function calls, and a few declarations.
 +
 
 +
''menu.cpp'' is what contains your entire gui. This is the only file (other than ''filebrowser.cpp'') that actually uses libwiigui. All of this sort of "wraps" libwiigui into a usable form. ''menu.cpp'' will contain your UpdateGui() function. This is what Draw()s any changes you've made, draws the cursor(s) on the screen, and checks if you want to exit (so that it can fade out). UpdateGui() is used by creating a thread that runs UpdateGui(). Threads are what allow two different functions to execute simultaneously (not really, but it gives the illusion of it), so regardless of what you are doing elsewhere, your gui will still be displayed as long as the thread is running. However, threads can cause quite a few problems, one being when a variable is being written to and read from at the same time. To avoid this, you must call HaltGui() before Append()ing anything to the mainWindow. After your done Appending, call ResumeGui() to start the gui back up.
 +
 
 +
Everything that is displayed ''should'' be a part of a "menu" (with a few exceptions, such as snes9gx, which stops the gui when emulating, and starts it when you return to the main menu). A "menu" is not actually defined by libwiigui, rather it is the concept of having images, buttons, and any other GuiElement used grouped together to be displayed at once. These are typically going to be grouped into one GuiWindow that is appended to the mainWindow. A "menu" should follow the following basic outline:
 +
 
 +
<source lang = "cpp">
 +
static int menu(){
 +
int menu = MENU_NONE;
 +
 
 +
                          ///All of the GuiElements here are optional, as you will be doing whatever pertains to your usage
 +
GuiText titleTxt("Menu Title", 28, (GXColor){255, 255, 255, 255});
 +
titleTxt.SetAlignment(ALIGN_LEFT, ALIGN_TOP);
 +
titleTxt.SetPosition(50,50);
 +
 
 +
GuiSound btnSoundOver(button_over_pcm, button_over_pcm_size, SOUND_PCM);
 +
GuiImageData btnOutline(button_png);
 +
GuiImageData btnOutlineOver(button_over_png);
 +
 
 +
GuiTrigger trigA;
 +
trigA.SetSimpleTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A);
 +
 
 +
GuiText backBtnTxt("Go Back", 22, (GXColor){0, 0, 0, 255});
 +
GuiImage backBtnImg(&btnOutline);
 +
GuiImage backBtnImgOver(&btnOutlineOver);
 +
GuiButton backBtn(btnOutline.GetWidth(), btnOutline.GetHeight());
 +
backBtn.SetAlignment(ALIGN_LEFT, ALIGN_BOTTOM);
 +
backBtn.SetPosition(100, -35);
 +
backBtn.SetLabel(&backBtnTxt);
 +
backBtn.SetImage(&backBtnImg);
 +
backBtn.SetImageOver(&backBtnImgOver);
 +
backBtn.SetSoundOver(&btnSoundOver);
 +
backBtn.SetTrigger(&trigA);
 +
backBtn.SetEffectGrow();
 +
 +
 +
GuiText okayBtnTxt("Okay", 22, (GXColor){0, 0, 0, 255});
 +
GuiImage okayBtnImg(&btnOutline);
 +
GuiImage okayBtnImgOver(&btnOutlineOver);
 +
GuiButton okayBtn(btnOutline.GetWidth(), btnOutline.GetHeight());
 +
okayBtn.SetAlignment(ALIGN_LEFT, ALIGN_BOTTOM);
 +
okayBtn.SetPosition(300, -35);
 +
okayBtn.SetLabel(&okayBtnTxt);
 +
okayBtn.SetImage(&okayBtnImg);
 +
okayBtn.SetImageOver(&okayBtnImgOver);
 +
okayBtn.SetSoundOver(&btnSoundOver);
 +
okayBtn.SetTrigger(&trigA);
 +
okaydBtn.SetEffectGrow();
 +
 
 +
        ///Here is where you Halt the Gui, and append things. Notice that everything is appended to the GuiWindow w. w is then appended to the mainWindow.
 +
 
 +
HaltGui();
 +
GuiWindow w(screenwidth, screenheight);
 +
w.Append(&backBtn);
 +
w.Append(&okayBtn);
 +
w.Append(&titleTxt);
 +
mainWindow->Append(&w);
 +
ResumeGui();
 +
 +
        ///This is the loop that keeps the menu running until told to stop
 +
 
 +
 
 +
while(menu == MENU_NONE)  //The loop will run until menu is changed
 +
{
 +
VIDEO_WaitVSync ();        //Waits for the vertical sync, to reduce flickering
 +
 
 +
if(backBtn.GetState() == STATE_CLICKED)            //Checks if you clicked back
 +
{
 +
menu = MENU_EXIT;  //stops the loop, and returns MENU_EXIT, which will exit the app
 +
}
 +
if(okayBtn.GetState() == STATE_CLICKED)            //Checks if you clicked okay
 +
                {
 +
menu = MENU_MAIN;                //stops the loop, and returns MENU_MAIN, which will start the main menu
 +
}
 +
}
 +
HaltGui();                        //stop the gui
 +
mainWindow->Remove(&w);            //remove your window to free memory
 +
return menu;                      //return the new menu to load
 +
}
 +
</source>
309

edits

Navigation menu