I'm currently trying to get the correct corresponding pixel ratio of my text label for placing within my root messenger window area.
(window)
------------------------------------------------
[Text2] => h2
[Text1] => h1
[Text0] => h0 -> first text inserted
...
-----------------------------------------------
This is what I'm trying to do currently:
Code: Select all
void InGameNetMsgSheet::AddMsg(const std::string& msg)
{
CEGUI::WindowManager& winManager = CEGUI::WindowManager::getSingleton();
CEGUI::Window* label = winManager.createWindow("TaharezLook/Label", "");
label->setText(msg);
label->setProperty("HorzFormatting", "WordWrapLeftAligned");
float hScale = (label->getRenderedString().getHorizontalExtent(sheetRoot) / sheetRoot->getPixelSize().d_height);
label->setArea(CEGUI::UDim(0.f, 0.f), CEGUI::UDim(.035f, 0.f), CEGUI::UDim(.2f, 0.f), CEGUI::UDim(hScale, 0.f));
label->setHorizontalAlignment(CEGUI::HorizontalAlignment::HA_LEFT);
sheetRoot->addChild(label);
msgs.push_front(MessageInfo(hScale, label));
// we need to displace the following messages
MessageInfo* prevMsg = &msgs.front();
for (auto it = std::next(msgs.begin(), 1); it != msgs.end(); ++it)
{
MessageInfo& msgInfo = *it;
msgInfo.msgLabel->setArea(CEGUI::UDim(0.f, 0.f), CEGUI::UDim(prevMsg->msgLabel->getArea().getPosition().d_y.d_scale + msgInfo.hScale, 0.f), CEGUI::UDim(.2f, 0.f), CEGUI::UDim(msgInfo.hScale, 0.f));
prevMsg = &msgInfo;
}
}
I'm using the label->getRenderedString().getHorizontalExtent(sheetRoot) function for trying to obtain the pixel size of my Label relative to the sheetRoot. Then I divide by the pixelSize.d_height of the sheetRoot to obtain a ratio between the two. Is there a step I'm missing to get this setup right? Right now it is displacing way too far down the screen instead of one after another. I found if I multiply the hScale by .1f I get close to the values I want, but it still isn't correct if the HorizontalExtents differ from line to line.