Fixed left offset parameter handling for center/right align string drawing. A brief note about string drawing, offset and display width is added in the WFont.h
This commit is contained in:
@@ -113,10 +113,22 @@ void JLBFont::DrawString(const char *string, float x, float y, int align, float
|
||||
|
||||
float width = GetStringWidth(string);
|
||||
|
||||
if (align == JGETEXT_RIGHT)
|
||||
dx0 -= width;
|
||||
else if (align == JGETEXT_CENTER)
|
||||
dx0 -= width/2;
|
||||
if (align == JGETEXT_RIGHT) {
|
||||
if (displayWidth) {
|
||||
dx0 -= displayWidth;
|
||||
leftOffset += width - displayWidth;
|
||||
}
|
||||
else
|
||||
dx0 -= width;
|
||||
}
|
||||
else if (align == JGETEXT_CENTER) {
|
||||
if (displayWidth) {
|
||||
dx0 -= displayWidth/2;
|
||||
leftOffset += width/2 - displayWidth/2;
|
||||
}
|
||||
else
|
||||
dx0 -= width/2;
|
||||
}
|
||||
|
||||
float dx = floorf(dx0);
|
||||
dy = floorf(dy);
|
||||
@@ -147,7 +159,7 @@ void JLBFont::DrawString(const char *string, float x, float y, int align, float
|
||||
if (leftOffset < 0){
|
||||
dx-=leftOffset;
|
||||
leftOffset = 0;
|
||||
continue;
|
||||
//continue;
|
||||
}else if (leftOffset - delta > 0){
|
||||
leftOffset -= delta;
|
||||
p++;
|
||||
@@ -160,7 +172,8 @@ void JLBFont::DrawString(const char *string, float x, float y, int align, float
|
||||
charWidth = (delta/mScale) - mTracking;
|
||||
}
|
||||
}
|
||||
else if (displayWidth){
|
||||
if (displayWidth){
|
||||
// This condiction must be tested indepently in the case leftOffset and displayWidth need a fix at the same time.
|
||||
if (dx > x0+displayWidth) return;
|
||||
if (dx+delta > x0+displayWidth) {
|
||||
delta = x0 + displayWidth - dx;
|
||||
|
||||
@@ -28,8 +28,14 @@ class WFont
|
||||
public:
|
||||
int mFontID;
|
||||
// Rendering text to screen.
|
||||
virtual void DrawString(const char *s, float x, float y, int align=JGETEXT_LEFT, float leftOffset = 0, float width = 0) = 0;
|
||||
virtual void DrawString(std::string s, float x, float y, int align=JGETEXT_LEFT, float leftOffset = 0, float width = 0) = 0;
|
||||
// Note:
|
||||
// align=JGETEXT_LEFT, string region (x-leftOffset, x-leftOffset+StringWidth), display window (x, x+displayWidth)
|
||||
// align=JGETEXT_CENTER, string region (x-leftOffset-StringWidth/2, x-leftOffset+StringWidth/2), display window (x-displayWidth/2, x+displayWidth/2)
|
||||
// align=JGETEXT_RIGHT, string region (x-leftOffset-StringWidth, x-leftOffset), display window (x-displayWidth, x)
|
||||
// Only when width is NOT zero, characters outside the display window are not rendered.
|
||||
//
|
||||
virtual void DrawString(const char *s, float x, float y, int align=JGETEXT_LEFT, float leftOffset = 0, float displayWidth = 0) = 0;
|
||||
virtual void DrawString(std::string s, float x, float y, int align=JGETEXT_LEFT, float leftOffset = 0, float displayWidth = 0) = 0;
|
||||
// Set font color.
|
||||
virtual void SetColor(PIXEL_TYPE color) = 0;
|
||||
// Get font color.
|
||||
|
||||
@@ -386,10 +386,20 @@ void WFBFont::DrawString(const char *s, float x, float y, int align, float leftO
|
||||
switch (align)
|
||||
{
|
||||
case JGETEXT_RIGHT:
|
||||
x -= GetStringWidth(s);
|
||||
if (width) {
|
||||
x -= width;
|
||||
leftOffset += GetStringWidth(s) - width;
|
||||
}
|
||||
else
|
||||
x -= GetStringWidth(s);
|
||||
break;
|
||||
case JGETEXT_CENTER:
|
||||
x -= GetStringWidth(s) / 2;
|
||||
if (width) {
|
||||
x -= width/2;
|
||||
leftOffset += GetStringWidth(s)/2 - width/2;
|
||||
}
|
||||
else
|
||||
x -= GetStringWidth(s)/2;
|
||||
break;
|
||||
case JGETEXT_LEFT:
|
||||
default:
|
||||
@@ -473,7 +483,7 @@ void WFBFont::DrawString(const char *s, float x, float y, int align, float leftO
|
||||
charW = delta / mScale;
|
||||
}
|
||||
}
|
||||
else if (width)
|
||||
if (width)
|
||||
{
|
||||
if (xx > x + width) return;
|
||||
if (xx + delta > x + width)
|
||||
@@ -778,10 +788,20 @@ void WGBKFont::DrawString(const char *s, float x, float y, int align, float left
|
||||
switch (align)
|
||||
{
|
||||
case JGETEXT_RIGHT:
|
||||
x -= GetStringWidth(s);
|
||||
if (width) {
|
||||
x -= width;
|
||||
leftOffset += GetStringWidth(s) - width;
|
||||
}
|
||||
else
|
||||
x -= GetStringWidth(s);
|
||||
break;
|
||||
case JGETEXT_CENTER:
|
||||
x -= GetStringWidth(s) / 2;
|
||||
if (width) {
|
||||
x -= width/2;
|
||||
leftOffset += GetStringWidth(s)/2 - width/2;
|
||||
}
|
||||
else
|
||||
x -= GetStringWidth(s)/2;
|
||||
break;
|
||||
case JGETEXT_LEFT:
|
||||
default:
|
||||
@@ -882,7 +902,7 @@ void WGBKFont::DrawString(const char *s, float x, float y, int align, float left
|
||||
charW = delta / mScale;
|
||||
}
|
||||
}
|
||||
else if (width)
|
||||
if (width)
|
||||
{
|
||||
if (xx > x + width) return;
|
||||
if (xx + delta > x + width)
|
||||
|
||||
Reference in New Issue
Block a user