Browse Source

update aus der schule

sebastian 12 years ago
parent
commit
f5b5ed31cd
7 changed files with 52 additions and 8 deletions
  1. 4
    0
      glfontengine.cpp
  2. 1
    0
      glfontengine.h
  3. 12
    3
      glmenu/menuitem.cpp
  4. 4
    1
      glmenu/menuitem.h
  5. 17
    0
      glmenu/menuitems.cpp
  6. 4
    0
      glmenu/menuitems.h
  7. 10
    4
      glmenu/menumenu.cpp

+ 4
- 0
glfontengine.cpp View File

@@ -241,4 +241,8 @@ int GLFontEngine::getTextWidth(const std::string &moep) {
241 241
 		return 1;
242 242
 }
243 243
 
244
+int GLFontEngine::getTextWidthbyInt(int length) {
245
+	return (int)(font->charwidth*fsize);
246
+}
247
+
244 248
 std::map<std::string, GLFont*> GLFontEngine::fontpool;

+ 1
- 0
glfontengine.h View File

@@ -63,6 +63,7 @@ class GLFontEngine {
63 63
 		int getSize();
64 64
 		void getSDLRect(const std::string&, SDL_Rect*);
65 65
 		int getTextWidth(const std::string&);
66
+		int getTextWidthbyInt(int length);
66 67
 		
67 68
 };
68 69
 

+ 12
- 3
glmenu/menuitem.cpp View File

@@ -24,7 +24,11 @@ void MenuItem::setCaption(std::string str) {
24 24
 	caption = str;
25 25
 }
26 26
 
27
-void MenuItem::render(Punkt2D pos, bool center, int basefontsize, int maxwidth, int valuewidth, bool highlight, int caplen, int vallen) {
27
+int MenuItem::getMaxValueLen() {
28
+	return (int)value.length();
29
+}
30
+
31
+void MenuItem::render(Punkt2D pos, bool center, int basefontsize, int maxwidth, int valuewidth, bool highlight, int caplen, int capvallen, int maxlen) {
28 32
 	fontengine.setSize(basefontsize+fontsizeadd);
29 33
 	if(highlight)
30 34
 		fontengine.setColor(1.0f, 0.0f, 0.0f);
@@ -39,13 +43,14 @@ void MenuItem::render(Punkt2D pos, bool center, int basefontsize, int maxwidth,
39 43
 		// center und position ggf. überarbeiten..
40 44
 		
41 45
 		Punkt2D tmp = pos;
42
-		tmp.x = pos.x - (caplen+vallen+valuewidth)/2;
46
+// 		tmp.x = pos.x - (caplen+vallen+valuewidth)/2;
47
+		tmp.x = pos.x - maxlen/2;
43 48
 		
44 49
 // 		tmp.x = pos.x - valuewidth/2 - fontengine.getTextWidth(caption)/2;
45 50
 // 		tmp.x = pos.x - caplen - valuewidth/2;
46 51
 		fontengine.renderLine(caption, (int)tmp.x, (int)tmp.y, false);
47 52
 		
48
-		tmp.x += caplen+valuewidth;
53
+		tmp.x += capvallen+valuewidth;
49 54
 		fontengine.renderLine(value, (int)tmp.x, (int)tmp.y, false);
50 55
 	}
51 56
 }
@@ -54,6 +59,10 @@ bool MenuItem::isSelectable() {
54 59
 	return (!grey)&&selectable;
55 60
 }
56 61
 
62
+bool MenuItem::hasValue() {
63
+	return usevalue;
64
+}
65
+
57 66
 void MenuItem::setFontSizeAdd(int fsa) {
58 67
 	fontsizeadd = fsa;
59 68
 }

+ 4
- 1
glmenu/menuitem.h View File

@@ -31,13 +31,16 @@ class MenuItem {
31 31
 		virtual void select() { };
32 32
 		virtual void charInput(char c) { };
33 33
 		
34
+		virtual int getMaxValueLen();
35
+		
36
+		bool hasValue();
34 37
 		void setFontSizeAdd(int fsa);
35 38
 		int getFontSizeAdd();
36 39
 		bool isSelectable();
37 40
 		void greyItem(bool _grey);
38 41
 		void noValueCenter(bool _vc);
39 42
 		
40
-		virtual void render(Punkt2D pos, bool center, int basefontsize, int maxwidth, int valuewidth, bool highlight, int caplen, int vallen);
43
+		virtual void render(Punkt2D pos, bool center, int basefontsize, int maxwidth, int valuewidth, bool highlight, int caplen, int capvallen, int maxlen);
41 44
 };
42 45
 
43 46
 #endif

+ 17
- 0
glmenu/menuitems.cpp View File

@@ -63,6 +63,15 @@ void MIToggle::addToggle(std::string str) {
63 63
 	}
64 64
 }
65 65
 
66
+int MIToggle::getMaxValueLen() {
67
+	int ret=0;
68
+	for(unsigned int i=0; i<toggles.size(); i++) {
69
+		ret = std::max(ret, (int)toggles[i].length());
70
+	}
71
+	
72
+	return ret;
73
+}
74
+
66 75
 int MIToggle::getValueInt() {
67 76
 	return togglepos;
68 77
 }
@@ -115,6 +124,10 @@ void MIStringInput::setValue(std::string str) {
115 124
 	value = str;
116 125
 }
117 126
 
127
+int MIStringInput::getMaxValueLen() {
128
+	return maxlen;
129
+}
130
+
118 131
 std::string MIStringInput::getValue() {
119 132
 	return value;
120 133
 }
@@ -148,6 +161,10 @@ void MICheckBox::left() {
148 161
 	updateValue();
149 162
 }
150 163
 
164
+int MICheckBox::getMaxValueLen() {
165
+	return 3;
166
+}
167
+
151 168
 void MICheckBox::updateValue() {
152 169
 	value = state ? "An" : "Aus";
153 170
 }

+ 4
- 0
glmenu/menuitems.h View File

@@ -45,6 +45,8 @@ class MIToggle : public MenuItem {
45 45
 		
46 46
 		void addToggle(std::string);
47 47
 		
48
+		int getMaxValueLen();
49
+		
48 50
 		int getValueInt();
49 51
 		void setValueInt(int val);
50 52
 		std::string getValueString();
@@ -59,6 +61,7 @@ class MIStringInput : public MenuItem {
59 61
 		MIStringInput(std::string str, int _maxlen=0);
60 62
 		void charInput(char c);
61 63
 		void setValue(std::string str);
64
+		int getMaxValueLen();
62 65
 		std::string getValue();
63 66
 	
64 67
 };
@@ -72,6 +75,7 @@ class MICheckBox : public MenuItem {
72 75
 		MICheckBox(std::string str);
73 76
 		
74 77
 		bool isChecked();
78
+		int getMaxValueLen();
75 79
 		void setState(bool _state);
76 80
 		void select();
77 81
 		void right();

+ 10
- 4
glmenu/menumenu.cpp View File

@@ -94,15 +94,21 @@ void MenuMenu::render() {
94 94
 		pos.x = screen->w/2;
95 95
 	}
96 96
 	
97
-	int clen=0, vlen=0, height=0, fullvalwidth=0;
97
+	int clen=0, vlen=0, cvlen=0, height=0, fullvalwidth=0, maxlen=0;
98 98
 	for(unsigned int i=0; i<menuitems.size(); i++) {
99 99
 		fontengine.setSize(basefontsize+menuitems[i]->getFontSizeAdd());
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()));
103
+		} else {
104
+			clen = std::max(clen, fontengine.getTextWidth(menuitems[i]->getCaption()));
105
+		}
100 106
 		
101
-		clen = std::max(clen, fontengine.getTextWidth(menuitems[i]->getCaption()));
102
-		vlen = std::max(vlen, fontengine.getTextWidth(menuitems[i]->getValue()));
103 107
 		height += basefontsize + menuitems[i]->getFontSizeAdd() + offset;
104 108
 	}
105 109
 	fullvalwidth = clen + vlen + valuewidth;
110
+	vlen += valuewidth;
111
+	maxlen = std::max(clen, vlen);
106 112
 	
107 113
 	if(paintbackground&&true) {
108 114
 		// geht noch nicht ganz
@@ -136,7 +142,7 @@ void MenuMenu::render() {
136 142
 	}
137 143
 
138 144
 	for(unsigned int i=0; i<menuitems.size(); i++) {
139
-		menuitems[i]->render(pos, centermenu, basefontsize, maxwidth, valuewidth, ((unsigned int)itempos==i)&&dohighlight, clen, vlen);
145
+		menuitems[i]->render(pos, centermenu, basefontsize, maxwidth, valuewidth, ((unsigned int)itempos==i)&&dohighlight, clen, cvlen, maxlen);
140 146
 		pos.y += basefontsize + menuitems[i]->getFontSizeAdd() + offset;
141 147
 	}
142 148
 }

Loading…
Cancel
Save