00001 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 00131 class GuiSound 00132 { 00133 public: 00138 GuiSound(const u8 * s, s32 l, int t); 00140 ~GuiSound(); 00142 void Play(); 00144 void Stop(); 00146 void Pause(); 00148 void Resume(); 00151 bool IsPlaying(); 00154 void SetVolume(int v); 00157 void SetLoop(bool l); 00158 protected: 00159 const u8 * sound; 00160 int type; 00161 s32 length; 00162 s32 voice; 00163 s32 volume; 00164 bool loop; 00165 }; 00166 00168 class GuiTrigger 00169 { 00170 public: 00172 GuiTrigger(); 00174 ~GuiTrigger(); 00179 void SetSimpleTrigger(s32 ch, u32 wiibtns, u16 gcbtns); 00184 void SetHeldTrigger(s32 ch, u32 wiibtns, u16 gcbtns); 00189 void SetButtonOnlyTrigger(s32 ch, u32 wiibtns, u16 gcbtns); 00194 void SetButtonOnlyInFocusTrigger(s32 ch, u32 wiibtns, u16 gcbtns); 00199 s8 WPAD_Stick(u8 right, int axis); 00202 bool Left(); 00205 bool Right(); 00208 bool Up(); 00211 bool Down(); 00212 00213 u8 type; 00214 s32 chan; 00215 WPADData * wpad; 00216 WPADData wpaddata; 00217 PADData pad; 00218 }; 00219 00220 extern GuiTrigger userInput[4]; 00221 00223 class GuiElement 00224 { 00225 public: 00227 GuiElement(); 00229 ~GuiElement(); 00232 void SetParent(GuiElement * e); 00235 GuiElement * GetParent(); 00239 int GetLeft(); 00243 int GetTop(); 00246 void SetMinY(int y); 00249 int GetMinY(); 00252 void SetMaxY(int y); 00255 int GetMaxY(); 00258 void SetMinX(int x); 00261 int GetMinX(); 00264 void SetMaxX(int x); 00267 int GetMaxX(); 00270 int GetWidth(); 00273 int GetHeight(); 00277 void SetSize(int w, int h); 00280 bool IsVisible(); 00283 bool IsSelectable(); 00286 bool IsClickable(); 00289 bool IsHoldable(); 00292 void SetSelectable(bool s); 00295 void SetClickable(bool c); 00298 void SetHoldable(bool h); 00301 int GetState(); 00304 int GetStateChan(); 00307 void SetAlpha(int a); 00311 int GetAlpha(); 00314 void SetScale(float s); 00317 float GetScale(); 00320 void SetTrigger(GuiTrigger * t); 00324 void SetTrigger(u8 i, GuiTrigger * t); 00327 bool Rumble(); 00330 void SetRumble(bool r); 00335 void SetEffect(int e, int a, int t=0); 00340 void SetEffectOnOver(int e, int a, int t=0); 00342 void SetEffectGrow(); 00345 int GetEffect(); 00350 bool IsInside(int x, int y); 00354 void SetPosition(int x, int y); 00357 void UpdateEffects(); 00360 void SetUpdateCallback(UpdateCallback u); 00363 int IsFocused(); 00366 virtual void SetVisible(bool v); 00369 virtual void SetFocus(int f); 00373 virtual void SetState(int s, int c = -1); 00375 virtual void ResetState(); 00378 virtual int GetSelected(); 00382 virtual void SetAlignment(int hor, int vert); 00385 virtual void Update(GuiTrigger * t); 00387 virtual void Draw(); 00388 protected: 00389 bool visible; 00390 int focus; 00391 int width; 00392 int height; 00393 int xoffset; 00394 int yoffset; 00395 int ymin; 00396 int ymax; 00397 int xmin; 00398 int xmax; 00399 int xoffsetDyn; 00400 int yoffsetDyn; 00401 int alpha; 00402 f32 scale; 00403 int alphaDyn; 00404 f32 scaleDyn; 00405 bool rumble; 00406 int effects; 00407 int effectAmount; 00408 int effectTarget; 00409 int effectsOver; 00410 int effectAmountOver; 00411 int effectTargetOver; 00412 int alignmentHor; 00413 int alignmentVert; 00414 int state; 00415 int stateChan; 00416 bool selectable; 00417 bool clickable; 00418 bool holdable; 00419 GuiTrigger * trigger[2]; 00420 GuiElement * parentElement; 00421 UpdateCallback updateCB; 00422 }; 00423 00425 class GuiWindow : public GuiElement 00426 { 00427 public: 00429 GuiWindow(); 00433 GuiWindow(int w, int h); 00435 ~GuiWindow(); 00438 void Append(GuiElement* e); 00442 void Insert(GuiElement* e, u32 i); 00445 void Remove(GuiElement* e); 00447 void RemoveAll(); 00451 GuiElement* GetGuiElementAt(u32 index) const; 00454 u32 GetSize(); 00457 void SetVisible(bool v); 00459 void ResetState(); 00462 void SetState(int s); 00465 int GetSelected(); 00468 void SetFocus(int f); 00472 void ChangeFocus(GuiElement * e); 00478 void ToggleFocus(GuiTrigger * t); 00481 void MoveSelectionHor(int d); 00484 void MoveSelectionVert(int d); 00486 void Draw(); 00490 void Update(GuiTrigger * t); 00491 protected: 00492 std::vector<GuiElement*> _elements; 00493 }; 00494 00496 class GuiImageData 00497 { 00498 public: 00502 GuiImageData(const u8 * i); 00504 ~GuiImageData(); 00507 u8 * GetImage(); 00510 int GetWidth(); 00513 int GetHeight(); 00514 protected: 00515 u8 * data; 00516 int height; 00517 int width; 00518 }; 00519 00521 class GuiImage : public GuiElement 00522 { 00523 public: 00525 GuiImage(); 00528 GuiImage(GuiImageData * img); 00534 GuiImage(u8 * img, int w, int h); 00540 GuiImage(int w, int h, GXColor c); 00542 ~GuiImage(); 00545 void SetAngle(float a); 00548 void SetTile(int t); 00550 void Draw(); 00553 u8 * GetImage(); 00556 void SetImage(GuiImageData * img); 00561 void SetImage(u8 * img, int w, int h); 00565 GXColor GetPixel(int x, int y); 00570 void SetPixel(int x, int y, GXColor color); 00574 void ColorStripe(int s); 00576 void Grayscale(); 00580 void SetStripe(int s); 00581 protected: 00582 int imgType; 00583 u8 * image; 00584 f32 imageangle; 00585 int tile; 00586 int stripe; 00587 }; 00588 00590 class GuiText : public GuiElement 00591 { 00592 public: 00597 GuiText(const char * t, int s, GXColor c); 00601 GuiText(const char * t); 00603 ~GuiText(); 00606 void SetText(const char * t); 00615 void SetPresets(int sz, GXColor c, int w, u16 s, int h, int v); 00618 void SetFontSize(int s); 00621 void SetMaxWidth(int w); 00624 void SetScroll(int s); 00628 void SetWrap(bool w, int width = 0); 00631 void SetColor(GXColor c); 00634 void SetStyle(u16 s); 00638 void SetAlignment(int hor, int vert); 00640 void Draw(); 00641 protected: 00642 char * origText; 00643 wchar_t* text; 00644 int size; 00645 int maxWidth; 00646 bool wrap; 00647 wchar_t* textDyn; 00648 int textScroll; 00649 int textScrollPos; 00650 int textScrollInitialDelay; 00651 int textScrollDelay; 00652 u16 style; 00653 GXColor color; 00654 }; 00655 00657 class GuiButton : public GuiElement 00658 { 00659 public: 00663 GuiButton(int w, int h); 00665 ~GuiButton(); 00668 void SetImage(GuiImage* i); 00671 void SetImageOver(GuiImage* i); 00674 void SetImageHold(GuiImage* i); 00677 void SetImageClick(GuiImage* i); 00680 void SetIcon(GuiImage* i); 00683 void SetIconOver(GuiImage* i); 00686 void SetIconHold(GuiImage* i); 00689 void SetIconClick(GuiImage* i); 00693 void SetLabel(GuiText* t, int n = 0); 00697 void SetLabelOver(GuiText* t, int n = 0); 00701 void SetLabelHold(GuiText* t, int n = 0); 00705 void SetLabelClick(GuiText* t, int n = 0); 00708 void SetSoundOver(GuiSound * s); 00711 void SetSoundHold(GuiSound * s); 00714 void SetSoundClick(GuiSound * s); 00716 void Draw(); 00719 void Update(GuiTrigger * t); 00720 protected: 00721 GuiImage * image; 00722 GuiImage * imageOver; 00723 GuiImage * imageHold; 00724 GuiImage * imageClick; 00725 GuiImage * icon; 00726 GuiImage * iconOver; 00727 GuiImage * iconHold; 00728 GuiImage * iconClick; 00729 GuiText * label[3]; 00730 GuiText * labelOver[3]; 00731 GuiText * labelHold[3]; 00732 GuiText * labelClick[3]; 00733 GuiSound * soundOver; 00734 GuiSound * soundHold; 00735 GuiSound * soundClick; 00736 }; 00737 00738 typedef struct _keytype { 00739 char ch, chShift; 00740 } Key; 00741 00743 class GuiKeyboard : public GuiWindow 00744 { 00745 public: 00746 GuiKeyboard(char * t, u32 m); 00747 ~GuiKeyboard(); 00748 void Update(GuiTrigger * t); 00749 char kbtextstr[256]; 00750 protected: 00751 u32 kbtextmaxlen; 00752 Key keys[4][11]; 00753 int shift; 00754 int caps; 00755 GuiText * kbText; 00756 GuiImage * keyTextboxImg; 00757 GuiText * keyCapsText; 00758 GuiImage * keyCapsImg; 00759 GuiImage * keyCapsOverImg; 00760 GuiButton * keyCaps; 00761 GuiText * keyShiftText; 00762 GuiImage * keyShiftImg; 00763 GuiImage * keyShiftOverImg; 00764 GuiButton * keyShift; 00765 GuiText * keyBackText; 00766 GuiImage * keyBackImg; 00767 GuiImage * keyBackOverImg; 00768 GuiButton * keyBack; 00769 GuiImage * keySpaceImg; 00770 GuiImage * keySpaceOverImg; 00771 GuiButton * keySpace; 00772 GuiButton * keyBtn[4][11]; 00773 GuiImage * keyImg[4][11]; 00774 GuiImage * keyImgOver[4][11]; 00775 GuiText * keyTxt[4][11]; 00776 GuiImageData * keyTextbox; 00777 GuiImageData * key; 00778 GuiImageData * keyOver; 00779 GuiImageData * keyMedium; 00780 GuiImageData * keyMediumOver; 00781 GuiImageData * keyLarge; 00782 GuiImageData * keyLargeOver; 00783 GuiSound * keySoundOver; 00784 GuiSound * keySoundClick; 00785 GuiTrigger * trigA; 00786 }; 00787 00788 typedef struct _optionlist { 00789 int length; 00790 char name[MAX_OPTIONS][50]; 00791 char value[MAX_OPTIONS][50]; 00792 } OptionList; 00793 00795 class GuiOptionBrowser : public GuiElement 00796 { 00797 public: 00798 GuiOptionBrowser(int w, int h, OptionList * l); 00799 ~GuiOptionBrowser(); 00800 void SetCol2Position(int x); 00801 int FindMenuItem(int c, int d); 00802 int GetClickedOption(); 00803 void ResetState(); 00804 void SetFocus(int f); 00805 void Draw(); 00806 void TriggerUpdate(); 00807 void Update(GuiTrigger * t); 00808 GuiText * optionVal[PAGESIZE]; 00809 protected: 00810 int selectedItem; 00811 int listOffset; 00812 bool listChanged; 00813 00814 OptionList * options; 00815 int optionIndex[PAGESIZE]; 00816 GuiButton * optionBtn[PAGESIZE]; 00817 GuiText * optionTxt[PAGESIZE]; 00818 GuiImage * optionBg[PAGESIZE]; 00819 00820 GuiButton * arrowUpBtn; 00821 GuiButton * arrowDownBtn; 00822 00823 GuiImage * bgOptionsImg; 00824 GuiImage * scrollbarImg; 00825 GuiImage * arrowDownImg; 00826 GuiImage * arrowDownOverImg; 00827 GuiImage * arrowUpImg; 00828 GuiImage * arrowUpOverImg; 00829 00830 GuiImageData * bgOptions; 00831 GuiImageData * bgOptionsEntry; 00832 GuiImageData * scrollbar; 00833 GuiImageData * arrowDown; 00834 GuiImageData * arrowDownOver; 00835 GuiImageData * arrowUp; 00836 GuiImageData * arrowUpOver; 00837 00838 GuiSound * btnSoundOver; 00839 GuiSound * btnSoundClick; 00840 GuiTrigger * trigA; 00841 }; 00842 00844 class GuiFileBrowser : public GuiElement 00845 { 00846 public: 00847 GuiFileBrowser(int w, int h); 00848 ~GuiFileBrowser(); 00849 void ResetState(); 00850 void SetFocus(int f); 00851 void Draw(); 00852 void TriggerUpdate(); 00853 void Update(GuiTrigger * t); 00854 GuiButton * fileList[FILE_PAGESIZE]; 00855 protected: 00856 int selectedItem; 00857 int numEntries; 00858 bool listChanged; 00859 00860 GuiText * fileListText[FILE_PAGESIZE]; 00861 GuiImage * fileListBg[FILE_PAGESIZE]; 00862 GuiImage * fileListFolder[FILE_PAGESIZE]; 00863 00864 GuiButton * arrowUpBtn; 00865 GuiButton * arrowDownBtn; 00866 GuiButton * scrollbarBoxBtn; 00867 00868 GuiImage * bgFileSelectionImg; 00869 GuiImage * scrollbarImg; 00870 GuiImage * arrowDownImg; 00871 GuiImage * arrowDownOverImg; 00872 GuiImage * arrowUpImg; 00873 GuiImage * arrowUpOverImg; 00874 GuiImage * scrollbarBoxImg; 00875 GuiImage * scrollbarBoxOverImg; 00876 00877 GuiImageData * bgFileSelection; 00878 GuiImageData * bgFileSelectionEntry; 00879 GuiImageData * fileFolder; 00880 GuiImageData * scrollbar; 00881 GuiImageData * arrowDown; 00882 GuiImageData * arrowDownOver; 00883 GuiImageData * arrowUp; 00884 GuiImageData * arrowUpOver; 00885 GuiImageData * scrollbarBox; 00886 GuiImageData * scrollbarBoxOver; 00887 00888 GuiSound * btnSoundOver; 00889 GuiSound * btnSoundClick; 00890 GuiTrigger * trigA; 00891 GuiTrigger * trigHeldA; 00892 }; 00893 00894 #endif