From 61fab09ceb832bb689a233ce5000a7759dd422f1 Mon Sep 17 00:00:00 2001 From: sippeangelo Date: Mon, 2 Jun 2014 16:07:17 +0200 Subject: [PATCH] UI scaling properly --- src/GUI/Frame.h | 13 ++++++++++--- src/GUI/VehicleSelection.h | 19 ++++++++++++++----- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/src/GUI/Frame.h b/src/GUI/Frame.h index e40d73a..47d5146 100644 --- a/src/GUI/Frame.h +++ b/src/GUI/Frame.h @@ -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 m_Parent; typedef std::multimap> Children_t; // name -> frame diff --git a/src/GUI/VehicleSelection.h b/src/GUI/VehicleSelection.h index bc13c92..fa11ceb 100644 --- a/src/GUI/VehicleSelection.h +++ b/src/GUI/VehicleSelection.h @@ -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;