Changes

Jump to navigation Jump to search
3,210 bytes added ,  07:58, 9 July 2009
Tantric: Sorry, my stupidity. You saved your edit before I saved mine
Line 445: Line 445:  
GuiImageData imagedata(image_source);
 
GuiImageData imagedata(image_source);
 
</source>
 
</source>
The image source is your image buffer, where the contents of the image are kept. The image must be in the png format, and have dimensions that are a multiple of 4. To load an image from an sd card to an image buffer, do the following:
+
The image source is your image buffer, where the contents of the image are kept. The image must be in the png format, and have dimensions that are a multiple of 4. To load an image from an sd card to an image buffer, do the following (this is a little more complicated, and is slower anyway, so only use it if necessary) '''Somebody verify this please''':
 
<source lang="cpp">
 
<source lang="cpp">
FILE *fp = fopen("Path to image on sd card","r");
+
const u8                *image_name_png;                //define the variables to hold your image file
''todo''
+
const u32                image_name_png_size;
 +
size_t amount_read;
 +
FILE *fp = fopen("Path to image on sd card","r");       //open the png file
 +
if(!fp) return;                                        //make sure the file exists
 +
 
 +
fseek (fp , 0 , SEEK_END);
 +
image_name_png_size = ftell(fp);                        //find the file size
 +
rewind(fp);
 +
 
 +
image_name_png = new u8 [image_name_png_size];          //allocate memory for your image buffer
 +
if(!image_name_png) return;                            //make sure memory allocated
 +
 
 +
amount_read = fread(image_name_png,1,image_name_png_size,fp);        //read file to buffer
 +
if(amount_read != image_size_png_size) return;                      //make sure it read everything
 +
 
 +
fclose(fp);                                  //close file
 +
delete result;                                //free memory
 
</source>
 
</source>
 
You may be wondering how an image gets loaded into a buffer without the sd card. Whenever you want to add a new image, you must copy the image to the source/images folder, and add it to filelist.h:
 
You may be wondering how an image gets loaded into a buffer without the sd card. Whenever you want to add a new image, you must copy the image to the source/images folder, and add it to filelist.h:
Line 882: Line 898:  
}
 
}
 
</source>
 
</source>
 +
 +
 +
 +
== 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.
 +
 +
''Not finished''
309

edits

Navigation menu