#include "menumenu.h" MenuMenu::MenuMenu() { itempos = 0; centermenu = false; centerScreenX = false; dohighlight = true; paintbackground = true; basefontsize = 20; maxwidth = 0; valuewidth = 100; offset = 20; } void MenuMenu::setPos(const Punkt2D &p) { menupos = p; } void MenuMenu::setCenter(bool _c) { centermenu = _c; } void MenuMenu::setCenterScreenX(bool _c) { centerScreenX = _c; } void MenuMenu::setBaseFontSize(int _bfs) { if(_bfs>0) basefontsize = _bfs; } void MenuMenu::setMaxWidth(int _mw) { if(_mw>0) maxwidth = _mw; } void MenuMenu::setPaintBackground(bool _pbg) { paintbackground = _pbg; } void MenuMenu::addMenuItem(MenuItem* mi) { menuitems.push_back(mi); } void MenuMenu::up() { do { if(itempos==0) itempos = menuitems.size()-1; else itempos--; } while(!menuitems[itempos]->isSelectable()); } void MenuMenu::down() { do { if((unsigned int)itempos==menuitems.size()-1) itempos = 0; else itempos++; } while(!menuitems[itempos]->isSelectable()); } void MenuMenu::left() { menuitems[itempos]->left(); } void MenuMenu::right() { menuitems[itempos]->right(); } void MenuMenu::select() { menuitems[itempos]->select(); } void MenuMenu::charInput(char c) { menuitems[itempos]->charInput(c); } void MenuMenu::resetItemPos() { dohighlight = true; for(itempos = 0; (unsigned int)itemposisSelectable(); itempos++); if((unsigned int)itempos==menuitems.size()) { itempos = 0; dohighlight = false; } } void MenuMenu::render() { Punkt2D pos = menupos; pos.y += offset; if(centerScreenX) { SDL_Surface *screen = SDL_GetVideoSurface(); pos.x = screen->w/2; } int clen=0, vlen=0, height=0, fullvalwidth=0; for(unsigned int i=0; igetFontSizeAdd()); 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; if(paintbackground&&true) { // geht noch nicht ganz glDisable(GL_TEXTURE_2D); glEnable(GL_BLEND); glColor4f(0.0f, 0.0f, 0.0f, 0.5f); SDL_Rect bgarea = { 0, (int)pos.y, 0, height }; if(vlen>0&&fullvalwidth>=clen) { bgarea.x = (int)pos.x-fullvalwidth/2; bgarea.w = fullvalwidth; } else { bgarea.x = (int)pos.x-clen/2; bgarea.w = clen; } std::cout << "clen: " << clen << " fvw: " << fullvalwidth << std::endl; // SDL_Rect bgarea = { pos.x-(clen/2)-((vlen>0)?(valuewidth+vlen):0), // pos.y, // clen+((vlen>0)?vlen+valuewidth:0), // height }; // std::cout << bgarea.x << " " << bgarea.y << " " << bgarea.w << " " << bgarea.h << std::endl; bgarea.x -= offset; bgarea.y -= offset; bgarea.w += offset*2; bgarea.h += offset; GLFontEngine::paintSDLRect(bgarea); } for(unsigned int i=0; irender(pos, centermenu, basefontsize, maxwidth, valuewidth, ((unsigned int)itempos==i)&&dohighlight, clen, vlen); pos.y += basefontsize + menuitems[i]->getFontSizeAdd() + offset; } }