mirror of
https://github.com/wiidev/usbloadergx.git
synced 2024-11-22 03:09:15 +01:00
*Added loop for WBFS init back in
*Replaced all text related stuff with the ones from WiiXplorer (FreeTypeGX/GuiText/...). Some alignments might need be adjusted or maxWidth in pixel of some text parts. Also the text scrolling needs to be adjusted.
This commit is contained in:
parent
64f8406b07
commit
044c48a1bc
@ -2,8 +2,8 @@
|
||||
<app version="1">
|
||||
<name> USB Loader GX</name>
|
||||
<coder>USB Loader GX Team</coder>
|
||||
<version>1.0 r944</version>
|
||||
<release_date>201009161846</release_date>
|
||||
<version>1.0 r945</version>
|
||||
<release_date>201009171347</release_date>
|
||||
<short_description>Loads games from USB-devices</short_description>
|
||||
<long_description>USB Loader GX is a libwiigui based USB iso loader with a wii-like GUI. You can install games to your HDDs and boot them with shorter loading times.
|
||||
The interactive GUI is completely controllable with WiiMote, Classic Controller or GC Controller.
|
||||
|
File diff suppressed because one or more lines are too long
81
source/FontSystem.cpp
Normal file
81
source/FontSystem.cpp
Normal file
@ -0,0 +1,81 @@
|
||||
/****************************************************************************
|
||||
* Copyright (C) 2010
|
||||
* by Dimok
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any
|
||||
* damages arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any
|
||||
* purpose, including commercial applications, and to alter it and
|
||||
* redistribute it freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you
|
||||
* must not claim that you wrote the original software. If you use
|
||||
* this software in a product, an acknowledgment in the product
|
||||
* documentation would be appreciated but is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such, and
|
||||
* must not be misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any source
|
||||
* distribution.
|
||||
*
|
||||
* for WiiXplorer 2010
|
||||
***************************************************************************/
|
||||
#include "FreeTypeGX.h"
|
||||
#include "filelist.h"
|
||||
|
||||
FreeTypeGX * fontSystem = NULL;
|
||||
static FT_Byte * MainFont = (FT_Byte *) font_ttf;
|
||||
static u32 MainFontSize = font_ttf_size;
|
||||
|
||||
void ClearFontData()
|
||||
{
|
||||
if(fontSystem)
|
||||
delete fontSystem;
|
||||
fontSystem = NULL;
|
||||
|
||||
if(MainFont != (FT_Byte *) font_ttf)
|
||||
{
|
||||
if(MainFont != NULL)
|
||||
delete [] MainFont;
|
||||
MainFont = (FT_Byte *) font_ttf;
|
||||
MainFontSize = font_ttf_size;
|
||||
}
|
||||
}
|
||||
|
||||
bool SetupDefaultFont(const char *path)
|
||||
{
|
||||
bool result = false;
|
||||
FILE *pfile = NULL;
|
||||
|
||||
ClearFontData();
|
||||
|
||||
if(path)
|
||||
pfile = fopen(path, "rb");
|
||||
|
||||
if(pfile)
|
||||
{
|
||||
fseek(pfile, 0, SEEK_END);
|
||||
MainFontSize = ftell(pfile);
|
||||
rewind(pfile);
|
||||
|
||||
MainFont = new (std::nothrow) FT_Byte[MainFontSize];
|
||||
if(!MainFont)
|
||||
{
|
||||
MainFont = (FT_Byte *) font_ttf;
|
||||
MainFontSize = font_ttf_size;
|
||||
}
|
||||
else
|
||||
{
|
||||
fread(MainFont, 1, MainFontSize, pfile);
|
||||
result = true;
|
||||
}
|
||||
fclose(pfile);
|
||||
}
|
||||
|
||||
fontSystem = new FreeTypeGX(MainFont, MainFontSize);
|
||||
|
||||
return result;
|
||||
}
|
32
source/FontSystem.h
Normal file
32
source/FontSystem.h
Normal file
@ -0,0 +1,32 @@
|
||||
/****************************************************************************
|
||||
* Copyright (C) 2010
|
||||
* by Dimok
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any
|
||||
* damages arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any
|
||||
* purpose, including commercial applications, and to alter it and
|
||||
* redistribute it freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you
|
||||
* must not claim that you wrote the original software. If you use
|
||||
* this software in a product, an acknowledgment in the product
|
||||
* documentation would be appreciated but is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such, and
|
||||
* must not be misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any source
|
||||
* distribution.
|
||||
*
|
||||
* for WiiXplorer 2010
|
||||
***************************************************************************/
|
||||
#ifndef FONTSYSTEM_H_
|
||||
#define FONTSYSTEM_H_
|
||||
|
||||
bool SetupDefaultFont(const char *path);
|
||||
void ClearFontData();
|
||||
|
||||
#endif
|
File diff suppressed because it is too large
Load Diff
@ -2,7 +2,7 @@
|
||||
* 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
|
||||
* Modified by Dimok, 2010
|
||||
*
|
||||
* This file is part of FreeTypeGX.
|
||||
*
|
||||
@ -20,134 +20,6 @@
|
||||
* 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_
|
||||
|
||||
@ -155,58 +27,69 @@
|
||||
#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>
|
||||
|
||||
/*! forward deklaration of private structures
|
||||
/*! \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. */
|
||||
uint32_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. */
|
||||
|
||||
uint8_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 0x0003
|
||||
#define FTGX_JUSTIFY_MASK 0x000f
|
||||
#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 0x0030
|
||||
#define FTGX_ALIGN_BASELINE 0x0040
|
||||
#define FTGX_ALIGN_GLYPH_TOP 0x0050
|
||||
#define FTGX_ALIGN_GLYPH_MIDDLE 0x0060
|
||||
#define FTGX_ALIGN_GLYPH_BOTTOM 0x0070
|
||||
#define FTGX_ALIGN_MASK 0x00f0
|
||||
#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 0x0100
|
||||
#define FTGX_STYLE_STRIKE 0x0200
|
||||
#define FTGX_STYLE_MASK 0x0f00
|
||||
#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
|
||||
const GXColor ftgxWhite = (GXColor){0xff, 0xff, 0xff, 0xff}; /**< Constant color value used only to sanitize Doxygen documentation. */
|
||||
|
||||
#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. */
|
||||
wchar_t* charToWideChar(const char* p);
|
||||
|
||||
/*! \class FreeTypeGX
|
||||
* \brief Wrapper class for the libFreeType library with GX rendering.
|
||||
@ -217,59 +100,43 @@ const GXColor ftgxWhite = (GXColor) {
|
||||
* 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.
|
||||
*/
|
||||
typedef std::map<wchar_t, ftgxCharData> FTGX_Cache;
|
||||
class FreeTypeGX {
|
||||
class FreeTypeGX
|
||||
{
|
||||
private:
|
||||
FT_Library ftLibrary; /**< FreeType FT_Library instance. */
|
||||
FT_Face ftFace; /**< FreeType reusable FT_Face typographic object. */
|
||||
int16_t ftPointSize; /**< Current set size of the rendered font. */
|
||||
bool ftKerningEnabled; /**< Flag indicating the availability of font kerning data. */
|
||||
uint8_t vertexIndex; /**< Vertex format descriptor index. */
|
||||
std::map<int16_t, std::map<wchar_t, ftgxCharData> > fontData; /**< Map which holds the glyph data structures for the corresponding characters in one size. */
|
||||
std::map<int16_t, ftgxDataOffset> ftgxAlign; /**< Map which holds the ascender and decender for different sizes. */
|
||||
|
||||
private:
|
||||
FT_Library ftLibrary; /**< FreeType FT_Library instance. */
|
||||
FT_Face ftFace; /**< FreeType reusable FT_Face typographic object. */
|
||||
FT_Byte *ftFace_fromFile;
|
||||
FT_GlyphSlot ftSlot; /**< FreeType reusable FT_GlyphSlot glyph container object. */
|
||||
FT_UInt ftPointSize_v; /**< Requested size of the rendered font. */
|
||||
FT_UInt ftPointSize_h; /**< Requested size of the rendered font. */
|
||||
bool ftKerningEnabled; /**< Flag indicating the availability of font kerning data. */
|
||||
int16_t getStyleOffsetWidth(uint16_t width, uint16_t format);
|
||||
int16_t getStyleOffsetHeight(int16_t format, uint16_t pixelSize);
|
||||
|
||||
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. */
|
||||
// FTGX_Cache fontData; /**< Map which holds the glyph data structures for the corresponding characters. */
|
||||
std::map<uint16_t, FTGX_Cache> fontDatas;
|
||||
void unloadFont();
|
||||
ftgxCharData *cacheGlyphData(wchar_t charCode, int16_t pixelSize);
|
||||
uint16_t cacheGlyphDataComplete(int16_t pixelSize);
|
||||
void loadGlyphData(FT_Bitmap *bmp, ftgxCharData *charData);
|
||||
|
||||
static uint16_t adjustTextureWidth(uint16_t textureWidth, uint8_t textureFormat);
|
||||
static uint16_t adjustTextureHeight(uint16_t textureHeight, uint8_t textureFormat);
|
||||
void setDefaultMode();
|
||||
|
||||
static int16_t getStyleOffsetWidth(uint16_t width, uint16_t format);
|
||||
static int16_t getStyleOffsetHeight(ftgxDataOffset *offset, uint16_t format);
|
||||
void drawTextFeature(int16_t x, int16_t y,int16_t z, int16_t pixelSize, uint16_t width, ftgxDataOffset *offsetData, uint16_t format, GXColor color);
|
||||
void copyTextureToFramebuffer(GXTexObj *texObj, f32 texWidth, f32 texHeight, int16_t screenX, int16_t screenY, int16_t screenZ, GXColor color);
|
||||
void copyFeatureToFramebuffer(f32 featureWidth, f32 featureHeight, int16_t screenX, int16_t screenY, int16_t screenZ, GXColor color);
|
||||
|
||||
void unloadFont();
|
||||
void clearGlyphData();
|
||||
ftgxCharData *cacheGlyphData(wchar_t charCode);
|
||||
ftgxCharData *cacheGlyphData(wchar_t charCode, FTGX_Cache &fontData);
|
||||
uint16_t cacheGlyphDataComplete();
|
||||
void loadGlyphData(FT_Bitmap *bmp, ftgxCharData *charData);
|
||||
public:
|
||||
FreeTypeGX(const uint8_t* fontBuffer, FT_Long bufferSize);
|
||||
~FreeTypeGX();
|
||||
|
||||
void setDefaultMode();
|
||||
void setVertexFormat(uint8_t vertexIndex);
|
||||
|
||||
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);
|
||||
uint16_t drawText(int16_t x, int16_t y, int16_t z, const wchar_t *text, int16_t pixelSize, GXColor color = ftgxWhite, uint16_t textStyling = FTGX_NULL, uint16_t textWidth = 0, uint16_t widthLimit = 0);
|
||||
|
||||
public:
|
||||
FreeTypeGX(uint8_t textureFormat = GX_TF_RGBA8, uint8_t vertexIndex = GX_VTXFMT1, uint32_t compatibilityMode = FTGX_COMPATIBILITY_NONE);
|
||||
~FreeTypeGX();
|
||||
|
||||
static wchar_t* charToWideChar(const char* p);
|
||||
void setVertexFormat(uint8_t vertexIndex);
|
||||
void setCompatibilityMode(uint32_t compatibilityMode);
|
||||
|
||||
uint16_t loadFont(const char* fontPath, const uint8_t* fontBuffer, FT_Long bufferSize, FT_UInt pointSize, bool cacheAll = false);
|
||||
void changeSize(FT_UInt vPointSize, FT_UInt hPointSize=0);
|
||||
|
||||
uint16_t drawText(int16_t x, int16_t y, const wchar_t *text, GXColor color = ftgxWhite, uint16_t textStyling = FTGX_NULL);
|
||||
|
||||
uint16_t getWidth(const wchar_t *text);
|
||||
uint16_t getHeight(const wchar_t *text);
|
||||
ftgxDataOffset* getOffset(const wchar_t *text, ftgxDataOffset* offset);
|
||||
uint16_t getWidth(const wchar_t *text, int16_t pixelSize);
|
||||
uint16_t getCharWidth(const wchar_t wChar, int16_t pixelSize, const wchar_t prevChar = 0x0000);
|
||||
uint16_t getHeight(const wchar_t *text, int16_t pixelSize);
|
||||
void getOffset(const wchar_t *text, int16_t pixelSize, uint16_t widthLimit = 0);
|
||||
};
|
||||
|
||||
#endif /* FREETYPEGX_H_ */
|
||||
|
@ -89,7 +89,7 @@ int CheatMenu(const char * gameID) {
|
||||
|
||||
GuiText titleTxt(c.getGameName().c_str(), 28, (GXColor) {0, 0, 0, 255});
|
||||
titleTxt.SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
|
||||
titleTxt.SetMaxWidth(350, GuiText::SCROLL);
|
||||
titleTxt.SetMaxWidth(350, SCROLL_HORIZONTAL);
|
||||
titleTxt.SetPosition(12,40);
|
||||
|
||||
for (int i = 0; i <= cntcheats; i++) {
|
||||
|
@ -191,15 +191,15 @@ int MenuHomebrewBrowse() {
|
||||
GuiImage MainButton1Img(&MainButtonImgData);
|
||||
GuiImage MainButton1ImgOver(&MainButtonImgOverData);
|
||||
GuiText MainButton1Txt(MainButtonText, 18, (GXColor) {0, 0, 0, 255});
|
||||
MainButton1Txt.SetMaxWidth(MainButton1Img.GetWidth()-150, GuiText::DOTTED);
|
||||
MainButton1Txt.SetMaxWidth(MainButton1Img.GetWidth()-150, DOTTED);
|
||||
MainButton1Txt.SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE);
|
||||
MainButton1Txt.SetPosition(148, -12);
|
||||
GuiText MainButton1DescTxt(MainButtonText, 18, (GXColor) {0, 0, 0, 255});
|
||||
MainButton1DescTxt.SetMaxWidth(MainButton1Img.GetWidth()-150, GuiText::DOTTED);
|
||||
MainButton1DescTxt.SetMaxWidth(MainButton1Img.GetWidth()-150, DOTTED);
|
||||
MainButton1DescTxt.SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE);
|
||||
MainButton1DescTxt.SetPosition(148, 15);
|
||||
GuiText MainButton1DescOverTxt(MainButtonText, 18, (GXColor) { 0, 0, 0, 255});
|
||||
MainButton1DescOverTxt.SetMaxWidth(MainButton1Img.GetWidth()-150, GuiText::SCROLL);
|
||||
MainButton1DescOverTxt.SetMaxWidth(MainButton1Img.GetWidth()-150, SCROLL_HORIZONTAL);
|
||||
MainButton1DescOverTxt.SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE);
|
||||
MainButton1DescOverTxt.SetPosition(148, 15);
|
||||
GuiButton MainButton1(MainButton1Img.GetWidth(), MainButton1Img.GetHeight());
|
||||
@ -220,15 +220,15 @@ int MenuHomebrewBrowse() {
|
||||
GuiText MainButton2Txt(MainButtonText, 18, (GXColor) {0, 0, 0, 255 });
|
||||
MainButton2Txt.SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE);
|
||||
MainButton2Txt.SetPosition(148, -12);
|
||||
MainButton2Txt.SetMaxWidth(MainButton2Img.GetWidth()-150, GuiText::DOTTED);
|
||||
MainButton2Txt.SetMaxWidth(MainButton2Img.GetWidth()-150, DOTTED);
|
||||
GuiText MainButton2DescTxt(MainButtonText, 18, (GXColor) { 0, 0, 0, 255});
|
||||
MainButton2DescTxt.SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE);
|
||||
MainButton2DescTxt.SetPosition(148, 15);
|
||||
MainButton2DescTxt.SetMaxWidth(MainButton2Img.GetWidth()-150, GuiText::DOTTED);
|
||||
MainButton2DescTxt.SetMaxWidth(MainButton2Img.GetWidth()-150, DOTTED);
|
||||
GuiText MainButton2DescOverTxt(MainButtonText, 18, (GXColor) {0, 0, 0, 255});
|
||||
MainButton2DescOverTxt.SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE);
|
||||
MainButton2DescOverTxt.SetPosition(148, 15);
|
||||
MainButton2DescOverTxt.SetMaxWidth(MainButton2Img.GetWidth()-150, GuiText::SCROLL);
|
||||
MainButton2DescOverTxt.SetMaxWidth(MainButton2Img.GetWidth()-150, SCROLL_HORIZONTAL);
|
||||
GuiButton MainButton2(MainButton2Img.GetWidth(), MainButton2Img.GetHeight());
|
||||
MainButton2.SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
|
||||
MainButton2.SetPosition(0, 160);
|
||||
@ -247,15 +247,15 @@ int MenuHomebrewBrowse() {
|
||||
GuiText MainButton3Txt(MainButtonText, 18, (GXColor) {0, 0, 0, 255});
|
||||
MainButton3Txt.SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE);
|
||||
MainButton3Txt.SetPosition(148, -12);
|
||||
MainButton3Txt.SetMaxWidth(MainButton3Img.GetWidth()-150, GuiText::DOTTED);
|
||||
MainButton3Txt.SetMaxWidth(MainButton3Img.GetWidth()-150, DOTTED);
|
||||
GuiText MainButton3DescTxt(MainButtonText, 18, (GXColor) { 0, 0, 0, 255});
|
||||
MainButton3DescTxt.SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE);
|
||||
MainButton3DescTxt.SetPosition(148, 15);
|
||||
MainButton3DescTxt.SetMaxWidth(MainButton3Img.GetWidth()-150, GuiText::DOTTED);
|
||||
MainButton3DescTxt.SetMaxWidth(MainButton3Img.GetWidth()-150, DOTTED);
|
||||
GuiText MainButton3DescOverTxt(MainButtonText, 18, (GXColor) {0, 0, 0, 255 });
|
||||
MainButton3DescOverTxt.SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE);
|
||||
MainButton3DescOverTxt.SetPosition(148, 15);
|
||||
MainButton3DescOverTxt.SetMaxWidth(MainButton3Img.GetWidth()-150, GuiText::SCROLL);
|
||||
MainButton3DescOverTxt.SetMaxWidth(MainButton3Img.GetWidth()-150, SCROLL_HORIZONTAL);
|
||||
GuiButton MainButton3(MainButton3Img.GetWidth(), MainButton3Img.GetHeight());
|
||||
MainButton3.SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
|
||||
MainButton3.SetPosition(0, 230);
|
||||
@ -274,15 +274,15 @@ int MenuHomebrewBrowse() {
|
||||
GuiText MainButton4Txt(MainButtonText, 18, (GXColor) {0, 0, 0, 255} );
|
||||
MainButton4Txt.SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE);
|
||||
MainButton4Txt.SetPosition(148, -12);
|
||||
MainButton4Txt.SetMaxWidth(MainButton4Img.GetWidth()-150, GuiText::DOTTED);
|
||||
MainButton4Txt.SetMaxWidth(MainButton4Img.GetWidth()-150, DOTTED);
|
||||
GuiText MainButton4DescTxt(MainButtonText, 18, (GXColor) {0, 0, 0, 255});
|
||||
MainButton4DescTxt.SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE);
|
||||
MainButton4DescTxt.SetPosition(148, 15);
|
||||
MainButton4DescTxt.SetMaxWidth(MainButton4Img.GetWidth()-150, GuiText::DOTTED);
|
||||
MainButton4DescTxt.SetMaxWidth(MainButton4Img.GetWidth()-150, DOTTED);
|
||||
GuiText MainButton4DescOverTxt(MainButtonText, 18, (GXColor) { 0, 0, 0, 255});
|
||||
MainButton4DescOverTxt.SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE);
|
||||
MainButton4DescOverTxt.SetPosition(148, 15);
|
||||
MainButton4DescOverTxt.SetMaxWidth(MainButton4Img.GetWidth()-150, GuiText::SCROLL);
|
||||
MainButton4DescOverTxt.SetMaxWidth(MainButton4Img.GetWidth()-150, SCROLL_HORIZONTAL);
|
||||
GuiButton MainButton4(MainButton4Img.GetWidth(), MainButton4Img.GetHeight());
|
||||
MainButton4.SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
|
||||
MainButton4.SetPosition(0, 300);
|
||||
|
350
source/libwiigui/Text.cpp
Normal file
350
source/libwiigui/Text.cpp
Normal file
@ -0,0 +1,350 @@
|
||||
#include "Text.hpp"
|
||||
|
||||
Text::Text(const char * t, int s, GXColor c)
|
||||
: GuiText(t, s, c)
|
||||
{
|
||||
maxWidth = 400;
|
||||
linestodraw = 9;
|
||||
curLineStart = 0;
|
||||
FirstLineOffset = 0;
|
||||
wText = NULL;
|
||||
|
||||
if(!text)
|
||||
return;
|
||||
|
||||
wText = new (std::nothrow) wString(text);
|
||||
if(!wText)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if(wText->size() == 0)
|
||||
{
|
||||
wText->push_back(L' ');
|
||||
wText->push_back(0);
|
||||
}
|
||||
|
||||
textWidth = (font ? font : fontSystem)->getWidth(wText->data(), currentSize);
|
||||
delete [] text;
|
||||
text = NULL;
|
||||
|
||||
SetMaxWidth(maxWidth);
|
||||
}
|
||||
|
||||
Text::Text(const wchar_t * t, int s, GXColor c)
|
||||
: GuiText((wchar_t *) NULL, s, c)
|
||||
{
|
||||
maxWidth = 400;
|
||||
linestodraw = 9;
|
||||
curLineStart = 0;
|
||||
FirstLineOffset = 0;
|
||||
wText = NULL;
|
||||
|
||||
if(!t)
|
||||
return;
|
||||
|
||||
wText = new (std::nothrow) wString(t);
|
||||
if(!wText)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if(wText->size() == 0)
|
||||
{
|
||||
wText->push_back(L' ');
|
||||
wText->push_back(0);
|
||||
}
|
||||
|
||||
textWidth = (font ? font : fontSystem)->getWidth(wText->data(), currentSize);
|
||||
|
||||
SetMaxWidth(maxWidth);
|
||||
}
|
||||
|
||||
Text::~Text()
|
||||
{
|
||||
if(wText)
|
||||
delete wText;
|
||||
wText = NULL;
|
||||
|
||||
TextLines.clear();
|
||||
ClearDynamicText();
|
||||
}
|
||||
|
||||
void Text::SetText(const char * t)
|
||||
{
|
||||
wchar_t * tmp = charToWideChar(t);
|
||||
if(!tmp)
|
||||
return;
|
||||
|
||||
if(wText)
|
||||
delete wText;
|
||||
|
||||
wText = new (std::nothrow) wString(tmp);
|
||||
if(!wText)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if(wText->size() == 0)
|
||||
{
|
||||
wText->push_back(L' ');
|
||||
wText->push_back(0);
|
||||
}
|
||||
|
||||
textWidth = (font ? font : fontSystem)->getWidth(wText->data(), currentSize);
|
||||
|
||||
delete [] tmp;
|
||||
|
||||
ClearDynamicText();
|
||||
CalcLineOffsets();
|
||||
}
|
||||
|
||||
void Text::SetText(const wchar_t * t)
|
||||
{
|
||||
if(!t)
|
||||
return;
|
||||
|
||||
if(wText)
|
||||
delete wText;
|
||||
|
||||
wText = new wString(t);
|
||||
textWidth = (font ? font : fontSystem)->getWidth(wText->data(), currentSize);
|
||||
CalcLineOffsets();
|
||||
}
|
||||
|
||||
void Text::SetMaxWidth(int w)
|
||||
{
|
||||
maxWidth = w;
|
||||
curLineStart = 0;
|
||||
Refresh();
|
||||
}
|
||||
|
||||
void Text::SetTextLine(int line)
|
||||
{
|
||||
if(line < 0)
|
||||
line = 0;
|
||||
else if(line > (int) TextLines.size()-1)
|
||||
line = TextLines.size()-1;
|
||||
|
||||
curLineStart = line;
|
||||
|
||||
FillRows();
|
||||
|
||||
while((int) textDyn.size() < linestodraw && curLineStart > 0)
|
||||
{
|
||||
PreviousLine();
|
||||
}
|
||||
}
|
||||
|
||||
void Text::SetTextPos(int pos)
|
||||
{
|
||||
if(!wText)
|
||||
return;
|
||||
|
||||
int diff = 10000;
|
||||
|
||||
for(u32 i = 0; i < TextLines.size(); i++)
|
||||
{
|
||||
int curDiff = abs(TextLines[i].LineOffset - pos);
|
||||
if(curDiff < diff)
|
||||
{
|
||||
diff = curDiff;
|
||||
curLineStart = i;
|
||||
}
|
||||
}
|
||||
|
||||
FillRows();
|
||||
|
||||
while((int) textDyn.size() < linestodraw && curLineStart > 0)
|
||||
{
|
||||
PreviousLine();
|
||||
}
|
||||
}
|
||||
|
||||
const wchar_t * Text::GetText()
|
||||
{
|
||||
return wText->c_str();
|
||||
}
|
||||
|
||||
std::string Text::GetUTF8String(void) const
|
||||
{
|
||||
return wText->toUTF8();
|
||||
}
|
||||
|
||||
int Text::GetLineOffset(int ind)
|
||||
{
|
||||
if(TextLines.size() == 0)
|
||||
return 0;
|
||||
|
||||
if(ind < 0)
|
||||
return TextLines[0].LineOffset;
|
||||
|
||||
if(ind >= (int) TextLines.size()-1)
|
||||
return TextLines[TextLines.size()-1].LineOffset;
|
||||
|
||||
return TextLines[ind].LineOffset;
|
||||
}
|
||||
|
||||
const wchar_t * Text::GetTextLine(int ind)
|
||||
{
|
||||
if(filling || textDyn.size() == 0)
|
||||
return NULL;
|
||||
|
||||
if(ind < 0)
|
||||
return textDyn[0];
|
||||
|
||||
if(ind >= (int) textDyn.size())
|
||||
return textDyn[textDyn.size()-1];
|
||||
|
||||
return textDyn[ind];
|
||||
}
|
||||
|
||||
void Text::Refresh()
|
||||
{
|
||||
CalcLineOffsets();
|
||||
FillRows();
|
||||
}
|
||||
|
||||
void Text::NextLine()
|
||||
{
|
||||
if(!wText || (curLineStart+1 > ((int) TextLines.size()-linestodraw)))
|
||||
return;
|
||||
|
||||
++curLineStart;
|
||||
|
||||
FillRows();
|
||||
}
|
||||
|
||||
void Text::PreviousLine()
|
||||
{
|
||||
if(!wText || curLineStart-1 < 0)
|
||||
return;
|
||||
|
||||
--curLineStart;
|
||||
|
||||
FillRows();
|
||||
}
|
||||
|
||||
void Text::FillRows()
|
||||
{
|
||||
if(!wText)
|
||||
return;
|
||||
|
||||
filling = true;
|
||||
|
||||
ClearDynamicText();
|
||||
|
||||
for(int i = 0; i < linestodraw && i < (int) TextLines.size(); i++)
|
||||
{
|
||||
if(i >= (int) textDyn.size())
|
||||
{
|
||||
textDyn.resize(i+1);
|
||||
textDyn[i] = new wchar_t[maxWidth];
|
||||
}
|
||||
int offset = TextLines[curLineStart+i].LineOffset;
|
||||
int count = TextLines[curLineStart+i].CharCount+1;
|
||||
|
||||
for(int n = 0; n < count && offset+n < (int) wText->size(); n++)
|
||||
textDyn[i][n] = wText->at(offset+n);
|
||||
|
||||
textDyn[i][count] = 0;
|
||||
}
|
||||
|
||||
filling = false;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void Text::CalcLineOffsets()
|
||||
{
|
||||
if(!wText)
|
||||
return;
|
||||
|
||||
TextLines.clear();
|
||||
|
||||
TextLine TmpLine;
|
||||
TmpLine.CharCount = 0;
|
||||
TmpLine.LineOffset = 0;
|
||||
TmpLine.width = 0;
|
||||
|
||||
const wchar_t * origTxt = wText->c_str();
|
||||
int ch = 0;
|
||||
int lastSpace = -1;
|
||||
int lastSpaceIndex = -1;
|
||||
int currWidth = 0;
|
||||
int i = 0;
|
||||
|
||||
while(origTxt[ch])
|
||||
{
|
||||
currWidth += fontSystem->getCharWidth(origTxt[ch], currentSize, ch > 0 ? origTxt[ch-1] : 0x0000);
|
||||
|
||||
if(currWidth >= maxWidth)
|
||||
{
|
||||
if(lastSpace > 0)
|
||||
{
|
||||
ch = lastSpace;
|
||||
}
|
||||
TmpLine.CharCount = ch-TmpLine.LineOffset;
|
||||
TmpLine.width = currWidth;
|
||||
TextLines.push_back(TmpLine);
|
||||
currWidth = 0;
|
||||
lastSpace = -1;
|
||||
i = -1;
|
||||
TmpLine.LineOffset = ch+1;
|
||||
}
|
||||
else if(origTxt[ch] == '\n')
|
||||
{
|
||||
TmpLine.CharCount = ch-TmpLine.LineOffset;
|
||||
TmpLine.width = currWidth;
|
||||
TextLines.push_back(TmpLine);
|
||||
currWidth = 0;
|
||||
lastSpace = -1;
|
||||
i = -1;
|
||||
TmpLine.LineOffset = ch+1;
|
||||
}
|
||||
else if(origTxt[ch] == ' ')
|
||||
{
|
||||
lastSpace = ch;
|
||||
lastSpaceIndex = i;
|
||||
}
|
||||
|
||||
ch++;
|
||||
i++;
|
||||
}
|
||||
|
||||
TmpLine.CharCount = ch-TmpLine.LineOffset;
|
||||
TmpLine.width = currWidth;
|
||||
|
||||
if(TmpLine.CharCount > 0)
|
||||
TextLines.push_back(TmpLine);
|
||||
}
|
||||
|
||||
void Text::Draw()
|
||||
{
|
||||
if(textDyn.size() == 0)
|
||||
return;
|
||||
|
||||
if(!this->IsVisible())
|
||||
return;
|
||||
|
||||
GXColor c = color;
|
||||
c.a = this->GetAlpha();
|
||||
|
||||
int newSize = size*GetScale();
|
||||
|
||||
if(newSize != currentSize)
|
||||
{
|
||||
currentSize = newSize;
|
||||
|
||||
if(wText)
|
||||
textWidth = (font ? font : fontSystem)->getWidth(wText->data(), currentSize);
|
||||
}
|
||||
|
||||
u16 lineheight = newSize + 6;
|
||||
|
||||
for(u32 i = 0; i < textDyn.size(); i++)
|
||||
{
|
||||
if(!filling)
|
||||
(font ? font : fontSystem)->drawText(this->GetLeft(), this->GetTop()+i*lineheight, 0, textDyn[i], currentSize, c, style, 0, maxWidth);
|
||||
}
|
||||
}
|
71
source/libwiigui/Text.hpp
Normal file
71
source/libwiigui/Text.hpp
Normal file
@ -0,0 +1,71 @@
|
||||
#ifndef _TEXT_HPP_
|
||||
#define _TEXT_HPP_
|
||||
|
||||
#include "libwiigui/gui.h"
|
||||
#include "wstring.hpp"
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int LineOffset;
|
||||
int CharCount;
|
||||
int width;
|
||||
} TextLine;
|
||||
|
||||
class Text : public GuiText
|
||||
{
|
||||
public:
|
||||
//!Constructor
|
||||
//!\param t Text
|
||||
//!\param s Font size
|
||||
//!\param c Font color
|
||||
Text(const char * t, int s, GXColor c);
|
||||
Text(const wchar_t * t, int s, GXColor c);
|
||||
~Text();
|
||||
//!Sets the text of the GuiText element
|
||||
//!\param t Text
|
||||
void SetText(const char * t);
|
||||
void SetText(const wchar_t * t);
|
||||
//!Set the max texwidth
|
||||
void SetMaxWidth(int width);
|
||||
//!Go to next line
|
||||
void NextLine();
|
||||
//!Go to previous line
|
||||
void PreviousLine();
|
||||
//!Refresh the rows to draw
|
||||
void Refresh();
|
||||
//!Set the text line
|
||||
void SetTextLine(int line);
|
||||
//!Set to the char pos in text
|
||||
void SetTextPos(int pos);
|
||||
//!Refresh the rows to draw
|
||||
int GetCurrPos() { return curLineStart; };
|
||||
//!Get the count of loaded lines
|
||||
int GetLinesCount() { return textDyn.size(); };
|
||||
//!Get the total count of lines
|
||||
int GetTotalLinesCount() { return TextLines.size(); };
|
||||
//!Get the original full Text
|
||||
const wchar_t * GetText();
|
||||
//!Get the original full Text as wString
|
||||
wString * GetwString() { return wText; };
|
||||
//!Get the original Text as a UTF-8 text
|
||||
//!memory is allocated in this
|
||||
//!which needs to be deleted later
|
||||
std::string GetUTF8String() const;
|
||||
//!Get a Textline
|
||||
const wchar_t * GetTextLine(int ind);
|
||||
//!Get the offset in the text of a drawn Line
|
||||
int GetLineOffset(int ind);
|
||||
//!Constantly called to draw the text
|
||||
void Draw();
|
||||
protected:
|
||||
void CalcLineOffsets();
|
||||
void FillRows();
|
||||
|
||||
wString * wText;
|
||||
std::vector<TextLine> TextLines;
|
||||
int curLineStart;
|
||||
int FirstLineOffset;
|
||||
bool filling;
|
||||
};
|
||||
|
||||
#endif
|
@ -91,6 +91,14 @@ enum
|
||||
TRIGGER_BUTTON_ONLY_IN_FOCUS
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
WRAP,
|
||||
DOTTED,
|
||||
SCROLL_HORIZONTAL,
|
||||
SCROLL_NONE
|
||||
};
|
||||
|
||||
typedef struct _paddata {
|
||||
u16 btns_d;
|
||||
u16 btns_u;
|
||||
@ -144,7 +152,7 @@ class GuiSound
|
||||
bool Load(const char *p);
|
||||
//!Destructor
|
||||
~GuiSound();
|
||||
|
||||
|
||||
//!Start sound playback
|
||||
void Play();
|
||||
//!Stop sound playback
|
||||
@ -430,7 +438,7 @@ class GuiElement
|
||||
void Lock();
|
||||
void Unlock();
|
||||
// static mutex_t mutex;
|
||||
static mutex_t _lock_mutex;
|
||||
static mutex_t _lock_mutex;
|
||||
lwp_t _lock_thread;
|
||||
u16 _lock_count;
|
||||
lwpq_t _lock_queue;
|
||||
@ -700,7 +708,6 @@ class GuiImage : public GuiElement
|
||||
short widescreen; //added
|
||||
bool parentangle;
|
||||
};
|
||||
|
||||
//!Display, manage, and manipulate text in the GUI
|
||||
class GuiText : public GuiElement
|
||||
{
|
||||
@ -711,6 +718,11 @@ class GuiText : public GuiElement
|
||||
//!\param c Font color
|
||||
GuiText(const char * t, int s, GXColor c);
|
||||
//!\overload
|
||||
//!\param t Text
|
||||
//!\param s Font size
|
||||
//!\param c Font color
|
||||
GuiText(const wchar_t * t, int s, GXColor c);
|
||||
//!\overload
|
||||
//!\Assumes SetPresets() has been called to setup preferred text attributes
|
||||
//!\param t Text
|
||||
GuiText(const char * t);
|
||||
@ -718,9 +730,9 @@ class GuiText : public GuiElement
|
||||
~GuiText();
|
||||
//!Sets the text of the GuiText element
|
||||
//!\param t Text
|
||||
void SetText(const char * t);
|
||||
void SetTextf(const char *format, ...) __attribute__((format(printf,2,3)));
|
||||
void SetText(const wchar_t * t);
|
||||
virtual void SetText(const char * t);
|
||||
virtual void SetText(const wchar_t * t);
|
||||
virtual void SetTextf(const char *format, ...) __attribute__((format(printf,2,3)));
|
||||
//!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
|
||||
@ -730,7 +742,7 @@ class GuiText : public GuiElement
|
||||
//!\param s Font style
|
||||
//!\param h Text alignment (horizontal)
|
||||
//!\param v Text alignment (vertical)
|
||||
static void SetPresets(int sz, GXColor c, int w, int wrap, u16 s, int h, int v);
|
||||
static 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);
|
||||
@ -738,60 +750,72 @@ class GuiText : public GuiElement
|
||||
//!If the text exceeds this, it is wrapped to the next line
|
||||
//!\param w Maximum width
|
||||
//!\param m WrapMode
|
||||
enum {
|
||||
WRAP,
|
||||
DOTTED,
|
||||
SCROLL,
|
||||
MARQUEE
|
||||
};
|
||||
void SetMaxWidth(int w, short m=GuiText::WRAP);
|
||||
void SetMaxWidth(int w = 0, int m = WRAP);
|
||||
//!Sets the font color
|
||||
//!\param c Font color
|
||||
void SetColor(GXColor c);
|
||||
//!Sets the FreeTypeGX style attributes
|
||||
//!\param s Style attributes
|
||||
//!\param m Style-Mask attributes
|
||||
void SetStyle(u16 s, u16 m=0xffff);
|
||||
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);
|
||||
//!Set PassChar
|
||||
void SetPassChar(wchar_t p);
|
||||
//!Sets the font
|
||||
//!\param f Font
|
||||
void SetFont(FreeTypeGX *f);
|
||||
//!Sets a password character
|
||||
//!\param p char
|
||||
void SetPassChar(wchar_t p);
|
||||
//!Get the original text as char
|
||||
virtual const wchar_t * GetText();
|
||||
//!Get the Horizontal Size of Text
|
||||
int GetTextWidth();
|
||||
// not NULL set horizontal scale to 0.75 //added
|
||||
void SetWidescreen(bool w);
|
||||
void SetNumLines(int n);//! these two are used to set the first line and numLine
|
||||
void SetFirstLine(int n);
|
||||
int GetNumLines();//! these return the line variables for this text
|
||||
int GetFirstLine();
|
||||
int GetLineHeight(int n);//! returns the height of the #n of lines including spacing if wrap mode is on
|
||||
int GetTotalLines();
|
||||
int GetTextWidth(int ind);
|
||||
//!Get the max textwidth
|
||||
int GetTextMaxWidth();
|
||||
//!Gets the total line number
|
||||
virtual int GetLinesCount() { return 1; };
|
||||
//!Get fontsize
|
||||
int GetFontSize() { return size; };
|
||||
//!Set max lines to draw
|
||||
void SetLinesToDraw(int l);
|
||||
void SetWidescreen(bool b) { widescreen = b; };
|
||||
//!Get current Textline (for position calculation)
|
||||
const wchar_t * GetDynText(int ind = 0);
|
||||
virtual const wchar_t * GetTextLine(int ind) { return GetDynText(ind); };
|
||||
//!Change the font
|
||||
//!\param font bufferblock
|
||||
//!\param font filesize
|
||||
bool SetFont(const u8 *font, const u32 filesize);
|
||||
//!Constantly called to draw the text
|
||||
void Draw();
|
||||
protected:
|
||||
wchar_t* text; //!< Unicode text value
|
||||
//!Clear the dynamic text
|
||||
void ClearDynamicText();
|
||||
//!Create a dynamic dotted text if the text is too long
|
||||
void MakeDottedText();
|
||||
//!Scroll the text once
|
||||
void ScrollText();
|
||||
//!Wrap the text to several lines
|
||||
void WrapText();
|
||||
|
||||
wchar_t *text;
|
||||
std::vector<wchar_t *> textDyn;
|
||||
int wrapMode; //!< Wrapping toggle
|
||||
int textScrollPos; //!< Current starting index of text string for scrolling
|
||||
int textScrollInitialDelay; //!< Delay to wait before starting to scroll
|
||||
int textScrollDelay; //!< Scrolling speed
|
||||
int size; //!< Font size
|
||||
int maxWidth; //!< Maximum width of the generated text object (for text wrapping)
|
||||
short wrapMode;
|
||||
short scrollPos1;
|
||||
short scrollPos2;
|
||||
short scrollOffset;
|
||||
u32 scrollDelay;
|
||||
u16 style; //!< FreeTypeGX style attributes
|
||||
GXColor color; //!< Font color
|
||||
FreeTypeGX *font;
|
||||
short widescreen; //added
|
||||
//!these are default until the text is drawn
|
||||
int firstLine; //!these are the first line and the number of lines drawn when the text is wrapped
|
||||
int numLines;//! default is -1 and it means that all lines are drawn
|
||||
int totalLines; //!this is the total # of lines when in wrap mode
|
||||
wchar_t passChar; //!this is the password character
|
||||
int textWidth;
|
||||
int currentSize;
|
||||
int linestodraw;
|
||||
wchar_t passChar;
|
||||
bool widescreen;
|
||||
};
|
||||
|
||||
//!Display, manage, and manipulate tooltips in the GUI.
|
||||
|
@ -241,14 +241,14 @@ GuiCustomOptionBrowser::GuiCustomOptionBrowser(int w, int h, customOptionList *
|
||||
optionTxt[i] = new GuiText(options->GetName(i), 20, THEME.settingstext);
|
||||
optionTxt[i]->SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE);
|
||||
optionTxt[i]->SetPosition(24,0);
|
||||
optionTxt[i]->SetMaxWidth(bgOptionsImg->GetWidth() - (coL2+24), GuiText::DOTTED);
|
||||
optionTxt[i]->SetMaxWidth(bgOptionsImg->GetWidth() - (coL2+24), DOTTED);
|
||||
|
||||
optionBg[i] = new GuiImage(bgOptionsEntry);
|
||||
|
||||
optionVal[i] = new GuiText(NULL, 20, THEME.settingstext);
|
||||
optionVal[i] = new GuiText((char *) NULL, 20, THEME.settingstext);
|
||||
optionVal[i]->SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE);
|
||||
|
||||
optionValOver[i] = new GuiText(NULL, 20, THEME.settingstext);
|
||||
optionValOver[i] = new GuiText((char *) NULL, 20, THEME.settingstext);
|
||||
optionValOver[i]->SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE);
|
||||
|
||||
optionBtn[i] = new GuiButton(width-28,GAMESELECTSIZE);
|
||||
@ -479,10 +479,10 @@ void GuiCustomOptionBrowser::UpdateListEntries()
|
||||
if(optionBtn[i]->GetState() != STATE_DISABLED)
|
||||
{
|
||||
optionVal[i]->SetPosition(coL2,0);
|
||||
optionVal[i]->SetMaxWidth(bgOptionsImg->GetWidth() - (coL2+24), GuiText::DOTTED);
|
||||
optionVal[i]->SetMaxWidth(bgOptionsImg->GetWidth() - (coL2+24), DOTTED);
|
||||
|
||||
optionValOver[i]->SetPosition(coL2,0);
|
||||
optionValOver[i]->SetMaxWidth(bgOptionsImg->GetWidth() - (coL2+24), GuiText::SCROLL);
|
||||
optionValOver[i]->SetMaxWidth(bgOptionsImg->GetWidth() - (coL2+24), SCROLL_HORIZONTAL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -108,15 +108,15 @@ GuiFileBrowser::GuiFileBrowser(int w, int h)
|
||||
|
||||
for(int i=0; i<FILEBROWSERSIZE; i++)
|
||||
{
|
||||
fileListText[i] = new GuiText(NULL,20, (GXColor){0, 0, 0, 0xff});
|
||||
fileListText[i] = new GuiText((char *) NULL,20, (GXColor){0, 0, 0, 0xff});
|
||||
fileListText[i]->SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE);
|
||||
fileListText[i]->SetPosition(5,0);
|
||||
fileListText[i]->SetMaxWidth(bgFileSelectionImg->GetWidth() - (arrowDownImg->GetWidth()+20), GuiText::DOTTED);
|
||||
fileListText[i]->SetMaxWidth(bgFileSelectionImg->GetWidth() - (arrowDownImg->GetWidth()+20), DOTTED);
|
||||
|
||||
fileListTextOver[i] = new GuiText(NULL,20, (GXColor){0, 0, 0, 0xff});
|
||||
fileListTextOver[i] = new GuiText((char *) NULL,20, (GXColor){0, 0, 0, 0xff});
|
||||
fileListTextOver[i]->SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE);
|
||||
fileListTextOver[i]->SetPosition(5,0);
|
||||
fileListTextOver[i]->SetMaxWidth(bgFileSelectionImg->GetWidth() - (arrowDownImg->GetWidth()+20), GuiText::SCROLL);
|
||||
fileListTextOver[i]->SetMaxWidth(bgFileSelectionImg->GetWidth() - (arrowDownImg->GetWidth()+20), SCROLL_HORIZONTAL);
|
||||
|
||||
fileListBg[i] = new GuiImage(bgFileSelectionEntry);
|
||||
//fileListArchives[i] = new GuiImage(fileArchives);
|
||||
|
@ -132,13 +132,13 @@ GuiGameBrowser::GuiGameBrowser(int w, int h, struct discHdr * l, int gameCnt, co
|
||||
gameTxt[i] = new GuiText(get_title(&gameList[i]), 20, THEME.gametext);
|
||||
gameTxt[i]->SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE);
|
||||
gameTxt[i]->SetPosition(24,0);
|
||||
gameTxt[i]->SetMaxWidth(maxTextWidth, GuiText::DOTTED);
|
||||
gameTxt[i]->SetMaxWidth(maxTextWidth, DOTTED);
|
||||
|
||||
|
||||
gameTxtOver[i] = new GuiText(get_title(&gameList[i]), 20, THEME.gametext);
|
||||
gameTxtOver[i]->SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE);
|
||||
gameTxtOver[i]->SetPosition(24,0);
|
||||
gameTxtOver[i]->SetMaxWidth(maxTextWidth, GuiText::SCROLL);
|
||||
gameTxtOver[i]->SetMaxWidth(maxTextWidth, SCROLL_HORIZONTAL);
|
||||
|
||||
gameBg[i] = new GuiImage(bgGamesEntry);
|
||||
|
||||
@ -344,11 +344,11 @@ void GuiGameBrowser::UpdateListEntries()
|
||||
if (Settings.marknewtitles) {
|
||||
bool isNew = NewTitles::Instance()->IsNew(gameList[next].id);
|
||||
if (isNew) {
|
||||
gameTxt[i]->SetMaxWidth(maxTextWidth - (newGames->GetWidth() + 1), GuiText::DOTTED);
|
||||
gameTxtOver[i]->SetMaxWidth(maxTextWidth - (newGames->GetWidth() + 1), GuiText::SCROLL);
|
||||
gameTxt[i]->SetMaxWidth(maxTextWidth - (newGames->GetWidth() + 1), DOTTED);
|
||||
gameTxtOver[i]->SetMaxWidth(maxTextWidth - (newGames->GetWidth() + 1), SCROLL_HORIZONTAL);
|
||||
} else {
|
||||
gameTxt[i]->SetMaxWidth(maxTextWidth, GuiText::DOTTED);
|
||||
gameTxtOver[i]->SetMaxWidth(maxTextWidth, GuiText::SCROLL);
|
||||
gameTxt[i]->SetMaxWidth(maxTextWidth, DOTTED);
|
||||
gameTxtOver[i]->SetMaxWidth(maxTextWidth, SCROLL_HORIZONTAL);
|
||||
}
|
||||
newImg[i]->SetVisible(isNew);
|
||||
}
|
||||
|
@ -111,7 +111,7 @@ noCover(nocover_png)
|
||||
gamename->SetParent(this);
|
||||
gamename->SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
|
||||
gamename->SetPosition(0, 330);
|
||||
gamename->SetMaxWidth(280, GuiText::DOTTED);
|
||||
gamename->SetMaxWidth(280, DOTTED);
|
||||
|
||||
gameIndex = new int[pagesize];
|
||||
game = new GuiButton * [pagesize];
|
||||
|
@ -107,13 +107,13 @@ GuiOptionBrowser::GuiOptionBrowser(int w, int h, OptionList * l, const u8 *image
|
||||
// optionBg = new GuiImage(bgOptionsEntry);
|
||||
for(int i=0; i<PAGESIZE; i++)
|
||||
{
|
||||
optionTxt[i] = new GuiText(NULL, 20, (GXColor){0, 0, 0, 0xff});
|
||||
optionTxt[i] = new GuiText((char *) NULL, 20, (GXColor){0, 0, 0, 0xff});
|
||||
optionTxt[i]->SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE);
|
||||
optionTxt[i]->SetPosition(24,0);
|
||||
|
||||
optionBg[i] = new GuiImage(bgOptionsEntry);
|
||||
|
||||
optionVal[i] = new GuiText(NULL, 20, (GXColor){0, 0, 0, 0xff});
|
||||
optionVal[i] = new GuiText((char *) NULL, 20, (GXColor){0, 0, 0, 0xff});
|
||||
optionVal[i]->SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE);
|
||||
optionVal[i]->SetPosition(250,0);
|
||||
|
||||
@ -232,7 +232,7 @@ GuiOptionBrowser::GuiOptionBrowser(int w, int h, OptionList * l, const char *the
|
||||
|
||||
optionBg[i] = new GuiImage(bgOptionsEntry);
|
||||
|
||||
optionVal[i] = new GuiText(NULL, 20, (GXColor){0, 0, 0, 0xff});
|
||||
optionVal[i] = new GuiText((char *) NULL, 20, (GXColor){0, 0, 0, 0xff});
|
||||
optionVal[i]->SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE);
|
||||
optionVal[i]->SetPosition(250,0);
|
||||
|
||||
|
@ -16,7 +16,7 @@ public:
|
||||
wchar(*Char),
|
||||
image(keyImageData),
|
||||
imageOver(keyOverImageData),
|
||||
text(NULL, 20, (GXColor){0, 0, 0, 0xff}),
|
||||
text((char *) NULL, 20, (GXColor){0, 0, 0, 0xff}),
|
||||
button(&image, &imageOver, ALIGN_LEFT, ALIGN_TOP, x, y, trig, sndOver, sndClick, 1)
|
||||
{
|
||||
text.SetText(Char);
|
||||
@ -35,7 +35,7 @@ private:
|
||||
GuiSearchBar::GuiSearchBar(const wchar_t *SearchChars)
|
||||
:
|
||||
inSide(0),
|
||||
text(NULL, 22, (GXColor) {0, 0, 0, 255}),
|
||||
text((char *) NULL, 22, (GXColor) {0, 0, 0, 255}),
|
||||
buttons(0),
|
||||
keyImageData(keyboard_key_png),
|
||||
keyOverImageData(keyboard_key_over_png),
|
||||
@ -70,7 +70,7 @@ sndClick(button_click_pcm, button_click_pcm_size, Settings.sfxvolume)
|
||||
text.SetPosition(10, 15);
|
||||
text.SetAlignment(ALIGN_LEFT, ALIGN_TOP);
|
||||
text.SetWidescreen(CFG.widescreen);
|
||||
text.SetMaxWidth(width-(10+2*42+10), GuiText::SCROLL);
|
||||
text.SetMaxWidth(width-(10+2*42+10), SCROLL_HORIZONTAL);
|
||||
this->Append(&text);
|
||||
|
||||
snprintf(imgPath, sizeof(imgPath), "%skeyboard_backspace_over.png", CFG.theme_path);
|
||||
|
@ -9,42 +9,84 @@
|
||||
***************************************************************************/
|
||||
|
||||
#include "gui.h"
|
||||
#include "wstring.hpp"
|
||||
|
||||
static int presetSize = 0;
|
||||
static GXColor presetColor = (GXColor){255, 255, 255, 255};
|
||||
#define MAX_LINES_TO_DRAW 9
|
||||
|
||||
static int presetSize = 18;
|
||||
static int presetMaxWidth = 0;
|
||||
static int presetWrapMode = GuiText::WRAP;
|
||||
static u16 presetStyle = FTGX_NULL;
|
||||
static int presetAlignmentHor = 0;
|
||||
static int presetAlignmentVert = 0;
|
||||
static u16 presetStyle = 0;
|
||||
static GXColor presetColor = (GXColor){255, 255, 255, 255};
|
||||
|
||||
#define TEXT_SCROLL_DELAY 5
|
||||
#define TEXT_SCROLL_INITIAL_DELAY 8
|
||||
|
||||
/**
|
||||
* Constructor for the GuiText class.
|
||||
*/
|
||||
|
||||
GuiText::GuiText(const char * t, int s, GXColor c)
|
||||
{
|
||||
text = NULL;
|
||||
size = s;
|
||||
currentSize = size;
|
||||
color = c;
|
||||
alpha = c.a;
|
||||
style = FTGX_JUSTIFY_CENTER | FTGX_ALIGN_MIDDLE;
|
||||
maxWidth = 0;
|
||||
wrapMode = GuiText::WRAP;
|
||||
scrollPos1 = 0;
|
||||
scrollPos2 = 0;
|
||||
scrollDelay = 0;
|
||||
font = NULL;
|
||||
widescreen = 0; //added
|
||||
firstLine = 1;
|
||||
numLines = -1;
|
||||
totalLines = 1;
|
||||
wrapMode = 0;
|
||||
passChar = 0;
|
||||
font = NULL;
|
||||
linestodraw = MAX_LINES_TO_DRAW;
|
||||
textScrollPos = 0;
|
||||
textScrollInitialDelay = TEXT_SCROLL_INITIAL_DELAY;
|
||||
textScrollDelay = TEXT_SCROLL_DELAY;
|
||||
|
||||
alignmentHor = ALIGN_CENTRE;
|
||||
alignmentVert = ALIGN_MIDDLE;
|
||||
|
||||
if(t)
|
||||
text = FreeTypeGX::charToWideChar((char *)t);
|
||||
{
|
||||
text = charToWideChar(t);
|
||||
if(!text)
|
||||
return;
|
||||
|
||||
textWidth = fontSystem->getWidth(text, currentSize);
|
||||
}
|
||||
}
|
||||
|
||||
GuiText::GuiText(const wchar_t * t, int s, GXColor c)
|
||||
{
|
||||
text = NULL;
|
||||
size = s;
|
||||
currentSize = size;
|
||||
color = c;
|
||||
alpha = c.a;
|
||||
style = FTGX_JUSTIFY_CENTER | FTGX_ALIGN_MIDDLE;
|
||||
maxWidth = 0;
|
||||
wrapMode = 0;
|
||||
passChar = 0;
|
||||
font = NULL;
|
||||
linestodraw = MAX_LINES_TO_DRAW;
|
||||
textScrollPos = 0;
|
||||
textScrollInitialDelay = TEXT_SCROLL_INITIAL_DELAY;
|
||||
textScrollDelay = TEXT_SCROLL_DELAY;
|
||||
|
||||
alignmentHor = ALIGN_CENTRE;
|
||||
alignmentVert = ALIGN_MIDDLE;
|
||||
|
||||
if(t)
|
||||
{
|
||||
text = new (std::nothrow) wchar_t[wcslen(t)+1];
|
||||
if(!text)
|
||||
return;
|
||||
|
||||
wcscpy(text, t);
|
||||
|
||||
textWidth = fontSystem->getWidth(text, currentSize);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -54,175 +96,197 @@ GuiText::GuiText(const char * t)
|
||||
{
|
||||
text = NULL;
|
||||
size = presetSize;
|
||||
currentSize = size;
|
||||
color = presetColor;
|
||||
alpha = presetColor.a;
|
||||
style = presetStyle;
|
||||
maxWidth = presetMaxWidth;
|
||||
wrapMode = presetWrapMode;
|
||||
scrollPos1 = 0;
|
||||
scrollPos2 = 0;
|
||||
scrollDelay = 0;
|
||||
wrapMode = 0;
|
||||
passChar = 0;
|
||||
font = NULL;
|
||||
widescreen = 0; //added
|
||||
firstLine = 1;
|
||||
numLines = -1;
|
||||
totalLines = 1;
|
||||
linestodraw = MAX_LINES_TO_DRAW;
|
||||
textScrollPos = 0;
|
||||
textScrollInitialDelay = TEXT_SCROLL_INITIAL_DELAY;
|
||||
textScrollDelay = TEXT_SCROLL_DELAY;
|
||||
|
||||
alignmentHor = presetAlignmentHor;
|
||||
alignmentVert = presetAlignmentVert;
|
||||
|
||||
if(t)
|
||||
text = FreeTypeGX::charToWideChar((char *)t);
|
||||
{
|
||||
text = charToWideChar(t);
|
||||
if(!text)
|
||||
return;
|
||||
|
||||
textWidth = fontSystem->getWidth(text, currentSize);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Destructor for the GuiText class.
|
||||
*/
|
||||
GuiText::~GuiText()
|
||||
{
|
||||
if(text)
|
||||
{
|
||||
delete [] text;
|
||||
text = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void GuiText::SetNumLines(int n)
|
||||
{
|
||||
numLines = n;
|
||||
}
|
||||
|
||||
void GuiText::SetFirstLine(int n)
|
||||
{
|
||||
firstLine = n;
|
||||
}
|
||||
|
||||
int GuiText::GetNumLines()
|
||||
{
|
||||
return numLines;
|
||||
}
|
||||
|
||||
int GuiText::GetFirstLine()
|
||||
{
|
||||
return firstLine;
|
||||
}
|
||||
|
||||
int GuiText::GetTotalLines()
|
||||
{
|
||||
return totalLines;
|
||||
}
|
||||
|
||||
int GuiText::GetLineHeight(int n)
|
||||
{
|
||||
int newSize = size*this->GetScale();
|
||||
int lineheight = newSize + 6;
|
||||
|
||||
if (numLines <0)
|
||||
return totalLines*lineheight+newSize;
|
||||
|
||||
else return numLines*lineheight+newSize;
|
||||
}
|
||||
|
||||
|
||||
void GuiText::SetText(const char * t)
|
||||
{
|
||||
LOCK(this);
|
||||
if(text)
|
||||
delete [] text;
|
||||
text = NULL;
|
||||
|
||||
if(t) {
|
||||
text = FreeTypeGX::charToWideChar((char *)t);
|
||||
|
||||
if (passChar != 0) {
|
||||
for (u8 i = 0; i < wcslen(text); i++) {
|
||||
text[i] = passChar;
|
||||
}
|
||||
}
|
||||
}
|
||||
scrollPos2 = 0;
|
||||
scrollDelay = 0;
|
||||
if(font)
|
||||
{
|
||||
delete font;
|
||||
font = NULL;
|
||||
}
|
||||
|
||||
ClearDynamicText();
|
||||
}
|
||||
|
||||
void GuiText::SetText(const char * t)
|
||||
{
|
||||
LOCK(this);
|
||||
|
||||
if(text)
|
||||
delete [] text;
|
||||
text = NULL;
|
||||
|
||||
ClearDynamicText();
|
||||
|
||||
textScrollPos = 0;
|
||||
textScrollInitialDelay = TEXT_SCROLL_INITIAL_DELAY;
|
||||
|
||||
if(t)
|
||||
{
|
||||
text = charToWideChar(t);
|
||||
if(!text)
|
||||
return;
|
||||
|
||||
if (passChar != 0)
|
||||
{
|
||||
for (u8 i = 0; i < wcslen(text); i++)
|
||||
text[i] = passChar;
|
||||
}
|
||||
|
||||
textWidth = fontSystem->getWidth(text, currentSize);
|
||||
}
|
||||
}
|
||||
|
||||
void GuiText::SetTextf(const char *format, ...)
|
||||
{
|
||||
if(!format)
|
||||
SetText((char *) NULL);
|
||||
|
||||
char *tmp=0;
|
||||
va_list va;
|
||||
va_start(va, format);
|
||||
if((vasprintf(&tmp, format, va)>=0) && tmp)
|
||||
{
|
||||
this->SetText(tmp);
|
||||
free(tmp);
|
||||
SetText(tmp);
|
||||
}
|
||||
va_end(va);
|
||||
|
||||
if(tmp)
|
||||
free(tmp);
|
||||
}
|
||||
|
||||
|
||||
void GuiText::SetText(const wchar_t * t)
|
||||
{
|
||||
LOCK(this);
|
||||
LOCK(this);
|
||||
|
||||
if(text)
|
||||
delete [] text;
|
||||
text = NULL;
|
||||
text = NULL;
|
||||
|
||||
ClearDynamicText();
|
||||
|
||||
textScrollPos = 0;
|
||||
textScrollInitialDelay = TEXT_SCROLL_INITIAL_DELAY;
|
||||
|
||||
if(t)
|
||||
{
|
||||
int len = wcslen(t);
|
||||
text = new wchar_t[len+1];
|
||||
if(text) {
|
||||
wcscpy(text, t);
|
||||
}
|
||||
|
||||
if (passChar != 0) {
|
||||
for (u8 i = 0; i < wcslen(text); i++) {
|
||||
text = new (std::nothrow) wchar_t[wcslen(t)+1];
|
||||
if(!text)
|
||||
return;
|
||||
|
||||
wcscpy(text, t);
|
||||
|
||||
if (passChar != 0)
|
||||
{
|
||||
for (u8 i = 0; i < wcslen(text); i++)
|
||||
text[i] = passChar;
|
||||
}
|
||||
}
|
||||
|
||||
textWidth = fontSystem->getWidth(text, currentSize);
|
||||
}
|
||||
scrollPos2 = 0;
|
||||
scrollDelay = 0;
|
||||
}
|
||||
|
||||
void GuiText::ClearDynamicText()
|
||||
{
|
||||
for(u32 i = 0; i < textDyn.size(); i++)
|
||||
{
|
||||
if(textDyn[i])
|
||||
delete [] textDyn[i];
|
||||
}
|
||||
textDyn.clear();
|
||||
}
|
||||
|
||||
void GuiText::SetPresets(int sz, GXColor c, int w, int wrap, u16 s, int h, int v)
|
||||
void GuiText::SetPresets(int sz, GXColor c, int w, u16 s, int h, int v)
|
||||
{
|
||||
presetSize = sz;
|
||||
presetColor = c;
|
||||
presetMaxWidth = w;
|
||||
presetWrapMode = wrap;
|
||||
presetStyle = s;
|
||||
presetMaxWidth = w;
|
||||
presetAlignmentHor = h;
|
||||
presetAlignmentVert = v;
|
||||
}
|
||||
|
||||
void GuiText::SetFontSize(int s)
|
||||
{
|
||||
LOCK(this);
|
||||
LOCK(this);
|
||||
|
||||
size = s;
|
||||
}
|
||||
|
||||
void GuiText::SetMaxWidth(int w, short m/*=GuiText::WRAP*/)
|
||||
void GuiText::SetMaxWidth(int width, int w)
|
||||
{
|
||||
LOCK(this);
|
||||
|
||||
maxWidth = width;
|
||||
wrapMode = w;
|
||||
|
||||
if(w == SCROLL_HORIZONTAL)
|
||||
{
|
||||
textScrollPos = 0;
|
||||
textScrollInitialDelay = TEXT_SCROLL_INITIAL_DELAY;
|
||||
textScrollDelay = TEXT_SCROLL_DELAY;
|
||||
}
|
||||
|
||||
ClearDynamicText();
|
||||
}
|
||||
|
||||
void GuiText::SetPassChar(wchar_t p)
|
||||
{
|
||||
LOCK(this);
|
||||
maxWidth = w;
|
||||
wrapMode = m;
|
||||
passChar = p;
|
||||
}
|
||||
|
||||
void GuiText::SetColor(GXColor c)
|
||||
{
|
||||
LOCK(this);
|
||||
LOCK(this);
|
||||
color = c;
|
||||
alpha = c.a;
|
||||
}
|
||||
|
||||
void GuiText::SetStyle(u16 s, u16 m/*=0xffff*/)
|
||||
void GuiText::SetStyle(u16 s)
|
||||
{
|
||||
LOCK(this);
|
||||
style &= ~m;
|
||||
style |= s & m;
|
||||
LOCK(this);
|
||||
style = s;
|
||||
}
|
||||
|
||||
void GuiText::SetAlignment(int hor, int vert)
|
||||
{
|
||||
LOCK(this);
|
||||
style = FTGX_NULL;
|
||||
LOCK(this);
|
||||
style = 0;
|
||||
|
||||
switch(hor)
|
||||
{
|
||||
@ -252,291 +316,285 @@ void GuiText::SetAlignment(int hor, int vert)
|
||||
alignmentHor = hor;
|
||||
alignmentVert = vert;
|
||||
}
|
||||
/**
|
||||
* Set a password character
|
||||
*/
|
||||
void GuiText::SetPassChar(wchar_t p)
|
||||
{
|
||||
LOCK(this);
|
||||
passChar = p;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the Font
|
||||
*/
|
||||
void GuiText::SetFont(FreeTypeGX *f)
|
||||
void GuiText::SetLinesToDraw(int l)
|
||||
{
|
||||
LOCK(this);
|
||||
font = f;
|
||||
linestodraw = l;
|
||||
}
|
||||
|
||||
int GuiText::GetTextWidth()
|
||||
{
|
||||
LOCK(this);
|
||||
if(!text)
|
||||
return 0;
|
||||
|
||||
int newSize = size*this->GetScale();
|
||||
|
||||
(font ? font : fontSystem)->changeSize(newSize, widescreen ? newSize*0.8 : 0);
|
||||
return (font ? font : fontSystem)->getWidth(text);
|
||||
return fontSystem->getWidth(text, currentSize);
|
||||
}
|
||||
|
||||
void GuiText::SetWidescreen(bool w)
|
||||
int GuiText::GetTextWidth(int ind)
|
||||
{
|
||||
LOCK(this);
|
||||
widescreen = w;
|
||||
if(ind < 0 || ind >= (int) textDyn.size())
|
||||
return this->GetTextWidth();
|
||||
|
||||
return fontSystem->getWidth(textDyn[ind], currentSize);
|
||||
}
|
||||
|
||||
int GuiText::GetTextMaxWidth()
|
||||
{
|
||||
return maxWidth;
|
||||
}
|
||||
|
||||
const wchar_t * GuiText::GetDynText(int ind)
|
||||
{
|
||||
if(ind < 0 || ind >= (int) textDyn.size())
|
||||
return text;
|
||||
|
||||
return textDyn[ind];
|
||||
}
|
||||
|
||||
const wchar_t * GuiText::GetText()
|
||||
{
|
||||
return text;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change font
|
||||
*/
|
||||
bool GuiText::SetFont(const u8 *fontbuffer, const u32 filesize)
|
||||
{
|
||||
if(!fontbuffer || !filesize)
|
||||
return false;
|
||||
|
||||
LOCK(this);
|
||||
if(font)
|
||||
{
|
||||
delete font;
|
||||
font = NULL;
|
||||
}
|
||||
font = new FreeTypeGX(fontbuffer, filesize);
|
||||
textWidth = font->getWidth(text, currentSize);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void GuiText::MakeDottedText()
|
||||
{
|
||||
int pos = textDyn.size();
|
||||
textDyn.resize(pos+1);
|
||||
|
||||
int i = 0, currentWidth = 0;
|
||||
textDyn[pos] = new wchar_t[maxWidth];
|
||||
|
||||
while(text[i])
|
||||
{
|
||||
currentWidth += (font ? font : fontSystem)->getCharWidth(text[i], currentSize, i > 0 ? text[i-1] : 0x0000);
|
||||
if(currentWidth >= maxWidth)
|
||||
{
|
||||
if(i > 3)
|
||||
{
|
||||
textDyn[pos][i-3] = '.';
|
||||
textDyn[pos][i-2] = '.';
|
||||
textDyn[pos][i-1] = '.';
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
textDyn[pos][i] = text[i];
|
||||
|
||||
i++;
|
||||
}
|
||||
textDyn[pos][i] = 0;
|
||||
}
|
||||
|
||||
void GuiText::ScrollText()
|
||||
{
|
||||
if(textDyn.size() == 0)
|
||||
{
|
||||
int pos = textDyn.size();
|
||||
int i = 0, currentWidth = 0;
|
||||
textDyn.resize(pos+1);
|
||||
|
||||
textDyn[pos] = new wchar_t[maxWidth];
|
||||
|
||||
while(text[i] && currentWidth < maxWidth)
|
||||
{
|
||||
textDyn[pos][i] = text[i];
|
||||
|
||||
currentWidth += (font ? font : fontSystem)->getCharWidth(text[i], currentSize, i > 0 ? text[i-1] : 0x0000);
|
||||
|
||||
++i;
|
||||
}
|
||||
textDyn[pos][i] = 0;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if(frameCount % textScrollDelay != 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if(textScrollInitialDelay)
|
||||
{
|
||||
--textScrollInitialDelay;
|
||||
return;
|
||||
}
|
||||
|
||||
int strlen = wcslen(text);
|
||||
|
||||
++textScrollPos;
|
||||
if(textScrollPos > strlen)
|
||||
{
|
||||
textScrollPos = 0;
|
||||
textScrollInitialDelay = TEXT_SCROLL_INITIAL_DELAY;
|
||||
}
|
||||
|
||||
int ch = textScrollPos;
|
||||
int pos = textDyn.size()-1;
|
||||
|
||||
if(textDyn[pos])
|
||||
delete [] textDyn[pos];
|
||||
|
||||
textDyn[pos] = new wchar_t[maxWidth];
|
||||
|
||||
int i = 0, currentWidth = 0;
|
||||
|
||||
while(currentWidth < maxWidth)
|
||||
{
|
||||
if(ch > strlen-1)
|
||||
{
|
||||
textDyn[pos][i++] = ' ';
|
||||
textDyn[pos][i++] = ' ';
|
||||
textDyn[pos][i++] = ' ';
|
||||
ch = 0;
|
||||
}
|
||||
|
||||
textDyn[pos][i] = text[ch];
|
||||
++ch;
|
||||
++i;
|
||||
|
||||
currentWidth += (font ? font : fontSystem)->getCharWidth(text[ch], currentSize, ch > 0 ? text[ch-1] : 0x0000);
|
||||
}
|
||||
textDyn[pos][i] = 0;
|
||||
}
|
||||
|
||||
void GuiText::WrapText()
|
||||
{
|
||||
if(textDyn.size() > 0)
|
||||
return;
|
||||
|
||||
int i = 0;
|
||||
int ch = 0;
|
||||
int linenum = 0;
|
||||
int lastSpace = -1;
|
||||
int lastSpaceIndex = -1;
|
||||
int currentWidth = 0;
|
||||
|
||||
while(text[ch] && linenum < linestodraw)
|
||||
{
|
||||
if(linenum >= (int) textDyn.size())
|
||||
{
|
||||
textDyn.resize(linenum+1);
|
||||
textDyn[linenum] = new wchar_t[maxWidth];
|
||||
}
|
||||
|
||||
textDyn[linenum][i] = text[ch];
|
||||
textDyn[linenum][i+1] = 0;
|
||||
|
||||
currentWidth += (font ? font : fontSystem)->getCharWidth(text[ch], currentSize, ch > 0 ? text[ch-1] : 0x0000);
|
||||
|
||||
if(currentWidth >= maxWidth)
|
||||
{
|
||||
if(lastSpace >= 0)
|
||||
{
|
||||
textDyn[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;
|
||||
}
|
||||
|
||||
if(linenum+1 == linestodraw && text[ch+1] != 0x0000)
|
||||
{
|
||||
textDyn[linenum][i-2] = '.';
|
||||
textDyn[linenum][i-1] = '.';
|
||||
textDyn[linenum][i] = '.';
|
||||
textDyn[linenum][i+1] = 0;
|
||||
}
|
||||
|
||||
currentWidth = 0;
|
||||
++linenum;
|
||||
i = -1;
|
||||
}
|
||||
if(text[ch] == ' ' && i >= 0)
|
||||
{
|
||||
lastSpace = ch;
|
||||
lastSpaceIndex = i;
|
||||
}
|
||||
++ch;
|
||||
++i;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw the text on screen
|
||||
*/
|
||||
void GuiText::Draw()
|
||||
{
|
||||
LOCK(this);
|
||||
if(!text)
|
||||
return;
|
||||
|
||||
if(!this->IsVisible())
|
||||
if(!IsVisible())
|
||||
return;
|
||||
|
||||
GXColor c = color;
|
||||
c.a = this->GetAlpha();
|
||||
c.a = GetAlpha();
|
||||
|
||||
int newSize = size*this->GetScale();
|
||||
int newSize = size*GetScale();
|
||||
|
||||
(font ? font : fontSystem)->changeSize(newSize, widescreen ? newSize*0.8 : 0);
|
||||
int voffset = 0;
|
||||
|
||||
// if(alignmentVert == ALIGN_MIDDLE)
|
||||
// voffset = -newSize/2 + 2;
|
||||
|
||||
if(maxWidth > 0 && (font ? font : fontSystem)->getWidth(text) > maxWidth)
|
||||
if(newSize != currentSize)
|
||||
{
|
||||
if(wrapMode == GuiText::WRAP) // text wrapping
|
||||
currentSize = newSize;
|
||||
|
||||
if(text)
|
||||
textWidth = (font ? font : fontSystem)->getWidth(text, currentSize);
|
||||
}
|
||||
|
||||
if(maxWidth > 0 && maxWidth <= textWidth)
|
||||
{
|
||||
if(wrapMode == DOTTED) // text dotted
|
||||
{
|
||||
int lineheight = newSize + 6;
|
||||
int strlen = wcslen(text);
|
||||
int i = 0;
|
||||
int ch = 0;
|
||||
int linenum = 0;
|
||||
int linemax = 200;
|
||||
int lastSpace = -1;
|
||||
int lastSpaceIndex = -1;
|
||||
wchar_t * tmptext[linemax];
|
||||
|
||||
totalLines=0;
|
||||
while(ch < strlen)
|
||||
{
|
||||
if(i == 0)
|
||||
{
|
||||
if (linenum <= linemax)
|
||||
{
|
||||
tmptext[linenum] = new wchar_t[strlen + 1];
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
tmptext[linenum][i] = text[ch];
|
||||
tmptext[linenum][i+1] = 0;
|
||||
if(textDyn.size() == 0)
|
||||
MakeDottedText();
|
||||
|
||||
//if(text[ch] == ' ' || ch == strlen-1)
|
||||
//{
|
||||
if((font ? font : fontSystem)->getWidth(tmptext[linenum]) >= maxWidth)
|
||||
//if(fontSystem->getWidth(tmptext[linenum]) >= maxWidth)
|
||||
{
|
||||
if(lastSpace >= 0)
|
||||
{
|
||||
tmptext[linenum][lastSpaceIndex] = 0; // discard space, and everything after
|
||||
ch = lastSpace; // go backwards to the last space
|
||||
lastSpace = -1; // we have used this space
|
||||
lastSpaceIndex = -1;
|
||||
}
|
||||
linenum++;
|
||||
i = -1;
|
||||
}
|
||||
else if(ch == strlen-1)
|
||||
{
|
||||
linenum++;
|
||||
}
|
||||
//}
|
||||
if(text[ch] == ' ' && i >= 0)
|
||||
{
|
||||
lastSpace = ch;
|
||||
lastSpaceIndex = i;
|
||||
}
|
||||
if(text[ch] == '\n' && ch != strlen-1 && i >= 0)
|
||||
{
|
||||
linenum++;
|
||||
i = -1;
|
||||
}
|
||||
ch++;
|
||||
i++;
|
||||
}
|
||||
totalLines = linenum;
|
||||
|
||||
if(alignmentVert == ALIGN_MIDDLE)
|
||||
voffset = voffset - (lineheight*linenum)/2 + lineheight/2;
|
||||
|
||||
if (numLines <0){
|
||||
for(i=0; i < linenum; i++)
|
||||
{
|
||||
(font ? font : fontSystem)->drawText(this->GetLeft(), this->GetTop()+voffset+i*lineheight, tmptext[i], c, style);
|
||||
delete tmptext[i];
|
||||
}
|
||||
}
|
||||
|
||||
//put in for txt vertical txt scrolling
|
||||
else {
|
||||
int j;
|
||||
i=0;
|
||||
for(j=firstLine-1; j < numLines+firstLine-1; j++)
|
||||
{
|
||||
//if (j<linenum-(firstLine-1))
|
||||
if (j < linenum)
|
||||
(font ? font : fontSystem)->drawText(this->GetLeft(), this->GetTop()+voffset+i*lineheight, tmptext[j], c, style);
|
||||
i++;
|
||||
}
|
||||
for(i=0; i < linenum; i++)
|
||||
{
|
||||
delete tmptext[i];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(textDyn.size() > 0)
|
||||
(font ? font : fontSystem)->drawText(this->GetLeft(), this->GetTop(), 0, textDyn[textDyn.size()-1], currentSize, c, style);
|
||||
}
|
||||
else if(wrapMode == GuiText::DOTTED) // text dotted
|
||||
|
||||
else if(wrapMode == SCROLL_HORIZONTAL)
|
||||
{
|
||||
wchar_t save[4];
|
||||
int strlen = wcslen(text);
|
||||
int dotPos=strlen-3;
|
||||
int i;
|
||||
bool drawed = false;
|
||||
while(dotPos > 0 && drawed == false)
|
||||
{
|
||||
for(i=0; i<4; i++) // save Text for "..."
|
||||
{
|
||||
save[i] = text[dotPos+i];
|
||||
text[dotPos+i] = (i != 3 ? _TEXT('.') : 0);
|
||||
}
|
||||
if(((font ? font : fontSystem)->getWidth(text)) <= maxWidth)
|
||||
{
|
||||
(font ? font : fontSystem)->drawText(this->GetLeft(), this->GetTop()+voffset, text, c, style);
|
||||
drawed = true;
|
||||
}
|
||||
ScrollText();
|
||||
|
||||
for(i=0; i<4; i++) // write saved Text back
|
||||
text[dotPos+i] = save[i];
|
||||
dotPos--;
|
||||
}
|
||||
if(!drawed)
|
||||
(font ? font : fontSystem)->drawText(this->GetLeft(), this->GetTop()+voffset, text, c, style);
|
||||
}
|
||||
else if(wrapMode == GuiText::SCROLL) // text scroller
|
||||
if(textDyn.size() > 0)
|
||||
(font ? font : fontSystem)->drawText(this->GetLeft(), this->GetTop(), 0, textDyn[textDyn.size()-1], currentSize, c, style);
|
||||
}
|
||||
else if(wrapMode == WRAP)
|
||||
{
|
||||
wchar_t save;
|
||||
|
||||
if(scrollPos2 == 0 || frameCount > scrollDelay+5)
|
||||
{
|
||||
scrollPos1 = 0;
|
||||
scrollOffset = 0;
|
||||
for(scrollPos2 = wcslen(text); scrollPos2 > 1; scrollPos2--)
|
||||
{
|
||||
save = text[scrollPos2]; // save Pos2
|
||||
text[scrollPos2] = 0;
|
||||
int textWidth = (font ? font : fontSystem)->getWidth(text);
|
||||
text[scrollPos2] = save; // restore Pos2
|
||||
if(textWidth <= maxWidth)
|
||||
break;
|
||||
}
|
||||
scrollDelay = frameCount+50; // wait 50 Frames before beginning with scrolling
|
||||
}
|
||||
else if(scrollPos2 > 0 && frameCount >= scrollDelay)
|
||||
{
|
||||
|
||||
if(--scrollOffset < 0)
|
||||
{
|
||||
wchar_t tmp[] = { text[scrollPos1], text[scrollPos1+1], 0 };
|
||||
scrollOffset += (font ? font : fontSystem)->getWidth(tmp) - (font ? font : fontSystem)->getWidth(tmp+1);
|
||||
scrollPos1++;
|
||||
}
|
||||
|
||||
int strlen = wcslen(text);
|
||||
for(; scrollPos2 < strlen; scrollPos2++)
|
||||
{
|
||||
save = text[scrollPos2+1]; // save Pos2
|
||||
text[scrollPos2+1] = 0;
|
||||
int textWidth = (font ? font : fontSystem)->getWidth(&text[scrollPos1]);
|
||||
text[scrollPos2+1] = save; // restore Pos2
|
||||
if(textWidth+scrollOffset > maxWidth)
|
||||
break;
|
||||
}
|
||||
if(scrollPos2 == strlen)
|
||||
{
|
||||
scrollPos2 = -scrollPos2;
|
||||
scrollDelay = frameCount+25; // when dir-change wait 25 Frames
|
||||
}
|
||||
else
|
||||
scrollDelay = frameCount+1; // wait 1 Frames
|
||||
}
|
||||
else if(frameCount >= scrollDelay)
|
||||
{
|
||||
scrollPos2 = -scrollPos2;
|
||||
|
||||
scrollOffset++;
|
||||
wchar_t tmp[] = { text[scrollPos1-1], text[scrollPos1], 0 };
|
||||
int tmpOffset = (font ? font : fontSystem)->getWidth(tmp) - (font ? font : fontSystem)->getWidth(tmp+1);
|
||||
if(scrollOffset >= tmpOffset)
|
||||
{
|
||||
scrollOffset -= tmpOffset;
|
||||
scrollPos1--;
|
||||
}
|
||||
int lineheight = currentSize + 6;
|
||||
int voffset = 0;
|
||||
if(alignmentVert == ALIGN_MIDDLE)
|
||||
voffset = -(lineheight*textDyn.size())/2 + lineheight/2;
|
||||
|
||||
for(; scrollPos2 > scrollPos1; scrollPos2--)
|
||||
{
|
||||
save = text[scrollPos2]; // save Pos2
|
||||
text[scrollPos2] = 0;
|
||||
int textWidth = (font ? font : fontSystem)->getWidth(&text[scrollPos1]);
|
||||
text[scrollPos2] = save; // restore Pos2
|
||||
if(textWidth+scrollOffset <= maxWidth)
|
||||
break;
|
||||
}
|
||||
if(scrollPos1 == 0)
|
||||
{
|
||||
scrollPos2 = -scrollPos2;
|
||||
scrollDelay = frameCount+25; // when dir-change wait 25 Frames
|
||||
}
|
||||
else
|
||||
scrollDelay = frameCount+1; // wait 10 Frames
|
||||
if(textDyn.size() == 0)
|
||||
WrapText();
|
||||
|
||||
scrollPos2 = -scrollPos2;
|
||||
}
|
||||
|
||||
uint16_t drawStyle = style;
|
||||
uint16_t drawX = this->GetLeft() + scrollOffset;
|
||||
|
||||
if((drawStyle & FTGX_JUSTIFY_MASK) == FTGX_JUSTIFY_CENTER)
|
||||
{
|
||||
drawStyle = (drawStyle & ~FTGX_JUSTIFY_MASK) | FTGX_JUSTIFY_LEFT;
|
||||
drawX -= maxWidth >> 1;
|
||||
}
|
||||
else if((drawStyle & FTGX_JUSTIFY_MASK) == FTGX_JUSTIFY_RIGHT)
|
||||
{
|
||||
drawStyle = (drawStyle & ~FTGX_JUSTIFY_MASK) | FTGX_JUSTIFY_LEFT;
|
||||
drawX -= maxWidth;
|
||||
}
|
||||
|
||||
save = text[abs(scrollPos2)]; // save Pos2
|
||||
text[abs(scrollPos2)] = 0;
|
||||
(font ? font : fontSystem)->drawText(drawX, this->GetTop()+voffset, &text[scrollPos1], c, drawStyle);
|
||||
text[abs(scrollPos2)] = save; // restore Pos2
|
||||
for(u32 i = 0; i < textDyn.size(); i++)
|
||||
{
|
||||
(font ? font : fontSystem)->drawText(this->GetLeft(), this->GetTop()+voffset+i*lineheight, 0, textDyn[i], currentSize, c, style);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
(font ? font : fontSystem)->drawText(this->GetLeft(), this->GetTop()+voffset, text, c, style);
|
||||
(font ? font : fontSystem)->drawText(this->GetLeft(), this->GetTop(), 0, text, currentSize, c, style, textWidth);
|
||||
}
|
||||
this->UpdateEffects();
|
||||
}
|
||||
|
@ -33,6 +33,7 @@ extern "C"
|
||||
#include "mload/mload.h"
|
||||
#include "mload/mload_modules.h"
|
||||
#include "FreeTypeGX.h"
|
||||
#include "FontSystem.h"
|
||||
#include "video.h"
|
||||
#include "audio.h"
|
||||
#include "menu.h"
|
||||
@ -63,8 +64,6 @@ extern char headlessID[8];
|
||||
#define CONSOLE_WIDTH 340
|
||||
#define CONSOLE_HEIGHT 218
|
||||
|
||||
FreeTypeGX *fontSystem=0;
|
||||
FreeTypeGX *fontClock=0;
|
||||
PartList partitions;
|
||||
u8 dbvideo =0;
|
||||
|
||||
@ -125,6 +124,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
printf("\n\tCheck for an existing cIOS");
|
||||
CheckForCIOS();
|
||||
printf("\n\tcIOS = %u (Rev %u)",IOS_GetVersion(), IOS_GetRevision());
|
||||
|
||||
// Let's load the cIOS now
|
||||
if(LoadAppCIOS() < 0)
|
||||
@ -134,13 +134,12 @@ int main(int argc, char *argv[])
|
||||
Sys_BackToLoader();
|
||||
}
|
||||
|
||||
printf("\n\tcIOS = %u (Rev %u)",IOS_GetVersion(), IOS_GetRevision());
|
||||
|
||||
// Init WBFS
|
||||
int ret = WBFS_Init(WBFS_DEVICE_USB);
|
||||
if (ret < 0)
|
||||
printf("\n\tWaiting for USB: ");
|
||||
if (MountWBFS() < 0)
|
||||
{
|
||||
printf("\nERROR: No WBFS drive mounted.");
|
||||
sleep(5);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
//if a ID was passed via args copy it and try to boot it after the partition is mounted
|
||||
@ -159,18 +158,11 @@ int main(int argc, char *argv[])
|
||||
WPAD_SetDataFormat(WPAD_CHAN_ALL,WPAD_FMT_BTNS_ACC_IR);
|
||||
WPAD_SetVRes(WPAD_CHAN_ALL, screenwidth, screenheight);
|
||||
|
||||
// load main font from file, or default to built-in font
|
||||
fontSystem = new FreeTypeGX();
|
||||
char *fontPath = NULL;
|
||||
asprintf(&fontPath, "%sfont.ttf", CFG.theme_path);
|
||||
fontSystem->loadFont(fontPath, font_ttf, font_ttf_size, 0);
|
||||
fontSystem->setCompatibilityMode(FTGX_COMPATIBILITY_DEFAULT_TEVOP_GX_PASSCLR | FTGX_COMPATIBILITY_DEFAULT_VTXDESC_GX_NONE);
|
||||
SetupDefaultFont(fontPath);
|
||||
free(fontPath);
|
||||
|
||||
fontClock = new FreeTypeGX();
|
||||
fontClock->loadFont(NULL, clock_ttf, clock_ttf_size, 0);
|
||||
fontClock->setCompatibilityMode(FTGX_COMPATIBILITY_DEFAULT_TEVOP_GX_PASSCLR | FTGX_COMPATIBILITY_DEFAULT_VTXDESC_GX_NONE);
|
||||
|
||||
gprintf("\n\tEnd of Main()");
|
||||
InitGUIThreads();
|
||||
MainMenu(MENU_CHECK);
|
||||
|
@ -65,7 +65,6 @@ static int ExitRequested = 0;
|
||||
|
||||
/*** Extern variables ***/
|
||||
extern struct discHdr * gameList;
|
||||
extern FreeTypeGX *fontClock;
|
||||
extern u8 shutdown;
|
||||
extern u8 reset;
|
||||
extern s32 gameSelected, gameStart;
|
||||
@ -343,7 +342,6 @@ int MainMenu(int menu) {
|
||||
delete GameIDTxt;
|
||||
delete cover;
|
||||
delete coverImg;
|
||||
delete fontClock;
|
||||
delete fontSystem;
|
||||
ShutdownAudio();
|
||||
StopGX();
|
||||
|
@ -559,11 +559,11 @@ int MenuDiscList() {
|
||||
GuiText clockTimeBack("88:88", 40, (GXColor) {THEME.clock.r, THEME.clock.g, THEME.clock.b, THEME.clock.a/6});
|
||||
clockTimeBack.SetAlignment(THEME.clock_align, ALIGN_TOP);
|
||||
clockTimeBack.SetPosition(THEME.clock_x, THEME.clock_y);
|
||||
clockTimeBack.SetFont(fontClock);
|
||||
clockTimeBack.SetFont(clock_ttf, clock_ttf_size);
|
||||
GuiText clockTime(theTime, 40, THEME.clock);
|
||||
clockTime.SetAlignment(THEME.clock_align, ALIGN_TOP);
|
||||
clockTime.SetPosition(THEME.clock_x, THEME.clock_y);
|
||||
clockTime.SetFont(fontClock);
|
||||
clockTime.SetFont(clock_ttf, clock_ttf_size);
|
||||
|
||||
HaltGui();
|
||||
GuiWindow w(screenwidth, screenheight);
|
||||
|
@ -163,7 +163,7 @@ int DiscBrowse(struct discHdr * header) {
|
||||
GuiText titleTxt(get_title(header), 28, (GXColor) {0, 0, 0, 255});
|
||||
titleTxt.SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
|
||||
titleTxt.SetPosition(12,40);
|
||||
titleTxt.SetMaxWidth(356, GuiText::SCROLL);
|
||||
titleTxt.SetMaxWidth(356, SCROLL_HORIZONTAL);
|
||||
|
||||
GuiImage settingsbackground(&settingsbg);
|
||||
GuiButton settingsbackgroundbtn(settingsbackground.GetWidth(), settingsbackground.GetHeight());
|
||||
|
@ -175,30 +175,30 @@ static void ProgressWindow(const char *title, const char *msg1, const char *msg2
|
||||
msg1Txt.SetPosition(0,120);
|
||||
else
|
||||
msg1Txt.SetPosition(0,100);
|
||||
msg1Txt.SetMaxWidth(430, GuiText::DOTTED);
|
||||
msg1Txt.SetMaxWidth(430, DOTTED);
|
||||
|
||||
GuiText msg2Txt(msg2, 22, THEME.prompttext );
|
||||
msg2Txt.SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
|
||||
msg2Txt.SetPosition(0,125);
|
||||
msg2Txt.SetMaxWidth(430, GuiText::DOTTED);
|
||||
msg2Txt.SetMaxWidth(430, DOTTED);
|
||||
|
||||
GuiText prsTxt("%", 22, THEME.prompttext);
|
||||
prsTxt.SetAlignment(ALIGN_RIGHT, ALIGN_MIDDLE);
|
||||
prsTxt.SetPosition(-188,40);
|
||||
|
||||
GuiText timeTxt(NULL, 22, THEME.prompttext);
|
||||
GuiText timeTxt((char*) NULL, 22, THEME.prompttext);
|
||||
timeTxt.SetAlignment(ALIGN_LEFT, ALIGN_BOTTOM);
|
||||
timeTxt.SetPosition(280,-50);
|
||||
|
||||
GuiText sizeTxt(NULL, 22, THEME.prompttext);
|
||||
GuiText sizeTxt((char*) NULL, 22, THEME.prompttext);
|
||||
sizeTxt.SetAlignment(ALIGN_LEFT, ALIGN_BOTTOM);
|
||||
sizeTxt.SetPosition(50, -50);
|
||||
|
||||
GuiText speedTxt(NULL, 22, THEME.prompttext);
|
||||
GuiText speedTxt((char*) NULL, 22, THEME.prompttext);
|
||||
speedTxt.SetAlignment(ALIGN_LEFT, ALIGN_BOTTOM);
|
||||
speedTxt.SetPosition(50, -74);
|
||||
|
||||
GuiText prTxt(NULL, 26, THEME.prompttext);
|
||||
GuiText prTxt((char*) NULL, 26, THEME.prompttext);
|
||||
prTxt.SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE);
|
||||
prTxt.SetPosition(200, 40);
|
||||
|
||||
@ -208,8 +208,8 @@ static void ProgressWindow(const char *title, const char *msg1, const char *msg2
|
||||
progressbarEmptyImg.SetPosition(80,40);
|
||||
progressbarEmptyImg.SetTile(78);
|
||||
progressbarImg.SetPosition(80, 40);
|
||||
msg1Txt.SetMaxWidth(380, GuiText::DOTTED);
|
||||
msg2Txt.SetMaxWidth(380, GuiText::DOTTED);
|
||||
msg1Txt.SetMaxWidth(380, DOTTED);
|
||||
msg2Txt.SetMaxWidth(380, DOTTED);
|
||||
|
||||
timeTxt.SetPosition(250,-50);
|
||||
timeTxt.SetFontSize(20);
|
||||
|
@ -15,6 +15,7 @@
|
||||
#include "language/gettext.h"
|
||||
#include "libwiigui/gui.h"
|
||||
#include "libwiigui/gui_diskcover.h"
|
||||
#include "libwiigui/Text.hpp"
|
||||
#include "network/networkops.h"
|
||||
#include "network/http.h"
|
||||
#include "prompts/PromptWindows.h"
|
||||
@ -71,9 +72,9 @@ extern void HaltGui();
|
||||
***************************************************************************/
|
||||
int OnScreenNumpad(char * var, u32 maxlen) {
|
||||
int save = -1;
|
||||
|
||||
|
||||
GuiNumpad numpad(var, maxlen);
|
||||
|
||||
|
||||
GuiSound btnSoundOver(button_over_pcm, button_over_pcm_size, Settings.sfxvolume);
|
||||
// because destroy GuiSound must wait while sound playing is finished, we use a global sound
|
||||
if(!btnClick2) btnClick2=new GuiSound(button_click2_pcm, button_click2_pcm_size,Settings.sfxvolume);
|
||||
@ -104,7 +105,7 @@ int OnScreenNumpad(char * var, u32 maxlen) {
|
||||
GuiButton cancelBtn(&cancelBtnImg,&cancelBtnImg, 1, 4, -5, -15, &trigA, &btnSoundOver, btnClick2,1);
|
||||
cancelBtn.SetLabel(&cancelBtnTxt);
|
||||
cancelBtn.SetTrigger(&trigB);
|
||||
|
||||
|
||||
numpad.Append(&okBtn);
|
||||
numpad.Append(&cancelBtn);
|
||||
|
||||
@ -132,7 +133,7 @@ int OnScreenNumpad(char * var, u32 maxlen) {
|
||||
mainWindow->SetState(STATE_DEFAULT);
|
||||
ResumeGui();
|
||||
gprintf("\t%s",(save == 1?"saved":"discarded"));
|
||||
return save;
|
||||
return save;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
@ -299,7 +300,7 @@ void WindowCredits() {
|
||||
i++;
|
||||
y+=26;
|
||||
|
||||
GuiText::SetPresets(22, (GXColor) {255, 255, 255, 255}, 0, GuiText::WRAP,FTGX_JUSTIFY_LEFT | FTGX_ALIGN_TOP, ALIGN_LEFT, ALIGN_TOP);
|
||||
GuiText::SetPresets(22, (GXColor) {255, 255, 255, 255}, 3000, FTGX_JUSTIFY_LEFT | FTGX_ALIGN_TOP, ALIGN_LEFT, ALIGN_TOP);
|
||||
|
||||
txt[i] = new GuiText(tr("Coding:"));
|
||||
txt[i]->SetAlignment(ALIGN_LEFT, ALIGN_TOP);
|
||||
@ -1159,7 +1160,7 @@ int GameWindowPrompt() {
|
||||
GuiText nameTxt("", 22, THEME.prompttext);
|
||||
if (Settings.wsprompt == yes)
|
||||
nameTxt.SetWidescreen(CFG.widescreen);
|
||||
nameTxt.SetMaxWidth(350, GuiText::SCROLL);
|
||||
nameTxt.SetMaxWidth(350, SCROLL_HORIZONTAL);
|
||||
GuiButton nameBtn(120,50);
|
||||
nameBtn.SetLabel(&nameTxt);
|
||||
// nameBtn.SetLabelOver(&nameTxt);
|
||||
@ -1174,7 +1175,7 @@ int GameWindowPrompt() {
|
||||
nameBtn.SetEffectGrow();
|
||||
}
|
||||
|
||||
GuiText sizeTxt(NULL, 22, THEME.prompttext); //TODO: get the size here
|
||||
GuiText sizeTxt((char*) NULL, 22, THEME.prompttext); //TODO: get the size here
|
||||
sizeTxt.SetAlignment(ALIGN_RIGHT, ALIGN_TOP);
|
||||
sizeTxt.SetPosition(-60,70);
|
||||
|
||||
@ -1190,7 +1191,7 @@ int GameWindowPrompt() {
|
||||
diskImg2.SetAngle(angle);
|
||||
diskImg2.SetBeta(180);
|
||||
|
||||
GuiText playcntTxt(NULL, 18, THEME.info);
|
||||
GuiText playcntTxt((char*) NULL, 18, THEME.info);
|
||||
playcntTxt.SetAlignment(ALIGN_CENTRE, ALIGN_MIDDLE);
|
||||
playcntTxt.SetPosition(-115,45);
|
||||
|
||||
@ -1295,7 +1296,7 @@ int GameWindowPrompt() {
|
||||
|
||||
promptWindow.Append(&diskImg2);
|
||||
promptWindow.Append(&btn1);
|
||||
|
||||
|
||||
short changed = -1;
|
||||
GuiImageData * diskCover = NULL;
|
||||
GuiImageData * diskCover2 = NULL;
|
||||
@ -1746,7 +1747,7 @@ DiscWait(const char *title, const char *msg, const char *btn1Label, const char *
|
||||
}
|
||||
}
|
||||
|
||||
GuiText timerTxt(NULL, 26, THEME.prompttext);
|
||||
GuiText timerTxt((char*) NULL, 26, THEME.prompttext);
|
||||
timerTxt.SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
|
||||
timerTxt.SetPosition(0,160);
|
||||
|
||||
@ -2143,15 +2144,15 @@ ProgressDownloadWindow(int choice2) {
|
||||
titleTxt.SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
|
||||
titleTxt.SetPosition(0,60);
|
||||
|
||||
GuiText msgTxt(NULL, 20, THEME.prompttext);
|
||||
GuiText msgTxt((char*) NULL, 20, THEME.prompttext);
|
||||
msgTxt.SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
|
||||
msgTxt.SetPosition(0,130);
|
||||
|
||||
GuiText msg2Txt(NULL, 26, THEME.prompttext);
|
||||
GuiText msg2Txt((char*) NULL, 26, THEME.prompttext);
|
||||
msg2Txt.SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
|
||||
msg2Txt.SetPosition(0,100);
|
||||
|
||||
GuiText prTxt(NULL, 26, THEME.prompttext);
|
||||
GuiText prTxt((char*) NULL, 26, THEME.prompttext);
|
||||
prTxt.SetAlignment(ALIGN_CENTRE, ALIGN_MIDDLE);
|
||||
prTxt.SetPosition(0, 40);
|
||||
|
||||
@ -2768,7 +2769,7 @@ int ProgressUpdateWindow() {
|
||||
} else {
|
||||
filesize = download_request("http://www.techjawa.com/usbloadergx/ULNR.file");//for some reason it didn't download completely when saved as a wad.
|
||||
}
|
||||
|
||||
|
||||
if (filesize > 0) {
|
||||
|
||||
pfile = fopen(dolpath, "wb");//here we save the txt as a wad
|
||||
@ -2889,7 +2890,7 @@ int ProgressUpdateWindow() {
|
||||
|
||||
return 1;
|
||||
}
|
||||
#else
|
||||
#else
|
||||
int ProgressUpdateWindow() {
|
||||
|
||||
gprintf("\nProgressUpdateWindow(not full channel)");
|
||||
@ -2954,7 +2955,7 @@ int ProgressUpdateWindow() {
|
||||
msg2Txt.SetAlignment(ALIGN_CENTRE, ALIGN_MIDDLE);
|
||||
msg2Txt.SetPosition(0, 50);
|
||||
|
||||
GuiText prTxt(NULL, 26, THEME.prompttext);
|
||||
GuiText prTxt((char*) NULL, 26, THEME.prompttext);
|
||||
prTxt.SetAlignment(ALIGN_CENTRE, ALIGN_MIDDLE);
|
||||
prTxt.SetPosition(0, 7);
|
||||
|
||||
@ -3053,7 +3054,7 @@ int ProgressUpdateWindow() {
|
||||
promptWindow.Append(&progressbarOutlineImg);
|
||||
promptWindow.Append(&prTxt);
|
||||
msgTxt.SetTextf("%s Rev%i", tr("Update to"), newrev);
|
||||
|
||||
|
||||
s32 filesize;
|
||||
if (Settings.beta_upgrades) {
|
||||
char url[255];
|
||||
@ -3487,7 +3488,7 @@ HBCWindowPrompt(const char *name, const char *coder, const char *version,
|
||||
GuiText nameTxt(name,30 , THEME.prompttext);
|
||||
nameTxt.SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
|
||||
nameTxt.SetPosition(0,-15);
|
||||
nameTxt.SetMaxWidth(430, GuiText::SCROLL);
|
||||
nameTxt.SetMaxWidth(430, SCROLL_HORIZONTAL);
|
||||
|
||||
|
||||
if (strcmp(coder,""))
|
||||
@ -3512,11 +3513,11 @@ HBCWindowPrompt(const char *name, const char *coder, const char *version,
|
||||
release_dateTxt.SetMaxWidth(430);
|
||||
|
||||
int pagesize = 6;
|
||||
GuiText long_descriptionTxt(long_description, 20, THEME.prompttext);
|
||||
Text long_descriptionTxt(long_description, 20, THEME.prompttext);
|
||||
long_descriptionTxt.SetAlignment(ALIGN_LEFT, ALIGN_TOP);
|
||||
long_descriptionTxt.SetPosition(46,117);
|
||||
long_descriptionTxt.SetMaxWidth(360);
|
||||
long_descriptionTxt.SetNumLines(pagesize);
|
||||
long_descriptionTxt.SetLinesToDraw(pagesize);
|
||||
|
||||
//convert filesize from u64 to char and put unit of measurement after it
|
||||
char temp2[7];
|
||||
@ -3623,18 +3624,17 @@ HBCWindowPrompt(const char *name, const char *coder, const char *version,
|
||||
gprintf("...It's easy, mmmmmmKay");
|
||||
}
|
||||
else if ((arrowUpBtn.GetState()==STATE_CLICKED||arrowUpBtn.GetState()==STATE_HELD) ) {
|
||||
if (long_descriptionTxt.GetFirstLine()>1)
|
||||
long_descriptionTxt.SetFirstLine(long_descriptionTxt.GetFirstLine()-1);
|
||||
long_descriptionTxt.SetTextLine(long_descriptionTxt.GetCurrPos()-1);
|
||||
usleep(60000);
|
||||
if (!((ButtonsHold() & WPAD_BUTTON_UP)||(ButtonsHold() & PAD_BUTTON_UP)))
|
||||
arrowUpBtn.ResetState();
|
||||
} else if ((arrowDownBtn.GetState()==STATE_CLICKED||arrowDownBtn.GetState()==STATE_HELD)
|
||||
&&long_descriptionTxt.GetTotalLines()>pagesize
|
||||
&&long_descriptionTxt.GetFirstLine()-1<long_descriptionTxt.GetTotalLines()-pagesize) {
|
||||
&&long_descriptionTxt.GetTotalLinesCount()>pagesize
|
||||
&&long_descriptionTxt.GetCurrPos()-1<long_descriptionTxt.GetTotalLinesCount()-pagesize) {
|
||||
int l=0;
|
||||
l=long_descriptionTxt.GetFirstLine()+1;
|
||||
l=long_descriptionTxt.GetCurrPos()+1;
|
||||
|
||||
long_descriptionTxt.SetFirstLine(l);
|
||||
long_descriptionTxt.SetTextLine(l);
|
||||
usleep(60000);
|
||||
if (!((ButtonsHold() & WPAD_BUTTON_DOWN)||(ButtonsHold() & PAD_BUTTON_DOWN)))
|
||||
arrowDownBtn.ResetState();
|
||||
|
@ -261,7 +261,7 @@ int TitleBrowser(u32 type) {
|
||||
GuiText titleTxt(tr("Title Launcher"), 28, (GXColor) {0, 0, 0, 255});
|
||||
titleTxt.SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
|
||||
titleTxt.SetPosition(12,40);
|
||||
titleTxt.SetMaxWidth(356, GuiText::SCROLL);
|
||||
titleTxt.SetMaxWidth(356, SCROLL_HORIZONTAL);
|
||||
|
||||
GuiImage settingsbackground(&settingsbg);
|
||||
GuiButton settingsbackgroundbtn(settingsbackground.GetWidth(), settingsbackground.GetHeight());
|
||||
|
@ -364,11 +364,11 @@ int BrowseDevice(char * Path, int Path_size, int Flags, FILTERCASCADE *Filter/*=
|
||||
fileBrowser.SetPosition(0, 120);
|
||||
|
||||
GuiImageData Address(addressbar_textbox_png);
|
||||
GuiText AdressText(NULL, 20, (GXColor) { 0, 0, 0, 255});
|
||||
GuiText AdressText((char*) NULL, 20, (GXColor) { 0, 0, 0, 255});
|
||||
AdressText.SetTextf("%s%s", browser->rootdir, browser->dir);
|
||||
AdressText.SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE);
|
||||
AdressText.SetPosition(20, 0);
|
||||
AdressText.SetMaxWidth(Address.GetWidth()-40, GuiText::SCROLL);
|
||||
AdressText.SetMaxWidth(Address.GetWidth()-40, SCROLL_HORIZONTAL);
|
||||
GuiImage AdressbarImg(&Address);
|
||||
GuiButton Adressbar(Address.GetWidth(), Address.GetHeight());
|
||||
Adressbar.SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
|
||||
|
@ -8,6 +8,7 @@
|
||||
#include "usbloader/wbfs.h"
|
||||
#include "language/gettext.h"
|
||||
#include "libwiigui/gui.h"
|
||||
#include "libwiigui/Text.hpp"
|
||||
#include "../xml/xml.h"
|
||||
#include "menu.h"
|
||||
#include "menu/menus.h"
|
||||
@ -126,7 +127,7 @@ int showGameInfo(char *ID) {
|
||||
GuiText * publisherTxt = NULL;
|
||||
GuiText * developerTxt = NULL;
|
||||
GuiText * titleTxt = NULL;
|
||||
GuiText * synopsisTxt = NULL;
|
||||
Text * synopsisTxt = NULL;
|
||||
GuiText ** genreTxt = NULL;
|
||||
GuiText ** wifiTxt = NULL;
|
||||
GuiText * wiitdb1Txt = NULL;
|
||||
@ -594,7 +595,7 @@ int showGameInfo(char *ID) {
|
||||
if (strcmp(gameinfo.title,"") != 0) {
|
||||
snprintf(linebuf, sizeof(linebuf), "%s",gameinfo.title);
|
||||
titleTxt = new GuiText(linebuf, titlefontsize, (GXColor) {0,0,0, 255});
|
||||
titleTxt->SetMaxWidth(350, GuiText::SCROLL);
|
||||
titleTxt->SetMaxWidth(350, SCROLL_HORIZONTAL);
|
||||
//while (titleTxt->GetWidth()>250) { titleTxt->SetFontSize(titlefontsize-=2); }
|
||||
titleTxt->SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
|
||||
titleTxt->SetPosition(txtXOffset,12+titley);
|
||||
@ -662,7 +663,7 @@ int showGameInfo(char *ID) {
|
||||
snprintf(linebuf, sizeof(linebuf), "%s %s", tr("Published by"), gameinfo.publisher);
|
||||
publisherTxt = new GuiText(linebuf, 16, (GXColor) {0,0,0, 255});
|
||||
if (publisherTxt->GetWidth()>250) newline=2;
|
||||
publisherTxt->SetMaxWidth(250,GuiText::WRAP);
|
||||
publisherTxt->SetMaxWidth(250, WRAP);
|
||||
publisherTxt->SetAlignment(ALIGN_RIGHT, ALIGN_TOP);
|
||||
publisherTxt->SetPosition(-17,12+indexy);
|
||||
indexy+=(20 * newline);
|
||||
@ -675,7 +676,7 @@ int showGameInfo(char *ID) {
|
||||
snprintf(linebuf, sizeof(linebuf), "%s %s", tr("Developed by"), gameinfo.developer);
|
||||
developerTxt = new GuiText(linebuf, 16, (GXColor) {0,0,0, 255});
|
||||
if (developerTxt->GetWidth()>250) newline=2;
|
||||
developerTxt->SetMaxWidth(250,GuiText::WRAP);
|
||||
developerTxt->SetMaxWidth(250, WRAP);
|
||||
developerTxt->SetAlignment(ALIGN_RIGHT, ALIGN_TOP);
|
||||
developerTxt->SetPosition(-17,12+indexy);
|
||||
indexy+=(20 * newline);
|
||||
@ -723,11 +724,11 @@ int showGameInfo(char *ID) {
|
||||
int pagesize=12;
|
||||
if (strcmp(gameinfo.synopsis,"") !=0) {
|
||||
snprintf(linebuf, sizeof(linebuf), "%s", gameinfo.synopsis);
|
||||
synopsisTxt = new GuiText(linebuf, 16, (GXColor) {0,0,0, 255});
|
||||
synopsisTxt->SetMaxWidth(350,GuiText::WRAP);
|
||||
synopsisTxt = new Text(linebuf, 16, (GXColor) {0,0,0, 255});
|
||||
synopsisTxt->SetMaxWidth(350);
|
||||
synopsisTxt->SetAlignment(ALIGN_LEFT, ALIGN_TOP);
|
||||
synopsisTxt->SetPosition(0,0);
|
||||
synopsisTxt->SetNumLines(pagesize);
|
||||
synopsisTxt->SetLinesToDraw(pagesize);
|
||||
//synopsisTxt->SetFirstLine(12);
|
||||
|
||||
dialogBoxImg11 = new GuiImage(&dialogBox1);
|
||||
@ -864,22 +865,22 @@ int showGameInfo(char *ID) {
|
||||
|
||||
} else if ((upBtn.GetState()==STATE_CLICKED||upBtn.GetState()==STATE_HELD) && page==2) {
|
||||
//int l=synopsisTxt->GetFirstLine()-1;
|
||||
if (synopsisTxt->GetFirstLine()>1)
|
||||
synopsisTxt->SetFirstLine(synopsisTxt->GetFirstLine()-1);
|
||||
if (synopsisTxt->GetCurrPos()>1)
|
||||
synopsisTxt->SetTextLine(synopsisTxt->GetCurrPos()-1);
|
||||
usleep(60000);
|
||||
if (!((ButtonsHold() & WPAD_BUTTON_UP)||(ButtonsHold() & PAD_BUTTON_UP)))
|
||||
upBtn.ResetState();
|
||||
} else if ((dnBtn.GetState()==STATE_CLICKED||dnBtn.GetState()==STATE_HELD) && page==2
|
||||
&&synopsisTxt->GetTotalLines()>pagesize
|
||||
&&synopsisTxt->GetFirstLine()-1<synopsisTxt->GetTotalLines()-pagesize) {
|
||||
&&synopsisTxt->GetTotalLinesCount()>pagesize
|
||||
&&synopsisTxt->GetCurrPos()-1<synopsisTxt->GetTotalLinesCount()-pagesize) {
|
||||
int l=0;
|
||||
//if(synopsisTxt->GetTotalLines()>pagesize)
|
||||
l=synopsisTxt->GetFirstLine()+1;
|
||||
l=synopsisTxt->GetCurrPos()+1;
|
||||
|
||||
//if (l>(synopsisTxt->GetTotalLines()+1)-pagesize)
|
||||
//l=(synopsisTxt->GetTotalLines()+1)-pagesize;
|
||||
|
||||
synopsisTxt->SetFirstLine(l);
|
||||
synopsisTxt->SetTextLine(l);
|
||||
usleep(60000);
|
||||
if (!((ButtonsHold() & WPAD_BUTTON_DOWN)||(ButtonsHold() & PAD_BUTTON_DOWN)))
|
||||
dnBtn.ResetState();
|
||||
|
@ -2275,7 +2275,7 @@ int GameSettings(struct discHdr * header)
|
||||
GuiText titleTxt(!mountMethod?get_title(header):gameName, 28, (GXColor) {0, 0, 0, 255});
|
||||
titleTxt.SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
|
||||
titleTxt.SetPosition(12,40);
|
||||
titleTxt.SetMaxWidth(356, GuiText::SCROLL);
|
||||
titleTxt.SetMaxWidth(356, SCROLL_HORIZONTAL);
|
||||
|
||||
GuiImage settingsbackground(&settingsbg);
|
||||
|
||||
|
@ -182,7 +182,7 @@ static int Theme_Prompt(const char *title, const char *author, GuiImageData *thu
|
||||
GuiText titleTxt2(title, 18, THEME.prompttext);
|
||||
titleTxt2.SetAlignment(ALIGN_LEFT, ALIGN_TOP);
|
||||
titleTxt2.SetPosition(230, 50);
|
||||
titleTxt2.SetMaxWidth(dialogBox.GetWidth()-220, GuiText::WRAP);
|
||||
titleTxt2.SetMaxWidth(dialogBox.GetWidth()-220, WRAP);
|
||||
|
||||
GuiText authorTxt(tr("Author:"), 18, THEME.prompttext);
|
||||
authorTxt.SetAlignment(ALIGN_LEFT, ALIGN_TOP);
|
||||
@ -191,7 +191,7 @@ static int Theme_Prompt(const char *title, const char *author, GuiImageData *thu
|
||||
GuiText authorTxt2(author, 18, THEME.prompttext);
|
||||
authorTxt2.SetAlignment(ALIGN_LEFT, ALIGN_TOP);
|
||||
authorTxt2.SetPosition(230, 120);
|
||||
authorTxt2.SetMaxWidth(dialogBox.GetWidth()-220, GuiText::DOTTED);
|
||||
authorTxt2.SetMaxWidth(dialogBox.GetWidth()-220, DOTTED);
|
||||
|
||||
GuiText downloadBtnTxt(tr("Download") , 22, THEME.prompttext);
|
||||
downloadBtnTxt.SetMaxWidth(btnOutline.GetWidth()-30);
|
||||
@ -417,7 +417,7 @@ int Theme_Downloader()
|
||||
GoRightBtn.SetTrigger(&trigPlus);
|
||||
|
||||
GuiImage PageindicatorImg(&PageindicatorImgData);
|
||||
GuiText PageindicatorTxt(NULL, 22, (GXColor) { 0, 0, 0, 255});
|
||||
GuiText PageindicatorTxt((char *) NULL, 22, (GXColor) { 0, 0, 0, 255});
|
||||
GuiButton PageIndicatorBtn(PageindicatorImg.GetWidth(), PageindicatorImg.GetHeight());
|
||||
PageIndicatorBtn.SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
|
||||
PageIndicatorBtn.SetPosition(110, 400);
|
||||
@ -518,7 +518,7 @@ int Theme_Downloader()
|
||||
MainButtonTxt[n] = new GuiText(Theme->GetThemeTitle(i), 18, (GXColor) { 0, 0, 0, 255});
|
||||
MainButtonTxt[n]->SetAlignment(ALIGN_CENTER, ALIGN_TOP);
|
||||
MainButtonTxt[n]->SetPosition(0, 10);
|
||||
MainButtonTxt[n]->SetMaxWidth(theme_box_Data.GetWidth()-10, GuiText::DOTTED);
|
||||
MainButtonTxt[n]->SetMaxWidth(theme_box_Data.GetWidth()-10, DOTTED);
|
||||
|
||||
sprintf(url, "%s", Theme->GetImageLink(i));
|
||||
|
||||
|
@ -225,7 +225,7 @@ int __Menu_GetPrevFilter(int t, wchar_t* gameFilter, u32 gameFiltered, wchar_t *
|
||||
}
|
||||
}
|
||||
|
||||
wchar_t *wname = FreeTypeGX::charToWideChar(get_title(header));
|
||||
wchar_t *wname = charToWideChar(get_title(header));
|
||||
if(wname) nameList.push_back(wname);
|
||||
}
|
||||
|
||||
@ -268,7 +268,7 @@ int __Menu_GetGameFilter_NextList(discHdr *gameList, u32 gameCnt, wchar_t **Pgam
|
||||
for(i=0; i<gameCnt; i++)
|
||||
{
|
||||
u32 nextFilterChar = 0x10000;
|
||||
wchar_t *gameName = FreeTypeGX::charToWideChar(get_title(&gameList[i]));
|
||||
wchar_t *gameName = charToWideChar(get_title(&gameList[i]));
|
||||
if(gameName == NULL) goto error;
|
||||
|
||||
if(wcslen(gameName) > filter_len)
|
||||
@ -439,7 +439,7 @@ int buildTitleList(int t, wchar_t* gameFilter, discHdr ** PgameList, u32 *PgameC
|
||||
|
||||
if(gameFilter && *gameFilter) {
|
||||
u32 filter_len = wcslen(gameFilter);
|
||||
wchar_t *gameName = FreeTypeGX::charToWideChar(get_title(header));
|
||||
wchar_t *gameName = charToWideChar(get_title(header));
|
||||
if (!gameName || wcsnicmp(gameName, gameFilter, filter_len)) {
|
||||
delete [] gameName;
|
||||
continue;
|
||||
@ -541,7 +541,7 @@ int __Menu_GetGameList(int t, wchar_t* gameFilter, discHdr ** PgameList, u32 *Pg
|
||||
|
||||
if(gameFilter && *gameFilter && t==0) {
|
||||
u32 filter_len = wcslen(gameFilter);
|
||||
wchar_t *gameName = FreeTypeGX::charToWideChar(get_title(header));
|
||||
wchar_t *gameName = charToWideChar(get_title(header));
|
||||
if (!gameName || wcsnicmp(gameName, gameFilter, filter_len)) {
|
||||
delete [] gameName;
|
||||
continue;
|
||||
|
@ -1,263 +1,290 @@
|
||||
#include <ogcsys.h>
|
||||
|
||||
#include "wbfs.h"
|
||||
#include "usbloader/wbfs/wbfs_base.h"
|
||||
#include "usbloader/wbfs/wbfs_wbfs.h"
|
||||
#include "usbloader/wbfs/wbfs_fat.h"
|
||||
#include "usbloader/wbfs/wbfs_ntfs.h"
|
||||
|
||||
#include "usbloader/partition_usbloader.h"
|
||||
#include "usbloader/getentries.h"
|
||||
#include "gecko.h"
|
||||
|
||||
Wbfs *current = NULL;
|
||||
#define DEBUG_WBFS
|
||||
|
||||
/* WBFS device */
|
||||
s32 wbfsDev = WBFS_MIN_DEVICE;
|
||||
|
||||
// partition
|
||||
char wbfs_fs_drive[16];
|
||||
int wbfs_part_fs = PART_FS_WBFS;
|
||||
u32 wbfs_part_idx = 0;
|
||||
u32 wbfs_part_lba = 0;
|
||||
|
||||
wbfs_disc_t* WBFS_OpenDisc(u8 *discid) {
|
||||
return current->OpenDisc(discid);
|
||||
}
|
||||
|
||||
void WBFS_CloseDisc(wbfs_disc_t *disc) {
|
||||
current->CloseDisc(disc);
|
||||
}
|
||||
|
||||
wbfs_t *GetHddInfo(void) {
|
||||
return current->GetHddInfo();
|
||||
}
|
||||
|
||||
s32 WBFS_Init(u32 device) {
|
||||
return Wbfs::Init(device);
|
||||
}
|
||||
|
||||
s32 WBFS_Open(void) {
|
||||
WBFS_Close();
|
||||
|
||||
current = new Wbfs_Wbfs(WBFS_DEVICE_USB, 0, 0); // Fix me!
|
||||
|
||||
wbfs_part_fs = wbfs_part_idx = wbfs_part_lba = 0;
|
||||
wbfs_part_idx = 1;
|
||||
|
||||
return current->Open();
|
||||
}
|
||||
|
||||
s32 WBFS_OpenPart(u32 part_fs, u32 part_idx, u32 part_lba, u32 part_size, char *partition)
|
||||
{
|
||||
// close
|
||||
WBFS_Close();
|
||||
|
||||
if (part_fs == PART_FS_FAT) {
|
||||
current = new Wbfs_Fat(wbfsDev, part_lba, part_size);
|
||||
strcpy(wbfs_fs_drive, "USB:");
|
||||
#ifdef DEBUG_WBFS
|
||||
gprintf("\n\tCreated WBFS_Fat instance at lba: %d of size %d", part_lba, part_size);
|
||||
#endif
|
||||
} else if (part_fs == PART_FS_NTFS) {
|
||||
current = new Wbfs_Ntfs(wbfsDev, part_lba, part_size);
|
||||
strcpy(wbfs_fs_drive, "NTFS:");
|
||||
#ifdef DEBUG_WBFS
|
||||
gprintf("\n\tCreated WBFS_Ntfs instance at lba: %d of size %d", part_lba, part_size);
|
||||
#endif
|
||||
} else {
|
||||
current = new Wbfs_Wbfs(wbfsDev, part_lba, part_size);
|
||||
#ifdef DEBUG_WBFS
|
||||
gprintf("\n\tCreated WBFS_Wbfs instance at lba: %d of size %d", part_lba, part_size);
|
||||
#endif
|
||||
}
|
||||
if (current->Open())
|
||||
{
|
||||
delete current;
|
||||
current = NULL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
// success
|
||||
wbfs_part_fs = part_fs;
|
||||
wbfs_part_idx = part_idx;
|
||||
wbfs_part_lba = part_lba;
|
||||
|
||||
const char *fs = "WBFS";
|
||||
if (wbfs_part_fs == PART_FS_FAT) fs = "FAT";
|
||||
if (wbfs_part_fs == PART_FS_NTFS) fs = "NTFS";
|
||||
sprintf(partition, "%s%d", fs, wbfs_part_idx);
|
||||
return 0;
|
||||
}
|
||||
|
||||
s32 WBFS_OpenNamed(char *partition)
|
||||
{
|
||||
u32 i;
|
||||
u32 part_fs = PART_FS_WBFS;
|
||||
u32 part_idx = 0;
|
||||
u32 part_lba = 0;
|
||||
s32 ret = 0;
|
||||
PartList plist;
|
||||
|
||||
// close
|
||||
WBFS_Close();
|
||||
|
||||
// parse partition option
|
||||
if (strncasecmp(partition, "WBFS", 4) == 0) {
|
||||
i = atoi(partition+4);
|
||||
if (i < 1 || i > 4) goto err;
|
||||
part_fs = PART_FS_WBFS;
|
||||
part_idx = i;
|
||||
} else if (strncasecmp(partition, "FAT", 3) == 0) {
|
||||
if (wbfsDev != WBFS_DEVICE_USB) goto err;
|
||||
i = atoi(partition+3);
|
||||
if (i < 1 || i > 9) goto err;
|
||||
part_fs = PART_FS_FAT;
|
||||
part_idx = i;
|
||||
} else if (strncasecmp(partition, "NTFS", 4) == 0) {
|
||||
i = atoi(partition+4);
|
||||
if (i < 1 || i > 9) goto err;
|
||||
part_fs = PART_FS_NTFS;
|
||||
part_idx = i;
|
||||
} else {
|
||||
goto err;
|
||||
}
|
||||
|
||||
// Get partition entries
|
||||
ret = Partition_GetList(wbfsDev, &plist);
|
||||
if (ret || plist.num == 0) return -1;
|
||||
|
||||
if (part_fs == PART_FS_WBFS) {
|
||||
if (part_idx > plist.wbfs_n) goto err;
|
||||
for (i=0; i<plist.num; i++) {
|
||||
if (plist.pinfo[i].wbfs_i == part_idx) break;
|
||||
}
|
||||
} else if (part_fs == PART_FS_FAT) {
|
||||
if (part_idx > plist.fat_n) goto err;
|
||||
for (i=0; i<plist.num; i++) {
|
||||
if (plist.pinfo[i].fat_i == part_idx) break;
|
||||
}
|
||||
} else if (part_fs == PART_FS_NTFS) {
|
||||
if (part_idx > plist.ntfs_n) goto err;
|
||||
for (i=0; i<plist.num; i++) {
|
||||
if (plist.pinfo[i].ntfs_i == part_idx) break;
|
||||
}
|
||||
}
|
||||
if (i >= plist.num) goto err;
|
||||
// set partition lba sector
|
||||
part_lba = plist.pentry[i].sector;
|
||||
|
||||
if (WBFS_OpenPart(part_fs, part_idx, part_lba, plist.pentry[i].size, partition)) {
|
||||
goto err;
|
||||
}
|
||||
// success
|
||||
return 0;
|
||||
err:
|
||||
return -1;
|
||||
}
|
||||
|
||||
s32 WBFS_OpenLBA(u32 lba, u32 size)
|
||||
{
|
||||
Wbfs *part = new Wbfs_Wbfs(wbfsDev, lba, size);
|
||||
if (part->Open() != 0)
|
||||
{
|
||||
delete part;
|
||||
return -1;
|
||||
}
|
||||
|
||||
WBFS_Close();
|
||||
current = part;
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool WBFS_Close(void)
|
||||
{
|
||||
if (current != NULL) {
|
||||
current->Close();
|
||||
delete current;
|
||||
current = NULL;
|
||||
}
|
||||
|
||||
wbfs_part_fs = 0;
|
||||
wbfs_part_idx = 0;
|
||||
wbfs_part_lba = 0;
|
||||
wbfs_fs_drive[0] = '\0';
|
||||
|
||||
ResetGamelist();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool WBFS_Mounted()
|
||||
{
|
||||
return (current != NULL && current->Mounted());
|
||||
}
|
||||
|
||||
s32 WBFS_Format(u32 lba, u32 size) {
|
||||
return current->Format();
|
||||
}
|
||||
|
||||
s32 WBFS_GetCount(u32 *count) {
|
||||
return current->GetCount(count);
|
||||
}
|
||||
|
||||
s32 WBFS_GetHeaders(struct discHdr *outbuf, u32 cnt, u32 len) {
|
||||
return current->GetHeaders(outbuf, cnt, len);
|
||||
}
|
||||
|
||||
s32 WBFS_CheckGame(u8 *discid) {
|
||||
return current->CheckGame(discid);
|
||||
}
|
||||
|
||||
s32 WBFS_AddGame(void) {
|
||||
s32 retval = current->AddGame();
|
||||
if (retval == 0) {
|
||||
ResetGamelist();
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
s32 WBFS_RemoveGame(u8 *discid) {
|
||||
s32 retval = current->RemoveGame(discid);
|
||||
if (retval == 0) {
|
||||
ResetGamelist();
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
s32 WBFS_GameSize(u8 *discid, f32 *size) {
|
||||
return current->GameSize(discid, size);
|
||||
}
|
||||
|
||||
s32 WBFS_DiskSpace(f32 *used, f32 *free) {
|
||||
return current->DiskSpace(used, free);
|
||||
}
|
||||
|
||||
s32 WBFS_RenameGame(u8 *discid, const void *newname) {
|
||||
s32 retval = current->RenameGame(discid, newname);
|
||||
if (retval == 0) {
|
||||
ResetGamelist();
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
s32 WBFS_ReIDGame(u8 *discid, const void *newID) {
|
||||
s32 retval = current->ReIDGame(discid, newID);
|
||||
if (retval == 0) {
|
||||
ResetGamelist();
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
f32 WBFS_EstimeGameSize(void) {
|
||||
return current->EstimateGameSize();
|
||||
}
|
||||
|
||||
int WBFS_GetFragList(u8 *id) {
|
||||
return current->GetFragList(id);
|
||||
}
|
||||
|
||||
bool WBFS_ShowFreeSpace(void) {
|
||||
return current->ShowFreeSpace();
|
||||
}
|
||||
#include <ogcsys.h>
|
||||
#include <unistd.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "usbloader/usbstorage2.h"
|
||||
#include "fatmounter.h"
|
||||
#include "wbfs.h"
|
||||
#include "usbloader/wbfs/wbfs_base.h"
|
||||
#include "usbloader/wbfs/wbfs_wbfs.h"
|
||||
#include "usbloader/wbfs/wbfs_fat.h"
|
||||
#include "usbloader/wbfs/wbfs_ntfs.h"
|
||||
|
||||
#include "usbloader/partition_usbloader.h"
|
||||
#include "usbloader/getentries.h"
|
||||
#include "gecko.h"
|
||||
|
||||
Wbfs *current = NULL;
|
||||
#define DEBUG_WBFS
|
||||
|
||||
/* WBFS device */
|
||||
s32 wbfsDev = WBFS_MIN_DEVICE;
|
||||
|
||||
// partition
|
||||
char wbfs_fs_drive[16];
|
||||
int wbfs_part_fs = PART_FS_WBFS;
|
||||
u32 wbfs_part_idx = 0;
|
||||
u32 wbfs_part_lba = 0;
|
||||
|
||||
wbfs_disc_t* WBFS_OpenDisc(u8 *discid) {
|
||||
return current->OpenDisc(discid);
|
||||
}
|
||||
|
||||
void WBFS_CloseDisc(wbfs_disc_t *disc) {
|
||||
current->CloseDisc(disc);
|
||||
}
|
||||
|
||||
wbfs_t *GetHddInfo(void) {
|
||||
return current->GetHddInfo();
|
||||
}
|
||||
|
||||
s32 WBFS_Init(u32 device) {
|
||||
return Wbfs::Init(device);
|
||||
}
|
||||
|
||||
s32 WBFS_Open(void) {
|
||||
WBFS_Close();
|
||||
|
||||
current = new Wbfs_Wbfs(WBFS_DEVICE_USB, 0, 0); // Fix me!
|
||||
|
||||
wbfs_part_fs = wbfs_part_idx = wbfs_part_lba = 0;
|
||||
wbfs_part_idx = 1;
|
||||
|
||||
return current->Open();
|
||||
}
|
||||
|
||||
s32 WBFS_OpenPart(u32 part_fs, u32 part_idx, u32 part_lba, u32 part_size, char *partition)
|
||||
{
|
||||
// close
|
||||
WBFS_Close();
|
||||
|
||||
if (part_fs == PART_FS_FAT) {
|
||||
current = new Wbfs_Fat(wbfsDev, part_lba, part_size);
|
||||
strcpy(wbfs_fs_drive, "USB:");
|
||||
#ifdef DEBUG_WBFS
|
||||
gprintf("\n\tCreated WBFS_Fat instance at lba: %d of size %d", part_lba, part_size);
|
||||
#endif
|
||||
} else if (part_fs == PART_FS_NTFS) {
|
||||
current = new Wbfs_Ntfs(wbfsDev, part_lba, part_size);
|
||||
strcpy(wbfs_fs_drive, "NTFS:");
|
||||
#ifdef DEBUG_WBFS
|
||||
gprintf("\n\tCreated WBFS_Ntfs instance at lba: %d of size %d", part_lba, part_size);
|
||||
#endif
|
||||
} else {
|
||||
current = new Wbfs_Wbfs(wbfsDev, part_lba, part_size);
|
||||
#ifdef DEBUG_WBFS
|
||||
gprintf("\n\tCreated WBFS_Wbfs instance at lba: %d of size %d", part_lba, part_size);
|
||||
#endif
|
||||
}
|
||||
if (current->Open())
|
||||
{
|
||||
delete current;
|
||||
current = NULL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
// success
|
||||
wbfs_part_fs = part_fs;
|
||||
wbfs_part_idx = part_idx;
|
||||
wbfs_part_lba = part_lba;
|
||||
|
||||
const char *fs = "WBFS";
|
||||
if (wbfs_part_fs == PART_FS_FAT) fs = "FAT";
|
||||
if (wbfs_part_fs == PART_FS_NTFS) fs = "NTFS";
|
||||
sprintf(partition, "%s%d", fs, wbfs_part_idx);
|
||||
return 0;
|
||||
}
|
||||
|
||||
s32 WBFS_OpenNamed(char *partition)
|
||||
{
|
||||
u32 i;
|
||||
u32 part_fs = PART_FS_WBFS;
|
||||
u32 part_idx = 0;
|
||||
u32 part_lba = 0;
|
||||
s32 ret = 0;
|
||||
PartList plist;
|
||||
|
||||
// close
|
||||
WBFS_Close();
|
||||
|
||||
// parse partition option
|
||||
if (strncasecmp(partition, "WBFS", 4) == 0) {
|
||||
i = atoi(partition+4);
|
||||
if (i < 1 || i > 4) goto err;
|
||||
part_fs = PART_FS_WBFS;
|
||||
part_idx = i;
|
||||
} else if (strncasecmp(partition, "FAT", 3) == 0) {
|
||||
if (wbfsDev != WBFS_DEVICE_USB) goto err;
|
||||
i = atoi(partition+3);
|
||||
if (i < 1 || i > 9) goto err;
|
||||
part_fs = PART_FS_FAT;
|
||||
part_idx = i;
|
||||
} else if (strncasecmp(partition, "NTFS", 4) == 0) {
|
||||
i = atoi(partition+4);
|
||||
if (i < 1 || i > 9) goto err;
|
||||
part_fs = PART_FS_NTFS;
|
||||
part_idx = i;
|
||||
} else {
|
||||
goto err;
|
||||
}
|
||||
|
||||
// Get partition entries
|
||||
ret = Partition_GetList(wbfsDev, &plist);
|
||||
if (ret || plist.num == 0) return -1;
|
||||
|
||||
if (part_fs == PART_FS_WBFS) {
|
||||
if (part_idx > plist.wbfs_n) goto err;
|
||||
for (i=0; i<plist.num; i++) {
|
||||
if (plist.pinfo[i].wbfs_i == part_idx) break;
|
||||
}
|
||||
} else if (part_fs == PART_FS_FAT) {
|
||||
if (part_idx > plist.fat_n) goto err;
|
||||
for (i=0; i<plist.num; i++) {
|
||||
if (plist.pinfo[i].fat_i == part_idx) break;
|
||||
}
|
||||
} else if (part_fs == PART_FS_NTFS) {
|
||||
if (part_idx > plist.ntfs_n) goto err;
|
||||
for (i=0; i<plist.num; i++) {
|
||||
if (plist.pinfo[i].ntfs_i == part_idx) break;
|
||||
}
|
||||
}
|
||||
if (i >= plist.num) goto err;
|
||||
// set partition lba sector
|
||||
part_lba = plist.pentry[i].sector;
|
||||
|
||||
if (WBFS_OpenPart(part_fs, part_idx, part_lba, plist.pentry[i].size, partition)) {
|
||||
goto err;
|
||||
}
|
||||
// success
|
||||
return 0;
|
||||
err:
|
||||
return -1;
|
||||
}
|
||||
|
||||
s32 WBFS_OpenLBA(u32 lba, u32 size)
|
||||
{
|
||||
Wbfs *part = new Wbfs_Wbfs(wbfsDev, lba, size);
|
||||
if (part->Open() != 0)
|
||||
{
|
||||
delete part;
|
||||
return -1;
|
||||
}
|
||||
|
||||
WBFS_Close();
|
||||
current = part;
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool WBFS_Close(void)
|
||||
{
|
||||
if (current != NULL) {
|
||||
current->Close();
|
||||
delete current;
|
||||
current = NULL;
|
||||
}
|
||||
|
||||
wbfs_part_fs = 0;
|
||||
wbfs_part_idx = 0;
|
||||
wbfs_part_lba = 0;
|
||||
wbfs_fs_drive[0] = '\0';
|
||||
|
||||
ResetGamelist();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool WBFS_Mounted()
|
||||
{
|
||||
return (current != NULL && current->Mounted());
|
||||
}
|
||||
|
||||
s32 WBFS_Format(u32 lba, u32 size) {
|
||||
return current->Format();
|
||||
}
|
||||
|
||||
s32 WBFS_GetCount(u32 *count) {
|
||||
return current->GetCount(count);
|
||||
}
|
||||
|
||||
s32 WBFS_GetHeaders(struct discHdr *outbuf, u32 cnt, u32 len) {
|
||||
return current->GetHeaders(outbuf, cnt, len);
|
||||
}
|
||||
|
||||
s32 WBFS_CheckGame(u8 *discid) {
|
||||
return current->CheckGame(discid);
|
||||
}
|
||||
|
||||
s32 WBFS_AddGame(void) {
|
||||
s32 retval = current->AddGame();
|
||||
if (retval == 0) {
|
||||
ResetGamelist();
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
s32 WBFS_RemoveGame(u8 *discid) {
|
||||
s32 retval = current->RemoveGame(discid);
|
||||
if (retval == 0) {
|
||||
ResetGamelist();
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
s32 WBFS_GameSize(u8 *discid, f32 *size) {
|
||||
return current->GameSize(discid, size);
|
||||
}
|
||||
|
||||
s32 WBFS_DiskSpace(f32 *used, f32 *free) {
|
||||
return current->DiskSpace(used, free);
|
||||
}
|
||||
|
||||
s32 WBFS_RenameGame(u8 *discid, const void *newname) {
|
||||
s32 retval = current->RenameGame(discid, newname);
|
||||
if (retval == 0) {
|
||||
ResetGamelist();
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
s32 WBFS_ReIDGame(u8 *discid, const void *newID) {
|
||||
s32 retval = current->ReIDGame(discid, newID);
|
||||
if (retval == 0) {
|
||||
ResetGamelist();
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
f32 WBFS_EstimeGameSize(void) {
|
||||
return current->EstimateGameSize();
|
||||
}
|
||||
|
||||
int WBFS_GetFragList(u8 *id) {
|
||||
return current->GetFragList(id);
|
||||
}
|
||||
|
||||
bool WBFS_ShowFreeSpace(void) {
|
||||
return current->ShowFreeSpace();
|
||||
}
|
||||
|
||||
int MountWBFS()
|
||||
{
|
||||
int ret = -1;
|
||||
time_t currTime = time(0);
|
||||
|
||||
while(time(0)-currTime < 15)
|
||||
{
|
||||
USBDevice_deInit();
|
||||
USBStorage2_Deinit();
|
||||
USBDevice_Init();
|
||||
ret = WBFS_Init(WBFS_DEVICE_USB);
|
||||
printf("%i...", int(time(0)-currTime));
|
||||
if(ret < 0)
|
||||
sleep(1);
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
printf("\n");
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
@ -54,6 +54,7 @@ extern "C" {
|
||||
bool WBFS_Close();
|
||||
bool WBFS_Mounted();
|
||||
bool WBFS_Selected();
|
||||
int MountWBFS();
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -179,27 +179,27 @@ s32 Wad_Install(FILE *fp)
|
||||
char msg[50];
|
||||
sprintf(msg, " ");
|
||||
// sprintf(msg, "%s", tr("Initializing Network"));
|
||||
GuiText msg1Txt(NULL, 20, THEME.prompttext);
|
||||
GuiText msg1Txt((char*)NULL, 20, THEME.prompttext);
|
||||
msg1Txt.SetAlignment(ALIGN_LEFT, ALIGN_TOP);
|
||||
msg1Txt.SetPosition(50,75);
|
||||
// char msg2[50] = " ";
|
||||
GuiText msg2Txt(NULL, 20, THEME.prompttext);
|
||||
GuiText msg2Txt((char*)NULL, 20, THEME.prompttext);
|
||||
msg2Txt.SetAlignment(ALIGN_LEFT, ALIGN_TOP);
|
||||
msg2Txt.SetPosition(50, 98);
|
||||
|
||||
GuiText msg3Txt(NULL, 20, THEME.prompttext);
|
||||
GuiText msg3Txt((char*)NULL, 20, THEME.prompttext);
|
||||
msg3Txt.SetAlignment(ALIGN_LEFT, ALIGN_TOP);
|
||||
msg3Txt.SetPosition(50, 121);
|
||||
|
||||
GuiText msg4Txt(NULL, 20, THEME.prompttext);
|
||||
GuiText msg4Txt((char*)NULL, 20, THEME.prompttext);
|
||||
msg4Txt.SetAlignment(ALIGN_LEFT, ALIGN_TOP);
|
||||
msg4Txt.SetPosition(50, 144);
|
||||
|
||||
GuiText msg5Txt(NULL, 20, THEME.prompttext);
|
||||
GuiText msg5Txt((char*)NULL, 20, THEME.prompttext);
|
||||
msg5Txt.SetAlignment(ALIGN_LEFT, ALIGN_TOP);
|
||||
msg5Txt.SetPosition(50, 167);
|
||||
|
||||
GuiText prTxt(NULL, 26, THEME.prompttext);
|
||||
GuiText prTxt((char*)NULL, 26, THEME.prompttext);
|
||||
prTxt.SetAlignment(ALIGN_CENTRE, ALIGN_MIDDLE);
|
||||
prTxt.SetPosition(0, 50);
|
||||
|
||||
@ -487,23 +487,23 @@ s32 Wad_Uninstall(FILE *fp)
|
||||
titleTxt.SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
|
||||
titleTxt.SetPosition(0,40);
|
||||
|
||||
GuiText msg1Txt(NULL, 18, THEME.prompttext);
|
||||
GuiText msg1Txt((char*)NULL, 18, THEME.prompttext);
|
||||
msg1Txt.SetAlignment(ALIGN_LEFT, ALIGN_TOP);
|
||||
msg1Txt.SetPosition(50,75);
|
||||
|
||||
GuiText msg2Txt(NULL, 18, THEME.prompttext);
|
||||
GuiText msg2Txt((char*)NULL, 18, THEME.prompttext);
|
||||
msg2Txt.SetAlignment(ALIGN_LEFT, ALIGN_TOP);
|
||||
msg2Txt.SetPosition(50, 98);
|
||||
|
||||
GuiText msg3Txt(NULL, 18, THEME.prompttext);
|
||||
GuiText msg3Txt((char*)NULL, 18, THEME.prompttext);
|
||||
msg3Txt.SetAlignment(ALIGN_LEFT, ALIGN_TOP);
|
||||
msg3Txt.SetPosition(50, 121);
|
||||
|
||||
GuiText msg4Txt(NULL, 18, THEME.prompttext);
|
||||
GuiText msg4Txt((char*)NULL, 18, THEME.prompttext);
|
||||
msg4Txt.SetAlignment(ALIGN_LEFT, ALIGN_TOP);
|
||||
msg4Txt.SetPosition(50, 144);
|
||||
|
||||
GuiText msg5Txt(NULL, 18, THEME.prompttext);
|
||||
GuiText msg5Txt((char*)NULL, 18, THEME.prompttext);
|
||||
msg5Txt.SetAlignment(ALIGN_LEFT, ALIGN_TOP);
|
||||
msg5Txt.SetPosition(50, 167);
|
||||
|
||||
|
151
source/wstring.cpp
Normal file
151
source/wstring.cpp
Normal file
@ -0,0 +1,151 @@
|
||||
#include "wstring.hpp"
|
||||
|
||||
using namespace std;
|
||||
|
||||
wString::wString(const wchar_t *s) :
|
||||
std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >(s)
|
||||
{
|
||||
}
|
||||
|
||||
wString::wString(const basic_string<wchar_t, char_traits<wchar_t>, allocator<wchar_t> > &ws) :
|
||||
basic_string<wchar_t, char_traits<wchar_t>, allocator<wchar_t> >(ws)
|
||||
{
|
||||
}
|
||||
|
||||
wString::wString(const string &s)
|
||||
{
|
||||
std::string::size_type size;
|
||||
|
||||
size = s.size();
|
||||
resize(size);
|
||||
for (std::string::size_type i = 0; i < size; ++i)
|
||||
(*this)[i] = (unsigned char)s[i];
|
||||
}
|
||||
|
||||
wString &wString::operator=(const string &s)
|
||||
{
|
||||
std::string::size_type size;
|
||||
|
||||
size = s.size();
|
||||
this->resize(size);
|
||||
for (std::string::size_type i = 0; i < size; ++i)
|
||||
(*this)[i] = (unsigned char)s[i];
|
||||
return *this;
|
||||
}
|
||||
|
||||
void wString::fromUTF8(const char *s)
|
||||
{
|
||||
size_t len = utf8Len(s);
|
||||
|
||||
clear();
|
||||
if (len == 0)
|
||||
return;
|
||||
reserve(len);
|
||||
for (int i = 0; s[i] != 0; )
|
||||
{
|
||||
if ((s[i] & 0xF8) == 0xF0)
|
||||
{
|
||||
push_back(((wchar_t)(s[i] & 0x07) << 18) | ((wchar_t)(s[i + 1] & 0x3F) << 12) | ((wchar_t)(s[i + 2] & 0x3F) << 6) | (wchar_t)(s[i + 3] & 0x3F));
|
||||
i += 4;
|
||||
}
|
||||
else if ((s[i] & 0xF0) == 0xE0)
|
||||
{
|
||||
push_back(((wchar_t)(s[i] & 0x0F) << 12) | ((wchar_t)(s[i + 1] & 0x3F) << 6) | (wchar_t)(s[i + 2] & 0x3F));
|
||||
i += 3;
|
||||
}
|
||||
else if ((s[i] & 0xE0) == 0xC0)
|
||||
{
|
||||
push_back(((wchar_t)(s[i] & 0x1F) << 6) | (wchar_t)(s[i + 1] & 0x3F));
|
||||
i += 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
push_back((wchar_t)s[i]);
|
||||
++i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
string wString::toUTF8(void) const
|
||||
{
|
||||
string s;
|
||||
size_t len = 0;
|
||||
wchar_t wc;
|
||||
|
||||
for (size_t i = 0; i < size(); ++i)
|
||||
{
|
||||
wc = operator[](i);
|
||||
if (wc < 0x80)
|
||||
++len;
|
||||
else if (wc < 0x800)
|
||||
len += 2;
|
||||
else if (wc < 0x10000)
|
||||
len += 3;
|
||||
else
|
||||
len += 4;
|
||||
}
|
||||
s.reserve(len);
|
||||
for (size_t i = 0; i < size(); ++i)
|
||||
{
|
||||
wc = operator[](i);
|
||||
if (wc < 0x80)
|
||||
s.push_back((char)wc);
|
||||
else if (wc < 0x800)
|
||||
{
|
||||
s.push_back((char)((wc >> 6) | 0xC0));
|
||||
s.push_back((char)((wc & 0x3F) | 0x80));
|
||||
}
|
||||
else if (wc < 0x10000)
|
||||
{
|
||||
s.push_back((char)((wc >> 12) | 0xE0));
|
||||
s.push_back((char)(((wc >> 6) & 0x3F) | 0x80));
|
||||
s.push_back((char)((wc & 0x3F) | 0x80));
|
||||
}
|
||||
else
|
||||
{
|
||||
s.push_back((char)(((wc >> 18) & 0x07) | 0xF0));
|
||||
s.push_back((char)(((wc >> 12) & 0x3F) | 0x80));
|
||||
s.push_back((char)(((wc >> 6) & 0x3F) | 0x80));
|
||||
s.push_back((char)((wc & 0x3F) | 0x80));
|
||||
}
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
size_t utf8Len(const char *s)
|
||||
{
|
||||
size_t len = 0;
|
||||
|
||||
for (int i = 0; s[i] != 0; )
|
||||
{
|
||||
if ((s[i] & 0xF8) == 0xF0)
|
||||
{
|
||||
if (((s[i + 1] & 0xC0) != 0x80) || ((s[i + 2] & 0xC0) != 0x80) || ((s[i + 3] & 0xC0) != 0x80))
|
||||
return 0;
|
||||
++len;
|
||||
i += 4;
|
||||
}
|
||||
else if ((s[i] & 0xF0) == 0xE0)
|
||||
{
|
||||
if (((s[i + 1] & 0xC0) != 0x80) || ((s[i + 2] & 0xC0) != 0x80))
|
||||
return 0;
|
||||
++len;
|
||||
i += 3;
|
||||
}
|
||||
else if ((s[i] & 0xE0) == 0xC0)
|
||||
{
|
||||
if (((s[i + 1] & 0xC0) != 0x80))
|
||||
return 0;
|
||||
++len;
|
||||
i += 2;
|
||||
}
|
||||
else if ((s[i] & 0x80) == 0x00)
|
||||
{
|
||||
++len;
|
||||
++i;
|
||||
}
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
return len;
|
||||
}
|
25
source/wstring.hpp
Normal file
25
source/wstring.hpp
Normal file
@ -0,0 +1,25 @@
|
||||
/****************************************************************************
|
||||
* wstring Class
|
||||
* by Hibernatus
|
||||
***************************************************************************/
|
||||
#ifndef __WSTRING_HPP
|
||||
#define __WSTRING_HPP
|
||||
|
||||
#include <string>
|
||||
|
||||
class wString : public std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >
|
||||
{
|
||||
public:
|
||||
wString(void) { }
|
||||
wString(const wchar_t *s);
|
||||
wString(const std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > &ws);
|
||||
wString(const std::string &s);
|
||||
wString &operator=(const std::string &s);
|
||||
void fromUTF8(const char *s);
|
||||
std::string toUTF8(void) const;
|
||||
};
|
||||
|
||||
size_t utf8Len(const char *s);
|
||||
|
||||
|
||||
#endif // !defined(__WSTRING_HPP)
|
Loading…
Reference in New Issue
Block a user