From 952d87e707354f6879f4cbd8356510c823d697cd Mon Sep 17 00:00:00 2001 From: seba Date: Mon, 31 Mar 2008 00:14:35 +0200 Subject: [PATCH] Menuupdates, geordnet --- Makefile | 23 +++++++++++++-------- glcolor.cpp | 1 + glfontengine.cpp | 2 +- glgui/Makefile | 5 +++-- glmenu/Makefile | 5 +++-- glmenu/menuitem.cpp | 13 ++++++------ glmenu/menuitems.cpp | 6 +++--- glmenu/menumenu.cpp | 48 +++++++++++++++++++++++++++++++------------- 8 files changed, 67 insertions(+), 36 deletions(-) diff --git a/Makefile b/Makefile index fa5622a..8352009 100755 --- a/Makefile +++ b/Makefile @@ -1,22 +1,26 @@ -COMPILER = g++ +CC = g++ +AR = ar OBJECTS = punkt3d.o punkt2d.o emath.o emath_opengl.o glcolor.o gldrawhelper.o glfontengine.o glrect.o gltexture.o matrix.o quaternion.o rotationsmatrix.o glsdlscreen.o sdlfuncs.o +OBJOPT = -Wall -c `sdl-config --cflags` SUBDIRS = glgui glmenu SUBDIROBJECTS = glgui/*.o glmenu/*.o VERSION = 0.0.1 LIBNAME = libsegl seglar: $(OBJECTS) subdirs + @echo OBJOPT $(OBJOPT) + @echo CC $(CC) rm -f $(LIBNAME).a - ar rcs $(LIBNAME).a $(OBJECTS) $(SUBDIROBJECTS) + $(AR) rcs $(LIBNAME).a $(OBJECTS) $(SUBDIROBJECTS) # ranlib $(LIBNAME).a segllib: $(OBJECTS) subdirs subdirs: - @for i in $(SUBDIRS); do $(MAKE) -C $$i; done + @for i in $(SUBDIRS); do $(MAKE) CC="$(CC)" OBJOPT="$(OBJOPT)" -C $$i; done %.o: %.cpp %.h - $(COMPILER) -c `sdl-config --cflags` $< + $(CC) $(OBJOPT) $< glgui/glgui.a: @@ -27,9 +31,12 @@ glmenu/glmenu.a: testprog: seglar testprog.o g++ `sdl-config --libs` -lSDL_image -lGL -lGLU testprog.o -o testprog $(LIBNAME).a - -clean: + +cleansubdirs: + @for i in $(SUBDIRS); do $(MAKE) clean -C $$i; done + +clean: cleansubdirs rm -f $(OBJECTS) - cd glgui; $(MAKE) clean - cd glmenu; $(MAKE) clean +# cd glgui; $(MAKE) clean +# cd glmenu; $(MAKE) clean @echo Done cleaning... \ No newline at end of file diff --git a/glcolor.cpp b/glcolor.cpp index e115eb7..c1c834d 100644 --- a/glcolor.cpp +++ b/glcolor.cpp @@ -19,6 +19,7 @@ void GLColor::set(float _r, float _g, float _b, float _a) { SDL_Color GLColor::getSDLColor() { SDL_Color c = {(Uint8)(r*255.0f), (Uint8)(g*255), (Uint8)(b*255), (Uint8)(a*255)}; + return c; } void glColorGLC(GLColor c) { diff --git a/glfontengine.cpp b/glfontengine.cpp index f1f7afb..4dee7ab 100644 --- a/glfontengine.cpp +++ b/glfontengine.cpp @@ -198,7 +198,7 @@ void GLFontEngine::renderLines(std::string str, int x, int y, bool center, SDL_R while(str!="") { - if((strlpos = str.find('\n'))!=std::string::npos) { + if( (unsigned int)(strlpos = str.find('\n')) != std::string::npos) { rstr = str.substr(0, strlpos); str = str.substr(strlpos+1); diff --git a/glgui/Makefile b/glgui/Makefile index e525db0..b4fc515 100755 --- a/glgui/Makefile +++ b/glgui/Makefile @@ -1,4 +1,5 @@ -COMPILER = g++ +CC = g++ +OBJOPT = -c `sdl-config --cflags` -Wall OBJECTS = button.o object.o textlabel.o window.o glguilib: $(OBJECTS) @@ -6,7 +7,7 @@ glguilib: $(OBJECTS) ar crus glgui.a $(OBJECTS) %.o: %.cpp %.h - $(COMPILER) -c `sdl-config --cflags` $< + $(CC) $(OBJOPT) $< clean: rm -f $(OBJECTS) diff --git a/glmenu/Makefile b/glmenu/Makefile index 50ab633..9f3cc6e 100755 --- a/glmenu/Makefile +++ b/glmenu/Makefile @@ -1,4 +1,5 @@ -COMPILER = g++ +CC = g++ +OBJOPT = -c `sdl-config --cflags` -Wall OBJECTS = menumanager.o menumenu.o menuitem.o menuitems.o glguilib: $(OBJECTS) @@ -6,7 +7,7 @@ glguilib: $(OBJECTS) ar crus glmenu.a $(OBJECTS) %.o: %.cpp %.h - $(COMPILER) -c `sdl-config --cflags` $< + $(CC) $(OBJOPT) $< clean: rm -f $(OBJECTS) diff --git a/glmenu/menuitem.cpp b/glmenu/menuitem.cpp index e61b173..7de3ca8 100644 --- a/glmenu/menuitem.cpp +++ b/glmenu/menuitem.cpp @@ -34,18 +34,19 @@ void MenuItem::render(Punkt2D pos, bool center, int basefontsize, int maxwidth, fontengine.setColor(1.0f, 1.0f, 1.0f); if(!usevalue) { - fontengine.renderLine(caption, pos.x, pos.y, center); + fontengine.renderLine(caption, (int)pos.x, (int)pos.y, center); } else { // center und position ggf. überarbeiten.. Punkt2D tmp = pos; + tmp.x = pos.x - (caplen+vallen+valuewidth)/2; - tmp.x = pos.x - valuewidth/2 - fontengine.getTextWidth(caption)/2; - fontengine.renderLine(caption, tmp.x, tmp.y, center); +// 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 = pos.x + valuewidth/2; - fontengine.renderLine(value, tmp.x, tmp.y, false); -// std::cout << "Value: " << value << std::endl; + tmp.x += caplen+valuewidth; + fontengine.renderLine(value, (int)tmp.x, (int)tmp.y, false); } } diff --git a/glmenu/menuitems.cpp b/glmenu/menuitems.cpp index d23d136..21b6159 100644 --- a/glmenu/menuitems.cpp +++ b/glmenu/menuitems.cpp @@ -47,7 +47,7 @@ void MIToggle::left() { void MIToggle::right() { togglepos++; - if(togglepos>=toggles.size()) + if((unsigned int)togglepos>=toggles.size()) togglepos = 0; value = getValueString(); } @@ -68,7 +68,7 @@ int MIToggle::getValueInt() { } void MIToggle::setValueInt(int val) { - if(val<0||val>=toggles.size()) + if(val<0||(unsigned int)val>=toggles.size()) return; togglepos = val; value = getValueString(); @@ -105,7 +105,7 @@ void MIStringInput::charInput(char c) { value = value.substr(0, value.length()-1); } } else if(c>=32) { - if(!maxlen || value.length()isSelectable(); itempos++); - if(itempos==menuitems.size()) { + for(itempos = 0; (unsigned int)itemposisSelectable(); itempos++); + + if((unsigned int)itempos==menuitems.size()) { itempos = 0; dohighlight = false; } @@ -87,12 +88,13 @@ void MenuMenu::resetItemPos() { 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; + int clen=0, vlen=0, height=0, fullvalwidth=0; for(unsigned int i=0; igetFontSizeAdd()); @@ -100,23 +102,41 @@ void MenuMenu::render() { vlen = std::max(vlen, fontengine.getTextWidth(menuitems[i]->getValue())); height += basefontsize + menuitems[i]->getFontSizeAdd() + offset; } + fullvalwidth = clen + vlen + valuewidth; - std::cout << "clen: " << clen << " und " << (int) paintbackground << std::endl; - - if(paintbackground&&false) { + if(paintbackground&&true) { // geht noch nicht ganz glDisable(GL_TEXTURE_2D); - glColor3f(0.4f, 0.4f, 0.4f); - SDL_Rect bgarea = { pos.x-(clen/2)-((vlen>0)?(valuewidth/2+vlen/2):0), - pos.y, - clen+((vlen>0)?vlen/2+valuewidth/2:0), - height }; - std::cout << bgarea.x << " " << bgarea.y << " " << bgarea.w << " " << bgarea.h << std::endl; + 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, (itempos==i)&&dohighlight, clen, vlen); + menuitems[i]->render(pos, centermenu, basefontsize, maxwidth, valuewidth, ((unsigned int)itempos==i)&&dohighlight, clen, vlen); pos.y += basefontsize + menuitems[i]->getFontSizeAdd() + offset; } }