diff --git a/glfontengine.cpp b/glfontengine.cpp index 4dee7ab..95a4a53 100644 --- a/glfontengine.cpp +++ b/glfontengine.cpp @@ -241,4 +241,8 @@ int GLFontEngine::getTextWidth(const std::string &moep) { return 1; } +int GLFontEngine::getTextWidthbyInt(int length) { + return (int)(font->charwidth*fsize); +} + std::map GLFontEngine::fontpool; diff --git a/glfontengine.h b/glfontengine.h index f9e0e0f..00e56e3 100644 --- a/glfontengine.h +++ b/glfontengine.h @@ -63,6 +63,7 @@ class GLFontEngine { int getSize(); void getSDLRect(const std::string&, SDL_Rect*); int getTextWidth(const std::string&); + int getTextWidthbyInt(int length); }; diff --git a/glmenu/menuitem.cpp b/glmenu/menuitem.cpp index 7de3ca8..160b41c 100644 --- a/glmenu/menuitem.cpp +++ b/glmenu/menuitem.cpp @@ -24,7 +24,11 @@ void MenuItem::setCaption(std::string str) { caption = str; } -void MenuItem::render(Punkt2D pos, bool center, int basefontsize, int maxwidth, int valuewidth, bool highlight, int caplen, int vallen) { +int MenuItem::getMaxValueLen() { + return (int)value.length(); +} + +void MenuItem::render(Punkt2D pos, bool center, int basefontsize, int maxwidth, int valuewidth, bool highlight, int caplen, int capvallen, int maxlen) { fontengine.setSize(basefontsize+fontsizeadd); if(highlight) fontengine.setColor(1.0f, 0.0f, 0.0f); @@ -39,13 +43,14 @@ void MenuItem::render(Punkt2D pos, bool center, int basefontsize, int maxwidth, // center und position ggf. überarbeiten.. Punkt2D tmp = pos; - tmp.x = pos.x - (caplen+vallen+valuewidth)/2; +// tmp.x = pos.x - (caplen+vallen+valuewidth)/2; + tmp.x = pos.x - maxlen/2; // tmp.x = pos.x - valuewidth/2 - fontengine.getTextWidth(caption)/2; // tmp.x = pos.x - caplen - valuewidth/2; fontengine.renderLine(caption, (int)tmp.x, (int)tmp.y, false); - tmp.x += caplen+valuewidth; + tmp.x += capvallen+valuewidth; fontengine.renderLine(value, (int)tmp.x, (int)tmp.y, false); } } @@ -54,6 +59,10 @@ bool MenuItem::isSelectable() { return (!grey)&&selectable; } +bool MenuItem::hasValue() { + return usevalue; +} + void MenuItem::setFontSizeAdd(int fsa) { fontsizeadd = fsa; } diff --git a/glmenu/menuitem.h b/glmenu/menuitem.h index 36021de..a29fb85 100644 --- a/glmenu/menuitem.h +++ b/glmenu/menuitem.h @@ -31,13 +31,16 @@ class MenuItem { virtual void select() { }; virtual void charInput(char c) { }; + virtual int getMaxValueLen(); + + bool hasValue(); void setFontSizeAdd(int fsa); int getFontSizeAdd(); bool isSelectable(); void greyItem(bool _grey); void noValueCenter(bool _vc); - virtual void render(Punkt2D pos, bool center, int basefontsize, int maxwidth, int valuewidth, bool highlight, int caplen, int vallen); + virtual void render(Punkt2D pos, bool center, int basefontsize, int maxwidth, int valuewidth, bool highlight, int caplen, int capvallen, int maxlen); }; #endif diff --git a/glmenu/menuitems.cpp b/glmenu/menuitems.cpp index 21b6159..298bff4 100644 --- a/glmenu/menuitems.cpp +++ b/glmenu/menuitems.cpp @@ -63,6 +63,15 @@ void MIToggle::addToggle(std::string str) { } } +int MIToggle::getMaxValueLen() { + int ret=0; + for(unsigned int i=0; iw/2; } - int clen=0, vlen=0, height=0, fullvalwidth=0; + int clen=0, vlen=0, cvlen=0, height=0, fullvalwidth=0, maxlen=0; for(unsigned int i=0; igetFontSizeAdd()); + if(menuitems[i]->hasValue()) { + cvlen = std::max(cvlen, fontengine.getTextWidthbyInt(menuitems[i]->getMaxValueLen())); + vlen = std::max(vlen, fontengine.getTextWidthbyInt(menuitems[i]->getMaxValueLen())+fontengine.getTextWidth(menuitems[i]->getCaption())); + } else { + clen = std::max(clen, fontengine.getTextWidth(menuitems[i]->getCaption())); + } - clen = std::max(clen, fontengine.getTextWidth(menuitems[i]->getCaption())); - vlen = std::max(vlen, fontengine.getTextWidth(menuitems[i]->getValue())); height += basefontsize + menuitems[i]->getFontSizeAdd() + offset; } fullvalwidth = clen + vlen + valuewidth; + vlen += valuewidth; + maxlen = std::max(clen, vlen); if(paintbackground&&true) { // geht noch nicht ganz @@ -136,7 +142,7 @@ void MenuMenu::render() { } for(unsigned int i=0; irender(pos, centermenu, basefontsize, maxwidth, valuewidth, ((unsigned int)itempos==i)&&dohighlight, clen, vlen); + menuitems[i]->render(pos, centermenu, basefontsize, maxwidth, valuewidth, ((unsigned int)itempos==i)&&dohighlight, clen, cvlen, maxlen); pos.y += basefontsize + menuitems[i]->getFontSizeAdd() + offset; } }