Browse Source

Menuupdates, geordnet

seba 12 years ago
parent
commit
952d87e707
8 changed files with 67 additions and 36 deletions
  1. 15
    8
      Makefile
  2. 1
    0
      glcolor.cpp
  3. 1
    1
      glfontengine.cpp
  4. 3
    2
      glgui/Makefile
  5. 3
    2
      glmenu/Makefile
  6. 7
    6
      glmenu/menuitem.cpp
  7. 3
    3
      glmenu/menuitems.cpp
  8. 34
    14
      glmenu/menumenu.cpp

+ 15
- 8
Makefile View File

@@ -1,22 +1,26 @@
1
-COMPILER = g++
1
+CC = g++
2
+AR = ar
2 3
 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
4
+OBJOPT = -Wall -c `sdl-config --cflags`
3 5
 SUBDIRS = glgui glmenu
4 6
 SUBDIROBJECTS = glgui/*.o glmenu/*.o
5 7
 VERSION = 0.0.1
6 8
 LIBNAME = libsegl
7 9
 
8 10
 seglar: $(OBJECTS) subdirs
11
+	@echo OBJOPT $(OBJOPT)
12
+	@echo CC $(CC)
9 13
 	rm -f $(LIBNAME).a
10
-	ar rcs $(LIBNAME).a $(OBJECTS) $(SUBDIROBJECTS)
14
+	$(AR) rcs $(LIBNAME).a $(OBJECTS) $(SUBDIROBJECTS)
11 15
 # 	ranlib $(LIBNAME).a
12 16
 
13 17
 segllib: $(OBJECTS) subdirs
14 18
 
15 19
 subdirs:
16
-	@for i in $(SUBDIRS); do $(MAKE) -C $$i; done
20
+	@for i in $(SUBDIRS); do $(MAKE) CC="$(CC)" OBJOPT="$(OBJOPT)" -C  $$i; done
17 21
 	
18 22
 %.o: %.cpp %.h
19
-	$(COMPILER) -c `sdl-config --cflags` $<
23
+	$(CC) $(OBJOPT) $<
20 24
 	
21 25
 	
22 26
 glgui/glgui.a:
@@ -27,9 +31,12 @@ glmenu/glmenu.a:
27 31
 	
28 32
 testprog: seglar testprog.o
29 33
 	g++ `sdl-config --libs` -lSDL_image -lGL -lGLU testprog.o -o testprog $(LIBNAME).a 
30
-	
31
-clean:
34
+
35
+cleansubdirs:
36
+	@for i in $(SUBDIRS); do $(MAKE) clean -C  $$i; done
37
+
38
+clean: cleansubdirs
32 39
 	rm -f $(OBJECTS)
33
-	cd glgui; $(MAKE) clean
34
-	cd glmenu; $(MAKE) clean
40
+# 	cd glgui; $(MAKE) clean
41
+# 	cd glmenu; $(MAKE) clean
35 42
 	@echo Done cleaning...

+ 1
- 0
glcolor.cpp View File

@@ -19,6 +19,7 @@ void GLColor::set(float _r, float _g, float _b, float _a) {
19 19
 
20 20
 SDL_Color GLColor::getSDLColor() {
21 21
 	SDL_Color c = {(Uint8)(r*255.0f), (Uint8)(g*255), (Uint8)(b*255), (Uint8)(a*255)};
22
+	return c;
22 23
 }
23 24
 
24 25
 void glColorGLC(GLColor c) {

+ 1
- 1
glfontengine.cpp View File

@@ -198,7 +198,7 @@ void GLFontEngine::renderLines(std::string str, int x, int y, bool center, SDL_R
198 198
 	
199 199
 	while(str!="") {
200 200
 		
201
-		if((strlpos = str.find('\n'))!=std::string::npos) {
201
+		if( (unsigned int)(strlpos = str.find('\n')) != std::string::npos) {
202 202
 			
203 203
 			rstr = str.substr(0, strlpos);
204 204
 			str = str.substr(strlpos+1);

+ 3
- 2
glgui/Makefile View File

@@ -1,4 +1,5 @@
1
-COMPILER = g++
1
+CC = g++
2
+OBJOPT = -c `sdl-config --cflags` -Wall
2 3
 OBJECTS = button.o object.o textlabel.o window.o
3 4
 
4 5
 glguilib: $(OBJECTS)
@@ -6,7 +7,7 @@ glguilib: $(OBJECTS)
6 7
 	ar crus glgui.a $(OBJECTS)
7 8
 
8 9
 %.o: %.cpp %.h
9
-	$(COMPILER) -c `sdl-config --cflags` $<
10
+	$(CC) $(OBJOPT) $<
10 11
 
11 12
 clean:
12 13
 	rm -f $(OBJECTS)

+ 3
- 2
glmenu/Makefile View File

@@ -1,4 +1,5 @@
1
-COMPILER = g++
1
+CC = g++
2
+OBJOPT = -c `sdl-config --cflags` -Wall
2 3
 OBJECTS = menumanager.o menumenu.o menuitem.o menuitems.o
3 4
 
4 5
 glguilib: $(OBJECTS)
@@ -6,7 +7,7 @@ glguilib: $(OBJECTS)
6 7
 	ar crus glmenu.a $(OBJECTS)
7 8
 
8 9
 %.o: %.cpp %.h
9
-	$(COMPILER) -c `sdl-config --cflags` $<
10
+	$(CC) $(OBJOPT) $<
10 11
 
11 12
 clean:
12 13
 	rm -f $(OBJECTS)

+ 7
- 6
glmenu/menuitem.cpp View File

@@ -34,18 +34,19 @@ void MenuItem::render(Punkt2D pos, bool center, int basefontsize, int maxwidth,
34 34
 		fontengine.setColor(1.0f, 1.0f, 1.0f);
35 35
 	
36 36
 	if(!usevalue) {
37
-		fontengine.renderLine(caption, pos.x, pos.y, center);
37
+		fontengine.renderLine(caption, (int)pos.x, (int)pos.y, center);
38 38
 	} else {
39 39
 		// center und position ggf. überarbeiten..
40 40
 		
41 41
 		Punkt2D tmp = pos;
42
+		tmp.x = pos.x - (caplen+vallen+valuewidth)/2;
42 43
 		
43
-		tmp.x = pos.x - valuewidth/2 - fontengine.getTextWidth(caption)/2;
44
-		fontengine.renderLine(caption, tmp.x, tmp.y, center);
44
+// 		tmp.x = pos.x - valuewidth/2 - fontengine.getTextWidth(caption)/2;
45
+// 		tmp.x = pos.x - caplen - valuewidth/2;
46
+		fontengine.renderLine(caption, (int)tmp.x, (int)tmp.y, false);
45 47
 		
46
-		tmp.x = pos.x + valuewidth/2;
47
-		fontengine.renderLine(value, tmp.x, tmp.y, false);
48
-// 		std::cout << "Value: " << value << std::endl;
48
+		tmp.x += caplen+valuewidth;
49
+		fontengine.renderLine(value, (int)tmp.x, (int)tmp.y, false);
49 50
 	}
50 51
 }
51 52
 

+ 3
- 3
glmenu/menuitems.cpp View File

@@ -47,7 +47,7 @@ void MIToggle::left() {
47 47
 
48 48
 void MIToggle::right() {
49 49
 	togglepos++;
50
-	if(togglepos>=toggles.size())
50
+	if((unsigned int)togglepos>=toggles.size())
51 51
 		togglepos = 0;
52 52
 	value = getValueString();
53 53
 }
@@ -68,7 +68,7 @@ int MIToggle::getValueInt() {
68 68
 }
69 69
 
70 70
 void MIToggle::setValueInt(int val) {
71
-	if(val<0||val>=toggles.size())
71
+	if(val<0||(unsigned int)val>=toggles.size())
72 72
 		return;
73 73
 	togglepos = val;
74 74
 	value = getValueString();
@@ -105,7 +105,7 @@ void MIStringInput::charInput(char c) {
105 105
 			value = value.substr(0, value.length()-1);
106 106
 		}
107 107
 	} else if(c>=32) {
108
-		if(!maxlen || value.length()<maxlen)
108
+		if(!maxlen || value.length()<(unsigned int)maxlen)
109 109
 			value +=c;
110 110
 // 		std::cout << maxlen << " && " << value.length() << " < " << maxlen << std::endl;
111 111
 	}

+ 34
- 14
glmenu/menumenu.cpp View File

@@ -53,7 +53,7 @@ void MenuMenu::up() {
53 53
 
54 54
 void MenuMenu::down() {
55 55
 	do {
56
-		if(itempos==menuitems.size()-1)
56
+		if((unsigned int)itempos==menuitems.size()-1)
57 57
 			itempos = 0;
58 58
 		else
59 59
 			itempos++;
@@ -78,8 +78,9 @@ void MenuMenu::charInput(char c) {
78 78
 
79 79
 void MenuMenu::resetItemPos() {
80 80
 	dohighlight = true;
81
-	for(itempos = 0; itempos<menuitems.size()&&!menuitems[itempos]->isSelectable(); itempos++);
82
-	if(itempos==menuitems.size()) {
81
+	for(itempos = 0; (unsigned int)itempos<menuitems.size()&&!menuitems[itempos]->isSelectable(); itempos++);
82
+	
83
+	if((unsigned int)itempos==menuitems.size()) {
83 84
 		itempos = 0;
84 85
 		dohighlight = false;
85 86
 	}
@@ -87,12 +88,13 @@ void MenuMenu::resetItemPos() {
87 88
 
88 89
 void MenuMenu::render() {
89 90
 	Punkt2D pos = menupos;
91
+	pos.y += offset;
90 92
 	if(centerScreenX) {
91 93
 		SDL_Surface *screen = SDL_GetVideoSurface();
92 94
 		pos.x = screen->w/2;
93 95
 	}
94 96
 	
95
-	int clen=0, vlen=0, height=0;
97
+	int clen=0, vlen=0, height=0, fullvalwidth=0;
96 98
 	for(unsigned int i=0; i<menuitems.size(); i++) {
97 99
 		fontengine.setSize(basefontsize+menuitems[i]->getFontSizeAdd());
98 100
 		
@@ -100,23 +102,41 @@ void MenuMenu::render() {
100 102
 		vlen = std::max(vlen, fontengine.getTextWidth(menuitems[i]->getValue()));
101 103
 		height += basefontsize + menuitems[i]->getFontSizeAdd() + offset;
102 104
 	}
105
+	fullvalwidth = clen + vlen + valuewidth;
103 106
 	
104
-	std::cout << "clen: " << clen << " und " << (int) paintbackground << std::endl;
105
-	
106
-	if(paintbackground&&false) {
107
+	if(paintbackground&&true) {
107 108
 		// geht noch nicht ganz
108 109
 		glDisable(GL_TEXTURE_2D);
109
-		glColor3f(0.4f, 0.4f, 0.4f);
110
-		SDL_Rect bgarea = { pos.x-(clen/2)-((vlen>0)?(valuewidth/2+vlen/2):0),
111
-							pos.y,
112
-	    					clen+((vlen>0)?vlen/2+valuewidth/2:0),
113
-							height };
114
-		std::cout << bgarea.x << " " << bgarea.y << " " << bgarea.w << " " << bgarea.h << std::endl;
110
+		glEnable(GL_BLEND);
111
+		glColor4f(0.0f, 0.0f, 0.0f, 0.5f);
112
+		
113
+		SDL_Rect bgarea = { 0, (int)pos.y, 0, height };
114
+		
115
+		if(vlen>0&&fullvalwidth>=clen) {
116
+			bgarea.x = (int)pos.x-fullvalwidth/2;
117
+			bgarea.w = fullvalwidth;
118
+		} else {
119
+			bgarea.x = (int)pos.x-clen/2;
120
+			bgarea.w = clen;
121
+		}
122
+		
123
+		std::cout << "clen: " << clen << " fvw: " << fullvalwidth << std::endl; 
124
+		
125
+// 		SDL_Rect bgarea = { pos.x-(clen/2)-((vlen>0)?(valuewidth+vlen):0),
126
+// 							pos.y,
127
+// 	    					clen+((vlen>0)?vlen+valuewidth:0),
128
+// 							height };
129
+// 		std::cout << bgarea.x << " " << bgarea.y << " " << bgarea.w << " " << bgarea.h << std::endl;
130
+		bgarea.x -= offset;
131
+		bgarea.y -= offset;
132
+		bgarea.w += offset*2;
133
+		bgarea.h += offset;
134
+
115 135
 		GLFontEngine::paintSDLRect(bgarea);
116 136
 	}
117 137
 
118 138
 	for(unsigned int i=0; i<menuitems.size(); i++) {
119
-		menuitems[i]->render(pos, centermenu, basefontsize, maxwidth, valuewidth, (itempos==i)&&dohighlight, clen, vlen);
139
+		menuitems[i]->render(pos, centermenu, basefontsize, maxwidth, valuewidth, ((unsigned int)itempos==i)&&dohighlight, clen, vlen);
120 140
 		pos.y += basefontsize + menuitems[i]->getFontSizeAdd() + offset;
121 141
 	}
122 142
 }

Loading…
Cancel
Save