- Main Page
- Classes
- Files

- File List

# gui.h

    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/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, int 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                 PADData pad;
    00217 };
    00218
    00219 extern GuiTrigger userInput[4];
    00220
    00222 class GuiElement
    00223 {
    00224         public:
    00226                 GuiElement();
    00228                 ~GuiElement();
    00231                 void SetParent(GuiElement * e);
    00234                 GuiElement * GetParent();
    00238                 int GetLeft();
    00242                 int GetTop();
    00245                 void SetMinY(int y);
    00248                 int GetMinY();
    00251                 void SetMaxY(int y);
    00254                 int GetMaxY();
    00257                 void SetMinX(int x);
    00260                 int GetMinX();
    00263                 void SetMaxX(int x);
    00266                 int GetMaxX();
    00269                 int GetWidth();
    00272                 int GetHeight();
    00276                 void SetSize(int w, int h);
    00279                 bool IsVisible();
    00282                 bool IsSelectable();
    00285                 bool IsClickable();
    00288                 bool IsHoldable();
    00291                 void SetSelectable(bool s);
    00294                 void SetClickable(bool c);
    00297                 void SetHoldable(bool d);
    00300                 int GetState();
    00303                 int GetStateChan();
    00306                 void SetAlpha(int a);
    00310                 int GetAlpha();
    00313                 void SetScale(float s);
    00316                 float GetScale();
    00319                 void SetTrigger(GuiTrigger * t);
    00323                 void SetTrigger(u8 i, GuiTrigger * t);
    00326                 bool Rumble();
    00329                 void SetRumble(bool r);
    00334                 void SetEffect(int e, int a, int t=0);
    00339                 void SetEffectOnOver(int e, int a, int t=0);
    00341                 void SetEffectGrow();
    00344                 int GetEffect();
    00349                 bool IsInside(int x, int y);
    00353                 void SetPosition(int x, int y);
    00356                 void UpdateEffects();
    00359                 void SetUpdateCallback(UpdateCallback u);
    00362                 int IsFocused();
    00365                 virtual void SetVisible(bool v);
    00368                 virtual void SetFocus(int f);
    00372                 virtual void SetState(int s, int c = -1);
    00374                 virtual void ResetState();
    00377                 virtual int GetSelected();
    00381                 virtual void SetAlignment(int hor, int vert);
    00384                 virtual void Update(GuiTrigger * t);
    00386                 virtual void Draw();
    00387         protected:
    00388                 bool visible;
    00389                 int focus;
    00390                 int width;
    00391                 int height;
    00392                 int xoffset;
    00393                 int yoffset;
    00394                 int ymin;
    00395                 int ymax;
    00396                 int xmin;
    00397                 int xmax;
    00398                 int xoffsetDyn;
    00399                 int yoffsetDyn;
    00400                 int alpha;
    00401                 f32 scale;
    00402                 int alphaDyn;
    00403                 f32 scaleDyn;
    00404                 bool rumble;
    00405                 int effects;
    00406                 int effectAmount;
    00407                 int effectTarget;
    00408                 int effectsOver;
    00409                 int effectAmountOver;
    00410                 int effectTargetOver;
    00411                 int alignmentHor;
    00412                 int alignmentVert;
    00413                 int state;
    00414                 int stateChan;
    00415                 bool selectable;
    00416                 bool clickable;
    00417                 bool holdable;
    00418                 GuiTrigger * trigger[2];
    00419                 GuiElement * parentElement;
    00420                 UpdateCallback updateCB;
    00421 };
    00422
    00424 class GuiWindow : public GuiElement
    00425 {
    00426         public:
    00428                 GuiWindow();
    00432                 GuiWindow(int w, int h);
    00434                 ~GuiWindow();
    00437                 void Append(GuiElement* e);
    00441                 void Insert(GuiElement* e, u32 i);
    00444                 void Remove(GuiElement* e);
    00446                 void RemoveAll();
    00450                 GuiElement* GetGuiElementAt(u32 index) const;
    00453                 u32 GetSize();
    00456                 void SetVisible(bool v);
    00458                 void ResetState();
    00461                 void SetState(int s);
    00464                 int GetSelected();
    00467                 void SetFocus(int f);
    00471                 void ChangeFocus(GuiElement * e);
    00477                 void ToggleFocus(GuiTrigger * t);
    00480                 void MoveSelectionHor(int d);
    00483                 void MoveSelectionVert(int d);
    00485                 void Draw();
    00489                 void Update(GuiTrigger * t);
    00490         protected:
    00491                 std::vector<GuiElement*> _elements;
    00492 };
    00493
    00495 class GuiImageData
    00496 {
    00497         public:
    00501                 GuiImageData(const u8 * i);
    00503                 ~GuiImageData();
    00506                 u8 * GetImage();
    00509                 int GetWidth();
    00512                 int GetHeight();
    00513         protected:
    00514                 u8 * data;
    00515                 int height;
    00516                 int width;
    00517 };
    00518
    00520 class GuiImage : public GuiElement
    00521 {
    00522         public:
    00524                 GuiImage();
    00527                 GuiImage(GuiImageData * img);
    00533                 GuiImage(u8 * img, int w, int h);
    00539                 GuiImage(int w, int h, GXColor c);
    00541                 ~GuiImage();
    00544                 void SetAngle(float a);
    00547                 void SetTile(int t);
    00549                 void Draw();
    00552                 u8 * GetImage();
    00555                 void SetImage(GuiImageData * img);
    00560                 void SetImage(u8 * img, int w, int h);
    00564                 GXColor GetPixel(int x, int y);
    00569                 void SetPixel(int x, int y, GXColor color);
    00573                 void ColorStripe(int s);
    00577                 void SetStripe(int s);
    00578         protected:
    00579                 int imgType;
    00580                 u8 * image;
    00581                 f32 imageangle;
    00582                 int tile;
    00583                 int stripe;
    00584 };
    00585
    00587 class GuiText : public GuiElement
    00588 {
    00589         public:
    00594                 GuiText(const char * t, int s, GXColor c);
    00598                 GuiText(const char * t);
    00600                 ~GuiText();
    00603                 void SetText(const char * t);
    00612                 void SetPresets(int sz, GXColor c, int w, u16 s, int h, int v);
    00615                 void SetFontSize(int s);
    00618                 void SetMaxWidth(int width);
    00621                 void SetScroll(int s);
    00625                 void SetWrap(bool w, int width = 0);
    00628                 void SetColor(GXColor c);
    00631                 void SetStyle(u16 s);
    00635                 void SetAlignment(int hor, int vert);
    00637                 void Draw();
    00638         protected:
    00639                 char * origText;
    00640                 wchar_t* text;
    00641                 int size;
    00642                 int maxWidth;
    00643                 bool wrap;
    00644                 wchar_t* textDyn;
    00645                 int textScroll;
    00646                 int textScrollPos;
    00647                 int textScrollInitialDelay;
    00648                 int textScrollDelay;
    00649                 u16 style;
    00650                 GXColor color;
    00651 };
    00652
    00654 class GuiButton : public GuiElement
    00655 {
    00656         public:
    00660                 GuiButton(int w, int h);
    00662                 ~GuiButton();
    00665                 void SetImage(GuiImage* i);
    00668                 void SetImageOver(GuiImage* i);
    00671                 void SetImageHold(GuiImage* i);
    00674                 void SetImageClick(GuiImage* i);
    00677                 void SetIcon(GuiImage* i);
    00680                 void SetIconOver(GuiImage* i);
    00683                 void SetIconHold(GuiImage* i);
    00686                 void SetIconClick(GuiImage* i);
    00690                 void SetLabel(GuiText* t, int n = 0);
    00694                 void SetLabelOver(GuiText* t, int n = 0);
    00698                 void SetLabelHold(GuiText* t, int n = 0);
    00702                 void SetLabelClick(GuiText* t, int n = 0);
    00705                 void SetSoundOver(GuiSound * s);
    00708                 void SetSoundHold(GuiSound * s);
    00711                 void SetSoundClick(GuiSound * s);
    00713                 void Draw();
    00716                 void Update(GuiTrigger * t);
    00717         protected:
    00718                 GuiImage * image;
    00719                 GuiImage * imageOver;
    00720                 GuiImage * imageHold;
    00721                 GuiImage * imageClick;
    00722                 GuiImage * icon;
    00723                 GuiImage * iconOver;
    00724                 GuiImage * iconHold;
    00725                 GuiImage * iconClick;
    00726                 GuiText * label[3];
    00727                 GuiText * labelOver[3];
    00728                 GuiText * labelHold[3];
    00729                 GuiText * labelClick[3];
    00730                 GuiSound * soundOver;
    00731                 GuiSound * soundHold;
    00732                 GuiSound * soundClick;
    00733 };
    00734
    00735 typedef struct _keytype {
    00736         char ch, chShift;
    00737 } Key;
    00738
    00740 class GuiKeyboard : public GuiWindow
    00741 {
    00742         public:
    00743                 GuiKeyboard(char * t, u32 m);
    00744                 ~GuiKeyboard();
    00745                 void Update(GuiTrigger * t);
    00746                 char kbtextstr[256];
    00747         protected:
    00748                 u32 kbtextmaxlen;
    00749                 Key keys[4][11];
    00750                 int shift;
    00751                 int caps;
    00752                 GuiText * kbText;
    00753                 GuiImage * keyTextboxImg;
    00754                 GuiText * keyCapsText;
    00755                 GuiImage * keyCapsImg;
    00756                 GuiImage * keyCapsOverImg;
    00757                 GuiButton * keyCaps;
    00758                 GuiText * keyShiftText;
    00759                 GuiImage * keyShiftImg;
    00760                 GuiImage * keyShiftOverImg;
    00761                 GuiButton * keyShift;
    00762                 GuiText * keyBackText;
    00763                 GuiImage * keyBackImg;
    00764                 GuiImage * keyBackOverImg;
    00765                 GuiButton * keyBack;
    00766                 GuiImage * keySpaceImg;
    00767                 GuiImage * keySpaceOverImg;
    00768                 GuiButton * keySpace;
    00769                 GuiButton * keyBtn[4][11];
    00770                 GuiImage * keyImg[4][11];
    00771                 GuiImage * keyImgOver[4][11];
    00772                 GuiText * keyTxt[4][11];
    00773                 GuiImageData * keyTextbox;
    00774                 GuiImageData * key;
    00775                 GuiImageData * keyOver;
    00776                 GuiImageData * keyMedium;
    00777                 GuiImageData * keyMediumOver;
    00778                 GuiImageData * keyLarge;
    00779                 GuiImageData * keyLargeOver;
    00780                 GuiSound * keySoundOver;
    00781                 GuiSound * keySoundClick;
    00782                 GuiTrigger * trigA;
    00783 };
    00784
    00785 typedef struct _optionlist {
    00786         int length;
    00787         char name[MAX_OPTIONS][50];
    00788         char value[MAX_OPTIONS][50];
    00789 } OptionList;
    00790
    00792 class GuiOptionBrowser : public GuiElement
    00793 {
    00794         public:
    00795                 GuiOptionBrowser(int w, int h, OptionList * l);
    00796                 ~GuiOptionBrowser();
    00797                 void SetCol2Position(int x);
    00798                 int FindMenuItem(int c, int d);
    00799                 int GetClickedOption();
    00800                 void ResetState();
    00801                 void SetFocus(int f);
    00802                 void Draw();
    00803                 void TriggerUpdate();
    00804                 void Update(GuiTrigger * t);
    00805                 GuiText * optionVal[PAGESIZE];
    00806         protected:
    00807                 int selectedItem;
    00808                 int listOffset;
    00809                 bool listChanged;
    00810
    00811                 OptionList * options;
    00812                 int optionIndex[PAGESIZE];
    00813                 GuiButton * optionBtn[PAGESIZE];
    00814                 GuiText * optionTxt[PAGESIZE];
    00815                 GuiImage * optionBg[PAGESIZE];
    00816
    00817                 GuiButton * arrowUpBtn;
    00818                 GuiButton * arrowDownBtn;
    00819
    00820                 GuiImage * bgOptionsImg;
    00821                 GuiImage * scrollbarImg;
    00822                 GuiImage * arrowDownImg;
    00823                 GuiImage * arrowDownOverImg;
    00824                 GuiImage * arrowUpImg;
    00825                 GuiImage * arrowUpOverImg;
    00826
    00827                 GuiImageData * bgOptions;
    00828                 GuiImageData * bgOptionsEntry;
    00829                 GuiImageData * scrollbar;
    00830                 GuiImageData * arrowDown;
    00831                 GuiImageData * arrowDownOver;
    00832                 GuiImageData * arrowUp;
    00833                 GuiImageData * arrowUpOver;
    00834
    00835                 GuiSound * btnSoundOver;
    00836                 GuiSound * btnSoundClick;
    00837                 GuiTrigger * trigA;
    00838 };
    00839
    00841 class GuiFileBrowser : public GuiElement
    00842 {
    00843         public:
    00844                 GuiFileBrowser(int w, int h);
    00845                 ~GuiFileBrowser();
    00846                 void ResetState();
    00847                 void SetFocus(int f);
    00848                 void Draw();
    00849                 void TriggerUpdate();
    00850                 void Update(GuiTrigger * t);
    00851                 GuiButton * fileList[FILE_PAGESIZE];
    00852         protected:
    00853                 int selectedItem;
    00854                 int numEntries;
    00855                 bool listChanged;
    00856
    00857                 GuiText * fileListText[FILE_PAGESIZE];
    00858                 GuiImage * fileListBg[FILE_PAGESIZE];
    00859                 GuiImage * fileListFolder[FILE_PAGESIZE];
    00860
    00861                 GuiButton * arrowUpBtn;
    00862                 GuiButton * arrowDownBtn;
    00863                 GuiButton * scrollbarBoxBtn;
    00864
    00865                 GuiImage * bgFileSelectionImg;
    00866                 GuiImage * scrollbarImg;
    00867                 GuiImage * arrowDownImg;
    00868                 GuiImage * arrowDownOverImg;
    00869                 GuiImage * arrowUpImg;
    00870                 GuiImage * arrowUpOverImg;
    00871                 GuiImage * scrollbarBoxImg;
    00872                 GuiImage * scrollbarBoxOverImg;
    00873
    00874                 GuiImageData * bgFileSelection;
    00875                 GuiImageData * bgFileSelectionEntry;
    00876                 GuiImageData * fileFolder;
    00877                 GuiImageData * scrollbar;
    00878                 GuiImageData * arrowDown;
    00879                 GuiImageData * arrowDownOver;
    00880                 GuiImageData * arrowUp;
    00881                 GuiImageData * arrowUpOver;
    00882                 GuiImageData * scrollbarBox;
    00883                 GuiImageData * scrollbarBoxOver;
    00884
    00885                 GuiSound * btnSoundOver;
    00886                 GuiSound * btnSoundClick;
    00887                 GuiTrigger * trigA;
    00888                 GuiTrigger * trigHeldA;
    00889 };
    00890
    00891 #endif