- improve ability to force label edit mode rendering to be a static width regardless of font size used
This commit is contained in:
parent
8dc59d74f7
commit
b665258897
|
@ -279,6 +279,7 @@ GraphicLabel::GraphicLabel() {
|
||||||
centeredH = 1;
|
centeredH = 1;
|
||||||
editModeEnabled = false;
|
editModeEnabled = false;
|
||||||
maxEditWidth = -1;
|
maxEditWidth = -1;
|
||||||
|
maxEditRenderWidth = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GraphicLabel::init(int x, int y, int w, int h, bool centered, Vec3f textColor, bool wordWrap) {
|
void GraphicLabel::init(int x, int y, int w, int h, bool centered, Vec3f textColor, bool wordWrap) {
|
||||||
|
|
|
@ -142,6 +142,7 @@ private:
|
||||||
|
|
||||||
bool editModeEnabled;
|
bool editModeEnabled;
|
||||||
int maxEditWidth;
|
int maxEditWidth;
|
||||||
|
int maxEditRenderWidth;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
GraphicLabel();
|
GraphicLabel();
|
||||||
|
@ -170,6 +171,9 @@ public:
|
||||||
void setMaxEditWidth(int value) { maxEditWidth = value; }
|
void setMaxEditWidth(int value) { maxEditWidth = value; }
|
||||||
int getMaxEditWidth() const { return maxEditWidth; }
|
int getMaxEditWidth() const { return maxEditWidth; }
|
||||||
|
|
||||||
|
void setMaxEditRenderWidth(int value) { maxEditRenderWidth = value; }
|
||||||
|
int getMaxEditRenderWidth() const { return maxEditRenderWidth; }
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// ===========================================================
|
// ===========================================================
|
||||||
|
|
|
@ -2364,13 +2364,20 @@ Vec2i computeCenteredPos(const string &text, Font3D *font, int x, int y) {
|
||||||
return textPos;
|
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());
|
//glColor4fv(color.ptr());
|
||||||
//glBegin(GL_QUADS); // Start drawing a quad primitive
|
//glBegin(GL_QUADS); // Start drawing a quad primitive
|
||||||
|
|
||||||
if(maxEditWidth >= 0 && maxEditWidth > w) {
|
//printf("A w = %d maxEditWidth = %d maxEditRenderWidth = %d\n",w,maxEditWidth,maxEditRenderWidth);
|
||||||
//printf("B w = %d maxEditWidth = %d\n",w,maxEditWidth);
|
if(maxEditWidth >= 0 || maxEditRenderWidth >= 0) {
|
||||||
w = maxEditWidth;
|
//printf("B w = %d maxEditWidth = %d maxEditRenderWidth = %d\n",w,maxEditWidth,maxEditRenderWidth);
|
||||||
|
if(maxEditRenderWidth >= 0) {
|
||||||
|
w = maxEditRenderWidth;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
w = maxEditWidth;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
//printf("HI!!!\n");
|
//printf("HI!!!\n");
|
||||||
glPointSize(20.0f);
|
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,
|
void Renderer::renderTextBoundingBox3D(const string &text, Font3D *font,
|
||||||
float alpha, int x, int y, int w, int h, bool centeredW, bool centeredH,
|
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) {
|
if(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == true) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -2404,16 +2411,19 @@ void Renderer::renderTextBoundingBox3D(const string &text, Font3D *font,
|
||||||
}
|
}
|
||||||
|
|
||||||
if(editModeEnabled) {
|
if(editModeEnabled) {
|
||||||
if(maxEditWidth >= 0) {
|
if(maxEditWidth >= 0 || maxEditRenderWidth >= 0) {
|
||||||
|
int useWidth = maxEditWidth;
|
||||||
string temp = "";
|
string temp = "";
|
||||||
for(int i = 0; i < maxEditWidth; ++i) {
|
for(int i = 0; i < useWidth; ++i) {
|
||||||
temp += DEFAULT_CHAR_FOR_WIDTH_CALC;
|
temp += DEFAULT_CHAR_FOR_WIDTH_CALC;
|
||||||
}
|
}
|
||||||
float lineWidth = (font->getTextHandler()->Advance(temp.c_str()) * Font::scaleFontValue);
|
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());
|
glColor4fv(Vec4f(1.f, 1.f, 1.f, alpha).ptr());
|
||||||
TextRendererSafeWrapper safeTextRender(textRenderer3D,font);
|
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,
|
void Renderer::renderTextBoundingBox3D(const string &text, Font3D *font,
|
||||||
const Vec3f &color, int x, int y, int w, int h, bool centeredW,
|
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) {
|
if(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == true) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -2552,16 +2562,19 @@ void Renderer::renderTextBoundingBox3D(const string &text, Font3D *font,
|
||||||
}
|
}
|
||||||
|
|
||||||
if(editModeEnabled) {
|
if(editModeEnabled) {
|
||||||
if(maxEditWidth >= 0) {
|
if(maxEditWidth >= 0 || maxEditRenderWidth >= 0) {
|
||||||
|
int useWidth = maxEditWidth;
|
||||||
string temp = "";
|
string temp = "";
|
||||||
for(int i = 0; i < maxEditWidth; ++i) {
|
for(int i = 0; i < useWidth; ++i) {
|
||||||
temp += DEFAULT_CHAR_FOR_WIDTH_CALC;
|
temp += DEFAULT_CHAR_FOR_WIDTH_CALC;
|
||||||
}
|
}
|
||||||
float lineWidth = (font->getTextHandler()->Advance(temp.c_str()) * Font::scaleFontValue);
|
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());
|
glColor3fv(color.ptr());
|
||||||
//textRenderer3D->begin(font);
|
//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,
|
void Renderer::renderTextBoundingBox3D(const string &text, Font3D *font,
|
||||||
const Vec4f &color, int x, int y, int w, int h, bool centeredW,
|
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) {
|
if(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == true) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -2631,16 +2644,19 @@ void Renderer::renderTextBoundingBox3D(const string &text, Font3D *font,
|
||||||
}
|
}
|
||||||
|
|
||||||
if(editModeEnabled) {
|
if(editModeEnabled) {
|
||||||
if(maxEditWidth >= 0) {
|
if(maxEditWidth >= 0 || maxEditRenderWidth >= 0) {
|
||||||
|
int useWidth = maxEditWidth;
|
||||||
string temp = "";
|
string temp = "";
|
||||||
for(int i = 0; i < maxEditWidth; ++i) {
|
for(int i = 0; i < useWidth; ++i) {
|
||||||
temp += DEFAULT_CHAR_FOR_WIDTH_CALC;
|
temp += DEFAULT_CHAR_FOR_WIDTH_CALC;
|
||||||
}
|
}
|
||||||
float lineWidth = (font->getTextHandler()->Advance(temp.c_str()) * Font::scaleFontValue);
|
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());
|
glColor4fv(color.ptr());
|
||||||
//textRenderer3D->begin(font);
|
//textRenderer3D->begin(font);
|
||||||
|
@ -2822,7 +2838,8 @@ void Renderer::renderLabel(GraphicLabel *label,const Vec4f *color) {
|
||||||
//printf("Label render C\n");
|
//printf("Label render C\n");
|
||||||
renderTextBoundingBox3D(lines[i], label->getFont3D(), (*color),
|
renderTextBoundingBox3D(lines[i], label->getFont3D(), (*color),
|
||||||
x, y, w, h, label->getCenteredW(),label->getCenteredH(),
|
x, y, w, h, label->getCenteredW(),label->getCenteredH(),
|
||||||
label->getEditModeEnabled(),label->getMaxEditWidth());
|
label->getEditModeEnabled(),label->getMaxEditWidth(),
|
||||||
|
label->getMaxEditRenderWidth());
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
//printf("Label render D\n");
|
//printf("Label render D\n");
|
||||||
|
@ -2837,7 +2854,8 @@ void Renderer::renderLabel(GraphicLabel *label,const Vec4f *color) {
|
||||||
renderTextBoundingBox3D(lines[i], label->getFont3D(),
|
renderTextBoundingBox3D(lines[i], label->getFont3D(),
|
||||||
GraphicComponent::getFade(), x, y, w, h,
|
GraphicComponent::getFade(), x, y, w, h,
|
||||||
label->getCenteredW(),label->getCenteredH(),
|
label->getCenteredW(),label->getCenteredH(),
|
||||||
label->getEditModeEnabled(),label->getMaxEditWidth());
|
label->getEditModeEnabled(),label->getMaxEditWidth(),
|
||||||
|
label->getMaxEditRenderWidth());
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
//printf("Label render F\n");
|
//printf("Label render F\n");
|
||||||
|
@ -2964,7 +2982,7 @@ void Renderer::renderButton(GraphicButton *button, const Vec4f *fontColorOverrid
|
||||||
if(renderText3DEnabled == true) {
|
if(renderText3DEnabled == true) {
|
||||||
//renderText3D(button->getText(), button->getFont3D(), color,x + (w / 2), y + (h / 2), true);
|
//renderText3D(button->getText(), button->getFont3D(), color,x + (w / 2), y + (h / 2), true);
|
||||||
renderTextBoundingBox3D(button->getText(), button->getFont3D(),
|
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 {
|
else {
|
||||||
renderText(button->getText(), button->getFont(), color,x + (w / 2), y + (h / 2), true);
|
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,
|
//renderText3D(button->getText(), button->getFont3D(),disabledTextColor,
|
||||||
// x + (w / 2), y + (h / 2), true);
|
// x + (w / 2), y + (h / 2), true);
|
||||||
renderTextBoundingBox3D(button->getText(), button->getFont3D(),disabledTextColor,
|
renderTextBoundingBox3D(button->getText(), button->getFont3D(),disabledTextColor,
|
||||||
x, y, w, h, true, true,false,-1);
|
x, y, w, h, true, true,false,-1,-1);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
renderText(button->getText(), button->getFont(),disabledTextColor,
|
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);
|
//printf("Render progress bar3d renderText [%s] y = %d, centeredText = %d\n",renderText.c_str(),y, centeredText);
|
||||||
|
|
||||||
renderTextBoundingBox3D(renderText, font, defColor, x, y, maxSize,
|
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,
|
void Renderer::renderProgressBar(int size, int x, int y, Font2D *font, int customWidth,
|
||||||
|
@ -8993,7 +9011,7 @@ void Renderer::renderPopupMenu(PopupMenu *menu) {
|
||||||
renderTextBoundingBox3D(
|
renderTextBoundingBox3D(
|
||||||
menu->getHeader(), menu->getFont3D(),fontColor,
|
menu->getHeader(), menu->getFont3D(),fontColor,
|
||||||
menu->getX(), menu->getY()+93*menu->getH()/100,menu->getW(),0,
|
menu->getX(), menu->getY()+93*menu->getH()/100,menu->getW(),0,
|
||||||
true,false, false,-1 );
|
true,false, false,-1,-1);
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
|
@ -491,11 +491,11 @@ public:
|
||||||
void renderProgressBar3D(int size, int x, int y, Font3D *font, int customWidth=-1, string prefixLabel="", bool centeredText=true);
|
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);
|
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 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);
|
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);
|
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 beginRenderToTexture(Texture2D **renderToTexture);
|
||||||
void endRenderToTexture(Texture2D **renderToTexture);
|
void endRenderToTexture(Texture2D **renderToTexture);
|
||||||
|
|
|
@ -373,6 +373,7 @@ MenuStateConnectedGame::MenuStateConnectedGame(Program *program, MainMenu *mainM
|
||||||
labelPlayers[i].setText(lang.get("Player")+" "+intToStr(i));
|
labelPlayers[i].setText(lang.get("Player")+" "+intToStr(i));
|
||||||
labelPlayerNames[i].setText("");
|
labelPlayerNames[i].setText("");
|
||||||
labelPlayerNames[i].setMaxEditWidth(16);
|
labelPlayerNames[i].setMaxEditWidth(16);
|
||||||
|
labelPlayerNames[i].setMaxEditRenderWidth(135);
|
||||||
|
|
||||||
listBoxTeams[i].setItems(teamItems);
|
listBoxTeams[i].setItems(teamItems);
|
||||||
listBoxTeams[i].setSelectedItemIndex(i);
|
listBoxTeams[i].setSelectedItemIndex(i);
|
||||||
|
|
|
@ -380,6 +380,7 @@ MenuStateCustomGame::MenuStateCustomGame(Program *program, MainMenu *mainMenu,
|
||||||
labelGameName.setText("headless ("+defaultPlayerName+")");
|
labelGameName.setText("headless ("+defaultPlayerName+")");
|
||||||
}
|
}
|
||||||
labelGameName.setMaxEditWidth(20);
|
labelGameName.setMaxEditWidth(20);
|
||||||
|
labelGameName.setMaxEditRenderWidth(160);
|
||||||
// Network Frame Period
|
// Network Frame Period
|
||||||
//labelNetworkFramePeriod.registerGraphicComponent(containerName,"labelNetworkFramePeriod");
|
//labelNetworkFramePeriod.registerGraphicComponent(containerName,"labelNetworkFramePeriod");
|
||||||
//labelNetworkFramePeriod.init(xoffset+230, networkHeadPos, 80);
|
//labelNetworkFramePeriod.init(xoffset+230, networkHeadPos, 80);
|
||||||
|
@ -538,6 +539,7 @@ MenuStateCustomGame::MenuStateCustomGame(Program *program, MainMenu *mainMenu,
|
||||||
labelPlayers[i].setText(lang.get("Player")+" "+intToStr(i));
|
labelPlayers[i].setText(lang.get("Player")+" "+intToStr(i));
|
||||||
labelPlayerNames[i].setText("*");
|
labelPlayerNames[i].setText("*");
|
||||||
labelPlayerNames[i].setMaxEditWidth(16);
|
labelPlayerNames[i].setMaxEditWidth(16);
|
||||||
|
labelPlayerNames[i].setMaxEditRenderWidth(135);
|
||||||
|
|
||||||
listBoxTeams[i].setItems(teamItems);
|
listBoxTeams[i].setItems(teamItems);
|
||||||
listBoxTeams[i].setSelectedItemIndex(i);
|
listBoxTeams[i].setSelectedItemIndex(i);
|
||||||
|
|
|
@ -382,6 +382,7 @@ MenuStateOptions::MenuStateOptions(Program *program, MainMenu *mainMenu):
|
||||||
labelPlayerName.setFont(CoreData::getInstance().getMenuFontBig());
|
labelPlayerName.setFont(CoreData::getInstance().getMenuFontBig());
|
||||||
labelPlayerName.setFont3D(CoreData::getInstance().getMenuFontBig3D());
|
labelPlayerName.setFont3D(CoreData::getInstance().getMenuFontBig3D());
|
||||||
labelPlayerName.setMaxEditWidth(16);
|
labelPlayerName.setMaxEditWidth(16);
|
||||||
|
labelPlayerName.setMaxEditRenderWidth(200);
|
||||||
currentLine-=lineOffset;
|
currentLine-=lineOffset;
|
||||||
|
|
||||||
//FontSizeAdjustment
|
//FontSizeAdjustment
|
||||||
|
|
Loading…
Reference in New Issue
Block a user