MCPcopy Create free account
hub / github.com/MayaPosch/NymphCast / updateGrid

Method updateGrid

src/server/gui/core/components/HelpComponent.cpp:54–101  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

52}
53
54void HelpComponent::updateGrid()
55{
56 if(!Settings::getInstance()->getBool("ShowHelpPrompts") || mPrompts.empty())
57 {
58 mGrid.reset();
59 return;
60 }
61
62 std::shared_ptr<Font>& font = mStyle.font;
63
64 mGrid = std::make_shared<ComponentGrid>(mWindow, Vector2i((int)mPrompts.size() * 4, 1));
65 // [icon] [spacer1] [text] [spacer2]
66
67 std::vector< std::shared_ptr<ImageComponent> > icons;
68 std::vector< std::shared_ptr<TextComponent> > labels;
69
70 float width = 0;
71 const float height = Math::round(font->getLetterHeight() * 1.25f);
72 for(auto it = mPrompts.cbegin(); it != mPrompts.cend(); it++)
73 {
74 auto icon = std::make_shared<ImageComponent>(mWindow);
75 icon->setImage(getIconTexture(it->first.c_str()));
76 icon->setColorShift(mStyle.iconColor);
77 icon->setResize(0, height);
78 icons.push_back(icon);
79
80 auto lbl = std::make_shared<TextComponent>(mWindow, Utils::String::toUpper(it->second), font, mStyle.textColor);
81 labels.push_back(lbl);
82
83 width += icon->getSize().x() + lbl->getSize().x() + ICON_TEXT_SPACING + ENTRY_SPACING;
84 }
85
86 mGrid->setSize(width, height);
87 for(unsigned int i = 0; i < icons.size(); i++)
88 {
89 const int col = i*4;
90 mGrid->setColWidthPerc(col, icons.at(i)->getSize().x() / width);
91 mGrid->setColWidthPerc(col + 1, ICON_TEXT_SPACING / width);
92 mGrid->setColWidthPerc(col + 2, labels.at(i)->getSize().x() / width);
93
94 mGrid->setEntry(icons.at(i), Vector2i(col, 0), false, false);
95 mGrid->setEntry(labels.at(i), Vector2i(col + 2, 0), false, false);
96 }
97
98 mGrid->setPosition(Vector3f(mStyle.position.x(), mStyle.position.y(), 0.0f));
99 //mGrid->setPosition(OFFSET_X, Renderer::getScreenHeight() - mGrid->getSize().y() - OFFSET_Y);
100 mGrid->setOrigin(mStyle.origin);
101}
102
103std::shared_ptr<TextureResource> HelpComponent::getIconTexture(const char* name)
104{

Callers

nothing calls this directly

Calls 15

roundFunction · 0.85
toUpperFunction · 0.85
getLetterHeightMethod · 0.80
c_strMethod · 0.80
push_backMethod · 0.80
setColWidthPercMethod · 0.80
setEntryMethod · 0.80
Vector2iClass · 0.50
Vector3fClass · 0.50
emptyMethod · 0.45
resetMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected