Line 393:
Line 393:
</source>
</source>
−
Most functions are pretty self-explanatory. Some you will not use often, while others you will be using all the time (like SetPosition). Remember, you will want to use these functions with the upper-most class you can. For example, if you set GuiImageData to a GuiImage, and then set the GuiImage to a GuiButton, you will want to set the position of the GuiButton, not the GuiImage.
+
Most functions are pretty self-explanatory. Some you will not use often, while others you will be using all the time (like SetPosition). Remember, you will want to use these functions with the upper-most class you can. For example, if you set GuiImageData to a GuiImage, and then set the GuiImage to a GuiButton, you will want to set the position of the GuiButton, not the GuiImage.
Line 443:
Line 443:
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''':
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">
−
const u8 *image_name_png; //define the variables to hold your image file
+
const u8 *image_name_png; //define the variables to hold your image file
−
const u32 image_name_png_size;
+
const u32 image_name_png_size;
size_t amount_read;
size_t amount_read;
−
FILE *fp = fopen("Path to image on sd card","r"); //open the png file
+
FILE *fp = fopen("Path to image on sd card","r"); //open the png file
−
if(!fp) return; //make sure the file exists
+
if(!fp) return; //make sure the file exists
fseek (fp , 0 , SEEK_END);
fseek (fp , 0 , SEEK_END);
−
image_name_png_size = ftell(fp); //find the file size
+
image_name_png_size = ftell(fp); //find the file size
rewind(fp);
rewind(fp);
−
image_name_png = new u8 [image_name_png_size]; //allocate memory for your image buffer
+
image_name_png = new u8 [image_name_png_size]; //allocate memory for your image buffer
−
if(!image_name_png) return; //make sure memory allocated
+
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
+
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
+
if(amount_read != image_size_png_size) return; //make sure it read everything
−
fclose(fp); //close file
+
fclose(fp); //close file
</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 963:
Line 963:
−
while(menu == MENU_NONE) //The loop will run until menu is changed
+
while(menu == MENU_NONE) //The loop will run until menu is changed
{
{
−
VIDEO_WaitVSync (); //Waits for the vertical sync, to reduce flickering
+
VIDEO_WaitVSync (); //Waits for the vertical sync, to reduce flickering
−
if(backBtn.GetState() == STATE_CLICKED) //Checks if you clicked back
+
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
+
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
+
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
+
menu = MENU_MAIN; //stops the loop, and returns MENU_MAIN, which will start the main menu
}
}
}
}
−
HaltGui(); //stop the gui
+
HaltGui(); //stop the gui
−
mainWindow->Remove(&w); //remove your window to free memory
+
mainWindow->Remove(&w); //remove your window to free memory
−
return menu; //return the new menu to load
+
return menu; //return the new menu to load
}
}
</source>
</source>