- 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 <math.h>
    00040 #include <asndlib.h>
    00041 #include <wiiuse/wpad.h>
    00042 #include "pngu/pngu.h"
    00043 #include "FreeTypeGX.h"
    00044 #include "video.h"
    00045 #include "filelist.h"
    00046 #include "input.h"
    00047 #include "oggplayer.h"
    00048
    00049 extern FreeTypeGX *fontSystem;
    00050
    00051 #define SCROLL_INITIAL_DELAY    20
    00052 #define SCROLL_LOOP_DELAY               3
    00053 #define PAGESIZE                                8
    00054 #define MAX_OPTIONS                     30
    00055
    00056 typedef void (*UpdateCallback)(void * e);
    00057
    00058 enum
    00059 {
    00060         ALIGN_LEFT,
    00061         ALIGN_RIGHT,
    00062         ALIGN_CENTRE,
    00063         ALIGN_TOP,
    00064         ALIGN_BOTTOM,
    00065         ALIGN_MIDDLE
    00066 };
    00067
    00068 enum
    00069 {
    00070         STATE_DEFAULT,
    00071         STATE_SELECTED,
    00072         STATE_CLICKED,
    00073         STATE_HELD,
    00074         STATE_DISABLED
    00075 };
    00076
    00077 enum
    00078 {
    00079         SOUND_PCM,
    00080         SOUND_OGG
    00081 };
    00082
    00083 enum
    00084 {
    00085         IMAGE_TEXTURE,
    00086         IMAGE_COLOR,
    00087         IMAGE_DATA
    00088 };
    00089
    00090 enum
    00091 {
    00092         TRIGGER_SIMPLE,
    00093         TRIGGER_HELD,
    00094         TRIGGER_BUTTON_ONLY,
    00095         TRIGGER_BUTTON_ONLY_IN_FOCUS
    00096 };
    00097
    00098 typedef struct _paddata {
    00099         u16 btns_d;
    00100         u16 btns_u;
    00101         u16 btns_h;
    00102         s8 stickX;
    00103         s8 stickY;
    00104         s8 substickX;
    00105         s8 substickY;
    00106         u8 triggerL;
    00107         u8 triggerR;
    00108 } PADData;
    00109
    00110 #define EFFECT_SLIDE_TOP                        1
    00111 #define EFFECT_SLIDE_BOTTOM                     2
    00112 #define EFFECT_SLIDE_RIGHT                      4
    00113 #define EFFECT_SLIDE_LEFT                       8
    00114 #define EFFECT_SLIDE_IN                         16
    00115 #define EFFECT_SLIDE_OUT                        32
    00116 #define EFFECT_FADE                                     64
    00117 #define EFFECT_SCALE                            128
    00118 #define EFFECT_COLOR_TRANSITION         256
    00119
    00121 class GuiSound
    00122 {
    00123         public:
    00128                 GuiSound(const u8 * s, int l, int t);
    00130                 ~GuiSound();
    00132                 void Play();
    00134                 void Stop();
    00136                 void Pause();
    00138                 void Resume();
    00141                 bool IsPlaying();
    00144                 void SetVolume(int v);
    00147                 void SetLoop(bool l);
    00148         protected:
    00149                 const u8 * sound;
    00150                 int type;
    00151                 s32 length;
    00152                 s32 voice;
    00153                 s32 volume;
    00154                 bool loop;
    00155 };
    00156
    00158 class GuiTrigger
    00159 {
    00160         public:
    00162                 GuiTrigger();
    00164                 ~GuiTrigger();
    00169                 void SetSimpleTrigger(s32 ch, u32 wiibtns, u16 gcbtns);
    00174                 void SetHeldTrigger(s32 ch, u32 wiibtns, u16 gcbtns);
    00179                 void SetButtonOnlyTrigger(s32 ch, u32 wiibtns, u16 gcbtns);
    00184                 void SetButtonOnlyInFocusTrigger(s32 ch, u32 wiibtns, u16 gcbtns);
    00189                 s8 WPAD_Stick(u8 right, int axis);
    00192                 bool Left();
    00195                 bool Right();
    00198                 bool Up();
    00201                 bool Down();
    00202
    00203                 u8 type;
    00204                 s32 chan;
    00205                 WPADData wpad;
    00206                 PADData pad;
    00207 };
    00208
    00209 extern GuiTrigger userInput[4];
    00210
    00212 class GuiElement
    00213 {
    00214         public:
    00216                 GuiElement();
    00218                 ~GuiElement();
    00221                 void SetParent(GuiElement * e);
    00225                 int GetLeft();
    00229                 int GetTop();
    00232                 void SetMinY(int y);
    00235                 int GetMinY();
    00238                 void SetMaxY(int y);
    00241                 int GetMaxY();
    00244                 void SetMinX(int x);
    00247                 int GetMinX();
    00250                 void SetMaxX(int x);
    00253                 int GetMaxX();
    00256                 int GetWidth();
    00259                 int GetHeight();
    00263                 void SetSize(int w, int h);
    00266                 bool IsVisible();
    00269                 bool IsSelectable();
    00272                 bool IsClickable();
    00275                 bool IsHoldable();
    00278                 void SetSelectable(bool s);
    00281                 void SetClickable(bool c);
    00284                 void SetHoldable(bool d);
    00287                 int GetState();
    00290                 int GetStateChan();
    00293                 void SetAlpha(int a);
    00297                 int GetAlpha();
    00300                 void SetScale(float s);
    00303                 float GetScale();
    00306                 void SetTrigger(GuiTrigger * t);
    00310                 void SetTrigger(u8 i, GuiTrigger * t);
    00313                 bool Rumble();
    00316                 void SetRumble(bool r);
    00321                 void SetEffect(int e, int a, int t=0);
    00326                 void SetEffectOnOver(int e, int a, int t=0);
    00328                 void SetEffectGrow();
    00331                 int GetEffect();
    00336                 bool IsInside(int x, int y);
    00340                 void SetPosition(int x, int y);
    00343                 void UpdateEffects();
    00346                 void SetUpdateCallback(UpdateCallback u);
    00349                 int IsFocused();
    00352                 virtual void SetVisible(bool v);
    00355                 virtual void SetFocus(int f);
    00359                 virtual void SetState(int s, int c = -1);
    00361                 virtual void ResetState();
    00364                 virtual int GetSelected();
    00368                 virtual void SetAlignment(int hor, int vert);
    00371                 virtual void Update(GuiTrigger * t);
    00373                 virtual void Draw();
    00374         protected:
    00375                 bool visible;
    00376                 int focus;
    00377                 int width;
    00378                 int height;
    00379                 int xoffset;
    00380                 int yoffset;
    00381                 int ymin;
    00382                 int ymax;
    00383                 int xmin;
    00384                 int xmax;
    00385                 int xoffsetDyn;
    00386                 int yoffsetDyn;
    00387                 int alpha;
    00388                 f32 scale;
    00389                 int alphaDyn;
    00390                 f32 scaleDyn;
    00391                 bool rumble;
    00392                 int effects;
    00393                 int effectAmount;
    00394                 int effectTarget;
    00395                 int effectsOver;
    00396                 int effectAmountOver;
    00397                 int effectTargetOver;
    00398                 int alignmentHor;
    00399                 int alignmentVert;
    00400                 int state;
    00401                 int stateChan;
    00402                 bool selectable;
    00403                 bool clickable;
    00404                 bool holdable;
    00405                 GuiTrigger * trigger[2];
    00406                 GuiElement * parentElement;
    00407                 UpdateCallback updateCB;
    00408 };
    00409
    00411 class GuiWindow : public GuiElement
    00412 {
    00413         public:
    00415                 GuiWindow();
    00419                 GuiWindow(int w, int h);
    00421                 ~GuiWindow();
    00424                 void Append(GuiElement* e);
    00428                 void Insert(GuiElement* e, u32 i);
    00431                 void Remove(GuiElement* e);
    00433                 void RemoveAll();
    00437                 GuiElement* GetGuiElementAt(u32 index) const;
    00440                 u32 GetSize();
    00443                 void SetVisible(bool v);
    00445                 void ResetState();
    00448                 void SetState(int s);
    00451                 int GetSelected();
    00454                 void SetFocus(int f);
    00458                 void ChangeFocus(GuiElement * e);
    00464                 void ToggleFocus(GuiTrigger * t);
    00467                 void MoveSelectionHor(int d);
    00470                 void MoveSelectionVert(int d);
    00472                 void Draw();
    00476                 void Update(GuiTrigger * t);
    00477         protected:
    00478                 std::vector<GuiElement*> _elements;
    00479 };
    00480
    00482 class GuiImageData
    00483 {
    00484         public:
    00488                 GuiImageData(const u8 * i);
    00490                 ~GuiImageData();
    00493                 u8 * GetImage();
    00496                 int GetWidth();
    00499                 int GetHeight();
    00500         protected:
    00501                 u8 * data;
    00502                 int height;
    00503                 int width;
    00504 };
    00505
    00507 class GuiImage : public GuiElement
    00508 {
    00509         public:
    00511                 GuiImage();
    00514                 GuiImage(GuiImageData * img);
    00520                 GuiImage(u8 * img, int w, int h);
    00526                 GuiImage(int w, int h, GXColor c);
    00528                 ~GuiImage();
    00531                 void SetAngle(float a);
    00534                 void SetTile(int t);
    00536                 void Draw();
    00539                 u8 * GetImage();
    00542                 void SetImage(GuiImageData * img);
    00547                 void SetImage(u8 * img, int w, int h);
    00551                 GXColor GetPixel(int x, int y);
    00556                 void SetPixel(int x, int y, GXColor color);
    00560                 void ColorStripe(int s);
    00564                 void SetStripe(int s);
    00565         protected:
    00566                 int imgType;
    00567                 u8 * image;
    00568                 f32 imageangle;
    00569                 int tile;
    00570                 int stripe;
    00571 };
    00572
    00574 class GuiText : public GuiElement
    00575 {
    00576         public:
    00581                 GuiText(const char * t, int s, GXColor c);
    00585                 GuiText(const char * t);
    00587                 ~GuiText();
    00590                 void SetText(const char * t);
    00599                 void SetPresets(int sz, GXColor c, int w, u16 s, int h, int v);
    00602                 void SetFontSize(int s);
    00606                 void SetMaxWidth(int w);
    00609                 void SetColor(GXColor c);
    00612                 void SetStyle(u16 s);
    00616                 void SetAlignment(int hor, int vert);
    00618                 void Draw();
    00619         protected:
    00620                 wchar_t* text;
    00621                 int size;
    00622                 int maxWidth;
    00623                 u16 style;
    00624                 GXColor color;
    00625 };
    00626
    00628 class GuiButton : public GuiElement
    00629 {
    00630         public:
    00634                 GuiButton(int w, int h);
    00636                 ~GuiButton();
    00639                 void SetImage(GuiImage* i);
    00642                 void SetImageOver(GuiImage* i);
    00645                 void SetImageHold(GuiImage* i);
    00648                 void SetImageClick(GuiImage* i);
    00651                 void SetIcon(GuiImage* i);
    00654                 void SetIconOver(GuiImage* i);
    00657                 void SetIconHold(GuiImage* i);
    00660                 void SetIconClick(GuiImage* i);
    00664                 void SetLabel(GuiText* t, int n = 0);
    00668                 void SetLabelOver(GuiText* t, int n = 0);
    00672                 void SetLabelHold(GuiText* t, int n = 0);
    00676                 void SetLabelClick(GuiText* t, int n = 0);
    00679                 void SetSoundOver(GuiSound * s);
    00682                 void SetSoundHold(GuiSound * s);
    00685                 void SetSoundClick(GuiSound * s);
    00687                 void Draw();
    00690                 void Update(GuiTrigger * t);
    00691         protected:
    00692                 GuiImage * image;
    00693                 GuiImage * imageOver;
    00694                 GuiImage * imageHold;
    00695                 GuiImage * imageClick;
    00696                 GuiImage * icon;
    00697                 GuiImage * iconOver;
    00698                 GuiImage * iconHold;
    00699                 GuiImage * iconClick;
    00700                 GuiText * label[3];
    00701                 GuiText * labelOver[3];
    00702                 GuiText * labelHold[3];
    00703                 GuiText * labelClick[3];
    00704                 GuiSound * soundOver;
    00705                 GuiSound * soundHold;
    00706                 GuiSound * soundClick;
    00707 };
    00708
    00709 typedef struct _keytype {
    00710         char ch, chShift;
    00711 } Key;
    00712
    00714 class GuiKeyboard : public GuiWindow
    00715 {
    00716         public:
    00717                 GuiKeyboard(char * t, u32 m);
    00718                 ~GuiKeyboard();
    00719                 void Update(GuiTrigger * t);
    00720                 char kbtextstr[256];
    00721         protected:
    00722                 u32 kbtextmaxlen;
    00723                 Key keys[4][11];
    00724                 int shift;
    00725                 int caps;
    00726                 GuiText * kbText;
    00727                 GuiImage * keyTextboxImg;
    00728                 GuiText * keyCapsText;
    00729                 GuiImage * keyCapsImg;
    00730                 GuiImage * keyCapsOverImg;
    00731                 GuiButton * keyCaps;
    00732                 GuiText * keyShiftText;
    00733                 GuiImage * keyShiftImg;
    00734                 GuiImage * keyShiftOverImg;
    00735                 GuiButton * keyShift;
    00736                 GuiText * keyBackText;
    00737                 GuiImage * keyBackImg;
    00738                 GuiImage * keyBackOverImg;
    00739                 GuiButton * keyBack;
    00740                 GuiImage * keySpaceImg;
    00741                 GuiImage * keySpaceOverImg;
    00742                 GuiButton * keySpace;
    00743                 GuiButton * keyBtn[4][11];
    00744                 GuiImage * keyImg[4][11];
    00745                 GuiImage * keyImgOver[4][11];
    00746                 GuiText * keyTxt[4][11];
    00747                 GuiImageData * keyTextbox;
    00748                 GuiImageData * key;
    00749                 GuiImageData * keyOver;
    00750                 GuiImageData * keyMedium;
    00751                 GuiImageData * keyMediumOver;
    00752                 GuiImageData * keyLarge;
    00753                 GuiImageData * keyLargeOver;
    00754                 GuiSound * keySoundOver;
    00755                 GuiSound * keySoundClick;
    00756                 GuiTrigger * trigA;
    00757 };
    00758
    00759 typedef struct _optionlist {
    00760         int length;
    00761         char name[MAX_OPTIONS][150];
    00762         char value[MAX_OPTIONS][150];
    00763 } OptionList;
    00764
    00766 class GuiOptionBrowser : public GuiElement
    00767 {
    00768         public:
    00769                 GuiOptionBrowser(int w, int h, OptionList * l);
    00770                 ~GuiOptionBrowser();
    00771                 void SetCol2Position(int x);
    00772                 int FindMenuItem(int c, int d);
    00773                 int GetClickedOption();
    00774                 void ResetState();
    00775                 void SetFocus(int f);
    00776                 void Draw();
    00777                 void Update(GuiTrigger * t);
    00778                 GuiText * optionVal[PAGESIZE];
    00779         protected:
    00780                 int selectedItem;
    00781                 int listOffset;
    00782
    00783                 OptionList * options;
    00784                 int optionIndex[PAGESIZE];
    00785                 GuiButton * optionBtn[PAGESIZE];
    00786                 GuiText * optionTxt[PAGESIZE];
    00787                 GuiImage * optionBg[PAGESIZE];
    00788
    00789                 GuiButton * arrowUpBtn;
    00790                 GuiButton * arrowDownBtn;
    00791                 GuiButton * scrollbarBoxBtn;
    00792
    00793                 GuiImage * bgOptionsImg;
    00794                 GuiImage * scrollbarImg;
    00795                 GuiImage * arrowDownImg;
    00796                 GuiImage * arrowDownOverImg;
    00797                 GuiImage * arrowUpImg;
    00798                 GuiImage * arrowUpOverImg;
    00799                 GuiImage * scrollbarBoxImg;
    00800                 GuiImage * scrollbarBoxOverImg;
    00801
    00802                 GuiImageData * bgOptions;
    00803                 GuiImageData * bgOptionsEntry;
    00804                 GuiImageData * scrollbar;
    00805                 GuiImageData * arrowDown;
    00806                 GuiImageData * arrowDownOver;
    00807                 GuiImageData * arrowUp;
    00808                 GuiImageData * arrowUpOver;
    00809                 GuiImageData * scrollbarBox;
    00810                 GuiImageData * scrollbarBoxOver;
    00811
    00812                 GuiSound * btnSoundOver;
    00813                 GuiSound * btnSoundClick;
    00814                 GuiTrigger * trigA;
    00815 };
    00816 #endif