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; return 1;
} }
int GLFontEngine::getTextWidthbyInt(int length) {
return (int)(font->charwidth*fsize);
}
std::map<std::string, GLFont*> GLFontEngine::fontpool; std::map<std::string, GLFont*> GLFontEngine::fontpool;

View File

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

View File

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

View File

@ -31,13 +31,16 @@ class MenuItem {
virtual void select() { }; virtual void select() { };
virtual void charInput(char c) { }; virtual void charInput(char c) { };
virtual int getMaxValueLen();
bool hasValue();
void setFontSizeAdd(int fsa); void setFontSizeAdd(int fsa);
int getFontSizeAdd(); int getFontSizeAdd();
bool isSelectable(); bool isSelectable();
void greyItem(bool _grey); void greyItem(bool _grey);
void noValueCenter(bool _vc); 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 #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() { int MIToggle::getValueInt() {
return togglepos; return togglepos;
} }
@ -115,6 +124,10 @@ void MIStringInput::setValue(std::string str) {
value = str; value = str;
} }
int MIStringInput::getMaxValueLen() {
return maxlen;
}
std::string MIStringInput::getValue() { std::string MIStringInput::getValue() {
return value; return value;
} }
@ -148,6 +161,10 @@ void MICheckBox::left() {
updateValue(); updateValue();
} }
int MICheckBox::getMaxValueLen() {
return 3;
}
void MICheckBox::updateValue() { void MICheckBox::updateValue() {
value = state ? "An" : "Aus"; value = state ? "An" : "Aus";
} }

View File

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

View File

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