MCPcopy Create free account
hub / github.com/BZFlag-Dev/bzflag / resize

Method resize

src/bzflag/TextOptionsMenu.cpp:196–250  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

194
195
196void TextOptionsMenu::resize(int _width, int _height) {
197 HUDDialog::resize(_width, _height);
198 FontSizer fs = FontSizer(_width, _height);
199
200 FontManager& fm = FontManager::instance();
201 const LocalFontFace* fontFace = MainMenu::getFontFace();
202
203 // use a big font for title, smaller font for the rest
204 fs.setMin(0, (int)(1.0 / BZDB.eval("headerFontSize") / 2.0));
205 const float titleFontSize = fs.getFontSize(fontFace->getFMFace(), "headerFontSize");
206
207 fs.setMin(0, 30);
208 const float fontSize = fs.getFontSize(fontFace->getFMFace(), "menuFontSize");
209
210 // reposition title
211 std::vector<HUDuiElement*>& listHUD = getElements();
212 HUDuiLabel* title = (HUDuiLabel*)listHUD[0];
213 title->setFontSize(titleFontSize);
214 const float titleWidth = fm.getStringWidth(fontFace->getFMFace(), titleFontSize, title->getString());
215 const float titleHeight = fm.getStringHeight(fontFace->getFMFace(), titleFontSize);
216 float x = 0.5f * ((float)_width - titleWidth);
217 float y = (float)_height - titleHeight;
218 title->setPosition(x, y);
219
220 // reposition options
221 x = 0.54f * (float)_width;
222 y -= 1.0f * titleHeight;
223 const float h = fm.getStringHeight(fontFace->getFMFace(), fontSize);
224 const int count = (const int)listHUD.size();
225 for (int i = 1; i < count; i++) {
226 listHUD[i]->setFontSize(fontSize);
227 listHUD[i]->setPosition(x, y);
228 y -= 1.0f * h;
229 }
230
231 // load current settings
232
233 int i = 1;
234 i++; // locale
235 i++; // font options
236 ((HUDuiList*)listHUD[i++])->setIndex(BZDB.evalInt("fontOutline"));
237 ((HUDuiList*)listHUD[i++])->setIndex(BZDB.evalInt("scoreFontSize") / fontStep);
238 ((HUDuiList*)listHUD[i++])->setIndex(BZDB.evalInt("consoleFontSize") / fontStep);
239 ((HUDuiList*)listHUD[i++])->setIndex(BZDB.isTrue("colorful") ? 1 : 0);
240
241 // underline color - find index of mode string in options
242 const std::vector<std::string> &opts = ((HUDuiList*)listHUD[i])->getList();
243 std::string uColor = BZDB.get("underlineColor");
244 ((HUDuiList*)listHUD[i++])->setIndex((int)(std::find(opts.begin(), opts.end(), uColor) -
245 opts.begin()));
246
247 ((HUDuiList*)listHUD[i++])->setIndex(BZDB.evalInt("killerhighlight"));
248 ((HUDuiList*)listHUD[i++])->setIndex(int(BZDB.eval("pulseRate") * 5.0f) - 1);
249 ((HUDuiList*)listHUD[i++])->setIndex(int(BZDB.eval("pulseDepth") * 10.0f) - 1);
250}
251
252
253void TextOptionsMenu::callback(HUDuiControl* w, void* data) {

Callers 1

callbackMethod · 0.45

Calls 15

FontSizerClass · 0.85
setMinMethod · 0.80
evalMethod · 0.80
getFMFaceMethod · 0.80
getStringWidthMethod · 0.80
getStringHeightMethod · 0.80
evalIntMethod · 0.80
isTrueMethod · 0.80
resizeFunction · 0.50
getFontSizeMethod · 0.45
setFontSizeMethod · 0.45
getStringMethod · 0.45

Tested by

no test coverage detected