add new GUI code
41
Makefile.gc
@ -15,12 +15,14 @@ include $(DEVKITPPC)/gamecube_rules
|
||||
# SOURCES is a list of directories containing source code
|
||||
# INCLUDES is a list of directories containing extra header files
|
||||
#---------------------------------------------------------------------------------
|
||||
TARGET := fceugx_gc
|
||||
TARGET := fceugx-gc
|
||||
TARGETDIR := executables
|
||||
BUILD := build_gc
|
||||
SOURCES := source/fceultra source/fceultra/boards source/fceultra/input \
|
||||
SOURCES := source/ngc/images source/ngc/sounds source/ngc/fonts \
|
||||
source/ngc/gui source/ngc \
|
||||
source/fceultra source/fceultra/boards source/fceultra/input \
|
||||
source/fceultra/mappers source/fceultra/mbshare \
|
||||
source/ngc source/sz source/unzip
|
||||
source/sz source/unzip
|
||||
INCLUDES := source/fceultra source/ngc source/unzip
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
@ -31,6 +33,7 @@ CFLAGS = -g -O3 -Wall $(MACHDEP) $(INCLUDE) -DNGC \
|
||||
-D_SZ_ONE_DIRECTORY -D_LZMA_IN_CB -D_LZMA_OUT_READ \
|
||||
-fomit-frame-pointer -fno-exceptions \
|
||||
-Wno-unused-parameter -Wno-strict-aliasing
|
||||
|
||||
CXXFLAGS = $(CFLAGS)
|
||||
|
||||
LDFLAGS = -g $(MACHDEP) -Wl,-Map,$(notdir $@).map -Wl,--cref
|
||||
@ -38,7 +41,7 @@ LDFLAGS = -g $(MACHDEP) -Wl,-Map,$(notdir $@).map -Wl,--cref
|
||||
#---------------------------------------------------------------------------------
|
||||
# any extra libraries we wish to link with the project
|
||||
#---------------------------------------------------------------------------------
|
||||
LIBS := -lmxml -lbba -ltinysmb -lfat -lz -logc -lm -lfreetype
|
||||
LIBS := -lpngu -lpng -lmxml -lmetaphrasis -lfat -lz -logc -lfreetype
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# list of directories containing libraries, this must be the top level containing
|
||||
@ -67,7 +70,9 @@ CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
|
||||
CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
|
||||
sFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
|
||||
SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.S)))
|
||||
BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
|
||||
TTFFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.ttf)))
|
||||
PNGFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.png)))
|
||||
PCMFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.pcm)))
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# use CXX for linking C++ projects, CC for standard C
|
||||
@ -78,9 +83,10 @@ else
|
||||
export LD := $(CXX)
|
||||
endif
|
||||
|
||||
export OFILES := $(addsuffix .o,$(BINFILES)) \
|
||||
$(CPPFILES:.cpp=.o) $(CFILES:.c=.o) \
|
||||
$(sFILES:.s=.o) $(SFILES:.S=.o)
|
||||
export OFILES := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) \
|
||||
$(sFILES:.s=.o) $(SFILES:.S=.o) \
|
||||
$(TTFFILES:.ttf=.ttf.o) $(PNGFILES:.png=.png.o) \
|
||||
$(PCMFILES:.pcm=.pcm.o)
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# build a list of include paths
|
||||
@ -108,15 +114,15 @@ $(BUILD):
|
||||
#---------------------------------------------------------------------------------
|
||||
clean:
|
||||
@echo clean ...
|
||||
@rm -fr $(BUILD) $(OUTPUT).dol source/tags
|
||||
@rm -fr $(BUILD) $(OUTPUT).elf $(OUTPUT).dol
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
run:
|
||||
psoload $(TARGET).dol
|
||||
psoload $(OUTPUT).dol
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
reload:
|
||||
psoload -r $(TARGET).dol
|
||||
psoload -r $(OUTPUT).dol
|
||||
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
@ -131,10 +137,17 @@ $(OUTPUT).dol: $(OUTPUT).elf
|
||||
$(OUTPUT).elf: $(OFILES)
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# This rule links in binary data with the .jpg extension
|
||||
#---------------------------------------------------------------------------------
|
||||
%.jpg.o : %.jpg
|
||||
# This rule links in binary data with .ttf, .png, and .mp3 extensions
|
||||
#---------------------------------------------------------------------------------
|
||||
%.ttf.o : %.ttf
|
||||
@echo $(notdir $<)
|
||||
$(bin2o)
|
||||
|
||||
%.png.o : %.png
|
||||
@echo $(notdir $<)
|
||||
$(bin2o)
|
||||
|
||||
%.pcm.o : %.pcm
|
||||
@echo $(notdir $<)
|
||||
$(bin2o)
|
||||
|
||||
|
48
Makefile.wii
@ -15,12 +15,14 @@ include $(DEVKITPPC)/wii_rules
|
||||
# SOURCES is a list of directories containing source code
|
||||
# INCLUDES is a list of directories containing extra header files
|
||||
#---------------------------------------------------------------------------------
|
||||
TARGET := fceugx_wii
|
||||
TARGET := fceugx-wii
|
||||
TARGETDIR := executables
|
||||
BUILD := build_wii
|
||||
SOURCES := source/fceultra source/fceultra/boards source/fceultra/input \
|
||||
SOURCES := source/ngc/images source/ngc/sounds source/ngc/fonts \
|
||||
source/ngc/gui source/ngc \
|
||||
source/fceultra source/fceultra/boards source/fceultra/input \
|
||||
source/fceultra/mappers source/fceultra/mbshare \
|
||||
source/ngc source/sz source/unzip
|
||||
source/sz source/unzip
|
||||
INCLUDES := source/fceultra source/ngc source/unzip
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
@ -38,7 +40,8 @@ LDFLAGS = -g $(MACHDEP) -Wl,-Map,$(notdir $@).map -Wl,--cref
|
||||
#---------------------------------------------------------------------------------
|
||||
# any extra libraries we wish to link with the project
|
||||
#---------------------------------------------------------------------------------
|
||||
LIBS := -ldi -lmxml -lfat -lwiiuse -lz -lbte -logc -lm -lfreetype -ltinysmb
|
||||
LIBS := -ldb -ldi -lpngu -lpng -lmxml -lmetaphrasis \
|
||||
-lfat -lwiiuse -lz -lbte -logc -lasnd -ltremor -lfreetype -ltinysmb
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# list of directories containing libraries, this must be the top level containing
|
||||
@ -67,8 +70,11 @@ CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
|
||||
CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
|
||||
sFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
|
||||
SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.S)))
|
||||
BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
|
||||
|
||||
TTFFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.ttf)))
|
||||
PNGFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.png)))
|
||||
OGGFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.ogg)))
|
||||
PCMFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.pcm)))
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# use CXX for linking C++ projects, CC for standard C
|
||||
#---------------------------------------------------------------------------------
|
||||
@ -78,9 +84,10 @@ else
|
||||
export LD := $(CXX)
|
||||
endif
|
||||
|
||||
export OFILES := $(addsuffix .o,$(BINFILES)) \
|
||||
$(CPPFILES:.cpp=.o) $(CFILES:.c=.o) \
|
||||
$(sFILES:.s=.o) $(SFILES:.S=.o)
|
||||
export OFILES := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) \
|
||||
$(sFILES:.s=.o) $(SFILES:.S=.o) \
|
||||
$(TTFFILES:.ttf=.ttf.o) $(PNGFILES:.png=.png.o) \
|
||||
$(OGGFILES:.ogg=.ogg.o) $(PCMFILES:.pcm=.pcm.o)
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# build a list of include paths
|
||||
@ -108,15 +115,15 @@ $(BUILD):
|
||||
#---------------------------------------------------------------------------------
|
||||
clean:
|
||||
@echo clean ...
|
||||
@rm -fr $(BUILD) $(OUTPUT).dol source/tags
|
||||
@rm -fr $(BUILD) $(OUTPUT).elf $(OUTPUT).dol
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
run:
|
||||
wiiload $(TARGET).dol
|
||||
wiiload $(OUTPUT).dol
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
reload:
|
||||
wiiload -r $(TARGET).dol
|
||||
wiiload -r $(OUTPUT).dol
|
||||
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
@ -131,10 +138,21 @@ $(OUTPUT).dol: $(OUTPUT).elf
|
||||
$(OUTPUT).elf: $(OFILES)
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# This rule links in binary data with the .jpg extension
|
||||
#---------------------------------------------------------------------------------
|
||||
%.jpg.o : %.jpg
|
||||
# This rule links in binary data with .ttf, .png, and .mp3 extensions
|
||||
#---------------------------------------------------------------------------------
|
||||
%.ttf.o : %.ttf
|
||||
@echo $(notdir $<)
|
||||
$(bin2o)
|
||||
|
||||
%.png.o : %.png
|
||||
@echo $(notdir $<)
|
||||
$(bin2o)
|
||||
|
||||
%.ogg.o : %.ogg
|
||||
@echo $(notdir $<)
|
||||
$(bin2o)
|
||||
|
||||
%.pcm.o : %.pcm
|
||||
@echo $(notdir $<)
|
||||
$(bin2o)
|
||||
|
||||
|
BIN
source/ngc/fonts/font.ttf
Normal file
517
source/ngc/gui/gui.h
Normal file
@ -0,0 +1,517 @@
|
||||
/****************************************************************************
|
||||
* Snes9x 1.51 Nintendo Wii/Gamecube Port
|
||||
*
|
||||
* Tantric February 2009
|
||||
*
|
||||
* gui.h
|
||||
*
|
||||
* GUI class definitions
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef GUI_H
|
||||
#define GUI_H
|
||||
|
||||
#include <gccore.h>
|
||||
#include <malloc.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <vector>
|
||||
#include <math.h>
|
||||
#include <asndlib.h>
|
||||
#include "pngu/pngu.h"
|
||||
#include "FreeTypeGX.h"
|
||||
#include "snes9xGX.h"
|
||||
#include "video.h"
|
||||
#include "input.h"
|
||||
#include "filelist.h"
|
||||
#include "fileop.h"
|
||||
#include "menu.h"
|
||||
#include "oggplayer.h"
|
||||
|
||||
#define SCROLL_INITIAL_DELAY 20
|
||||
#define SCROLL_LOOP_DELAY 3
|
||||
#define PAGESIZE 8
|
||||
#define SAVELISTSIZE 6
|
||||
#define MAX_SAVES 20
|
||||
#define MAX_OPTIONS 30
|
||||
|
||||
typedef void (*UpdateCallback)(void * e);
|
||||
|
||||
enum
|
||||
{
|
||||
ALIGN_LEFT,
|
||||
ALIGN_RIGHT,
|
||||
ALIGN_CENTRE,
|
||||
ALIGN_TOP,
|
||||
ALIGN_BOTTOM,
|
||||
ALIGN_MIDDLE
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
STATE_DEFAULT,
|
||||
STATE_SELECTED,
|
||||
STATE_CLICKED,
|
||||
STATE_DISABLED
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
SOUND_PCM,
|
||||
SOUND_OGG
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
IMAGE_TEXTURE,
|
||||
IMAGE_COLOR,
|
||||
IMAGE_DATA
|
||||
};
|
||||
|
||||
#define EFFECT_SLIDE_TOP 1
|
||||
#define EFFECT_SLIDE_BOTTOM 2
|
||||
#define EFFECT_SLIDE_RIGHT 4
|
||||
#define EFFECT_SLIDE_LEFT 8
|
||||
#define EFFECT_SLIDE_IN 16
|
||||
#define EFFECT_SLIDE_OUT 32
|
||||
#define EFFECT_FADE 64
|
||||
#define EFFECT_SCALE 128
|
||||
#define EFFECT_COLOR_TRANSITION 256
|
||||
|
||||
class GuiSound
|
||||
{
|
||||
public:
|
||||
GuiSound(const u8 * s, int l, int t);
|
||||
~GuiSound();
|
||||
void Play();
|
||||
void Stop();
|
||||
void Pause();
|
||||
void Resume();
|
||||
void SetVolume(int v);
|
||||
protected:
|
||||
const u8 * sound;
|
||||
int type;
|
||||
s32 length;
|
||||
s32 voice;
|
||||
s32 volume;
|
||||
};
|
||||
|
||||
class GuiElement
|
||||
{
|
||||
public:
|
||||
GuiElement();
|
||||
~GuiElement();
|
||||
void SetParent(GuiElement * e);
|
||||
int GetLeft();
|
||||
int GetTop();
|
||||
int GetWidth();
|
||||
int GetHeight();
|
||||
void SetSize(int w, int h);
|
||||
bool IsVisible();
|
||||
bool IsSelectable();
|
||||
bool IsClickable();
|
||||
void SetSelectable(bool s);
|
||||
void SetClickable(bool c);
|
||||
int GetState();
|
||||
void SetAlpha(int a);
|
||||
int GetAlpha();
|
||||
void SetScale(float s);
|
||||
float GetScale();
|
||||
void SetTrigger(GuiTrigger * t);
|
||||
void SetTrigger(u8 i, GuiTrigger * t);
|
||||
bool Rumble();
|
||||
void SetRumble(bool r);
|
||||
void SetEffect(int e, int a, int t=0);
|
||||
void SetEffectOnOver(int e, int a, int t=0);
|
||||
void SetEffectGrow();
|
||||
int GetEffect();
|
||||
bool IsInside(int x, int y);
|
||||
void SetPosition(int x, int y);
|
||||
void UpdateEffects();
|
||||
void SetUpdateCallback(UpdateCallback u);
|
||||
int IsFocused();
|
||||
virtual void SetVisible(bool v);
|
||||
virtual void SetFocus(int f);
|
||||
virtual void SetState(int s);
|
||||
virtual void ResetState();
|
||||
virtual int GetSelected();
|
||||
virtual void SetAlignment(int hor, int vert);
|
||||
virtual void Update(GuiTrigger * t);
|
||||
virtual void Draw();
|
||||
protected:
|
||||
bool visible;
|
||||
int focus; // -1 = cannot focus, 0 = not focused, 1 = focused
|
||||
int width;
|
||||
int height;
|
||||
int xoffset;
|
||||
int yoffset;
|
||||
int xoffsetDyn;
|
||||
int yoffsetDyn;
|
||||
int alpha;
|
||||
f32 scale;
|
||||
int alphaDyn;
|
||||
f32 scaleDyn;
|
||||
bool rumble;
|
||||
int effects;
|
||||
int effectAmount;
|
||||
int effectTarget;
|
||||
int effectsOver;
|
||||
int effectAmountOver;
|
||||
int effectTargetOver;
|
||||
int alignmentHor; // LEFT, RIGHT, CENTRE
|
||||
int alignmentVert; // TOP, BOTTOM, MIDDLE
|
||||
int state; // DEFAULT, SELECTED, CLICKED, DISABLED
|
||||
bool selectable; // is SELECTED a valid state?
|
||||
bool clickable; // is CLICKED a valid state?
|
||||
GuiTrigger * trigger[2];
|
||||
GuiElement * parentElement;
|
||||
UpdateCallback updateCB;
|
||||
};
|
||||
|
||||
//!Groups elements into one window in which they can be managed.
|
||||
class GuiWindow : public GuiElement
|
||||
{
|
||||
public:
|
||||
//!Constructor
|
||||
GuiWindow();
|
||||
GuiWindow(int w, int h);
|
||||
//!Destructor.
|
||||
~GuiWindow();
|
||||
|
||||
//!Appends a element at the end, thus drawing it at last.
|
||||
//!\param element The element to append. If it is already in the list, it gets removed first.
|
||||
void Append(GuiElement* e);
|
||||
//!Inserts a element into the manager.
|
||||
//!\param element The element to insert. If it is already in the list, it gets removed first.
|
||||
//!\param index The new index of the element.
|
||||
void Insert(GuiElement* e, u32 index);
|
||||
//!Removes a element from the list.
|
||||
//!\param element A element that is in the list.
|
||||
void Remove(GuiElement* e);
|
||||
//!Clears the whole GuiWindow from all GuiElement.
|
||||
void RemoveAll();
|
||||
|
||||
//!Returns a element at a specified index.
|
||||
//!\param index The index from where to poll the element.
|
||||
//!\return A pointer to the element at the index. NULL if index is out of bounds.
|
||||
GuiElement* GetGuiElementAt(u32 index) const;
|
||||
//!Returns the size of the list of elements.
|
||||
//!\return The size of the current elementlist.
|
||||
u32 GetSize();
|
||||
void SetVisible(bool v);
|
||||
void ResetState();
|
||||
void SetState(int s);
|
||||
int GetSelected();
|
||||
void SetFocus(int f);
|
||||
void ChangeFocus(GuiElement * e);
|
||||
void ToggleFocus(GuiTrigger * t);
|
||||
void MoveSelectionHor(int d);
|
||||
void MoveSelectionVert(int d);
|
||||
|
||||
//!Draws all the elements in this GuiWindow.
|
||||
void Draw();
|
||||
void Update(GuiTrigger * t);
|
||||
|
||||
protected:
|
||||
std::vector<GuiElement*> _elements;
|
||||
};
|
||||
|
||||
class GuiImageData
|
||||
{
|
||||
public:
|
||||
GuiImageData(const u8 * i);
|
||||
~GuiImageData();
|
||||
u8 * GetImage();
|
||||
int GetWidth();
|
||||
int GetHeight();
|
||||
protected:
|
||||
u8 * data;
|
||||
int height;
|
||||
int width;
|
||||
};
|
||||
|
||||
class GuiImage : public GuiElement
|
||||
{
|
||||
public:
|
||||
GuiImage(GuiImageData * img);
|
||||
GuiImage(u8 * img, int w, int h);
|
||||
GuiImage(int w, int h, GXColor c);
|
||||
~GuiImage();
|
||||
void SetAngle(float a);
|
||||
void SetTile(int t);
|
||||
void Draw();
|
||||
u8 * GetImage();
|
||||
void SetImage(GuiImageData * img);
|
||||
void SetImage(u8 * img, int w, int h);
|
||||
GXColor GetPixel(int x, int y);
|
||||
void SetPixel(int x, int y, GXColor color);
|
||||
void ColorStripe(int s);
|
||||
void SetStripe(int s);
|
||||
protected:
|
||||
int imgType;
|
||||
u8 * image;
|
||||
f32 imageangle;
|
||||
int tile;
|
||||
int stripe;
|
||||
};
|
||||
|
||||
class GuiText : public GuiElement
|
||||
{
|
||||
public:
|
||||
GuiText(const char * t, int s, GXColor c);
|
||||
GuiText(const char * t);
|
||||
~GuiText();
|
||||
void SetText(const char * t);
|
||||
void SetPresets(int sz, GXColor c, int w, u16 s, int h, int v);
|
||||
void SetFontSize(int s);
|
||||
void SetMaxWidth(int w);
|
||||
void SetColor(GXColor c);
|
||||
void SetStyle(u16 s);
|
||||
void SetAlignment(int hor, int vert);
|
||||
void Draw();
|
||||
protected:
|
||||
wchar_t* text;
|
||||
int size;
|
||||
int maxWidth;
|
||||
u16 style;
|
||||
GXColor color;
|
||||
};
|
||||
|
||||
class GuiButton : public GuiElement
|
||||
{
|
||||
public:
|
||||
GuiButton(int w, int h);
|
||||
~GuiButton();
|
||||
void SetImage(GuiImage* i);
|
||||
void SetImageOver(GuiImage* i);
|
||||
void SetIcon(GuiImage* i);
|
||||
void SetIconOver(GuiImage* i);
|
||||
void SetLabel(GuiText* t);
|
||||
void SetLabelOver(GuiText* t);
|
||||
void SetLabel(GuiText* t, int n);
|
||||
void SetLabelOver(GuiText* t, int n);
|
||||
void SetSoundOver(GuiSound * s);
|
||||
void SetSoundClick(GuiSound * s);
|
||||
void Draw();
|
||||
void Update(GuiTrigger * t);
|
||||
protected:
|
||||
GuiImage * image;
|
||||
GuiImage * imageOver;
|
||||
GuiImage * icon;
|
||||
GuiImage * iconOver;
|
||||
GuiText * label[3];
|
||||
GuiText * labelOver[3];
|
||||
GuiSound * soundOver;
|
||||
GuiSound * soundClick;
|
||||
};
|
||||
|
||||
class GuiFileBrowser : public GuiElement
|
||||
{
|
||||
public:
|
||||
GuiFileBrowser(int w, int h);
|
||||
~GuiFileBrowser();
|
||||
void ResetState();
|
||||
void SetFocus(int f);
|
||||
void Draw();
|
||||
void TriggerUpdate();
|
||||
void Update(GuiTrigger * t);
|
||||
GuiButton * gameList[PAGESIZE];
|
||||
protected:
|
||||
int selectedItem;
|
||||
bool listChanged;
|
||||
|
||||
GuiText * gameListText[PAGESIZE];
|
||||
GuiImage * gameListBg[PAGESIZE];
|
||||
GuiImage * gameListFolder[PAGESIZE];
|
||||
|
||||
GuiButton * arrowUpBtn;
|
||||
GuiButton * arrowDownBtn;
|
||||
GuiButton * scrollbarBoxBtn;
|
||||
|
||||
GuiImage * bgGameSelectionImg;
|
||||
GuiImage * scrollbarImg;
|
||||
GuiImage * arrowDownImg;
|
||||
GuiImage * arrowDownOverImg;
|
||||
GuiImage * arrowUpImg;
|
||||
GuiImage * arrowUpOverImg;
|
||||
GuiImage * scrollbarBoxImg;
|
||||
GuiImage * scrollbarBoxOverImg;
|
||||
|
||||
GuiImageData * bgGameSelection;
|
||||
GuiImageData * bgGameSelectionEntry;
|
||||
GuiImageData * gameFolder;
|
||||
GuiImageData * scrollbar;
|
||||
GuiImageData * arrowDown;
|
||||
GuiImageData * arrowDownOver;
|
||||
GuiImageData * arrowUp;
|
||||
GuiImageData * arrowUpOver;
|
||||
GuiImageData * scrollbarBox;
|
||||
GuiImageData * scrollbarBoxOver;
|
||||
|
||||
GuiTrigger * trigA;
|
||||
};
|
||||
|
||||
typedef struct _optionlist {
|
||||
int length;
|
||||
char name[MAX_OPTIONS][150];
|
||||
char value[MAX_OPTIONS][150];
|
||||
} OptionList;
|
||||
|
||||
class GuiOptionBrowser : public GuiElement
|
||||
{
|
||||
public:
|
||||
GuiOptionBrowser(int w, int h, OptionList * l);
|
||||
~GuiOptionBrowser();
|
||||
void SetCol2Position(int x);
|
||||
int FindMenuItem(int c, int d);
|
||||
int GetClickedOption();
|
||||
void ResetState();
|
||||
void SetFocus(int f);
|
||||
void Draw();
|
||||
void Update(GuiTrigger * t);
|
||||
GuiText * optionVal[PAGESIZE];
|
||||
protected:
|
||||
int selectedItem;
|
||||
int listOffset;
|
||||
|
||||
OptionList * options;
|
||||
int optionIndex[PAGESIZE];
|
||||
GuiButton * optionBtn[PAGESIZE];
|
||||
GuiText * optionTxt[PAGESIZE];
|
||||
GuiImage * optionBg[PAGESIZE];
|
||||
|
||||
GuiButton * arrowUpBtn;
|
||||
GuiButton * arrowDownBtn;
|
||||
GuiButton * scrollbarBoxBtn;
|
||||
|
||||
GuiImage * bgOptionsImg;
|
||||
GuiImage * scrollbarImg;
|
||||
GuiImage * arrowDownImg;
|
||||
GuiImage * arrowDownOverImg;
|
||||
GuiImage * arrowUpImg;
|
||||
GuiImage * arrowUpOverImg;
|
||||
GuiImage * scrollbarBoxImg;
|
||||
GuiImage * scrollbarBoxOverImg;
|
||||
|
||||
GuiImageData * bgOptions;
|
||||
GuiImageData * bgOptionsEntry;
|
||||
GuiImageData * scrollbar;
|
||||
GuiImageData * arrowDown;
|
||||
GuiImageData * arrowDownOver;
|
||||
GuiImageData * arrowUp;
|
||||
GuiImageData * arrowUpOver;
|
||||
GuiImageData * scrollbarBox;
|
||||
GuiImageData * scrollbarBoxOver;
|
||||
|
||||
GuiTrigger * trigA;
|
||||
};
|
||||
|
||||
typedef struct _savelist {
|
||||
int length;
|
||||
char filename[MAX_SAVES][256];
|
||||
GuiImageData * previewImg[MAX_SAVES];
|
||||
char date[MAX_SAVES][20];
|
||||
char time[MAX_SAVES][10];
|
||||
int type[MAX_SAVES];
|
||||
int files[2][100];
|
||||
} SaveList;
|
||||
|
||||
class GuiSaveBrowser : public GuiElement
|
||||
{
|
||||
public:
|
||||
GuiSaveBrowser(int w, int h, SaveList * l, int a);
|
||||
~GuiSaveBrowser();
|
||||
int GetClickedSave();
|
||||
void ResetState();
|
||||
void SetFocus(int f);
|
||||
void Draw();
|
||||
void Update(GuiTrigger * t);
|
||||
protected:
|
||||
int selectedItem;
|
||||
int listOffset;
|
||||
int action;
|
||||
|
||||
SaveList * saves;
|
||||
GuiButton * saveBtn[SAVELISTSIZE];
|
||||
GuiText * saveDate[SAVELISTSIZE];
|
||||
GuiText * saveTime[SAVELISTSIZE];
|
||||
GuiText * saveType[SAVELISTSIZE];
|
||||
|
||||
GuiImage * saveBgImg[SAVELISTSIZE];
|
||||
GuiImage * saveBgOverImg[SAVELISTSIZE];
|
||||
GuiImage * savePreviewImg[SAVELISTSIZE];
|
||||
|
||||
GuiButton * arrowUpBtn;
|
||||
GuiButton * arrowDownBtn;
|
||||
GuiButton * scrollbarBoxBtn;
|
||||
|
||||
GuiImage * scrollbarImg;
|
||||
GuiImage * arrowDownImg;
|
||||
GuiImage * arrowDownOverImg;
|
||||
GuiImage * arrowUpImg;
|
||||
GuiImage * arrowUpOverImg;
|
||||
GuiImage * scrollbarBoxImg;
|
||||
GuiImage * scrollbarBoxOverImg;
|
||||
|
||||
GuiImageData * gameSave;
|
||||
GuiImageData * gameSaveOver;
|
||||
GuiImageData * gameSaveBlank;
|
||||
GuiImageData * scrollbar;
|
||||
GuiImageData * arrowDown;
|
||||
GuiImageData * arrowDownOver;
|
||||
GuiImageData * arrowUp;
|
||||
GuiImageData * arrowUpOver;
|
||||
GuiImageData * scrollbarBox;
|
||||
GuiImageData * scrollbarBoxOver;
|
||||
|
||||
GuiTrigger * trigA;
|
||||
};
|
||||
|
||||
typedef struct _keytype {
|
||||
char ch, chShift;
|
||||
} Key;
|
||||
|
||||
class GuiKeyboard : public GuiWindow
|
||||
{
|
||||
public:
|
||||
GuiKeyboard(char * t);
|
||||
~GuiKeyboard();
|
||||
void Update(GuiTrigger * t);
|
||||
char kbtextstr[100];
|
||||
protected:
|
||||
Key keys[4][10];
|
||||
int shift;
|
||||
int caps;
|
||||
GuiText * kbText;
|
||||
GuiImage * keyTextboxImg;
|
||||
GuiText * keyCapsText;
|
||||
GuiImage * keyCapsImg;
|
||||
GuiImage * keyCapsOverImg;
|
||||
GuiButton * keyCaps;
|
||||
GuiText * keyShiftText;
|
||||
GuiImage * keyShiftImg;
|
||||
GuiImage * keyShiftOverImg;
|
||||
GuiButton * keyShift;
|
||||
GuiText * keyBackText;
|
||||
GuiImage * keyBackImg;
|
||||
GuiImage * keyBackOverImg;
|
||||
GuiButton * keyBack;
|
||||
GuiImage * keySpaceImg;
|
||||
GuiImage * keySpaceOverImg;
|
||||
GuiButton * keySpace;
|
||||
GuiButton * keyBtn[4][10];
|
||||
GuiImage * keyImg[4][10];
|
||||
GuiImage * keyImgOver[4][10];
|
||||
GuiText * keyTxt[4][10];
|
||||
GuiImageData * keyTextbox;
|
||||
GuiImageData * key;
|
||||
GuiImageData * keyOver;
|
||||
GuiImageData * keyMedium;
|
||||
GuiImageData * keyMediumOver;
|
||||
GuiImageData * keyLarge;
|
||||
GuiImageData * keyLargeOver;
|
||||
GuiSound * keySoundOver;
|
||||
GuiTrigger * trigA;
|
||||
};
|
||||
|
||||
#endif
|
231
source/ngc/gui/gui_button.cpp
Normal file
@ -0,0 +1,231 @@
|
||||
/****************************************************************************
|
||||
* Snes9x 1.51 Nintendo Wii/Gamecube Port
|
||||
*
|
||||
* Tantric February 2009
|
||||
*
|
||||
* gui_button.cpp
|
||||
*
|
||||
* GUI class definitions
|
||||
***************************************************************************/
|
||||
|
||||
#include "gui.h"
|
||||
/**
|
||||
* Constructor for the GuiButton class.
|
||||
*/
|
||||
|
||||
GuiButton::GuiButton(int w, int h)
|
||||
{
|
||||
width = w;
|
||||
height = h;
|
||||
image = NULL;
|
||||
imageOver = NULL;
|
||||
icon = NULL;
|
||||
iconOver = NULL;
|
||||
|
||||
for(int i=0; i < 3; i++)
|
||||
{
|
||||
label[i] = NULL;
|
||||
labelOver[i] = NULL;
|
||||
}
|
||||
|
||||
soundOver = NULL;
|
||||
soundClick = NULL;
|
||||
selectable = true;
|
||||
clickable = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Destructor for the GuiButton class.
|
||||
*/
|
||||
GuiButton::~GuiButton()
|
||||
{
|
||||
}
|
||||
|
||||
void GuiButton::SetImage(GuiImage* img)
|
||||
{
|
||||
image = img;
|
||||
|
||||
if(img)
|
||||
img->SetParent(this);
|
||||
}
|
||||
void GuiButton::SetImageOver(GuiImage* img)
|
||||
{
|
||||
imageOver = img;
|
||||
|
||||
if(img)
|
||||
img->SetParent(this);
|
||||
}
|
||||
void GuiButton::SetIcon(GuiImage* img)
|
||||
{
|
||||
icon = img;
|
||||
|
||||
if(img)
|
||||
img->SetParent(this);
|
||||
}
|
||||
void GuiButton::SetIconOver(GuiImage* img)
|
||||
{
|
||||
iconOver = img;
|
||||
|
||||
if(img)
|
||||
img->SetParent(this);
|
||||
}
|
||||
void GuiButton::SetLabel(GuiText* txt)
|
||||
{
|
||||
label[0] = txt;
|
||||
|
||||
if(txt)
|
||||
txt->SetParent(this);
|
||||
}
|
||||
void GuiButton::SetLabelOver(GuiText* txt)
|
||||
{
|
||||
labelOver[0] = txt;
|
||||
|
||||
if(txt)
|
||||
txt->SetParent(this);
|
||||
}
|
||||
void GuiButton::SetLabel(GuiText* txt, int n)
|
||||
{
|
||||
label[n] = txt;
|
||||
|
||||
if(txt)
|
||||
txt->SetParent(this);
|
||||
}
|
||||
void GuiButton::SetLabelOver(GuiText* txt, int n)
|
||||
{
|
||||
labelOver[n] = txt;
|
||||
|
||||
if(txt)
|
||||
txt->SetParent(this);
|
||||
}
|
||||
void GuiButton::SetSoundOver(GuiSound * snd)
|
||||
{
|
||||
soundOver = snd;
|
||||
}
|
||||
void GuiButton::SetSoundClick(GuiSound * snd)
|
||||
{
|
||||
soundClick = snd;
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw the button on screen
|
||||
*/
|
||||
void GuiButton::Draw()
|
||||
{
|
||||
if(!this->IsVisible())
|
||||
return;
|
||||
|
||||
// draw image
|
||||
if(state == STATE_SELECTED && imageOver)
|
||||
imageOver->Draw();
|
||||
else if(image)
|
||||
image->Draw();
|
||||
// draw icon
|
||||
if(state == STATE_SELECTED && iconOver)
|
||||
iconOver->Draw();
|
||||
else if(icon)
|
||||
icon->Draw();
|
||||
// draw text
|
||||
for(int i=0; i<3; i++)
|
||||
{
|
||||
if(state == STATE_SELECTED && labelOver[i])
|
||||
labelOver[i]->Draw();
|
||||
else if(label[i])
|
||||
label[i]->Draw();
|
||||
}
|
||||
|
||||
this->UpdateEffects();
|
||||
}
|
||||
|
||||
void GuiButton::Update(GuiTrigger * t)
|
||||
{
|
||||
if(state == STATE_CLICKED || state == STATE_DISABLED || !t)
|
||||
return;
|
||||
else if(parentElement && parentElement->GetState() == STATE_DISABLED)
|
||||
return;
|
||||
|
||||
#ifdef HW_RVL
|
||||
// cursor
|
||||
if(t->wpad.ir.valid)
|
||||
{
|
||||
if(this->IsInside(t->wpad.ir.x, t->wpad.ir.y))
|
||||
{
|
||||
if(state == STATE_DEFAULT) // we weren't on the button before!
|
||||
{
|
||||
state = STATE_SELECTED;
|
||||
|
||||
if(this->Rumble())
|
||||
rumbleRequest[t->chan] = 1;
|
||||
|
||||
if(soundOver)
|
||||
soundOver->Play();
|
||||
|
||||
if(effectsOver && !effects)
|
||||
{
|
||||
// initiate effects
|
||||
effects = effectsOver;
|
||||
effectAmount = effectAmountOver;
|
||||
effectTarget = effectTargetOver;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(state == STATE_SELECTED)
|
||||
state = STATE_DEFAULT;
|
||||
|
||||
if(effectTarget == effectTargetOver && effectAmount == effectAmountOver)
|
||||
{
|
||||
// initiate effects (in reverse)
|
||||
effects = effectsOver;
|
||||
effectAmount = -effectAmountOver;
|
||||
effectTarget = 100;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
// button triggers
|
||||
if(this->IsClickable())
|
||||
{
|
||||
for(int i=0; i<2; i++)
|
||||
{
|
||||
if(trigger[i] && (trigger[i]->chan == -1 || trigger[i]->chan == t->chan))
|
||||
{
|
||||
// higher 16 bits only (wiimote)
|
||||
s32 wm_btns = t->wpad.btns_d << 16;
|
||||
s32 wm_btns_trig = trigger[i]->wpad.btns_d << 16;
|
||||
|
||||
// lower 16 bits only (classic controller)
|
||||
s32 cc_btns = t->wpad.btns_d >> 16;
|
||||
s32 cc_btns_trig = trigger[i]->wpad.btns_d >> 16;
|
||||
|
||||
if(
|
||||
(t->wpad.btns_d > 0 &&
|
||||
wm_btns == wm_btns_trig ||
|
||||
(cc_btns == cc_btns_trig && t->wpad.exp.type == EXP_CLASSIC)) ||
|
||||
(t->pad.btns_d == trigger[i]->pad.btns_d && t->pad.btns_d > 0))
|
||||
{
|
||||
if(state == STATE_SELECTED)
|
||||
{
|
||||
state = STATE_CLICKED;
|
||||
|
||||
if(soundClick)
|
||||
soundClick->Play();
|
||||
}
|
||||
else if(trigger[i]->type == TRIGGER_BUTTON_ONLY)
|
||||
{
|
||||
state = STATE_CLICKED;
|
||||
}
|
||||
else if(trigger[i]->type == TRIGGER_BUTTON_ONLY_IN_FOCUS &&
|
||||
parentElement->IsFocused())
|
||||
{
|
||||
state = STATE_CLICKED;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(updateCB)
|
||||
updateCB(this);
|
||||
}
|
495
source/ngc/gui/gui_element.cpp
Normal file
@ -0,0 +1,495 @@
|
||||
/****************************************************************************
|
||||
* Snes9x 1.51 Nintendo Wii/Gamecube Port
|
||||
*
|
||||
* Tantric February 2009
|
||||
*
|
||||
* gui_element.cpp
|
||||
*
|
||||
* GUI class definitions
|
||||
***************************************************************************/
|
||||
|
||||
#include "gui.h"
|
||||
|
||||
/**
|
||||
* Constructor for the Object class.
|
||||
*/
|
||||
GuiElement::GuiElement()
|
||||
{
|
||||
xoffset = 0;
|
||||
yoffset = 0;
|
||||
width = 0;
|
||||
height = 0;
|
||||
alpha = 255;
|
||||
scale = 1;
|
||||
state = STATE_DEFAULT;
|
||||
trigger[0] = NULL;
|
||||
trigger[1] = NULL;
|
||||
parentElement = NULL;
|
||||
rumble = true;
|
||||
selectable = false;
|
||||
clickable = false;
|
||||
visible = true;
|
||||
focus = -1; // cannot be focused
|
||||
updateCB = NULL;
|
||||
yoffsetDyn = 0;
|
||||
xoffsetDyn = 0;
|
||||
alphaDyn = -1;
|
||||
scaleDyn = 1;
|
||||
effects = 0;
|
||||
effectAmount = 0;
|
||||
effectTarget = 0;
|
||||
effectsOver = 0;
|
||||
effectAmountOver = 0;
|
||||
effectTargetOver = 0;
|
||||
|
||||
// default alignment - align to top left
|
||||
alignmentVert = ALIGN_TOP;
|
||||
alignmentHor = ALIGN_LEFT;
|
||||
}
|
||||
|
||||
/**
|
||||
* Destructor for the GuiElement class.
|
||||
*/
|
||||
GuiElement::~GuiElement()
|
||||
{
|
||||
}
|
||||
|
||||
void GuiElement::SetParent(GuiElement * e)
|
||||
{
|
||||
parentElement = e;
|
||||
}
|
||||
/**
|
||||
* Get the left position of the GuiElement.
|
||||
* @see SetLeft()
|
||||
* @return Left position in pixel.
|
||||
*/
|
||||
int GuiElement::GetLeft()
|
||||
{
|
||||
int x = 0;
|
||||
int pWidth = 0;
|
||||
int pLeft = 0;
|
||||
|
||||
if(parentElement)
|
||||
{
|
||||
pWidth = parentElement->GetWidth();
|
||||
pLeft = parentElement->GetLeft();
|
||||
}
|
||||
|
||||
if(effects & (EFFECT_SLIDE_IN | EFFECT_SLIDE_OUT))
|
||||
pLeft += xoffsetDyn;
|
||||
|
||||
switch(alignmentHor)
|
||||
{
|
||||
case ALIGN_LEFT:
|
||||
x = pLeft;
|
||||
break;
|
||||
case ALIGN_CENTRE:
|
||||
x = pLeft + (pWidth/2) - (width/2);
|
||||
break;
|
||||
case ALIGN_RIGHT:
|
||||
x = pLeft + pWidth - width;
|
||||
break;
|
||||
}
|
||||
return x + xoffset;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the top position of the GuiElement.
|
||||
* @see SetTop()
|
||||
* @return Top position in pixel.
|
||||
*/
|
||||
int GuiElement::GetTop()
|
||||
{
|
||||
int y = 0;
|
||||
int pHeight = 0;
|
||||
int pTop = 0;
|
||||
|
||||
if(parentElement)
|
||||
{
|
||||
pHeight = parentElement->GetHeight();
|
||||
pTop = parentElement->GetTop();
|
||||
}
|
||||
|
||||
if(effects & (EFFECT_SLIDE_IN | EFFECT_SLIDE_OUT))
|
||||
pTop += yoffsetDyn;
|
||||
|
||||
switch(alignmentVert)
|
||||
{
|
||||
case ALIGN_TOP:
|
||||
y = pTop;
|
||||
break;
|
||||
case ALIGN_MIDDLE:
|
||||
y = pTop + (pHeight/2) - (height/2);
|
||||
break;
|
||||
case ALIGN_BOTTOM:
|
||||
y = pTop + pHeight - height;
|
||||
break;
|
||||
}
|
||||
return y + yoffset;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the width of the GuiElement.
|
||||
* @see SetWidth()
|
||||
* @return Width of the GuiElement.
|
||||
*/
|
||||
int GuiElement::GetWidth()
|
||||
{
|
||||
return width;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the height of the GuiElement.
|
||||
* @see SetHeight()
|
||||
* @return Height of the GuiElement.
|
||||
*/
|
||||
int GuiElement::GetHeight()
|
||||
{
|
||||
return height;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the width and height of the GuiElement.
|
||||
* @param[in] Width Width in pixel.
|
||||
* @param[in] Height Height in pixel.
|
||||
* @see SetWidth()
|
||||
* @see SetHeight()
|
||||
*/
|
||||
void GuiElement::SetSize(int w, int h)
|
||||
{
|
||||
|
||||
width = w;
|
||||
height = h;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get visible.
|
||||
* @see SetVisible()
|
||||
* @return true if visible, false otherwise.
|
||||
*/
|
||||
bool GuiElement::IsVisible()
|
||||
{
|
||||
return visible;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set visible.
|
||||
* @param[in] Visible Set to true to show GuiElement.
|
||||
* @see IsVisible()
|
||||
*/
|
||||
void GuiElement::SetVisible(bool v)
|
||||
{
|
||||
visible = v;
|
||||
}
|
||||
|
||||
void GuiElement::SetAlpha(int a)
|
||||
{
|
||||
alpha = a;
|
||||
}
|
||||
|
||||
int GuiElement::GetAlpha()
|
||||
{
|
||||
int a;
|
||||
|
||||
if(alphaDyn >= 0)
|
||||
a = alphaDyn;
|
||||
else
|
||||
a = alpha;
|
||||
|
||||
if(parentElement)
|
||||
a *= parentElement->GetAlpha()/255.0;
|
||||
|
||||
return a;
|
||||
}
|
||||
|
||||
void GuiElement::SetScale(float s)
|
||||
{
|
||||
scale = s;
|
||||
}
|
||||
|
||||
float GuiElement::GetScale()
|
||||
{
|
||||
float s = scale * scaleDyn;
|
||||
|
||||
if(parentElement)
|
||||
s *= parentElement->GetScale();
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
int GuiElement::GetState()
|
||||
{
|
||||
return state;
|
||||
}
|
||||
|
||||
void GuiElement::SetState(int s)
|
||||
{
|
||||
state = s;
|
||||
}
|
||||
|
||||
void GuiElement::ResetState()
|
||||
{
|
||||
if(state != STATE_DISABLED)
|
||||
state = STATE_DEFAULT;
|
||||
}
|
||||
|
||||
void GuiElement::SetClickable(bool c)
|
||||
{
|
||||
clickable = c;
|
||||
}
|
||||
|
||||
void GuiElement::SetSelectable(bool s)
|
||||
{
|
||||
selectable = s;
|
||||
}
|
||||
|
||||
bool GuiElement::IsSelectable()
|
||||
{
|
||||
if(state == STATE_DISABLED || state == STATE_CLICKED)
|
||||
return false;
|
||||
else
|
||||
return selectable;
|
||||
}
|
||||
|
||||
bool GuiElement::IsClickable()
|
||||
{
|
||||
if(state == STATE_DISABLED || state == STATE_CLICKED)
|
||||
return false;
|
||||
else
|
||||
return clickable;
|
||||
}
|
||||
|
||||
void GuiElement::SetFocus(int f)
|
||||
{
|
||||
focus = f;
|
||||
}
|
||||
|
||||
int GuiElement::IsFocused()
|
||||
{
|
||||
return focus;
|
||||
}
|
||||
|
||||
void GuiElement::SetTrigger(GuiTrigger * t)
|
||||
{
|
||||
if(!trigger[0])
|
||||
trigger[0] = t;
|
||||
else if(!trigger[1])
|
||||
trigger[1] = t;
|
||||
else // both were assigned, so we'll just overwrite the first one
|
||||
trigger[0] = t;
|
||||
}
|
||||
|
||||
void GuiElement::SetTrigger(u8 i, GuiTrigger * t)
|
||||
{
|
||||
trigger[i] = t;
|
||||
}
|
||||
|
||||
bool GuiElement::Rumble()
|
||||
{
|
||||
return rumble;
|
||||
}
|
||||
|
||||
void GuiElement::SetRumble(bool r)
|
||||
{
|
||||
rumble = r;
|
||||
}
|
||||
|
||||
int GuiElement::GetEffect()
|
||||
{
|
||||
return effects;
|
||||
}
|
||||
|
||||
void GuiElement::SetEffect(int eff, int amount, int target)
|
||||
{
|
||||
if(eff & EFFECT_SLIDE_IN)
|
||||
{
|
||||
// these calculations overcompensate a little
|
||||
if(eff & EFFECT_SLIDE_TOP)
|
||||
yoffsetDyn = -screenheight;
|
||||
else if(eff & EFFECT_SLIDE_LEFT)
|
||||
xoffsetDyn = -screenwidth;
|
||||
else if(eff & EFFECT_SLIDE_BOTTOM)
|
||||
yoffsetDyn = screenheight;
|
||||
else if(eff & EFFECT_SLIDE_RIGHT)
|
||||
xoffsetDyn = screenwidth;
|
||||
}
|
||||
if(eff & EFFECT_FADE && amount > 0)
|
||||
{
|
||||
alphaDyn = 0;
|
||||
}
|
||||
else if(eff & EFFECT_FADE && amount < 0)
|
||||
{
|
||||
alphaDyn = alpha;
|
||||
}
|
||||
|
||||
effects |= eff;
|
||||
effectAmount = amount;
|
||||
effectTarget = target;
|
||||
}
|
||||
|
||||
void GuiElement::SetEffectOnOver(int eff, int amount, int target)
|
||||
{
|
||||
effectsOver |= eff;
|
||||
effectAmountOver = amount;
|
||||
effectTargetOver = target;
|
||||
}
|
||||
|
||||
void GuiElement::SetEffectGrow()
|
||||
{
|
||||
SetEffectOnOver(EFFECT_SCALE, 4, 110);
|
||||
}
|
||||
|
||||
void GuiElement::UpdateEffects()
|
||||
{
|
||||
if(effects & (EFFECT_SLIDE_IN | EFFECT_SLIDE_OUT))
|
||||
{
|
||||
if(effects & EFFECT_SLIDE_IN)
|
||||
{
|
||||
if(effects & EFFECT_SLIDE_LEFT)
|
||||
{
|
||||
xoffsetDyn += effectAmount;
|
||||
|
||||
if(xoffsetDyn >= 0)
|
||||
{
|
||||
xoffsetDyn = 0;
|
||||
effects = 0;
|
||||
}
|
||||
}
|
||||
else if(effects & EFFECT_SLIDE_RIGHT)
|
||||
{
|
||||
xoffsetDyn -= effectAmount;
|
||||
|
||||
if(xoffsetDyn <= 0)
|
||||
{
|
||||
xoffsetDyn = 0;
|
||||
effects = 0;
|
||||
}
|
||||
}
|
||||
else if(effects & EFFECT_SLIDE_TOP)
|
||||
{
|
||||
yoffsetDyn += effectAmount;
|
||||
|
||||
if(yoffsetDyn >= 0)
|
||||
{
|
||||
yoffsetDyn = 0;
|
||||
effects = 0;
|
||||
}
|
||||
}
|
||||
else if(effects & EFFECT_SLIDE_BOTTOM)
|
||||
{
|
||||
yoffsetDyn -= effectAmount;
|
||||
|
||||
if(yoffsetDyn <= 0)
|
||||
{
|
||||
yoffsetDyn = 0;
|
||||
effects = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(effects & EFFECT_SLIDE_LEFT)
|
||||
{
|
||||
xoffsetDyn -= effectAmount;
|
||||
|
||||
if(xoffsetDyn <= -screenwidth)
|
||||
effects = 0; // shut off effect
|
||||
}
|
||||
else if(effects & EFFECT_SLIDE_RIGHT)
|
||||
{
|
||||
xoffsetDyn += effectAmount;
|
||||
|
||||
if(xoffsetDyn >= screenwidth)
|
||||
effects = 0; // shut off effect
|
||||
}
|
||||
else if(effects & EFFECT_SLIDE_TOP)
|
||||
{
|
||||
yoffsetDyn -= effectAmount;
|
||||
|
||||
if(yoffsetDyn <= -screenheight)
|
||||
effects = 0; // shut off effect
|
||||
}
|
||||
else if(effects & EFFECT_SLIDE_BOTTOM)
|
||||
{
|
||||
yoffsetDyn += effectAmount;
|
||||
|
||||
if(yoffsetDyn >= screenheight)
|
||||
effects = 0; // shut off effect
|
||||
}
|
||||
}
|
||||
}
|
||||
if(effects & EFFECT_FADE)
|
||||
{
|
||||
alphaDyn += effectAmount;
|
||||
|
||||
if(effectAmount < 0 && alphaDyn <= 0)
|
||||
{
|
||||
alphaDyn = 0;
|
||||
effects = 0; // shut off effect
|
||||
}
|
||||
else if(effectAmount > 0 && alphaDyn >= alpha)
|
||||
{
|
||||
alphaDyn = alpha;
|
||||
effects = 0; // shut off effect
|
||||
}
|
||||
}
|
||||
if(effects & EFFECT_SCALE)
|
||||
{
|
||||
scaleDyn += effectAmount/100.0;
|
||||
|
||||
if((effectAmount < 0 && scaleDyn <= effectTarget/100.0)
|
||||
|| (effectAmount > 0 && scaleDyn >= effectTarget/100.0))
|
||||
{
|
||||
scaleDyn = effectTarget/100.0;
|
||||
effects = 0; // shut off effect
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GuiElement::Update(GuiTrigger * t)
|
||||
{
|
||||
if(updateCB)
|
||||
updateCB(this);
|
||||
}
|
||||
|
||||
void GuiElement::SetUpdateCallback(UpdateCallback u)
|
||||
{
|
||||
updateCB = u;
|
||||
}
|
||||
|
||||
void GuiElement::SetPosition(int xoff, int yoff)
|
||||
{
|
||||
xoffset = xoff;
|
||||
yoffset = yoff;
|
||||
}
|
||||
|
||||
void GuiElement::SetAlignment(int hor, int vert)
|
||||
{
|
||||
alignmentHor = hor;
|
||||
alignmentVert = vert;
|
||||
}
|
||||
|
||||
int GuiElement::GetSelected()
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw an element on screen.
|
||||
*/
|
||||
void GuiElement::Draw()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a position is inside the GuiElement.
|
||||
* @param[in] x X position in pixel.
|
||||
* @param[in] y Y position in pixel.
|
||||
*/
|
||||
bool GuiElement::IsInside(int x, int y)
|
||||
{
|
||||
if(x > this->GetLeft() && x < (this->GetLeft()+width)
|
||||
&& y > this->GetTop() && y < (this->GetTop()+height))
|
||||
return true;
|
||||
return false;
|
||||
}
|
318
source/ngc/gui/gui_filebrowser.cpp
Normal file
@ -0,0 +1,318 @@
|
||||
/****************************************************************************
|
||||
* Snes9x 1.51 Nintendo Wii/Gamecube Port
|
||||
*
|
||||
* Tantric February 2009
|
||||
*
|
||||
* gui_filebrowser.cpp
|
||||
*
|
||||
* GUI class definitions
|
||||
***************************************************************************/
|
||||
|
||||
#include "gui.h"
|
||||
#include "filebrowser.h"
|
||||
|
||||
/**
|
||||
* Constructor for the GuiFileBrowser class.
|
||||
*/
|
||||
GuiFileBrowser::GuiFileBrowser(int w, int h)
|
||||
{
|
||||
width = w;
|
||||
height = h;
|
||||
selectedItem = 0;
|
||||
selectable = true;
|
||||
listChanged = true; // trigger an initial list update
|
||||
focus = 0; // allow focus
|
||||
|
||||
trigA = new GuiTrigger;
|
||||
if(GCSettings.WiimoteOrientation)
|
||||
trigA->SetSimpleTrigger(-1, WPAD_BUTTON_2 | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A);
|
||||
else
|
||||
trigA->SetSimpleTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A);
|
||||
|
||||
bgGameSelection = new GuiImageData(bg_game_selection_png);
|
||||
bgGameSelectionImg = new GuiImage(bgGameSelection);
|
||||
bgGameSelectionImg->SetParent(this);
|
||||
bgGameSelectionImg->SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE);
|
||||
|
||||
bgGameSelectionEntry = new GuiImageData(bg_game_selection_entry_png);
|
||||
gameFolder = new GuiImageData(folder_png);
|
||||
|
||||
scrollbar = new GuiImageData(scrollbar_png);
|
||||
scrollbarImg = new GuiImage(scrollbar);
|
||||
scrollbarImg->SetParent(this);
|
||||
scrollbarImg->SetAlignment(ALIGN_RIGHT, ALIGN_TOP);
|
||||
scrollbarImg->SetPosition(0, 30);
|
||||
|
||||
arrowDown = new GuiImageData(scrollbar_arrowdown_png);
|
||||
arrowDownImg = new GuiImage(arrowDown);
|
||||
arrowDownOver = new GuiImageData(scrollbar_arrowdown_over_png);
|
||||
arrowDownOverImg = new GuiImage(arrowDownOver);
|
||||
arrowUp = new GuiImageData(scrollbar_arrowup_png);
|
||||
arrowUpImg = new GuiImage(arrowUp);
|
||||
arrowUpOver = new GuiImageData(scrollbar_arrowup_over_png);
|
||||
arrowUpOverImg = new GuiImage(arrowUpOver);
|
||||
scrollbarBox = new GuiImageData(scrollbar_box_png);
|
||||
scrollbarBoxImg = new GuiImage(scrollbarBox);
|
||||
scrollbarBoxOver = new GuiImageData(scrollbar_box_over_png);
|
||||
scrollbarBoxOverImg = new GuiImage(scrollbarBoxOver);
|
||||
|
||||
arrowUpBtn = new GuiButton(arrowUpImg->GetWidth(), arrowUpImg->GetHeight());
|
||||
arrowUpBtn->SetParent(this);
|
||||
arrowUpBtn->SetImage(arrowUpImg);
|
||||
arrowUpBtn->SetImageOver(arrowUpOverImg);
|
||||
arrowUpBtn->SetAlignment(ALIGN_RIGHT, ALIGN_TOP);
|
||||
arrowUpBtn->SetSelectable(false);
|
||||
arrowUpBtn->SetTrigger(trigA);
|
||||
|
||||
arrowDownBtn = new GuiButton(arrowDownImg->GetWidth(), arrowDownImg->GetHeight());
|
||||
arrowDownBtn->SetParent(this);
|
||||
arrowDownBtn->SetImage(arrowDownImg);
|
||||
arrowDownBtn->SetImageOver(arrowDownOverImg);
|
||||
arrowDownBtn->SetAlignment(ALIGN_RIGHT, ALIGN_BOTTOM);
|
||||
arrowDownBtn->SetSelectable(false);
|
||||
arrowDownBtn->SetTrigger(trigA);
|
||||
|
||||
scrollbarBoxBtn = new GuiButton(scrollbarBoxImg->GetWidth(), scrollbarBoxImg->GetHeight());
|
||||
scrollbarBoxBtn->SetParent(this);
|
||||
scrollbarBoxBtn->SetImage(scrollbarBoxImg);
|
||||
scrollbarBoxBtn->SetImageOver(scrollbarBoxOverImg);
|
||||
scrollbarBoxBtn->SetAlignment(ALIGN_RIGHT, ALIGN_TOP);
|
||||
scrollbarBoxBtn->SetSelectable(false);
|
||||
|
||||
for(int i=0; i<PAGESIZE; i++)
|
||||
{
|
||||
gameListText[i] = new GuiText("Game",22, (GXColor){0, 0, 0, 0xff});
|
||||
gameListText[i]->SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE);
|
||||
gameListText[i]->SetPosition(5,0);
|
||||
|
||||
gameListBg[i] = new GuiImage(bgGameSelectionEntry);
|
||||
gameListFolder[i] = new GuiImage(gameFolder);
|
||||
|
||||
gameList[i] = new GuiButton(380, 30);
|
||||
gameList[i]->SetParent(this);
|
||||
gameList[i]->SetLabel(gameListText[i]);
|
||||
gameList[i]->SetImageOver(gameListBg[i]);
|
||||
gameList[i]->SetPosition(2,30*i+3);
|
||||
gameList[i]->SetTrigger(trigA);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Destructor for the GuiFileBrowser class.
|
||||
*/
|
||||
GuiFileBrowser::~GuiFileBrowser()
|
||||
{
|
||||
delete arrowUpBtn;
|
||||
delete arrowDownBtn;
|
||||
delete scrollbarBoxBtn;
|
||||
|
||||
delete bgGameSelectionImg;
|
||||
delete scrollbarImg;
|
||||
delete arrowDownImg;
|
||||
delete arrowDownOverImg;
|
||||
delete arrowUpImg;
|
||||
delete arrowUpOverImg;
|
||||
delete scrollbarBoxImg;
|
||||
delete scrollbarBoxOverImg;
|
||||
|
||||
delete bgGameSelection;
|
||||
delete bgGameSelectionEntry;
|
||||
delete gameFolder;
|
||||
delete scrollbar;
|
||||
delete arrowDown;
|
||||
delete arrowDownOver;
|
||||
delete arrowUp;
|
||||
delete arrowUpOver;
|
||||
delete scrollbarBox;
|
||||
delete scrollbarBoxOver;
|
||||
|
||||
delete trigA;
|
||||
|
||||
for(int i=0; i<PAGESIZE; i++)
|
||||
{
|
||||
delete gameListText[i];
|
||||
delete gameList[i];
|
||||
delete gameListBg[i];
|
||||
delete gameListFolder[i];
|
||||
}
|
||||
}
|
||||
|
||||
void GuiFileBrowser::SetFocus(int f)
|
||||
{
|
||||
focus = f;
|
||||
|
||||
for(int i=0; i<PAGESIZE; i++)
|
||||
gameList[i]->ResetState();
|
||||
|
||||
if(f == 1)
|
||||
gameList[selectedItem]->SetState(STATE_SELECTED);
|
||||
}
|
||||
|
||||
void GuiFileBrowser::ResetState()
|
||||
{
|
||||
state = STATE_DEFAULT;
|
||||
selectedItem = 0;
|
||||
|
||||
for(int i=0; i<PAGESIZE; i++)
|
||||
{
|
||||
gameList[i]->ResetState();
|
||||
}
|
||||
}
|
||||
|
||||
void GuiFileBrowser::TriggerUpdate()
|
||||
{
|
||||
listChanged = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw the button on screen
|
||||
*/
|
||||
void GuiFileBrowser::Draw()
|
||||
{
|
||||
if(!this->IsVisible())
|
||||
return;
|
||||
|
||||
bgGameSelectionImg->Draw();
|
||||
|
||||
for(int i=0; i<PAGESIZE; i++)
|
||||
{
|
||||
gameList[i]->Draw();
|
||||
}
|
||||
|
||||
scrollbarImg->Draw();
|
||||
arrowUpBtn->Draw();
|
||||
arrowDownBtn->Draw();
|
||||
scrollbarBoxBtn->Draw();
|
||||
|
||||
this->UpdateEffects();
|
||||
}
|
||||
|
||||
void GuiFileBrowser::Update(GuiTrigger * t)
|
||||
{
|
||||
if(state == STATE_DISABLED || !t)
|
||||
return;
|
||||
|
||||
// update the location of the scroll box based on the position in the file list
|
||||
int position = 136*(browser.pageIndex + selectedItem) / browser.numEntries;
|
||||
scrollbarBoxBtn->SetPosition(0,position+36);
|
||||
|
||||
arrowUpBtn->Update(t);
|
||||
arrowDownBtn->Update(t);
|
||||
scrollbarBoxBtn->Update(t);
|
||||
|
||||
// pad/joystick navigation
|
||||
if(!focus)
|
||||
{
|
||||
goto endNavigation; // skip navigation
|
||||
listChanged = false;
|
||||
}
|
||||
|
||||
if(t->Right() || arrowDownBtn->GetState() == STATE_CLICKED)
|
||||
{
|
||||
if(browser.pageIndex < browser.numEntries && browser.numEntries > PAGESIZE)
|
||||
{
|
||||
browser.pageIndex += PAGESIZE;
|
||||
if(browser.pageIndex+PAGESIZE >= browser.numEntries)
|
||||
browser.pageIndex = browser.numEntries-PAGESIZE;
|
||||
listChanged = true;
|
||||
}
|
||||
arrowDownBtn->ResetState();
|
||||
}
|
||||
else if(t->Left() || arrowUpBtn->GetState() == STATE_CLICKED)
|
||||
{
|
||||
if(browser.pageIndex > 0)
|
||||
{
|
||||
browser.pageIndex -= PAGESIZE;
|
||||
if(browser.pageIndex < 0)
|
||||
browser.pageIndex = 0;
|
||||
listChanged = true;
|
||||
}
|
||||
arrowUpBtn->ResetState();
|
||||
}
|
||||
else if(t->Down())
|
||||
{
|
||||
if(browser.pageIndex + selectedItem + 1 < browser.numEntries)
|
||||
{
|
||||
if(selectedItem == PAGESIZE-1)
|
||||
{
|
||||
// move list down by 1
|
||||
browser.pageIndex++;
|
||||
listChanged = true;
|
||||
}
|
||||
else if(gameList[selectedItem+1]->IsVisible())
|
||||
{
|
||||
gameList[selectedItem]->ResetState();
|
||||
gameList[++selectedItem]->SetState(STATE_SELECTED);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(t->Up())
|
||||
{
|
||||
if(selectedItem == 0 && browser.pageIndex + selectedItem > 0)
|
||||
{
|
||||
// move list up by 1
|
||||
browser.pageIndex--;
|
||||
listChanged = true;
|
||||
}
|
||||
else if(selectedItem > 0)
|
||||
{
|
||||
gameList[selectedItem]->ResetState();
|
||||
gameList[--selectedItem]->SetState(STATE_SELECTED);
|
||||
}
|
||||
}
|
||||
|
||||
endNavigation:
|
||||
|
||||
for(int i=0; i<PAGESIZE; i++)
|
||||
{
|
||||
if(listChanged)
|
||||
{
|
||||
if(browser.pageIndex+i < browser.numEntries)
|
||||
{
|
||||
if(gameList[i]->GetState() == STATE_DISABLED)
|
||||
gameList[i]->SetState(STATE_DEFAULT);
|
||||
|
||||
gameList[i]->SetVisible(true);
|
||||
|
||||
gameListText[i]->SetText(browserList[browser.pageIndex+i].displayname);
|
||||
|
||||
if(browserList[browser.pageIndex+i].isdir) // directory
|
||||
{
|
||||
gameList[i]->SetIcon(gameListFolder[i]);
|
||||
gameListText[i]->SetPosition(30,0);
|
||||
}
|
||||
else
|
||||
{
|
||||
gameList[i]->SetIcon(NULL);
|
||||
gameListText[i]->SetPosition(10,0);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
gameList[i]->SetVisible(false);
|
||||
gameList[i]->SetState(STATE_DISABLED);
|
||||
}
|
||||
}
|
||||
|
||||
if(focus)
|
||||
{
|
||||
if(i != selectedItem && gameList[i]->GetState() == STATE_SELECTED)
|
||||
gameList[i]->ResetState();
|
||||
else if(i == selectedItem && gameList[i]->GetState() == STATE_DEFAULT)
|
||||
gameList[selectedItem]->SetState(STATE_SELECTED);
|
||||
}
|
||||
|
||||
gameList[i]->Update(t);
|
||||
|
||||
if(gameList[i]->GetState() == STATE_SELECTED)
|
||||
{
|
||||
selectedItem = i;
|
||||
browser.selIndex = browser.pageIndex + i;
|
||||
}
|
||||
}
|
||||
|
||||
listChanged = false;
|
||||
|
||||
if(updateCB)
|
||||
updateCB(this);
|
||||
}
|
220
source/ngc/gui/gui_image.cpp
Normal file
@ -0,0 +1,220 @@
|
||||
/****************************************************************************
|
||||
* Snes9x 1.51 Nintendo Wii/Gamecube Port
|
||||
*
|
||||
* Tantric February 2009
|
||||
*
|
||||
* gui_image.cpp
|
||||
*
|
||||
* GUI class definitions
|
||||
***************************************************************************/
|
||||
|
||||
#include "gui.h"
|
||||
/**
|
||||
* Constructor for the GuiImage class.
|
||||
*/
|
||||
|
||||
GuiImage::GuiImage(GuiImageData * img)
|
||||
{
|
||||
image = img->GetImage();
|
||||
width = img->GetWidth();
|
||||
height = img->GetHeight();
|
||||
imageangle = 0;
|
||||
tile = -1;
|
||||
stripe = 0;
|
||||
imgType = IMAGE_DATA;
|
||||
}
|
||||
|
||||
GuiImage::GuiImage(u8 * img, int w, int h)
|
||||
{
|
||||
image = img;
|
||||
width = w;
|
||||
height = h;
|
||||
imageangle = 0;
|
||||
tile = -1;
|
||||
stripe = 0;
|
||||
imgType = IMAGE_TEXTURE;
|
||||
}
|
||||
|
||||
GuiImage::GuiImage(int w, int h, GXColor c)
|
||||
{
|
||||
image = (u8 *)memalign (32, w * h * 4);
|
||||
width = w;
|
||||
height = h;
|
||||
imageangle = 0;
|
||||
tile = -1;
|
||||
stripe = 0;
|
||||
imgType = IMAGE_COLOR;
|
||||
|
||||
if(!image)
|
||||
return;
|
||||
|
||||
int x, y;
|
||||
|
||||
for(y=0; y < h; y++)
|
||||
{
|
||||
for(x=0; x < w; x++)
|
||||
{
|
||||
this->SetPixel(x, y, c);
|
||||
}
|
||||
}
|
||||
int len = w*h*4;
|
||||
if(len%32) len += (32-len%32);
|
||||
DCFlushRange(image, len);
|
||||
}
|
||||
|
||||
/**
|
||||
* Destructor for the GuiImage class.
|
||||
*/
|
||||
GuiImage::~GuiImage()
|
||||
{
|
||||
if(imgType == IMAGE_COLOR && image)
|
||||
free(image);
|
||||
}
|
||||
|
||||
u8 * GuiImage::GetImage()
|
||||
{
|
||||
return image;
|
||||
}
|
||||
|
||||
void GuiImage::SetImage(GuiImageData * img)
|
||||
{
|
||||
image = img->GetImage();
|
||||
width = img->GetWidth();
|
||||
height = img->GetHeight();
|
||||
imgType = IMAGE_DATA;
|
||||
}
|
||||
|
||||
void GuiImage::SetImage(u8 * img, int w, int h)
|
||||
{
|
||||
image = img;
|
||||
width = w;
|
||||
height = h;
|
||||
imgType = IMAGE_TEXTURE;
|
||||
}
|
||||
|
||||
void GuiImage::SetAngle(float a)
|
||||
{
|
||||
imageangle = a;
|
||||
}
|
||||
|
||||
void GuiImage::SetTile(int t)
|
||||
{
|
||||
tile = t;
|
||||
}
|
||||
|
||||
GXColor GuiImage::GetPixel(int x, int y)
|
||||
{
|
||||
if(!image || this->GetWidth() <= 0 || x < 0 || y < 0)
|
||||
return (GXColor){0, 0, 0, 0};
|
||||
|
||||
u32 offset = (((y >> 2)<<4)*this->GetWidth()) + ((x >> 2)<<6) + (((y%4 << 2) + x%4 ) << 1);
|
||||
GXColor color;
|
||||
color.a = *(image+offset);
|
||||
color.r = *(image+offset+1);
|
||||
color.g = *(image+offset+32);
|
||||
color.b = *(image+offset+33);
|
||||
return color;
|
||||
}
|
||||
|
||||
void GuiImage::SetPixel(int x, int y, GXColor color)
|
||||
{
|
||||
if(!image || this->GetWidth() <= 0 || x < 0 || y < 0)
|
||||
return;
|
||||
|
||||
u32 offset = (((y >> 2)<<4)*this->GetWidth()) + ((x >> 2)<<6) + (((y%4 << 2) + x%4 ) << 1);
|
||||
*(image+offset) = color.a;
|
||||
*(image+offset+1) = color.r;
|
||||
*(image+offset+32) = color.g;
|
||||
*(image+offset+33) = color.b;
|
||||
}
|
||||
|
||||
void GuiImage::SetStripe(int s)
|
||||
{
|
||||
stripe = s;
|
||||
}
|
||||
|
||||
void GuiImage::ColorStripe(int shift)
|
||||
{
|
||||
int x, y;
|
||||
GXColor color;
|
||||
int alt = 0;
|
||||
|
||||
for(y=0; y < this->GetHeight(); y++)
|
||||
{
|
||||
if(y % 3 == 0)
|
||||
alt ^= 1;
|
||||
|
||||
for(x=0; x < this->GetWidth(); x++)
|
||||
{
|
||||
color = GetPixel(x, y);
|
||||
|
||||
if(alt)
|
||||
{
|
||||
if(color.r < 255-shift)
|
||||
color.r += shift;
|
||||
else
|
||||
color.r = 255;
|
||||
if(color.g < 255-shift)
|
||||
color.g += shift;
|
||||
else
|
||||
color.g = 255;
|
||||
if(color.b < 255-shift)
|
||||
color.b += shift;
|
||||
else
|
||||
color.b = 255;
|
||||
|
||||
color.a = 255;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(color.r > shift)
|
||||
color.r -= shift;
|
||||
else
|
||||
color.r = 0;
|
||||
if(color.g > shift)
|
||||
color.g -= shift;
|
||||
else
|
||||
color.g = 0;
|
||||
if(color.b > shift)
|
||||
color.b -= shift;
|
||||
else
|
||||
color.b = 0;
|
||||
|
||||
color.a = 255;
|
||||
}
|
||||
SetPixel(x, y, color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw the button on screen
|
||||
*/
|
||||
void GuiImage::Draw()
|
||||
{
|
||||
if(!image || !this->IsVisible() || tile == 0)
|
||||
return;
|
||||
|
||||
float currScale = this->GetScale();
|
||||
int currLeft = this->GetLeft();
|
||||
|
||||
if(tile > 0)
|
||||
{
|
||||
for(int i=0; i<tile; i++)
|
||||
Menu_DrawImg(currLeft+width*i, this->GetTop(), width, height, image, imageangle, currScale, currScale, this->GetAlpha());
|
||||
}
|
||||
else
|
||||
{
|
||||
// temporary (maybe), used to correct offset for scaled images
|
||||
if(scale != 1)
|
||||
currLeft = currLeft - width/2 + (width*scale)/2;
|
||||
|
||||
Menu_DrawImg(currLeft, this->GetTop(), width, height, image, imageangle, currScale, currScale, this->GetAlpha());
|
||||
}
|
||||
|
||||
if(stripe > 0)
|
||||
for(int y=0; y < this->GetHeight(); y+=6)
|
||||
Menu_DrawRectangle(currLeft,this->GetTop()+y,this->GetWidth(),3,(GXColor){0, 0, 0, stripe},1);
|
||||
|
||||
this->UpdateEffects();
|
||||
}
|
84
source/ngc/gui/gui_imagedata.cpp
Normal file
@ -0,0 +1,84 @@
|
||||
/****************************************************************************
|
||||
* Snes9x 1.51 Nintendo Wii/Gamecube Port
|
||||
*
|
||||
* Tantric February 2009
|
||||
*
|
||||
* gui_imagedata.cpp
|
||||
*
|
||||
* GUI class definitions
|
||||
***************************************************************************/
|
||||
|
||||
#include "gui.h"
|
||||
|
||||
/**
|
||||
* Constructor for the GuiImageData class.
|
||||
*/
|
||||
GuiImageData::GuiImageData(const u8 * img)
|
||||
{
|
||||
data = NULL;
|
||||
width = 0;
|
||||
height = 0;
|
||||
|
||||
if(img)
|
||||
{
|
||||
PNGUPROP imgProp;
|
||||
IMGCTX ctx = PNGU_SelectImageFromBuffer(img);
|
||||
|
||||
if(!ctx)
|
||||
return;
|
||||
|
||||
int res = PNGU_GetImageProperties(ctx, &imgProp);
|
||||
|
||||
if(res == PNGU_OK)
|
||||
{
|
||||
int len = imgProp.imgWidth * imgProp.imgHeight * 4;
|
||||
if(len%32) len += (32-len%32);
|
||||
data = (u8 *)memalign (32, len);
|
||||
|
||||
if(data)
|
||||
{
|
||||
res = PNGU_DecodeTo4x4RGBA8 (ctx, imgProp.imgWidth, imgProp.imgHeight, data, 255);
|
||||
|
||||
if(res == PNGU_OK)
|
||||
{
|
||||
width = imgProp.imgWidth;
|
||||
height = imgProp.imgHeight;
|
||||
DCFlushRange(data, len);
|
||||
}
|
||||
else
|
||||
{
|
||||
free(data);
|
||||
data = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
PNGU_ReleaseImageContext (ctx);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Destructor for the GuiImageData class.
|
||||
*/
|
||||
GuiImageData::~GuiImageData()
|
||||
{
|
||||
if(data)
|
||||
{
|
||||
free(data);
|
||||
data = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
u8 * GuiImageData::GetImage()
|
||||
{
|
||||
return data;
|
||||
}
|
||||
|
||||
int GuiImageData::GetWidth()
|
||||
{
|
||||
return width;
|
||||
}
|
||||
|
||||
int GuiImageData::GetHeight()
|
||||
{
|
||||
return height;
|
||||
}
|
302
source/ngc/gui/gui_keyboard.cpp
Normal file
@ -0,0 +1,302 @@
|
||||
/****************************************************************************
|
||||
* Snes9x 1.51 Nintendo Wii/Gamecube Port
|
||||
*
|
||||
* Tantric February 2009
|
||||
*
|
||||
* gui_keyboard.cpp
|
||||
*
|
||||
* GUI class definitions
|
||||
***************************************************************************/
|
||||
|
||||
#include "gui.h"
|
||||
/**
|
||||
* Constructor for the GuiKeyboard class.
|
||||
*/
|
||||
|
||||
GuiKeyboard::GuiKeyboard(char * t)
|
||||
{
|
||||
width = 540;
|
||||
height = 400;
|
||||
shift = 0;
|
||||
caps = 0;
|
||||
selectable = true;
|
||||
focus = 0; // allow focus
|
||||
alignmentHor = ALIGN_CENTRE;
|
||||
alignmentVert = ALIGN_MIDDLE;
|
||||
strncpy(kbtextstr, t, 100);
|
||||
kbtextstr[100] = 0;
|
||||
|
||||
Key thekeys[4][10] = {
|
||||
{
|
||||
{'1','!'},
|
||||
{'2','@'},
|
||||
{'3','#'},
|
||||
{'4','$'},
|
||||
{'5','%'},
|
||||
{'6','^'},
|
||||
{'7','&'},
|
||||
{'8','*'},
|
||||
{'9','('},
|
||||
{'0',')'}
|
||||
},
|
||||
{
|
||||
{'q','Q'},
|
||||
{'w','W'},
|
||||
{'e','E'},
|
||||
{'r','R'},
|
||||
{'t','T'},
|
||||
{'y','Y'},
|
||||
{'u','U'},
|
||||
{'i','I'},
|
||||
{'o','O'},
|
||||
{'p','P'}
|
||||
},
|
||||
{
|
||||
{'a','A'},
|
||||
{'s','S'},
|
||||
{'d','D'},
|
||||
{'f','F'},
|
||||
{'g','G'},
|
||||
{'h','H'},
|
||||
{'j','J'},
|
||||
{'k','K'},
|
||||
{'l','L'},
|
||||
{':',';'}
|
||||
},
|
||||
|
||||
{
|
||||
{'z','Z'},
|
||||
{'x','X'},
|
||||
{'c','C'},
|
||||
{'v','V'},
|
||||
{'b','B'},
|
||||
{'n','N'},
|
||||
{'m','M'},
|
||||
{',','<'},
|
||||
{'.','>'},
|
||||
{'/','?'}
|
||||
}
|
||||
};
|
||||
memcpy(keys, thekeys, sizeof(thekeys));
|
||||
|
||||
keyTextbox = new GuiImageData(keyboard_textbox_png);
|
||||
keyTextboxImg = new GuiImage(keyTextbox);
|
||||
keyTextboxImg->SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
|
||||
keyTextboxImg->SetPosition(0, 0);
|
||||
this->Append(keyTextboxImg);
|
||||
|
||||
kbText = new GuiText(kbtextstr, 22, (GXColor){0, 0, 0, 0xff});
|
||||
kbText->SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
|
||||
kbText->SetPosition(0, 13);
|
||||
this->Append(kbText);
|
||||
|
||||
key = new GuiImageData(keyboard_key_png);
|
||||
keyOver = new GuiImageData(keyboard_key_over_png);
|
||||
keyMedium = new GuiImageData(keyboard_mediumkey_png);
|
||||
keyMediumOver = new GuiImageData(keyboard_mediumkey_over_png);
|
||||
keyLarge = new GuiImageData(keyboard_largekey_png);
|
||||
keyLargeOver = new GuiImageData(keyboard_largekey_over_png);
|
||||
|
||||
keySoundOver = new GuiSound(button_over_pcm, button_over_pcm_size, SOUND_PCM);
|
||||
trigA = new GuiTrigger;
|
||||
|
||||
if(GCSettings.WiimoteOrientation)
|
||||
trigA->SetSimpleTrigger(-1, WPAD_BUTTON_2 | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A);
|
||||
else
|
||||
trigA->SetSimpleTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A);
|
||||
|
||||
keyBackImg = new GuiImage(keyMedium);
|
||||
keyBackOverImg = new GuiImage(keyMediumOver);
|
||||
keyBackText = new GuiText("Back", 22, (GXColor){0, 0, 0, 0xff});
|
||||
keyBack = new GuiButton(keyMedium->GetWidth(), keyMedium->GetHeight());
|
||||
keyBack->SetImage(keyBackImg);
|
||||
keyBack->SetImageOver(keyBackOverImg);
|
||||
keyBack->SetLabel(keyBackText);
|
||||
keyBack->SetSoundOver(keySoundOver);
|
||||
keyBack->SetTrigger(trigA);
|
||||
keyBack->SetPosition(10*42+40, 0*42+80);
|
||||
keyBack->SetEffectGrow();
|
||||
this->Append(keyBack);
|
||||
|
||||
keyCapsImg = new GuiImage(keyMedium);
|
||||
keyCapsOverImg = new GuiImage(keyMediumOver);
|
||||
keyCapsText = new GuiText("Caps", 22, (GXColor){0, 0, 0, 0xff});
|
||||
keyCaps = new GuiButton(keyMedium->GetWidth(), keyMedium->GetHeight());
|
||||
keyCaps->SetImage(keyCapsImg);
|
||||
keyCaps->SetImageOver(keyCapsOverImg);
|
||||
keyCaps->SetLabel(keyCapsText);
|
||||
keyCaps->SetSoundOver(keySoundOver);
|
||||
keyCaps->SetTrigger(trigA);
|
||||
keyCaps->SetPosition(0, 2*42+80);
|
||||
keyCaps->SetEffectGrow();
|
||||
this->Append(keyCaps);
|
||||
|
||||
keyShiftImg = new GuiImage(keyMedium);
|
||||
keyShiftOverImg = new GuiImage(keyMediumOver);
|
||||
keyShiftText = new GuiText("Shift", 22, (GXColor){0, 0, 0, 0xff});
|
||||
keyShift = new GuiButton(keyMedium->GetWidth(), keyMedium->GetHeight());
|
||||
keyShift->SetImage(keyShiftImg);
|
||||
keyShift->SetImageOver(keyShiftOverImg);
|
||||
keyShift->SetLabel(keyShiftText);
|
||||
keyShift->SetSoundOver(keySoundOver);
|
||||
keyShift->SetTrigger(trigA);
|
||||
keyShift->SetPosition(21, 3*42+80);
|
||||
keyShift->SetEffectGrow();
|
||||
this->Append(keyShift);
|
||||
|
||||
keySpaceImg = new GuiImage(keyLarge);
|
||||
keySpaceOverImg = new GuiImage(keyLargeOver);
|
||||
keySpace = new GuiButton(keyLarge->GetWidth(), keyLarge->GetHeight());
|
||||
keySpace->SetImage(keySpaceImg);
|
||||
keySpace->SetImageOver(keySpaceOverImg);
|
||||
keySpace->SetSoundOver(keySoundOver);
|
||||
keySpace->SetTrigger(trigA);
|
||||
keySpace->SetPosition(0, 4*42+80);
|
||||
keySpace->SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
|
||||
keySpace->SetEffectGrow();
|
||||
this->Append(keySpace);
|
||||
|
||||
for(int i=0; i<4; i++)
|
||||
{
|
||||
for(int j=0; j<10; j++)
|
||||
{
|
||||
keyImg[i][j] = new GuiImage(key);
|
||||
keyImgOver[i][j] = new GuiImage(keyOver);
|
||||
keyTxt[i][j] = new GuiText(NULL, 22, (GXColor){0, 0, 0, 0xff});
|
||||
keyTxt[i][j]->SetAlignment(ALIGN_CENTRE, ALIGN_BOTTOM);
|
||||
keyTxt[i][j]->SetPosition(0, -10);
|
||||
keyBtn[i][j] = new GuiButton(key->GetWidth(), key->GetHeight());
|
||||
keyBtn[i][j]->SetImage(keyImg[i][j]);
|
||||
keyBtn[i][j]->SetImageOver(keyImgOver[i][j]);
|
||||
keyBtn[i][j]->SetSoundOver(keySoundOver);
|
||||
keyBtn[i][j]->SetTrigger(trigA);
|
||||
keyBtn[i][j]->SetLabel(keyTxt[i][j]);
|
||||
keyBtn[i][j]->SetPosition(j*42+21*i+40, i*42+80);
|
||||
keyBtn[i][j]->SetEffectGrow();
|
||||
this->Append(keyBtn[i][j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Destructor for the GuiKeyboard class.
|
||||
*/
|
||||
GuiKeyboard::~GuiKeyboard()
|
||||
{
|
||||
delete kbText;
|
||||
delete keyTextbox;
|
||||
delete keyTextboxImg;
|
||||
delete keyCapsText;
|
||||
delete keyCapsImg;
|
||||
delete keyCapsOverImg;
|
||||
delete keyCaps;
|
||||
delete keyShiftText;
|
||||
delete keyShiftImg;
|
||||
delete keyShiftOverImg;
|
||||
delete keyShift;
|
||||
delete keyBackText;
|
||||
delete keyBackImg;
|
||||
delete keyBackOverImg;
|
||||
delete keyBack;
|
||||
delete keySpaceImg;
|
||||
delete keySpaceOverImg;
|
||||
delete keySpace;
|
||||
delete key;
|
||||
delete keyOver;
|
||||
delete keyMedium;
|
||||
delete keyMediumOver;
|
||||
delete keyLarge;
|
||||
delete keyLargeOver;
|
||||
delete keySoundOver;
|
||||
delete trigA;
|
||||
|
||||
for(int i=0; i<4; i++)
|
||||
{
|
||||
for(int j=0; j<10; j++)
|
||||
{
|
||||
delete keyImg[i][j];
|
||||
delete keyImgOver[i][j];
|
||||
delete keyTxt[i][j];
|
||||
delete keyBtn[i][j];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GuiKeyboard::Update(GuiTrigger * t)
|
||||
{
|
||||
if(_elements.size() == 0 || (state == STATE_DISABLED && parentElement))
|
||||
return;
|
||||
|
||||
for (u8 i = 0; i < _elements.size(); i++)
|
||||
{
|
||||
try { _elements.at(i)->Update(t); }
|
||||
catch (exception& e) { }
|
||||
}
|
||||
|
||||
if(keySpace->GetState() == STATE_CLICKED)
|
||||
{
|
||||
kbtextstr[strlen(kbtextstr)] = ' ';
|
||||
kbText->SetText(kbtextstr);
|
||||
keySpace->SetState(STATE_SELECTED);
|
||||
}
|
||||
else if(keyBack->GetState() == STATE_CLICKED)
|
||||
{
|
||||
kbtextstr[strlen(kbtextstr)-1] = 0;
|
||||
kbText->SetText(kbtextstr);
|
||||
keyBack->SetState(STATE_SELECTED);
|
||||
}
|
||||
else if(keyShift->GetState() == STATE_CLICKED)
|
||||
{
|
||||
shift ^= 1;
|
||||
keyShift->SetState(STATE_SELECTED);
|
||||
}
|
||||
else if(keyCaps->GetState() == STATE_CLICKED)
|
||||
{
|
||||
caps ^= 1;
|
||||
keyCaps->SetState(STATE_SELECTED);
|
||||
}
|
||||
|
||||
char txt[2] = { 0, 0 };
|
||||
|
||||
for(int i=0; i<4; i++)
|
||||
{
|
||||
for(int j=0; j<10; j++)
|
||||
{
|
||||
if(shift || caps)
|
||||
txt[0] = keys[i][j].chShift;
|
||||
else
|
||||
txt[0] = keys[i][j].ch;
|
||||
|
||||
keyTxt[i][j]->SetText(txt);
|
||||
|
||||
if(keyBtn[i][j]->GetState() == STATE_CLICKED)
|
||||
{
|
||||
if(shift || caps)
|
||||
{
|
||||
kbtextstr[strlen(kbtextstr)] = keys[i][j].chShift;
|
||||
if(shift) shift ^= 1;
|
||||
}
|
||||
else
|
||||
kbtextstr[strlen(kbtextstr)] = keys[i][j].ch;
|
||||
|
||||
kbText->SetText(kbtextstr);
|
||||
keyBtn[i][j]->SetState(STATE_SELECTED);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this->ToggleFocus(t);
|
||||
|
||||
if(focus) // only send actions to this window if it's in focus
|
||||
{
|
||||
// pad/joystick navigation
|
||||
if(t->Right())
|
||||
this->MoveSelectionHor(1);
|
||||
else if(t->Left())
|
||||
this->MoveSelectionHor(-1);
|
||||
else if(t->Down())
|
||||
this->MoveSelectionVert(1);
|
||||
else if(t->Up())
|
||||
this->MoveSelectionVert(-1);
|
||||
}
|
||||
}
|
341
source/ngc/gui/gui_optionbrowser.cpp
Normal file
@ -0,0 +1,341 @@
|
||||
/****************************************************************************
|
||||
* Snes9x 1.51 Nintendo Wii/Gamecube Port
|
||||
*
|
||||
* Tantric February 2009
|
||||
*
|
||||
* gui_optionbrowser.cpp
|
||||
*
|
||||
* GUI class definitions
|
||||
***************************************************************************/
|
||||
|
||||
#include "gui.h"
|
||||
#include "filebrowser.h"
|
||||
|
||||
/**
|
||||
* Constructor for the GuiOptionBrowser class.
|
||||
*/
|
||||
GuiOptionBrowser::GuiOptionBrowser(int w, int h, OptionList * l)
|
||||
{
|
||||
width = w;
|
||||
height = h;
|
||||
options = l;
|
||||
selectable = true;
|
||||
listOffset = this->FindMenuItem(-1, 1);
|
||||
selectedItem = 0;
|
||||
focus = 0; // allow focus
|
||||
|
||||
trigA = new GuiTrigger;
|
||||
if(GCSettings.WiimoteOrientation)
|
||||
trigA->SetSimpleTrigger(-1, WPAD_BUTTON_2 | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A);
|
||||
else
|
||||
trigA->SetSimpleTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A);
|
||||
|
||||
bgOptions = new GuiImageData(bg_options_png);
|
||||
bgOptionsImg = new GuiImage(bgOptions);
|
||||
bgOptionsImg->SetParent(this);
|
||||
bgOptionsImg->SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE);
|
||||
|
||||
bgOptionsEntry = new GuiImageData(bg_options_entry_png);
|
||||
|
||||
scrollbar = new GuiImageData(scrollbar_png);
|
||||
scrollbarImg = new GuiImage(scrollbar);
|
||||
scrollbarImg->SetParent(this);
|
||||
scrollbarImg->SetAlignment(ALIGN_RIGHT, ALIGN_TOP);
|
||||
scrollbarImg->SetPosition(0, 30);
|
||||
|
||||
arrowDown = new GuiImageData(scrollbar_arrowdown_png);
|
||||
arrowDownImg = new GuiImage(arrowDown);
|
||||
arrowDownOver = new GuiImageData(scrollbar_arrowdown_over_png);
|
||||
arrowDownOverImg = new GuiImage(arrowDownOver);
|
||||
arrowUp = new GuiImageData(scrollbar_arrowup_png);
|
||||
arrowUpImg = new GuiImage(arrowUp);
|
||||
arrowUpOver = new GuiImageData(scrollbar_arrowup_over_png);
|
||||
arrowUpOverImg = new GuiImage(arrowUpOver);
|
||||
scrollbarBox = new GuiImageData(scrollbar_box_png);
|
||||
scrollbarBoxImg = new GuiImage(scrollbarBox);
|
||||
scrollbarBoxOver = new GuiImageData(scrollbar_box_over_png);
|
||||
scrollbarBoxOverImg = new GuiImage(scrollbarBoxOver);
|
||||
|
||||
arrowUpBtn = new GuiButton(arrowUpImg->GetWidth(), arrowUpImg->GetHeight());
|
||||
arrowUpBtn->SetParent(this);
|
||||
arrowUpBtn->SetImage(arrowUpImg);
|
||||
arrowUpBtn->SetImageOver(arrowUpOverImg);
|
||||
arrowUpBtn->SetAlignment(ALIGN_RIGHT, ALIGN_TOP);
|
||||
arrowUpBtn->SetSelectable(false);
|
||||
arrowUpBtn->SetTrigger(trigA);
|
||||
|
||||
arrowDownBtn = new GuiButton(arrowDownImg->GetWidth(), arrowDownImg->GetHeight());
|
||||
arrowDownBtn->SetParent(this);
|
||||
arrowDownBtn->SetImage(arrowDownImg);
|
||||
arrowDownBtn->SetImageOver(arrowDownOverImg);
|
||||
arrowDownBtn->SetAlignment(ALIGN_RIGHT, ALIGN_BOTTOM);
|
||||
arrowDownBtn->SetSelectable(false);
|
||||
arrowDownBtn->SetTrigger(trigA);
|
||||
|
||||
scrollbarBoxBtn = new GuiButton(scrollbarBoxImg->GetWidth(), scrollbarBoxImg->GetHeight());
|
||||
scrollbarBoxBtn->SetParent(this);
|
||||
scrollbarBoxBtn->SetImage(scrollbarBoxImg);
|
||||
scrollbarBoxBtn->SetImageOver(scrollbarBoxOverImg);
|
||||
scrollbarBoxBtn->SetAlignment(ALIGN_RIGHT, ALIGN_TOP);
|
||||
scrollbarBoxBtn->SetSelectable(false);
|
||||
|
||||
for(int i=0; i<PAGESIZE; i++)
|
||||
{
|
||||
optionTxt[i] = new GuiText(options->name[i], 22, (GXColor){0, 0, 0, 0xff});
|
||||
optionTxt[i]->SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE);
|
||||
optionTxt[i]->SetPosition(8,0);
|
||||
|
||||
optionVal[i] = new GuiText(NULL, 22, (GXColor){0, 0, 0, 0xff});
|
||||
optionVal[i]->SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE);
|
||||
optionVal[i]->SetPosition(250,0);
|
||||
|
||||
optionBg[i] = new GuiImage(bgOptionsEntry);
|
||||
|
||||
optionBtn[i] = new GuiButton(512,30);
|
||||
optionBtn[i]->SetParent(this);
|
||||
optionBtn[i]->SetLabel(optionTxt[i], 0);
|
||||
optionBtn[i]->SetLabel(optionVal[i], 1);
|
||||
optionBtn[i]->SetImageOver(optionBg[i]);
|
||||
optionBtn[i]->SetPosition(0,30*i+3);
|
||||
optionBtn[i]->SetTrigger(trigA);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Destructor for the GuiOptionBrowser class.
|
||||
*/
|
||||
GuiOptionBrowser::~GuiOptionBrowser()
|
||||
{
|
||||
delete arrowUpBtn;
|
||||
delete arrowDownBtn;
|
||||
delete scrollbarBoxBtn;
|
||||
|
||||
delete bgOptionsImg;
|
||||
delete scrollbarImg;
|
||||
delete arrowDownImg;
|
||||
delete arrowDownOverImg;
|
||||
delete arrowUpImg;
|
||||
delete arrowUpOverImg;
|
||||
delete scrollbarBoxImg;
|
||||
delete scrollbarBoxOverImg;
|
||||
|
||||
delete bgOptions;
|
||||
delete bgOptionsEntry;
|
||||
delete scrollbar;
|
||||
delete arrowDown;
|
||||
delete arrowDownOver;
|
||||
delete arrowUp;
|
||||
delete arrowUpOver;
|
||||
delete scrollbarBox;
|
||||
delete scrollbarBoxOver;
|
||||
|
||||
delete trigA;
|
||||
|
||||
for(int i=0; i<PAGESIZE; i++)
|
||||
{
|
||||
delete optionTxt[i];
|
||||
delete optionVal[i];
|
||||
delete optionBg[i];
|
||||
delete optionBtn[i];
|
||||
}
|
||||
}
|
||||
|
||||
void GuiOptionBrowser::SetCol2Position(int x)
|
||||
{
|
||||
for(int i=0; i<PAGESIZE; i++)
|
||||
optionVal[i]->SetPosition(x,0);
|
||||
}
|
||||
|
||||
void GuiOptionBrowser::SetFocus(int f)
|
||||
{
|
||||
focus = f;
|
||||
|
||||
for(int i=0; i<PAGESIZE; i++)
|
||||
optionBtn[i]->ResetState();
|
||||
|
||||
if(f == 1)
|
||||
optionBtn[selectedItem]->SetState(STATE_SELECTED);
|
||||
}
|
||||
|
||||
void GuiOptionBrowser::ResetState()
|
||||
{
|
||||
if(state != STATE_DISABLED)
|
||||
state = STATE_DEFAULT;
|
||||
|
||||
for(int i=0; i<PAGESIZE; i++)
|
||||
{
|
||||
optionBtn[i]->ResetState();
|
||||
}
|
||||
}
|
||||
|
||||
int GuiOptionBrowser::GetClickedOption()
|
||||
{
|
||||
int found = -1;
|
||||
for(int i=0; i<PAGESIZE; i++)
|
||||
{
|
||||
if(optionBtn[i]->GetState() == STATE_CLICKED)
|
||||
{
|
||||
optionBtn[i]->SetState(STATE_SELECTED);
|
||||
found = optionIndex[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
return found;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* FindMenuItem
|
||||
*
|
||||
* Help function to find the next visible menu item on the list
|
||||
***************************************************************************/
|
||||
|
||||
int GuiOptionBrowser::FindMenuItem(int currentItem, int direction)
|
||||
{
|
||||
int nextItem = currentItem + direction;
|
||||
|
||||
if(nextItem < 0 || nextItem >= options->length)
|
||||
return -1;
|
||||
|
||||
if(strlen(options->name[nextItem]) > 0)
|
||||
return nextItem;
|
||||
else
|
||||
return FindMenuItem(nextItem, direction);
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw the button on screen
|
||||
*/
|
||||
void GuiOptionBrowser::Draw()
|
||||
{
|
||||
if(!this->IsVisible())
|
||||
return;
|
||||
|
||||
bgOptionsImg->Draw();
|
||||
|
||||
int next = listOffset;
|
||||
|
||||
for(int i=0; i<PAGESIZE; i++)
|
||||
{
|
||||
if(next >= 0)
|
||||
{
|
||||
optionBtn[i]->Draw();
|
||||
next = this->FindMenuItem(next, 1);
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
scrollbarImg->Draw();
|
||||
arrowUpBtn->Draw();
|
||||
arrowDownBtn->Draw();
|
||||
scrollbarBoxBtn->Draw();
|
||||
|
||||
this->UpdateEffects();
|
||||
}
|
||||
|
||||
void GuiOptionBrowser::Update(GuiTrigger * t)
|
||||
{
|
||||
if(state == STATE_DISABLED || !t)
|
||||
return;
|
||||
|
||||
int next, prev;
|
||||
|
||||
// update the location of the scroll box based on the position in the option list
|
||||
int position = 136*(listOffset+selectedItem)/options->length;
|
||||
|
||||
if(position > 130)
|
||||
position = 136;
|
||||
|
||||
scrollbarBoxBtn->SetPosition(0,position+36);
|
||||
|
||||
arrowUpBtn->Update(t);
|
||||
arrowDownBtn->Update(t);
|
||||
scrollbarBoxBtn->Update(t);
|
||||
|
||||
next = listOffset;
|
||||
|
||||
for(int i=0; i<PAGESIZE; i++)
|
||||
{
|
||||
if(next >= 0)
|
||||
{
|
||||
if(optionBtn[i]->GetState() == STATE_DISABLED)
|
||||
{
|
||||
optionBtn[i]->SetVisible(true);
|
||||
optionBtn[i]->SetState(STATE_DEFAULT);
|
||||
}
|
||||
|
||||
optionTxt[i]->SetText(options->name[next]);
|
||||
optionVal[i]->SetText(options->value[next]);
|
||||
optionIndex[i] = next;
|
||||
next = this->FindMenuItem(next, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
optionBtn[i]->SetVisible(false);
|
||||
optionBtn[i]->SetState(STATE_DISABLED);
|
||||
}
|
||||
|
||||
if(focus)
|
||||
{
|
||||
if(i != selectedItem && optionBtn[i]->GetState() == STATE_SELECTED)
|
||||
optionBtn[i]->ResetState();
|
||||
else if(i == selectedItem && optionBtn[i]->GetState() == STATE_DEFAULT)
|
||||
optionBtn[selectedItem]->SetState(STATE_SELECTED);
|
||||
}
|
||||
|
||||
optionBtn[i]->Update(t);
|
||||
|
||||
if(optionBtn[i]->GetState() == STATE_SELECTED)
|
||||
{
|
||||
selectedItem = i;
|
||||
}
|
||||
}
|
||||
|
||||
// pad/joystick navigation
|
||||
if(!focus)
|
||||
return; // skip navigation
|
||||
|
||||
if(t->Down() || arrowDownBtn->GetState() == STATE_CLICKED)
|
||||
{
|
||||
next = this->FindMenuItem(optionIndex[selectedItem], 1);
|
||||
|
||||
if(next >= 0)
|
||||
{
|
||||
if(selectedItem == PAGESIZE-1)
|
||||
{
|
||||
// move list down by 1
|
||||
listOffset = this->FindMenuItem(listOffset, 1);
|
||||
}
|
||||
else if(optionBtn[selectedItem+1]->IsVisible())
|
||||
{
|
||||
optionBtn[selectedItem]->ResetState();
|
||||
optionBtn[selectedItem+1]->SetState(STATE_SELECTED);
|
||||
selectedItem++;
|
||||
}
|
||||
}
|
||||
arrowDownBtn->ResetState();
|
||||
}
|
||||
else if(t->Up() || arrowUpBtn->GetState() == STATE_CLICKED)
|
||||
{
|
||||
prev = this->FindMenuItem(optionIndex[selectedItem], -1);
|
||||
|
||||
if(prev >= 0)
|
||||
{
|
||||
if(selectedItem == 0)
|
||||
{
|
||||
// move list up by 1
|
||||
listOffset = prev;
|
||||
}
|
||||
else
|
||||
{
|
||||
optionBtn[selectedItem]->ResetState();
|
||||
optionBtn[selectedItem-1]->SetState(STATE_SELECTED);
|
||||
selectedItem--;
|
||||
}
|
||||
}
|
||||
arrowUpBtn->ResetState();
|
||||
}
|
||||
|
||||
if(updateCB)
|
||||
updateCB(this);
|
||||
}
|
409
source/ngc/gui/gui_savebrowser.cpp
Normal file
@ -0,0 +1,409 @@
|
||||
/****************************************************************************
|
||||
* Snes9x 1.51 Nintendo Wii/Gamecube Port
|
||||
*
|
||||
* Tantric February 2009
|
||||
*
|
||||
* gui_savebrowser.cpp
|
||||
*
|
||||
* GUI class definitions
|
||||
***************************************************************************/
|
||||
|
||||
#include "gui.h"
|
||||
#include "filebrowser.h"
|
||||
|
||||
/**
|
||||
* Constructor for the GuiSaveBrowser class.
|
||||
*/
|
||||
GuiSaveBrowser::GuiSaveBrowser(int w, int h, SaveList * s, int a)
|
||||
{
|
||||
width = w;
|
||||
height = h;
|
||||
saves = s;
|
||||
action = a;
|
||||
selectable = true;
|
||||
|
||||
if(action == 0) // save
|
||||
listOffset = 0;
|
||||
else
|
||||
listOffset = -2;
|
||||
|
||||
selectedItem = 0;
|
||||
focus = 0; // allow focus
|
||||
|
||||
trigA = new GuiTrigger;
|
||||
|
||||
if(GCSettings.WiimoteOrientation)
|
||||
trigA->SetSimpleTrigger(-1, WPAD_BUTTON_2 | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A);
|
||||
else
|
||||
trigA->SetSimpleTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A);
|
||||
|
||||
gameSave = new GuiImageData(button_gamesave_png);
|
||||
gameSaveOver = new GuiImageData(button_gamesave_over_png);
|
||||
gameSaveBlank = new GuiImageData(button_gamesave_blank_png);
|
||||
|
||||
scrollbar = new GuiImageData(scrollbar_png);
|
||||
scrollbarImg = new GuiImage(scrollbar);
|
||||
scrollbarImg->SetParent(this);
|
||||
scrollbarImg->SetAlignment(ALIGN_RIGHT, ALIGN_TOP);
|
||||
scrollbarImg->SetPosition(0, 30);
|
||||
|
||||
arrowDown = new GuiImageData(scrollbar_arrowdown_png);
|
||||
arrowDownImg = new GuiImage(arrowDown);
|
||||
arrowDownOver = new GuiImageData(scrollbar_arrowdown_over_png);
|
||||
arrowDownOverImg = new GuiImage(arrowDownOver);
|
||||
arrowUp = new GuiImageData(scrollbar_arrowup_png);
|
||||
arrowUpImg = new GuiImage(arrowUp);
|
||||
arrowUpOver = new GuiImageData(scrollbar_arrowup_over_png);
|
||||
arrowUpOverImg = new GuiImage(arrowUpOver);
|
||||
scrollbarBox = new GuiImageData(scrollbar_box_png);
|
||||
scrollbarBoxImg = new GuiImage(scrollbarBox);
|
||||
scrollbarBoxOver = new GuiImageData(scrollbar_box_over_png);
|
||||
scrollbarBoxOverImg = new GuiImage(scrollbarBoxOver);
|
||||
|
||||
arrowUpBtn = new GuiButton(arrowUpImg->GetWidth(), arrowUpImg->GetHeight());
|
||||
arrowUpBtn->SetParent(this);
|
||||
arrowUpBtn->SetImage(arrowUpImg);
|
||||
arrowUpBtn->SetImageOver(arrowUpOverImg);
|
||||
arrowUpBtn->SetAlignment(ALIGN_RIGHT, ALIGN_TOP);
|
||||
arrowUpBtn->SetSelectable(false);
|
||||
arrowUpBtn->SetTrigger(trigA);
|
||||
|
||||
arrowDownBtn = new GuiButton(arrowDownImg->GetWidth(), arrowDownImg->GetHeight());
|
||||
arrowDownBtn->SetParent(this);
|
||||
arrowDownBtn->SetImage(arrowDownImg);
|
||||
arrowDownBtn->SetImageOver(arrowDownOverImg);
|
||||
arrowDownBtn->SetAlignment(ALIGN_RIGHT, ALIGN_BOTTOM);
|
||||
arrowDownBtn->SetSelectable(false);
|
||||
arrowDownBtn->SetTrigger(trigA);
|
||||
|
||||
scrollbarBoxBtn = new GuiButton(scrollbarBoxImg->GetWidth(), scrollbarBoxImg->GetHeight());
|
||||
scrollbarBoxBtn->SetParent(this);
|
||||
scrollbarBoxBtn->SetImage(scrollbarBoxImg);
|
||||
scrollbarBoxBtn->SetImageOver(scrollbarBoxOverImg);
|
||||
scrollbarBoxBtn->SetAlignment(ALIGN_RIGHT, ALIGN_TOP);
|
||||
scrollbarBoxBtn->SetSelectable(false);
|
||||
|
||||
for(int i=0; i<SAVELISTSIZE; i++)
|
||||
{
|
||||
saveDate[i] = new GuiText(NULL, 22, (GXColor){0, 0, 0, 0xff});
|
||||
saveDate[i]->SetAlignment(ALIGN_LEFT, ALIGN_TOP);
|
||||
saveDate[i]->SetPosition(80,5);
|
||||
saveTime[i] = new GuiText(NULL, 22, (GXColor){0, 0, 0, 0xff});
|
||||
saveTime[i]->SetAlignment(ALIGN_LEFT, ALIGN_TOP);
|
||||
saveTime[i]->SetPosition(80,27);
|
||||
|
||||
saveType[i] = new GuiText(NULL, 22, (GXColor){0, 0, 0, 0xff});
|
||||
saveType[i]->SetAlignment(ALIGN_LEFT, ALIGN_TOP);
|
||||
saveType[i]->SetPosition(80,50);
|
||||
|
||||
saveBgImg[i] = new GuiImage(gameSave);
|
||||
saveBgOverImg[i] = new GuiImage(gameSaveOver);
|
||||
savePreviewImg[i] = new GuiImage(gameSaveBlank);
|
||||
savePreviewImg[i]->SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE);
|
||||
savePreviewImg[i]->SetPosition(5,0);
|
||||
|
||||
saveBtn[i] = new GuiButton(saveBgImg[i]->GetWidth(),saveBgImg[i]->GetHeight());
|
||||
saveBtn[i]->SetParent(this);
|
||||
saveBtn[i]->SetLabel(saveDate[i], 0);
|
||||
saveBtn[i]->SetLabel(saveTime[i], 1);
|
||||
saveBtn[i]->SetLabel(saveType[i], 2);
|
||||
saveBtn[i]->SetImage(saveBgImg[i]);
|
||||
saveBtn[i]->SetImageOver(saveBgOverImg[i]);
|
||||
saveBtn[i]->SetIcon(savePreviewImg[i]);
|
||||
saveBtn[i]->SetAlignment(ALIGN_LEFT, ALIGN_TOP);
|
||||
saveBtn[i]->SetPosition(257*(i % 2),87*(i/2));
|
||||
saveBtn[i]->SetTrigger(trigA);
|
||||
saveBtn[i]->SetState(STATE_DISABLED);
|
||||
saveBtn[i]->SetEffectGrow();
|
||||
saveBtn[i]->SetVisible(false);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Destructor for the GuiSaveBrowser class.
|
||||
*/
|
||||
GuiSaveBrowser::~GuiSaveBrowser()
|
||||
{
|
||||
delete arrowUpBtn;
|
||||
delete arrowDownBtn;
|
||||
delete scrollbarBoxBtn;
|
||||
|
||||
delete scrollbarImg;
|
||||
delete arrowDownImg;
|
||||
delete arrowDownOverImg;
|
||||
delete arrowUpImg;
|
||||
delete arrowUpOverImg;
|
||||
delete scrollbarBoxImg;
|
||||
delete scrollbarBoxOverImg;
|
||||
|
||||
delete gameSave;
|
||||
delete gameSaveOver;
|
||||
delete gameSaveBlank;
|
||||
delete scrollbar;
|
||||
delete arrowDown;
|
||||
delete arrowDownOver;
|
||||
delete arrowUp;
|
||||
delete arrowUpOver;
|
||||
delete scrollbarBox;
|
||||
delete scrollbarBoxOver;
|
||||
|
||||
delete trigA;
|
||||
|
||||
for(int i=0; i<SAVELISTSIZE; i++)
|
||||
{
|
||||
delete saveBtn[i];
|
||||
delete saveDate[i];
|
||||
delete saveTime[i];
|
||||
delete saveType[i];
|
||||
delete saveBgImg[i];
|
||||
delete saveBgOverImg[i];
|
||||
delete savePreviewImg[i];
|
||||
}
|
||||
}
|
||||
|
||||
void GuiSaveBrowser::SetFocus(int f)
|
||||
{
|
||||
focus = f;
|
||||
|
||||
for(int i=0; i<SAVELISTSIZE; i++)
|
||||
saveBtn[i]->ResetState();
|
||||
|
||||
if(f == 1)
|
||||
saveBtn[selectedItem]->SetState(STATE_SELECTED);
|
||||
}
|
||||
|
||||
void GuiSaveBrowser::ResetState()
|
||||
{
|
||||
if(state != STATE_DISABLED)
|
||||
state = STATE_DEFAULT;
|
||||
|
||||
for(int i=0; i<SAVELISTSIZE; i++)
|
||||
{
|
||||
saveBtn[i]->ResetState();
|
||||
}
|
||||
}
|
||||
|
||||
int GuiSaveBrowser::GetClickedSave()
|
||||
{
|
||||
int found = -1;
|
||||
for(int i=0; i<SAVELISTSIZE; i++)
|
||||
{
|
||||
if(saveBtn[i]->GetState() == STATE_CLICKED)
|
||||
{
|
||||
saveBtn[i]->SetState(STATE_SELECTED);
|
||||
found = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return found;
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw the button on screen
|
||||
*/
|
||||
void GuiSaveBrowser::Draw()
|
||||
{
|
||||
if(!this->IsVisible())
|
||||
return;
|
||||
|
||||
for(int i=0; i<SAVELISTSIZE; i++)
|
||||
saveBtn[i]->Draw();
|
||||
|
||||
scrollbarImg->Draw();
|
||||
arrowUpBtn->Draw();
|
||||
arrowDownBtn->Draw();
|
||||
scrollbarBoxBtn->Draw();
|
||||
|
||||
this->UpdateEffects();
|
||||
}
|
||||
|
||||
void GuiSaveBrowser::Update(GuiTrigger * t)
|
||||
{
|
||||
if(state == STATE_DISABLED || !t)
|
||||
return;
|
||||
|
||||
int i, len;
|
||||
char savetext[50];
|
||||
// update the location of the scroll box based on the position in the option list
|
||||
int position;
|
||||
if(action == 0)
|
||||
position = 136*(listOffset+selectedItem)/saves->length;
|
||||
else
|
||||
position = 136*(listOffset+selectedItem+2)/saves->length;
|
||||
|
||||
if(position > 130)
|
||||
position = 136;
|
||||
|
||||
scrollbarBoxBtn->SetPosition(0,position+36);
|
||||
|
||||
arrowUpBtn->Update(t);
|
||||
arrowDownBtn->Update(t);
|
||||
scrollbarBoxBtn->Update(t);
|
||||
|
||||
// pad/joystick navigation
|
||||
if(!focus)
|
||||
goto endNavigation; // skip navigation
|
||||
|
||||
if(t->Right())
|
||||
{
|
||||
if(selectedItem == SAVELISTSIZE-1)
|
||||
{
|
||||
if(listOffset + SAVELISTSIZE < saves->length)
|
||||
{
|
||||
// move list down by 1 row
|
||||
listOffset += 2;
|
||||
selectedItem -= 1;
|
||||
}
|
||||
}
|
||||
else if(saveBtn[selectedItem+1]->IsVisible())
|
||||
{
|
||||
saveBtn[selectedItem]->ResetState();
|
||||
saveBtn[selectedItem+1]->SetState(STATE_SELECTED);
|
||||
selectedItem += 1;
|
||||
}
|
||||
}
|
||||
else if(t->Left())
|
||||
{
|
||||
if(selectedItem == 0)
|
||||
{
|
||||
if((listOffset - 2 >= 0 && action == 0) ||
|
||||
(listOffset - 2 >= -2 && action == 1))
|
||||
{
|
||||
// move list up by 1
|
||||
listOffset -= 2;
|
||||
selectedItem = SAVELISTSIZE-1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
selectedItem -= 1;
|
||||
}
|
||||
}
|
||||
else if(t->Down() || arrowDownBtn->GetState() == STATE_CLICKED)
|
||||
{
|
||||
if(selectedItem >= SAVELISTSIZE-2)
|
||||
{
|
||||
if(listOffset + SAVELISTSIZE + 1 < saves->length)
|
||||
{
|
||||
listOffset += 2;
|
||||
}
|
||||
else if(listOffset + SAVELISTSIZE < saves->length)
|
||||
{
|
||||
listOffset += 2;
|
||||
|
||||
if(selectedItem == SAVELISTSIZE-1)
|
||||
selectedItem -= 1;
|
||||
}
|
||||
}
|
||||
else if(saveBtn[selectedItem+2]->IsVisible())
|
||||
{
|
||||
selectedItem += 2;
|
||||
}
|
||||
arrowDownBtn->ResetState();
|
||||
}
|
||||
else if(t->Up() || arrowUpBtn->GetState() == STATE_CLICKED)
|
||||
{
|
||||
if(selectedItem < 2)
|
||||
{
|
||||
if((listOffset - 2 >= 0 && action == 0) ||
|
||||
(listOffset - 2 >= -2 && action == 1))
|
||||
{
|
||||
// move list up by 1
|
||||
listOffset -= 2;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
selectedItem -= 2;
|
||||
}
|
||||
arrowUpBtn->ResetState();
|
||||
}
|
||||
|
||||
endNavigation:
|
||||
|
||||
for(i=0; i<SAVELISTSIZE; i++)
|
||||
{
|
||||
if(listOffset+i < 0 && action == 1)
|
||||
{
|
||||
saveDate[0]->SetText(NULL);
|
||||
saveDate[1]->SetText(NULL);
|
||||
saveTime[0]->SetText("New SRAM");
|
||||
saveTime[1]->SetText("New Snapshot");
|
||||
saveType[0]->SetText(NULL);
|
||||
saveType[1]->SetText(NULL);
|
||||
savePreviewImg[0]->SetImage(gameSaveBlank);
|
||||
savePreviewImg[1]->SetImage(gameSaveBlank);
|
||||
savePreviewImg[0]->SetScale(1);
|
||||
savePreviewImg[1]->SetScale(1);
|
||||
saveBtn[0]->SetVisible(true);
|
||||
saveBtn[1]->SetVisible(true);
|
||||
|
||||
if(saveBtn[0]->GetState() == STATE_DISABLED)
|
||||
saveBtn[0]->SetState(STATE_DEFAULT);
|
||||
if(saveBtn[1]->GetState() == STATE_DISABLED)
|
||||
saveBtn[1]->SetState(STATE_DEFAULT);
|
||||
}
|
||||
else if(listOffset+i < saves->length)
|
||||
{
|
||||
if(saveBtn[i]->GetState() == STATE_DISABLED)
|
||||
{
|
||||
saveBtn[i]->SetVisible(true);
|
||||
saveBtn[i]->SetState(STATE_DEFAULT);
|
||||
}
|
||||
|
||||
saveDate[i]->SetText(saves->date[listOffset+i]);
|
||||
saveTime[i]->SetText(saves->time[listOffset+i]);
|
||||
|
||||
if(saves->type[listOffset+i] == FILE_SRAM)
|
||||
sprintf(savetext, "SRAM");
|
||||
else
|
||||
sprintf(savetext, "Snapshot");
|
||||
|
||||
len = strlen(saves->filename[listOffset+i]);
|
||||
if(len > 10 &&
|
||||
((saves->filename[listOffset+i][len-8] == 'A' &&
|
||||
saves->filename[listOffset+i][len-7] == 'u' &&
|
||||
saves->filename[listOffset+i][len-6] == 't' &&
|
||||
saves->filename[listOffset+i][len-5] == 'o') ||
|
||||
saves->filename[listOffset+i][len-5] == '0')
|
||||
)
|
||||
{
|
||||
strcat(savetext, " (Auto)");
|
||||
}
|
||||
saveType[i]->SetText(savetext);
|
||||
|
||||
if(saves->previewImg[listOffset+i] != NULL)
|
||||
{
|
||||
savePreviewImg[i]->SetImage(saves->previewImg[listOffset+i]);
|
||||
savePreviewImg[i]->SetScale(0.1);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
savePreviewImg[i]->SetImage(gameSaveBlank);
|
||||
savePreviewImg[i]->SetScale(1);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
saveBtn[i]->SetVisible(false);
|
||||
saveBtn[i]->SetState(STATE_DISABLED);
|
||||
}
|
||||
|
||||
if(focus)
|
||||
{
|
||||
if(i != selectedItem && saveBtn[i]->GetState() == STATE_SELECTED)
|
||||
saveBtn[i]->ResetState();
|
||||
else if(i == selectedItem && saveBtn[i]->GetState() == STATE_DEFAULT)
|
||||
saveBtn[selectedItem]->SetState(STATE_SELECTED);
|
||||
}
|
||||
|
||||
saveBtn[i]->Update(t);
|
||||
|
||||
if(saveBtn[i]->GetState() == STATE_SELECTED)
|
||||
selectedItem = i;
|
||||
}
|
||||
|
||||
if(updateCB)
|
||||
updateCB(this);
|
||||
}
|
134
source/ngc/gui/gui_sound.cpp
Normal file
@ -0,0 +1,134 @@
|
||||
/****************************************************************************
|
||||
* Snes9x 1.51 Nintendo Wii/Gamecube Port
|
||||
*
|
||||
* Tantric February 2009
|
||||
*
|
||||
* gui_sound.cpp
|
||||
*
|
||||
* GUI class definitions
|
||||
***************************************************************************/
|
||||
|
||||
#include "gui.h"
|
||||
|
||||
/**
|
||||
* Constructor for the GuiSound class.
|
||||
*/
|
||||
GuiSound::GuiSound(const u8 * snd, s32 len, int t)
|
||||
{
|
||||
sound = snd;
|
||||
length = len;
|
||||
type = t;
|
||||
voice = -1;
|
||||
volume = 100;
|
||||
}
|
||||
|
||||
/**
|
||||
* Destructor for the GuiSound class.
|
||||
*/
|
||||
GuiSound::~GuiSound()
|
||||
{
|
||||
}
|
||||
|
||||
void GuiSound::Play()
|
||||
{
|
||||
#ifndef NO_SOUND
|
||||
int vol;
|
||||
|
||||
switch(type)
|
||||
{
|
||||
case SOUND_PCM:
|
||||
vol = 255*(volume/100.0)*(GCSettings.SFXVolume/100.0);
|
||||
voice = ASND_GetFirstUnusedVoice();
|
||||
if(voice >= 0)
|
||||
ASND_SetVoice(voice, VOICE_MONO_8BIT, 8000, 0,
|
||||
(u8 *)sound, length, vol, vol, NULL);
|
||||
break;
|
||||
|
||||
case SOUND_OGG:
|
||||
voice = 0;
|
||||
PlayOgg(mem_open((char *)sound, length), 0, OGG_INFINITE_TIME);
|
||||
SetVolumeOgg(255*(volume/100.0));
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void GuiSound::Stop()
|
||||
{
|
||||
#ifndef NO_SOUND
|
||||
if(voice < 0)
|
||||
return;
|
||||
|
||||
switch(type)
|
||||
{
|
||||
case SOUND_PCM:
|
||||
ASND_StopVoice(voice);
|
||||
break;
|
||||
|
||||
case SOUND_OGG:
|
||||
StopOgg();
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void GuiSound::Pause()
|
||||
{
|
||||
#ifndef NO_SOUND
|
||||
if(voice < 0)
|
||||
return;
|
||||
|
||||
switch(type)
|
||||
{
|
||||
case SOUND_PCM:
|
||||
ASND_PauseVoice(voice, 1);
|
||||
break;
|
||||
|
||||
case SOUND_OGG:
|
||||
PauseOgg(1);
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void GuiSound::Resume()
|
||||
{
|
||||
#ifndef NO_SOUND
|
||||
if(voice < 0)
|
||||
return;
|
||||
|
||||
switch(type)
|
||||
{
|
||||
case SOUND_PCM:
|
||||
ASND_PauseVoice(voice, 0);
|
||||
break;
|
||||
|
||||
case SOUND_OGG:
|
||||
PauseOgg(0);
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void GuiSound::SetVolume(int vol)
|
||||
{
|
||||
#ifndef NO_SOUND
|
||||
volume = vol;
|
||||
|
||||
if(voice < 0)
|
||||
return;
|
||||
|
||||
int newvol = 255*(volume/100.0)*(GCSettings.SFXVolume/100.0);
|
||||
|
||||
switch(type)
|
||||
{
|
||||
case SOUND_PCM:
|
||||
ASND_ChangeVolumeVoice(voice, newvol, newvol);
|
||||
break;
|
||||
|
||||
case SOUND_OGG:
|
||||
SetVolumeOgg(255*(volume/100.0));
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
}
|
236
source/ngc/gui/gui_text.cpp
Normal file
@ -0,0 +1,236 @@
|
||||
/****************************************************************************
|
||||
* Snes9x 1.51 Nintendo Wii/Gamecube Port
|
||||
*
|
||||
* Tantric February 2009
|
||||
*
|
||||
* gui_text.cpp
|
||||
*
|
||||
* GUI class definitions
|
||||
***************************************************************************/
|
||||
|
||||
#include "gui.h"
|
||||
#include "snes9xGX.h"
|
||||
#include "filelist.h"
|
||||
|
||||
static int currentSize = 0;
|
||||
static int presetSize = 0;
|
||||
static int presetMaxWidth = 0;
|
||||
static int presetAlignmentHor = 0;
|
||||
static int presetAlignmentVert = 0;
|
||||
static u16 presetStyle = 0;
|
||||
static GXColor presetColor = (GXColor){255, 255, 255, 255};
|
||||
|
||||
/**
|
||||
* Constructor for the GuiText class.
|
||||
*/
|
||||
GuiText::GuiText(const char * t, int s, GXColor c)
|
||||
{
|
||||
text = NULL;
|
||||
size = s;
|
||||
color = c;
|
||||
alpha = c.a;
|
||||
style = FTGX_JUSTIFY_CENTER | FTGX_ALIGN_MIDDLE;
|
||||
maxWidth = 0;
|
||||
|
||||
alignmentHor = ALIGN_CENTRE;
|
||||
alignmentVert = ALIGN_MIDDLE;
|
||||
|
||||
if(t)
|
||||
text = fontSystem->charToWideChar((char *)t);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for the GuiText class, uses presets
|
||||
*/
|
||||
GuiText::GuiText(const char * t)
|
||||
{
|
||||
text = NULL;
|
||||
size = presetSize;
|
||||
color = presetColor;
|
||||
alpha = presetColor.a;
|
||||
style = presetStyle;
|
||||
maxWidth = presetMaxWidth;
|
||||
|
||||
alignmentHor = presetAlignmentHor;
|
||||
alignmentVert = presetAlignmentVert;
|
||||
|
||||
if(t)
|
||||
text = fontSystem->charToWideChar((char *)t);
|
||||
}
|
||||
|
||||
/**
|
||||
* Destructor for the GuiText class.
|
||||
*/
|
||||
GuiText::~GuiText()
|
||||
{
|
||||
if(text)
|
||||
{
|
||||
delete text;
|
||||
text = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void GuiText::SetText(const char * t)
|
||||
{
|
||||
if(text)
|
||||
delete text;
|
||||
|
||||
text = NULL;
|
||||
|
||||
if(t)
|
||||
text = fontSystem->charToWideChar((char *)t);
|
||||
}
|
||||
|
||||
void GuiText::SetPresets(int sz, GXColor c, int w, u16 s, int h, int v)
|
||||
{
|
||||
presetSize = sz;
|
||||
presetColor = c;
|
||||
presetStyle = s;
|
||||
presetMaxWidth = w;
|
||||
presetAlignmentHor = h;
|
||||
presetAlignmentVert = v;
|
||||
}
|
||||
|
||||
void GuiText::SetFontSize(int s)
|
||||
{
|
||||
size = s;
|
||||
}
|
||||
|
||||
void GuiText::SetMaxWidth(int w)
|
||||
{
|
||||
maxWidth = w;
|
||||
}
|
||||
|
||||
void GuiText::SetColor(GXColor c)
|
||||
{
|
||||
color = c;
|
||||
alpha = c.a;
|
||||
}
|
||||
|
||||
void GuiText::SetStyle(u16 s)
|
||||
{
|
||||
style = s;
|
||||
}
|
||||
|
||||
void GuiText::SetAlignment(int hor, int vert)
|
||||
{
|
||||
style = 0;
|
||||
|
||||
switch(hor)
|
||||
{
|
||||
case ALIGN_LEFT:
|
||||
style |= FTGX_JUSTIFY_LEFT;
|
||||
break;
|
||||
case ALIGN_RIGHT:
|
||||
style |= FTGX_JUSTIFY_RIGHT;
|
||||
break;
|
||||
default:
|
||||
style |= FTGX_JUSTIFY_CENTER;
|
||||
break;
|
||||
}
|
||||
switch(vert)
|
||||
{
|
||||
case ALIGN_TOP:
|
||||
style |= FTGX_ALIGN_TOP;
|
||||
break;
|
||||
case ALIGN_BOTTOM:
|
||||
style |= FTGX_ALIGN_BOTTOM;
|
||||
break;
|
||||
default:
|
||||
style |= FTGX_ALIGN_MIDDLE;
|
||||
break;
|
||||
}
|
||||
|
||||
alignmentHor = hor;
|
||||
alignmentVert = vert;
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw the text on screen
|
||||
*/
|
||||
void GuiText::Draw()
|
||||
{
|
||||
if(!text)
|
||||
return;
|
||||
|
||||
if(!this->IsVisible())
|
||||
return;
|
||||
|
||||
GXColor c = color;
|
||||
c.a = this->GetAlpha();
|
||||
|
||||
int newSize = size*this->GetScale();
|
||||
|
||||
if(newSize != currentSize)
|
||||
{
|
||||
fontSystem->changeSize(newSize);
|
||||
currentSize = newSize;
|
||||
}
|
||||
|
||||
int voffset = 0;
|
||||
|
||||
if(alignmentVert == ALIGN_MIDDLE)
|
||||
voffset = -newSize/2 + 2;
|
||||
|
||||
if(maxWidth > 0) // text wrapping
|
||||
{
|
||||
int lineheight = newSize + 6;
|
||||
int strlen = wcslen(text);
|
||||
int i = 0;
|
||||
int ch = 0;
|
||||
int linenum = 0;
|
||||
int lastSpace = -1;
|
||||
int lastSpaceIndex = -1;
|
||||
wchar_t * tmptext[20];
|
||||
|
||||
while(ch < strlen)
|
||||
{
|
||||
if(i == 0)
|
||||
tmptext[linenum] = new wchar_t[strlen + 1];
|
||||
|
||||
tmptext[linenum][i] = text[ch];
|
||||
tmptext[linenum][i+1] = 0;
|
||||
|
||||
if(text[ch] == ' ' || ch == strlen-1)
|
||||
{
|
||||
if(fontSystem->getWidth(tmptext[linenum]) >= maxWidth)
|
||||
{
|
||||
if(lastSpace >= 0)
|
||||
{
|
||||
tmptext[linenum][lastSpaceIndex] = 0; // discard space, and everything after
|
||||
ch = lastSpace; // go backwards to the last space
|
||||
lastSpace = -1; // we have used this space
|
||||
lastSpaceIndex = -1;
|
||||
}
|
||||
linenum++;
|
||||
i = -1;
|
||||
}
|
||||
else if(ch == strlen-1)
|
||||
{
|
||||
linenum++;
|
||||
}
|
||||
}
|
||||
if(text[ch] == ' ' && i >= 0)
|
||||
{
|
||||
lastSpace = ch;
|
||||
lastSpaceIndex = i;
|
||||
}
|
||||
ch++;
|
||||
i++;
|
||||
}
|
||||
|
||||
if(alignmentVert == ALIGN_MIDDLE)
|
||||
voffset = voffset - (lineheight*linenum)/2 + lineheight/2;
|
||||
|
||||
for(i=0; i < linenum; i++)
|
||||
{
|
||||
fontSystem->drawText(this->GetLeft(), this->GetTop()+voffset+i*lineheight, tmptext[i], c, style);
|
||||
delete tmptext[i];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
fontSystem->drawText(this->GetLeft(), this->GetTop()+voffset, text, c, style);
|
||||
}
|
||||
this->UpdateEffects();
|
||||
}
|
238
source/ngc/gui/gui_trigger.cpp
Normal file
@ -0,0 +1,238 @@
|
||||
/****************************************************************************
|
||||
* Snes9x 1.51 Nintendo Wii/Gamecube Port
|
||||
*
|
||||
* Tantric February 2009
|
||||
*
|
||||
* gui_trigger.cpp
|
||||
*
|
||||
* GUI class definitions
|
||||
***************************************************************************/
|
||||
|
||||
#include "gui.h"
|
||||
|
||||
static int scrollDelay = 0;
|
||||
|
||||
/**
|
||||
* Constructor for the GuiTrigger class.
|
||||
*/
|
||||
GuiTrigger::GuiTrigger()
|
||||
{
|
||||
chan = -1;
|
||||
memset(&wpad, 0, sizeof(WPADData));
|
||||
memset(&pad, 0, sizeof(PADData));
|
||||
}
|
||||
|
||||
/**
|
||||
* Destructor for the GuiTrigger class.
|
||||
*/
|
||||
GuiTrigger::~GuiTrigger()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a simple trigger. Requires:
|
||||
* - Element is selected
|
||||
* - Trigger button is pressed
|
||||
*/
|
||||
void GuiTrigger::SetSimpleTrigger(s32 ch, u32 wiibtns, u16 gcbtns)
|
||||
{
|
||||
type = TRIGGER_SIMPLE;
|
||||
chan = ch;
|
||||
wpad.btns_d = wiibtns;
|
||||
pad.btns_d = gcbtns;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a button trigger. Requires:
|
||||
* - Trigger button is pressed
|
||||
*/
|
||||
void GuiTrigger::SetButtonOnlyTrigger(s32 ch, u32 wiibtns, u16 gcbtns)
|
||||
{
|
||||
type = TRIGGER_BUTTON_ONLY;
|
||||
chan = ch;
|
||||
wpad.btns_d = wiibtns;
|
||||
pad.btns_d = gcbtns;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a button trigger. Requires:
|
||||
* - Trigger button is pressed
|
||||
* - Parent window is in focus
|
||||
*/
|
||||
void GuiTrigger::SetButtonOnlyInFocusTrigger(s32 ch, u32 wiibtns, u16 gcbtns)
|
||||
{
|
||||
type = TRIGGER_BUTTON_ONLY_IN_FOCUS;
|
||||
chan = ch;
|
||||
wpad.btns_d = wiibtns;
|
||||
pad.btns_d = gcbtns;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* WPAD_Stick
|
||||
*
|
||||
* Get X/Y value from Wii Joystick (classic, nunchuk) input
|
||||
***************************************************************************/
|
||||
|
||||
s8 GuiTrigger::WPAD_Stick(u8 right, int axis)
|
||||
{
|
||||
#ifdef HW_RVL
|
||||
|
||||
float mag = 0.0;
|
||||
float ang = 0.0;
|
||||
|
||||
switch (wpad.exp.type)
|
||||
{
|
||||
case WPAD_EXP_NUNCHUK:
|
||||
case WPAD_EXP_GUITARHERO3:
|
||||
if (right == 0)
|
||||
{
|
||||
mag = wpad.exp.nunchuk.js.mag;
|
||||
ang = wpad.exp.nunchuk.js.ang;
|
||||
}
|
||||
break;
|
||||
|
||||
case WPAD_EXP_CLASSIC:
|
||||
if (right == 0)
|
||||
{
|
||||
mag = wpad.exp.classic.ljs.mag;
|
||||
ang = wpad.exp.classic.ljs.ang;
|
||||
}
|
||||
else
|
||||
{
|
||||
mag = wpad.exp.classic.rjs.mag;
|
||||
ang = wpad.exp.classic.rjs.ang;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
/* calculate x/y value (angle need to be converted into radian) */
|
||||
if (mag > 1.0) mag = 1.0;
|
||||
else if (mag < -1.0) mag = -1.0;
|
||||
double val;
|
||||
|
||||
if(axis == 0) // x-axis
|
||||
val = mag * sin((PI * ang)/180.0f);
|
||||
else // y-axis
|
||||
val = mag * cos((PI * ang)/180.0f);
|
||||
|
||||
return (s8)(val * 128.0f);
|
||||
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool GuiTrigger::Left()
|
||||
{
|
||||
u32 wiibtn = GCSettings.WiimoteOrientation ? WPAD_BUTTON_UP : WPAD_BUTTON_LEFT;
|
||||
|
||||
if((wpad.btns_d | wpad.btns_h) & (wiibtn | WPAD_CLASSIC_BUTTON_LEFT)
|
||||
|| (pad.btns_d | pad.btns_h) & PAD_BUTTON_LEFT
|
||||
|| pad.stickX < -PADCAL
|
||||
|| WPAD_Stick(0,0) < -PADCAL)
|
||||
{
|
||||
if(wpad.btns_d & (wiibtn | WPAD_CLASSIC_BUTTON_LEFT)
|
||||
|| pad.btns_d & PAD_BUTTON_LEFT)
|
||||
{
|
||||
scrollDelay = SCROLL_INITIAL_DELAY; // reset scroll delay.
|
||||
return true;
|
||||
}
|
||||
else if(scrollDelay == 0)
|
||||
{
|
||||
scrollDelay = SCROLL_LOOP_DELAY;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
scrollDelay--;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool GuiTrigger::Right()
|
||||
{
|
||||
u32 wiibtn = GCSettings.WiimoteOrientation ? WPAD_BUTTON_DOWN : WPAD_BUTTON_RIGHT;
|
||||
|
||||
if((wpad.btns_d | wpad.btns_h) & (wiibtn | WPAD_CLASSIC_BUTTON_RIGHT)
|
||||
|| (pad.btns_d | pad.btns_h) & PAD_BUTTON_RIGHT
|
||||
|| pad.stickX > PADCAL
|
||||
|| WPAD_Stick(0,0) > PADCAL)
|
||||
{
|
||||
if(wpad.btns_d & (wiibtn | WPAD_CLASSIC_BUTTON_RIGHT)
|
||||
|| pad.btns_d & PAD_BUTTON_RIGHT)
|
||||
{
|
||||
scrollDelay = SCROLL_INITIAL_DELAY; // reset scroll delay.
|
||||
return true;
|
||||
}
|
||||
else if(scrollDelay == 0)
|
||||
{
|
||||
scrollDelay = SCROLL_LOOP_DELAY;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
scrollDelay--;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool GuiTrigger::Up()
|
||||
{
|
||||
u32 wiibtn = GCSettings.WiimoteOrientation ? WPAD_BUTTON_RIGHT : WPAD_BUTTON_UP;
|
||||
|
||||
if((wpad.btns_d | wpad.btns_h) & (wiibtn | WPAD_CLASSIC_BUTTON_UP)
|
||||
|| (pad.btns_d | pad.btns_h) & PAD_BUTTON_UP
|
||||
|| pad.stickY > PADCAL
|
||||
|| WPAD_Stick(0,1) > PADCAL)
|
||||
{
|
||||
if(wpad.btns_d & (wiibtn | WPAD_CLASSIC_BUTTON_UP)
|
||||
|| pad.btns_d & PAD_BUTTON_UP)
|
||||
{
|
||||
scrollDelay = SCROLL_INITIAL_DELAY; // reset scroll delay.
|
||||
return true;
|
||||
}
|
||||
else if(scrollDelay == 0)
|
||||
{
|
||||
scrollDelay = SCROLL_LOOP_DELAY;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
scrollDelay--;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool GuiTrigger::Down()
|
||||
{
|
||||
u32 wiibtn = GCSettings.WiimoteOrientation ? WPAD_BUTTON_LEFT : WPAD_BUTTON_DOWN;
|
||||
|
||||
if((wpad.btns_d | wpad.btns_h) & (wiibtn | WPAD_CLASSIC_BUTTON_DOWN)
|
||||
|| (pad.btns_d | pad.btns_h) & PAD_BUTTON_DOWN
|
||||
|| pad.stickY < -PADCAL
|
||||
|| WPAD_Stick(0,1) < -PADCAL)
|
||||
{
|
||||
if(wpad.btns_d & (wiibtn | WPAD_CLASSIC_BUTTON_DOWN)
|
||||
|| pad.btns_d & PAD_BUTTON_DOWN)
|
||||
{
|
||||
scrollDelay = SCROLL_INITIAL_DELAY; // reset scroll delay.
|
||||
return true;
|
||||
}
|
||||
else if(scrollDelay == 0)
|
||||
{
|
||||
scrollDelay = SCROLL_LOOP_DELAY;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
scrollDelay--;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
404
source/ngc/gui/gui_window.cpp
Normal file
@ -0,0 +1,404 @@
|
||||
/****************************************************************************
|
||||
* Snes9x 1.51 Nintendo Wii/Gamecube Port
|
||||
*
|
||||
* Tantric February 2009
|
||||
*
|
||||
* gui_window.cpp
|
||||
*
|
||||
* GUI class definitions
|
||||
***************************************************************************/
|
||||
|
||||
#include "gui.h"
|
||||
|
||||
GuiWindow::GuiWindow()
|
||||
{
|
||||
width = 0;
|
||||
height = 0;
|
||||
focus = 0; // allow focus
|
||||
}
|
||||
|
||||
GuiWindow::GuiWindow(int w, int h)
|
||||
{
|
||||
width = w;
|
||||
height = h;
|
||||
focus = 0; // allow focus
|
||||
}
|
||||
|
||||
GuiWindow::~GuiWindow()
|
||||
{
|
||||
}
|
||||
|
||||
void GuiWindow::Append(GuiElement* e)
|
||||
{
|
||||
if (e == NULL)
|
||||
return;
|
||||
|
||||
Remove(e);
|
||||
_elements.push_back(e);
|
||||
e->SetParent(this);
|
||||
}
|
||||
|
||||
void GuiWindow::Insert(GuiElement* e, u32 index)
|
||||
{
|
||||
if (e == NULL || index > (_elements.size() - 1))
|
||||
return;
|
||||
|
||||
Remove(e);
|
||||
_elements.insert(_elements.begin()+index, e);
|
||||
e->SetParent(this);
|
||||
}
|
||||
|
||||
void GuiWindow::Remove(GuiElement* e)
|
||||
{
|
||||
if (e == NULL)
|
||||
return;
|
||||
|
||||
for (u8 i = 0; i < _elements.size(); i++)
|
||||
{
|
||||
if(e == _elements.at(i))
|
||||
{
|
||||
_elements.erase(_elements.begin()+i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GuiWindow::RemoveAll()
|
||||
{
|
||||
_elements.clear();
|
||||
}
|
||||
|
||||
GuiElement* GuiWindow::GetGuiElementAt(u32 index) const
|
||||
{
|
||||
if (index >= _elements.size())
|
||||
return NULL;
|
||||
return _elements.at(index);
|
||||
}
|
||||
|
||||
u32 GuiWindow::GetSize()
|
||||
{
|
||||
return _elements.size();
|
||||
}
|
||||
|
||||
void GuiWindow::Draw()
|
||||
{
|
||||
if(_elements.size() == 0 || !this->IsVisible())
|
||||
return;
|
||||
|
||||
for (u8 i = 0; i < _elements.size(); i++)
|
||||
{
|
||||
try { _elements.at(i)->Draw(); }
|
||||
catch (exception& e) { }
|
||||
}
|
||||
|
||||
this->UpdateEffects();
|
||||
|
||||
if(parentElement && state == STATE_DISABLED)
|
||||
Menu_DrawRectangle(0,0,screenwidth,screenheight,(GXColor){0xbe, 0xca, 0xd5, 0x70},1);
|
||||
}
|
||||
|
||||
void GuiWindow::ResetState()
|
||||
{
|
||||
if(state != STATE_DISABLED)
|
||||
state = STATE_DEFAULT;
|
||||
|
||||
for (u8 i = 0; i < _elements.size(); i++)
|
||||
{
|
||||
try { _elements.at(i)->ResetState(); }
|
||||
catch (exception& e) { }
|
||||
}
|
||||
}
|
||||
|
||||
void GuiWindow::SetState(int s)
|
||||
{
|
||||
state = s;
|
||||
|
||||
for (u8 i = 0; i < _elements.size(); i++)
|
||||
{
|
||||
try { _elements.at(i)->SetState(s); }
|
||||
catch (exception& e) { }
|
||||
}
|
||||
}
|
||||
|
||||
void GuiWindow::SetVisible(bool v)
|
||||
{
|
||||
visible = v;
|
||||
|
||||
for (u8 i = 0; i < _elements.size(); i++)
|
||||
{
|
||||
try { _elements.at(i)->SetVisible(v); }
|
||||
catch (exception& e) { }
|
||||
}
|
||||
}
|
||||
|
||||
void GuiWindow::SetFocus(int f)
|
||||
{
|
||||
focus = f;
|
||||
|
||||
if(f == 1)
|
||||
this->MoveSelectionVert(1);
|
||||
else
|
||||
this->ResetState();
|
||||
}
|
||||
|
||||
void GuiWindow::ChangeFocus(GuiElement* e)
|
||||
{
|
||||
if(parentElement)
|
||||
return; // this is only intended for the main window
|
||||
|
||||
for (u8 i = 0; i < _elements.size(); i++)
|
||||
{
|
||||
if(e == _elements.at(i))
|
||||
_elements.at(i)->SetFocus(1);
|
||||
else if(_elements.at(i)->IsFocused() == 1)
|
||||
_elements.at(i)->SetFocus(0);
|
||||
}
|
||||
}
|
||||
|
||||
void GuiWindow::ToggleFocus(GuiTrigger * t)
|
||||
{
|
||||
if(parentElement)
|
||||
return; // this is only intended for the main window
|
||||
|
||||
int found = -1;
|
||||
int newfocus = -1;
|
||||
u8 i;
|
||||
|
||||
// look for currently in focus element
|
||||
for (i = 0; i < _elements.size(); i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
if(_elements.at(i)->IsFocused() == 1)
|
||||
{
|
||||
found = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch (exception& e) { }
|
||||
}
|
||||
|
||||
// element with focus not found, try to give focus
|
||||
if(found == -1)
|
||||
{
|
||||
for (i = 0; i < _elements.size(); i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
if(_elements.at(i)->IsFocused() == 0 && _elements.at(i)->GetState() != STATE_DISABLED) // focus is possible (but not set)
|
||||
{
|
||||
_elements.at(i)->SetFocus(1); // give this element focus
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch (exception& e) { }
|
||||
}
|
||||
}
|
||||
// change focus
|
||||
else if(t->wpad.btns_d & (WPAD_BUTTON_1 | WPAD_BUTTON_B | WPAD_CLASSIC_BUTTON_B)
|
||||
|| t->pad.btns_d & PAD_BUTTON_B)
|
||||
{
|
||||
for (i = found; i < _elements.size(); i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
if(_elements.at(i)->IsFocused() == 0 && _elements.at(i)->GetState() != STATE_DISABLED) // focus is possible (but not set)
|
||||
{
|
||||
newfocus = i;
|
||||
_elements.at(i)->SetFocus(1); // give this element focus
|
||||
_elements.at(found)->SetFocus(0); // disable focus on other element
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch (exception& e) { }
|
||||
}
|
||||
|
||||
if(newfocus == -1)
|
||||
{
|
||||
for (i = 0; i < found; i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
if(_elements.at(i)->IsFocused() == 0 && _elements.at(i)->GetState() != STATE_DISABLED) // focus is possible (but not set)
|
||||
{
|
||||
_elements.at(i)->SetFocus(1); // give this element focus
|
||||
_elements.at(found)->SetFocus(0); // disable focus on other element
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch (exception& e) { }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int GuiWindow::GetSelected()
|
||||
{
|
||||
// find selected element
|
||||
int found = -1;
|
||||
for (u8 i = 0; i < _elements.size(); i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
if(_elements.at(i)->GetState() == STATE_SELECTED)
|
||||
{
|
||||
found = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch (exception& e) { }
|
||||
}
|
||||
return found;
|
||||
}
|
||||
|
||||
// set element to left/right as selected
|
||||
// there's probably a more clever way to do this, but this way works
|
||||
void GuiWindow::MoveSelectionHor(int dir)
|
||||
{
|
||||
int found = -1;
|
||||
u16 left = 0;
|
||||
u16 top = 0;
|
||||
u8 i = 0;
|
||||
|
||||
int selected = this->GetSelected();
|
||||
|
||||
if(selected >= 0)
|
||||
{
|
||||
left = _elements.at(selected)->GetLeft();
|
||||
top = _elements.at(selected)->GetTop();
|
||||
}
|
||||
|
||||
// look for a button on the same row, to the left/right
|
||||
for (i = 0; i < _elements.size(); i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
if(_elements.at(i)->IsSelectable())
|
||||
{
|
||||
if(_elements.at(i)->GetLeft()*dir > left*dir && _elements.at(i)->GetTop() == top)
|
||||
{
|
||||
if(found == -1)
|
||||
found = i;
|
||||
else if(_elements.at(i)->GetLeft()*dir < _elements.at(found)->GetLeft()*dir)
|
||||
found = i; // this is a better match
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (exception& e) { }
|
||||
}
|
||||
if(found >= 0)
|
||||
goto matchfound;
|
||||
|
||||
// match still not found, let's try the first button in the next row
|
||||
for (i = 0; i < _elements.size(); i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
if(_elements.at(i)->IsSelectable())
|
||||
{
|
||||
if(_elements.at(i)->GetTop()*dir > top*dir)
|
||||
{
|
||||
if(found == -1)
|
||||
found = i;
|
||||
else if(_elements.at(i)->GetTop()*dir < _elements.at(found)->GetTop()*dir)
|
||||
found = i; // this is a better match
|
||||
else if(_elements.at(i)->GetTop()*dir == _elements.at(found)->GetTop()*dir
|
||||
&&
|
||||
_elements.at(i)->GetLeft()*dir < _elements.at(found)->GetLeft()*dir)
|
||||
found = i; // this is a better match
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (exception& e) { }
|
||||
}
|
||||
|
||||
// match found
|
||||
matchfound:
|
||||
if(found >= 0)
|
||||
{
|
||||
_elements.at(found)->SetState(STATE_SELECTED);
|
||||
if(selected >= 0)
|
||||
_elements.at(selected)->ResetState();
|
||||
}
|
||||
}
|
||||
|
||||
void GuiWindow::MoveSelectionVert(int dir)
|
||||
{
|
||||
int found = -1;
|
||||
u16 left = 0;
|
||||
u16 top = 0;
|
||||
u8 i = 0;
|
||||
|
||||
int selected = this->GetSelected();
|
||||
|
||||
if(selected >= 0)
|
||||
{
|
||||
left = _elements.at(selected)->GetLeft();
|
||||
top = _elements.at(selected)->GetTop();
|
||||
}
|
||||
|
||||
// look for a button above/below, with the least horizontal difference
|
||||
for (i = 0; i < _elements.size(); i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
if(_elements.at(i)->IsSelectable())
|
||||
{
|
||||
if(_elements.at(i)->GetTop()*dir > top*dir)
|
||||
{
|
||||
if(found == -1)
|
||||
found = i;
|
||||
else if(_elements.at(i)->GetTop()*dir < _elements.at(found)->GetTop()*dir)
|
||||
found = i; // this is a better match
|
||||
else if(_elements.at(i)->GetTop()*dir == _elements.at(found)->GetTop()*dir
|
||||
&&
|
||||
abs(_elements.at(i)->GetLeft() - left) <
|
||||
abs(_elements.at(found)->GetLeft() - left))
|
||||
found = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (exception& e) { }
|
||||
}
|
||||
if(found >= 0)
|
||||
goto matchfound;
|
||||
|
||||
// match found
|
||||
matchfound:
|
||||
if(found >= 0)
|
||||
{
|
||||
_elements.at(found)->SetState(STATE_SELECTED);
|
||||
if(selected >= 0)
|
||||
_elements.at(selected)->ResetState();
|
||||
}
|
||||
}
|
||||
|
||||
void GuiWindow::Update(GuiTrigger * t)
|
||||
{
|
||||
if(_elements.size() == 0 || (state == STATE_DISABLED && parentElement))
|
||||
return;
|
||||
|
||||
for (u8 i = 0; i < _elements.size(); i++)
|
||||
{
|
||||
try { _elements.at(i)->Update(t); }
|
||||
catch (exception& e) { }
|
||||
}
|
||||
|
||||
this->ToggleFocus(t);
|
||||
|
||||
if(focus) // only send actions to this window if it's in focus
|
||||
{
|
||||
// pad/joystick navigation
|
||||
if(t->Right())
|
||||
this->MoveSelectionHor(1);
|
||||
else if(t->Left())
|
||||
this->MoveSelectionHor(-1);
|
||||
else if(t->Down())
|
||||
this->MoveSelectionVert(1);
|
||||
else if(t->Up())
|
||||
this->MoveSelectionVert(-1);
|
||||
}
|
||||
|
||||
if(updateCB)
|
||||
updateCB(this);
|
||||
}
|
BIN
source/ngc/images/battery.png
Normal file
After Width: | Height: | Size: 216 B |
BIN
source/ngc/images/battery_bar.png
Normal file
After Width: | Height: | Size: 145 B |
BIN
source/ngc/images/battery_red.png
Normal file
After Width: | Height: | Size: 230 B |
BIN
source/ngc/images/bg_bottom.png
Normal file
After Width: | Height: | Size: 838 B |
BIN
source/ngc/images/bg_game_selection.png
Normal file
After Width: | Height: | Size: 1.4 KiB |
BIN
source/ngc/images/bg_game_selection_entry.png
Normal file
After Width: | Height: | Size: 279 B |
BIN
source/ngc/images/bg_options.png
Normal file
After Width: | Height: | Size: 1.6 KiB |
BIN
source/ngc/images/bg_options_entry.png
Normal file
After Width: | Height: | Size: 299 B |
BIN
source/ngc/images/bg_top.png
Normal file
After Width: | Height: | Size: 771 B |
BIN
source/ngc/images/button.png
Normal file
After Width: | Height: | Size: 1.7 KiB |
BIN
source/ngc/images/button_arrow_down.png
Normal file
After Width: | Height: | Size: 792 B |
BIN
source/ngc/images/button_arrow_down_over.png
Normal file
After Width: | Height: | Size: 764 B |
BIN
source/ngc/images/button_arrow_left.png
Normal file
After Width: | Height: | Size: 842 B |
BIN
source/ngc/images/button_arrow_left_over.png
Normal file
After Width: | Height: | Size: 776 B |
BIN
source/ngc/images/button_arrow_right.png
Normal file
After Width: | Height: | Size: 821 B |
BIN
source/ngc/images/button_arrow_right_over.png
Normal file
After Width: | Height: | Size: 775 B |
BIN
source/ngc/images/button_arrow_up.png
Normal file
After Width: | Height: | Size: 746 B |
BIN
source/ngc/images/button_arrow_up_over.png
Normal file
After Width: | Height: | Size: 710 B |
BIN
source/ngc/images/button_close.png
Normal file
After Width: | Height: | Size: 1.0 KiB |
BIN
source/ngc/images/button_close_over.png
Normal file
After Width: | Height: | Size: 1.2 KiB |
BIN
source/ngc/images/button_gamesave.png
Normal file
After Width: | Height: | Size: 549 B |
BIN
source/ngc/images/button_gamesave_blank.png
Normal file
After Width: | Height: | Size: 1.1 KiB |
BIN
source/ngc/images/button_gamesave_over.png
Normal file
After Width: | Height: | Size: 546 B |
BIN
source/ngc/images/button_large.png
Normal file
After Width: | Height: | Size: 2.9 KiB |
BIN
source/ngc/images/button_large_over.png
Normal file
After Width: | Height: | Size: 3.0 KiB |
BIN
source/ngc/images/button_over.png
Normal file
After Width: | Height: | Size: 1.7 KiB |
BIN
source/ngc/images/credits_box.png
Normal file
After Width: | Height: | Size: 2.5 KiB |
BIN
source/ngc/images/dialogue_box.png
Normal file
After Width: | Height: | Size: 1.5 KiB |
BIN
source/ngc/images/folder.png
Normal file
After Width: | Height: | Size: 1.4 KiB |
BIN
source/ngc/images/icon_home.png
Normal file
After Width: | Height: | Size: 294 B |
BIN
source/ngc/images/icon_settings.png
Normal file
After Width: | Height: | Size: 434 B |
BIN
source/ngc/images/keyboard_key.png
Normal file
After Width: | Height: | Size: 613 B |
BIN
source/ngc/images/keyboard_key_over.png
Normal file
After Width: | Height: | Size: 587 B |
BIN
source/ngc/images/keyboard_largekey.png
Normal file
After Width: | Height: | Size: 705 B |
BIN
source/ngc/images/keyboard_largekey_over.png
Normal file
After Width: | Height: | Size: 685 B |
BIN
source/ngc/images/keyboard_mediumkey.png
Normal file
After Width: | Height: | Size: 654 B |
BIN
source/ngc/images/keyboard_mediumkey_over.png
Normal file
After Width: | Height: | Size: 639 B |
BIN
source/ngc/images/keyboard_textbox.png
Normal file
After Width: | Height: | Size: 749 B |
BIN
source/ngc/images/logo.png
Normal file
After Width: | Height: | Size: 10 KiB |
BIN
source/ngc/images/logo_over.png
Normal file
After Width: | Height: | Size: 8.3 KiB |
BIN
source/ngc/images/player1_grab.png
Normal file
After Width: | Height: | Size: 2.2 KiB |
BIN
source/ngc/images/player1_point.png
Normal file
After Width: | Height: | Size: 2.3 KiB |
BIN
source/ngc/images/player2_grab.png
Normal file
After Width: | Height: | Size: 2.4 KiB |
BIN
source/ngc/images/player2_point.png
Normal file
After Width: | Height: | Size: 2.4 KiB |
BIN
source/ngc/images/player3_grab.png
Normal file
After Width: | Height: | Size: 2.4 KiB |
BIN
source/ngc/images/player3_point.png
Normal file
After Width: | Height: | Size: 2.5 KiB |
BIN
source/ngc/images/player4_grab.png
Normal file
After Width: | Height: | Size: 2.4 KiB |
BIN
source/ngc/images/player4_point.png
Normal file
After Width: | Height: | Size: 2.4 KiB |
BIN
source/ngc/images/progressbar.png
Normal file
After Width: | Height: | Size: 160 B |
BIN
source/ngc/images/progressbar_empty.png
Normal file
After Width: | Height: | Size: 279 B |
BIN
source/ngc/images/progressbar_outline.png
Normal file
After Width: | Height: | Size: 888 B |
BIN
source/ngc/images/screen_position.png
Normal file
After Width: | Height: | Size: 1.3 KiB |
BIN
source/ngc/images/scrollbar.png
Normal file
After Width: | Height: | Size: 270 B |
BIN
source/ngc/images/scrollbar_arrowdown.png
Normal file
After Width: | Height: | Size: 721 B |
BIN
source/ngc/images/scrollbar_arrowdown_over.png
Normal file
After Width: | Height: | Size: 733 B |
BIN
source/ngc/images/scrollbar_arrowup.png
Normal file
After Width: | Height: | Size: 700 B |
BIN
source/ngc/images/scrollbar_arrowup_over.png
Normal file
After Width: | Height: | Size: 739 B |
BIN
source/ngc/images/scrollbar_box.png
Normal file
After Width: | Height: | Size: 481 B |
BIN
source/ngc/images/scrollbar_box_over.png
Normal file
After Width: | Height: | Size: 469 B |
BIN
source/ngc/images/throbber.png
Normal file
After Width: | Height: | Size: 2.5 KiB |