UI scaling properly

This commit is contained in:
2014-06-02 16:07:17 +02:00
parent 72420d4248
commit 61fab09ceb
2 changed files with 24 additions and 8 deletions
+10 -3
View File
@@ -25,8 +25,8 @@ public:
Bottom
};
static const float BaseWidth = 1280.f;
static const float BaseHeight = 720.f;
static const int BaseWidth = 1280;
static const int BaseHeight = 720;
// Set up a base frame with an event broker
Frame(std::shared_ptr<::EventBroker> eventBroker, std::shared_ptr<::ResourceManager> resourceManager)
@@ -112,6 +112,14 @@ public:
return Top() + Height;
}
glm::vec2 Scale()
{
if (m_Parent)
return m_Parent->Scale();
else
return glm::vec2(Width, Height) / glm::vec2(BaseWidth, BaseHeight);
}
Rectangle AbsoluteRectangle()
{
int left = Left();
@@ -183,7 +191,6 @@ protected:
std::string m_Name;
int m_Layer;
bool m_Hidden;
glm::vec2 Scale;
std::shared_ptr<Frame> m_Parent;
typedef std::multimap<std::string, std::shared_ptr<Frame>> Children_t; // name -> frame
+14 -5
View File
@@ -15,11 +15,17 @@ namespace GUI
, m_World(world)
, m_PlayerID(playerID)
{
ResourceManager->Preload("Texture", "Textures/GUI/VehicleSelection/1.png");
ResourceManager->Preload("Texture", "Textures/GUI/VehicleSelection/2.png");
ResourceManager->Preload("Texture", "Textures/GUI/VehicleSelection/3.png");
ResourceManager->Preload("Texture", "Textures/GUI/VehicleSelection/4.png");
m_CurrentSelection = 0;
m_CurrentCoordinate = -m_SelectionCoordinates[0] + glm::vec2(Width / 2.f, Height / 2.f);
glm::vec2 scale = Scale();
m_CurrentCoordinate = -m_SelectionCoordinates[0] * scale + glm::vec2(Width / 2.f, Height / 2.f);
m_TargetCoordinate = m_CurrentCoordinate;
m_CurrentSize = m_SelectionSizes[0];
m_CurrentSize = m_SelectionSizes[0] * scale;
m_TargetSize = m_CurrentSize;
m_CurrentAlpha = 0.f;
@@ -46,17 +52,20 @@ namespace GUI
std::stringstream ss;
ss << "Textures/GUI/VehicleSelection/" << m_CurrentSelection + 1 << ".png";
m_Background->FadeToTexture(ss.str(), 1.f);
glm::vec2 coord = -m_SelectionCoordinates[m_CurrentSelection];
m_TargetCoordinate = coord + glm::vec2(Width / 2.f, Height / 2.f);
glm::vec2 scale = Scale();
glm::vec2 coord = -m_SelectionCoordinates[m_CurrentSelection];
m_TargetCoordinate = coord * scale + glm::vec2(Width / 2.f, Height / 2.f);
glm::vec2 size = m_SelectionSizes[m_CurrentSelection];
m_TargetSize = size;
m_TargetSize = size * scale;
return true;
}
void Update(double dt) override
{
glm::vec2 posDiff = m_TargetCoordinate - m_CurrentCoordinate;
m_CurrentCoordinate += posDiff * 2.f * (float)dt;