commit my stuff again and fix it (no more codedumps on the Download)

This commit is contained in:
ardi@ist-einmalig.de 2009-05-28 15:36:45 +00:00
parent f793af2d39
commit 45ae32f0cd
5 changed files with 1105 additions and 1039 deletions

View File

@ -26,6 +26,36 @@
#include "main.h" #include "main.h"
#include "cfg.h" #include "cfg.h"
/*! \struct ftgxCharData_
*
* Font face character glyph relevant data structure.
*/
typedef struct ftgxCharData_ {
int16_t renderOffsetX; /**< Texture X axis bearing offset. */
uint16_t glyphAdvanceX; /**< Character glyph X coordinate advance in pixels. */
uint16_t glyphIndex; /**< Charachter glyph index in the font face. */
uint16_t textureWidth; /**< Texture width in pixels/bytes. */
uint16_t textureHeight; /**< Texture glyph height in pixels/bytes. */
int16_t renderOffsetY; /**< Texture Y axis bearing offset. */
int16_t renderOffsetMax; /**< Texture Y axis bearing maximum value. */
int16_t renderOffsetMin; /**< Texture Y axis bearing minimum value. */
uint32_t* glyphDataTexture; /**< Glyph texture bitmap data buffer. */
} ftgxCharData;
/*! \struct ftgxDataOffset_
*
* Offset structure which hold both a maximum and minimum value.
*/
typedef struct ftgxDataOffset_ {
int16_t ascender; /**< Maximum data offset. */
int16_t descender; /**< Minimum data offset. */
int16_t max; /**< Maximum data offset. */
int16_t min; /**< Minimum data offset. */
} ftgxDataOffset;
/** /**
* Default constructor for the FreeTypeGX class. * Default constructor for the FreeTypeGX class.
@ -407,16 +437,16 @@ void FreeTypeGX::loadGlyphData(FT_Bitmap *bmp, ftgxCharData *charData) {
* @param width Current pixel width of the string. * @param width Current pixel width of the string.
* @param format Positional format of the string. * @param format Positional format of the string.
*/ */
uint16_t FreeTypeGX::getStyleOffsetWidth(uint16_t width, uint16_t format) { int16_t FreeTypeGX::getStyleOffsetWidth(uint16_t width, uint16_t format) {
if (format & FTGX_JUSTIFY_LEFT ) { if (format & FTGX_JUSTIFY_LEFT ) {
return 0; return 0;
} }
else if (format & FTGX_JUSTIFY_CENTER ) { else if (format & FTGX_JUSTIFY_CENTER ) {
return width >> 1; return -(width >> 1);
} }
else if (format & FTGX_JUSTIFY_RIGHT ) { else if (format & FTGX_JUSTIFY_RIGHT ) {
return width; return -width;
} }
return 0; return 0;
@ -430,15 +460,31 @@ uint16_t FreeTypeGX::getStyleOffsetWidth(uint16_t width, uint16_t format) {
* @param offset Current pixel offset data of the string. * @param offset Current pixel offset data of the string.
* @param format Positional format of the string. * @param format Positional format of the string.
*/ */
uint16_t FreeTypeGX::getStyleOffsetHeight(ftgxDataOffset offset, uint16_t format) { int16_t FreeTypeGX::getStyleOffsetHeight(ftgxDataOffset *offset, uint16_t format)
if (format & FTGX_ALIGN_TOP ) { {
return -offset.max; switch(format & FTGX_ALIGN_MASK)
} {
else if (format & FTGX_ALIGN_MIDDLE ) { case FTGX_ALIGN_TOP:
return -offset.max; return offset->ascender;
}
else if (format & FTGX_ALIGN_BOTTOM ) { default:
return offset.min; case FTGX_ALIGN_MIDDLE:
return (offset->ascender + offset->descender + 1) >> 1;
case FTGX_ALIGN_BOTTOM:
return offset->descender;
case FTGX_ALIGN_BASELINE:
return 0;
case FTGX_ALIGN_GLYPH_TOP:
return offset->max;
case FTGX_ALIGN_GLYPH_MIDDLE:
return (offset->max + offset->min + 1) >> 1;
case FTGX_ALIGN_GLYPH_BOTTOM:
return offset->min;
} }
return 0; return 0;
@ -463,12 +509,13 @@ uint16_t FreeTypeGX::drawText(int16_t x, int16_t y, wchar_t *text, GXColor color
uint16_t x_offset = 0, y_offset = 0; uint16_t x_offset = 0, y_offset = 0;
GXTexObj glyphTexture; GXTexObj glyphTexture;
FT_Vector pairDelta; FT_Vector pairDelta;
ftgxDataOffset offset;
if(textStyle & 0x000F) { if(textStyle & FTGX_JUSTIFY_MASK) {
x_offset = this->getStyleOffsetWidth(this->getWidth(text), textStyle); x_offset = this->getStyleOffsetWidth(this->getWidth(text), textStyle);
} }
if(textStyle & 0x00F0) { if(textStyle & FTGX_ALIGN_MASK) {
y_offset = this->getStyleOffsetHeight(this->getOffset(text), textStyle); y_offset = this->getStyleOffsetHeight(this->getOffset(text, &offset), textStyle);
} }
for (uint16_t i = 0; i < strLength; i++) { for (uint16_t i = 0; i < strLength; i++) {
@ -489,15 +536,15 @@ uint16_t FreeTypeGX::drawText(int16_t x, int16_t y, wchar_t *text, GXColor color
} }
GX_InitTexObj(&glyphTexture, glyphData->glyphDataTexture, glyphData->textureWidth, glyphData->textureHeight, this->textureFormat, GX_CLAMP, GX_CLAMP, GX_FALSE); GX_InitTexObj(&glyphTexture, glyphData->glyphDataTexture, glyphData->textureWidth, glyphData->textureHeight, this->textureFormat, GX_CLAMP, GX_CLAMP, GX_FALSE);
this->copyTextureToFramebuffer(&glyphTexture, glyphData->textureWidth, glyphData->textureHeight, x_pos + glyphData->renderOffsetX - x_offset, y - glyphData->renderOffsetY - y_offset, color); this->copyTextureToFramebuffer(&glyphTexture, glyphData->textureWidth, glyphData->textureHeight, x_pos + glyphData->renderOffsetX + x_offset, y - glyphData->renderOffsetY + y_offset, color);
x_pos += glyphData->glyphAdvanceX; x_pos += glyphData->glyphAdvanceX;
printed++; printed++;
} }
} }
if(textStyle & 0x0F00) { if(textStyle & FTGX_STYLE_MASK) {
this->drawTextFeature(x - x_offset, y, this->getWidth(text), this->getOffset(text), textStyle, color); this->drawTextFeature(x + x_offset, y + y_offset, this->getWidth(text), this->getOffset(text, &offset), textStyle, color);
} }
return printed; return printed;
@ -510,20 +557,22 @@ uint16_t FreeTypeGX::drawText(int16_t x, int16_t y, wchar_t const *text, GXColor
return this->drawText(x, y, (wchar_t *)text, color, textStyle); return this->drawText(x, y, (wchar_t *)text, color, textStyle);
} }
void FreeTypeGX::drawTextFeature(int16_t x, int16_t y, uint16_t width, ftgxDataOffset offsetData, uint16_t format, GXColor color) { void FreeTypeGX::drawTextFeature(int16_t x, int16_t y, uint16_t width, ftgxDataOffset *offsetData, uint16_t format, GXColor color) {
uint16_t featureHeight = this->ftPointSize >> 4 > 0 ? this->ftPointSize >> 4 : 1; uint16_t featureHeight = this->ftPointSize >> 4 > 0 ? this->ftPointSize >> 4 : 1;
if (format & FTGX_STYLE_UNDERLINE ) { if (format & FTGX_STYLE_UNDERLINE ) {
switch(format & 0x00F0) { switch(format & FTGX_ALIGN_MASK) {
/*
case FTGX_ALIGN_TOP: case FTGX_ALIGN_TOP:
this->copyFeatureToFramebuffer(width, featureHeight, x, y + offsetData.max + 1, color); this->copyFeatureToFramebuffer(width, featureHeight, x, y + offsetData->max + 1, color);
break; break;
case FTGX_ALIGN_MIDDLE: case FTGX_ALIGN_MIDDLE:
this->copyFeatureToFramebuffer(width, featureHeight, x, y + ((offsetData.max - offsetData.min) >> 1) + 1, color); this->copyFeatureToFramebuffer(width, featureHeight, x, y + ((offsetData->max - offsetData->min + 1) >> 1), color);
break; break;
case FTGX_ALIGN_BOTTOM: case FTGX_ALIGN_BOTTOM:
this->copyFeatureToFramebuffer(width, featureHeight, x, y - offsetData.min, color); this->copyFeatureToFramebuffer(width, featureHeight, x, y - offsetData->min, color);
break; break;
*/
default: default:
this->copyFeatureToFramebuffer(width, featureHeight, x, y + 1, color); this->copyFeatureToFramebuffer(width, featureHeight, x, y + 1, color);
break; break;
@ -531,18 +580,21 @@ void FreeTypeGX::drawTextFeature(int16_t x, int16_t y, uint16_t width, ftgxDataO
} }
if (format & FTGX_STYLE_STRIKE ) { if (format & FTGX_STYLE_STRIKE ) {
switch(format & 0x00F0) { switch(format & FTGX_ALIGN_MASK) {
/*
case FTGX_ALIGN_TOP: case FTGX_ALIGN_TOP:
this->copyFeatureToFramebuffer(width, featureHeight, x, y + ((offsetData.max + offsetData.min) >> 1), color); this->copyFeatureToFramebuffer(width, featureHeight, x, y + ((offsetData->max - offsetData->min + 1) >> 1), color);
break; break;
case FTGX_ALIGN_MIDDLE: case FTGX_ALIGN_MIDDLE:
this->copyFeatureToFramebuffer(width, featureHeight, x, y, color); this->copyFeatureToFramebuffer(width, featureHeight, x, y, color);
break; break;
case FTGX_ALIGN_BOTTOM: case FTGX_ALIGN_BOTTOM:
this->copyFeatureToFramebuffer(width, featureHeight, x, y - ((offsetData.max + offsetData.min) >> 1), color); this->copyFeatureToFramebuffer(width, featureHeight, x, y - ((offsetData->max + offsetData->min) >> 1), color);
break; break;
*/
default: default:
this->copyFeatureToFramebuffer(width, featureHeight, x, y - ((offsetData.max - offsetData.min) >> 1), color); // this->copyFeatureToFramebuffer(width, featureHeight, x, y - ((offsetData->max - offsetData->min) >> 1), color);
this->copyFeatureToFramebuffer(width, featureHeight, x, y - ((offsetData->max) >> 1), color);
break; break;
} }
} }
@ -603,9 +655,10 @@ uint16_t FreeTypeGX::getWidth(wchar_t const *text) {
* @return The height of the text string in pixels. * @return The height of the text string in pixels.
*/ */
uint16_t FreeTypeGX::getHeight(wchar_t *text) { uint16_t FreeTypeGX::getHeight(wchar_t *text) {
ftgxDataOffset offset = this->getOffset(text); ftgxDataOffset offset;
this->getOffset(text, &offset);
return offset.max + offset.min; return offset.max - offset.min;
} }
/** /**
@ -623,11 +676,12 @@ uint16_t FreeTypeGX::getHeight(wchar_t const *text) {
* pixel height below the font origin line and returns the values in an addressible structure. * pixel height below the font origin line and returns the values in an addressible structure.
* *
* @param text NULL terminated string to calculate. * @param text NULL terminated string to calculate.
* @return The max and min values above and below the font origin line. * @param offset returns the max and min values above and below the font origin line
*
*/ */
ftgxDataOffset FreeTypeGX::getOffset(wchar_t *text) { ftgxDataOffset* FreeTypeGX::getOffset(wchar_t *text, ftgxDataOffset* offset) {
uint16_t strLength = wcslen(text); uint16_t strLength = wcslen(text);
int16_t strMax = 0, strMin = 0; int16_t strMax = 0, strMin = 9999;
for (uint16_t i = 0; i < strLength; i++) { for (uint16_t i = 0; i < strLength; i++) {
@ -641,19 +695,22 @@ ftgxDataOffset FreeTypeGX::getOffset(wchar_t *text) {
if(glyphData != NULL) { if(glyphData != NULL) {
strMax = glyphData->renderOffsetMax > strMax ? glyphData->renderOffsetMax : strMax; strMax = glyphData->renderOffsetMax > strMax ? glyphData->renderOffsetMax : strMax;
strMin = glyphData->renderOffsetMin > strMin ? glyphData->renderOffsetMin : strMin; strMin = glyphData->renderOffsetMin < strMin ? glyphData->renderOffsetMin : strMin;
} }
} }
offset->ascender = this->ftFace->size->metrics.ascender>>6;
return (ftgxDataOffset){strMax, strMin}; offset->descender = this->ftFace->size->metrics.descender>>6;
offset->max = strMax;
offset->min = strMin;
return offset;
} }
/** /**
* *
* \overload * \overload
*/ */
ftgxDataOffset FreeTypeGX::getOffset(wchar_t const *text) { ftgxDataOffset* FreeTypeGX::getOffset(wchar_t const *text, ftgxDataOffset* offset) {
return this->getOffset(text); return this->getOffset(text, offset);
} }
/** /**

View File

@ -20,7 +20,6 @@
* along with FreeTypeGX. If not, see <http://www.gnu.org/licenses/>. * along with FreeTypeGX. If not, see <http://www.gnu.org/licenses/>.
*/ */
/** \mainpage FreeTypeGX /** \mainpage FreeTypeGX
* *
* \section sec_intro Introduction * \section sec_intro Introduction
@ -162,47 +161,32 @@
#include <string.h> #include <string.h>
#include <map> #include <map>
/*! \struct ftgxCharData_ /*! forward deklaration of private structures
* *
* Font face character glyph relevant data structure.
*/ */
typedef struct ftgxCharData_ { typedef struct ftgxCharData_ ftgxCharData;
int16_t renderOffsetX; /**< Texture X axis bearing offset. */ typedef struct ftgxDataOffset_ ftgxDataOffset;
uint16_t glyphAdvanceX; /**< Character glyph X coordinate advance in pixels. */
uint16_t glyphIndex; /**< Charachter glyph index in the font face. */
uint16_t textureWidth; /**< Texture width in pixels/bytes. */
uint16_t textureHeight; /**< Texture glyph height in pixels/bytes. */
int16_t renderOffsetY; /**< Texture Y axis bearing offset. */
int16_t renderOffsetMax; /**< Texture Y axis bearing maximum value. */
int16_t renderOffsetMin; /**< Texture Y axis bearing minimum value. */
uint32_t* glyphDataTexture; /**< Glyph texture bitmap data buffer. */
} ftgxCharData;
/*! \struct ftgxDataOffset_
*
* Offset structure which hold both a maximum and minimum value.
*/
typedef struct ftgxDataOffset_ {
int16_t max; /**< Maximum data offset. */
int16_t min; /**< Minimum data offset. */
} ftgxDataOffset;
#define _TEXT(t) L ## t /**< Unicode helper macro. */ #define _TEXT(t) L ## t /**< Unicode helper macro. */
#define FTGX_NULL 0x0000 #define FTGX_NULL 0x0000
#define FTGX_JUSTIFY_LEFT 0x0001 #define FTGX_JUSTIFY_LEFT 0x0001
#define FTGX_JUSTIFY_CENTER 0x0002 #define FTGX_JUSTIFY_CENTER 0x0002
#define FTGX_JUSTIFY_RIGHT 0x0004 #define FTGX_JUSTIFY_RIGHT 0x0003
#define FTGX_JUSTIFY_MASK 0x000f
#define FTGX_ALIGN_TOP 0x0010 #define FTGX_ALIGN_TOP 0x0010
#define FTGX_ALIGN_MIDDLE 0x0020 #define FTGX_ALIGN_MIDDLE 0x0020
#define FTGX_ALIGN_BOTTOM 0x0040 #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_STYLE_UNDERLINE 0x0100 #define FTGX_STYLE_UNDERLINE 0x0100
#define FTGX_STYLE_STRIKE 0x0200 #define FTGX_STYLE_STRIKE 0x0200
#define FTGX_STYLE_MASK 0x0f00
#define FTGX_COMPATIBILITY_DEFAULT_TEVOP_GX_MODULATE 0X0001 #define FTGX_COMPATIBILITY_DEFAULT_TEVOP_GX_MODULATE 0X0001
#define FTGX_COMPATIBILITY_DEFAULT_TEVOP_GX_DECAL 0X0002 #define FTGX_COMPATIBILITY_DEFAULT_TEVOP_GX_DECAL 0X0002
@ -247,8 +231,8 @@ class FreeTypeGX {
static uint16_t adjustTextureWidth(uint16_t textureWidth, uint8_t textureFormat); static uint16_t adjustTextureWidth(uint16_t textureWidth, uint8_t textureFormat);
static uint16_t adjustTextureHeight(uint16_t textureHeight, uint8_t textureFormat); static uint16_t adjustTextureHeight(uint16_t textureHeight, uint8_t textureFormat);
static uint16_t getStyleOffsetWidth(uint16_t width, uint16_t format); static int16_t getStyleOffsetWidth(uint16_t width, uint16_t format);
static uint16_t getStyleOffsetHeight(ftgxDataOffset offset, uint16_t format); static int16_t getStyleOffsetHeight(ftgxDataOffset *offset, uint16_t format);
void unloadFont(); void unloadFont();
ftgxCharData *cacheGlyphData(wchar_t charCode); ftgxCharData *cacheGlyphData(wchar_t charCode);
@ -257,7 +241,7 @@ class FreeTypeGX {
void setDefaultMode(); void setDefaultMode();
void drawTextFeature(int16_t x, int16_t y, uint16_t width, ftgxDataOffset offsetData, uint16_t format, GXColor color); 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 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); void copyFeatureToFramebuffer(f32 featureWidth, f32 featureHeight, int16_t screenX, int16_t screenY, GXColor color);
@ -281,8 +265,8 @@ class FreeTypeGX {
uint16_t getWidth(wchar_t const *text); uint16_t getWidth(wchar_t const *text);
uint16_t getHeight(wchar_t *text); uint16_t getHeight(wchar_t *text);
uint16_t getHeight(wchar_t const *text); uint16_t getHeight(wchar_t const *text);
ftgxDataOffset getOffset(wchar_t *text); ftgxDataOffset* getOffset(wchar_t *text, ftgxDataOffset* offset);
ftgxDataOffset getOffset(wchar_t const *text); ftgxDataOffset* getOffset(wchar_t const *text, ftgxDataOffset* offset);
}; };
#endif /* FREETYPEGX_H_ */ #endif /* FREETYPEGX_H_ */

View File

@ -664,7 +664,7 @@ class GuiText : public GuiElement
//!\param s Font style //!\param s Font style
//!\param h Text alignment (horizontal) //!\param h Text alignment (horizontal)
//!\param v Text alignment (vertical) //!\param v Text alignment (vertical)
void SetPresets(int sz, GXColor c, int w, u16 s, int h, int v); static void SetPresets(int sz, GXColor c, int w, int wrap, u16 s, int h, int v);
//!Sets the font size //!Sets the font size
//!\param s Font size //!\param s Font size
void SetFontSize(int s); void SetFontSize(int s);
@ -672,14 +672,12 @@ class GuiText : public GuiElement
//!If the text exceeds this, it is wrapped to the next line //!If the text exceeds this, it is wrapped to the next line
//!\param w Maximum width //!\param w Maximum width
//!\param m WrapMode //!\param m WrapMode
/*
enum { enum {
WRAP, WRAP,
DOTTED, DOTTED,
SCROLL, SCROLL,
MARQUEE MARQUEE
}; };
*/
void SetMaxWidth(int w, short m=GuiText::WRAP); void SetMaxWidth(int w, short m=GuiText::WRAP);
//!Sets the font color //!Sets the font color
//!\param c Font color //!\param c Font color
@ -687,7 +685,7 @@ class GuiText : public GuiElement
//!Sets the FreeTypeGX style attributes //!Sets the FreeTypeGX style attributes
//!\param s Style attributes //!\param s Style attributes
//!\param m Style-Mask attributes //!\param m Style-Mask attributes
void SetStyle(u16 s/*, u16 m=0xffff*/); void SetStyle(u16 s, u16 m=0xffff);
//!Sets the text alignment //!Sets the text alignment
//!\param hor Horizontal alignment (ALIGN_LEFT, ALIGN_RIGHT, ALIGN_CENTRE) //!\param hor Horizontal alignment (ALIGN_LEFT, ALIGN_RIGHT, ALIGN_CENTRE)
//!\param vert Vertical alignment (ALIGN_TOP, ALIGN_BOTTOM, ALIGN_MIDDLE) //!\param vert Vertical alignment (ALIGN_TOP, ALIGN_BOTTOM, ALIGN_MIDDLE)
@ -701,12 +699,6 @@ class GuiText : public GuiElement
void SetWidescreen(bool w); void SetWidescreen(bool w);
//!Constantly called to draw the text //!Constantly called to draw the text
void Draw(); void Draw();
enum {
WRAP,
DOTTED,
SCROLL,
MARQUEE
};
protected: protected:
wchar_t* text; //!< Unicode text value wchar_t* text; //!< Unicode text value
int size; //!< Font size int size; //!< Font size

View File

@ -13,12 +13,12 @@
static int currentSize = 0; static int currentSize = 0;
static int currentWidescreen = 0; static int currentWidescreen = 0;
static int presetSize = 0; static int presetSize = 0;
static GXColor presetColor = (GXColor){255, 255, 255, 255};
static int presetMaxWidth = 0; static int presetMaxWidth = 0;
static int presetWrapMode = GuiText::WRAP; static int presetWrapMode = GuiText::WRAP;
static u16 presetStyle = FTGX_NULL;
static int presetAlignmentHor = 0; static int presetAlignmentHor = 0;
static int presetAlignmentVert = 0; static int presetAlignmentVert = 0;
static u16 presetStyle = 0;
static GXColor presetColor = (GXColor){255, 255, 255, 255};
/** /**
* Constructor for the GuiText class. * Constructor for the GuiText class.
@ -42,7 +42,7 @@ GuiText::GuiText(const char * t, int s, GXColor c)
alignmentVert = ALIGN_MIDDLE; alignmentVert = ALIGN_MIDDLE;
if(t) if(t)
text = fontSystem->charToWideChar((char *)t); text = FreeTypeGX::charToWideChar((char *)t);
} }
/** /**
@ -67,7 +67,7 @@ GuiText::GuiText(const char * t)
alignmentVert = presetAlignmentVert; alignmentVert = presetAlignmentVert;
if(t) if(t)
text = fontSystem->charToWideChar((char *)t); text = FreeTypeGX::charToWideChar((char *)t);
} }
/** /**
@ -90,17 +90,18 @@ void GuiText::SetText(const char * t)
text = NULL; text = NULL;
if(t) if(t)
text = fontSystem->charToWideChar((char *)t); text = FreeTypeGX::charToWideChar((char *)t);
scrollPos2 = 0; scrollPos2 = 0;
scrollDelay = 0; scrollDelay = 0;
} }
void GuiText::SetPresets(int sz, GXColor c, int w, u16 s, int h, int v) void GuiText::SetPresets(int sz, GXColor c, int w, int wrap, u16 s, int h, int v)
{ {
presetSize = sz; presetSize = sz;
presetColor = c; presetColor = c;
presetStyle = s;
presetMaxWidth = w; presetMaxWidth = w;
presetWrapMode = wrap;
presetStyle = s;
presetAlignmentHor = h; presetAlignmentHor = h;
presetAlignmentVert = v; presetAlignmentVert = v;
} }
@ -125,16 +126,17 @@ void GuiText::SetColor(GXColor c)
alpha = c.a; alpha = c.a;
} }
void GuiText::SetStyle(u16 s) void GuiText::SetStyle(u16 s, u16 m/*=0xffff*/)
{ {
LOCK(this); LOCK(this);
style = s; style &= ~m;
style |= s & m;
} }
void GuiText::SetAlignment(int hor, int vert) void GuiText::SetAlignment(int hor, int vert)
{ {
LOCK(this); LOCK(this);
style = 0; style = FTGX_NULL;
switch(hor) switch(hor)
{ {
@ -220,8 +222,8 @@ void GuiText::Draw()
int voffset = 0; int voffset = 0;
if(alignmentVert == ALIGN_MIDDLE) // if(alignmentVert == ALIGN_MIDDLE)
voffset = -newSize/2 + 2; // voffset = -newSize/2 + 2;
if(maxWidth > 0 && (font ? font : fontSystem)->getWidth(text) > maxWidth) if(maxWidth > 0 && (font ? font : fontSystem)->getWidth(text) > maxWidth)
{ {
@ -316,6 +318,7 @@ void GuiText::Draw()
if(scrollPos2 == 0 || frameCount > scrollDelay+5) if(scrollPos2 == 0 || frameCount > scrollDelay+5)
{ {
scrollPos1 = 0; scrollPos1 = 0;
scrollOffset = 0;
for(scrollPos2 = wcslen(text); scrollPos2 > 1; scrollPos2--) for(scrollPos2 = wcslen(text); scrollPos2 > 1; scrollPos2--)
{ {
save = text[scrollPos2]; // save Pos2 save = text[scrollPos2]; // save Pos2
@ -329,7 +332,14 @@ void GuiText::Draw()
} }
else if(scrollPos2 > 0 && frameCount >= scrollDelay) else if(scrollPos2 > 0 && frameCount >= scrollDelay)
{ {
scrollPos1++;
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); int strlen = wcslen(text);
for(; scrollPos2 < strlen; scrollPos2++) for(; scrollPos2 < strlen; scrollPos2++)
{ {
@ -337,7 +347,7 @@ void GuiText::Draw()
text[scrollPos2+1] = 0; text[scrollPos2+1] = 0;
int textWidth = (font ? font : fontSystem)->getWidth(&text[scrollPos1]); int textWidth = (font ? font : fontSystem)->getWidth(&text[scrollPos1]);
text[scrollPos2+1] = save; // restore Pos2 text[scrollPos2+1] = save; // restore Pos2
if(textWidth > maxWidth) if(textWidth+scrollOffset > maxWidth)
break; break;
} }
if(scrollPos2 == strlen) if(scrollPos2 == strlen)
@ -346,20 +356,28 @@ void GuiText::Draw()
scrollDelay = frameCount+25; // when dir-change wait 25 Frames scrollDelay = frameCount+25; // when dir-change wait 25 Frames
} }
else else
scrollDelay = frameCount+10; // wait 10 Frames scrollDelay = frameCount+1; // wait 1 Frames
} }
else if(frameCount >= scrollDelay) else if(frameCount >= scrollDelay)
{ {
scrollPos2 = -scrollPos2; scrollPos2 = -scrollPos2;
scrollPos1--; 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--;
}
for(; scrollPos2 > scrollPos1; scrollPos2--) for(; scrollPos2 > scrollPos1; scrollPos2--)
{ {
save = text[scrollPos2]; // save Pos2 save = text[scrollPos2]; // save Pos2
text[scrollPos2] = 0; text[scrollPos2] = 0;
int textWidth = (font ? font : fontSystem)->getWidth(&text[scrollPos1]); int textWidth = (font ? font : fontSystem)->getWidth(&text[scrollPos1]);
text[scrollPos2] = save; // restore Pos2 text[scrollPos2] = save; // restore Pos2
if(textWidth <= maxWidth) if(textWidth+scrollOffset <= maxWidth)
break; break;
} }
if(scrollPos1 == 0) if(scrollPos1 == 0)
@ -368,13 +386,28 @@ void GuiText::Draw()
scrollDelay = frameCount+25; // when dir-change wait 25 Frames scrollDelay = frameCount+25; // when dir-change wait 25 Frames
} }
else else
scrollDelay = frameCount+10; // wait 10 Frames scrollDelay = frameCount+1; // wait 10 Frames
scrollPos2 = -scrollPos2; 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 save = text[abs(scrollPos2)]; // save Pos2
text[abs(scrollPos2)] = 0; text[abs(scrollPos2)] = 0;
(font ? font : fontSystem)->drawText(this->GetLeft(), this->GetTop()+voffset, &text[scrollPos1], c, style); (font ? font : fontSystem)->drawText(drawX, this->GetTop()+voffset, &text[scrollPos1], c, drawStyle);
text[abs(scrollPos2)] = save; // restore Pos2 text[abs(scrollPos2)] = save; // restore Pos2
} }
} }

View File

@ -229,7 +229,7 @@ static void WindowCredits(void * ptr)
txt[i] = new GuiText(LANGUAGE.OfficialSite, 20, (GXColor){255, 255, 255, 255}); txt[i] = new GuiText(LANGUAGE.OfficialSite, 20, (GXColor){255, 255, 255, 255});
txt[i]->SetAlignment(ALIGN_CENTRE, ALIGN_TOP); txt[i]->SetPosition(-180,y); i++; y+=28; txt[i]->SetAlignment(ALIGN_CENTRE, ALIGN_TOP); txt[i]->SetPosition(-180,y); i++; y+=28;
txt[i]->SetPresets(22, (GXColor){255, 255, 255, 255}, 0, GuiText::SetPresets(22, (GXColor){255, 255, 255, 255}, 0, GuiText::WRAP,
FTGX_JUSTIFY_LEFT | FTGX_ALIGN_TOP, ALIGN_LEFT, ALIGN_TOP); FTGX_JUSTIFY_LEFT | FTGX_ALIGN_TOP, ALIGN_LEFT, ALIGN_TOP);
txt[i] = new GuiText("Coding:"); txt[i] = new GuiText("Coding:");