finalize 1.0

This commit is contained in:
dborth 2009-10-09 23:13:17 +00:00
parent f0f4e75fe3
commit 676a53462f
60 changed files with 8533 additions and 7 deletions

View File

@ -20,7 +20,9 @@ TARGETDIR := executables
BUILD := build_wii BUILD := build_wii
SOURCES := src src/cpu src/debug src/dos src/fpu src/gui \ SOURCES := src src/cpu src/debug src/dos src/fpu src/gui \
src/hardware src/hardware/serialport src/ints src/libs \ src/hardware src/hardware/serialport src/ints src/libs \
src/misc src/platform/wii src/shell src/misc src/platform/wii src/platform/wii/fonts \
src/platform/wii/images src/platform/wii/libwiigui \
src/platform/wii/sounds src/shell
INCLUDES := include src/platform/wii INCLUDES := include src/platform/wii
#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------
@ -35,13 +37,14 @@ LDFLAGS = -g $(MACHDEP) -Wl,-Map,$(notdir $@).map -Wl,--cref
#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------
# any extra libraries we wish to link with # any extra libraries we wish to link with
#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------
LIBS := -lSDL -lfat -lwiiuse -lbte -logc -lwiikeyboard LIBS := -lSDL -lfat -lwiiuse -lbte -lasnd -logc -lwiikeyboard \
-lpng -lvorbisidec -lfreetype -lz
#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------
# list of directories containing libraries, this must be the top level containing # list of directories containing libraries, this must be the top level containing
# include and lib # include and lib
#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------
LIBDIRS := $(CURDIR) LIBDIRS := $(PORTLIBS)
#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------
# no real need to edit anything past this point unless you need to add additional # no real need to edit anything past this point unless you need to add additional
@ -64,6 +67,10 @@ CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
sFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) sFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.S))) SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.S)))
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 # use CXX for linking C++ projects, CC for standard C
@ -75,7 +82,9 @@ else
endif endif
export OFILES := $(addsuffix .o,$(BINFILES)) \ export OFILES := $(addsuffix .o,$(BINFILES)) \
$(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) \
$(TTFFILES:.ttf=.ttf.o) $(PNGFILES:.png=.png.o) \
$(OGGFILES:.ogg=.ogg.o) $(PCMFILES:.pcm=.pcm.o)
#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------
# build a list of include paths # build a list of include paths
@ -83,7 +92,7 @@ export OFILES := $(addsuffix .o,$(BINFILES)) \
export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \ export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
$(foreach dir,$(LIBDIRS),-I$(dir)/include) \ $(foreach dir,$(LIBDIRS),-I$(dir)/include) \
-I$(CURDIR)/$(BUILD) \ -I$(CURDIR)/$(BUILD) \
-I$(LIBOGC_INC) -I$(LIBOGC_INC)/SDL -I$(LIBOGC_INC) -I$(LIBOGC_INC)/SDL -I$(PORTLIBS)/include/freetype2
#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------
# build a list of library paths # build a list of library paths
@ -124,6 +133,25 @@ DEPENDS := $(OFILES:.o=.d)
$(OUTPUT).dol: $(OUTPUT).elf $(OUTPUT).dol: $(OUTPUT).elf
$(OUTPUT).elf: $(OFILES) $(OUTPUT).elf: $(OFILES)
#---------------------------------------------------------------------------------
# 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)
-include $(DEPENDS) -include $(DEPENDS)
#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------

71
README
View File

@ -1,3 +1,74 @@
¸,ø¤°`°¤ø,¸¸,ø¤°`°¤ø,¸,ø¤°`°¤ø,¸¸,ø¤°`°¤ø,¸,ø¤°`°¤ø,¸¸,ø¤°`°¤ø,¸,ø¤°`°¤ø,¸¸,ø¤
- DOSBox Wii -
Version 1.0
http://code.google.com/p/dosbox-wii
(Under GPL License)
¸,ø¤°`°¤ø,¸¸,ø¤°`°¤ø,¸,ø¤°`°¤ø,¸¸,ø¤°`°¤ø,¸,ø¤°`°¤ø,¸¸,ø¤°`°¤ø,¸,ø¤°`°¤ø,¸¸,ø¤
A port of DOSBox to the Wii using SDL Wii.
-=[ Features ]=-
* USB Keyboard and mouse support
* Wiimote pointer support
* SD/USB mounting
* Most DOS games are playable
-=[ Update History ]=-
[1.0 - October 9, 2009]
* Home menu and on-screen keyboard (a proof of concept showing SDL + libwiigui)
* Small speed increases via SDL Wii improvements
* Compiled with devkitPPC r18 and libogc 1.8.0
* Updated to latest DOSBox SVN
[0.73.02 - July 1, 2009]
* Upgraded DOSBox engine to latest SVN
* Fixed lockup when only using the Wiimote (no attachments connected)
* Compiled with latest libogc and SDL Wii
[0.73.01 - June 3, 2009]
* Upgraded DOSBox engine to 0.73
* Sound issues fixed
* Compiled with latest libogc and SDL Wii
[0.72.01 - May 14, 2009]
* Initial release
-=[ Instructions ]=-
You need a Wii Remote and a USB keyboard. The C: drive will automatically be
mounted to sd:/DOSBox/ if loaded from apps/dosbox-wii/. Otherwise, the
directory the dol is loaded from will be mounted as C, and sd:/DOSBox as D
(if present). The Z: driver is a virtual drive that is part of DOSBox.
Other drives can be mounted using the MOUNT command. Prefix sd: for an SD card,
and usb: for a USB drive. The Wii's DVD drive and network folders can't be
mounted at this time.
The configuration file is loaded from the directory the dol is located in
(if present) and sd:/DOSBox/dosbox.conf otherwise. This file will be created
automatically after you start DOSBox. Please edit it with a text editor
to choose settings appropriate for each game.
Press the Home button, type "exit", press Ctrl+F9, or press Reset (on the
console) to exit.
-=[ Compatibility ]=-
Most games work properly now; however, many games will require some sort
of adjustment to the dosbox.conf file. It is recommended to try the game
you want to play on the PC version of DOSBox first to discover the optimum
settings.
-------------------------------------------------------------------------------
DOSBox v0.73 DOSBox v0.73

View File

@ -1330,7 +1330,7 @@ void GFX_Events() {
{ {
btns = WPAD_ButtonsHeld(i); btns = WPAD_ButtonsHeld(i);
if((btns & WPAD_BUTTON_HOME) || (btns & WPAD_CLASSIC_BUTTON_HOME)) if((btns & WPAD_BUTTON_HOME) || (btns & WPAD_CLASSIC_BUTTON_HOME))
throw(0); WiiMenu ();
} }
#endif #endif

View File

@ -0,0 +1,718 @@
/*
* FreeTypeGX is a wrapper class for libFreeType which renders a compiled
* FreeType parsable font into a GX texture for Wii homebrew development.
* Copyright (C) 2008 Armin Tamzarian
* Modified by Tantric, 2009
*
* This file is part of FreeTypeGX.
*
* FreeTypeGX is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* FreeTypeGX is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with FreeTypeGX. If not, see <http://www.gnu.org/licenses/>.
*/
#include "FreeTypeGX.h"
static FT_Library ftLibrary; /**< FreeType FT_Library instance. */
static FT_Face ftFace; /**< FreeType reusable FT_Face typographic object. */
static FT_GlyphSlot ftSlot; /**< FreeType reusable FT_GlyphSlot glyph container object. */
FreeTypeGX *fontSystem[MAX_FONT_SIZE+1];
void InitFreeType(uint8_t* fontBuffer, FT_Long bufferSize)
{
FT_Init_FreeType(&ftLibrary);
FT_New_Memory_Face(ftLibrary, (FT_Byte *)fontBuffer, bufferSize, 0, &ftFace);
ftSlot = ftFace->glyph;
for(int i=0; i<50; i++)
fontSystem[i] = NULL;
}
void ChangeFontSize(FT_UInt pixelSize)
{
FT_Set_Pixel_Sizes(ftFace, 0, pixelSize);
}
void ClearFontData()
{
for(int i=0; i<50; i++)
{
if(fontSystem[i])
delete fontSystem[i];
fontSystem[i] = NULL;
}
}
/**
* Convert a short char sctring to a wide char string.
*
* This routine converts a supplied shot character string into a wide character string.
* Note that it is the user's responsibility to clear the returned buffer once it is no longer needed.
*
* @param strChar Character string to be converted.
* @return Wide character representation of supplied character string.
*/
wchar_t* charToWideChar(const char* strChar)
{
wchar_t *strWChar;
strWChar = new wchar_t[strlen(strChar) + 1];
char *tempSrc = (char *)strChar;
wchar_t *tempDest = strWChar;
while((*tempDest++ = *tempSrc++));
return strWChar;
}
/**
* Default constructor for the FreeTypeGX class.
*
* @param textureFormat Optional format (GX_TF_*) of the texture as defined by the libogc gx.h header file. If not specified default value is GX_TF_RGBA8.
* @param vertexIndex Optional vertex format index (GX_VTXFMT*) of the glyph textures as defined by the libogc gx.h header file. If not specified default value is GX_VTXFMT1.
*/
FreeTypeGX::FreeTypeGX(FT_UInt pixelSize, uint8_t textureFormat, uint8_t vertexIndex)
{
this->textureFormat = textureFormat;
this->setVertexFormat(vertexIndex);
this->setCompatibilityMode(FTGX_COMPATIBILITY_DEFAULT_TEVOP_GX_PASSCLR | FTGX_COMPATIBILITY_DEFAULT_VTXDESC_GX_NONE);
this->ftPointSize = pixelSize;
this->ftKerningEnabled = FT_HAS_KERNING(ftFace);
}
/**
* Default destructor for the FreeTypeGX class.
*/
FreeTypeGX::~FreeTypeGX()
{
this->unloadFont();
}
/**
* Setup the vertex attribute formats for the glyph textures.
*
* This function sets up the vertex format for the glyph texture on the specified vertex format index.
* Note that this function should not need to be called except if the vertex formats are cleared or the specified
* vertex format index is modified.
*
* @param vertexIndex Vertex format index (GX_VTXFMT*) of the glyph textures as defined by the libogc gx.h header file.
*/
void FreeTypeGX::setVertexFormat(uint8_t vertexIndex)
{
this->vertexIndex = vertexIndex;
GX_SetVtxAttrFmt(this->vertexIndex, GX_VA_POS, GX_POS_XY, GX_S16, 0);
GX_SetVtxAttrFmt(this->vertexIndex, GX_VA_TEX0, GX_TEX_ST, GX_F32, 0);
GX_SetVtxAttrFmt(this->vertexIndex, GX_VA_CLR0, GX_CLR_RGBA, GX_RGBA8, 0);
}
/**
* Sets the TEV and VTX rendering compatibility requirements for the class.
*
* This sets up the default TEV opertion and VTX descriptions rendering values for the class. This ensures that FreeTypeGX
* can remain compatible with external liraries or project code. Certain external libraries or code by design or lack of
* foresight assume that the TEV opertion and VTX descriptions values will remain constant or are always returned to a
* certain value. This will enable compatibility with those libraries and any other code which cannot or will not be changed.
*
* @param compatibilityMode Compatibility descritor (FTGX_COMPATIBILITY_*) as defined in FreeTypeGX.h
*/
void FreeTypeGX::setCompatibilityMode(uint32_t compatibilityMode)
{
this->compatibilityMode = compatibilityMode;
}
/**
* Sets the TEV operation and VTX descriptor values after texture rendering it complete.
*
* This function calls the GX_SetTevOp and GX_SetVtxDesc functions with the compatibility parameters specified
* in setCompatibilityMode.
*/
void FreeTypeGX::setDefaultMode()
{
if(this->compatibilityMode)
{
switch(this->compatibilityMode & 0x00FF)
{
case FTGX_COMPATIBILITY_DEFAULT_TEVOP_GX_MODULATE:
GX_SetTevOp(GX_TEVSTAGE0, GX_MODULATE);
break;
case FTGX_COMPATIBILITY_DEFAULT_TEVOP_GX_DECAL:
GX_SetTevOp(GX_TEVSTAGE0, GX_DECAL);
break;
case FTGX_COMPATIBILITY_DEFAULT_TEVOP_GX_BLEND:
GX_SetTevOp(GX_TEVSTAGE0, GX_BLEND);
break;
case FTGX_COMPATIBILITY_DEFAULT_TEVOP_GX_REPLACE:
GX_SetTevOp(GX_TEVSTAGE0, GX_REPLACE);
break;
case FTGX_COMPATIBILITY_DEFAULT_TEVOP_GX_PASSCLR:
GX_SetTevOp(GX_TEVSTAGE0, GX_PASSCLR);
break;
default:
break;
}
switch(this->compatibilityMode & 0xFF00)
{
case FTGX_COMPATIBILITY_DEFAULT_VTXDESC_GX_NONE:
GX_SetVtxDesc(GX_VA_TEX0, GX_NONE);
break;
case FTGX_COMPATIBILITY_DEFAULT_VTXDESC_GX_DIRECT:
GX_SetVtxDesc(GX_VA_TEX0, GX_DIRECT);
break;
case FTGX_COMPATIBILITY_DEFAULT_VTXDESC_GX_INDEX8:
GX_SetVtxDesc(GX_VA_TEX0, GX_INDEX8);
break;
case FTGX_COMPATIBILITY_DEFAULT_VTXDESC_GX_INDEX16:
GX_SetVtxDesc(GX_VA_TEX0, GX_INDEX16);
break;
default:
break;
}
}
}
/**
* Clears all loaded font glyph data.
*
* This routine clears all members of the font map structure and frees all allocated memory back to the system.
*/
void FreeTypeGX::unloadFont()
{
if(this->fontData.size() == 0)
return;
for(std::map<wchar_t, ftgxCharData>::iterator i = this->fontData.begin(); i != this->fontData.end(); i++)
free(i->second.glyphDataTexture);
this->fontData.clear();
}
/**
* Adjusts the texture data buffer to necessary width for a given texture format.
*
* This routine determines adjusts the given texture width into the required width to hold the necessary texture data for proper alignment.
*
* @param textureWidth The initial guess for the texture width.
* @param textureFormat The texture format to which the data is to be converted.
* @return The correctly adjusted texture width.
*/
uint16_t FreeTypeGX::adjustTextureWidth(uint16_t textureWidth, uint8_t textureFormat)
{
uint16_t alignment;
switch(textureFormat)
{
case GX_TF_I4: /* 8x8 Tiles - 4-bit Intensity */
case GX_TF_I8: /* 8x4 Tiles - 8-bit Intensity */
case GX_TF_IA4: /* 8x4 Tiles - 4-bit Intensity, , 4-bit Alpha */
alignment = 8;
break;
case GX_TF_IA8: /* 4x4 Tiles - 8-bit Intensity, 8-bit Alpha */
case GX_TF_RGB565: /* 4x4 Tiles - RGB565 Format */
case GX_TF_RGB5A3: /* 4x4 Tiles - RGB5A3 Format */
case GX_TF_RGBA8: /* 4x4 Tiles - RGBA8 Dual Cache Line Format */
default:
alignment = 4;
break;
}
return textureWidth % alignment == 0 ? textureWidth : alignment + textureWidth - (textureWidth % alignment);
}
/**
* Adjusts the texture data buffer to necessary height for a given texture format.
*
* This routine determines adjusts the given texture height into the required height to hold the necessary texture data for proper alignment.
*
* @param textureHeight The initial guess for the texture height.
* @param textureFormat The texture format to which the data is to be converted.
* @return The correctly adjusted texture height.
*/
uint16_t FreeTypeGX::adjustTextureHeight(uint16_t textureHeight, uint8_t textureFormat)
{
uint16_t alignment;
switch(textureFormat)
{
case GX_TF_I4: /* 8x8 Tiles - 4-bit Intensity */
alignment = 8;
break;
case GX_TF_I8: /* 8x4 Tiles - 8-bit Intensity */
case GX_TF_IA4: /* 8x4 Tiles - 4-bit Intensity, , 4-bit Alpha */
case GX_TF_IA8: /* 4x4 Tiles - 8-bit Intensity, 8-bit Alpha */
case GX_TF_RGB565: /* 4x4 Tiles - RGB565 Format */
case GX_TF_RGB5A3: /* 4x4 Tiles - RGB5A3 Format */
case GX_TF_RGBA8: /* 4x4 Tiles - RGBA8 Dual Cache Line Format */
default:
alignment = 4;
break;
}
return textureHeight % alignment == 0 ? textureHeight : alignment + textureHeight - (textureHeight % alignment);
}
/**
* Caches the given font glyph in the instance font texture buffer.
*
* This routine renders and stores the requested glyph's bitmap and relevant information into its own quickly addressible
* structure within an instance-specific map.
*
* @param charCode The requested glyph's character code.
* @return A pointer to the allocated font structure.
*/
ftgxCharData *FreeTypeGX::cacheGlyphData(wchar_t charCode)
{
FT_UInt gIndex;
uint16_t textureWidth = 0, textureHeight = 0;
gIndex = FT_Get_Char_Index( ftFace, charCode );
if (!FT_Load_Glyph(ftFace, gIndex, FT_LOAD_DEFAULT )) {
FT_Render_Glyph( ftSlot, FT_RENDER_MODE_NORMAL );
if(ftSlot->format == FT_GLYPH_FORMAT_BITMAP) {
FT_Bitmap *glyphBitmap = &ftSlot->bitmap;
textureWidth = adjustTextureWidth(glyphBitmap->width, this->textureFormat);
textureHeight = adjustTextureHeight(glyphBitmap->rows, this->textureFormat);
this->fontData[charCode] = (ftgxCharData){
ftSlot->bitmap_left,
ftSlot->advance.x >> 6,
gIndex,
textureWidth,
textureHeight,
ftSlot->bitmap_top,
ftSlot->bitmap_top,
glyphBitmap->rows - ftSlot->bitmap_top,
NULL
};
this->loadGlyphData(glyphBitmap, &this->fontData[charCode]);
return &this->fontData[charCode];
}
}
return NULL;
}
/**
* Locates each character in this wrapper's configured font face and proccess them.
*
* This routine locates each character in the configured font face and renders the glyph's bitmap.
* Each bitmap and relevant information is loaded into its own quickly addressible structure within an instance-specific map.
*/
uint16_t FreeTypeGX::cacheGlyphDataComplete()
{
uint16_t i = 0;
FT_UInt gIndex;
FT_ULong charCode = FT_Get_First_Char( ftFace, &gIndex );
while ( gIndex != 0 )
{
if(this->cacheGlyphData(charCode) != NULL)
i++;
charCode = FT_Get_Next_Char( ftFace, charCode, &gIndex );
}
return i;
}
/**
* Loads the rendered bitmap into the relevant structure's data buffer.
*
* This routine does a simple byte-wise copy of the glyph's rendered 8-bit grayscale bitmap into the structure's buffer.
* Each byte is converted from the bitmap's intensity value into the a uint32_t RGBA value.
*
* @param bmp A pointer to the most recently rendered glyph's bitmap.
* @param charData A pointer to an allocated ftgxCharData structure whose data represent that of the last rendered glyph.
*/
void FreeTypeGX::loadGlyphData(FT_Bitmap *bmp, ftgxCharData *charData)
{
uint32_t *glyphData = (uint32_t *)memalign(32, charData->textureWidth * charData->textureHeight * 4);
memset(glyphData, 0x00, charData->textureWidth * charData->textureHeight * 4);
for (uint16_t imagePosY = 0; imagePosY < bmp->rows; imagePosY++)
{
for (uint16_t imagePosX = 0; imagePosX < bmp->width; imagePosX++)
{
uint32_t pixel = (uint32_t) bmp->buffer[imagePosY * bmp->width + imagePosX];
glyphData[imagePosY * charData->textureWidth + imagePosX] = 0x00000000 | (pixel << 24) | (pixel << 16) | (pixel << 8) | pixel;
}
}
switch(this->textureFormat)
{
case GX_TF_I4:
charData->glyphDataTexture = Metaphrasis::convertBufferToI4(glyphData, charData->textureWidth, charData->textureHeight);
break;
case GX_TF_I8:
charData->glyphDataTexture = Metaphrasis::convertBufferToI8(glyphData, charData->textureWidth, charData->textureHeight);
break;
case GX_TF_IA4:
charData->glyphDataTexture = Metaphrasis::convertBufferToIA4(glyphData, charData->textureWidth, charData->textureHeight);
break;
case GX_TF_IA8:
charData->glyphDataTexture = Metaphrasis::convertBufferToIA8(glyphData, charData->textureWidth, charData->textureHeight);
break;
case GX_TF_RGB565:
charData->glyphDataTexture = Metaphrasis::convertBufferToRGB565(glyphData, charData->textureWidth, charData->textureHeight);
break;
case GX_TF_RGB5A3:
charData->glyphDataTexture = Metaphrasis::convertBufferToRGB5A3(glyphData, charData->textureWidth, charData->textureHeight);
break;
case GX_TF_RGBA8:
default:
charData->glyphDataTexture = Metaphrasis::convertBufferToRGBA8(glyphData, charData->textureWidth, charData->textureHeight);
break;
}
free(glyphData);
}
/**
* Determines the x offset of the rendered string.
*
* This routine calculates the x offset of the rendered string based off of a supplied positional format parameter.
*
* @param width Current pixel width of the string.
* @param format Positional format of the string.
*/
int16_t FreeTypeGX::getStyleOffsetWidth(uint16_t width, uint16_t format)
{
if (format & FTGX_JUSTIFY_LEFT)
return 0;
else if (format & FTGX_JUSTIFY_CENTER)
return -(width >> 1);
else if (format & FTGX_JUSTIFY_RIGHT)
return -width;
return 0;
}
/**
* Determines the y offset of the rendered string.
*
* This routine calculates the y offset of the rendered string based off of a supplied positional format parameter.
*
* @param offset Current pixel offset data of the string.
* @param format Positional format of the string.
*/
int16_t FreeTypeGX::getStyleOffsetHeight(ftgxDataOffset *offset, uint16_t format)
{
switch(format & FTGX_ALIGN_MASK)
{
case FTGX_ALIGN_TOP:
return offset->ascender;
default:
case FTGX_ALIGN_MIDDLE:
return (offset->ascender + offset->descender + 1) >> 1;
case FTGX_ALIGN_BOTTOM:
return offset->descender;
case FTGX_ALIGN_BASELINE:
return 0;
case FTGX_ALIGN_GLYPH_TOP:
return offset->max;
case FTGX_ALIGN_GLYPH_MIDDLE:
return (offset->max + offset->min + 1) >> 1;
case FTGX_ALIGN_GLYPH_BOTTOM:
return offset->min;
}
return 0;
}
/**
* Processes the supplied text string and prints the results at the specified coordinates.
*
* This routine processes each character of the supplied text string, loads the relevant preprocessed bitmap buffer,
* a texture from said buffer, and loads the resultant texture into the EFB.
*
* @param x Screen X coordinate at which to output the text.
* @param y Screen Y coordinate at which to output the text. Note that this value corresponds to the text string origin and not the top or bottom of the glyphs.
* @param text NULL terminated string to output.
* @param color Optional color to apply to the text characters. If not specified default value is ftgxWhite: (GXColor){0xff, 0xff, 0xff, 0xff}
* @param textStyle Flags which specify any styling which should be applied to the rendered string.
* @return The number of characters printed.
*/
uint16_t FreeTypeGX::drawText(int16_t x, int16_t y, wchar_t *text, GXColor color, uint16_t textStyle)
{
uint16_t strLength = wcslen(text);
uint16_t x_pos = x, printed = 0;
uint16_t x_offset = 0, y_offset = 0;
GXTexObj glyphTexture;
FT_Vector pairDelta;
ftgxDataOffset offset;
if(textStyle & FTGX_JUSTIFY_MASK)
{
x_offset = this->getStyleOffsetWidth(this->getWidth(text), textStyle);
}
if(textStyle & FTGX_ALIGN_MASK)
{
this->getOffset(text, &offset);
y_offset = this->getStyleOffsetHeight(&offset, textStyle);
}
for (uint16_t i = 0; i < strLength; i++)
{
ftgxCharData* glyphData = NULL;
if( this->fontData.find(text[i]) != this->fontData.end() )
{
glyphData = &this->fontData[text[i]];
}
else
{
glyphData = this->cacheGlyphData(text[i]);
}
if(glyphData != NULL)
{
if(this->ftKerningEnabled && i)
{
FT_Get_Kerning( ftFace, this->fontData[text[i - 1]].glyphIndex, glyphData->glyphIndex, FT_KERNING_DEFAULT, &pairDelta );
x_pos += pairDelta.x >> 6;
}
GX_InitTexObj(&glyphTexture, glyphData->glyphDataTexture, glyphData->textureWidth, glyphData->textureHeight, this->textureFormat, GX_CLAMP, GX_CLAMP, GX_FALSE);
this->copyTextureToFramebuffer(&glyphTexture, glyphData->textureWidth, glyphData->textureHeight, x_pos + glyphData->renderOffsetX + x_offset, y - glyphData->renderOffsetY + y_offset, color);
x_pos += glyphData->glyphAdvanceX;
printed++;
}
}
if(textStyle & FTGX_STYLE_MASK)
{
this->getOffset(text, &offset);
this->drawTextFeature(x + x_offset, y + y_offset, this->getWidth(text), &offset, textStyle, color);
}
return printed;
}
/**
* \overload
*/
uint16_t FreeTypeGX::drawText(int16_t x, int16_t y, wchar_t const *text, GXColor color, uint16_t textStyle)
{
return this->drawText(x, y, (wchar_t *)text, color, textStyle);
}
void FreeTypeGX::drawTextFeature(int16_t x, int16_t y, uint16_t width, ftgxDataOffset *offsetData, uint16_t format, GXColor color)
{
uint16_t featureHeight = this->ftPointSize >> 4 > 0 ? this->ftPointSize >> 4 : 1;
if (format & FTGX_STYLE_UNDERLINE)
this->copyFeatureToFramebuffer(width, featureHeight, x, y + 1, color);
if (format & FTGX_STYLE_STRIKE)
this->copyFeatureToFramebuffer(width, featureHeight, x, y - ((offsetData->max) >> 1), color);
}
/**
* Processes the supplied string and return the width of the string in pixels.
*
* This routine processes each character of the supplied text string and calculates the width of the entire string.
* Note that if precaching of the entire font set is not enabled any uncached glyph will be cached after the call to this function.
*
* @param text NULL terminated string to calculate.
* @return The width of the text string in pixels.
*/
uint16_t FreeTypeGX::getWidth(wchar_t *text)
{
uint16_t strLength = wcslen(text);
uint16_t strWidth = 0;
FT_Vector pairDelta;
for (uint16_t i = 0; i < strLength; i++)
{
ftgxCharData* glyphData = NULL;
if( this->fontData.find(text[i]) != this->fontData.end() )
{
glyphData = &this->fontData[text[i]];
}
else
{
glyphData = this->cacheGlyphData(text[i]);
}
if(glyphData != NULL)
{
if(this->ftKerningEnabled && (i > 0))
{
FT_Get_Kerning( ftFace, this->fontData[text[i - 1]].glyphIndex, glyphData->glyphIndex, FT_KERNING_DEFAULT, &pairDelta );
strWidth += pairDelta.x >> 6;
}
strWidth += glyphData->glyphAdvanceX;
}
}
return strWidth;
}
/**
*
* \overload
*/
uint16_t FreeTypeGX::getWidth(wchar_t const *text)
{
return this->getWidth((wchar_t *)text);
}
/**
* Processes the supplied string and return the height of the string in pixels.
*
* This routine processes each character of the supplied text string and calculates the height of the entire string.
* Note that if precaching of the entire font set is not enabled any uncached glyph will be cached after the call to this function.
*
* @param text NULL terminated string to calculate.
* @return The height of the text string in pixels.
*/
uint16_t FreeTypeGX::getHeight(wchar_t *text)
{
ftgxDataOffset offset;
this->getOffset(text, &offset);
return offset.max - offset.min;
}
/**
*
* \overload
*/
uint16_t FreeTypeGX::getHeight(wchar_t const *text)
{
return this->getHeight((wchar_t *)text);
}
/**
* Get the maximum offset above and minimum offset below the font origin line.
*
* This function calculates the maximum pixel height above the font origin line and the minimum
* pixel height below the font origin line and returns the values in an addressible structure.
*
* @param text NULL terminated string to calculate.
* @param offset returns the max and min values above and below the font origin line
*
*/
void FreeTypeGX::getOffset(wchar_t *text, ftgxDataOffset* offset)
{
uint16_t strLength = wcslen(text);
int16_t strMax = 0, strMin = 9999;
for (uint16_t i = 0; i < strLength; i++)
{
ftgxCharData* glyphData = NULL;
if( this->fontData.find(text[i]) != this->fontData.end() )
{
glyphData = &this->fontData[text[i]];
}
else
{
glyphData = this->cacheGlyphData(text[i]);
}
if(glyphData != NULL)
{
strMax = glyphData->renderOffsetMax > strMax ? glyphData->renderOffsetMax : strMax;
strMin = glyphData->renderOffsetMin < strMin ? glyphData->renderOffsetMin : strMin;
}
}
offset->ascender = ftFace->size->metrics.ascender>>6;
offset->descender = ftFace->size->metrics.descender>>6;
offset->max = strMax;
offset->min = strMin;
}
/**
*
* \overload
*/
void FreeTypeGX::getOffset(wchar_t const *text, ftgxDataOffset* offset)
{
this->getOffset(text, offset);
}
/**
* Copies the supplied texture quad to the EFB.
*
* This routine uses the in-built GX quad builder functions to define the texture bounds and location on the EFB target.
*
* @param texObj A pointer to the glyph's initialized texture object.
* @param texWidth The pixel width of the texture object.
* @param texHeight The pixel height of the texture object.
* @param screenX The screen X coordinate at which to output the rendered texture.
* @param screenY The screen Y coordinate at which to output the rendered texture.
* @param color Color to apply to the texture.
*/
void FreeTypeGX::copyTextureToFramebuffer(GXTexObj *texObj, f32 texWidth, f32 texHeight, int16_t screenX, int16_t screenY, GXColor color)
{
GX_LoadTexObj(texObj, GX_TEXMAP0);
GX_InvalidateTexAll();
GX_SetTevOp (GX_TEVSTAGE0, GX_MODULATE);
GX_SetVtxDesc (GX_VA_TEX0, GX_DIRECT);
GX_Begin(GX_QUADS, this->vertexIndex, 4);
GX_Position2s16(screenX, screenY);
GX_Color4u8(color.r, color.g, color.b, color.a);
GX_TexCoord2f32(0.0f, 0.0f);
GX_Position2s16(texWidth + screenX, screenY);
GX_Color4u8(color.r, color.g, color.b, color.a);
GX_TexCoord2f32(1.0f, 0.0f);
GX_Position2s16(texWidth + screenX, texHeight + screenY);
GX_Color4u8(color.r, color.g, color.b, color.a);
GX_TexCoord2f32(1.0f, 1.0f);
GX_Position2s16(screenX, texHeight + screenY);
GX_Color4u8(color.r, color.g, color.b, color.a);
GX_TexCoord2f32(0.0f, 1.0f);
GX_End();
GX_DrawDone();
this->setDefaultMode();
}
/**
* Creates a feature quad to the EFB.
*
* This function creates a simple quad for displaying underline or strikeout text styling.
*
* @param featureWidth The pixel width of the quad.
* @param featureHeight The pixel height of the quad.
* @param screenX The screen X coordinate at which to output the quad.
* @param screenY The screen Y coordinate at which to output the quad.
* @param color Color to apply to the texture.
*/
void FreeTypeGX::copyFeatureToFramebuffer(f32 featureWidth, f32 featureHeight, int16_t screenX, int16_t screenY, GXColor color)
{
GX_SetTevOp (GX_TEVSTAGE0, GX_PASSCLR);
GX_SetVtxDesc (GX_VA_TEX0, GX_NONE);
GX_Begin(GX_QUADS, this->vertexIndex, 4);
GX_Position2s16(screenX, screenY);
GX_Color4u8(color.r, color.g, color.b, color.a);
GX_Position2s16(featureWidth + screenX, screenY);
GX_Color4u8(color.r, color.g, color.b, color.a);
GX_Position2s16(featureWidth + screenX, featureHeight + screenY);
GX_Color4u8(color.r, color.g, color.b, color.a);
GX_Position2s16(screenX, featureHeight + screenY);
GX_Color4u8(color.r, color.g, color.b, color.a);
GX_End();
GX_DrawDone();
this->setDefaultMode();
}

View File

@ -0,0 +1,298 @@
/*
* FreeTypeGX is a wrapper class for libFreeType which renders a compiled
* FreeType parsable font into a GX texture for Wii homebrew development.
* Copyright (C) 2008 Armin Tamzarian
* Modified by Tantric, 2009
*
* This file is part of FreeTypeGX.
*
* FreeTypeGX is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* FreeTypeGX is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with FreeTypeGX. If not, see <http://www.gnu.org/licenses/>.
*/
/** \mainpage FreeTypeGX
*
* \section sec_intro Introduction
*
* FreeTypeGX is a wrapper class for libFreeType which renders a compiled FreeType parsable font into a GX texture for Wii homebrew development.
* <br>
* FreeTypeGX is written in C++ and makes use of a selectable pre-buffered or buffer-on-demand methodology to allow fast and efficient printing of text to the EFB.
* <p>
* This library was developed in-full by Armin Tamzarian with the support of developers in \#wiibrew on EFnet.
*
* \section sec_installation_source Installation (Source Code)
*
* -# Ensure that you have the <a href = "http://www.tehskeen.com/forums/showthread.php?t=9404">libFreeType</a> Wii library installed in your development environment with the library added to your Makefile where appropriate.
* -# Ensure that you have the <a href = "http://code.google.com/p/metaphrasis">Metaphrasis</a> library installed in your development environment with the library added to your Makefile where appropriate.
* -# Extract the FreeTypeGX archive.
* -# Copy the contents of the <i>src</i> directory into your project's development path.
* -# Include the FreeTypeGX header file in your code using syntax such as the following:
* \code
* #include "FreeTypeGX.h"
* \endcode
*
* \section sec_installation_library Installation (Library)
*
* -# Ensure that you have the <a href = "http://www.tehskeen.com/forums/showthread.php?t=9404">libFreeType</a> Wii library installed in your development environment with the library added to your Makefile where appropriate.
* -# Ensure that you have the <a href = "http://code.google.com/p/metaphrasis">Metaphrasis</a> library installed in your development environment with the library added to your Makefile where appropriate.
* -# Extract the FreeTypeGX archive.
* -# Copy the contents of the <i>lib</i> directory into your <i>devKitPro/libogc</i> directory.
* -# Include the FreeTypeGX header file in your code using syntax such as the following:
* \code
* #include "FreeTypeGX.h"
* \endcode
*
* \section sec_freetypegx_prerequisites FreeTypeGX Prerequisites
*
* Before you begin using FreeTypeGX in your project you must ensure that the desired font in compiled into your project. For this example I will assume you are building your project with a Makefile using devKitPro evironment and are attempting to include a font whose filename is rursus_compact_mono.ttf.
*
* -# Copy the font into a directory which will be processed by the project's Makefile. If you are unsure about where you should place your font just copy the it into your project's source directory.
* \n\n
* -# Modify the Makefile to convert the font into an object file:
* \code
* %.ttf.o : %.ttf
* @echo $(notdir $<)
* $(bin2o)
* \endcode
* \n
* -# Include the font object's generated header file in your source code:
* \code
* #include "rursus_compact_mono_ttf.h"
* \endcode
* This header file defines the two variables that you will need for use within your project:
* \code
* extern const u8 rursus_compact_mono_ttf[]; A pointer to the font buffer within the compiled project.
* extern const u32 rursus_compact_mono_ttf_size; The size of the font's buffer in bytes.
* \endcode
*
* \section sec_freetypegx_usage FreeTypeGX Usage
*
* -# Within the file you included the FreeTypeGX.h header create an instance object of the FreeTypeGX class:
* \code
* FreeTypeGX *freeTypeGX = new FreeTypeGX();
* \endcode
* Alternately you can specify a texture format to which you would like to render the font characters. Note that the default value for this parameter is GX_TF_RGBA8.
* \code
* FreeTypeGX *freeTypeGX = new FreeTypeGX(GX_TF_RGB565);
* \endcode
* Furthermore, you can also specify a vertex format index to avoid conflicts with concurrent libraries or other systems. Note that the default value for this parameter is GX_VTXFMT1.
* \code
* FreeTypeGX *freeTypeGX = new FreeTypeGX(GX_TF_RGB565, GX_VTXFMT1);
* \endcode
* \n
* Currently supported textures are:
* \li <i>GX_TF_I4</i>
* \li <i>GX_TF_I8</i>
* \li <i>GX_TF_IA4</i>
* \li <i>GX_TF_IA8</i>
* \li <i>GX_TF_RGB565</i>
* \li <i>GX_TF_RGB5A3</i>
* \li <i>GX_TF_RGBA8</i>
*
* \n
* -# Using the allocated FreeTypeGX instance object call the loadFont function to load the font from the compiled buffer and specify the desired point size. Note that this function can be called multiple times to load a new:
* \code
* freeTypeGX->loadFont(rursus_compact_mono_ttf, rursus_compact_mono_ttf_size, 64);
* \endcode
* Alternately you can specify a flag which will load and cache all available font glyphs immidiately. Note that on large font sets enabling this feature could take a significant amount of time.
* \code
* freeTypeGX->loadFont(rursus_compact_mono_ttf, rursus_compact_mono_ttf_size, 64, true);
* \endcode
* \n
* -# If necessary you can enable compatibility modes with concurrent libraries or systems. For more information on this feature see the documentation for setCompatibilityMode:
* \code
* freeTypeGX->setCompatibilityMode(FTGX_COMPATIBILITY_GRRLIB);
* \endcode
* -# Using the allocated FreeTypeGX instance object call the drawText function to print a string at the specified screen X and Y coordinates to the current EFB:
* \code
* freeTypeGX->drawText(10, 25, _TEXT("FreeTypeGX Rocks!"));
* \endcode
* Alternately you can specify a <i>GXColor</i> object you would like to apply to the printed characters:
* \code
* freeTypeGX->drawText(10, 25, _TEXT("FreeTypeGX Rocks!"),
* (GXColor){0xff, 0xee, 0xaa, 0xff});
* \endcode
* Furthermore you can also specify a group of styling parameters which will modify the positioning or style of the text:
* \code
* freeTypeGX->drawText(10, 25, _TEXT("FreeTypeGX Rocks!"),
* (GXColor){0xff, 0xee, 0xaa, 0xff},
* FTGX_JUSTIFY_CENTER | FTGX_ALIGN_BOTTOM | FTGX_STYLE_UNDERLINE);
* \endcode
* \n
* Currently style parameters are:
* \li <i>FTGX_JUSTIFY_LEFT</i>
* \li <i>FTGX_JUSTIFY_CENTER</i>
* \li <i>FTGX_JUSTIFY_RIGHT</i>
* \li <i>FTGX_ALIGN_TOP</i>
* \li <i>FTGX_ALIGN_MIDDLE</i>
* \li <i>FTGX_ALIGN_BOTTOM</i>
* \li <i>FTGX_STYLE_UNDERLINE</i>
* \li <i>FTGX_STYLE_STRIKE</i>
*
* \section sec_license License
*
* FreeTypeGX is distributed under the GNU Lesser General Public License.
*
* \section sec_contact Contact
*
* If you have any suggestions, questions, or comments regarding this library feel free to e-mail me at tamzarian1989 [at] gmail [dawt] com.
*/
#ifndef FREETYPEGX_H_
#define FREETYPEGX_H_
#include <gccore.h>
#include <ft2build.h>
#include FT_FREETYPE_H
#include FT_BITMAP_H
#include "Metaphrasis.h"
#include <malloc.h>
#include <string.h>
#include <wchar.h>
#include <map>
#define MAX_FONT_SIZE 100
/*! \struct ftgxCharData_
*
* Font face character glyph relevant data structure.
*/
typedef struct ftgxCharData_ {
int16_t renderOffsetX; /**< Texture X axis bearing offset. */
uint16_t glyphAdvanceX; /**< Character glyph X coordinate advance in pixels. */
uint16_t glyphIndex; /**< Charachter glyph index in the font face. */
uint16_t textureWidth; /**< Texture width in pixels/bytes. */
uint16_t textureHeight; /**< Texture glyph height in pixels/bytes. */
int16_t renderOffsetY; /**< Texture Y axis bearing offset. */
int16_t renderOffsetMax; /**< Texture Y axis bearing maximum value. */
int16_t renderOffsetMin; /**< Texture Y axis bearing minimum value. */
uint32_t* glyphDataTexture; /**< Glyph texture bitmap data buffer. */
} ftgxCharData;
/*! \struct ftgxDataOffset_
*
* Offset structure which hold both a maximum and minimum value.
*/
typedef struct ftgxDataOffset_ {
int16_t ascender; /**< Maximum data offset. */
int16_t descender; /**< Minimum data offset. */
int16_t max; /**< Maximum data offset. */
int16_t min; /**< Minimum data offset. */
} ftgxDataOffset;
typedef struct ftgxCharData_ ftgxCharData;
typedef struct ftgxDataOffset_ ftgxDataOffset;
#define _TEXT(t) L ## t /**< Unicode helper macro. */
#define FTGX_NULL 0x0000
#define FTGX_JUSTIFY_LEFT 0x0001
#define FTGX_JUSTIFY_CENTER 0x0002
#define FTGX_JUSTIFY_RIGHT 0x0004
#define FTGX_JUSTIFY_MASK 0x000f
#define FTGX_ALIGN_TOP 0x0010
#define FTGX_ALIGN_MIDDLE 0x0020
#define FTGX_ALIGN_BOTTOM 0x0040
#define FTGX_ALIGN_BASELINE 0x0080
#define FTGX_ALIGN_GLYPH_TOP 0x0100
#define FTGX_ALIGN_GLYPH_MIDDLE 0x0200
#define FTGX_ALIGN_GLYPH_BOTTOM 0x0400
#define FTGX_ALIGN_MASK 0x0ff0
#define FTGX_STYLE_UNDERLINE 0x1000
#define FTGX_STYLE_STRIKE 0x2000
#define FTGX_STYLE_MASK 0xf000
#define FTGX_COMPATIBILITY_DEFAULT_TEVOP_GX_MODULATE 0X0001
#define FTGX_COMPATIBILITY_DEFAULT_TEVOP_GX_DECAL 0X0002
#define FTGX_COMPATIBILITY_DEFAULT_TEVOP_GX_BLEND 0X0004
#define FTGX_COMPATIBILITY_DEFAULT_TEVOP_GX_REPLACE 0X0008
#define FTGX_COMPATIBILITY_DEFAULT_TEVOP_GX_PASSCLR 0X0010
#define FTGX_COMPATIBILITY_DEFAULT_VTXDESC_GX_NONE 0X0100
#define FTGX_COMPATIBILITY_DEFAULT_VTXDESC_GX_DIRECT 0X0200
#define FTGX_COMPATIBILITY_DEFAULT_VTXDESC_GX_INDEX8 0X0400
#define FTGX_COMPATIBILITY_DEFAULT_VTXDESC_GX_INDEX16 0X0800
#define FTGX_COMPATIBILITY_NONE 0x0000
#define FTGX_COMPATIBILITY_GRRLIB FTGX_COMPATIBILITY_DEFAULT_TEVOP_GX_PASSCLR | FTGX_COMPATIBILITY_DEFAULT_VTXDESC_GX_NONE
#define FTGX_COMPATIBILITY_LIBWIISPRITE FTGX_COMPATIBILITY_DEFAULT_TEVOP_GX_MODULATE | FTGX_COMPATIBILITY_DEFAULT_VTXDESC_GX_DIRECT
const GXColor ftgxWhite = (GXColor){0xff, 0xff, 0xff, 0xff}; /**< Constant color value used only to sanitize Doxygen documentation. */
void InitFreeType(uint8_t* fontBuffer, FT_Long bufferSize);
void ChangeFontSize(FT_UInt pixelSize);
wchar_t* charToWideChar(const char* p);
void ClearFontData();
/*! \class FreeTypeGX
* \brief Wrapper class for the libFreeType library with GX rendering.
* \author Armin Tamzarian
* \version 0.2.4
*
* FreeTypeGX acts as a wrapper class for the libFreeType library. It supports precaching of transformed glyph data into
* a specified texture format. Rendering of the data to the EFB is accomplished through the application of high performance
* GX texture functions resulting in high throughput of string rendering.
*/
class FreeTypeGX {
private:
FT_UInt ftPointSize; /**< Requested size of the rendered font. */
bool ftKerningEnabled; /**< Flag indicating the availability of font kerning data. */
uint8_t textureFormat; /**< Defined texture format of the target EFB. */
uint8_t vertexIndex; /**< Vertex format descriptor index. */
uint32_t compatibilityMode; /**< Compatibility mode for default tev operations and vertex descriptors. */
std::map<wchar_t, ftgxCharData> fontData; /**< Map which holds the glyph data structures for the corresponding characters. */
static uint16_t adjustTextureWidth(uint16_t textureWidth, uint8_t textureFormat);
static uint16_t adjustTextureHeight(uint16_t textureHeight, uint8_t textureFormat);
static int16_t getStyleOffsetWidth(uint16_t width, uint16_t format);
static int16_t getStyleOffsetHeight(ftgxDataOffset *offset, uint16_t format);
void unloadFont();
ftgxCharData *cacheGlyphData(wchar_t charCode);
uint16_t cacheGlyphDataComplete();
void loadGlyphData(FT_Bitmap *bmp, ftgxCharData *charData);
void setDefaultMode();
void drawTextFeature(int16_t x, int16_t y, uint16_t width, ftgxDataOffset *offsetData, uint16_t format, GXColor color);
void copyTextureToFramebuffer(GXTexObj *texObj, f32 texWidth, f32 texHeight, int16_t screenX, int16_t screenY, GXColor color);
void copyFeatureToFramebuffer(f32 featureWidth, f32 featureHeight, int16_t screenX, int16_t screenY, GXColor color);
public:
FreeTypeGX(FT_UInt pixelSize, uint8_t textureFormat = GX_TF_RGBA8, uint8_t vertexIndex = GX_VTXFMT1);
~FreeTypeGX();
void setVertexFormat(uint8_t vertexIndex);
void setCompatibilityMode(uint32_t compatibilityMode);
uint16_t drawText(int16_t x, int16_t y, wchar_t *text, GXColor color = ftgxWhite, uint16_t textStyling = FTGX_NULL);
uint16_t drawText(int16_t x, int16_t y, wchar_t const *text, GXColor color = ftgxWhite, uint16_t textStyling = FTGX_NULL);
uint16_t getWidth(wchar_t *text);
uint16_t getWidth(wchar_t const *text);
uint16_t getHeight(wchar_t *text);
uint16_t getHeight(wchar_t const *text);
void getOffset(wchar_t *text, ftgxDataOffset* offset);
void getOffset(wchar_t const *text, ftgxDataOffset* offset);
};
#endif /* FREETYPEGX_H_ */

View File

@ -0,0 +1,383 @@
/*
* Metaphrasis is a static conversion class for transforming RGBA image
* buffers into verious GX texture formats for Wii homebrew development.
* Copyright (C) 2008 Armin Tamzarian
*
* This file is part of Metaphrasis.
*
* Metaphrasis is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Metaphrasis is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Metaphrasis. If not, see <http://www.gnu.org/licenses/>.
*/
#include "Metaphrasis.h"
/**
* Default constructor for the Metaphrasis class.
*/
Metaphrasis::Metaphrasis() {
}
/**
* Default destructor for the Metaphrasis class.
*/
Metaphrasis::~Metaphrasis() {
}
/**
* Convert the specified RGBA data buffer into the I4 texture format
*
* This routine converts the RGBA data buffer into the I4 texture format and returns a pointer to the converted buffer.
*
* @param rgbaBuffer Buffer containing the temporarily rendered RGBA data.
* @param bufferWidth Pixel width of the data buffer.
* @param bufferHeight Pixel height of the data buffer.
* @return A pointer to the allocated buffer.
*/
uint32_t* Metaphrasis::convertBufferToI4(uint32_t* rgbaBuffer, uint16_t bufferWidth, uint16_t bufferHeight) {
uint32_t bufferSize = bufferWidth * bufferHeight >> 1;
uint32_t* dataBufferI4 = (uint32_t *)memalign(32, bufferSize);
memset(dataBufferI4, 0x00, bufferSize);
uint32_t *src = (uint32_t *)rgbaBuffer;
uint8_t *dst = (uint8_t *)dataBufferI4;
for(uint16_t y = 0; y < bufferHeight; y += 8) {
for(uint16_t x = 0; x < bufferWidth; x += 8) {
for(uint16_t rows = 0; rows < 8; rows++) {
*dst++ = (src[((y + rows) * bufferWidth) + (x + 0)] & 0xf0) | ((src[((y + rows) * bufferWidth) + (x + 1)] & 0xf0) >> 4);
*dst++ = (src[((y + rows) * bufferWidth) + (x + 2)] & 0xf0) | ((src[((y + rows) * bufferWidth) + (x + 3)] & 0xf0) >> 4);
*dst++ = (src[((y + rows) * bufferWidth) + (x + 4)] & 0xf0) | ((src[((y + rows) * bufferWidth) + (x + 5)] & 0xf0) >> 4);
*dst++ = (src[((y + rows) * bufferWidth) + (x + 5)] & 0xf0) | ((src[((y + rows) * bufferWidth) + (x + 7)] & 0xf0) >> 4);
}
}
}
DCFlushRange(dataBufferI4, bufferSize);
return dataBufferI4;
}
/**
* Convert the specified RGBA data buffer into the I8 texture format
*
* This routine converts the RGBA data buffer into the I8 texture format and returns a pointer to the converted buffer.
*
* @param rgbaBuffer Buffer containing the temporarily rendered RGBA data.
* @param bufferWidth Pixel width of the data buffer.
* @param bufferHeight Pixel height of the data buffer.
* @return A pointer to the allocated buffer.
*/
uint32_t* Metaphrasis::convertBufferToI8(uint32_t* rgbaBuffer, uint16_t bufferWidth, uint16_t bufferHeight) {
uint32_t bufferSize = bufferWidth * bufferHeight;
uint32_t* dataBufferI8 = (uint32_t *)memalign(32, bufferSize);
memset(dataBufferI8, 0x00, bufferSize);
uint32_t *src = (uint32_t *)rgbaBuffer;
uint8_t *dst = (uint8_t *)dataBufferI8;
for(uint16_t y = 0; y < bufferHeight; y += 4) {
for(uint16_t x = 0; x < bufferWidth; x += 8) {
for(uint16_t rows = 0; rows < 4; rows++) {
*dst++ = src[((y + rows) * bufferWidth) + (x + 0)] & 0xff;
*dst++ = src[((y + rows) * bufferWidth) + (x + 1)] & 0xff;
*dst++ = src[((y + rows) * bufferWidth) + (x + 2)] & 0xff;
*dst++ = src[((y + rows) * bufferWidth) + (x + 3)] & 0xff;
*dst++ = src[((y + rows) * bufferWidth) + (x + 4)] & 0xff;
*dst++ = src[((y + rows) * bufferWidth) + (x + 5)] & 0xff;
*dst++ = src[((y + rows) * bufferWidth) + (x + 6)] & 0xff;
*dst++ = src[((y + rows) * bufferWidth) + (x + 7)] & 0xff;
}
}
}
DCFlushRange(dataBufferI8, bufferSize);
return dataBufferI8;
}
/**
* Downsample the specified RGBA value data buffer to an IA4 value.
*
* This routine downsamples the given RGBA data value into the IA4 texture data format.
*
* @param rgba A 32-bit RGBA value to convert to the IA4 format.
* @return The IA4 value of the given RGBA value.
*/
uint8_t Metaphrasis::convertRGBAToIA4(uint32_t rgba) {
uint8_t i, a;
i = (rgba >> 8) & 0xf0;
a = (rgba ) & 0xff;
return i | (a >> 4);
}
/**
* Convert the specified RGBA data buffer into the IA4 texture format
*
* This routine converts the RGBA data buffer into the IA4 texture format and returns a pointer to the converted buffer.
*
* @param rgbaBuffer Buffer containing the temporarily rendered RGBA data.
* @param bufferWidth Pixel width of the data buffer.
* @param bufferHeight Pixel height of the data buffer.
* @return A pointer to the allocated buffer.
*/
uint32_t* Metaphrasis::convertBufferToIA4(uint32_t* rgbaBuffer, uint16_t bufferWidth, uint16_t bufferHeight) {
uint32_t bufferSize = bufferWidth * bufferHeight;
uint32_t* dataBufferIA4 = (uint32_t *)memalign(32, bufferSize);
memset(dataBufferIA4, 0x00, bufferSize);
uint32_t *src = (uint32_t *)rgbaBuffer;
uint8_t *dst = (uint8_t *)dataBufferIA4;
for(uint16_t y = 0; y < bufferHeight; y += 4) {
for(uint16_t x = 0; x < bufferWidth; x += 8) {
for(uint16_t rows = 0; rows < 4; rows++) {
*dst++ = Metaphrasis::convertRGBAToIA4(src[((y + rows) * bufferWidth) + (x + 0)]);
*dst++ = Metaphrasis::convertRGBAToIA4(src[((y + rows) * bufferWidth) + (x + 1)]);
*dst++ = Metaphrasis::convertRGBAToIA4(src[((y + rows) * bufferWidth) + (x + 2)]);
*dst++ = Metaphrasis::convertRGBAToIA4(src[((y + rows) * bufferWidth) + (x + 3)]);
*dst++ = Metaphrasis::convertRGBAToIA4(src[((y + rows) * bufferWidth) + (x + 4)]);
*dst++ = Metaphrasis::convertRGBAToIA4(src[((y + rows) * bufferWidth) + (x + 5)]);
*dst++ = Metaphrasis::convertRGBAToIA4(src[((y + rows) * bufferWidth) + (x + 6)]);
*dst++ = Metaphrasis::convertRGBAToIA4(src[((y + rows) * bufferWidth) + (x + 7)]);
}
}
}
DCFlushRange(dataBufferIA4, bufferSize);
return dataBufferIA4;
}
/**
* Downsample the specified RGBA value data buffer to an IA8 value.
*
* This routine downsamples the given RGBA data value into the IA8 texture data format.
*
* @param rgba A 32-bit RGBA value to convert to the IA8 format.
* @return The IA8 value of the given RGBA value.
*/
uint16_t Metaphrasis::convertRGBAToIA8(uint32_t rgba) {
uint8_t i, a;
i = (rgba >> 8) & 0xff;
a = (rgba ) & 0xff;
return (i << 8) | a;
}
/**
* Convert the specified RGBA data buffer into the IA8 texture format
*
* This routine converts the RGBA data buffer into the IA8 texture format and returns a pointer to the converted buffer.
*
* @param rgbaBuffer Buffer containing the temporarily rendered RGBA data.
* @param bufferWidth Pixel width of the data buffer.
* @param bufferHeight Pixel height of the data buffer.
* @return A pointer to the allocated buffer.
*/
uint32_t* Metaphrasis::convertBufferToIA8(uint32_t* rgbaBuffer, uint16_t bufferWidth, uint16_t bufferHeight) {
uint32_t bufferSize = (bufferWidth * bufferHeight) << 1;
uint32_t* dataBufferIA8 = (uint32_t *)memalign(32, bufferSize);
memset(dataBufferIA8, 0x00, bufferSize);
uint32_t *src = (uint32_t *)rgbaBuffer;
uint16_t *dst = (uint16_t *)dataBufferIA8;
for(uint16_t y = 0; y < bufferHeight; y += 4) {
for(uint16_t x = 0; x < bufferWidth; x += 4) {
for(uint16_t rows = 0; rows < 4; rows++) {
*dst++ = Metaphrasis::convertRGBAToIA8(src[((y + rows) * bufferWidth) + (x + 0)]);
*dst++ = Metaphrasis::convertRGBAToIA8(src[((y + rows) * bufferWidth) + (x + 1)]);
*dst++ = Metaphrasis::convertRGBAToIA8(src[((y + rows) * bufferWidth) + (x + 2)]);
*dst++ = Metaphrasis::convertRGBAToIA8(src[((y + rows) * bufferWidth) + (x + 3)]);
}
}
}
DCFlushRange(dataBufferIA8, bufferSize);
return dataBufferIA8;
}
/**
* Convert the specified RGBA data buffer into the RGBA8 texture format
*
* This routine converts the RGBA data buffer into the RGBA8 texture format and returns a pointer to the converted buffer.
*
* @param rgbaBuffer Buffer containing the temporarily rendered RGBA data.
* @param bufferWidth Pixel width of the data buffer.
* @param bufferHeight Pixel height of the data buffer.
* @return A pointer to the allocated buffer.
*/
uint32_t* Metaphrasis::convertBufferToRGBA8(uint32_t* rgbaBuffer, uint16_t bufferWidth, uint16_t bufferHeight) {
uint32_t bufferSize = (bufferWidth * bufferHeight) << 2;
uint32_t* dataBufferRGBA8 = (uint32_t *)memalign(32, bufferSize);
memset(dataBufferRGBA8, 0x00, bufferSize);
uint8_t *src = (uint8_t *)rgbaBuffer;
uint8_t *dst = (uint8_t *)dataBufferRGBA8;
for(uint16_t block = 0; block < bufferHeight; block += 4) {
for(uint16_t i = 0; i < bufferWidth; i += 4) {
for (uint16_t c = 0; c < 4; c++) {
for (uint16_t ar = 0; ar < 4; ar++) {
*dst++ = src[(((i + ar) + ((block + c) * bufferWidth)) * 4) + 3];
*dst++ = src[((i + ar) + ((block + c) * bufferWidth)) * 4];
}
}
for (uint16_t c = 0; c < 4; c++) {
for (uint16_t gb = 0; gb < 4; gb++) {
*dst++ = src[(((i + gb) + ((block + c) * bufferWidth)) * 4) + 1];
*dst++ = src[(((i + gb) + ((block + c) * bufferWidth)) * 4) + 2];
}
}
}
}
DCFlushRange(dataBufferRGBA8, bufferSize);
return dataBufferRGBA8;
}
/**
* Downsample the specified RGBA value data buffer to an RGB565 value.
*
* This routine downsamples the given RGBA data value into the RGB565 texture data format.
* Attribution for this routine is given fully to NoNameNo of GRRLIB Wii library.
*
* @param rgba A 32-bit RGBA value to convert to the RGB565 format.
* @return The RGB565 value of the given RGBA value.
*/
uint16_t Metaphrasis::convertRGBAToRGB565(uint32_t rgba) {
uint8_t r, g, b;
r = (((rgba >> 24) & 0xff) * 31) / 255;
g = (((rgba >> 16) & 0xff) * 63) / 255;
b = (((rgba >> 8) & 0xff) * 31) / 255;
return (((r << 6) | g ) << 5 ) | b;
}
/**
* Convert the specified RGBA data buffer into the RGB565 texture format
*
* This routine converts the RGBA data buffer into the RGB565 texture format and returns a pointer to the converted buffer.
*
* @param rgbaBuffer Buffer containing the temporarily rendered RGBA data.
* @param bufferWidth Pixel width of the data buffer.
* @param bufferHeight Pixel height of the data buffer.
* @return A pointer to the allocated buffer.
*/
uint32_t* Metaphrasis::convertBufferToRGB565(uint32_t* rgbaBuffer, uint16_t bufferWidth, uint16_t bufferHeight) {
uint32_t bufferSize = (bufferWidth * bufferHeight) << 1;
uint32_t* dataBufferRGB565 = (uint32_t *)memalign(32, bufferSize);
memset(dataBufferRGB565, 0x00, bufferSize);
uint32_t *src = (uint32_t *)rgbaBuffer;
uint16_t *dst = (uint16_t *)dataBufferRGB565;
for(uint16_t y = 0; y < bufferHeight; y += 4) {
for(uint16_t x = 0; x < bufferWidth; x += 4) {
for(uint16_t rows = 0; rows < 4; rows++) {
*dst++ = Metaphrasis::convertRGBAToRGB565(src[((y + rows) * bufferWidth) + (x + 0)]);
*dst++ = Metaphrasis::convertRGBAToRGB565(src[((y + rows) * bufferWidth) + (x + 1)]);
*dst++ = Metaphrasis::convertRGBAToRGB565(src[((y + rows) * bufferWidth) + (x + 2)]);
*dst++ = Metaphrasis::convertRGBAToRGB565(src[((y + rows) * bufferWidth) + (x + 3)]);
}
}
}
DCFlushRange(dataBufferRGB565, bufferSize);
return dataBufferRGB565;
}
/**
* Downsample the specified RGBA value data buffer to an RGB5A3 value.
*
* This routine downsamples the given RGBA data value into the RGB5A3 texture data format.
* Attribution for this routine is given fully to WiiGator via the TehSkeen forum.
*
* @param rgba A 32-bit RGBA value to convert to the RGB5A3 format.
* @return The RGB5A3 value of the given RGBA value.
*/
uint16_t Metaphrasis::convertRGBAToRGB5A3(uint32_t rgba) {
uint32_t r, g, b, a;
uint16_t color;
r = (rgba >> 24) & 0xff;
g = (rgba >> 16) & 0xff;
b = (rgba >> 8) & 0xff;
a = (rgba ) & 0xff;
if (a > 0xe0) {
r = r >> 3;
g = g >> 3;
b = b >> 3;
color = (r << 10) | (g << 5) | b;
color |= 0x8000;
}
else {
r = r >> 4;
g = g >> 4;
b = b >> 4;
a = a >> 5;
color = (a << 12) | (r << 8) | (g << 4) | b;
}
return color;
}
/**
* Convert the specified RGBA data buffer into the RGB5A3 texture format
*
* This routine converts the RGBA data buffer into the RGB5A3 texture format and returns a pointer to the converted buffer.
*
* @param rgbaBuffer Buffer containing the temporarily rendered RGBA data.
* @param bufferWidth Pixel width of the data buffer.
* @param bufferHeight Pixel height of the data buffer.
* @return A pointer to the allocated buffer.
*/
uint32_t* Metaphrasis::convertBufferToRGB5A3(uint32_t* rgbaBuffer, uint16_t bufferWidth, uint16_t bufferHeight) {
uint32_t bufferSize = (bufferWidth * bufferHeight) << 1;
uint32_t* dataBufferRGB5A3 = (uint32_t *)memalign(32, bufferSize);
memset(dataBufferRGB5A3, 0x00, bufferSize);
uint32_t *src = (uint32_t *)rgbaBuffer;
uint16_t *dst = (uint16_t *)dataBufferRGB5A3;
for(uint16_t y = 0; y < bufferHeight; y += 4) {
for(uint16_t x = 0; x < bufferWidth; x += 4) {
for(uint16_t rows = 0; rows < 4; rows++) {
*dst++ = Metaphrasis::convertRGBAToRGB5A3(src[((y + rows) * bufferWidth) + (x + 0)]);
*dst++ = Metaphrasis::convertRGBAToRGB5A3(src[((y + rows) * bufferWidth) + (x + 1)]);
*dst++ = Metaphrasis::convertRGBAToRGB5A3(src[((y + rows) * bufferWidth) + (x + 2)]);
*dst++ = Metaphrasis::convertRGBAToRGB5A3(src[((y + rows) * bufferWidth) + (x + 3)]);
}
}
}
DCFlushRange(dataBufferRGB5A3, bufferSize);
return dataBufferRGB5A3;
}

View File

@ -0,0 +1,116 @@
/*
* Metaphrasis is a static conversion class for transforming RGBA image
* buffers into verious GX texture formats for Wii homebrew development.
* Copyright (C) 2008 Armin Tamzarian
*
* This file is part of Metaphrasis.
*
* Metaphrasis is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Metaphrasis is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Metaphrasis. If not, see <http://www.gnu.org/licenses/>.
*/
/** \mainpage Metaphrasis
*
* \section sec_intro Introduction
*
* Metaphrasis is a static conversion class for transforming RGBA image buffers into verious GX texture formats for Wii homebrew development.
* <br>
* Metaphrasis is written in C++ and makes use of a community standard and newly developed algorithms for conversion of 32-bit RGBA data buffers into various GX texture formats common to both the Gamecube and Wii platforms.
* <p>
* This library was developed in-full by Armin Tamzarian with the support of developers in \#wiibrew on EFnet, Chaosteil of libwiisprite, and DrTwox of GRRLIB.
*
* \section sec_installation_source Installation (Source Code)
*
* -# Extract the Metaphrasis archive.
* -# Copy the contents of the <i>src</i> directory into your project's development path.
* -# Include the Metaphrasis header file in your code using syntax such as the following:
* \code
* #include "Metaphrasis.h"
* \endcode
*
* \section sec_installation_library Installation (Library)
*
* -# Extract the Metaphrasis archive.
* -# Copy the contents of the <i>lib</i> directory into your <i>devKitPro/libogc</i> directory.
* -# Include the Metaphrasis header file in your code using syntax such as the following:
* \code
* #include "Metaphrasis.h"
* \endcode
*
* \section sec_usage Usage
*
* -# Create a buffer full of 32-bit RGBA values noting both the pixel height and width of the buffer.
* -# Call one of the many conversion routines from within your code. (Note: All methods within the Metaphrasis class are static and thus no class instance need be allocated)
* \code
* uint32_t* rgba8Buffer = Metaphrasis::convertBufferToRGBA8(rgbaBuffer, bufferWidth, bufferHeight);
* \endcode
* -# Free your temporary RGBA value buffer if you no longer need said values.
*
* Currently supported conversion routines are as follows:
* \li convertBufferToI4
* \li convertBufferToI8
* \li convertBufferToIA4
* \li convertBufferToIA8
* \li convertBufferToRGBA8
* \li convertBufferToRGB565
* \li convertBufferToRGB5A3
*
* \section sec_license License
*
* Metaphrasis is distributed under the GNU Lesser General Public License.
*
* \section sec_contact Contact
*
* If you have any suggestions, questions, or comments regarding this library feel free to e-mail me at tamzarian1989 [at] gmail [dawt] com.
*/
#ifndef METAPHRASIS_H_
#define METAPHRASIS_H_
#include <gccore.h>
#include <stdint.h>
#include <malloc.h>
#include <string.h>
/*! \class Metaphrasis
* \brief A static conversion class for transforming RGBA image buffers into verious GX texture formats for
* Wii homebrew development.
* \author Armin Tamzarian
* \version 0.1.0
*
* Metaphrasis is a static conversion class for transforming RGBA image buffers into verious GX texture formats for
* Wii homebrew development. Metaphrasis is written in C++ and makes use of a community standard and newly developed
* algorithms for conversion of 32-bit RGBA data buffers into various GX texture formats common to both the Gamecube
* and Wii platforms.
*/
class Metaphrasis {
public:
Metaphrasis();
virtual ~Metaphrasis();
static uint32_t* convertBufferToI4(uint32_t* rgbaBuffer, uint16_t bufferWidth, uint16_t bufferHeight);
static uint32_t* convertBufferToI8(uint32_t* rgbaBuffer, uint16_t bufferWidth, uint16_t bufferHeight);
static uint32_t* convertBufferToIA4(uint32_t* rgbaBuffer, uint16_t bufferWidth, uint16_t bufferHeight);
static uint32_t* convertBufferToIA8(uint32_t* rgbaBuffer, uint16_t bufferWidth, uint16_t bufferHeight);
static uint32_t* convertBufferToRGBA8(uint32_t* rgbaBuffer, uint16_t bufferWidth, uint16_t bufferHeight);
static uint32_t* convertBufferToRGB565(uint32_t* rgbaBuffer, uint16_t bufferWidth, uint16_t bufferHeight);
static uint32_t* convertBufferToRGB5A3(uint32_t* rgbaBuffer, uint16_t bufferWidth, uint16_t bufferHeight);
static uint8_t convertRGBAToIA4(uint32_t rgba);
static uint16_t convertRGBAToIA8(uint32_t rgba);
static uint16_t convertRGBAToRGB565(uint32_t rgba);
static uint16_t convertRGBAToRGB5A3(uint32_t rgba);
};
#endif /*METAPHRASIS_H_*/

View File

@ -1,4 +1,4 @@
#define VERSION "0.73.02" #define VERSION "0.73"
/* Define to 1 to enable internal debugger, requires libcurses */ /* Define to 1 to enable internal debugger, requires libcurses */
#define C_DEBUG 0 #define C_DEBUG 0

106
src/platform/wii/filelist.h Normal file
View File

@ -0,0 +1,106 @@
/****************************************************************************
* DOSBox Wii Home Menu
* Tantric 2009
*
* filelist.h
*
* Contains a list of all of the files stored in the images/, fonts/, and
* sounds/ folders
***************************************************************************/
#ifndef _FILELIST_H_
#define _FILELIST_H_
#include <gccore.h>
extern const u8 font_ttf[];
extern const u32 font_ttf_size;
extern const u8 enter_ogg[];
extern const u32 enter_ogg_size;
extern const u8 exit_ogg[];
extern const u32 exit_ogg_size;
extern const u8 button_over_pcm[];
extern const u32 button_over_pcm_size;
extern const u8 button_click_pcm[];
extern const u32 button_click_pcm_size;
extern const u8 logo_png[];
extern const u32 logo_png_size;
extern const u8 logo_over_png[];
extern const u32 logo_over_png_size;
extern const u8 bg_top_png[];
extern const u32 bg_top_png_size;
extern const u8 bg_bottom_png[];
extern const u32 bg_bottom_png_size;
extern const u8 button_png[];
extern const u32 button_png_size;
extern const u8 button_over_png[];
extern const u32 button_over_png_size;
extern const u8 button_small_png[];
extern const u32 button_small_png_size;
extern const u8 button_small_over_png[];
extern const u32 button_small_over_png_size;
extern const u8 button_large_png[];
extern const u32 button_large_png_size;
extern const u8 button_large_over_png[];
extern const u32 button_large_over_png_size;
extern const u8 battery_png[];
extern const u32 battery_png_size;
extern const u8 battery_red_png[];
extern const u32 battery_red_png_size;
extern const u8 battery_bar_png[];
extern const u32 battery_bar_png_size;
extern const u8 credits_box_png[];
extern const u32 credits_box_png_size;
extern const u8 keyboard_textbox_png[];
extern const u32 keyboard_textbox_png_size;
extern const u8 keyboard_key_png[];
extern const u32 keyboard_key_png_size;
extern const u8 keyboard_key_over_png[];
extern const u32 keyboard_key_over_png_size;
extern const u8 keyboard_mediumkey_png[];
extern const u32 keyboard_mediumkey_png_size;
extern const u8 keyboard_mediumkey_over_png[];
extern const u32 keyboard_mediumkey_over_png_size;
extern const u8 keyboard_largekey_png[];
extern const u32 keyboard_largekey_png_size;
extern const u8 keyboard_largekey_over_png[];
extern const u32 keyboard_largekey_over_png_size;
extern const u8 player1_point_png[];
extern const u32 player1_point_png_size;
extern const u8 player2_point_png[];
extern const u32 player2_point_png_size;
extern const u8 player3_point_png[];
extern const u32 player3_point_png_size;
extern const u8 player4_point_png[];
extern const u32 player4_point_png_size;
#endif

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 216 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 145 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 230 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 60 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 981 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 929 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

100
src/platform/wii/input.cpp Normal file
View File

@ -0,0 +1,100 @@
/****************************************************************************
* DOSBox Wii Home Menu
* Tantric 2009
*
* input.cpp
*
* Wii/Gamecube controller management
***************************************************************************/
#include <gccore.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <ogcsys.h>
#include <unistd.h>
#include <wiiuse/wpad.h>
#include "input.h"
#include "libwiigui/gui.h"
int rumbleRequest[4] = {0,0,0,0};
GuiTrigger userInput[4];
static int rumbleCount[4] = {0,0,0,0};
/****************************************************************************
* UpdatePads
*
* called by postRetraceCallback in InitGCVideo - scans pad and wpad
***************************************************************************/
void UpdatePads()
{
WPAD_ScanPads();
PAD_ScanPads();
for(int i=3; i >= 0; i--)
{
memcpy(&userInput[i].wpad, WPAD_Data(i), sizeof(WPADData));
userInput[i].chan = i;
userInput[i].pad.btns_d = PAD_ButtonsDown(i);
userInput[i].pad.btns_u = PAD_ButtonsUp(i);
userInput[i].pad.btns_h = PAD_ButtonsHeld(i);
userInput[i].pad.stickX = PAD_StickX(i);
userInput[i].pad.stickY = PAD_StickY(i);
userInput[i].pad.substickX = PAD_SubStickX(i);
userInput[i].pad.substickY = PAD_SubStickY(i);
userInput[i].pad.triggerL = PAD_TriggerL(i);
userInput[i].pad.triggerR = PAD_TriggerR(i);
}
}
/****************************************************************************
* ShutoffRumble
***************************************************************************/
void ShutoffRumble()
{
for(int i=0;i<4;i++)
{
WPAD_Rumble(i, 0);
rumbleCount[i] = 0;
}
}
/****************************************************************************
* DoRumble
***************************************************************************/
void DoRumble(int i)
{
if(rumbleRequest[i] && rumbleCount[i] < 3)
{
WPAD_Rumble(i, 1); // rumble on
rumbleCount[i]++;
}
else if(rumbleRequest[i])
{
rumbleCount[i] = 12;
rumbleRequest[i] = 0;
}
else
{
if(rumbleCount[i])
rumbleCount[i]--;
WPAD_Rumble(i, 0); // rumble off
}
}
bool MenuRequested()
{
for(int i=0; i<4; i++)
{
if ((userInput[i].wpad.btns_h & WPAD_BUTTON_HOME) ||
(userInput[i].wpad.btns_h & WPAD_CLASSIC_BUTTON_HOME))
{
return true;
}
}
return false;
}

26
src/platform/wii/input.h Normal file
View File

@ -0,0 +1,26 @@
/****************************************************************************
* DOSBox Wii Home Menu
* Tantric 2009
*
* input.h
*
* Wii/Gamecube controller management
***************************************************************************/
#ifndef _INPUT_H_
#define _INPUT_H_
#include <gccore.h>
#include <wiiuse/wpad.h>
#define PI 3.14159265f
#define PADCAL 50
extern int rumbleRequest[4];
void ShutoffRumble();
void DoRumble(int i);
void UpdatePads();
bool MenuRequested();
#endif

View File

@ -0,0 +1,783 @@
/*!\mainpage libwiigui Documentation
*
* \section Introduction
* libwiigui is a GUI library for the Wii, created to help structure the
* design of a complicated GUI interface, and to enable an author to create
* a sophisticated, feature-rich GUI. It was originally conceived and written
* after I started to design a GUI for Snes9x GX, and found libwiisprite and
* GRRLIB inadequate for the purpose. It uses GX for drawing, and makes use
* of PNGU for displaying images and FreeTypeGX for text. It was designed to
* be flexible and is easy to modify - don't be afraid to change the way it
* works or expand it to suit your GUI's purposes! If you do, and you think
* your changes might benefit others, please share them so they might be
* added to the project!
*
* \section Quickstart
* Start from the supplied template example. For more advanced uses, see the
* source code for Snes9x GX, FCE Ultra GX, and Visual Boy Advance GX.
* \section Contact
* If you have any suggestions for the library or documentation, or want to
* contribute, please visit the libwiigui website:
* http://code.google.com/p/libwiigui/
* \section Credits
* This library was wholly designed and written by Tantric. Thanks to the
* authors of PNGU and FreeTypeGX, of which this library makes use. Thanks
* also to the authors of GRRLIB and libwiisprite for laying the foundations.
*
*/
#ifndef LIBWIIGUI_H
#define LIBWIIGUI_H
#include <gccore.h>
#include <malloc.h>
#include <stdlib.h>
#include <string.h>
#include <vector>
#include <exception>
#include <wchar.h>
#include <math.h>
#include <asndlib.h>
#include <wiiuse/wpad.h>
#include "pngu.h"
#include "FreeTypeGX.h"
#include "wiivideo.h"
#include "filelist.h"
#include "input.h"
#include "oggplayer.h"
extern FreeTypeGX *fontSystem[];
#define SCROLL_INITIAL_DELAY 20
#define SCROLL_LOOP_DELAY 3
#define MAX_KEYBOARD_DISPLAY 32
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_HELD,
STATE_DISABLED
};
enum
{
SOUND_PCM,
SOUND_OGG
};
enum
{
IMAGE_TEXTURE,
IMAGE_COLOR,
IMAGE_DATA
};
enum
{
TRIGGER_SIMPLE,
TRIGGER_HELD,
TRIGGER_BUTTON_ONLY,
TRIGGER_BUTTON_ONLY_IN_FOCUS
};
enum
{
SCROLL_NONE,
SCROLL_HORIZONTAL
};
typedef struct _paddata {
u16 btns_d;
u16 btns_u;
u16 btns_h;
s8 stickX;
s8 stickY;
s8 substickX;
s8 substickY;
u8 triggerL;
u8 triggerR;
} PADData;
#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
//!Sound conversion and playback. A wrapper for other sound libraries - ASND, libmad, ltremor, etc
class GuiSound
{
public:
//!Constructor
//!\param s Pointer to the sound data
//!\param l Length of sound data
//!\param t Sound format type (SOUND_PCM or SOUND_OGG)
GuiSound(const u8 * s, int l, int t);
//!Destructor
~GuiSound();
//!Start sound playback
void Play();
//!Stop sound playback
void Stop();
//!Pause sound playback
void Pause();
//!Resume sound playback
void Resume();
//!Checks if the sound is currently playing
//!\return true if sound is playing, false otherwise
bool IsPlaying();
//!Set sound volume
//!\param v Sound volume (0-100)
void SetVolume(int v);
//!Set the sound to loop playback (only applies to OGG)
//!\param l Loop (true to loop)
void SetLoop(bool l);
protected:
const u8 * sound; //!< Pointer to the sound data
int type; //!< Sound format type (SOUND_PCM or SOUND_OGG)
s32 length; //!< Length of sound data
s32 voice; //!< Currently assigned ASND voice channel
s32 volume; //!< Sound volume (0-100)
bool loop; //!< Loop sound playback
};
//!Menu input trigger management. Determine if action is neccessary based on input data by comparing controller input data to a specific trigger element.
class GuiTrigger
{
public:
//!Constructor
GuiTrigger();
//!Destructor
~GuiTrigger();
//!Sets a simple trigger. Requires: element is selected, and trigger button is pressed
//!\param ch Controller channel number
//!\param wiibtns Wii controller trigger button(s) - classic controller buttons are considered separately
//!\param gcbtns GameCube controller trigger button(s)
void SetSimpleTrigger(s32 ch, u32 wiibtns, u16 gcbtns);
//!Sets a held trigger. Requires: element is selected, and trigger button is pressed
//!\param ch Controller channel number
//!\param wiibtns Wii controller trigger button(s) - classic controller buttons are considered separately
//!\param gcbtns GameCube controller trigger button(s)
void SetHeldTrigger(s32 ch, u32 wiibtns, u16 gcbtns);
//!Sets a button-only trigger. Requires: Trigger button is pressed
//!\param ch Controller channel number
//!\param wiibtns Wii controller trigger button(s) - classic controller buttons are considered separately
//!\param gcbtns GameCube controller trigger button(s)
void SetButtonOnlyTrigger(s32 ch, u32 wiibtns, u16 gcbtns);
//!Sets a button-only trigger. Requires: trigger button is pressed and parent window of element is in focus
//!\param ch Controller channel number
//!\param wiibtns Wii controller trigger button(s) - classic controller buttons are considered separately
//!\param gcbtns GameCube controller trigger button(s)
void SetButtonOnlyInFocusTrigger(s32 ch, u32 wiibtns, u16 gcbtns);
//!Get X/Y value from Wii Joystick (classic, nunchuk) input
//!\param right Controller stick (left = 0, right = 1)
//!\param axis Controller stick axis (x-axis = 0, y-axis = 1)
//!\return Stick value
s8 WPAD_Stick(u8 right, int axis);
//!Move menu selection left (via pad/joystick). Allows scroll delay and button overriding
//!\return true if selection should be moved left, false otherwise
bool Left();
//!Move menu selection right (via pad/joystick). Allows scroll delay and button overriding
//!\return true if selection should be moved right, false otherwise
bool Right();
//!Move menu selection up (via pad/joystick). Allows scroll delay and button overriding
//!\return true if selection should be moved up, false otherwise
bool Up();
//!Move menu selection down (via pad/joystick). Allows scroll delay and button overriding
//!\return true if selection should be moved down, false otherwise
bool Down();
u8 type; //!< trigger type (TRIGGER_SIMPLE, TRIGGER_HELD, TRIGGER_BUTTON_ONLY, TRIGGER_BUTTON_ONLY_IN_FOCUS)
s32 chan; //!< Trigger controller channel (0-3, -1 for all)
WPADData wpad; //!< Wii controller trigger data
PADData pad; //!< GameCube controller trigger data
};
extern GuiTrigger userInput[4];
//!Primary GUI class. Most other classes inherit from this class.
class GuiElement
{
public:
//!Constructor
GuiElement();
//!Destructor
~GuiElement();
//!Set the element's parent
//!\param e Pointer to parent element
void SetParent(GuiElement * e);
//!Gets the element's parent
//!\return Pointer to parent element
GuiElement * GetParent();
//!Gets the current leftmost coordinate of the element
//!Considers horizontal alignment, x offset, width, and parent element's GetLeft() / GetWidth() values
//!\return left coordinate
int GetLeft();
//!Gets the current topmost coordinate of the element
//!Considers vertical alignment, y offset, height, and parent element's GetTop() / GetHeight() values
//!\return top coordinate
int GetTop();
//!Sets the minimum y offset of the element
//!\param y Y offset
void SetMinY(int y);
//!Gets the minimum y offset of the element
//!\return Minimum Y offset
int GetMinY();
//!Sets the maximum y offset of the element
//!\param y Y offset
void SetMaxY(int y);
//!Gets the maximum y offset of the element
//!\return Maximum Y offset
int GetMaxY();
//!Sets the minimum x offset of the element
//!\param x X offset
void SetMinX(int x);
//!Gets the minimum x offset of the element
//!\return Minimum X offset
int GetMinX();
//!Sets the maximum x offset of the element
//!\param x X offset
void SetMaxX(int x);
//!Gets the maximum x offset of the element
//!\return Maximum X offset
int GetMaxX();
//!Gets the current width of the element. Does not currently consider the scale
//!\return width
int GetWidth();
//!Gets the height of the element. Does not currently consider the scale
//!\return height
int GetHeight();
//!Sets the size (width/height) of the element
//!\param w Width of element
//!\param h Height of element
void SetSize(int w, int h);
//!Checks whether or not the element is visible
//!\return true if visible, false otherwise
bool IsVisible();
//!Checks whether or not the element is selectable
//!\return true if selectable, false otherwise
bool IsSelectable();
//!Checks whether or not the element is clickable
//!\return true if clickable, false otherwise
bool IsClickable();
//!Checks whether or not the element is holdable
//!\return true if holdable, false otherwise
bool IsHoldable();
//!Sets whether or not the element is selectable
//!\param s Selectable
void SetSelectable(bool s);
//!Sets whether or not the element is clickable
//!\param c Clickable
void SetClickable(bool c);
//!Sets whether or not the element is holdable
//!\param c Holdable
void SetHoldable(bool d);
//!Gets the element's current state
//!\return state
int GetState();
//!Gets the controller channel that last changed the element's state
//!\return Channel number (0-3, -1 = no channel)
int GetStateChan();
//!Sets the element's alpha value
//!\param a alpha value
void SetAlpha(int a);
//!Gets the element's alpha value
//!Considers alpha, alphaDyn, and the parent element's GetAlpha() value
//!\return alpha
int GetAlpha();
//!Sets the element's scale
//!\param s scale (1 is 100%)
void SetScale(float s);
//!Gets the element's current scale
//!Considers scale, scaleDyn, and the parent element's GetScale() value
float GetScale();
//!Set a new GuiTrigger for the element
//!\param t Pointer to GuiTrigger
void SetTrigger(GuiTrigger * t);
//!\overload
//!\param i Index of trigger array to set
//!\param t Pointer to GuiTrigger
void SetTrigger(u8 i, GuiTrigger * t);
//!Checks whether rumble was requested by the element
//!\return true is rumble was requested, false otherwise
bool Rumble();
//!Sets whether or not the element is requesting a rumble event
//!\param r true if requesting rumble, false if not
void SetRumble(bool r);
//!Set an effect for the element
//!\param e Effect to enable
//!\param a Amount of the effect (usage varies on effect)
//!\param t Target amount of the effect (usage varies on effect)
void SetEffect(int e, int a, int t=0);
//!Sets an effect to be enabled on wiimote cursor over
//!\param e Effect to enable
//!\param a Amount of the effect (usage varies on effect)
//!\param t Target amount of the effect (usage varies on effect)
void SetEffectOnOver(int e, int a, int t=0);
//!Shortcut to SetEffectOnOver(EFFECT_SCALE, 4, 110)
void SetEffectGrow();
//!Gets the current element effects
//!\return element effects
int GetEffect();
//!Checks whether the specified coordinates are within the element's boundaries
//!\param x X coordinate
//!\param y Y coordinate
//!\return true if contained within, false otherwise
bool IsInside(int x, int y);
//!Sets the element's position
//!\param x X coordinate
//!\param y Y coordinate
void SetPosition(int x, int y);
//!Updates the element's effects (dynamic values)
//!Called by Draw(), used for animation purposes
void UpdateEffects();
//!Sets a function to called after after Update()
//!Callback function can be used to response to changes in the state of the element, and/or update the element's attributes
void SetUpdateCallback(UpdateCallback u);
//!Checks whether the element is in focus
//!\return true if element is in focus, false otherwise
int IsFocused();
//!Sets the element's visibility
//!\param v Visibility (true = visible)
virtual void SetVisible(bool v);
//!Sets the element's focus
//!\param f Focus (true = in focus)
virtual void SetFocus(int f);
//!Sets the element's state
//!\param s State (STATE_DEFAULT, STATE_SELECTED, STATE_CLICKED, STATE_DISABLED)
//!\param c Controller channel (0-3, -1 = none)
virtual void SetState(int s, int c = -1);
//!Resets the element's state to STATE_DEFAULT
virtual void ResetState();
//!Gets whether or not the element is in STATE_SELECTED
//!\return true if selected, false otherwise
virtual int GetSelected();
//!Sets the element's alignment respective to its parent element
//!\param hor Horizontal alignment (ALIGN_LEFT, ALIGN_RIGHT, ALIGN_CENTRE)
//!\param vert Vertical alignment (ALIGN_TOP, ALIGN_BOTTOM, ALIGN_MIDDLE)
virtual void SetAlignment(int hor, int vert);
//!Called constantly to allow the element to respond to the current input data
//!\param t Pointer to a GuiTrigger, containing the current input data from PAD/WPAD
virtual void Update(GuiTrigger * t);
//!Called constantly to redraw the element
virtual void Draw();
protected:
bool visible; //!< Visibility of the element. If false, Draw() is skipped
int focus; //!< Element focus (-1 = focus disabled, 0 = not focused, 1 = focused)
int width; //!< Element width
int height; //!< Element height
int xoffset; //!< Element X offset
int yoffset; //!< Element Y offset
int ymin; //!< Element's min Y offset allowed
int ymax; //!< Element's max Y offset allowed
int xmin; //!< Element's min X offset allowed
int xmax; //!< Element's max X offset allowed
int xoffsetDyn; //!< Element X offset, dynamic (added to xoffset value for animation effects)
int yoffsetDyn; //!< Element Y offset, dynamic (added to yoffset value for animation effects)
int alpha; //!< Element alpha value (0-255)
f32 scale; //!< Element scale (1 = 100%)
int alphaDyn; //!< Element alpha, dynamic (multiplied by alpha value for blending/fading effects)
f32 scaleDyn; //!< Element scale, dynamic (multiplied by alpha value for blending/fading effects)
bool rumble; //!< Wiimote rumble (on/off) - set to on when this element requests a rumble event
int effects; //!< Currently enabled effect(s). 0 when no effects are enabled
int effectAmount; //!< Effect amount. Used by different effects for different purposes
int effectTarget; //!< Effect target amount. Used by different effects for different purposes
int effectsOver; //!< Effects to enable when wiimote cursor is over this element. Copied to effects variable on over event
int effectAmountOver; //!< EffectAmount to set when wiimote cursor is over this element
int effectTargetOver; //!< EffectTarget to set when wiimote cursor is over this element
int alignmentHor; //!< Horizontal element alignment, respective to parent element (LEFT, RIGHT, CENTRE)
int alignmentVert; //!< Horizontal element alignment, respective to parent element (TOP, BOTTOM, MIDDLE)
int state; //!< Element state (DEFAULT, SELECTED, CLICKED, DISABLED)
int stateChan; //!< Which controller channel is responsible for the last change in state
bool selectable; //!< Whether or not this element selectable (can change to SELECTED state)
bool clickable; //!< Whether or not this element is clickable (can change to CLICKED state)
bool holdable; //!< Whether or not this element is holdable (can change to HELD state)
GuiTrigger * trigger[2]; //!< GuiTriggers (input actions) that this element responds to
GuiElement * parentElement; //!< Parent element
UpdateCallback updateCB; //!< Callback function to call when this element is updated
};
//!Allows GuiElements to be grouped together into a "window"
class GuiWindow : public GuiElement
{
public:
//!Constructor
GuiWindow();
//!\overload
//!\param w Width of window
//!\param h Height of window
GuiWindow(int w, int h);
//!Destructor
~GuiWindow();
//!Appends a GuiElement to the GuiWindow
//!\param e The GuiElement to append. If it is already in the GuiWindow, it is removed first
void Append(GuiElement* e);
//!Inserts a GuiElement into the GuiWindow at the specified index
//!\param e The GuiElement to insert. If it is already in the GuiWindow, it is removed first
//!\param i Index in which to insert the element
void Insert(GuiElement* e, u32 i);
//!Removes the specified GuiElement from the GuiWindow
//!\param e GuiElement to be removed
void Remove(GuiElement* e);
//!Removes all GuiElements
void RemoveAll();
//!Returns the GuiElement at the specified index
//!\param index The index of the element
//!\return A pointer to the element at the index, NULL on error (eg: out of bounds)
GuiElement* GetGuiElementAt(u32 index) const;
//!Returns the size of the list of elements
//!\return The size of the current element list
u32 GetSize();
//!Sets the visibility of the window
//!\param v visibility (true = visible)
void SetVisible(bool v);
//!Resets the window's state to STATE_DEFAULT
void ResetState();
//!Sets the window's state
//!\param s State
void SetState(int s);
//!Gets the index of the GuiElement inside the window that is currently selected
//!\return index of selected GuiElement
int GetSelected();
//!Sets the window focus
//!\param f Focus
void SetFocus(int f);
//!Change the focus to the specified element
//!This is intended for the primary GuiWindow only
//!\param e GuiElement that should have focus
void ChangeFocus(GuiElement * e);
//!Changes window focus to the next focusable window or element
//!If no element is in focus, changes focus to the first available element
//!If B or 1 button is pressed, changes focus to the next available element
//!This is intended for the primary GuiWindow only
//!\param t Pointer to a GuiTrigger, containing the current input data from PAD/WPAD
void ToggleFocus(GuiTrigger * t);
//!Moves the selected element to the element to the left or right
//!\param d Direction to move (-1 = left, 1 = right)
void MoveSelectionHor(int d);
//!Moves the selected element to the element above or below
//!\param d Direction to move (-1 = up, 1 = down)
void MoveSelectionVert(int d);
//!Draws all the elements in this GuiWindow
void Draw();
//!Updates the window and all elements contains within
//!Allows the GuiWindow and all elements to respond to the input data specified
//!\param t Pointer to a GuiTrigger, containing the current input data from PAD/WPAD
void Update(GuiTrigger * t);
protected:
std::vector<GuiElement*> _elements; //!< Contains all elements within the GuiWindow
};
//!Converts image data into GX-useable RGBA8. Currently designed for use only with PNG files
class GuiImageData
{
public:
//!Constructor
//!Converts the image data to RGBA8 - expects PNG format
//!\param i Image data
GuiImageData(const u8 * i);
//!Destructor
~GuiImageData();
//!Gets a pointer to the image data
//!\return pointer to image data
u8 * GetImage();
//!Gets the image width
//!\return image width
int GetWidth();
//!Gets the image height
//!\return image height
int GetHeight();
protected:
u8 * data; //!< Image data
int height; //!< Height of image
int width; //!< Width of image
};
//!Display, manage, and manipulate images in the GUI
class GuiImage : public GuiElement
{
public:
//!Constructor
GuiImage();
//!\overload
//!\param img Pointer to GuiImageData element
GuiImage(GuiImageData * img);
//!\overload
//!Sets up a new image from the image data specified
//!\param img
//!\param w Image width
//!\param h Image height
GuiImage(u8 * img, int w, int h);
//!\overload
//!Creates an image filled with the specified color
//!\param w Image width
//!\param h Image height
//!\param c Image color
GuiImage(int w, int h, GXColor c);
//!Destructor
~GuiImage();
//!Sets the image rotation angle for drawing
//!\param a Angle (in degrees)
void SetAngle(float a);
//!Sets the number of times to draw the image horizontally
//!\param t Number of times to draw the image
void SetTile(int t);
//!Constantly called to draw the image
void Draw();
//!Gets the image data
//!\return pointer to image data
u8 * GetImage();
//!Sets up a new image using the GuiImageData object specified
//!\param img Pointer to GuiImageData object
void SetImage(GuiImageData * img);
//!\overload
//!\param img Pointer to image data
//!\param w Width
//!\param h Height
void SetImage(u8 * img, int w, int h);
//!Gets the pixel color at the specified coordinates of the image
//!\param x X coordinate
//!\param y Y coordinate
GXColor GetPixel(int x, int y);
//!Sets the pixel color at the specified coordinates of the image
//!\param x X coordinate
//!\param y Y coordinate
//!\param color Pixel color
void SetPixel(int x, int y, GXColor color);
//!Directly modifies the image data to create a color-striped effect
//!Alters the RGB values by the specified amount
//!\param s Amount to increment/decrement the RGB values in the image
void ColorStripe(int s);
//!Sets a stripe effect on the image, overlaying alpha blended rectangles
//!Does not alter the image data
//!\param s Alpha amount to draw over the image
void SetStripe(int s);
protected:
int imgType; //!< Type of image data (IMAGE_TEXTURE, IMAGE_COLOR, IMAGE_DATA)
u8 * image; //!< Poiner to image data. May be shared with GuiImageData data
f32 imageangle; //!< Angle to draw the image
int tile; //!< Number of times to draw (tile) the image horizontally
int stripe; //!< Alpha value (0-255) to apply a stripe effect to the texture
};
//!Display, manage, and manipulate text in the GUI
class GuiText : public GuiElement
{
public:
//!Constructor
//!\param t Text
//!\param s Font size
//!\param c Font color
GuiText(const char * t, int s, GXColor c);
//!\overload
//!\Assumes SetPresets() has been called to setup preferred text attributes
//!\param t Text
GuiText(const char * t);
//!Destructor
~GuiText();
//!Sets the text of the GuiText element
//!\param t Text
void SetText(const char * t);
//!Sets up preset values to be used by GuiText(t)
//!Useful when printing multiple text elements, all with the same attributes set
//!\param sz Font size
//!\param c Font color
//!\param w Maximum width of texture image (for text wrapping)
//!\param s Font size
//!\param h Text alignment (horizontal)
//!\param v Text alignment (vertical)
void SetPresets(int sz, GXColor c, int w, u16 s, int h, int v);
//!Sets the font size
//!\param s Font size
void SetFontSize(int s);
//!Sets the maximum width of the drawn texture image
//!\param w Maximum width
void SetMaxWidth(int width);
//!Enables/disables text scrolling
//!\param s Scrolling on/off
void SetScroll(int s);
//!Enables/disables text wrapping
//!\param w Wrapping on/off
//!\param width Maximum width (0 to disable)
void SetWrap(bool w, int width = 0);
//!Sets the font color
//!\param c Font color
void SetColor(GXColor c);
//!Sets the FreeTypeGX style attributes
//!\param s Style attributes
void SetStyle(u16 s);
//!Sets the text alignment
//!\param hor Horizontal alignment (ALIGN_LEFT, ALIGN_RIGHT, ALIGN_CENTRE)
//!\param vert Vertical alignment (ALIGN_TOP, ALIGN_BOTTOM, ALIGN_MIDDLE)
void SetAlignment(int hor, int vert);
//!Constantly called to draw the text
void Draw();
protected:
char * origText; //!< Original text data
wchar_t* text; //!< Unicode text value
int size; //!< Font size
int maxWidth; //!< Maximum width of the generated text object (for text wrapping)
bool wrap; //!< Wrapping toggle
wchar_t* textDyn; //!< Wrapped text value
int textScroll; //!< Scrolling toggle
int textScrollPos; //!< Current starting index of text string for scrolling
int textScrollInitialDelay; //!< Delay to wait before starting to scroll
int textScrollDelay; //!< Scrolling speed
u16 style; //!< FreeTypeGX style attributes
GXColor color; //!< Font color
};
//!Display, manage, and manipulate buttons in the GUI. Buttons can have images, icons, text, and sound set (all of which are optional)
class GuiButton : public GuiElement
{
public:
//!Constructor
//!\param w Width
//!\param h Height
GuiButton(int w, int h);
//!Destructor
~GuiButton();
//!Sets the button's image
//!\param i Pointer to GuiImage object
void SetImage(GuiImage* i);
//!Sets the button's image on over
//!\param i Pointer to GuiImage object
void SetImageOver(GuiImage* i);
//!Sets the button's image on hold
//!\param i Pointer to GuiImage object
void SetImageHold(GuiImage* i);
//!Sets the button's image on click
//!\param i Pointer to GuiImage object
void SetImageClick(GuiImage* i);
//!Sets the button's icon
//!\param i Pointer to GuiImage object
void SetIcon(GuiImage* i);
//!Sets the button's icon on over
//!\param i Pointer to GuiImage object
void SetIconOver(GuiImage* i);
//!Sets the button's icon on hold
//!\param i Pointer to GuiImage object
void SetIconHold(GuiImage* i);
//!Sets the button's icon on click
//!\param i Pointer to GuiImage object
void SetIconClick(GuiImage* i);
//!Sets the button's label
//!\param t Pointer to GuiText object
//!\param n Index of label to set (optional, default is 0)
void SetLabel(GuiText* t, int n = 0);
//!Sets the button's label on over (eg: different colored text)
//!\param t Pointer to GuiText object
//!\param n Index of label to set (optional, default is 0)
void SetLabelOver(GuiText* t, int n = 0);
//!Sets the button's label on hold
//!\param t Pointer to GuiText object
//!\param n Index of label to set (optional, default is 0)
void SetLabelHold(GuiText* t, int n = 0);
//!Sets the button's label on click
//!\param t Pointer to GuiText object
//!\param n Index of label to set (optional, default is 0)
void SetLabelClick(GuiText* t, int n = 0);
//!Sets the sound to play on over
//!\param s Pointer to GuiSound object
void SetSoundOver(GuiSound * s);
//!Sets the sound to play on hold
//!\param s Pointer to GuiSound object
void SetSoundHold(GuiSound * s);
//!Sets the sound to play on click
//!\param s Pointer to GuiSound object
void SetSoundClick(GuiSound * s);
//!Constantly called to draw the GuiButton
void Draw();
//!Constantly called to allow the GuiButton to respond to updated input data
//!\param t Pointer to a GuiTrigger, containing the current input data from PAD/WPAD
void Update(GuiTrigger * t);
protected:
GuiImage * image; //!< Button image (default)
GuiImage * imageOver; //!< Button image for STATE_SELECTED
GuiImage * imageHold; //!< Button image for STATE_HELD
GuiImage * imageClick; //!< Button image for STATE_CLICKED
GuiImage * icon; //!< Button icon (drawn after button image)
GuiImage * iconOver; //!< Button icon for STATE_SELECTED
GuiImage * iconHold; //!< Button icon for STATE_HELD
GuiImage * iconClick; //!< Button icon for STATE_CLICKED
GuiText * label[3]; //!< Label(s) to display (default)
GuiText * labelOver[3]; //!< Label(s) to display for STATE_SELECTED
GuiText * labelHold[3]; //!< Label(s) to display for STATE_HELD
GuiText * labelClick[3]; //!< Label(s) to display for STATE_CLICKED
GuiSound * soundOver; //!< Sound to play for STATE_SELECTED
GuiSound * soundHold; //!< Sound to play for STATE_HELD
GuiSound * soundClick; //!< Sound to play for STATE_CLICKED
};
typedef struct _keytype {
char ch, chShift;
} Key;
//!On-screen keyboard
class GuiKeyboard : public GuiWindow
{
public:
GuiKeyboard(char * t, u32 m);
~GuiKeyboard();
void Update(GuiTrigger * t);
char kbtextstr[256];
protected:
u32 kbtextmaxlen;
Key keys[4][11];
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][11];
GuiImage * keyImg[4][11];
GuiImage * keyImgOver[4][11];
GuiText * keyTxt[4][11];
GuiImageData * keyTextbox;
GuiImageData * key;
GuiImageData * keyOver;
GuiImageData * keyMedium;
GuiImageData * keyMediumOver;
GuiImageData * keyLarge;
GuiImageData * keyLargeOver;
GuiSound * keySoundOver;
GuiSound * keySoundClick;
GuiTrigger * trigA;
};
#endif

View File

@ -0,0 +1,306 @@
/****************************************************************************
* libwiigui
*
* Tantric 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;
imageHold = NULL;
imageClick = NULL;
icon = NULL;
iconOver = NULL;
iconHold = NULL;
iconClick = NULL;
for(int i=0; i < 3; i++)
{
label[i] = NULL;
labelOver[i] = NULL;
labelHold[i] = NULL;
labelClick[i] = NULL;
}
soundOver = NULL;
soundHold = NULL;
soundClick = NULL;
selectable = true;
holdable = false;
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::SetImageHold(GuiImage* img)
{
imageHold = img;
if(img) img->SetParent(this);
}
void GuiButton::SetImageClick(GuiImage* img)
{
imageClick = 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::SetIconHold(GuiImage* img)
{
iconHold = img;
if(img) img->SetParent(this);
}
void GuiButton::SetIconClick(GuiImage* img)
{
iconClick = img;
if(img) img->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::SetLabelHold(GuiText* txt, int n)
{
labelHold[n] = txt;
if(txt) txt->SetParent(this);
}
void GuiButton::SetLabelClick(GuiText* txt, int n)
{
labelClick[n] = txt;
if(txt) txt->SetParent(this);
}
void GuiButton::SetSoundOver(GuiSound * snd)
{
soundOver = snd;
}
void GuiButton::SetSoundHold(GuiSound * snd)
{
soundHold = 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 || state == STATE_HELD) && imageOver)
imageOver->Draw();
else if(image)
image->Draw();
// draw icon
if((state == STATE_SELECTED || state == STATE_HELD) && iconOver)
iconOver->Draw();
else if(icon)
icon->Draw();
// draw text
for(int i=0; i<3; i++)
{
if((state == STATE_SELECTED || state == STATE_HELD) && 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 && t->chan >= 0)
{
if(this->IsInside(t->wpad.ir.x, t->wpad.ir.y))
{
if(state == STATE_DEFAULT) // we weren't on the button before!
{
this->SetState(STATE_SELECTED, t->chan);
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 && (stateChan == t->chan || stateChan == -1))
this->ResetState();
if(effectTarget == effectTargetOver && effectAmount == effectAmountOver)
{
// initiate effects (in reverse)
effects = effectsOver;
effectAmount = -effectAmountOver;
effectTarget = 100;
}
}
}
#endif
// button triggers
if(this->IsClickable())
{
s32 wm_btns, wm_btns_trig, cc_btns, cc_btns_trig;
for(int i=0; i<2; i++)
{
if(trigger[i] && (trigger[i]->chan == -1 || trigger[i]->chan == t->chan))
{
// higher 16 bits only (wiimote)
wm_btns = t->wpad.btns_d << 16;
wm_btns_trig = trigger[i]->wpad.btns_d << 16;
// lower 16 bits only (classic controller)
cc_btns = t->wpad.btns_d >> 16;
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(t->chan == stateChan || stateChan == -1)
{
if(state == STATE_SELECTED)
{
if(!t->wpad.ir.valid || this->IsInside(t->wpad.ir.x, t->wpad.ir.y))
{
this->SetState(STATE_CLICKED, t->chan);
if(soundClick)
soundClick->Play();
}
}
else if(trigger[i]->type == TRIGGER_BUTTON_ONLY)
{
this->SetState(STATE_CLICKED, t->chan);
}
else if(trigger[i]->type == TRIGGER_BUTTON_ONLY_IN_FOCUS &&
parentElement->IsFocused())
{
this->SetState(STATE_CLICKED, t->chan);
}
}
}
}
}
}
if(this->IsHoldable())
{
bool held = false;
s32 wm_btns, wm_btns_h, wm_btns_trig, cc_btns, cc_btns_h, cc_btns_trig;
for(int i=0; i<2; i++)
{
if(trigger[i] && (trigger[i]->chan == -1 || trigger[i]->chan == t->chan))
{
// higher 16 bits only (wiimote)
wm_btns = t->wpad.btns_d << 16;
wm_btns_h = t->wpad.btns_h << 16;
wm_btns_trig = trigger[i]->wpad.btns_h << 16;
// lower 16 bits only (classic controller)
cc_btns = t->wpad.btns_d >> 16;
cc_btns_h = t->wpad.btns_h >> 16;
cc_btns_trig = trigger[i]->wpad.btns_h >> 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_h && t->pad.btns_d > 0))
{
if(trigger[i]->type == TRIGGER_HELD && state == STATE_SELECTED &&
(t->chan == stateChan || stateChan == -1))
this->SetState(STATE_CLICKED, t->chan);
}
if(
(t->wpad.btns_h > 0 &&
(wm_btns_h == wm_btns_trig ||
(cc_btns_h == cc_btns_trig && t->wpad.exp.type == EXP_CLASSIC))) ||
(t->pad.btns_h == trigger[i]->pad.btns_h && t->pad.btns_h > 0))
{
if(trigger[i]->type == TRIGGER_HELD)
held = true;
}
if(!held && state == STATE_HELD && stateChan == t->chan)
{
this->ResetState();
}
else if(held && state == STATE_CLICKED && stateChan == t->chan)
{
this->SetState(STATE_HELD, t->chan);
}
}
}
}
if(updateCB)
updateCB(this);
}

View File

@ -0,0 +1,570 @@
/****************************************************************************
* libwiigui
*
* Tantric 2009
*
* gui_element.cpp
*
* GUI class definitions
***************************************************************************/
#include "gui.h"
/**
* Constructor for the Object class.
*/
GuiElement::GuiElement()
{
xoffset = 0;
yoffset = 0;
xmin = 0;
xmax = 0;
ymin = 0;
ymax = 0;
width = 0;
height = 0;
alpha = 255;
scale = 1;
state = STATE_DEFAULT;
stateChan = -1;
trigger[0] = NULL;
trigger[1] = NULL;
parentElement = NULL;
rumble = true;
selectable = false;
clickable = false;
holdable = 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;
}
GuiElement * GuiElement::GetParent()
{
return parentElement;
}
/**
* 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;
}
void GuiElement::SetMinX(int x)
{
xmin = x;
}
int GuiElement::GetMinX()
{
return xmin;
}
void GuiElement::SetMaxX(int x)
{
xmax = x;
}
int GuiElement::GetMaxX()
{
return xmax;
}
void GuiElement::SetMinY(int y)
{
ymin = y;
}
int GuiElement::GetMinY()
{
return ymin;
}
void GuiElement::SetMaxY(int y)
{
ymax = y;
}
int GuiElement::GetMaxY()
{
return ymax;
}
/**
* 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;
}
int GuiElement::GetStateChan()
{
return stateChan;
}
void GuiElement::SetState(int s, int c)
{
state = s;
stateChan = c;
}
void GuiElement::ResetState()
{
if(state != STATE_DISABLED)
{
state = STATE_DEFAULT;
stateChan = -1;
}
}
void GuiElement::SetClickable(bool c)
{
clickable = c;
}
void GuiElement::SetSelectable(bool s)
{
selectable = s;
}
void GuiElement::SetHoldable(bool d)
{
holdable = d;
}
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 ||
state == STATE_HELD)
return false;
else
return clickable;
}
bool GuiElement::IsHoldable()
{
if(state == STATE_DISABLED)
return false;
else
return holdable;
}
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;
}

View File

@ -0,0 +1,242 @@
/****************************************************************************
* libwiigui
*
* Tantric 2009
*
* gui_image.cpp
*
* GUI class definitions
***************************************************************************/
#include "gui.h"
/**
* Constructor for the GuiImage class.
*/
GuiImage::GuiImage()
{
image = NULL;
width = 0;
height = 0;
imageangle = 0;
tile = -1;
stripe = 0;
imgType = IMAGE_DATA;
}
GuiImage::GuiImage(GuiImageData * img)
{
image = NULL;
width = 0;
height = 0;
if(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 = NULL;
width = 0;
height = 0;
if(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();
}

View File

@ -0,0 +1,84 @@
/****************************************************************************
* libwiigui
*
* Tantric 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;
}

View File

@ -0,0 +1,362 @@
/****************************************************************************
* libwiigui
*
* Tantric 2009
*
* gui_keyboard.cpp
*
* GUI class definitions
***************************************************************************/
#include "gui.h"
static char tmptxt[MAX_KEYBOARD_DISPLAY];
static char * GetDisplayText(char * t)
{
if(!t)
return NULL;
int len = strlen(t);
if(len < MAX_KEYBOARD_DISPLAY)
return t;
strncpy(tmptxt, &t[len-MAX_KEYBOARD_DISPLAY], MAX_KEYBOARD_DISPLAY);
tmptxt[MAX_KEYBOARD_DISPLAY-1] = 0;
return &tmptxt[0];
}
/**
* Constructor for the GuiKeyboard class.
*/
GuiKeyboard::GuiKeyboard(char * t, u32 max)
{
width = 540;
height = 400;
shift = 0;
caps = 0;
selectable = true;
focus = 0; // allow focus
alignmentHor = ALIGN_CENTRE;
alignmentVert = ALIGN_MIDDLE;
strncpy(kbtextstr, t, max);
kbtextstr[max] = 0;
kbtextmaxlen = max;
Key thekeys[4][11] = {
{
{'1','!'},
{'2','@'},
{'3','#'},
{'4','$'},
{'5','%'},
{'6','^'},
{'7','&'},
{'8','*'},
{'9','('},
{'0',')'},
{'\0','\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'},
{',','<'},
{'.','>'},
{'/','?'},
{'\0','\0'}
}
};
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(GetDisplayText(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);
keySoundClick = new GuiSound(button_click_pcm, button_click_pcm_size, SOUND_PCM);
trigA = new GuiTrigger;
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->SetSoundClick(keySoundClick);
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->SetSoundClick(keySoundClick);
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->SetSoundClick(keySoundClick);
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->SetSoundClick(keySoundClick);
keySpace->SetTrigger(trigA);
keySpace->SetPosition(0, 4*42+80);
keySpace->SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
keySpace->SetEffectGrow();
this->Append(keySpace);
char txt[2] = { 0, 0 };
for(int i=0; i<4; i++)
{
for(int j=0; j<11; j++)
{
if(keys[i][j].ch != '\0')
{
txt[0] = keys[i][j].ch;
keyImg[i][j] = new GuiImage(key);
keyImgOver[i][j] = new GuiImage(keyOver);
keyTxt[i][j] = new GuiText(txt, 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]->SetSoundClick(keySoundClick);
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 keySoundClick;
delete trigA;
for(int i=0; i<4; i++)
{
for(int j=0; j<11; j++)
{
if(keys[i][j].ch != '\0')
{
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 (const std::exception& e) { }
}
bool update = false;
if(keySpace->GetState() == STATE_CLICKED)
{
if(strlen(kbtextstr) < kbtextmaxlen)
{
kbtextstr[strlen(kbtextstr)] = ' ';
kbText->SetText(kbtextstr);
}
keySpace->SetState(STATE_SELECTED, t->chan);
}
else if(keyBack->GetState() == STATE_CLICKED)
{
kbtextstr[strlen(kbtextstr)-1] = 0;
kbText->SetText(GetDisplayText(kbtextstr));
keyBack->SetState(STATE_SELECTED, t->chan);
}
else if(keyShift->GetState() == STATE_CLICKED)
{
shift ^= 1;
keyShift->SetState(STATE_SELECTED, t->chan);
update = true;
}
else if(keyCaps->GetState() == STATE_CLICKED)
{
caps ^= 1;
keyCaps->SetState(STATE_SELECTED, t->chan);
update = true;
}
char txt[2] = { 0, 0 };
startloop:
for(int i=0; i<4; i++)
{
for(int j=0; j<11; j++)
{
if(keys[i][j].ch != '\0')
{
if(update)
{
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(strlen(kbtextstr) < kbtextmaxlen)
{
if(shift || caps)
{
kbtextstr[strlen(kbtextstr)] = keys[i][j].chShift;
}
else
{
kbtextstr[strlen(kbtextstr)] = keys[i][j].ch;
}
}
kbText->SetText(GetDisplayText(kbtextstr));
keyBtn[i][j]->SetState(STATE_SELECTED, t->chan);
if(shift)
{
shift ^= 1;
update = true;
goto startloop;
}
}
}
}
}
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);
}
}

View File

@ -0,0 +1,143 @@
/****************************************************************************
* libwiigui
*
* Tantric 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;
loop = false;
}
/**
* Destructor for the GuiSound class.
*/
GuiSound::~GuiSound()
{
if(type == SOUND_OGG)
StopOgg();
}
void GuiSound::Play()
{
int vol;
switch(type)
{
case SOUND_PCM:
vol = 255*(volume/100.0);
voice = ASND_GetFirstUnusedVoice();
if(voice >= 0)
ASND_SetVoice(voice, VOICE_STEREO_16BIT, 48000, 0,
(u8 *)sound, length, vol, vol, NULL);
break;
case SOUND_OGG:
voice = 0;
if(loop)
PlayOgg((char *)sound, length, 0, OGG_INFINITE_TIME);
else
PlayOgg((char *)sound, length, 0, OGG_ONE_TIME);
SetVolumeOgg(255*(volume/100.0));
break;
}
}
void GuiSound::Stop()
{
if(voice < 0)
return;
switch(type)
{
case SOUND_PCM:
ASND_StopVoice(voice);
break;
case SOUND_OGG:
StopOgg();
break;
}
}
void GuiSound::Pause()
{
if(voice < 0)
return;
switch(type)
{
case SOUND_PCM:
ASND_PauseVoice(voice, 1);
break;
case SOUND_OGG:
PauseOgg(1);
break;
}
}
void GuiSound::Resume()
{
if(voice < 0)
return;
switch(type)
{
case SOUND_PCM:
ASND_PauseVoice(voice, 0);
break;
case SOUND_OGG:
PauseOgg(0);
break;
}
}
bool GuiSound::IsPlaying()
{
if(ASND_StatusVoice(voice) == SND_WORKING || ASND_StatusVoice(voice) == SND_WAITING)
return true;
else
return false;
}
void GuiSound::SetVolume(int vol)
{
volume = vol;
if(voice < 0)
return;
int newvol = 255*(volume/100.0);
switch(type)
{
case SOUND_PCM:
ASND_ChangeVolumeVoice(voice, newvol, newvol);
break;
case SOUND_OGG:
SetVolumeOgg(255*(volume/100.0));
break;
}
}
void GuiSound::SetLoop(bool l)
{
loop = l;
}

View File

@ -0,0 +1,348 @@
/****************************************************************************
* libwiigui
*
* Tantric 2009
*
* gui_text.cpp
*
* GUI class definitions
***************************************************************************/
#include "gui.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};
#define TEXT_SCROLL_DELAY 8
#define TEXT_SCROLL_INITIAL_DELAY 6
/**
* Constructor for the GuiText class.
*/
GuiText::GuiText(const char * t, int s, GXColor c)
{
origText = NULL;
text = NULL;
size = s;
color = c;
alpha = c.a;
style = FTGX_JUSTIFY_CENTER | FTGX_ALIGN_MIDDLE;
maxWidth = 0;
wrap = false;
textDyn = NULL;
textScroll = SCROLL_NONE;
textScrollPos = 0;
textScrollInitialDelay = TEXT_SCROLL_INITIAL_DELAY;
textScrollDelay = TEXT_SCROLL_DELAY;
alignmentHor = ALIGN_CENTRE;
alignmentVert = ALIGN_MIDDLE;
if(t)
{
origText = strdup(t);
text = charToWideChar(t);
}
}
/**
* Constructor for the GuiText class, uses presets
*/
GuiText::GuiText(const char * t)
{
origText = NULL;
text = NULL;
size = presetSize;
color = presetColor;
alpha = presetColor.a;
style = presetStyle;
maxWidth = presetMaxWidth;
wrap = false;
textDyn = NULL;
textScroll = SCROLL_NONE;
textScrollPos = 0;
textScrollInitialDelay = TEXT_SCROLL_INITIAL_DELAY;
textScrollDelay = TEXT_SCROLL_DELAY;
alignmentHor = presetAlignmentHor;
alignmentVert = presetAlignmentVert;
if(t)
{
origText = strdup(t);
text = charToWideChar(t);
}
}
/**
* Destructor for the GuiText class.
*/
GuiText::~GuiText()
{
if(origText)
free(origText);
if(text)
delete[] text;
if(textDyn)
delete[] textDyn;
}
void GuiText::SetText(const char * t)
{
if(origText)
free(origText);
if(text)
delete[] text;
if(textDyn)
delete[] textDyn;
origText = NULL;
text = NULL;
textDyn = NULL;
textScrollPos = 0;
textScrollInitialDelay = TEXT_SCROLL_INITIAL_DELAY;
if(t)
{
origText = strdup(t);
text = charToWideChar(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 width)
{
maxWidth = width;
}
void GuiText::SetWrap(bool w, int width)
{
wrap = w;
maxWidth = width;
}
void GuiText::SetScroll(int s)
{
if(textScroll == s)
return;
if(textDyn)
{
delete[] textDyn;
textDyn = NULL;
}
textScroll = s;
textScrollPos = 0;
textScrollInitialDelay = TEXT_SCROLL_INITIAL_DELAY;
textScrollDelay = TEXT_SCROLL_DELAY;
}
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 > MAX_FONT_SIZE)
newSize = MAX_FONT_SIZE;
if(newSize != currentSize)
{
ChangeFontSize(newSize);
if(!fontSystem[newSize])
fontSystem[newSize] = new FreeTypeGX(newSize);
currentSize = newSize;
}
if(maxWidth > 0)
{
char * tmpText = strdup(origText);
u8 maxChar = (maxWidth*2.0) / newSize;
if(!textDyn)
{
if(strlen(tmpText) > maxChar)
tmpText[maxChar] = 0;
textDyn = charToWideChar(tmpText);
}
if(textScroll == SCROLL_HORIZONTAL)
{
int textlen = strlen(origText);
if(textlen > maxChar && (FrameTimer % textScrollDelay == 0))
{
if(textScrollInitialDelay)
{
textScrollInitialDelay--;
}
else
{
textScrollPos++;
if(textScrollPos > textlen-1)
{
textScrollPos = 0;
textScrollInitialDelay = TEXT_SCROLL_INITIAL_DELAY;
}
strncpy(tmpText, &origText[textScrollPos], maxChar-1);
tmpText[maxChar-1] = 0;
int dynlen = strlen(tmpText);
if(dynlen+2 < maxChar)
{
tmpText[dynlen] = ' ';
tmpText[dynlen+1] = ' ';
strncat(&tmpText[dynlen+2], origText, maxChar - dynlen - 2);
}
if(textDyn) delete[] textDyn;
textDyn = charToWideChar(tmpText);
}
}
if(textDyn)
fontSystem[currentSize]->drawText(this->GetLeft(), this->GetTop(), textDyn, c, style);
}
else if(wrap)
{
int lineheight = newSize + 6;
int txtlen = wcslen(text);
int i = 0;
int ch = 0;
int linenum = 0;
int lastSpace = -1;
int lastSpaceIndex = -1;
wchar_t * textrow[20];
while(ch < txtlen)
{
if(i == 0)
textrow[linenum] = new wchar_t[txtlen + 1];
textrow[linenum][i] = text[ch];
textrow[linenum][i+1] = 0;
if(text[ch] == ' ' || ch == txtlen-1)
{
if(wcslen(textrow[linenum]) >= maxChar)
{
if(lastSpace >= 0)
{
textrow[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 == txtlen-1)
{
linenum++;
}
}
if(text[ch] == ' ' && i >= 0)
{
lastSpace = ch;
lastSpaceIndex = i;
}
ch++;
i++;
}
int voffset = 0;
if(alignmentVert == ALIGN_MIDDLE)
voffset = -(lineheight*linenum)/2 + lineheight/2;
for(i=0; i < linenum; i++)
{
fontSystem[currentSize]->drawText(this->GetLeft(), this->GetTop()+voffset+i*lineheight, textrow[i], c, style);
delete[] textrow[i];
}
}
else
{
fontSystem[currentSize]->drawText(this->GetLeft(), this->GetTop(), textDyn, c, style);
}
free(tmpText);
}
else
{
fontSystem[currentSize]->drawText(this->GetLeft(), this->GetTop(), text, c, style);
}
this->UpdateEffects();
}

View File

@ -0,0 +1,249 @@
/****************************************************************************
* libwiigui
*
* Tantric 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 held trigger. Requires:
* - Element is selected
* - Trigger button is pressed and held
*/
void GuiTrigger::SetHeldTrigger(s32 ch, u32 wiibtns, u16 gcbtns)
{
type = TRIGGER_HELD;
chan = ch;
wpad.btns_h = wiibtns;
pad.btns_h = 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)
{
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);
}
bool GuiTrigger::Left()
{
u32 wiibtn = 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
{
if(scrollDelay > 0)
scrollDelay--;
}
}
return false;
}
bool GuiTrigger::Right()
{
u32 wiibtn = 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
{
if(scrollDelay > 0)
scrollDelay--;
}
}
return false;
}
bool GuiTrigger::Up()
{
u32 wiibtn = 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
{
if(scrollDelay > 0)
scrollDelay--;
}
}
return false;
}
bool GuiTrigger::Down()
{
u32 wiibtn = 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
{
if(scrollDelay > 0)
scrollDelay--;
}
}
return false;
}

View File

@ -0,0 +1,404 @@
/****************************************************************************
* libwiigui
*
* Tantric 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 (const std::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 (const std::exception& e) { }
}
}
void GuiWindow::SetState(int s)
{
state = s;
for (u8 i = 0; i < _elements.size(); i++)
{
try { _elements.at(i)->SetState(s); }
catch (const std::exception& e) { }
}
}
void GuiWindow::SetVisible(bool v)
{
visible = v;
for (u8 i = 0; i < _elements.size(); i++)
{
try { _elements.at(i)->SetVisible(v); }
catch (const std::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 (const std::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 (const std::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 (const std::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 (const std::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 (const std::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 (const std::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 (const std::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 (const std::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 (const std::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);
}

591
src/platform/wii/menu.cpp Normal file
View File

@ -0,0 +1,591 @@
/****************************************************************************
* DOSBox Wii Home Menu
* Tantric 2009
*
* menu.cpp
*
* Menu flow routines - handles all menu logic
***************************************************************************/
#include <gccore.h>
#include <ogcsys.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <wiiuse/wpad.h>
#include <sys/stat.h>
#include <unistd.h>
#include "libwiigui/gui.h"
#include "wiihardware.h"
#define THREAD_SLEEP 100
#define APPVERSION "1.0"
static GuiImageData * pointer[4];
static GuiWindow * mainWindow = NULL;
static GuiButton * logoBtn = NULL;
static lwp_t guithread = LWP_THREAD_NULL;
static lwp_t creditsthread = LWP_THREAD_NULL;
static bool guiHalt = true;
static bool ExitRequested = false;
static bool creditsOpen = false;
/****************************************************************************
* UpdateGUI
*
* Primary thread to allow GUI to respond to state changes, and draws GUI
***************************************************************************/
static void * UpdateGUI (void *arg)
{
int i;
while(1)
{
if(guiHalt)
break;
UpdatePads();
mainWindow->Draw();
for(i=3; i >= 0; i--) // so that player 1's cursor appears on top!
{
if(userInput[i].wpad.ir.valid)
Menu_DrawImg(userInput[i].wpad.ir.x-48, userInput[i].wpad.ir.y-48,
96, 96, pointer[i]->GetImage(), userInput[i].wpad.ir.angle, 1, 1, 255);
DoRumble(i);
}
Menu_Render();
for(i=3; i >= 0; i--)
mainWindow->Update(&userInput[i]);
if(!creditsOpen && creditsthread != LWP_THREAD_NULL)
{
LWP_JoinThread(creditsthread, NULL);
creditsthread = LWP_THREAD_NULL;
}
if(ExitRequested)
{
for(i = 0; i < 255; i += 15)
{
mainWindow->Draw();
Menu_DrawRectangle(0,0,screenwidth,screenheight,(GXColor){0, 0, 0, i},1);
Menu_Render();
}
ShutoffRumble();
VIDEO_SetBlack(TRUE);
VIDEO_Flush();
throw(0);
}
usleep(THREAD_SLEEP);
}
return NULL;
}
/****************************************************************************
* ResumeGui
*
* Signals the GUI thread to start, and resumes the thread. This is called
* after finishing the removal/insertion of new elements, and after initial
* GUI setup.
***************************************************************************/
static void
ResumeGui()
{
guiHalt = false;
if(guithread == LWP_THREAD_NULL)
LWP_CreateThread (&guithread, UpdateGUI, NULL, NULL, 0, 66);
}
/****************************************************************************
* HaltGui
*
* Signals the GUI thread to stop, and waits for GUI thread to stop
* This is necessary whenever removing/inserting new elements into the GUI.
* This eliminates the possibility that the GUI is in the middle of accessing
* an element that is being changed.
***************************************************************************/
static void
HaltGui()
{
guiHalt = true;
if(guithread == LWP_THREAD_NULL)
return;
// wait for thread to finish
LWP_JoinThread(guithread, NULL);
guithread = LWP_THREAD_NULL;
}
/****************************************************************************
* OnScreenKeyboard
*
* Opens an on-screen keyboard window, with the data entered being stored
* into the specified variable.
***************************************************************************/
static void OnScreenKeyboard(char * var, u32 maxlen)
{
int save = -1;
GuiKeyboard keyboard(var, maxlen);
GuiSound btnSoundOver(button_over_pcm, button_over_pcm_size, SOUND_PCM);
GuiSound btnSoundClick(button_click_pcm, button_click_pcm_size, SOUND_PCM);
GuiImageData btnOutline(button_png);
GuiImageData btnOutlineOver(button_over_png);
GuiTrigger trigA;
trigA.SetSimpleTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A);
GuiText okBtnTxt("OK", 24, (GXColor){0, 0, 0, 255});
GuiImage okBtnImg(&btnOutline);
GuiImage okBtnImgOver(&btnOutlineOver);
GuiButton okBtn(btnOutline.GetWidth(), btnOutline.GetHeight());
okBtn.SetAlignment(ALIGN_LEFT, ALIGN_BOTTOM);
okBtn.SetPosition(25, -25);
okBtn.SetLabel(&okBtnTxt);
okBtn.SetImage(&okBtnImg);
okBtn.SetImageOver(&okBtnImgOver);
okBtn.SetSoundOver(&btnSoundOver);
okBtn.SetSoundClick(&btnSoundClick);
okBtn.SetTrigger(&trigA);
okBtn.SetEffectGrow();
GuiText cancelBtnTxt("Cancel", 24, (GXColor){0, 0, 0, 255});
GuiImage cancelBtnImg(&btnOutline);
GuiImage cancelBtnImgOver(&btnOutlineOver);
GuiButton cancelBtn(btnOutline.GetWidth(), btnOutline.GetHeight());
cancelBtn.SetAlignment(ALIGN_RIGHT, ALIGN_BOTTOM);
cancelBtn.SetPosition(-25, -25);
cancelBtn.SetLabel(&cancelBtnTxt);
cancelBtn.SetImage(&cancelBtnImg);
cancelBtn.SetImageOver(&cancelBtnImgOver);
cancelBtn.SetSoundOver(&btnSoundOver);
cancelBtn.SetSoundClick(&btnSoundClick);
cancelBtn.SetTrigger(&trigA);
cancelBtn.SetEffectGrow();
keyboard.Append(&okBtn);
keyboard.Append(&cancelBtn);
HaltGui();
mainWindow->SetState(STATE_DISABLED);
mainWindow->Append(&keyboard);
mainWindow->ChangeFocus(&keyboard);
ResumeGui();
while(save == -1)
{
usleep(THREAD_SLEEP);
if(okBtn.GetState() == STATE_CLICKED)
save = 1;
else if(cancelBtn.GetState() == STATE_CLICKED)
save = 0;
}
if(save)
{
snprintf(var, maxlen, "%s", keyboard.kbtextstr);
}
HaltGui();
mainWindow->Remove(&keyboard);
mainWindow->SetState(STATE_DEFAULT);
ResumeGui();
}
/****************************************************************************
* WindowCredits
* Display credits, legal copyright and licence
*
* THIS MUST NOT BE REMOVED OR DISABLED IN ANY DERIVATIVE WORK
***************************************************************************/
static void * WindowCredits(void *arg)
{
bool exit = false;
int i = 0;
int y = 20;
GuiWindow creditsWindow(528,408);
creditsWindow.SetAlignment(ALIGN_CENTRE, ALIGN_MIDDLE);
GuiImageData creditsBox(credits_box_png);
GuiImage creditsBoxImg(&creditsBox);
creditsBoxImg.SetAlignment(ALIGN_CENTRE, ALIGN_MIDDLE);
creditsWindow.Append(&creditsBoxImg);
int numEntries = 11;
GuiText * txt[numEntries];
txt[i] = new GuiText("Credits", 30, (GXColor){0, 0, 0, 255});
txt[i]->SetAlignment(ALIGN_CENTRE, ALIGN_TOP); txt[i]->SetPosition(0,y); i++; y+=32;
txt[i] = new GuiText("Official Site: http://code.google.com/p/dosbox-wii/", 20, (GXColor){0, 0, 0, 255});
txt[i]->SetAlignment(ALIGN_CENTRE, ALIGN_TOP); txt[i]->SetPosition(0,y); i++; y+=40;
txt[i]->SetPresets(20, (GXColor){0, 0, 0, 255}, 0,
FTGX_JUSTIFY_CENTER | FTGX_ALIGN_TOP, ALIGN_CENTRE, ALIGN_TOP);
txt[i] = new GuiText("Porting & Menu Coding:");
txt[i]->SetPosition(0,y); i++; y+=36;
txt[i] = new GuiText("Tantric");
txt[i]->SetPosition(0,y); i++; y+=60;
txt[i] = new GuiText("Thanks to:");
txt[i]->SetPosition(0,y); i++; y+=36;
txt[i] = new GuiText("DOSBox Team");
txt[i]->SetPosition(0,y); i++; y+=22;
txt[i] = new GuiText("shagkur & wintermute (libogc / devkitPPC)");
txt[i]->SetPosition(0,y); i++; y+=22;
txt[i] = new GuiText("Carl Kenner & Armin Tamzarian");
txt[i]->SetPosition(0,y); i++; y+=60;
txt[i]->SetPresets(18, (GXColor){0, 0, 0, 255}, 0,
FTGX_JUSTIFY_CENTER | FTGX_ALIGN_TOP, ALIGN_CENTRE, ALIGN_TOP);
txt[i] = new GuiText("This software is open source and may be copied,");
txt[i]->SetPosition(0,y); i++; y+=20;
txt[i] = new GuiText("distributed, or modified under the terms of the");
txt[i]->SetPosition(0,y); i++; y+=20;
txt[i] = new GuiText("GNU General Public License (GPL) Version 2.");
txt[i]->SetPosition(0,y); i++; y+=20;
for(i=0; i < numEntries; i++)
creditsWindow.Append(txt[i]);
HaltGui();
mainWindow->SetState(STATE_DISABLED);
mainWindow->Append(&creditsWindow);
mainWindow->ChangeFocus(&creditsWindow);
ResumeGui();
while(!exit)
{
for(i=0; i < 4; i++)
{
if(userInput[i].wpad.btns_d || userInput[i].pad.btns_d)
exit = true;
}
usleep(THREAD_SLEEP);
}
HaltGui();
mainWindow->Remove(&creditsWindow);
mainWindow->SetState(STATE_DEFAULT);
ResumeGui();
for(i=0; i < numEntries; i++)
delete txt[i];
creditsOpen = false;
return NULL;
}
static void DisplayCredits(void * ptr)
{
if(logoBtn->GetState() != STATE_CLICKED)
return;
logoBtn->ResetState();
// spawn a new thread to handle the Credits
creditsOpen = true;
if(creditsthread == LWP_THREAD_NULL)
LWP_CreateThread (&creditsthread, WindowCredits, NULL, NULL, 0, 60);
}
/****************************************************************************
* HomeMenu
***************************************************************************/
void HomeMenu ()
{
ResetVideo_Menu();
pointer[0] = new GuiImageData(player1_point_png);
pointer[1] = new GuiImageData(player2_point_png);
pointer[2] = new GuiImageData(player3_point_png);
pointer[3] = new GuiImageData(player4_point_png);
mainWindow = new GuiWindow(screenwidth, screenheight);
GuiImage screenImg(screenTex, screenwidth, screenheight);
screenImg.SetAlpha(192);
screenImg.ColorStripe(30);
GuiTrigger trigA;
trigA.SetSimpleTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A);
GuiTrigger trigHome;
trigHome.SetButtonOnlyTrigger(-1, WPAD_BUTTON_HOME | WPAD_CLASSIC_BUTTON_HOME, 0);
GuiSound btnSoundOver(button_over_pcm, button_over_pcm_size, SOUND_PCM);
GuiSound btnSoundClick(button_click_pcm, button_click_pcm_size, SOUND_PCM);
GuiSound enterSound(enter_ogg, enter_ogg_size, SOUND_OGG);
GuiSound exitSound(exit_ogg, exit_ogg_size, SOUND_OGG);
GuiImageData btnLargeOutline(button_large_png);
GuiImageData btnLargeOutlineOver(button_large_over_png);
GuiImageData btnCloseOutline(button_small_png);
GuiImageData btnCloseOutlineOver(button_small_over_png);
GuiImageData battery(battery_png);
GuiImageData batteryRed(battery_red_png);
GuiImageData batteryBar(battery_bar_png);
GuiImageData bgTop(bg_top_png);
GuiImage bgTopImg(&bgTop);
GuiImageData bgBottom(bg_bottom_png);
GuiImage bgBottomImg(&bgBottom);
bgBottomImg.SetAlignment(ALIGN_LEFT, ALIGN_BOTTOM);
GuiImageData logo(logo_png);
GuiImage logoImg(&logo);
GuiImageData logoOver(logo_over_png);
GuiImage logoImgOver(&logoOver);
GuiText logoTxt(APPVERSION, 18, (GXColor){255, 255, 255, 255});
logoTxt.SetAlignment(ALIGN_RIGHT, ALIGN_TOP);
logoTxt.SetPosition(30, 31);
logoBtn = new GuiButton(logoImg.GetWidth(), logoImg.GetHeight());
logoBtn->SetAlignment(ALIGN_RIGHT, ALIGN_BOTTOM);
logoBtn->SetPosition(-85, -40);
logoBtn->SetImage(&logoImg);
logoBtn->SetImageOver(&logoImgOver);
logoBtn->SetLabel(&logoTxt);
logoBtn->SetSoundOver(&btnSoundOver);
logoBtn->SetSoundClick(&btnSoundClick);
logoBtn->SetTrigger(&trigA);
logoBtn->SetUpdateCallback(DisplayCredits);
GuiText exitBtnTxt("Exit", 24, (GXColor){0, 0, 0, 255});
GuiImage exitBtnImg(&btnLargeOutline);
GuiImage exitBtnImgOver(&btnLargeOutlineOver);
GuiButton exitBtn(btnLargeOutline.GetWidth(), btnLargeOutline.GetHeight());
exitBtn.SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
exitBtn.SetPosition(-125, 120);
exitBtn.SetLabel(&exitBtnTxt);
exitBtn.SetImage(&exitBtnImg);
exitBtn.SetImageOver(&exitBtnImgOver);
exitBtn.SetSoundOver(&btnSoundOver);
exitBtn.SetSoundClick(&btnSoundClick);
exitBtn.SetTrigger(&trigA);
exitBtn.SetEffectGrow();
GuiText keyboardBtnTxt("Keyboard", 24, (GXColor){0, 0, 0, 255});
GuiImage keyboardBtnImg(&btnLargeOutline);
GuiImage keyboardBtnImgOver(&btnLargeOutlineOver);
GuiButton keyboardBtn(btnLargeOutline.GetWidth(), btnLargeOutline.GetHeight());
keyboardBtn.SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
keyboardBtn.SetPosition(125, 120);
keyboardBtn.SetLabel(&keyboardBtnTxt);
keyboardBtn.SetImage(&keyboardBtnImg);
keyboardBtn.SetImageOver(&keyboardBtnImgOver);
keyboardBtn.SetSoundOver(&btnSoundOver);
keyboardBtn.SetSoundClick(&btnSoundClick);
keyboardBtn.SetTrigger(&trigA);
keyboardBtn.SetEffectGrow();
GuiText closeBtnTxt("Close", 22, (GXColor){0, 0, 0, 255});
GuiImage closeBtnImg(&btnCloseOutline);
GuiImage closeBtnImgOver(&btnCloseOutlineOver);
GuiButton closeBtn(btnCloseOutline.GetWidth(), btnCloseOutline.GetHeight());
closeBtn.SetAlignment(ALIGN_RIGHT, ALIGN_TOP);
closeBtn.SetPosition(-50, 35);
closeBtn.SetLabel(&closeBtnTxt);
closeBtn.SetImage(&closeBtnImg);
closeBtn.SetImageOver(&closeBtnImgOver);
closeBtn.SetSoundOver(&btnSoundOver);
closeBtn.SetSoundClick(&btnSoundClick);
closeBtn.SetTrigger(&trigA);
closeBtn.SetTrigger(&trigHome);
closeBtn.SetEffectGrow();
int i;
char txt[3];
bool status[4] = { false, false, false, false };
int level[4] = { 0, 0, 0, 0 };
bool newStatus;
int newLevel;
GuiText * batteryTxt[4];
GuiImage * batteryImg[4];
GuiImage * batteryBarImg[4];
GuiButton * batteryBtn[4];
for(i=0; i < 4; i++)
{
if(i == 0)
sprintf(txt, "P %d", i+1);
else
sprintf(txt, "P%d", i+1);
batteryTxt[i] = new GuiText(txt, 22, (GXColor){255, 255, 255, 255});
batteryTxt[i]->SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE);
batteryImg[i] = new GuiImage(&battery);
batteryImg[i]->SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE);
batteryImg[i]->SetPosition(30, 0);
batteryBarImg[i] = new GuiImage(&batteryBar);
batteryBarImg[i]->SetTile(0);
batteryBarImg[i]->SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE);
batteryBarImg[i]->SetPosition(34, 0);
batteryBtn[i] = new GuiButton(70, 20);
batteryBtn[i]->SetLabel(batteryTxt[i]);
batteryBtn[i]->SetImage(batteryImg[i]);
batteryBtn[i]->SetIcon(batteryBarImg[i]);
batteryBtn[i]->SetAlignment(ALIGN_LEFT, ALIGN_BOTTOM);
batteryBtn[i]->SetRumble(false);
batteryBtn[i]->SetSelectable(false);
batteryBtn[i]->SetAlpha(150);
}
batteryBtn[0]->SetPosition(45, -65);
batteryBtn[1]->SetPosition(135, -65);
batteryBtn[2]->SetPosition(45, -40);
batteryBtn[3]->SetPosition(135, -40);
GuiWindow w(screenwidth, screenheight);
w.Append(&bgTopImg);
w.Append(&bgBottomImg);
w.Append(batteryBtn[0]);
w.Append(batteryBtn[1]);
w.Append(batteryBtn[2]);
w.Append(batteryBtn[3]);
w.Append(logoBtn);
w.Append(&closeBtn);
w.Append(&exitBtn);
w.Append(&keyboardBtn);
mainWindow->Append(&screenImg);
mainWindow->Append(&w);
enterSound.Play();
bgTopImg.SetEffect(EFFECT_SLIDE_TOP | EFFECT_SLIDE_IN, 35);
closeBtn.SetEffect(EFFECT_SLIDE_TOP | EFFECT_SLIDE_IN, 35);
bgBottomImg.SetEffect(EFFECT_SLIDE_BOTTOM | EFFECT_SLIDE_IN, 35);
logoBtn->SetEffect(EFFECT_SLIDE_BOTTOM | EFFECT_SLIDE_IN, 35);
batteryBtn[0]->SetEffect(EFFECT_SLIDE_BOTTOM | EFFECT_SLIDE_IN, 35);
batteryBtn[1]->SetEffect(EFFECT_SLIDE_BOTTOM | EFFECT_SLIDE_IN, 35);
batteryBtn[2]->SetEffect(EFFECT_SLIDE_BOTTOM | EFFECT_SLIDE_IN, 35);
batteryBtn[3]->SetEffect(EFFECT_SLIDE_BOTTOM | EFFECT_SLIDE_IN, 35);
w.SetEffect(EFFECT_FADE, 15);
ResumeGui();
while(1)
{
usleep(THREAD_SLEEP);
for(i=0; i < 4; i++)
{
if(WPAD_Probe(i, NULL) == WPAD_ERR_NONE)
{
newStatus = true;
newLevel = (userInput[i].wpad.battery_level / 100.0) * 4;
if(newLevel > 4) newLevel = 4;
}
else
{
newStatus = false;
newLevel = 0;
}
if(status[i] != newStatus || level[i] != newLevel)
{
if(newStatus == true) // controller connected
{
batteryBtn[i]->SetAlpha(255);
batteryBarImg[i]->SetTile(newLevel);
if(newLevel == 0)
batteryImg[i]->SetImage(&batteryRed);
else
batteryImg[i]->SetImage(&battery);
}
else // controller not connected
{
batteryBtn[i]->SetAlpha(150);
batteryBarImg[i]->SetTile(0);
batteryImg[i]->SetImage(&battery);
}
status[i] = newStatus;
level[i] = newLevel;
}
}
if(closeBtn.GetState() == STATE_CLICKED)
{
exitSound.Play();
bgTopImg.SetEffect(EFFECT_SLIDE_TOP | EFFECT_SLIDE_OUT, 15);
closeBtn.SetEffect(EFFECT_SLIDE_TOP | EFFECT_SLIDE_OUT, 15);
bgBottomImg.SetEffect(EFFECT_SLIDE_BOTTOM | EFFECT_SLIDE_OUT, 15);
logoBtn->SetEffect(EFFECT_SLIDE_BOTTOM | EFFECT_SLIDE_OUT, 15);
batteryBtn[0]->SetEffect(EFFECT_SLIDE_BOTTOM | EFFECT_SLIDE_OUT, 15);
batteryBtn[1]->SetEffect(EFFECT_SLIDE_BOTTOM | EFFECT_SLIDE_OUT, 15);
batteryBtn[2]->SetEffect(EFFECT_SLIDE_BOTTOM | EFFECT_SLIDE_OUT, 15);
batteryBtn[3]->SetEffect(EFFECT_SLIDE_BOTTOM | EFFECT_SLIDE_OUT, 15);
w.SetEffect(EFFECT_FADE, -15);
usleep(450000); // wait for effects to finish
break;
}
else if(exitBtn.GetState() == STATE_CLICKED)
{
ExitRequested = 1;
}
else if(keyboardBtn.GetState() == STATE_CLICKED)
{
keyboardBtn.ResetState();
OnScreenKeyboard(dosboxCommand, MAXPATHLEN);
if(dosboxCommand[0] != 0)
break;
}
}
ShutoffRumble();
// wait for keys to be depressed
while(MenuRequested())
usleep(THREAD_SLEEP);
exitSound.Stop();
HaltGui();
for(i=0; i < 4; i++)
{
delete batteryTxt[i];
delete batteryImg[i];
delete batteryBarImg[i];
delete batteryBtn[i];
}
delete mainWindow;
delete logoBtn;
delete pointer[0];
delete pointer[1];
delete pointer[2];
delete pointer[3];
mainWindow = NULL;
if(screenTex)
{
free(screenTex);
screenTex = NULL;
}
}

View File

@ -0,0 +1,539 @@
/*
Copyright (c) 2008 Francisco Muñoz 'Hermes' <www.elotrolado.net>
All rights reserved.
Proper (standard) vorbis usage by Tantric, 2009
Threading modifications/corrections by Tantric, 2009
Redistribution and use in source and binary forms, with or without modification, are
permitted provided that the following conditions are met:
- Redistributions of source code must retain the above copyright notice, this list of
conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright notice, this list
of conditions and the following disclaimer in the documentation and/or other
materials provided with the distribution.
- The names of the contributors may not be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef NO_SOUND
#include "oggplayer.h"
#include <gccore.h>
#include <unistd.h>
#include <string.h>
/* functions to read the Ogg file from memory */
static struct
{
char *mem;
int size;
int pos;
} file[4];
static int f_read(void * punt, int bytes, int blocks, int *f)
{
int b;
int c;
int d;
if (bytes * blocks <= 0)
return 0;
blocks = bytes * blocks;
c = 0;
while (blocks > 0)
{
b = blocks;
if (b > 4096)
b = 4096;
if (*f >= 0x666 && *f <= 0x669)
{
d = (*f) - 0x666;
if (file[d].size == 0)
return -1;
if ((file[d].pos + b) > file[d].size)
b = file[d].size - file[d].pos;
if (b > 0)
{
memcpy(punt, file[d].mem + file[d].pos, b);
file[d].pos += b;
}
}
else
b = read(*f, ((char *) punt) + c, b);
if (b <= 0)
{
return c / bytes;
}
c += b;
blocks -= b;
}
return c / bytes;
}
static int f_seek(int *f, ogg_int64_t offset, int mode)
{
if(f==NULL) return(-1);
int k, d;
mode &= 3;
if (*f >= 0x666 && *f <= 0x669)
{
d = (*f) - 0x666;
k = 0;
if (file[d].size == 0)
return -1;
if (mode == 0)
{
if ((offset) >= file[d].size)
{
file[d].pos = file[d].size;
k = -1;
}
else if ((offset) < 0)
{
file[d].pos = 0;
k = -1;
}
else
file[d].pos = offset;
}
if (mode == 1)
{
if ((file[d].pos + offset) >= file[d].size)
{
file[d].pos = file[d].size;
k = -1;
}
else if ((file[d].pos + offset) < 0)
{
file[d].pos = 0;
k = -1;
}
else
file[d].pos += offset;
}
if (mode == 2)
{
if ((file[d].size + offset) >= file[d].size)
{
file[d].pos = file[d].size;
k = -1;
}
else if ((file[d].size + offset) < 0)
{
file[d].pos = 0;
k = -1;
}
else
file[d].pos = file[d].size + offset;
}
}
else
k = lseek(*f, (int) offset, mode);
if (k < 0)
k = -1;
else
k = 0;
return k;
}
static int f_close(int *f)
{
int d;
if (*f >= 0x666 && *f <= 0x669)
{
d = (*f) - 0x666;
file[d].size = 0;
file[d].pos = 0;
if (file[d].mem)
{
file[d].mem = (void *) 0;
}
return 0;
}
else
return close(*f);
return 0;
}
static long f_tell(int *f)
{
int k, d;
if (*f >= 0x666 && *f <= 0x669)
{
d = (*f) - 0x666;
k = file[d].pos;
}
else
k = lseek(*f, 0, 1);
return (long) k;
}
static int mem_open(char * ogg, int size)
{
static int one = 1;
int n;
if (one)
{
one = 0;
for (n = 0; n < 4; n++)
file[n].size = 0;
}
for (n = 0; n < 4; n++)
{
if (file[n].size == 0)
{
file[n].mem = ogg;
file[n].size = size;
file[n].pos = 0;
return (0x666 + n);
}
}
return -1;
}
static int mem_close(int fd)
{
if (fd >= 0x666 && fd <= 0x669) // it is a memory file descriptor?
{
fd -= 0x666;
file[fd].size = 0;
return 0;
}
else
return f_close(&fd);
}
static ov_callbacks callbacks = {
(size_t (*)(void *, size_t, size_t, void *)) f_read,
(int (*)(void *, ogg_int64_t, int)) f_seek,
(int (*)(void *)) f_close,
(long (*)(void *)) f_tell
};
/* OGG control */
#define READ_SAMPLES 4096 // samples that it must read before to send
#define MAX_PCMOUT 4096 // minimum size to read ogg samples
typedef struct
{
OggVorbis_File vf;
vorbis_info *vi;
int current_section;
// OGG file operation
int fd;
int mode;
int eof;
int flag;
int volume;
int seek_time;
/* OGG buffer control */
short pcmout[2][READ_SAMPLES + MAX_PCMOUT * 2]; /* take 4k out of the data segment, not the stack */
int pcmout_pos;
int pcm_indx;
} private_data_ogg;
static private_data_ogg private_ogg;
// OGG thread control
#define STACKSIZE 8192
static u8 oggplayer_stack[STACKSIZE];
static lwpq_t oggplayer_queue = LWP_TQUEUE_NULL;
static lwp_t h_oggplayer = LWP_THREAD_NULL;
static int ogg_thread_running = 0;
static void ogg_add_callback(int voice)
{
if (!ogg_thread_running)
{
ASND_StopVoice(0);
return;
}
if (private_ogg.flag & 128)
return; // Ogg is paused
if (private_ogg.pcm_indx >= READ_SAMPLES)
{
if (ASND_AddVoice(0,
(void *) private_ogg.pcmout[private_ogg.pcmout_pos],
private_ogg.pcm_indx << 1) == 0)
{
private_ogg.pcmout_pos ^= 1;
private_ogg.pcm_indx = 0;
private_ogg.flag = 0;
LWP_ThreadSignal(oggplayer_queue);
}
}
else
{
if (private_ogg.flag & 64)
{
private_ogg.flag &= ~64;
LWP_ThreadSignal(oggplayer_queue);
}
}
}
static void * ogg_player_thread(private_data_ogg * priv)
{
int first_time = 1;
long ret;
//init
LWP_InitQueue(&oggplayer_queue);
priv[0].vi = ov_info(&priv[0].vf, -1);
ASND_Pause(0);
priv[0].pcm_indx = 0;
priv[0].pcmout_pos = 0;
priv[0].eof = 0;
priv[0].flag = 0;
priv[0].current_section = 0;
ogg_thread_running = 1;
while (!priv[0].eof && ogg_thread_running)
{
if (priv[0].flag)
LWP_ThreadSleep(oggplayer_queue); // wait only when i have samples to send
if (priv[0].flag == 0) // wait to all samples are sent
{
if (ASND_TestPointer(0, priv[0].pcmout[priv[0].pcmout_pos])
&& ASND_StatusVoice(0) != SND_UNUSED)
{
priv[0].flag |= 64;
continue;
}
if (priv[0].pcm_indx < READ_SAMPLES)
{
priv[0].flag = 3;
if (priv[0].seek_time >= 0)
{
ov_time_seek(&priv[0].vf, priv[0].seek_time);
priv[0].seek_time = -1;
}
ret
= ov_read(
&priv[0].vf,
(void *) &priv[0].pcmout[priv[0].pcmout_pos][priv[0].pcm_indx],
MAX_PCMOUT,/*0,2,1,*/&priv[0].current_section);
priv[0].flag &= 192;
if (ret == 0)
{
/* EOF */
if (priv[0].mode & 1)
ov_time_seek(&priv[0].vf, 0); // repeat
else
priv[0].eof = 1; // stops
}
else if (ret < 0)
{
/* error in the stream. Not a problem, just reporting it in
case we (the app) cares. In this case, we don't. */
if (ret != OV_HOLE)
{
if (priv[0].mode & 1)
ov_time_seek(&priv[0].vf, 0); // repeat
else
priv[0].eof = 1; // stops
}
}
else
{
/* we don't bother dealing with sample rate changes, etc, but
you'll have to*/
priv[0].pcm_indx += ret >> 1; //get 16 bits samples
}
}
else
priv[0].flag = 1;
}
if (priv[0].flag == 1)
{
if (ASND_StatusVoice(0) == SND_UNUSED || first_time)
{
first_time = 0;
if (priv[0].vi->channels == 2)
{
ASND_SetVoice(0, VOICE_STEREO_16BIT, priv[0].vi->rate, 0,
(void *) priv[0].pcmout[priv[0].pcmout_pos],
priv[0].pcm_indx << 1, priv[0].volume,
priv[0].volume, ogg_add_callback);
priv[0].pcmout_pos ^= 1;
priv[0].pcm_indx = 0;
priv[0].flag = 0;
}
else
{
ASND_SetVoice(0, VOICE_MONO_16BIT, priv[0].vi->rate, 0,
(void *) priv[0].pcmout[priv[0].pcmout_pos],
priv[0].pcm_indx << 1, priv[0].volume,
priv[0].volume, ogg_add_callback);
priv[0].pcmout_pos ^= 1;
priv[0].pcm_indx = 0;
priv[0].flag = 0;
}
}
}
usleep(100);
}
ov_clear(&priv[0].vf);
priv[0].fd = -1;
priv[0].pcm_indx = 0;
return 0;
}
void StopOgg()
{
ASND_StopVoice(0);
ogg_thread_running = 0;
if(h_oggplayer != LWP_THREAD_NULL)
{
if(oggplayer_queue != LWP_TQUEUE_NULL)
LWP_ThreadSignal(oggplayer_queue);
LWP_JoinThread(h_oggplayer, NULL);
h_oggplayer = LWP_THREAD_NULL;
}
if(oggplayer_queue != LWP_TQUEUE_NULL)
{
LWP_CloseQueue(oggplayer_queue);
oggplayer_queue = LWP_TQUEUE_NULL;
}
}
int PlayOgg(char * buf, int buflen, int time_pos, int mode)
{
StopOgg();
private_ogg.fd = mem_open(buf, buflen);
if (private_ogg.fd < 0)
{
private_ogg.fd = -1;
return -1;
}
private_ogg.mode = mode;
private_ogg.eof = 0;
private_ogg.volume = 127;
private_ogg.flag = 0;
private_ogg.seek_time = -1;
if (time_pos > 0)
private_ogg.seek_time = time_pos;
if (ov_open_callbacks((void *) &private_ogg.fd, &private_ogg.vf, NULL, 0, callbacks) < 0)
{
mem_close(private_ogg.fd); // mem_close() can too close files from devices
private_ogg.fd = -1;
ogg_thread_running = 0;
return -1;
}
if (LWP_CreateThread(&h_oggplayer, (void *) ogg_player_thread,
&private_ogg, oggplayer_stack, STACKSIZE, 80) == -1)
{
ogg_thread_running = 0;
ov_clear(&private_ogg.vf);
private_ogg.fd = -1;
return -1;
}
return 0;
}
void PauseOgg(int pause)
{
if (pause)
{
private_ogg.flag |= 128;
}
else
{
if (private_ogg.flag & 128)
{
private_ogg.flag |= 64;
private_ogg.flag &= ~128;
if (ogg_thread_running > 0)
{
LWP_ThreadSignal(oggplayer_queue);
}
}
}
}
int StatusOgg()
{
if (ogg_thread_running == 0)
return -1; // Error
else if (private_ogg.eof)
return 255; // EOF
else if (private_ogg.flag & 128)
return 2; // paused
else
return 1; // running
}
void SetVolumeOgg(int volume)
{
private_ogg.volume = volume;
ASND_ChangeVolumeVoice(0, volume, volume);
}
s32 GetTimeOgg()
{
int ret;
if (ogg_thread_running == 0 || private_ogg.fd < 0)
return 0;
ret = ((s32) ov_time_tell(&private_ogg.vf));
if (ret < 0)
ret = 0;
return ret;
}
void SetTimeOgg(s32 time_pos)
{
if (time_pos >= 0)
private_ogg.seek_time = time_pos;
}
#endif

View File

@ -0,0 +1,177 @@
/*
Copyright (c) 2008 Francisco Muñoz 'Hermes' <www.elotrolado.net>
All rights reserved.
Proper (standard) vorbis usage by Tantric, 2009
Threading modifications/corrections by Tantric, 2009
Redistribution and use in source and binary forms, with or without modification, are
permitted provided that the following conditions are met:
- Redistributions of source code must retain the above copyright notice, this list of
conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright notice, this list
of conditions and the following disclaimer in the documentation and/or other
materials provided with the distribution.
- The names of the contributors may not be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef NO_SOUND
#ifndef __OGGPLAYER_H__
#define __OGGPLAYER_H__
#include <asndlib.h>
#include <tremor/ivorbiscodec.h>
#include <tremor/ivorbisfile.h>
#ifdef __cplusplus
extern "C"
{
#endif
#define OGG_ONE_TIME 0
#define OGG_INFINITE_TIME 1
#define OGG_STATUS_RUNNING 1
#define OGG_STATUS_ERR -1
#define OGG_STATUS_PAUSED 2
#define OGG_STATUS_EOF 255
/*------------------------------------------------------------------------------------------------------------------------------------------------------*/
/* Player OGG functions */
/*------------------------------------------------------------------------------------------------------------------------------------------------------*/
/* int PlayOgg(int fd, int time_pos, int mode);
Play an Ogg file. This file can be loaded from memory (mem_open(void *ogg, int size_ogg)) or from device with open("device:file.ogg",O_RDONLY,0);
NOTE: The file is closed by the player when you call PlayOgg(), StopOgg() or if it fail.
-- Params ---
fd: file descriptor from open() or mem_open()
time_pos: initial time position in the file (in milliseconds). For example, use 30000 to advance 30 seconds
mode: Use OGG_ONE_TIME or OGG_INFINITE_TIME. When you use OGG_ONE_TIME the sound stops and StatusOgg() return OGG_STATUS_EOF
return: 0- Ok, -1 Error
*/
int PlayOgg(char * buf, int buflen, int time_pos, int mode);
/*------------------------------------------------------------------------------------------------------------------------------------------------------*/
/* void StopOgg();
Stop an Ogg file.
NOTE: The file is closed and the player thread is released
-- Params ---
*/
void StopOgg();
/*------------------------------------------------------------------------------------------------------------------------------------------------------*/
/* void PauseOgg(int pause);
Pause an Ogg file.
-- Params ---
pause: 0 -> continue, 1-> pause
*/
void PauseOgg(int pause);
/*------------------------------------------------------------------------------------------------------------------------------------------------------*/
/* int StatusOgg();
Return the Ogg status
-- Params ---
return: OGG_STATUS_RUNNING
OGG_STATUS_ERR -> not initialized?
OGG_STATUS_PAUSED
OGG_STATUS_EOF -> player stopped by End Of File
*/
int StatusOgg();
/*------------------------------------------------------------------------------------------------------------------------------------------------------*/
/* void SetVolumeOgg(int volume);
Set the Ogg playing volume.
NOTE: it change the volume of voice 0 (used for the Ogg player)
-- Params ---
volume: 0 to 255 (max)
*/
void SetVolumeOgg(int volume);
/*------------------------------------------------------------------------------------------------------------------------------------------------------*/
/* s32 GetTimeOgg();
Return the Ogg time from the starts of the file
-- Params ---
return: 0 -> Ok or error condition (you must ignore this value)
>0 -> time in milliseconds from the starts
*/
s32 GetTimeOgg();
/*------------------------------------------------------------------------------------------------------------------------------------------------------*/
/* void SetTimeOgg(s32 time_pos);
Set the time position
NOTE: The file is closed by the player when you call PlayOgg(), StopOgg() or if it fail.
-- Params ---
time_pos: time position in the file (in milliseconds). For example, use 30000 to advance 30 seconds
*/
void SetTimeOgg(s32 time_pos);
/*------------------------------------------------------------------------------------------------------------------------------------------------------*/
#ifdef __cplusplus
}
#endif
#endif
#endif

1266
src/platform/wii/pngu.c Normal file

File diff suppressed because it is too large Load Diff

176
src/platform/wii/pngu.h Normal file
View File

@ -0,0 +1,176 @@
/********************************************************************************************
PNGU Version : 0.2a
Coder : frontier
More info : http://frontier-dev.net
Modified by Tantric, 2009
********************************************************************************************/
#ifndef __PNGU__
#define __PNGU__
// Return codes
#define PNGU_OK 0
#define PNGU_ODD_WIDTH 1
#define PNGU_ODD_STRIDE 2
#define PNGU_INVALID_WIDTH_OR_HEIGHT 3
#define PNGU_FILE_IS_NOT_PNG 4
#define PNGU_UNSUPPORTED_COLOR_TYPE 5
#define PNGU_NO_FILE_SELECTED 6
#define PNGU_CANT_OPEN_FILE 7
#define PNGU_CANT_READ_FILE 8
#define PNGU_LIB_ERROR 9
// Color types
#define PNGU_COLOR_TYPE_GRAY 1
#define PNGU_COLOR_TYPE_GRAY_ALPHA 2
#define PNGU_COLOR_TYPE_PALETTE 3
#define PNGU_COLOR_TYPE_RGB 4
#define PNGU_COLOR_TYPE_RGB_ALPHA 5
#define PNGU_COLOR_TYPE_UNKNOWN 6
#ifdef __cplusplus
extern "C" {
#endif
// Types
typedef unsigned char PNGU_u8;
typedef unsigned short PNGU_u16;
typedef unsigned int PNGU_u32;
typedef unsigned long long PNGU_u64;
typedef struct
{
PNGU_u8 r;
PNGU_u8 g;
PNGU_u8 b;
} PNGUCOLOR;
typedef struct
{
PNGU_u32 imgWidth; // In pixels
PNGU_u32 imgHeight; // In pixels
PNGU_u32 imgBitDepth; // In bitx
PNGU_u32 imgColorType; // PNGU_COLOR_TYPE_*
PNGU_u32 validBckgrnd; // Non zero if there is a background color
PNGUCOLOR bckgrnd; // Backgroun color
PNGU_u32 numTrans; // Number of transparent colors
PNGUCOLOR *trans; // Transparent colors
} PNGUPROP;
// Image context, always initialize with SelectImageFrom* and free with ReleaseImageContext
struct _IMGCTX;
typedef struct _IMGCTX *IMGCTX;
/****************************************************************************
* Pixel conversion *
****************************************************************************/
// Macro to convert RGB8 values to RGB565
#define PNGU_RGB8_TO_RGB565(r,g,b) ( ((((PNGU_u16) r) & 0xF8U) << 8) | ((((PNGU_u16) g) & 0xFCU) << 3) | (((PNGU_u16) b) >> 3) )
// Macro to convert RGBA8 values to RGB5A3
#define PNGU_RGB8_TO_RGB5A3(r,g,b,a) (PNGU_u16) (((a & 0xE0U) == 0xE0U) ? \
(0x8000U | ((((PNGU_u16) r) & 0xF8U) << 7) | ((((PNGU_u16) g) & 0xF8U) << 2) | (((PNGU_u16) b) >> 3)) : \
(((((PNGU_u16) a) & 0xE0U) << 7) | ((((PNGU_u16) r) & 0xF0U) << 4) | (((PNGU_u16) g) & 0xF0U) | ((((PNGU_u16) b) & 0xF0U) >> 4)))
// Function to convert two RGB8 values to YCbYCr
PNGU_u32 PNGU_RGB8_TO_YCbYCr (PNGU_u8 r1, PNGU_u8 g1, PNGU_u8 b1, PNGU_u8 r2, PNGU_u8 g2, PNGU_u8 b2);
// Function to convert an YCbYCr to two RGB8 values.
void PNGU_YCbYCr_TO_RGB8 (PNGU_u32 ycbycr, PNGU_u8 *r1, PNGU_u8 *g1, PNGU_u8 *b1, PNGU_u8 *r2, PNGU_u8 *g2, PNGU_u8 *b2);
/****************************************************************************
* Image context handling *
****************************************************************************/
// Selects a PNG file, previosly loaded into a buffer, and creates an image context for subsequent procesing.
IMGCTX PNGU_SelectImageFromBuffer (const void *buffer);
// Selects a PNG file, from any devoptab device, and creates an image context for subsequent procesing.
IMGCTX PNGU_SelectImageFromDevice (const char *filename);
// Frees resources associated with an image context. Always call this function when you no longer need the IMGCTX.
void PNGU_ReleaseImageContext (IMGCTX ctx);
/****************************************************************************
* Miscelaneous *
****************************************************************************/
// Retrieves info from selected PNG file, including image dimensions, color format, background and transparency colors.
int PNGU_GetImageProperties (IMGCTX ctx, PNGUPROP *fileproperties);
/****************************************************************************
* Image conversion *
****************************************************************************/
// Expands selected image into an YCbYCr buffer. You need to specify context, image dimensions,
// destination address and stride in pixels (stride = buffer width - image width).
int PNGU_DecodeToYCbYCr (IMGCTX ctx, PNGU_u32 width, PNGU_u32 height, void *buffer, PNGU_u32 stride);
// Macro for decoding an image inside a buffer at given coordinates.
#define PNGU_DECODE_TO_COORDS_YCbYCr(ctx,coordX,coordY,imgWidth,imgHeight,bufferWidth,bufferHeight,buffer) \
\
PNGU_DecodeToYCbYCr (ctx, imgWidth, imgHeight, ((void *) buffer) + (coordY) * (bufferWidth) * 2 + \
(coordX) * 2, (bufferWidth) - (imgWidth))
// Expands selected image into a linear RGB565 buffer. You need to specify context, image dimensions,
// destination address and stride in pixels (stride = buffer width - image width).
int PNGU_DecodeToRGB565 (IMGCTX ctx, PNGU_u32 width, PNGU_u32 height, void *buffer, PNGU_u32 stride);
// Macro for decoding an image inside a buffer at given coordinates.
#define PNGU_DECODE_TO_COORDS_RGB565(ctx,coordX,coordY,imgWidth,imgHeight,bufferWidth,bufferHeight,buffer) \
\
PNGU_DecodeToRGB565 (ctx, imgWidth, imgHeight, ((void *) buffer) + (coordY) * (bufferWidth) * 2 + \
(coordX) * 2, (bufferWidth) - (imgWidth))
// Expands selected image into a linear RGBA8 buffer. You need to specify context, image dimensions,
// destination address, stride in pixels and default alpha value, which is used if the source image
// doesn't have an alpha channel.
int PNGU_DecodeToRGBA8 (IMGCTX ctx, PNGU_u32 width, PNGU_u32 height, void *buffer, PNGU_u32 stride, PNGU_u8 default_alpha);
// Macro for decoding an image inside a buffer at given coordinates.
#define PNGU_DECODE_TO_COORDS_RGBA8(ctx,coordX,coordY,imgWidth,imgHeight,default_alpha,bufferWidth,bufferHeight,buffer) \
\
PNGU_DecodeToRGBA8 (ctx, imgWidth, imgHeight, ((void *) buffer) + (coordY) * (bufferWidth) * 2 + \
(coordX) * 2, (bufferWidth) - (imgWidth), default_alpha)
// Expands selected image into a 4x4 tiled RGB565 buffer. You need to specify context, image dimensions
// and destination address.
int PNGU_DecodeTo4x4RGB565 (IMGCTX ctx, PNGU_u32 width, PNGU_u32 height, void *buffer);
// Expands selected image into a 4x4 tiled RGB5A3 buffer. You need to specify context, image dimensions,
// destination address and default alpha value, which is used if the source image doesn't have an alpha channel.
int PNGU_DecodeTo4x4RGB5A3 (IMGCTX ctx, PNGU_u32 width, PNGU_u32 height, void *buffer, PNGU_u8 default_alpha);
// Expands selected image into a 4x4 tiled RGBA8 buffer. You need to specify context, image dimensions,
// destination address and default alpha value, which is used if the source image doesn't have an alpha channel.
int PNGU_DecodeTo4x4RGBA8 (IMGCTX ctx, PNGU_u32 width, PNGU_u32 height, void *buffer, PNGU_u8 default_alpha);
// Encodes an YCbYCr image in PNG format and stores it in the selected device or memory buffer. You need to
// specify context, image dimensions, destination address and stride in pixels (stride = buffer width - image width).
int PNGU_EncodeFromYCbYCr (IMGCTX ctx, PNGU_u32 width, PNGU_u32 height, void *buffer, PNGU_u32 stride);
int PNGU_EncodeFromRGB (IMGCTX ctx, PNGU_u32 width, PNGU_u32 height, void *buffer, PNGU_u32 stride);
int PNGU_EncodeFromGXTexture (IMGCTX ctx, PNGU_u32 width, PNGU_u32 height, void *buffer, PNGU_u32 stride);
// Macro for encoding an image stored into an YCbYCr buffer at given coordinates.
#define PNGU_ENCODE_TO_COORDS_YCbYCr(ctx,coordX,coordY,imgWidth,imgHeight,bufferWidth,bufferHeight,buffer) \
\
PNGU_EncodeFromYCbYCr (ctx, imgWidth, imgHeight, ((void *) buffer) + (coordY) * (bufferWidth) * 2 + \
(coordX) * 2, (bufferWidth) - (imgWidth))
#ifdef __cplusplus
}
#endif
#endif

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -1,3 +1,8 @@
/****************************************************************************
* DOSBox Wii
* Tantric 2009
***************************************************************************/
#include <gccore.h> #include <gccore.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
@ -8,13 +13,200 @@
#include <zlib.h> #include <zlib.h>
#include <malloc.h> #include <malloc.h>
#include <fat.h> #include <fat.h>
#include <asndlib.h>
#include <sys/iosupport.h>
#include "wiihardware.h" #include "wiihardware.h"
#include "FreeTypeGX.h"
#include "filelist.h"
#include "SDL_events.h"
extern "C" {
extern void __exception_setreload(int t);
extern void WII_AudioStart();
extern void WII_AudioStop();
extern void WII_VideoStart();
extern void WII_VideoStop();
}
void MAPPER_CheckEvent(SDL_Event * event);
void HomeMenu();
char appPath[1024]; char appPath[1024];
char dosboxCommand[1024] = { 0 };
static lwp_t keythread = LWP_THREAD_NULL;
static char shiftkey[100];
/****************************************************************************
* SwitchAudioMode
*
* Switches between menu sound and emulator sound
***************************************************************************/
static void SwitchAudioMode(int mode)
{
if(mode == 0) // emulator
{
ASND_Pause(1);
AUDIO_StopDMA();
WII_AudioStart();
}
else // menu
{
WII_AudioStop();
ASND_Init();
ASND_Pause(0);
}
}
static void * PressKeys (void *arg)
{
SDL_Event event;
int shift;
u16 i;
memset(shiftkey, 0, sizeof(shiftkey));
shiftkey[33] = 49;
shiftkey[34] = 39;
shiftkey[35] = 51;
shiftkey[36] = 52;
shiftkey[37] = 53;
shiftkey[38] = 55;
shiftkey[40] = 57;
shiftkey[41] = 48;
shiftkey[42] = 56;
shiftkey[58] = 59;
shiftkey[60] = 44;
shiftkey[62] = 46;
shiftkey[63] = 47;
shiftkey[64] = 50;
shiftkey[94] = 54;
shiftkey[95] = 45;
while(1)
{
LWP_SuspendThread(keythread);
usleep(1200);
for(i=0; i<strlen(dosboxCommand); i++)
{
shift=0;
if((dosboxCommand[i] >= 65 && dosboxCommand[i] <= 90))
{
dosboxCommand[i] += 32;
shift = 1;
}
else if(dosboxCommand[i] > 0 && dosboxCommand[i] < 100 &&
shiftkey[(int)dosboxCommand[i]] > 0)
{
dosboxCommand[i] = shiftkey[(int)dosboxCommand[i]];
shift = 1;
}
if(shift)
{
event.type = SDL_KEYDOWN;
event.key.keysym.sym = SDLK_LSHIFT;
MAPPER_CheckEvent(&event);
usleep(600);
}
event.type = SDL_KEYDOWN;
event.key.keysym.sym = (SDLKey)dosboxCommand[i];
MAPPER_CheckEvent(&event);
usleep(600);
event.type = SDL_KEYUP;
event.key.keysym.sym = (SDLKey)dosboxCommand[i];
MAPPER_CheckEvent(&event);
usleep(600);
if(shift)
{
event.type = SDL_KEYUP;
event.key.keysym.sym = SDLK_LSHIFT;
MAPPER_CheckEvent(&event);
usleep(600);
}
}
event.type = SDL_KEYDOWN;
event.key.keysym.sym = SDLK_RETURN;
MAPPER_CheckEvent(&event);
usleep(600);
event.type = SDL_KEYUP;
event.key.keysym.sym = SDLK_RETURN;
MAPPER_CheckEvent(&event);
usleep(600);
dosboxCommand[0] = 0;
}
return NULL;
}
/****************************************************************************
* USB Gecko Debugging
***************************************************************************/
static bool gecko = false;
static mutex_t gecko_mutex = 0;
static ssize_t __out_write(struct _reent *r, int fd, const char *ptr, size_t len)
{
u32 level;
if (!ptr || len <= 0 || !gecko)
return -1;
LWP_MutexLock(gecko_mutex);
level = IRQ_Disable();
usb_sendbuffer(1, ptr, len);
IRQ_Restore(level);
LWP_MutexUnlock(gecko_mutex);
return len;
}
const devoptab_t gecko_out = {
"stdout", // device name
0, // size of file structure
NULL, // device open
NULL, // device close
__out_write,// device write
NULL, // device read
NULL, // device seek
NULL, // device fstat
NULL, // device stat
NULL, // device link
NULL, // device unlink
NULL, // device chdir
NULL, // device rename
NULL, // device mkdir
0, // dirStateSize
NULL, // device diropen_r
NULL, // device dirreset_r
NULL, // device dirnext_r
NULL, // device dirclose_r
NULL // device statvfs_r
};
void USBGeckoOutput()
{
LWP_MutexInit(&gecko_mutex, false);
gecko = usb_isgeckoalive(1);
devoptab_list[STD_OUT] = &gecko_out;
devoptab_list[STD_ERR] = &gecko_out;
}
void WiiInit() void WiiInit()
{ {
//USBGeckoOutput(); // uncomment to enable USB gecko output
__exception_setreload(8);
fatInitDefault(); fatInitDefault();
ASND_Init();
InitFreeType((u8*)font_ttf, font_ttf_size);
LWP_CreateThread (&keythread, PressKeys, NULL, NULL, 0, 65);
appPath[0] = 0; appPath[0] = 0;
} }
@ -43,6 +235,24 @@ void CreateAppPath(char origpath[])
free(path); free(path);
} }
void WiiMenu()
{
// wait for thread to finish
while(!LWP_ThreadIsSuspended(keythread))
usleep(100);
WII_VideoStop();
SwitchAudioMode(1);
HomeMenu();
WII_VideoStart();
SwitchAudioMode(0);
if(dosboxCommand[0] != 0)
LWP_ResumeThread(keythread);
}
void WiiFinished() void WiiFinished()
{ {

View File

@ -1,11 +1,18 @@
/****************************************************************************
* DOSBox Wii
* Tantric 2009
***************************************************************************/
#ifndef WIIHARDWARE_H #ifndef WIIHARDWARE_H
#define WIIHARDWARE_H #define WIIHARDWARE_H
#include <wiiuse/wpad.h> #include <wiiuse/wpad.h>
void WiiInit(); void WiiInit();
void WiiMenu();
void CreateAppPath(char origpath[]); void CreateAppPath(char origpath[]);
void WiiFinished(); void WiiFinished();
extern char appPath[1024]; extern char appPath[1024];
extern char dosboxCommand[1024];
#endif #endif

View File

@ -0,0 +1,197 @@
/****************************************************************************
* DOSBox Wii Home Menu
* Tantric 2009
*
* video.cpp
*
* Video routines
***************************************************************************/
#include <gccore.h>
#include <ogcsys.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <malloc.h>
#include "input.h"
extern unsigned int *xfb[2];
extern int whichfb;
extern GXRModeObj* vmode;
static Mtx GXmodelView2D;
u32 FrameTimer = 0;
int screenheight = 480;
int screenwidth = 640;
/****************************************************************************
* ResetVideo_Menu
*
* Reset the video/rendering mode for the menu
****************************************************************************/
void ResetVideo_Menu ()
{
Mtx44 p;
f32 yscale;
u32 xfbHeight;
// clears the bg to color and clears the z buffer
GXColor background = {0, 0, 0, 255};
GX_SetCopyClear (background, 0x00ffffff);
yscale = GX_GetYScaleFactor(vmode->efbHeight,vmode->xfbHeight);
xfbHeight = GX_SetDispCopyYScale(yscale);
GX_SetScissor(0,0,vmode->fbWidth,vmode->efbHeight);
GX_SetDispCopySrc(0,0,vmode->fbWidth,vmode->efbHeight);
GX_SetDispCopyDst(vmode->fbWidth,xfbHeight);
GX_SetCopyFilter(vmode->aa,vmode->sample_pattern,GX_TRUE,vmode->vfilter);
GX_SetFieldMode(vmode->field_rendering,((vmode->viHeight==2*vmode->xfbHeight)?GX_ENABLE:GX_DISABLE));
if (vmode->aa)
GX_SetPixelFmt(GX_PF_RGB565_Z16, GX_ZC_LINEAR);
else
GX_SetPixelFmt(GX_PF_RGB8_Z24, GX_ZC_LINEAR);
// setup the vertex descriptor
// tells the flipper to expect direct data
GX_ClearVtxDesc();
GX_InvVtxCache ();
GX_InvalidateTexAll();
GX_SetVtxDesc(GX_VA_TEX0, GX_NONE);
GX_SetVtxDesc(GX_VA_POS, GX_DIRECT);
GX_SetVtxDesc (GX_VA_CLR0, GX_DIRECT);
GX_SetVtxAttrFmt (GX_VTXFMT0, GX_VA_POS, GX_POS_XYZ, GX_F32, 0);
GX_SetVtxAttrFmt (GX_VTXFMT0, GX_VA_CLR0, GX_CLR_RGBA, GX_RGBA8, 0);
GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_TEX0, GX_TEX_ST, GX_F32, 0);
GX_SetZMode (GX_FALSE, GX_LEQUAL, GX_TRUE);
GX_SetNumChans(1);
GX_SetNumTexGens(1);
GX_SetTevOp (GX_TEVSTAGE0, GX_PASSCLR);
GX_SetTevOrder(GX_TEVSTAGE0, GX_TEXCOORD0, GX_TEXMAP0, GX_COLOR0A0);
GX_SetTexCoordGen(GX_TEXCOORD0, GX_TG_MTX2x4, GX_TG_TEX0, GX_IDENTITY);
guMtxIdentity(GXmodelView2D);
guMtxTransApply (GXmodelView2D, GXmodelView2D, 0.0F, 0.0F, -50.0F);
GX_LoadPosMtxImm(GXmodelView2D,GX_PNMTX0);
guOrtho(p,0,479,0,639,0,300);
GX_LoadProjectionMtx(p, GX_ORTHOGRAPHIC);
GX_SetViewport(0,0,vmode->fbWidth,vmode->efbHeight,0,1);
GX_SetBlendMode(GX_BM_BLEND, GX_BL_SRCALPHA, GX_BL_INVSRCALPHA, GX_LO_CLEAR);
GX_SetAlphaUpdate(GX_TRUE);
}
/****************************************************************************
* Menu_Render
*
* Renders everything current sent to GX, and flushes video
***************************************************************************/
void Menu_Render()
{
whichfb ^= 1; // flip framebuffer
GX_SetZMode(GX_TRUE, GX_LEQUAL, GX_TRUE);
GX_SetColorUpdate(GX_TRUE);
GX_CopyDisp(xfb[whichfb],GX_TRUE);
VIDEO_SetNextFramebuffer(xfb[whichfb]);
VIDEO_Flush();
VIDEO_WaitVSync();
FrameTimer++;
}
/****************************************************************************
* Menu_DrawImg
*
* Draws the specified image on screen using GX
***************************************************************************/
void Menu_DrawImg(f32 xpos, f32 ypos, u16 width, u16 height, u8 data[],
f32 degrees, f32 scaleX, f32 scaleY, u8 alpha)
{
if(data == NULL)
return;
GXTexObj texObj;
guVector axis = (guVector) {0, 0, 1 };
GX_InitTexObj(&texObj, data, width,height, GX_TF_RGBA8,GX_CLAMP, GX_CLAMP,GX_FALSE);
GX_LoadTexObj(&texObj, GX_TEXMAP0);
GX_InvalidateTexAll();
GX_SetTevOp (GX_TEVSTAGE0, GX_MODULATE);
GX_SetVtxDesc (GX_VA_TEX0, GX_DIRECT);
Mtx m,m1,m2, mv;
width *=.5;
height*=.5;
guMtxIdentity (m1);
guMtxRotAxisDeg (m2, &axis, degrees);
guMtxScaleApply(m1,m1,scaleX,scaleY,1.0);
guMtxConcat(m2,m1,m); // change me?
guMtxTransApply(m,m, xpos+width,ypos+height,0);
guMtxConcat (GXmodelView2D, m, mv);
GX_LoadPosMtxImm (mv, GX_PNMTX0);
GX_Begin(GX_QUADS, GX_VTXFMT0,4);
GX_Position3f32(-width, -height, 0);
GX_Color4u8(0xFF,0xFF,0xFF,alpha);
GX_TexCoord2f32(0, 0);
GX_Position3f32(width, -height, 0);
GX_Color4u8(0xFF,0xFF,0xFF,alpha);
GX_TexCoord2f32(1, 0);
GX_Position3f32(width, height, 0);
GX_Color4u8(0xFF,0xFF,0xFF,alpha);
GX_TexCoord2f32(1, 1);
GX_Position3f32(-width, height, 0);
GX_Color4u8(0xFF,0xFF,0xFF,alpha);
GX_TexCoord2f32(0, 1);
GX_End();
GX_DrawDone();
GX_LoadPosMtxImm (GXmodelView2D, GX_PNMTX0);
GX_SetTevOp (GX_TEVSTAGE0, GX_PASSCLR);
GX_SetVtxDesc (GX_VA_TEX0, GX_NONE);
}
/****************************************************************************
* Menu_DrawRectangle
*
* Draws a rectangle at the specified coordinates using GX
***************************************************************************/
void Menu_DrawRectangle(f32 x, f32 y, f32 width, f32 height, GXColor color, u8 filled)
{
u8 fmt;
long n;
int i;
f32 x2 = x+width;
f32 y2 = y+height;
guVector v[] = {{x,y,0.0f}, {x2,y,0.0f}, {x2,y2,0.0f}, {x,y2,0.0f}, {x,y,0.0f}};
if(!filled)
{
fmt = GX_LINESTRIP;
n = 5;
}
else
{
fmt = GX_TRIANGLEFAN;
n = 4;
}
GX_Begin(fmt, GX_VTXFMT0, n);
for(i=0; i<n; i++)
{
GX_Position3f32(v[i].x, v[i].y, v[i].z);
GX_Color4u8(color.r, color.g, color.b, color.a);
}
GX_End();
GX_DrawDone();
}

View File

@ -0,0 +1,26 @@
/****************************************************************************
* DOSBox Wii Home Menu
* Tantric 2009
*
* wiivideo.h
*
* Video routines
***************************************************************************/
#ifndef _WIIVIDEOH_
#define _WIIVIDEOH_
#include <ogcsys.h>
void ResetVideo_Menu();
void TakeScreenshot();
void Menu_Render();
void Menu_DrawImg(f32 xpos, f32 ypos, u16 width, u16 height, u8 data[], f32 degrees, f32 scaleX, f32 scaleY, u8 alphaF );
void Menu_DrawRectangle(f32 x, f32 y, f32 width, f32 height, GXColor color, u8 filled);
extern int screenheight;
extern int screenwidth;
extern u8 * screenTex;
extern u32 FrameTimer;
#endif