update aus der schule

This commit is contained in:
sebastian 2008-03-31 13:00:13 +02:00
parent 952d87e707
commit f5b5ed31cd
7 changed files with 52 additions and 8 deletions

View File

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

View File

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

View File

@ -24,7 +24,11 @@ void MenuItem::setCaption(std::string str) {
caption = str;
}
void MenuItem::render(Punkt2D pos, bool center, int basefontsize, int maxwidth, int valuewidth, bool highlight, int caplen, int vallen) {
int MenuItem::getMaxValueLen() {
return (int)value.length();
}
void MenuItem::render(Punkt2D pos, bool center, int basefontsize, int maxwidth, int valuewidth, bool highlight, int caplen, int capvallen, int maxlen) {
fontengine.setSize(basefontsize+fontsizeadd);
if(highlight)
fontengine.setColor(1.0f, 0.0f, 0.0f);
@ -39,13 +43,14 @@ void MenuItem::render(Punkt2D pos, bool center, int basefontsize, int maxwidth,
// center und position ggf. überarbeiten..
Punkt2D tmp = pos;
tmp.x = pos.x - (caplen+vallen+valuewidth)/2;
// tmp.x = pos.x - (caplen+vallen+valuewidth)/2;
tmp.x = pos.x - maxlen/2;
// 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 += caplen+valuewidth;
tmp.x += capvallen+valuewidth;
fontengine.renderLine(value, (int)tmp.x, (int)tmp.y, false);
}
}
@ -54,6 +59,10 @@ bool MenuItem::isSelectable() {
return (!grey)&&selectable;
}
bool MenuItem::hasValue() {
return usevalue;
}
void MenuItem::setFontSizeAdd(int fsa) {
fontsizeadd = fsa;
}

View File

@ -31,13 +31,16 @@ class MenuItem {
virtual void select() { };
virtual void charInput(char c) { };
virtual int getMaxValueLen();
bool hasValue();
void setFontSizeAdd(int fsa);
int getFontSizeAdd();
bool isSelectable();
void greyItem(bool _grey);
void noValueCenter(bool _vc);
virtual void render(Punkt2D pos, bool center, int basefontsize, int maxwidth, int valuewidth, bool highlight, int caplen, int vallen);
virtual void render(Punkt2D pos, bool center, int basefontsize, int maxwidth, int valuewidth, bool highlight, int caplen, int capvallen, int maxlen);
};
#endif

View File

@ -63,6 +63,15 @@ void MIToggle::addToggle(std::string str) {
}
}
int MIToggle::getMaxValueLen() {
int ret=0;
for(unsigned int i=0; i<toggles.size(); i++) {
ret = std::max(ret, (int)toggles[i].length());
}
return ret;
}
int MIToggle::getValueInt() {
return togglepos;
}
@ -115,6 +124,10 @@ void MIStringInput::setValue(std::string str) {
value = str;
}
int MIStringInput::getMaxValueLen() {
return maxlen;
}
std::string MIStringInput::getValue() {
return value;
}
@ -148,6 +161,10 @@ void MICheckBox::left() {
updateValue();
}
int MICheckBox::getMaxValueLen() {
return 3;
}
void MICheckBox::updateValue() {
value = state ? "An" : "Aus";
}

View File

@ -45,6 +45,8 @@ class MIToggle : public MenuItem {
void addToggle(std::string);
int getMaxValueLen();
int getValueInt();
void setValueInt(int val);
std::string getValueString();
@ -59,6 +61,7 @@ class MIStringInput : public MenuItem {
MIStringInput(std::string str, int _maxlen=0);
void charInput(char c);
void setValue(std::string str);
int getMaxValueLen();
std::string getValue();
};
@ -72,6 +75,7 @@ class MICheckBox : public MenuItem {
MICheckBox(std::string str);
bool isChecked();
int getMaxValueLen();
void setState(bool _state);
void select();
void right();

View File

@ -94,15 +94,21 @@ void MenuMenu::render() {
pos.x = screen->w/2;
}
int clen=0, vlen=0, height=0, fullvalwidth=0;
int clen=0, vlen=0, cvlen=0, height=0, fullvalwidth=0, maxlen=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()));
} else {
clen = std::max(clen, fontengine.getTextWidth(menuitems[i]->getCaption()));
}
clen = std::max(clen, fontengine.getTextWidth(menuitems[i]->getCaption()));
vlen = std::max(vlen, fontengine.getTextWidth(menuitems[i]->getValue()));
height += basefontsize + menuitems[i]->getFontSizeAdd() + offset;
}
fullvalwidth = clen + vlen + valuewidth;
vlen += valuewidth;
maxlen = std::max(clen, vlen);
if(paintbackground&&true) {
// geht noch nicht ganz
@ -136,7 +142,7 @@ void MenuMenu::render() {
}
for(unsigned int i=0; i<menuitems.size(); i++) {
menuitems[i]->render(pos, centermenu, basefontsize, maxwidth, valuewidth, ((unsigned int)itempos==i)&&dohighlight, clen, vlen);
menuitems[i]->render(pos, centermenu, basefontsize, maxwidth, valuewidth, ((unsigned int)itempos==i)&&dohighlight, clen, cvlen, maxlen);
pos.y += basefontsize + menuitems[i]->getFontSizeAdd() + offset;
}
}