- improve ability to force label edit mode rendering to be a static width regardless of font size used

This commit is contained in:
Mark Vejvoda 2012-07-26 15:26:59 +00:00
parent 8dc59d74f7
commit b665258897
7 changed files with 56 additions and 29 deletions

View File

@ -279,6 +279,7 @@ GraphicLabel::GraphicLabel() {
centeredH = 1;
editModeEnabled = false;
maxEditWidth = -1;
maxEditRenderWidth = -1;
}
void GraphicLabel::init(int x, int y, int w, int h, bool centered, Vec3f textColor, bool wordWrap) {

View File

@ -142,6 +142,7 @@ private:
bool editModeEnabled;
int maxEditWidth;
int maxEditRenderWidth;
public:
GraphicLabel();
@ -170,6 +171,9 @@ public:
void setMaxEditWidth(int value) { maxEditWidth = value; }
int getMaxEditWidth() const { return maxEditWidth; }
void setMaxEditRenderWidth(int value) { maxEditRenderWidth = value; }
int getMaxEditRenderWidth() const { return maxEditRenderWidth; }
};
// ===========================================================

View File

@ -2364,13 +2364,20 @@ Vec2i computeCenteredPos(const string &text, Font3D *font, int x, int y) {
return textPos;
}
void Renderer::renderTextSurroundingBox(int x, int y, int w, int h,int maxEditWidth) {
void Renderer::renderTextSurroundingBox(int x, int y, int w, int h,
int maxEditWidth, int maxEditRenderWidth) {
//glColor4fv(color.ptr());
//glBegin(GL_QUADS); // Start drawing a quad primitive
if(maxEditWidth >= 0 && maxEditWidth > w) {
//printf("B w = %d maxEditWidth = %d\n",w,maxEditWidth);
w = maxEditWidth;
//printf("A w = %d maxEditWidth = %d maxEditRenderWidth = %d\n",w,maxEditWidth,maxEditRenderWidth);
if(maxEditWidth >= 0 || maxEditRenderWidth >= 0) {
//printf("B w = %d maxEditWidth = %d maxEditRenderWidth = %d\n",w,maxEditWidth,maxEditRenderWidth);
if(maxEditRenderWidth >= 0) {
w = maxEditRenderWidth;
}
else {
w = maxEditWidth;
}
}
//printf("HI!!!\n");
glPointSize(20.0f);
@ -2388,7 +2395,7 @@ void Renderer::renderTextSurroundingBox(int x, int y, int w, int h,int maxEditWi
void Renderer::renderTextBoundingBox3D(const string &text, Font3D *font,
float alpha, int x, int y, int w, int h, bool centeredW, bool centeredH,
bool editModeEnabled,int maxEditWidth) {
bool editModeEnabled,int maxEditWidth, int maxEditRenderWidth) {
if(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == true) {
return;
}
@ -2404,16 +2411,19 @@ void Renderer::renderTextBoundingBox3D(const string &text, Font3D *font,
}
if(editModeEnabled) {
if(maxEditWidth >= 0) {
if(maxEditWidth >= 0 || maxEditRenderWidth >= 0) {
int useWidth = maxEditWidth;
string temp = "";
for(int i = 0; i < maxEditWidth; ++i) {
for(int i = 0; i < useWidth; ++i) {
temp += DEFAULT_CHAR_FOR_WIDTH_CALC;
}
float lineWidth = (font->getTextHandler()->Advance(temp.c_str()) * Font::scaleFontValue);
maxEditWidth = (int)lineWidth;
useWidth = (int)lineWidth;
maxEditWidth = useWidth;
}
renderTextSurroundingBox(pos.x, pos.y, w, h,maxEditWidth);
renderTextSurroundingBox(pos.x, pos.y, w, h,maxEditWidth,maxEditRenderWidth);
}
glColor4fv(Vec4f(1.f, 1.f, 1.f, alpha).ptr());
TextRendererSafeWrapper safeTextRender(textRenderer3D,font);
@ -2536,7 +2546,7 @@ Vec2f Renderer::getCentered3DPos(const string &text, Font3D *font, Vec2f &pos, i
void Renderer::renderTextBoundingBox3D(const string &text, Font3D *font,
const Vec3f &color, int x, int y, int w, int h, bool centeredW,
bool centeredH, bool editModeEnabled,int maxEditWidth) {
bool centeredH, bool editModeEnabled,int maxEditWidth, int maxEditRenderWidth) {
if(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == true) {
return;
}
@ -2552,16 +2562,19 @@ void Renderer::renderTextBoundingBox3D(const string &text, Font3D *font,
}
if(editModeEnabled) {
if(maxEditWidth >= 0) {
if(maxEditWidth >= 0 || maxEditRenderWidth >= 0) {
int useWidth = maxEditWidth;
string temp = "";
for(int i = 0; i < maxEditWidth; ++i) {
for(int i = 0; i < useWidth; ++i) {
temp += DEFAULT_CHAR_FOR_WIDTH_CALC;
}
float lineWidth = (font->getTextHandler()->Advance(temp.c_str()) * Font::scaleFontValue);
maxEditWidth = (int)lineWidth;
useWidth = (int)lineWidth;
maxEditWidth = useWidth;
}
renderTextSurroundingBox(pos.x, pos.y, w, h,maxEditWidth);
renderTextSurroundingBox(pos.x, pos.y, w, h,maxEditWidth,maxEditRenderWidth);
}
glColor3fv(color.ptr());
//textRenderer3D->begin(font);
@ -2614,7 +2627,7 @@ void Renderer::renderText(const string &text, Font2D *font, const Vec3f &color,
void Renderer::renderTextBoundingBox3D(const string &text, Font3D *font,
const Vec4f &color, int x, int y, int w, int h, bool centeredW,
bool centeredH, bool editModeEnabled,int maxEditWidth) {
bool centeredH, bool editModeEnabled,int maxEditWidth, int maxEditRenderWidth) {
if(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == true) {
return;
}
@ -2631,16 +2644,19 @@ void Renderer::renderTextBoundingBox3D(const string &text, Font3D *font,
}
if(editModeEnabled) {
if(maxEditWidth >= 0) {
if(maxEditWidth >= 0 || maxEditRenderWidth >= 0) {
int useWidth = maxEditWidth;
string temp = "";
for(int i = 0; i < maxEditWidth; ++i) {
for(int i = 0; i < useWidth; ++i) {
temp += DEFAULT_CHAR_FOR_WIDTH_CALC;
}
float lineWidth = (font->getTextHandler()->Advance(temp.c_str()) * Font::scaleFontValue);
maxEditWidth = (int)lineWidth;
useWidth = (int)lineWidth;
maxEditWidth = useWidth;
}
renderTextSurroundingBox(pos.x, pos.y, w, h,maxEditWidth);
renderTextSurroundingBox(pos.x, pos.y, w, h,maxEditWidth,maxEditRenderWidth);
}
glColor4fv(color.ptr());
//textRenderer3D->begin(font);
@ -2822,7 +2838,8 @@ void Renderer::renderLabel(GraphicLabel *label,const Vec4f *color) {
//printf("Label render C\n");
renderTextBoundingBox3D(lines[i], label->getFont3D(), (*color),
x, y, w, h, label->getCenteredW(),label->getCenteredH(),
label->getEditModeEnabled(),label->getMaxEditWidth());
label->getEditModeEnabled(),label->getMaxEditWidth(),
label->getMaxEditRenderWidth());
}
else {
//printf("Label render D\n");
@ -2837,7 +2854,8 @@ void Renderer::renderLabel(GraphicLabel *label,const Vec4f *color) {
renderTextBoundingBox3D(lines[i], label->getFont3D(),
GraphicComponent::getFade(), x, y, w, h,
label->getCenteredW(),label->getCenteredH(),
label->getEditModeEnabled(),label->getMaxEditWidth());
label->getEditModeEnabled(),label->getMaxEditWidth(),
label->getMaxEditRenderWidth());
}
else {
//printf("Label render F\n");
@ -2964,7 +2982,7 @@ void Renderer::renderButton(GraphicButton *button, const Vec4f *fontColorOverrid
if(renderText3DEnabled == true) {
//renderText3D(button->getText(), button->getFont3D(), color,x + (w / 2), y + (h / 2), true);
renderTextBoundingBox3D(button->getText(), button->getFont3D(),
color, x, y, w, h, true, true,false,-1);
color, x, y, w, h, true, true,false,-1,-1);
}
else {
renderText(button->getText(), button->getFont(), color,x + (w / 2), y + (h / 2), true);
@ -2975,7 +2993,7 @@ void Renderer::renderButton(GraphicButton *button, const Vec4f *fontColorOverrid
//renderText3D(button->getText(), button->getFont3D(),disabledTextColor,
// x + (w / 2), y + (h / 2), true);
renderTextBoundingBox3D(button->getText(), button->getFont3D(),disabledTextColor,
x, y, w, h, true, true,false,-1);
x, y, w, h, true, true,false,-1,-1);
}
else {
renderText(button->getText(), button->getFont(),disabledTextColor,
@ -7786,7 +7804,7 @@ void Renderer::renderProgressBar3D(int size, int x, int y, Font3D *font, int cus
//printf("Render progress bar3d renderText [%s] y = %d, centeredText = %d\n",renderText.c_str(),y, centeredText);
renderTextBoundingBox3D(renderText, font, defColor, x, y, maxSize,
progressbarHeight, true, true, false,-1);
progressbarHeight, true, true, false,-1,-1);
}
void Renderer::renderProgressBar(int size, int x, int y, Font2D *font, int customWidth,
@ -8993,7 +9011,7 @@ void Renderer::renderPopupMenu(PopupMenu *menu) {
renderTextBoundingBox3D(
menu->getHeader(), menu->getFont3D(),fontColor,
menu->getX(), menu->getY()+93*menu->getH()/100,menu->getW(),0,
true,false, false,-1 );
true,false, false,-1,-1);
}
else {

View File

@ -491,11 +491,11 @@ public:
void renderProgressBar3D(int size, int x, int y, Font3D *font, int customWidth=-1, string prefixLabel="", bool centeredText=true);
Vec2f getCentered3DPos(const string &text, Font3D *font, Vec2f &pos, int w, int h, bool centeredW, bool centeredH);
void renderTextBoundingBox3D(const string &text, Font3D *font, const Vec4f &color, int x, int y, int w, int h, bool centeredW, bool centeredH, bool editModeEnabled, int maxEditWidth);
void renderTextBoundingBox3D(const string &text, Font3D *font, const Vec3f &color, int x, int y, int w, int h, bool centeredW, bool centeredH, bool editModeEnabled,int maxEditWidth);
void renderTextBoundingBox3D(const string &text, Font3D *font, float alpha, int x, int y, int w, int h, bool centeredW, bool centeredH, bool editModeEnabled,int maxEditWidth);
void renderTextBoundingBox3D(const string &text, Font3D *font, const Vec4f &color, int x, int y, int w, int h, bool centeredW, bool centeredH, bool editModeEnabled, int maxEditWidth, int maxEditRenderWidth);
void renderTextBoundingBox3D(const string &text, Font3D *font, const Vec3f &color, int x, int y, int w, int h, bool centeredW, bool centeredH, bool editModeEnabled,int maxEditWidth, int maxEditRenderWidth);
void renderTextBoundingBox3D(const string &text, Font3D *font, float alpha, int x, int y, int w, int h, bool centeredW, bool centeredH, bool editModeEnabled,int maxEditWidth, int maxEditRenderWidth);
void renderTextSurroundingBox(int x, int y, int w, int h,int maxEditWidth);
void renderTextSurroundingBox(int x, int y, int w, int h,int maxEditWidth, int maxEditRenderWidth);
void beginRenderToTexture(Texture2D **renderToTexture);
void endRenderToTexture(Texture2D **renderToTexture);

View File

@ -373,6 +373,7 @@ MenuStateConnectedGame::MenuStateConnectedGame(Program *program, MainMenu *mainM
labelPlayers[i].setText(lang.get("Player")+" "+intToStr(i));
labelPlayerNames[i].setText("");
labelPlayerNames[i].setMaxEditWidth(16);
labelPlayerNames[i].setMaxEditRenderWidth(135);
listBoxTeams[i].setItems(teamItems);
listBoxTeams[i].setSelectedItemIndex(i);

View File

@ -380,6 +380,7 @@ MenuStateCustomGame::MenuStateCustomGame(Program *program, MainMenu *mainMenu,
labelGameName.setText("headless ("+defaultPlayerName+")");
}
labelGameName.setMaxEditWidth(20);
labelGameName.setMaxEditRenderWidth(160);
// Network Frame Period
//labelNetworkFramePeriod.registerGraphicComponent(containerName,"labelNetworkFramePeriod");
//labelNetworkFramePeriod.init(xoffset+230, networkHeadPos, 80);
@ -538,6 +539,7 @@ MenuStateCustomGame::MenuStateCustomGame(Program *program, MainMenu *mainMenu,
labelPlayers[i].setText(lang.get("Player")+" "+intToStr(i));
labelPlayerNames[i].setText("*");
labelPlayerNames[i].setMaxEditWidth(16);
labelPlayerNames[i].setMaxEditRenderWidth(135);
listBoxTeams[i].setItems(teamItems);
listBoxTeams[i].setSelectedItemIndex(i);

View File

@ -382,6 +382,7 @@ MenuStateOptions::MenuStateOptions(Program *program, MainMenu *mainMenu):
labelPlayerName.setFont(CoreData::getInstance().getMenuFontBig());
labelPlayerName.setFont3D(CoreData::getInstance().getMenuFontBig3D());
labelPlayerName.setMaxEditWidth(16);
labelPlayerName.setMaxEditRenderWidth(200);
currentLine-=lineOffset;
//FontSizeAdjustment