summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPiotr Dziwinski <piotrdz@gmail.com>2013-01-04 00:29:19 +0100
committerPiotr Dziwinski <piotrdz@gmail.com>2013-01-04 00:29:19 +0100
commitd1942e1216768d41bc747a79287962a76a3aeb75 (patch)
tree0ec2ebdb68f9fbfec5301142e7da78ad26585c7b /src
parent89a3f586a224328b430ba2483ce5c12b33709c6a (diff)
downloadcolobot-d1942e1216768d41bc747a79287962a76a3aeb75.tar.gz
colobot-d1942e1216768d41bc747a79287962a76a3aeb75.tar.bz2
colobot-d1942e1216768d41bc747a79287962a76a3aeb75.zip
Correct font scaling with resolution
Diffstat (limited to 'src')
-rw-r--r--src/app/app.cpp4
-rw-r--r--src/graphics/engine/engine.cpp2
-rw-r--r--src/graphics/engine/text.cpp10
-rw-r--r--src/math/intpoint.h6
4 files changed, 17 insertions, 5 deletions
diff --git a/src/app/app.cpp b/src/app/app.cpp
index 2155cf4..4c66e24 100644
--- a/src/app/app.cpp
+++ b/src/app/app.cpp
@@ -903,14 +903,14 @@ Event CApplication::ProcessSystemEvent()
{
event.type = EVENT_QUIT;
}
- /*else if (m_private->currentEvent.type == SDL_VIDEORESIZE)
+ else if (m_private->currentEvent.type == SDL_VIDEORESIZE)
{
Gfx::GLDeviceConfig newConfig = m_deviceConfig;
newConfig.size.x = m_private->currentEvent.resize.w;
newConfig.size.y = m_private->currentEvent.resize.h;
if (newConfig.size != m_deviceConfig.size)
ChangeVideoConfig(newConfig);
- }*/
+ }
else if ( (m_private->currentEvent.type == SDL_KEYDOWN) ||
(m_private->currentEvent.type == SDL_KEYUP) )
{
diff --git a/src/graphics/engine/engine.cpp b/src/graphics/engine/engine.cpp
index f7e300e..7c90a8d 100644
--- a/src/graphics/engine/engine.cpp
+++ b/src/graphics/engine/engine.cpp
@@ -281,6 +281,8 @@ void CEngine::Destroy()
void CEngine::ResetAfterDeviceChanged()
{
+ m_size = m_app->GetVideoConfig().size;;
+
m_text->FlushCache();
// TODO reload textures, reset device state, etc.
diff --git a/src/graphics/engine/text.cpp b/src/graphics/engine/text.cpp
index 101e01a..da1a290 100644
--- a/src/graphics/engine/text.cpp
+++ b/src/graphics/engine/text.cpp
@@ -46,7 +46,7 @@ struct CachedFont
};
-
+const Math::IntPoint REFERENCE_SIZE(800, 600);
CText::CText(CInstanceManager *iMan, CEngine* engine)
@@ -147,6 +147,10 @@ void CText::FlushCache()
f->cache.clear();
}
}
+
+ m_lastFontType = FONT_COLOBOT;
+ m_lastFontSize = 0;
+ m_lastCachedFont = nullptr;
}
void CText::DrawText(const std::string &text, std::map<unsigned int, FontMetaChar> &format,
@@ -723,8 +727,8 @@ void CText::DrawCharAndAdjustPos(UTF8Char ch, FontType font, float size, Math::P
CachedFont* CText::GetOrOpenFont(FontType font, float size)
{
- // TODO: sizing
- int pointSize = static_cast<int>(size);
+ Math::IntPoint windowSize = m_engine->GetWindowSize();
+ int pointSize = static_cast<int>(size * (windowSize.Length() / REFERENCE_SIZE.Length()));
if (m_lastCachedFont != nullptr)
{
diff --git a/src/math/intpoint.h b/src/math/intpoint.h
index ebd9c5e..010b0fb 100644
--- a/src/math/intpoint.h
+++ b/src/math/intpoint.h
@@ -21,6 +21,7 @@
#pragma once
+#include <cmath>
// Math module namespace
namespace Math {
@@ -49,6 +50,11 @@ struct IntPoint
{
return !operator==(p);
}
+
+ inline float Length() const
+ {
+ return sqrtf(x*x + y*y);
+ }
};