- Main Page
- Classes
- Files

- File List

# gui.h

    00001
    00032 #ifndef LIBWIIGUI_H
    00033 #define LIBWIIGUI_H
    00034
    00035 #include <gccore.h>
    00036 #include <malloc.h>
    00037 #include <stdlib.h>
    00038 #include <string.h>
    00039 #include <exception>
    00040 #include <vector>
    00041 #include <math.h>
    00042 #include <asndlib.h>
    00043 #include "pngu/pngu.h"
    00044 #include "FreeTypeGX.h"
    00045 #include "video.h"
    00046 #include "input.h"
    00047 #include "filelist.h"
    00048 #include "menu.h"
    00049 #include "oggplayer.h"
    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_DISABLED
    00074 };
    00075
    00076 enum
    00077 {
    00078         SOUND_PCM,
    00079         SOUND_OGG
    00080 };
    00081
    00082 enum
    00083 {
    00084         IMAGE_TEXTURE,
    00085         IMAGE_COLOR,
    00086         IMAGE_DATA
    00087 };
    00088
    00089 #define EFFECT_SLIDE_TOP                        1
    00090 #define EFFECT_SLIDE_BOTTOM                     2
    00091 #define EFFECT_SLIDE_RIGHT                      4
    00092 #define EFFECT_SLIDE_LEFT                       8
    00093 #define EFFECT_SLIDE_IN                         16
    00094 #define EFFECT_SLIDE_OUT                        32
    00095 #define EFFECT_FADE                                     64
    00096 #define EFFECT_SCALE                            128
    00097 #define EFFECT_COLOR_TRANSITION         256
    00098
    00099 extern FreeTypeGX *fontSystem;
    00100
    00102 class GuiSound
    00103 {
    00104         public:
    00109                 GuiSound(const u8 * s, int l, int t);
    00111                 ~GuiSound();
    00113                 void Play();
    00115                 void Stop();
    00117                 void Pause();
    00119                 void Resume();
    00122                 void SetVolume(int v);
    00123         protected:
    00124                 const u8 * sound;
    00125                 int type;
    00126                 s32 length;
    00127                 s32 voice;
    00128                 s32 volume;
    00129 };
    00130
    00132 class GuiElement
    00133 {
    00134         public:
    00136                 GuiElement();
    00138                 ~GuiElement();
    00141                 void SetParent(GuiElement * e);
    00145                 int GetLeft();
    00149                 int GetTop();
    00152                 int GetWidth();
    00155                 int GetHeight();
    00159                 void SetSize(int w, int h);
    00162                 bool IsVisible();
    00165                 bool IsSelectable();
    00168                 bool IsClickable();
    00171                 void SetSelectable(bool s);
    00174                 void SetClickable(bool c);
    00177                 int GetState();
    00180                 void SetAlpha(int a);
    00184                 int GetAlpha();
    00187                 void SetScale(float s);
    00190                 float GetScale();
    00193                 void SetTrigger(GuiTrigger * t);
    00197                 void SetTrigger(u8 i, GuiTrigger * t);
    00200                 bool Rumble();
    00203                 void SetRumble(bool r);
    00208                 void SetEffect(int e, int a, int t=0);
    00213                 void SetEffectOnOver(int e, int a, int t=0);
    00215                 void SetEffectGrow();
    00218                 int GetEffect();
    00223                 bool IsInside(int x, int y);
    00227                 void SetPosition(int x, int y);
    00230                 void UpdateEffects();
    00233                 void SetUpdateCallback(UpdateCallback u);
    00236                 int IsFocused();
    00239                 virtual void SetVisible(bool v);
    00242                 virtual void SetFocus(int f);
    00245                 virtual void SetState(int s);
    00247                 virtual void ResetState();
    00250                 virtual int GetSelected();
    00254                 virtual void SetAlignment(int hor, int vert);
    00257                 virtual void Update(GuiTrigger * t);
    00259                 virtual void Draw();
    00260         protected:
    00261                 bool visible;
    00262                 int focus;
    00263                 int width;
    00264                 int height;
    00265                 int xoffset;
    00266                 int yoffset;
    00267                 int xoffsetDyn;
    00268                 int yoffsetDyn;
    00269                 int alpha;
    00270                 f32 scale;
    00271                 int alphaDyn;
    00272                 f32 scaleDyn;
    00273                 bool rumble;
    00274                 int effects;
    00275                 int effectAmount;
    00276                 int effectTarget;
    00277                 int effectsOver;
    00278                 int effectAmountOver;
    00279                 int effectTargetOver;
    00280                 int alignmentHor;
    00281                 int alignmentVert;
    00282                 int state;
    00283                 bool selectable;
    00284                 bool clickable;
    00285                 GuiTrigger * trigger[2];
    00286                 GuiElement * parentElement;
    00287                 UpdateCallback updateCB;
    00288 };
    00289
    00291 class GuiWindow : public GuiElement
    00292 {
    00293         public:
    00295                 GuiWindow();
    00299                 GuiWindow(int w, int h);
    00301                 ~GuiWindow();
    00304                 void Append(GuiElement* e);
    00308                 void Insert(GuiElement* e, u32 i);
    00311                 void Remove(GuiElement* e);
    00313                 void RemoveAll();
    00317                 GuiElement* GetGuiElementAt(u32 index) const;
    00320                 u32 GetSize();
    00323                 void SetVisible(bool v);
    00325                 void ResetState();
    00328                 void SetState(int s);
    00331                 int GetSelected();
    00334                 void SetFocus(int f);
    00338                 void ChangeFocus(GuiElement * e);
    00344                 void ToggleFocus(GuiTrigger * t);
    00347                 void MoveSelectionHor(int d);
    00350                 void MoveSelectionVert(int d);
    00352                 void Draw();
    00356                 void Update(GuiTrigger * t);
    00357         protected:
    00358                 std::vector<GuiElement*> _elements;
    00359 };
    00360
    00363 class GuiImageData
    00364 {
    00365         public:
    00369                 GuiImageData(const u8 * i);
    00371                 ~GuiImageData();
    00374                 u8 * GetImage();
    00377                 int GetWidth();
    00380                 int GetHeight();
    00381         protected:
    00382                 u8 * data;
    00383                 int height;
    00384                 int width;
    00385 };
    00386
    00388 class GuiImage : public GuiElement
    00389 {
    00390         public:
    00393                 GuiImage(GuiImageData * img);
    00399                 GuiImage(u8 * img, int w, int h);
    00405                 GuiImage(int w, int h, GXColor c);
    00407                 ~GuiImage();
    00410                 void SetAngle(float a);
    00413                 void SetTile(int t);
    00415                 void Draw();
    00418                 u8 * GetImage();
    00421                 void SetImage(GuiImageData * img);
    00426                 void SetImage(u8 * img, int w, int h);
    00430                 GXColor GetPixel(int x, int y);
    00435                 void SetPixel(int x, int y, GXColor color);
    00439                 void ColorStripe(int s);
    00443                 void SetStripe(int s);
    00444         protected:
    00445                 int imgType;
    00446                 u8 * image;
    00447                 f32 imageangle;
    00448                 int tile;
    00449                 int stripe;
    00450 };
    00451
    00453 class GuiText : public GuiElement
    00454 {
    00455         public:
    00460                 GuiText(const char * t, int s, GXColor c);
    00464                 GuiText(const char * t);
    00466                 ~GuiText();
    00469                 void SetText(const char * t);
    00478                 void SetPresets(int sz, GXColor c, int w, u16 s, int h, int v);
    00481                 void SetFontSize(int s);
    00485                 void SetMaxWidth(int w);
    00488                 void SetColor(GXColor c);
    00491                 void SetStyle(u16 s);
    00495                 void SetAlignment(int hor, int vert);
    00497                 void Draw();
    00498         protected:
    00499                 wchar_t* text;
    00500                 int size;
    00501                 int maxWidth;
    00502                 u16 style;
    00503                 GXColor color;
    00504 };
    00505
    00508 class GuiButton : public GuiElement
    00509 {
    00510         public:
    00514                 GuiButton(int w, int h);
    00516                 ~GuiButton();
    00519                 void SetImage(GuiImage* i);
    00522                 void SetImageOver(GuiImage* i);
    00525                 void SetIcon(GuiImage* i);
    00528                 void SetIconOver(GuiImage* i);
    00531                 void SetLabel(GuiText* t);
    00535                 void SetLabel(GuiText* t, int n);
    00538                 void SetLabelOver(GuiText* t);
    00542                 void SetLabelOver(GuiText* t, int n);
    00545                 void SetSoundOver(GuiSound * s);
    00548                 void SetSoundClick(GuiSound * s);
    00550                 void Draw();
    00553                 void Update(GuiTrigger * t);
    00554         protected:
    00555                 GuiImage * image;
    00556                 GuiImage * imageOver;
    00557                 GuiImage * icon;
    00558                 GuiImage * iconOver;
    00559                 GuiText * label[3];
    00560                 GuiText * labelOver[3];
    00561                 GuiSound * soundOver;
    00562                 GuiSound * soundClick;
    00563 };
    00564
    00565
    00566 typedef struct _keytype {
    00567         char ch, chShift;
    00568 } Key;
    00569
    00571 class GuiKeyboard : public GuiWindow
    00572 {
    00573         public:
    00574                 GuiKeyboard(char * t, u16 m);
    00575                 ~GuiKeyboard();
    00576                 void Update(GuiTrigger * t);
    00577                 char kbtextstr[100];
    00578         protected:
    00579                 u16 kbtextmaxlen;
    00580                 Key keys[4][10];
    00581                 int shift;
    00582                 int caps;
    00583                 GuiText * kbText;
    00584                 GuiImage * keyTextboxImg;
    00585                 GuiText * keyCapsText;
    00586                 GuiImage * keyCapsImg;
    00587                 GuiImage * keyCapsOverImg;
    00588                 GuiButton * keyCaps;
    00589                 GuiText * keyShiftText;
    00590                 GuiImage * keyShiftImg;
    00591                 GuiImage * keyShiftOverImg;
    00592                 GuiButton * keyShift;
    00593                 GuiText * keyBackText;
    00594                 GuiImage * keyBackImg;
    00595                 GuiImage * keyBackOverImg;
    00596                 GuiButton * keyBack;
    00597                 GuiImage * keySpaceImg;
    00598                 GuiImage * keySpaceOverImg;
    00599                 GuiButton * keySpace;
    00600                 GuiButton * keyBtn[4][10];
    00601                 GuiImage * keyImg[4][10];
    00602                 GuiImage * keyImgOver[4][10];
    00603                 GuiText * keyTxt[4][10];
    00604                 GuiImageData * keyTextbox;
    00605                 GuiImageData * key;
    00606                 GuiImageData * keyOver;
    00607                 GuiImageData * keyMedium;
    00608                 GuiImageData * keyMediumOver;
    00609                 GuiImageData * keyLarge;
    00610                 GuiImageData * keyLargeOver;
    00611                 GuiSound * keySoundOver;
    00612                 GuiTrigger * trigA;
    00613 };
    00614
    00615 typedef struct _optionlist {
    00616         int length;
    00617         char name[MAX_OPTIONS][150];
    00618         char value[MAX_OPTIONS][150];
    00619 } OptionList;
    00620
    00622 class GuiOptionBrowser : public GuiElement
    00623 {
    00624         public:
    00625                 GuiOptionBrowser(int w, int h, OptionList * l);
    00626                 ~GuiOptionBrowser();
    00627                 void SetCol2Position(int x);
    00628                 int FindMenuItem(int c, int d);
    00629                 int GetClickedOption();
    00630                 void ResetState();
    00631                 void SetFocus(int f);
    00632                 void Draw();
    00633                 void Update(GuiTrigger * t);
    00634                 GuiText * optionVal[PAGESIZE];
    00635         protected:
    00636                 int selectedItem;
    00637                 int listOffset;
    00638
    00639                 OptionList * options;
    00640                 int optionIndex[PAGESIZE];
    00641                 GuiButton * optionBtn[PAGESIZE];
    00642                 GuiText * optionTxt[PAGESIZE];
    00643                 GuiImage * optionBg[PAGESIZE];
    00644
    00645                 GuiButton * arrowUpBtn;
    00646                 GuiButton * arrowDownBtn;
    00647                 GuiButton * scrollbarBoxBtn;
    00648
    00649                 GuiImage * bgOptionsImg;
    00650                 GuiImage * scrollbarImg;
    00651                 GuiImage * arrowDownImg;
    00652                 GuiImage * arrowDownOverImg;
    00653                 GuiImage * arrowUpImg;
    00654                 GuiImage * arrowUpOverImg;
    00655                 GuiImage * scrollbarBoxImg;
    00656                 GuiImage * scrollbarBoxOverImg;
    00657
    00658                 GuiImageData * bgOptions;
    00659                 GuiImageData * bgOptionsEntry;
    00660                 GuiImageData * scrollbar;
    00661                 GuiImageData * arrowDown;
    00662                 GuiImageData * arrowDownOver;
    00663                 GuiImageData * arrowUp;
    00664                 GuiImageData * arrowUpOver;
    00665                 GuiImageData * scrollbarBox;
    00666                 GuiImageData * scrollbarBoxOver;
    00667
    00668                 GuiTrigger * trigA;
    00669 };
    00670
    00671 #endif