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:
+17
-4
@@ -113,10 +113,22 @@ void JLBFont::DrawString(const char *string, float x, float y, int align, float
|
|||||||
|
|
||||||
float width = GetStringWidth(string);
|
float width = GetStringWidth(string);
|
||||||
|
|
||||||
if (align == JGETEXT_RIGHT)
|
if (align == JGETEXT_RIGHT) {
|
||||||
|
if (displayWidth) {
|
||||||
|
dx0 -= displayWidth;
|
||||||
|
leftOffset += width - displayWidth;
|
||||||
|
}
|
||||||
|
else
|
||||||
dx0 -= width;
|
dx0 -= width;
|
||||||
else if (align == JGETEXT_CENTER)
|
}
|
||||||
|
else if (align == JGETEXT_CENTER) {
|
||||||
|
if (displayWidth) {
|
||||||
|
dx0 -= displayWidth/2;
|
||||||
|
leftOffset += width/2 - displayWidth/2;
|
||||||
|
}
|
||||||
|
else
|
||||||
dx0 -= width/2;
|
dx0 -= width/2;
|
||||||
|
}
|
||||||
|
|
||||||
float dx = floorf(dx0);
|
float dx = floorf(dx0);
|
||||||
dy = floorf(dy);
|
dy = floorf(dy);
|
||||||
@@ -147,7 +159,7 @@ void JLBFont::DrawString(const char *string, float x, float y, int align, float
|
|||||||
if (leftOffset < 0){
|
if (leftOffset < 0){
|
||||||
dx-=leftOffset;
|
dx-=leftOffset;
|
||||||
leftOffset = 0;
|
leftOffset = 0;
|
||||||
continue;
|
//continue;
|
||||||
}else if (leftOffset - delta > 0){
|
}else if (leftOffset - delta > 0){
|
||||||
leftOffset -= delta;
|
leftOffset -= delta;
|
||||||
p++;
|
p++;
|
||||||
@@ -160,7 +172,8 @@ void JLBFont::DrawString(const char *string, float x, float y, int align, float
|
|||||||
charWidth = (delta/mScale) - mTracking;
|
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 > x0+displayWidth) return;
|
||||||
if (dx+delta > x0+displayWidth) {
|
if (dx+delta > x0+displayWidth) {
|
||||||
delta = x0 + displayWidth - dx;
|
delta = x0 + displayWidth - dx;
|
||||||
|
|||||||
@@ -28,8 +28,14 @@ class WFont
|
|||||||
public:
|
public:
|
||||||
int mFontID;
|
int mFontID;
|
||||||
// Rendering text to screen.
|
// 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;
|
// Note:
|
||||||
virtual void DrawString(std::string s, float x, float y, int align=JGETEXT_LEFT, float leftOffset = 0, float width = 0) = 0;
|
// 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.
|
// Set font color.
|
||||||
virtual void SetColor(PIXEL_TYPE color) = 0;
|
virtual void SetColor(PIXEL_TYPE color) = 0;
|
||||||
// Get font color.
|
// Get font color.
|
||||||
|
|||||||
@@ -386,9 +386,19 @@ void WFBFont::DrawString(const char *s, float x, float y, int align, float leftO
|
|||||||
switch (align)
|
switch (align)
|
||||||
{
|
{
|
||||||
case JGETEXT_RIGHT:
|
case JGETEXT_RIGHT:
|
||||||
|
if (width) {
|
||||||
|
x -= width;
|
||||||
|
leftOffset += GetStringWidth(s) - width;
|
||||||
|
}
|
||||||
|
else
|
||||||
x -= GetStringWidth(s);
|
x -= GetStringWidth(s);
|
||||||
break;
|
break;
|
||||||
case JGETEXT_CENTER:
|
case JGETEXT_CENTER:
|
||||||
|
if (width) {
|
||||||
|
x -= width/2;
|
||||||
|
leftOffset += GetStringWidth(s)/2 - width/2;
|
||||||
|
}
|
||||||
|
else
|
||||||
x -= GetStringWidth(s)/2;
|
x -= GetStringWidth(s)/2;
|
||||||
break;
|
break;
|
||||||
case JGETEXT_LEFT:
|
case JGETEXT_LEFT:
|
||||||
@@ -473,7 +483,7 @@ void WFBFont::DrawString(const char *s, float x, float y, int align, float leftO
|
|||||||
charW = delta / mScale;
|
charW = delta / mScale;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (width)
|
if (width)
|
||||||
{
|
{
|
||||||
if (xx > x + width) return;
|
if (xx > x + width) return;
|
||||||
if (xx + delta > x + width)
|
if (xx + delta > x + width)
|
||||||
@@ -778,9 +788,19 @@ void WGBKFont::DrawString(const char *s, float x, float y, int align, float left
|
|||||||
switch (align)
|
switch (align)
|
||||||
{
|
{
|
||||||
case JGETEXT_RIGHT:
|
case JGETEXT_RIGHT:
|
||||||
|
if (width) {
|
||||||
|
x -= width;
|
||||||
|
leftOffset += GetStringWidth(s) - width;
|
||||||
|
}
|
||||||
|
else
|
||||||
x -= GetStringWidth(s);
|
x -= GetStringWidth(s);
|
||||||
break;
|
break;
|
||||||
case JGETEXT_CENTER:
|
case JGETEXT_CENTER:
|
||||||
|
if (width) {
|
||||||
|
x -= width/2;
|
||||||
|
leftOffset += GetStringWidth(s)/2 - width/2;
|
||||||
|
}
|
||||||
|
else
|
||||||
x -= GetStringWidth(s)/2;
|
x -= GetStringWidth(s)/2;
|
||||||
break;
|
break;
|
||||||
case JGETEXT_LEFT:
|
case JGETEXT_LEFT:
|
||||||
@@ -882,7 +902,7 @@ void WGBKFont::DrawString(const char *s, float x, float y, int align, float left
|
|||||||
charW = delta / mScale;
|
charW = delta / mScale;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (width)
|
if (width)
|
||||||
{
|
{
|
||||||
if (xx > x + width) return;
|
if (xx > x + width) return;
|
||||||
if (xx + delta > x + width)
|
if (xx + delta > x + width)
|
||||||
|
|||||||
Reference in New Issue
Block a user