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

Method resize

src/bzflag/HelpInstructionsMenu.cpp:38–81  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

36}
37
38void HelpInstructionsMenu::resize(int _width, int _height) {
39 HelpMenu::resize(_width, _height);
40 FontSizer fs = FontSizer(_width, _height);
41
42 // find good font size
43 FontManager& fm = FontManager::instance();
44 std::vector<HUDuiElement*>& listHUD = getElements();
45 const int count = (const int)listHUD.size();
46 const LocalFontFace* fontFace = listHUD[2]->getFontFace();
47
48 float fontSize = fs.getFontSize(fontFace->getFMFace(), "infoFontSize");
49
50#if 0 /* XXX FIXME XXX */
51 fontSize = _height; // guaranteed to be too big
52 const float workingWidth = _width - 2 * getLeftSide(_width, _height);
53
54 // find the longest localized string
55 float longestLength = 0;
56 std::string longestString = "";
57 std::vector<HUDuiElement*>& listHUD = getElements();
58 for (int i = 2; i < count; ++i) {
59 float thisLength = fm.getStringWidth(fontFace->getFMFace(), fontSize, ((HUDuiLabel*)listHUD[i])->getString());
60 if (thisLength > longestLength) {
61 longestLength = thisLength;
62 longestString = ((HUDuiLabel*)listHUD[i])->getString();
63 }
64 }
65
66 // make the longest fit perfectly in the working width, and use that font size
67 for (fontSize = ((float)_height / 5.0f); longestLength > workingWidth; --fontSize) {
68 longestLength = fm.getStringWidth(fontFace->getFMFace(), fontSize, longestString);
69 }
70#endif
71
72 // reposition instruction text
73 const float h = fm.getStringHeight(fontFace->getFMFace(), fontSize);
74 const float x = getLeftSide(_width, _height);
75 float y = listHUD[2]->getY();
76 for (int i = 2; i < count; ++i) {
77 listHUD[i]->setFontSize(fontSize);
78 listHUD[i]->setPosition(x, y);
79 y -= 1.0f * h;
80 }
81}
82
83// Local Variables: ***
84// mode: C++ ***

Callers

nothing calls this directly

Calls 12

FontSizerClass · 0.85
getFMFaceMethod · 0.80
getStringWidthMethod · 0.80
getStringHeightMethod · 0.80
resizeFunction · 0.50
sizeMethod · 0.45
getFontFaceMethod · 0.45
getFontSizeMethod · 0.45
getStringMethod · 0.45
getYMethod · 0.45
setFontSizeMethod · 0.45
setPositionMethod · 0.45

Tested by

no test coverage detected