Hintergrund von Menus transparent

This commit is contained in:
seba 2008-03-31 18:48:58 +02:00
parent f5b5ed31cd
commit ce3456fa98
3 changed files with 33 additions and 21 deletions

View File

@ -17,7 +17,7 @@ seglar: $(OBJECTS) subdirs
segllib: $(OBJECTS) subdirs
subdirs:
@for i in $(SUBDIRS); do $(MAKE) CC="$(CC)" OBJOPT="$(OBJOPT)" -C $$i; done
@for i in $(SUBDIRS); do $(MAKE) CC="$(CC)" AR="$(AR)" OBJOPT="$(OBJOPT)" -C $$i; done
%.o: %.cpp %.h
$(CC) $(OBJOPT) $<

View File

@ -236,13 +236,14 @@ void GLFontEngine::getSDLRect(const std::string &str, SDL_Rect *r) {
int GLFontEngine::getTextWidth(const std::string &moep) {
if(fontloaded)
return (int)(moep.length()*(font->charwidth*fsize));
return getTextWidthbyInt(moep.length());
// return (int)(moep.length()*(font->charwidth*fsize));
else
return 1;
}
int GLFontEngine::getTextWidthbyInt(int length) {
return (int)(font->charwidth*fsize);
return (int)(length*font->charwidth*fsize);
}
std::map<std::string, GLFont*> GLFontEngine::fontpool;

View File

@ -94,27 +94,32 @@ void MenuMenu::render() {
pos.x = screen->w/2;
}
int clen=0, vlen=0, cvlen=0, height=0, fullvalwidth=0, maxlen=0;
int clen=0, vlen=0, cvlen=0, height=0, fullvalwidth=0, maxlen=0, extravalwidth=0;
for(unsigned int i=0; i<menuitems.size(); i++) {
fontengine.setSize(basefontsize+menuitems[i]->getFontSizeAdd());
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()));
// cvlen = std::max(cvlen, fontengine.getTextWidthbyInt(menuitems[i]->getMaxValueLen()));
cvlen = std::max(cvlen, fontengine.getTextWidth(menuitems[i]->getCaption()));
vlen = std::max(vlen, fontengine.getTextWidthbyInt(menuitems[i]->getMaxValueLen()) + fontengine.getTextWidth(menuitems[i]->getCaption()) + valuewidth);
extravalwidth = std::max(extravalwidth, fontengine.getTextWidthbyInt(menuitems[i]->getMaxValueLen()));
// if(menuitems[i]->getMaxValueLen()==9)
// std::cout << "Moep: " << menuitems[i]->getMaxValueLen() << " * " << fontengine.getTextWidthbyInt(1) << " + " << fontengine.getTextWidthbyInt(menuitems[i]->getMaxValueLen()) << " + " << valuewidth << " und das erg: " << fontengine.getTextWidthbyInt(menuitems[i]->getMaxValueLen()) + fontengine.getTextWidth(menuitems[i]->getCaption()) + valuewidth<< std::endl;
} else {
clen = std::max(clen, fontengine.getTextWidth(menuitems[i]->getCaption()));
}
// std::cout << "moep" << extravalwidth << std::endl;
height += basefontsize + menuitems[i]->getFontSizeAdd() + offset;
}
fullvalwidth = clen + vlen + valuewidth;
vlen += valuewidth;
maxlen = std::max(clen, vlen);
// fullvalwidth = clen + vlen + valuewidth;
maxlen = std::max(clen, cvlen+extravalwidth+(cvlen>0?valuewidth:0));
if(paintbackground&&true) {
// geht noch nicht ganz
glDisable(GL_TEXTURE_2D);
// glBlendFunc(GL_DST_COLOR, GL_SRC_ALPHA);
glBlendFunc(GL_ONE_MINUS_SRC_ALPHA, GL_SRC_ALPHA);
glEnable(GL_BLEND);
glColor4f(0.0f, 0.0f, 0.0f, 0.5f);
SDL_Rect bgarea = { 0, (int)pos.y, 0, height };
@ -125,20 +130,26 @@ void MenuMenu::render() {
bgarea.x = (int)pos.x-clen/2;
bgarea.w = clen;
}
bgarea.x = pos.x-maxlen/2;
bgarea.w = maxlen;
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;
//offset
// bgarea.x += offset;
// bgarea.y += offset;
bgarea.w += offset*2;
bgarea.h += offset;
//Wenn schatten dann hier...
// bgarea.x += offset;
// bgarea.y += offset;
glColor4f(0.1f, 0.1f, 0.1f, 0.2f);
GLFontEngine::paintSDLRect(bgarea);
bgarea.x -= offset;
bgarea.y -= offset;
glColor4f(0.2f, 0.2f, 0.2f, 0.3f);
GLFontEngine::paintSDLRect(bgarea);
glDisable(GL_BLEND);
}
for(unsigned int i=0; i<menuitems.size(); i++) {