From b66525889777fe16d78aa3178d0b17e4d68efb28 Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Thu, 26 Jul 2012 15:26:59 +0000 Subject: [PATCH] - improve ability to force label edit mode rendering to be a static width regardless of font size used --- source/glest_game/facilities/components.cpp | 1 + source/glest_game/facilities/components.h | 4 ++ source/glest_game/graphics/renderer.cpp | 68 ++++++++++++------- source/glest_game/graphics/renderer.h | 8 +-- .../menu/menu_state_connected_game.cpp | 1 + .../menu/menu_state_custom_game.cpp | 2 + source/glest_game/menu/menu_state_options.cpp | 1 + 7 files changed, 56 insertions(+), 29 deletions(-) diff --git a/source/glest_game/facilities/components.cpp b/source/glest_game/facilities/components.cpp index 2b5171b5..b1b63348 100644 --- a/source/glest_game/facilities/components.cpp +++ b/source/glest_game/facilities/components.cpp @@ -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) { diff --git a/source/glest_game/facilities/components.h b/source/glest_game/facilities/components.h index ee3e5e5d..05d28177 100644 --- a/source/glest_game/facilities/components.h +++ b/source/glest_game/facilities/components.h @@ -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; } + }; // =========================================================== diff --git a/source/glest_game/graphics/renderer.cpp b/source/glest_game/graphics/renderer.cpp index 1c5c491b..3c31740f 100644 --- a/source/glest_game/graphics/renderer.cpp +++ b/source/glest_game/graphics/renderer.cpp @@ -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 { diff --git a/source/glest_game/graphics/renderer.h b/source/glest_game/graphics/renderer.h index 382387b0..d3ae8723 100644 --- a/source/glest_game/graphics/renderer.h +++ b/source/glest_game/graphics/renderer.h @@ -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); diff --git a/source/glest_game/menu/menu_state_connected_game.cpp b/source/glest_game/menu/menu_state_connected_game.cpp index 3d4226f2..bf913777 100644 --- a/source/glest_game/menu/menu_state_connected_game.cpp +++ b/source/glest_game/menu/menu_state_connected_game.cpp @@ -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); diff --git a/source/glest_game/menu/menu_state_custom_game.cpp b/source/glest_game/menu/menu_state_custom_game.cpp index 0b9650b1..f4bb4c9c 100644 --- a/source/glest_game/menu/menu_state_custom_game.cpp +++ b/source/glest_game/menu/menu_state_custom_game.cpp @@ -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); diff --git a/source/glest_game/menu/menu_state_options.cpp b/source/glest_game/menu/menu_state_options.cpp index 06580481..2e07b878 100644 --- a/source/glest_game/menu/menu_state_options.cpp +++ b/source/glest_game/menu/menu_state_options.cpp @@ -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