miz
Thought something like this would be good to be built into urho until then you can use this
only thing is you lose some sharpness for not whole number values of scale but I guess that’s unavoidable
If you enter a Window and set recursive to true and set the scale to size of screen / size of screen it was designed for - it works really nicely
void ScaleUIElement(UIElement * uiElement, float scale, bool recursive)
{
IntVector2 Size = uiElement->GetSize();
Size = IntVector2(Size.x_ * scale, Size.y_ * scale);
uiElement->SetSize(Size);
IntVector2 Position = uiElement->GetPosition();
Position = IntVector2(Position.x_* scale, Position.y_ * scale);
uiElement->SetPosition(Position);
if (dynamic_cast<TextEdit*>(uiElement) != NULL)
{
int fontSize = (dynamic_cast<TextEdit*>(uiElement))->GetFontSize();
dynamic_cast<TextEdit*>(uiElement)->SetFontSize(fontSize * scale);
}
if (dynamic_cast<Text*>(uiElement) != NULL)
{
int fontSize = (dynamic_cast<Text*>(uiElement))->GetFontSize();
Font *font = (dynamic_cast<Text*>(uiElement))->GetFont();
dynamic_cast<Text*>(uiElement)->SetFont(font, fontSize * scale);
}
if (dynamic_cast<Sprite*>(uiElement) != NULL)
{
IntVector2 hotspot = (dynamic_cast<Sprite*>(uiElement))->GetHotSpot();
hotspot = IntVector2(hotspot.x_ * scale, hotspot.y_ * scale);
dynamic_cast<Sprite*>(uiElement)->SetHotSpot(hotspot);
}
if (recursive)
{
Vector<SharedPtr<UIElement> > allChildren = uiElement->GetChildren();
for (int i = 0; i < allChildren.Size(); i++)
{
ScaleUIElement(allChildren[i], scale, true);
}
}
}