00001 /*!\mainpage libwiigui Documentation 00002 * 00003 * \section Introduction 00004 * libwiigui is a GUI library for the Wii, created to help structure the 00005 * design of a complicated GUI interface, and to enable an author to create 00006 * a sophisticated, feature-rich GUI. It was originally conceived and written 00007 * after I started to design a GUI for Snes9x GX, and found libwiisprite and 00008 * GRRLIB inadequate for the purpose. It uses GX for drawing, and makes use 00009 * of PNGU for displaying images and FreeTypeGX for text. It was designed to 00010 * be flexible and is easy to modify - don't be afraid to change the way it 00011 * works or expand it to suit your GUI's purposes! If you do, and you think 00012 * your changes might benefit others, please share them so they might be 00013 * added to the project! 00014 * 00015 * \section Quickstart 00016 * Start from the supplied template example. For more advanced uses, see the 00017 * source code for Snes9x GX, FCE Ultra GX, and Visual Boy Advance GX. 00018 00019 * \section Contact 00020 * If you have any suggestions for the library or documentation, or want to 00021 * contribute, please visit the libwiigui website: 00022 * http://code.google.com/p/libwiigui/ 00023 00024 * \section Credits 00025 * This library was wholly designed and written by Tantric. Thanks to the 00026 * authors of PNGU and FreeTypeGX, of which this library makes use. Thanks 00027 * also to the authors of GRRLIB and libwiisprite for laying the foundations. 00028 * 00029 */ 00030 00031 #ifndef LIBWIIGUI_H 00032 #define LIBWIIGUI_H 00033 00034 #include <gccore.h> 00035 #include <malloc.h> 00036 #include <stdlib.h> 00037 #include <string.h> 00038 #include <vector> 00039 #include <exception> 00040 #include <wchar.h> 00041 #include <math.h> 00042 #include <asndlib.h> 00043 #include <wiiuse/wpad.h> 00044 #include "pngu.h" 00045 #include "FreeTypeGX.h" 00046 #include "video.h" 00047 #include "filelist.h" 00048 #include "input.h" 00049 #include "oggplayer.h" 00050 00051 extern FreeTypeGX *fontSystem[]; 00052 00053 #define SCROLL_INITIAL_DELAY 20 00054 #define SCROLL_LOOP_DELAY 3 00055 #define FILE_PAGESIZE 8 00056 #define PAGESIZE 8 00057 #define MAX_OPTIONS 30 00058 #define MAX_KEYBOARD_DISPLAY 32 00059 00060 typedef void (*UpdateCallback)(void * e); 00061 00062 enum 00063 { 00064 ALIGN_LEFT, 00065 ALIGN_RIGHT, 00066 ALIGN_CENTRE, 00067 ALIGN_TOP, 00068 ALIGN_BOTTOM, 00069 ALIGN_MIDDLE 00070 }; 00071 00072 enum 00073 { 00074 STATE_DEFAULT, 00075 STATE_SELECTED, 00076 STATE_CLICKED, 00077 STATE_HELD, 00078 STATE_DISABLED 00079 }; 00080 00081 enum 00082 { 00083 SOUND_PCM, 00084 SOUND_OGG 00085 }; 00086 00087 enum 00088 { 00089 IMAGE_TEXTURE, 00090 IMAGE_COLOR, 00091 IMAGE_DATA 00092 }; 00093 00094 enum 00095 { 00096 TRIGGER_SIMPLE, 00097 TRIGGER_HELD, 00098 TRIGGER_BUTTON_ONLY, 00099 TRIGGER_BUTTON_ONLY_IN_FOCUS 00100 }; 00101 00102 enum 00103 { 00104 SCROLL_NONE, 00105 SCROLL_HORIZONTAL 00106 }; 00107 00108 typedef struct _paddata { 00109 u16 btns_d; 00110 u16 btns_u; 00111 u16 btns_h; 00112 s8 stickX; 00113 s8 stickY; 00114 s8 substickX; 00115 s8 substickY; 00116 u8 triggerL; 00117 u8 triggerR; 00118 } PADData; 00119 00120 #define EFFECT_SLIDE_TOP 1 00121 #define EFFECT_SLIDE_BOTTOM 2 00122 #define EFFECT_SLIDE_RIGHT 4 00123 #define EFFECT_SLIDE_LEFT 8 00124 #define EFFECT_SLIDE_IN 16 00125 #define EFFECT_SLIDE_OUT 32 00126 #define EFFECT_FADE 64 00127 #define EFFECT_SCALE 128 00128 #define EFFECT_COLOR_TRANSITION 256 00129 00130 //!Sound conversion and playback. A wrapper for other sound libraries - ASND, libmad, ltremor, etc 00131 class GuiSound 00132 { 00133 public: 00134 //!Constructor 00135 //!\param s Pointer to the sound data 00136 //!\param l Length of sound data 00137 //!\param t Sound format type (SOUND_PCM or SOUND_OGG) 00138 GuiSound(const u8 * s, int l, int t); 00139 //!Destructor 00140 ~GuiSound(); 00141 //!Start sound playback 00142 void Play(); 00143 //!Stop sound playback 00144 void Stop(); 00145 //!Pause sound playback 00146 void Pause(); 00147 //!Resume sound playback 00148 void Resume(); 00149 //!Checks if the sound is currently playing 00150 //!\return true if sound is playing, false otherwise 00151 bool IsPlaying(); 00152 //!Set sound volume 00153 //!\param v Sound volume (0-100) 00154 void SetVolume(int v); 00155 //!Set the sound to loop playback (only applies to OGG) 00156 //!\param l Loop (true to loop) 00157 void SetLoop(bool l); 00158 protected: 00159 const u8 * sound; //!< Pointer to the sound data 00160 int type; //!< Sound format type (SOUND_PCM or SOUND_OGG) 00161 s32 length; //!< Length of sound data 00162 s32 voice; //!< Currently assigned ASND voice channel 00163 s32 volume; //!< Sound volume (0-100) 00164 bool loop; //!< Loop sound playback 00165 }; 00166 00167 //!Menu input trigger management. Determine if action is neccessary based on input data by comparing controller input data to a specific trigger element. 00168 class GuiTrigger 00169 { 00170 public: 00171 //!Constructor 00172 GuiTrigger(); 00173 //!Destructor 00174 ~GuiTrigger(); 00175 //!Sets a simple trigger. Requires: element is selected, and trigger button is pressed 00176 //!\param ch Controller channel number 00177 //!\param wiibtns Wii controller trigger button(s) - classic controller buttons are considered separately 00178 //!\param gcbtns GameCube controller trigger button(s) 00179 void SetSimpleTrigger(s32 ch, u32 wiibtns, u16 gcbtns); 00180 //!Sets a held trigger. Requires: element is selected, and trigger button is pressed 00181 //!\param ch Controller channel number 00182 //!\param wiibtns Wii controller trigger button(s) - classic controller buttons are considered separately 00183 //!\param gcbtns GameCube controller trigger button(s) 00184 void SetHeldTrigger(s32 ch, u32 wiibtns, u16 gcbtns); 00185 //!Sets a button-only trigger. Requires: Trigger button is pressed 00186 //!\param ch Controller channel number 00187 //!\param wiibtns Wii controller trigger button(s) - classic controller buttons are considered separately 00188 //!\param gcbtns GameCube controller trigger button(s) 00189 void SetButtonOnlyTrigger(s32 ch, u32 wiibtns, u16 gcbtns); 00190 //!Sets a button-only trigger. Requires: trigger button is pressed and parent window of element is in focus 00191 //!\param ch Controller channel number 00192 //!\param wiibtns Wii controller trigger button(s) - classic controller buttons are considered separately 00193 //!\param gcbtns GameCube controller trigger button(s) 00194 void SetButtonOnlyInFocusTrigger(s32 ch, u32 wiibtns, u16 gcbtns); 00195 //!Get X/Y value from Wii Joystick (classic, nunchuk) input 00196 //!\param right Controller stick (left = 0, right = 1) 00197 //!\param axis Controller stick axis (x-axis = 0, y-axis = 1) 00198 //!\return Stick value 00199 s8 WPAD_Stick(u8 right, int axis); 00200 //!Move menu selection left (via pad/joystick). Allows scroll delay and button overriding 00201 //!\return true if selection should be moved left, false otherwise 00202 bool Left(); 00203 //!Move menu selection right (via pad/joystick). Allows scroll delay and button overriding 00204 //!\return true if selection should be moved right, false otherwise 00205 bool Right(); 00206 //!Move menu selection up (via pad/joystick). Allows scroll delay and button overriding 00207 //!\return true if selection should be moved up, false otherwise 00208 bool Up(); 00209 //!Move menu selection down (via pad/joystick). Allows scroll delay and button overriding 00210 //!\return true if selection should be moved down, false otherwise 00211 bool Down(); 00212 00213 u8 type; //!< trigger type (TRIGGER_SIMPLE, TRIGGER_HELD, TRIGGER_BUTTON_ONLY, TRIGGER_BUTTON_ONLY_IN_FOCUS) 00214 s32 chan; //!< Trigger controller channel (0-3, -1 for all) 00215 WPADData * wpad; //!< Wii controller trigger 00216 WPADData wpaddata; //!< Wii controller trigger data 00217 PADData pad; //!< GameCube controller trigger data 00218 }; 00219 00220 extern GuiTrigger userInput[4]; 00221 00222 //!Primary GUI class. Most other classes inherit from this class. 00223 class GuiElement 00224 { 00225 public: 00226 //!Constructor 00227 GuiElement(); 00228 //!Destructor 00229 ~GuiElement(); 00230 //!Set the element's parent 00231 //!\param e Pointer to parent element 00232 void SetParent(GuiElement * e); 00233 //!Gets the element's parent 00234 //!\return Pointer to parent element 00235 GuiElement * GetParent(); 00236 //!Gets the current leftmost coordinate of the element 00237 //!Considers horizontal alignment, x offset, width, and parent element's GetLeft() / GetWidth() values 00238 //!\return left coordinate 00239 int GetLeft(); 00240 //!Gets the current topmost coordinate of the element 00241 //!Considers vertical alignment, y offset, height, and parent element's GetTop() / GetHeight() values 00242 //!\return top coordinate 00243 int GetTop(); 00244 //!Sets the minimum y offset of the element 00245 //!\param y Y offset 00246 void SetMinY(int y); 00247 //!Gets the minimum y offset of the element 00248 //!\return Minimum Y offset 00249 int GetMinY(); 00250 //!Sets the maximum y offset of the element 00251 //!\param y Y offset 00252 void SetMaxY(int y); 00253 //!Gets the maximum y offset of the element 00254 //!\return Maximum Y offset 00255 int GetMaxY(); 00256 //!Sets the minimum x offset of the element 00257 //!\param x X offset 00258 void SetMinX(int x); 00259 //!Gets the minimum x offset of the element 00260 //!\return Minimum X offset 00261 int GetMinX(); 00262 //!Sets the maximum x offset of the element 00263 //!\param x X offset 00264 void SetMaxX(int x); 00265 //!Gets the maximum x offset of the element 00266 //!\return Maximum X offset 00267 int GetMaxX(); 00268 //!Gets the current width of the element. Does not currently consider the scale 00269 //!\return width 00270 int GetWidth(); 00271 //!Gets the height of the element. Does not currently consider the scale 00272 //!\return height 00273 int GetHeight(); 00274 //!Sets the size (width/height) of the element 00275 //!\param w Width of element 00276 //!\param h Height of element 00277 void SetSize(int w, int h); 00278 //!Checks whether or not the element is visible 00279 //!\return true if visible, false otherwise 00280 bool IsVisible(); 00281 //!Checks whether or not the element is selectable 00282 //!\return true if selectable, false otherwise 00283 bool IsSelectable(); 00284 //!Checks whether or not the element is clickable 00285 //!\return true if clickable, false otherwise 00286 bool IsClickable(); 00287 //!Checks whether or not the element is holdable 00288 //!\return true if holdable, false otherwise 00289 bool IsHoldable(); 00290 //!Sets whether or not the element is selectable 00291 //!\param s Selectable 00292 void SetSelectable(bool s); 00293 //!Sets whether or not the element is clickable 00294 //!\param c Clickable 00295 void SetClickable(bool c); 00296 //!Sets whether or not the element is holdable 00297 //!\param c Holdable 00298 void SetHoldable(bool d); 00299 //!Gets the element's current state 00300 //!\return state 00301 int GetState(); 00302 //!Gets the controller channel that last changed the element's state 00303 //!\return Channel number (0-3, -1 = no channel) 00304 int GetStateChan(); 00305 //!Sets the element's alpha value 00306 //!\param a alpha value 00307 void SetAlpha(int a); 00308 //!Gets the element's alpha value 00309 //!Considers alpha, alphaDyn, and the parent element's GetAlpha() value 00310 //!\return alpha 00311 int GetAlpha(); 00312 //!Sets the element's scale 00313 //!\param s scale (1 is 100%) 00314 void SetScale(float s); 00315 //!Gets the element's current scale 00316 //!Considers scale, scaleDyn, and the parent element's GetScale() value 00317 float GetScale(); 00318 //!Set a new GuiTrigger for the element 00319 //!\param t Pointer to GuiTrigger 00320 void SetTrigger(GuiTrigger * t); 00321 //!\overload 00322 //!\param i Index of trigger array to set 00323 //!\param t Pointer to GuiTrigger 00324 void SetTrigger(u8 i, GuiTrigger * t); 00325 //!Checks whether rumble was requested by the element 00326 //!\return true is rumble was requested, false otherwise 00327 bool Rumble(); 00328 //!Sets whether or not the element is requesting a rumble event 00329 //!\param r true if requesting rumble, false if not 00330 void SetRumble(bool r); 00331 //!Set an effect for the element 00332 //!\param e Effect to enable 00333 //!\param a Amount of the effect (usage varies on effect) 00334 //!\param t Target amount of the effect (usage varies on effect) 00335 void SetEffect(int e, int a, int t=0); 00336 //!Sets an effect to be enabled on wiimote cursor over 00337 //!\param e Effect to enable 00338 //!\param a Amount of the effect (usage varies on effect) 00339 //!\param t Target amount of the effect (usage varies on effect) 00340 void SetEffectOnOver(int e, int a, int t=0); 00341 //!Shortcut to SetEffectOnOver(EFFECT_SCALE, 4, 110) 00342 void SetEffectGrow(); 00343 //!Gets the current element effects 00344 //!\return element effects 00345 int GetEffect(); 00346 //!Checks whether the specified coordinates are within the element's boundaries 00347 //!\param x X coordinate 00348 //!\param y Y coordinate 00349 //!\return true if contained within, false otherwise 00350 bool IsInside(int x, int y); 00351 //!Sets the element's position 00352 //!\param x X coordinate 00353 //!\param y Y coordinate 00354 void SetPosition(int x, int y); 00355 //!Updates the element's effects (dynamic values) 00356 //!Called by Draw(), used for animation purposes 00357 void UpdateEffects(); 00358 //!Sets a function to called after after Update() 00359 //!Callback function can be used to response to changes in the state of the element, and/or update the element's attributes 00360 void SetUpdateCallback(UpdateCallback u); 00361 //!Checks whether the element is in focus 00362 //!\return true if element is in focus, false otherwise 00363 int IsFocused(); 00364 //!Sets the element's visibility 00365 //!\param v Visibility (true = visible) 00366 virtual void SetVisible(bool v); 00367 //!Sets the element's focus 00368 //!\param f Focus (true = in focus) 00369 virtual void SetFocus(int f); 00370 //!Sets the element's state 00371 //!\param s State (STATE_DEFAULT, STATE_SELECTED, STATE_CLICKED, STATE_DISABLED) 00372 //!\param c Controller channel (0-3, -1 = none) 00373 virtual void SetState(int s, int c = -1); 00374 //!Resets the element's state to STATE_DEFAULT 00375 virtual void ResetState(); 00376 //!Gets whether or not the element is in STATE_SELECTED 00377 //!\return true if selected, false otherwise 00378 virtual int GetSelected(); 00379 //!Sets the element's alignment respective to its parent element 00380 //!\param hor Horizontal alignment (ALIGN_LEFT, ALIGN_RIGHT, ALIGN_CENTRE) 00381 //!\param vert Vertical alignment (ALIGN_TOP, ALIGN_BOTTOM, ALIGN_MIDDLE) 00382 virtual void SetAlignment(int hor, int vert); 00383 //!Called constantly to allow the element to respond to the current input data 00384 //!\param t Pointer to a GuiTrigger, containing the current input data from PAD/WPAD 00385 virtual void Update(GuiTrigger * t); 00386 //!Called constantly to redraw the element 00387 virtual void Draw(); 00388 protected: 00389 bool visible; //!< Visibility of the element. If false, Draw() is skipped 00390 int focus; //!< Element focus (-1 = focus disabled, 0 = not focused, 1 = focused) 00391 int width; //!< Element width 00392 int height; //!< Element height 00393 int xoffset; //!< Element X offset 00394 int yoffset; //!< Element Y offset 00395 int ymin; //!< Element's min Y offset allowed 00396 int ymax; //!< Element's max Y offset allowed 00397 int xmin; //!< Element's min X offset allowed 00398 int xmax; //!< Element's max X offset allowed 00399 int xoffsetDyn; //!< Element X offset, dynamic (added to xoffset value for animation effects) 00400 int yoffsetDyn; //!< Element Y offset, dynamic (added to yoffset value for animation effects) 00401 int alpha; //!< Element alpha value (0-255) 00402 f32 scale; //!< Element scale (1 = 100%) 00403 int alphaDyn; //!< Element alpha, dynamic (multiplied by alpha value for blending/fading effects) 00404 f32 scaleDyn; //!< Element scale, dynamic (multiplied by alpha value for blending/fading effects) 00405 bool rumble; //!< Wiimote rumble (on/off) - set to on when this element requests a rumble event 00406 int effects; //!< Currently enabled effect(s). 0 when no effects are enabled 00407 int effectAmount; //!< Effect amount. Used by different effects for different purposes 00408 int effectTarget; //!< Effect target amount. Used by different effects for different purposes 00409 int effectsOver; //!< Effects to enable when wiimote cursor is over this element. Copied to effects variable on over event 00410 int effectAmountOver; //!< EffectAmount to set when wiimote cursor is over this element 00411 int effectTargetOver; //!< EffectTarget to set when wiimote cursor is over this element 00412 int alignmentHor; //!< Horizontal element alignment, respective to parent element (LEFT, RIGHT, CENTRE) 00413 int alignmentVert; //!< Horizontal element alignment, respective to parent element (TOP, BOTTOM, MIDDLE) 00414 int state; //!< Element state (DEFAULT, SELECTED, CLICKED, DISABLED) 00415 int stateChan; //!< Which controller channel is responsible for the last change in state 00416 bool selectable; //!< Whether or not this element selectable (can change to SELECTED state) 00417 bool clickable; //!< Whether or not this element is clickable (can change to CLICKED state) 00418 bool holdable; //!< Whether or not this element is holdable (can change to HELD state) 00419 GuiTrigger * trigger[2]; //!< GuiTriggers (input actions) that this element responds to 00420 GuiElement * parentElement; //!< Parent element 00421 UpdateCallback updateCB; //!< Callback function to call when this element is updated 00422 }; 00423 00424 //!Allows GuiElements to be grouped together into a "window" 00425 class GuiWindow : public GuiElement 00426 { 00427 public: 00428 //!Constructor 00429 GuiWindow(); 00430 //!\overload 00431 //!\param w Width of window 00432 //!\param h Height of window 00433 GuiWindow(int w, int h); 00434 //!Destructor 00435 ~GuiWindow(); 00436 //!Appends a GuiElement to the GuiWindow 00437 //!\param e The GuiElement to append. If it is already in the GuiWindow, it is removed first 00438 void Append(GuiElement* e); 00439 //!Inserts a GuiElement into the GuiWindow at the specified index 00440 //!\param e The GuiElement to insert. If it is already in the GuiWindow, it is removed first 00441 //!\param i Index in which to insert the element 00442 void Insert(GuiElement* e, u32 i); 00443 //!Removes the specified GuiElement from the GuiWindow 00444 //!\param e GuiElement to be removed 00445 void Remove(GuiElement* e); 00446 //!Removes all GuiElements 00447 void RemoveAll(); 00448 //!Returns the GuiElement at the specified index 00449 //!\param index The index of the element 00450 //!\return A pointer to the element at the index, NULL on error (eg: out of bounds) 00451 GuiElement* GetGuiElementAt(u32 index) const; 00452 //!Returns the size of the list of elements 00453 //!\return The size of the current element list 00454 u32 GetSize(); 00455 //!Sets the visibility of the window 00456 //!\param v visibility (true = visible) 00457 void SetVisible(bool v); 00458 //!Resets the window's state to STATE_DEFAULT 00459 void ResetState(); 00460 //!Sets the window's state 00461 //!\param s State 00462 void SetState(int s); 00463 //!Disables all of the window's children 00464 void DisableChildren(); 00465 //!Gets the index of the GuiElement inside the window that is currently selected 00466 //!\return index of selected GuiElement 00467 int GetSelected(); 00468 //!Sets the window focus 00469 //!\param f Focus 00470 void SetFocus(int f); 00471 //!Change the focus to the specified element 00472 //!This is intended for the primary GuiWindow only 00473 //!\param e GuiElement that should have focus 00474 void ChangeFocus(GuiElement * e); 00475 //!Changes window focus to the next focusable window or element 00476 //!If no element is in focus, changes focus to the first available element 00477 //!If B or 1 button is pressed, changes focus to the next available element 00478 //!This is intended for the primary GuiWindow only 00479 //!\param t Pointer to a GuiTrigger, containing the current input data from PAD/WPAD 00480 void ToggleFocus(GuiTrigger * t); 00481 //!Moves the selected element to the element to the left or right 00482 //!\param d Direction to move (-1 = left, 1 = right) 00483 void MoveSelectionHor(int d); 00484 //!Moves the selected element to the element above or below 00485 //!\param d Direction to move (-1 = up, 1 = down) 00486 void MoveSelectionVert(int d); 00487 //!Draws all the elements in this GuiWindow 00488 void Draw(); 00489 //!Updates the window and all elements contains within 00490 //!Allows the GuiWindow and all elements to respond to the input data specified 00491 //!\param t Pointer to a GuiTrigger, containing the current input data from PAD/WPAD 00492 void Update(GuiTrigger * t); 00493 protected: 00494 std::vector<GuiElement*> _elements; //!< Contains all elements within the GuiWindow 00495 }; 00496 00497 //!Converts image data into GX-useable RGBA8. Currently designed for use only with PNG files 00498 class GuiImageData 00499 { 00500 public: 00501 //!Constructor 00502 //!Converts the image data to RGBA8 - expects PNG format 00503 //!\param i Image data 00504 GuiImageData(const u8 * i); 00505 //!Destructor 00506 ~GuiImageData(); 00507 //!Gets a pointer to the image data 00508 //!\return pointer to image data 00509 u8 * GetImage(); 00510 //!Gets the image width 00511 //!\return image width 00512 int GetWidth(); 00513 //!Gets the image height 00514 //!\return image height 00515 int GetHeight(); 00516 protected: 00517 u8 * data; //!< Image data 00518 int height; //!< Height of image 00519 int width; //!< Width of image 00520 }; 00521 00522 //!Display, manage, and manipulate images in the GUI 00523 class GuiImage : public GuiElement 00524 { 00525 public: 00526 //!Constructor 00527 GuiImage(); 00528 //!\overload 00529 //!\param img Pointer to GuiImageData element 00530 GuiImage(GuiImageData * img); 00531 //!\overload 00532 //!Sets up a new image from the image data specified 00533 //!\param img 00534 //!\param w Image width 00535 //!\param h Image height 00536 GuiImage(u8 * img, int w, int h); 00537 //!\overload 00538 //!Creates an image filled with the specified color 00539 //!\param w Image width 00540 //!\param h Image height 00541 //!\param c Image color 00542 GuiImage(int w, int h, GXColor c); 00543 //!Destructor 00544 ~GuiImage(); 00545 //!Sets the image rotation angle for drawing 00546 //!\param a Angle (in degrees) 00547 void SetAngle(float a); 00548 //!Sets the number of times to draw the image horizontally 00549 //!\param t Number of times to draw the image 00550 void SetTile(int t); 00551 //!Constantly called to draw the image 00552 void Draw(); 00553 //!Gets the image data 00554 //!\return pointer to image data 00555 u8 * GetImage(); 00556 //!Sets up a new image using the GuiImageData object specified 00557 //!\param img Pointer to GuiImageData object 00558 void SetImage(GuiImageData * img); 00559 //!\overload 00560 //!\param img Pointer to image data 00561 //!\param w Width 00562 //!\param h Height 00563 void SetImage(u8 * img, int w, int h); 00564 //!Gets the pixel color at the specified coordinates of the image 00565 //!\param x X coordinate 00566 //!\param y Y coordinate 00567 GXColor GetPixel(int x, int y); 00568 //!Sets the pixel color at the specified coordinates of the image 00569 //!\param x X coordinate 00570 //!\param y Y coordinate 00571 //!\param color Pixel color 00572 void SetPixel(int x, int y, GXColor color); 00573 //!Sets the image to the specified color 00574 //!\param c Image color 00575 void SetColor(GXColor c); 00576 //!Directly modifies the image data to create a color-striped effect 00577 //!Alters the RGB values by the specified amount 00578 //!\param s Amount to increment/decrement the RGB values in the image 00579 void ColorStripe(int s); 00580 //!Directly modifies the image data to change the image to grayscale 00581 void Grayscale(); 00582 //!Sets a stripe effect on the image, overlaying alpha blended rectangles 00583 //!Does not alter the image data 00584 //!\param s Alpha amount to draw over the image 00585 void SetStripe(int s); 00586 void SetDisplaySize(int w, int h) { displayWidth = w, displayHeight = h; } 00587 protected: 00588 int imgType; //!< Type of image data (IMAGE_TEXTURE, IMAGE_COLOR, IMAGE_DATA) 00589 u8 * image; //!< Poiner to image data. May be shared with GuiImageData data 00590 f32 imageangle; //!< Angle to draw the image 00591 int tile; //!< Number of times to draw (tile) the image horizontally 00592 int stripe; //!< Alpha value (0-255) to apply a stripe effect to the texture 00593 u16 displayWidth; 00594 u16 displayHeight; 00595 }; 00596 00597 //!Display, manage, and manipulate text in the GUI 00598 class GuiText : public GuiElement 00599 { 00600 public: 00601 GuiText(); 00602 //!Constructor 00603 //!\param t Text 00604 //!\param s Font size 00605 //!\param c Font color 00606 GuiText(const char * t, int s, GXColor c); 00607 //!\overload 00608 //!\Assumes SetPresets() has been called to setup preferred text attributes 00609 //!\param t Text 00610 GuiText(const char * t); 00611 //!Destructor 00612 ~GuiText(); 00613 //!Sets the text of the GuiText element 00614 //!\param t Text 00615 void SetText(const char * t); 00616 //!Sets up preset values to be used by GuiText(t) 00617 //!Useful when printing multiple text elements, all with the same attributes set 00618 //!\param sz Font size 00619 //!\param c Font color 00620 //!\param w Maximum width of texture image (for text wrapping) 00621 //!\param s Font size 00622 //!\param h Text alignment (horizontal) 00623 //!\param v Text alignment (vertical) 00624 void SetPresets(int sz, GXColor c, int w, u16 s, int h, int v); 00625 //!Sets the font size 00626 //!\param s Font size 00627 void SetFontSize(int s); 00628 //!Sets the maximum width of the drawn texture image 00629 //!\param w Maximum width 00630 void SetMaxWidth(int width); 00631 //!Enables/disables text scrolling 00632 //!\param s Scrolling on/off 00633 void SetScroll(int s); 00634 //!Enables/disables text wrapping 00635 //!\param w Wrapping on/off 00636 //!\param width Maximum width (0 to disable) 00637 void SetWrap(bool w, int width = 0); 00638 //!Sets the font color 00639 //!\param c Font color 00640 void SetColor(GXColor c); 00641 //!Sets the FreeTypeGX style attributes 00642 //!\param s Style attributes 00643 void SetStyle(u16 s); 00644 //!Sets the text alignment 00645 //!\param hor Horizontal alignment (ALIGN_LEFT, ALIGN_RIGHT, ALIGN_CENTRE) 00646 //!\param vert Vertical alignment (ALIGN_TOP, ALIGN_BOTTOM, ALIGN_MIDDLE) 00647 void SetAlignment(int hor, int vert); 00648 //!Constantly called to draw the text 00649 void Draw(); 00650 protected: 00651 char * origText; //!< Original text data 00652 wchar_t* text; //!< Unicode text value 00653 int size; //!< Font size 00654 int maxWidth; //!< Maximum width of the generated text object (for text wrapping) 00655 bool wrap; //!< Wrapping toggle 00656 wchar_t* textDyn; //!< Wrapped text value 00657 int textScroll; //!< Scrolling toggle 00658 int textScrollPos; //!< Current starting index of text string for scrolling 00659 int textScrollInitialDelay; //!< Delay to wait before starting to scroll 00660 int textScrollDelay; //!< Scrolling speed 00661 u16 style; //!< FreeTypeGX style attributes 00662 GXColor color; //!< Font color 00663 }; 00664 00665 //!Display, manage, and manipulate buttons in the GUI. Buttons can have images, icons, text, and sound set (all of which are optional) 00666 class GuiButton : public GuiElement 00667 { 00668 public: 00669 GuiButton(); 00670 //!Constructor 00671 //!\param w Width 00672 //!\param h Height 00673 GuiButton(int w, int h); 00674 //!Destructor 00675 ~GuiButton(); 00676 //!Sets the button's image 00677 //!\param i Pointer to GuiImage object 00678 void SetImage(GuiImage* i); 00679 //!Sets the button's image on over 00680 //!\param i Pointer to GuiImage object 00681 void SetImageOver(GuiImage* i); 00682 //!Sets the button's image on hold 00683 //!\param i Pointer to GuiImage object 00684 void SetImageHold(GuiImage* i); 00685 //!Sets the button's image on click 00686 //!\param i Pointer to GuiImage object 00687 void SetImageClick(GuiImage* i); 00688 //!Sets the button's icon 00689 //!\param i Pointer to GuiImage object 00690 void SetIcon(GuiImage* i); 00691 //!Sets the button's icon on over 00692 //!\param i Pointer to GuiImage object 00693 void SetIconOver(GuiImage* i); 00694 //!Sets the button's icon on hold 00695 //!\param i Pointer to GuiImage object 00696 void SetIconHold(GuiImage* i); 00697 //!Sets the button's icon on click 00698 //!\param i Pointer to GuiImage object 00699 void SetIconClick(GuiImage* i); 00700 //!Sets the button's label 00701 //!\param t Pointer to GuiText object 00702 //!\param n Index of label to set (optional, default is 0) 00703 void SetLabel(GuiText* t, int n = 0); 00704 //!Sets the button's label on over (eg: different colored text) 00705 //!\param t Pointer to GuiText object 00706 //!\param n Index of label to set (optional, default is 0) 00707 void SetLabelOver(GuiText* t, int n = 0); 00708 //!Sets the button's label on hold 00709 //!\param t Pointer to GuiText object 00710 //!\param n Index of label to set (optional, default is 0) 00711 void SetLabelHold(GuiText* t, int n = 0); 00712 //!Sets the button's label on click 00713 //!\param t Pointer to GuiText object 00714 //!\param n Index of label to set (optional, default is 0) 00715 void SetLabelClick(GuiText* t, int n = 0); 00716 //!Sets the sound to play on over 00717 //!\param s Pointer to GuiSound object 00718 void SetSoundOver(GuiSound * s); 00719 //!Sets the sound to play on hold 00720 //!\param s Pointer to GuiSound object 00721 void SetSoundHold(GuiSound * s); 00722 //!Sets the sound to play on click 00723 //!\param s Pointer to GuiSound object 00724 void SetSoundClick(GuiSound * s); 00725 //!Constantly called to draw the GuiButton 00726 void Draw(); 00727 //!Constantly called to allow the GuiButton to respond to updated input data 00728 //!\param t Pointer to a GuiTrigger, containing the current input data from PAD/WPAD 00729 void Update(GuiTrigger * t); 00730 protected: 00731 GuiImage * image; //!< Button image (default) 00732 GuiImage * imageOver; //!< Button image for STATE_SELECTED 00733 GuiImage * imageHold; //!< Button image for STATE_HELD 00734 GuiImage * imageClick; //!< Button image for STATE_CLICKED 00735 GuiImage * icon; //!< Button icon (drawn after button image) 00736 GuiImage * iconOver; //!< Button icon for STATE_SELECTED 00737 GuiImage * iconHold; //!< Button icon for STATE_HELD 00738 GuiImage * iconClick; //!< Button icon for STATE_CLICKED 00739 GuiText * label[3]; //!< Label(s) to display (default) 00740 GuiText * labelOver[3]; //!< Label(s) to display for STATE_SELECTED 00741 GuiText * labelHold[3]; //!< Label(s) to display for STATE_HELD 00742 GuiText * labelClick[3]; //!< Label(s) to display for STATE_CLICKED 00743 GuiSound * soundOver; //!< Sound to play for STATE_SELECTED 00744 GuiSound * soundHold; //!< Sound to play for STATE_HELD 00745 GuiSound * soundClick; //!< Sound to play for STATE_CLICKED 00746 }; 00747 00748 typedef struct _keytype { 00749 char ch, chShift; 00750 } Key; 00751 00752 //!On-screen keyboard 00753 class GuiKeyboard : public GuiWindow 00754 { 00755 public: 00756 GuiKeyboard(char * t, u32 m); 00757 ~GuiKeyboard(); 00758 void Update(GuiTrigger * t); 00759 char kbtextstr[256]; 00760 protected: 00761 u32 kbtextmaxlen; 00762 Key keys[4][11]; 00763 int shift; 00764 int caps; 00765 GuiText * kbText; 00766 GuiImage * keyTextboxImg; 00767 GuiText * keyCapsText; 00768 GuiImage * keyCapsImg; 00769 GuiImage * keyCapsOverImg; 00770 GuiButton * keyCaps; 00771 GuiText * keyShiftText; 00772 GuiImage * keyShiftImg; 00773 GuiImage * keyShiftOverImg; 00774 GuiButton * keyShift; 00775 GuiText * keyBackText; 00776 GuiImage * keyBackImg; 00777 GuiImage * keyBackOverImg; 00778 GuiButton * keyBack; 00779 GuiImage * keySpaceImg; 00780 GuiImage * keySpaceOverImg; 00781 GuiButton * keySpace; 00782 GuiButton * keyBtn[4][11]; 00783 GuiImage * keyImg[4][11]; 00784 GuiImage * keyImgOver[4][11]; 00785 GuiText * keyTxt[4][11]; 00786 GuiImageData * keyTextbox; 00787 GuiImageData * key; 00788 GuiImageData * keyOver; 00789 GuiImageData * keyMedium; 00790 GuiImageData * keyMediumOver; 00791 GuiImageData * keyLarge; 00792 GuiImageData * keyLargeOver; 00793 GuiSound * keySoundOver; 00794 GuiSound * keySoundClick; 00795 GuiTrigger * trigA; 00796 }; 00797 00798 typedef struct _optionlist { 00799 int length; 00800 char name[MAX_OPTIONS][50]; 00801 char value[MAX_OPTIONS][50]; 00802 } OptionList; 00803 00804 //!Display a list of menu options 00805 class GuiOptionBrowser : public GuiElement 00806 { 00807 public: 00808 GuiOptionBrowser(int w, int h, OptionList * l); 00809 ~GuiOptionBrowser(); 00810 void SetCol2Position(int x); 00811 int FindMenuItem(int c, int d); 00812 int GetClickedOption(); 00813 void ResetState(); 00814 void SetFocus(int f); 00815 void Draw(); 00816 void TriggerUpdate(); 00817 void Update(GuiTrigger * t); 00818 GuiText * optionVal[PAGESIZE]; 00819 protected: 00820 int selectedItem; 00821 int listOffset; 00822 bool listChanged; 00823 00824 OptionList * options; 00825 int optionIndex[PAGESIZE]; 00826 GuiButton * optionBtn[PAGESIZE]; 00827 GuiText * optionTxt[PAGESIZE]; 00828 GuiImage * optionBg[PAGESIZE]; 00829 00830 GuiButton * arrowUpBtn; 00831 GuiButton * arrowDownBtn; 00832 00833 GuiImage * bgOptionsImg; 00834 GuiImage * scrollbarImg; 00835 GuiImage * arrowDownImg; 00836 GuiImage * arrowDownOverImg; 00837 GuiImage * arrowUpImg; 00838 GuiImage * arrowUpOverImg; 00839 00840 GuiImageData * bgOptions; 00841 GuiImageData * bgOptionsEntry; 00842 GuiImageData * scrollbar; 00843 GuiImageData * arrowDown; 00844 GuiImageData * arrowDownOver; 00845 GuiImageData * arrowUp; 00846 GuiImageData * arrowUpOver; 00847 00848 GuiSound * btnSoundOver; 00849 GuiSound * btnSoundClick; 00850 GuiTrigger * trigA; 00851 }; 00852 00853 //!Display a list of files 00854 class GuiFileBrowser : public GuiElement 00855 { 00856 public: 00857 GuiFileBrowser(int w, int h); 00858 ~GuiFileBrowser(); 00859 void ResetState(); 00860 void SetFocus(int f); 00861 void Draw(); 00862 void TriggerUpdate(); 00863 void Update(GuiTrigger * t); 00864 GuiButton * fileList[FILE_PAGESIZE]; 00865 protected: 00866 int selectedItem; 00867 int numEntries; 00868 bool listChanged; 00869 00870 GuiText * fileListText[FILE_PAGESIZE]; 00871 GuiImage * fileListBg[FILE_PAGESIZE]; 00872 GuiImage * fileListFolder[FILE_PAGESIZE]; 00873 00874 GuiButton * arrowUpBtn; 00875 GuiButton * arrowDownBtn; 00876 GuiButton * scrollbarBoxBtn; 00877 00878 GuiImage * bgFileSelectionImg; 00879 GuiImage * scrollbarImg; 00880 GuiImage * arrowDownImg; 00881 GuiImage * arrowDownOverImg; 00882 GuiImage * arrowUpImg; 00883 GuiImage * arrowUpOverImg; 00884 GuiImage * scrollbarBoxImg; 00885 GuiImage * scrollbarBoxOverImg; 00886 00887 GuiImageData * bgFileSelection; 00888 GuiImageData * bgFileSelectionEntry; 00889 GuiImageData * fileFolder; 00890 GuiImageData * scrollbar; 00891 GuiImageData * arrowDown; 00892 GuiImageData * arrowDownOver; 00893 GuiImageData * arrowUp; 00894 GuiImageData * arrowUpOver; 00895 GuiImageData * scrollbarBox; 00896 GuiImageData * scrollbarBoxOver; 00897 00898 GuiSound * btnSoundOver; 00899 GuiSound * btnSoundClick; 00900 GuiTrigger * trigA; 00901 GuiTrigger * trigHeldA; 00902 }; 00903 00904 #endif