Browse Source

Hintergrund von Menus transparent

seba 13 years ago
parent
commit
ce3456fa98
3 changed files with 31 additions and 19 deletions
  1. 1
    1
      Makefile
  2. 3
    2
      glfontengine.cpp
  3. 27
    16
      glmenu/menumenu.cpp

+ 1
- 1
Makefile View File

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

+ 3
- 2
glfontengine.cpp View File

@@ -236,13 +236,14 @@ void GLFontEngine::getSDLRect(const std::string &str, SDL_Rect *r) {
236 236
 
237 237
 int GLFontEngine::getTextWidth(const std::string &moep) {
238 238
 	if(fontloaded)
239
-		return (int)(moep.length()*(font->charwidth*fsize));
239
+		return getTextWidthbyInt(moep.length());
240
+// 		return (int)(moep.length()*(font->charwidth*fsize));
240 241
 	else
241 242
 		return 1;
242 243
 }
243 244
 
244 245
 int GLFontEngine::getTextWidthbyInt(int length) {
245
-	return (int)(font->charwidth*fsize);
246
+	return (int)(length*font->charwidth*fsize);
246 247
 }
247 248
 
248 249
 std::map<std::string, GLFont*> GLFontEngine::fontpool;

+ 27
- 16
glmenu/menumenu.cpp View File

@@ -94,27 +94,32 @@ void MenuMenu::render() {
94 94
 		pos.x = screen->w/2;
95 95
 	}
96 96
 	
97
-	int clen=0, vlen=0, cvlen=0, height=0, fullvalwidth=0, maxlen=0;
97
+	int clen=0, vlen=0, cvlen=0, height=0, fullvalwidth=0, maxlen=0, extravalwidth=0;
98 98
 	for(unsigned int i=0; i<menuitems.size(); i++) {
99 99
 		fontengine.setSize(basefontsize+menuitems[i]->getFontSizeAdd());
100 100
 		if(menuitems[i]->hasValue()) {
101
-			cvlen = std::max(cvlen, fontengine.getTextWidthbyInt(menuitems[i]->getMaxValueLen()));
102
-			vlen = std::max(vlen, fontengine.getTextWidthbyInt(menuitems[i]->getMaxValueLen())+fontengine.getTextWidth(menuitems[i]->getCaption()));
101
+// 			cvlen = std::max(cvlen, fontengine.getTextWidthbyInt(menuitems[i]->getMaxValueLen()));
102
+			cvlen = std::max(cvlen, fontengine.getTextWidth(menuitems[i]->getCaption()));
103
+			vlen = std::max(vlen, fontengine.getTextWidthbyInt(menuitems[i]->getMaxValueLen()) + fontengine.getTextWidth(menuitems[i]->getCaption()) + valuewidth);
104
+			extravalwidth = std::max(extravalwidth, fontengine.getTextWidthbyInt(menuitems[i]->getMaxValueLen()));
105
+// 			if(menuitems[i]->getMaxValueLen()==9)
106
+// 				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;
103 107
 		} else {
104 108
 			clen = std::max(clen, fontengine.getTextWidth(menuitems[i]->getCaption()));
105 109
 		}
106
-		
110
+// 		std::cout << "moep" << extravalwidth << std::endl;
107 111
 		height += basefontsize + menuitems[i]->getFontSizeAdd() + offset;
108 112
 	}
109
-	fullvalwidth = clen + vlen + valuewidth;
110
-	vlen += valuewidth;
111
-	maxlen = std::max(clen, vlen);
113
+// 	fullvalwidth = clen + vlen + valuewidth;
114
+	maxlen = std::max(clen, cvlen+extravalwidth+(cvlen>0?valuewidth:0));
112 115
 	
113 116
 	if(paintbackground&&true) {
114 117
 		// geht noch nicht ganz
115 118
 		glDisable(GL_TEXTURE_2D);
119
+// 		glBlendFunc(GL_DST_COLOR, GL_SRC_ALPHA);
120
+		glBlendFunc(GL_ONE_MINUS_SRC_ALPHA, GL_SRC_ALPHA);
116 121
 		glEnable(GL_BLEND);
117
-		glColor4f(0.0f, 0.0f, 0.0f, 0.5f);
122
+		
118 123
 		
119 124
 		SDL_Rect bgarea = { 0, (int)pos.y, 0, height };
120 125
 		
@@ -125,20 +130,26 @@ void MenuMenu::render() {
125 130
 			bgarea.x = (int)pos.x-clen/2;
126 131
 			bgarea.w = clen;
127 132
 		}
133
+		bgarea.x = pos.x-maxlen/2;
134
+		bgarea.w = maxlen;
128 135
 		
129
-		std::cout << "clen: " << clen << " fvw: " << fullvalwidth << std::endl; 
136
+		//offset
137
+// 		bgarea.x += offset;
138
+// 		bgarea.y += offset;
139
+		bgarea.w += offset*2;
140
+		bgarea.h += offset;
130 141
 		
131
-// 		SDL_Rect bgarea = { pos.x-(clen/2)-((vlen>0)?(valuewidth+vlen):0),
132
-// 							pos.y,
133
-// 	    					clen+((vlen>0)?vlen+valuewidth:0),
134
-// 							height };
135
-// 		std::cout << bgarea.x << " " << bgarea.y << " " << bgarea.w << " " << bgarea.h << std::endl;
142
+		//Wenn schatten dann hier...
143
+// 		bgarea.x += offset;
144
+// 		bgarea.y += offset;
145
+		glColor4f(0.1f, 0.1f, 0.1f, 0.2f);
146
+		GLFontEngine::paintSDLRect(bgarea);
136 147
 		bgarea.x -= offset;
137 148
 		bgarea.y -= offset;
138
-		bgarea.w += offset*2;
139
-		bgarea.h += offset;
140 149
 
150
+		glColor4f(0.2f, 0.2f, 0.2f, 0.3f);
141 151
 		GLFontEngine::paintSDLRect(bgarea);
152
+		glDisable(GL_BLEND);
142 153
 	}
143 154
 
144 155
 	for(unsigned int i=0; i<menuitems.size(); i++) {

Loading…
Cancel
Save