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

Difference between revisions of "Libwiigui/tutorial"

From WiiBrew
Jump to navigation Jump to search
(←Created page with ' == Foreward == LibwiiGui is written in C++ and uses classes. Classes are a collection of functions and variables related to a single thing. When using these classes, their c...')
 
Line 1: Line 1:
 
 
== Foreward ==
 
== Foreward ==
  
Line 37: Line 36:
 
There are two ways a class instance can be created. LibwiiGui uses both methods. When you want a class to be able to be accessed by any other function, you will want to create it with an asterisk, which declares a pointer to your class. You will want to use this for your main GuiWindow, which should contain the background, and every other window (these other windows will be your menus). You also will want to initially set it to NULL for safety's sake.
 
There are two ways a class instance can be created. LibwiiGui uses both methods. When you want a class to be able to be accessed by any other function, you will want to create it with an asterisk, which declares a pointer to your class. You will want to use this for your main GuiWindow, which should contain the background, and every other window (these other windows will be your menus). You also will want to initially set it to NULL for safety's sake.
  
<source lang = "c++" >
+
<source lang = "cpp" >
 
GuiWindow * mainWindow = NULL;
 
GuiWindow * mainWindow = NULL;
 
</source>
 
</source>
Line 43: Line 42:
 
These declarations should be at the top of the file, underneath the includes. Then, when using it, you will use ->
 
These declarations should be at the top of the file, underneath the includes. Then, when using it, you will use ->
  
<source lang = "c++">
+
<source lang = "cpp">
 
mainWindow->Append(image);
 
mainWindow->Append(image);
 
</source>
 
</source>
Line 49: Line 48:
 
If you have a class that is only relavent to the function you are in (e.g. a menu) you will want to declare the instance inside the function:
 
If you have a class that is only relavent to the function you are in (e.g. a menu) you will want to declare the instance inside the function:
  
<source lang = "c++">
+
<source lang = "cpp">
 
int menu_function(){
 
int menu_function(){
 
     GuiWindow menuwindow;
 
     GuiWindow menuwindow;
Line 58: Line 57:
 
and then use the dot:
 
and then use the dot:
  
<source lang = "c++">
+
<source lang = "cpp">
 
int menu_function(){
 
int menu_function(){
 
     GuiWindow menuwindow;
 
     GuiWindow menuwindow;

Revision as of 07:25, 26 June 2009

Foreward

LibwiiGui is written in C++ and uses classes. Classes are a collection of functions and variables related to a single thing. When using these classes, their collected functions and variables (if they are declared public) can be accessed by a dot (.) in some cases, and an arrow (->) in other cases. This will become more understandable later on in the tutorial, but for now, know that when the class instance is created with an asterisk (*) before it, you will be using the arrow (->). When the class is created without the asterisk, you will use the dot (.).

This tutorial uses the same design as the demo included with libwiigui. Every menu is created inside a function. The GUI updating routine is created as a function, and is in a thread. When wanting to change to a knew menu, you set the menu variable to a value that denotes the menu you wish to change to. Again, this will become more apparent later on.

Lastly, before attempting to read this tutorial (or try to use libwiigui for that matter) you should already have at least a basic understanding of C++, if not more. You can easily find some online tutorials (cprogramming.com, cplusplus.com) or a book from your local library.


Setting Up

You first must have devkitPro. DevkitPro is what allows programmer's to compile their programs for other systems, such as the Wii, PSP, and DS. This should be pretty straight-foreward for Windows users. Just download the latest Windows installer, and go through the installer. When asked what to install, you must install devkitPPC. That allows you to compile for the PowerPC architecture, which the Wii uses. You also will need libOGC, which is the library that lets you program for the Wii. Windows users may skip to the horizontal line below.

Linux and Mac users will need to download devkitPPC and libOGC. Select the appropriate version to download, and put them both in a directory (I would suggest making a devkitpro directory in your home folder and putting both in this folder). In Linux, you will want to edit your bash configuration file to define the DEVKITPRO and DEVKITPPC variables. The following code should do the trick for most linux users:

sudo gedit /usr/bash.bashrc

Then input your password, and add the following to the top of the file:

export DEVKITPPC="<path to devkitpro directory>"
eport DEVKITPPC="<path to devkitPPC directory>"

You also may want to download the examples from devkitpro. Put these in your devkitpro directory in a folder named examples.


If you haven't already done so, download libwiigui. You can extract this anywhere, as this is where your source will be for your entire project. You also will need to download the required devkitpro libraries. Extract these to your libogc folder (should be devkitPro/libogc) overwriting any existing files.


Class Creation

There are two ways a class instance can be created. LibwiiGui uses both methods. When you want a class to be able to be accessed by any other function, you will want to create it with an asterisk, which declares a pointer to your class. You will want to use this for your main GuiWindow, which should contain the background, and every other window (these other windows will be your menus). You also will want to initially set it to NULL for safety's sake.

GuiWindow * mainWindow = NULL;

These declarations should be at the top of the file, underneath the includes. Then, when using it, you will use ->

mainWindow->Append(image);

If you have a class that is only relavent to the function you are in (e.g. a menu) you will want to declare the instance inside the function:

int menu_function(){
     GuiWindow menuwindow;
     GuiImage menuimage;
}

and then use the dot:

int menu_function(){
     GuiWindow menuwindow;
     GuiImage menuimage;
     menuwindow.Append(&menuimage);
}


Your First Image