Changes

7,837 bytes added ,  15:50, 3 July 2009
no edit summary
Line 64: Line 64:  
}
 
}
 
</source>
 
</source>
 +
 +
 +
 +
== The GuiElement ==
 +
 +
Every class instance you create, save for a GuiSound, GuiTrigger, or a GuiImageData, will be inherited from the GuiElement class. This means that you can use any GuiElement function in any GuiElement you use, allowing you to move, get the width of, and get the state of images, buttons, keyboards, option browsers, etc. The GuiElement (from libwiigui/gui.h) class defines the following public functions which you can use with any GuiElement:
 +
 +
<source lang = "cpp">
 +
//!Constructor
 +
 +
GuiElement();
 +
 +
//!Destructor
 +
 +
~GuiElement();
 +
 +
//!Set the element's parent
 +
 +
//!\param e Pointer to parent element
 +
 +
void SetParent(GuiElement * e);
 +
 +
//!Gets the element's parent
 +
 +
//!\return Pointer to parent element
 +
 +
GuiElement * GetParent();
 +
 +
//!Gets the current leftmost coordinate of the element
 +
 +
//!Considers horizontal alignment, x offset, width, and parent element's GetLeft() / GetWidth() values
 +
 +
//!\return left coordinate
 +
 +
int GetLeft();
 +
 +
//!Gets the current topmost coordinate of the element
 +
 +
//!Considers vertical alignment, y offset, height, and parent element's GetTop() / GetHeight() values
 +
 +
//!\return top coordinate
 +
 +
int GetTop();
 +
 +
//!Sets the minimum y offset of the element
 +
 +
//!\param y Y offset
 +
 +
void SetMinY(int y);
 +
 +
//!Gets the minimum y offset of the element
 +
 +
//!\return Minimum Y offset
 +
 +
int GetMinY();
 +
 +
//!Sets the maximum y offset of the element
 +
 +
//!\param y Y offset
 +
 +
void SetMaxY(int y);
 +
 +
//!Gets the maximum y offset of the element
 +
 +
//!\return Maximum Y offset
 +
 +
int GetMaxY();
 +
 +
//!Sets the minimum x offset of the element
 +
 +
//!\param x X offset
 +
 +
void SetMinX(int x);
 +
 +
//!Gets the minimum x offset of the element
 +
 +
//!\return Minimum X offset
 +
 +
int GetMinX();
 +
 +
//!Sets the maximum x offset of the element
 +
 +
//!\param x X offset
 +
 +
void SetMaxX(int x);
 +
 +
//!Gets the maximum x offset of the element
 +
 +
//!\return Maximum X offset
 +
 +
int GetMaxX();
 +
 +
//!Gets the current width of the element. Does not currently consider the scale
 +
 +
//!\return width
 +
 +
int GetWidth();
 +
 +
//!Gets the height of the element. Does not currently consider the scale
 +
 +
//!\return height
 +
 +
int GetHeight();
 +
 +
//!Sets the size (width/height) of the element
 +
 +
//!\param w Width of element
 +
 +
//!\param h Height of element
 +
 +
void SetSize(int w, int h);
 +
 +
//!Checks whether or not the element is visible
 +
 +
//!\return true if visible, false otherwise
 +
 +
bool IsVisible();
 +
 +
//!Checks whether or not the element is selectable
 +
 +
//!\return true if selectable, false otherwise
 +
 +
bool IsSelectable();
 +
 +
//!Checks whether or not the element is clickable
 +
 +
//!\return true if clickable, false otherwise
 +
 +
bool IsClickable();
 +
 +
//!Checks whether or not the element is holdable
 +
 +
//!\return true if holdable, false otherwise
 +
 +
bool IsHoldable();
 +
 +
//!Sets whether or not the element is selectable
 +
 +
//!\param s Selectable
 +
 +
void SetSelectable(bool s);
 +
 +
//!Sets whether or not the element is clickable
 +
 +
//!\param c Clickable
 +
 +
void SetClickable(bool c);
 +
 +
//!Sets whether or not the element is holdable
 +
 +
//!\param c Holdable
 +
 +
void SetHoldable(bool d);
 +
 +
//!Gets the element's current state
 +
 +
//!\return state
 +
 +
int GetState();
 +
 +
//!Gets the controller channel that last changed the element's state
 +
 +
//!\return Channel number (0-3, -1 = no channel)
 +
 +
int GetStateChan();
 +
 +
//!Sets the element's alpha value
 +
 +
//!\param a alpha value
 +
 +
void SetAlpha(int a);
 +
 +
//!Gets the element's alpha value
 +
 +
//!Considers alpha, alphaDyn, and the parent element's GetAlpha() value
 +
 +
//!\return alpha
 +
 +
int GetAlpha();
 +
 +
//!Sets the element's scale
 +
 +
//!\param s scale (1 is 100%)
 +
 +
void SetScale(float s);
 +
 +
//!Gets the element's current scale
 +
 +
//!Considers scale, scaleDyn, and the parent element's GetScale() value
 +
 +
float GetScale();
 +
 +
//!Set a new GuiTrigger for the element
 +
 +
//!\param t Pointer to GuiTrigger
 +
 +
void SetTrigger(GuiTrigger * t);
 +
 +
//!\overload
 +
 +
//!\param i Index of trigger array to set
 +
 +
//!\param t Pointer to GuiTrigger
 +
 +
void SetTrigger(u8 i, GuiTrigger * t);
 +
 +
//!Checks whether rumble was requested by the element
 +
 +
//!\return true is rumble was requested, false otherwise
 +
 +
bool Rumble();
 +
 +
//!Sets whether or not the element is requesting a rumble event
 +
 +
//!\param r true if requesting rumble, false if not
 +
 +
void SetRumble(bool r);
 +
 +
//!Set an effect for the element
 +
 +
//!\param e Effect to enable
 +
 +
//!\param a Amount of the effect (usage varies on effect)
 +
 +
//!\param t Target amount of the effect (usage varies on effect)
 +
 +
void SetEffect(int e, int a, int t=0);
 +
 +
//!Sets an effect to be enabled on wiimote cursor over
 +
 +
//!\param e Effect to enable
 +
 +
//!\param a Amount of the effect (usage varies on effect)
 +
 +
//!\param t Target amount of the effect (usage varies on effect)
 +
 +
void SetEffectOnOver(int e, int a, int t=0);
 +
 +
//!Shortcut to SetEffectOnOver(EFFECT_SCALE, 4, 110)
 +
 +
void SetEffectGrow();
 +
 +
//!Gets the current element effects
 +
 +
//!\return element effects
 +
 +
int GetEffect();
 +
 +
//!Checks whether the specified coordinates are within the element's boundaries
 +
 +
//!\param x X coordinate
 +
 +
//!\param y Y coordinate
 +
 +
//!\return true if contained within, false otherwise
 +
 +
bool IsInside(int x, int y);
 +
 +
//!Sets the element's position
 +
 +
//!\param x X coordinate
 +
 +
//!\param y Y coordinate
 +
 +
void SetPosition(int x, int y);
 +
 +
//!Updates the element's effects (dynamic values)
 +
 +
//!Called by Draw(), used for animation purposes
 +
 +
void UpdateEffects();
 +
 +
//!Sets a function to called after after Update()
 +
 +
//!Callback function can be used to response to changes in the state of the element, and/or update the element's attributes
 +
 +
void SetUpdateCallback(UpdateCallback u);
 +
 +
//!Checks whether the element is in focus
 +
 +
//!\return true if element is in focus, false otherwise
 +
 +
int IsFocused();
 +
 +
//!Sets the element's visibility
 +
 +
//!\param v Visibility (true = visible)
 +
 +
virtual void SetVisible(bool v);
 +
 +
//!Sets the element's focus
 +
 +
//!\param f Focus (true = in focus)
 +
 +
virtual void SetFocus(int f);
 +
 +
//!Sets the element's state
 +
 +
//!\param s State (STATE_DEFAULT, STATE_SELECTED, STATE_CLICKED, STATE_DISABLED)
 +
 +
//!\param c Controller channel (0-3, -1 = none)
 +
 +
virtual void SetState(int s, int c = -1);
 +
 +
//!Resets the element's state to STATE_DEFAULT
 +
 +
virtual void ResetState();
 +
 +
//!Gets whether or not the element is in STATE_SELECTED
 +
 +
//!\return true if selected, false otherwise
 +
 +
virtual int GetSelected();
 +
 +
//!Sets the element's alignment respective to its parent element
 +
 +
//!\param hor Horizontal alignment (ALIGN_LEFT, ALIGN_RIGHT, ALIGN_CENTRE)
 +
 +
//!\param vert Vertical alignment (ALIGN_TOP, ALIGN_BOTTOM, ALIGN_MIDDLE)
 +
 +
virtual void SetAlignment(int hor, int vert);
 +
 +
//!Called constantly to allow the element to respond to the current input data
 +
 +
//!\param t Pointer to a GuiTrigger, containing the current input data from PAD/WPAD
 +
 +
virtual void Update(GuiTrigger * t);
 +
 +
//!Called constantly to redraw the element
 +
 +
virtual void Draw();
 +
</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. 
 +
      Line 70: Line 405:  
Images are created using the GuiImage class. Images can either be loaded from the sd card, or from a buffer. There are quite a few things you will have to do, though, before you can display your image. Open demo.cpp from the libwiigui template.
 
Images are created using the GuiImage class. Images can either be loaded from the sd card, or from a buffer. There are quite a few things you will have to do, though, before you can display your image. Open demo.cpp from the libwiigui template.
   −
First, we must initialize the video hardware, by using the function from video.cpp:
+
First, we must initialize the video hardware, by using the function from video.cpp. This must be done in any wii application you make, even if you are not going to be displaying any images:
 
<source lang = "cpp">
 
<source lang = "cpp">
 
InitVideo();
 
InitVideo();
 +
</source>
 +
If you are going to want sound, initilaize the sound hardware also:
 +
<source lang = "cpp">
 +
InitAudio();
 
</source>
 
</source>
 
If you are going to be loading images from the sd card (or using the sd card for any other reason), you will need to initialize it:
 
If you are going to be loading images from the sd card (or using the sd card for any other reason), you will need to initialize it:
Line 90: Line 429:  
Now, open menu.cpp. Find the MainMenu function. To load an image, you declare an instance of the GuiImage class. Unless, in the main window, you will want to declare it this way:
 
Now, open menu.cpp. Find the MainMenu function. To load an image, you declare an instance of the GuiImage class. Unless, in the main window, you will want to declare it this way:
 
<source lang="cpp">
 
<source lang="cpp">
GuiImage image(ImageData);
+
GuiImage image(&ImageData);
 
</source>
 
</source>
 
What is the ImageData inside the initializer function? Well before actually creating the image, you must load your image. This can be done by creating an instance of the GuiImageData class:
 
What is the ImageData inside the initializer function? Well before actually creating the image, you must load your image. This can be done by creating an instance of the GuiImageData class:
Line 96: Line 435:  
GuiImageData imagedata(image_source);
 
GuiImageData imagedata(image_source);
 
</source>
 
</source>
The image source is your image buffer, where the contents of the image are help. 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:
 
<source lang="cpp">
 
<source lang="cpp">
 
FILE *fp = fopen("Path to image on sd card","r");
 
FILE *fp = fopen("Path to image on sd card","r");
 
''todo''
 
''todo''
 
</source>
 
</source>
You may be wondering how an image gets loaded into a buffer. 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:
 
<source lang = "cpp">
 
<source lang = "cpp">
 
extern const u8 image_name_png[];
 
extern const u8 image_name_png[];
Line 107: Line 446:  
extern const u32 image_name_png_size;
 
extern const u32 image_name_png_size;
 
</source>
 
</source>
Then your image will be put into the ''image_name_without_.png''_png buffer when it is compiled.  
+
Then your image will be put into the ''image_name_without_.png''_png buffer when it is compiled. Just place your image in the images folder, and the compiler will take care of the rest for you.  
    
Last, you must append your new image to the GuiWindow you are dealing with. Before doing do, you need to suspend the gui thread, so that you are not making changes to variables while the thread is reading them, and resume the thread after appending:
 
Last, you must append your new image to the GuiWindow you are dealing with. Before doing do, you need to suspend the gui thread, so that you are not making changes to variables while the thread is reading them, and resume the thread after appending:
Line 115: Line 454:  
ResumeGui();
 
ResumeGui();
 
</source>
 
</source>
Unless the image is declared as a pointer, you must have the & before it to pass the address of your GuiImage to the Append function.
+
Unless the image is created as a pointer, you must have the & before it to pass the address of your GuiImage to the Append function.
    
So that's all it takes to load an image. Easy, right? Here's an example of the complete proccess:
 
So that's all it takes to load an image. Easy, right? Here's an example of the complete proccess:
Line 138: Line 477:  
void initall(){
 
void initall(){
 
InitVideo(); // Initialise video
 
InitVideo(); // Initialise video
 +
        InitAudio()
 
InitGUIThreads();
 
InitGUIThreads();
 
fatInitDefault();
 
fatInitDefault();
309

edits