forked from 0ad/0ad
Add basic support for GUI scaling factor, to help with high-res displays (e.g. 4K monitors and 1080p tablets).
Use the config setting "gui.scale = 0.5" to make the GUI bigger. This was SVN commit r16223.
This commit is contained in:
parent
c976366590
commit
59503b9ae9
@ -309,6 +309,7 @@ move.right = "Ctrl+RightArrow" ; Move cursor to start of word to the right of
|
||||
|
||||
[gui]
|
||||
cursorblinkrate = 0.5 ; Cursor blink rate in seconds (0.0 to disable blinking)
|
||||
scale = 1.0 ; GUI scaling factor, for improved compatibility with 4K displays
|
||||
|
||||
[gui.session]
|
||||
attacknotificationmessage = true ; Show attack notification messages
|
||||
|
@ -24,10 +24,9 @@
|
||||
#include "graphics/ShaderProgram.h"
|
||||
#include "lib/ogl.h"
|
||||
#include "ps/CStrIntern.h"
|
||||
#include "ps/GameSetup/Config.h"
|
||||
#include "renderer/Renderer.h"
|
||||
|
||||
extern int g_xres, g_yres;
|
||||
|
||||
CTextRenderer::CTextRenderer(const CShaderProgramPtr& shader) :
|
||||
m_Shader(shader)
|
||||
{
|
||||
@ -38,12 +37,15 @@ CTextRenderer::CTextRenderer(const CShaderProgramPtr& shader) :
|
||||
|
||||
void CTextRenderer::ResetTransform()
|
||||
{
|
||||
float xres = g_xres * g_GuiScale;
|
||||
float yres = g_yres * g_GuiScale;
|
||||
|
||||
m_Transform.SetIdentity();
|
||||
m_Transform.Scale(1.0f, -1.f, 1.0f);
|
||||
m_Transform.Translate(0.0f, (float)g_yres, -1000.0f);
|
||||
m_Transform.Translate(0.0f, yres, -1000.0f);
|
||||
|
||||
CMatrix3D proj;
|
||||
proj.SetOrtho(0.f, (float)g_xres, 0.f, (float)g_yres, -1.f, 1000.f);
|
||||
proj.SetOrtho(0.f, xres, 0.f, yres, -1.f, 1000.f);
|
||||
m_Transform = proj * m_Transform;
|
||||
m_Dirty = true;
|
||||
}
|
||||
|
@ -89,7 +89,7 @@ InReaction CGUI::HandleEvent(const SDL_Event_* ev)
|
||||
// Yes the mouse position is stored as float to avoid
|
||||
// constant conversions when operating in a
|
||||
// float-based environment.
|
||||
m_MousePos = CPos((float)ev->ev.motion.x, (float)ev->ev.motion.y);
|
||||
m_MousePos = CPos((float)ev->ev.motion.x * g_GuiScale, (float)ev->ev.motion.y * g_GuiScale);
|
||||
|
||||
SGUIMessage msg(GUIM_MOUSE_MOTION);
|
||||
GUI<SGUIMessage>::RecurseObject(GUIRR_HIDDEN | GUIRR_GHOST, m_BaseObject,
|
||||
@ -116,7 +116,7 @@ InReaction CGUI::HandleEvent(const SDL_Event_* ev)
|
||||
CPos oldMousePos = m_MousePos;
|
||||
if (ev->ev.type == SDL_MOUSEBUTTONDOWN || ev->ev.type == SDL_MOUSEBUTTONUP)
|
||||
{
|
||||
m_MousePos = CPos((float)ev->ev.button.x, (float)ev->ev.button.y);
|
||||
m_MousePos = CPos((float)ev->ev.button.x * g_GuiScale, (float)ev->ev.button.y * g_GuiScale);
|
||||
}
|
||||
|
||||
// Only one object can be hovered
|
||||
@ -868,7 +868,11 @@ void CGUI::DrawText(SGUIText &Text, const CColor &DefaultColor,
|
||||
if (isClipped)
|
||||
{
|
||||
glEnable(GL_SCISSOR_TEST);
|
||||
glScissor(clipping.left, g_yres - clipping.bottom, clipping.GetWidth(), clipping.GetHeight());
|
||||
glScissor(
|
||||
clipping.left / g_GuiScale,
|
||||
g_yres - clipping.bottom / g_GuiScale,
|
||||
clipping.GetWidth() / g_GuiScale,
|
||||
clipping.GetHeight() / g_GuiScale);
|
||||
}
|
||||
|
||||
CTextRenderer textRenderer(tech->GetShader());
|
||||
|
@ -1218,7 +1218,11 @@ void CInput::Draw()
|
||||
if (cliparea != CRect())
|
||||
{
|
||||
glEnable(GL_SCISSOR_TEST);
|
||||
glScissor(cliparea.left, g_yres - cliparea.bottom, cliparea.GetWidth(), cliparea.GetHeight());
|
||||
glScissor(
|
||||
cliparea.left / g_GuiScale,
|
||||
g_yres - cliparea.bottom / g_GuiScale,
|
||||
cliparea.GetWidth() / g_GuiScale,
|
||||
cliparea.GetHeight() / g_GuiScale);
|
||||
}
|
||||
|
||||
// These are useful later.
|
||||
|
@ -270,13 +270,16 @@ bool __ParseString<CGUIList>(const CStrW& UNUSED(Value), CGUIList& UNUSED(Output
|
||||
|
||||
CMatrix3D GetDefaultGuiMatrix()
|
||||
{
|
||||
float xres = g_xres * g_GuiScale;
|
||||
float yres = g_yres * g_GuiScale;
|
||||
|
||||
CMatrix3D m;
|
||||
m.SetIdentity();
|
||||
m.Scale(1.0f, -1.f, 1.0f);
|
||||
m.Translate(0.0f, (float)g_yres, -1000.0f);
|
||||
m.Translate(0.0f, yres, -1000.0f);
|
||||
|
||||
CMatrix3D proj;
|
||||
proj.SetOrtho(0.f, (float)g_xres, 0.f, (float)g_yres, -1.f, 1000.f);
|
||||
proj.SetOrtho(0.f, xres, 0.f, yres, -1.f, 1000.f);
|
||||
m = proj * m;
|
||||
|
||||
return m;
|
||||
|
@ -28,8 +28,6 @@ IGUIObject
|
||||
|
||||
#include "ps/CLogger.h"
|
||||
|
||||
extern int g_xres, g_yres;
|
||||
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Implementation Macros
|
||||
@ -347,7 +345,7 @@ void IGUIObject::UpdateCachedSize()
|
||||
if (absolute == false && m_pParent && !IsRootObject())
|
||||
m_CachedActualSize = ca.GetClientArea(m_pParent->m_CachedActualSize);
|
||||
else
|
||||
m_CachedActualSize = ca.GetClientArea(CRect(0.f, 0.f, (float)g_xres, (float)g_yres));
|
||||
m_CachedActualSize = ca.GetClientArea(CRect(0.f, 0.f, g_xres * g_GuiScale, g_yres * g_GuiScale));
|
||||
|
||||
// In a few cases, GUI objects have to resize to fill the screen
|
||||
// but maintain a constant aspect ratio.
|
||||
|
@ -296,7 +296,11 @@ void CMiniMap::DrawViewRect(CMatrix3D transform)
|
||||
};
|
||||
|
||||
// Enable Scissoring to restrict the rectangle to only the minimap.
|
||||
glScissor((int)m_CachedActualSize.left, g_Renderer.GetHeight() - (int)m_CachedActualSize.bottom, (int)width, (int)height);
|
||||
glScissor(
|
||||
m_CachedActualSize.left / g_GuiScale,
|
||||
g_Renderer.GetHeight() - m_CachedActualSize.bottom / g_GuiScale,
|
||||
width / g_GuiScale,
|
||||
height / g_GuiScale);
|
||||
glEnable(GL_SCISSOR_TEST);
|
||||
glLineWidth(2.0f);
|
||||
|
||||
|
@ -84,7 +84,7 @@ void CConsole::SetSize(float X, float Y, float W, float H)
|
||||
void CConsole::UpdateScreenSize(int w, int h)
|
||||
{
|
||||
float height = h * 0.6f;
|
||||
SetSize(0, 0, (float)w, height);
|
||||
SetSize(0, 0, w * g_GuiScale, height * g_GuiScale);
|
||||
}
|
||||
|
||||
|
||||
|
@ -57,6 +57,7 @@ float g_Gamma = 1.0f;
|
||||
CStr g_RenderPath = "default";
|
||||
|
||||
int g_xres, g_yres;
|
||||
float g_GuiScale = 1.0f;
|
||||
bool g_VSync = false;
|
||||
|
||||
bool g_Quickstart = false;
|
||||
@ -104,6 +105,7 @@ static void LoadGlobals()
|
||||
CFG_GET_VAL("particles", g_Particles);
|
||||
CFG_GET_VAL("silhouettes", g_Silhouettes);
|
||||
CFG_GET_VAL("showsky", g_ShowSky);
|
||||
CFG_GET_VAL("gui.scale", g_GuiScale);
|
||||
|
||||
if (g_SoundManager)
|
||||
{
|
||||
|
@ -78,6 +78,7 @@ extern float g_Gamma;
|
||||
extern CStr g_RenderPath;
|
||||
|
||||
extern int g_xres, g_yres;
|
||||
extern float g_GuiScale;
|
||||
extern bool g_VSync;
|
||||
|
||||
extern bool g_Quickstart;
|
||||
|
Loading…
Reference in New Issue
Block a user