summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrey Nazarov <skuller@skuller.net>2013-10-20 20:15:22 +0400
committerAndrey Nazarov <skuller@skuller.net>2013-10-20 20:15:22 +0400
commitc9129395e9b4fc76ff501dabacbea5d088d2dfcc (patch)
tree96bc676e0dc65a90d480d2f03dfb2baf375d188b
parent35a992e557d09c58d6cd21c2650e3798f5a6e885 (diff)
Implement automatic screen scaling.
Automatically scale 1x, 2x or 4x when ‘(con|scr|ui)_scale’ variables are set to 0, depending on current display resolution.
-rw-r--r--doc/client.txt10
-rw-r--r--inc/refresh/refresh.h4
-rw-r--r--src/client/client.h1
-rw-r--r--src/client/console.c25
-rw-r--r--src/client/screen.c33
-rw-r--r--src/client/ui/playerconfig.c2
-rw-r--r--src/client/ui/q2pro.menu6
-rw-r--r--src/client/ui/ui.c12
-rw-r--r--src/refresh/gl/draw.c27
-rw-r--r--src/refresh/sw/draw.c11
10 files changed, 80 insertions, 51 deletions
diff --git a/doc/client.txt b/doc/client.txt
index ea76441..f1f13cd 100644
--- a/doc/client.txt
+++ b/doc/client.txt
@@ -290,7 +290,8 @@ con_alpha::
con_scale::
Scaling factor of the console text. Takes effect in OpenGL mode only.
- Default value is 1.
+ Default value is 1. Automatically scales depending on current display
+ resolution when set to 0.
con_font::
Font used for drawing console text. Default value is "conchars".
@@ -362,7 +363,8 @@ scr_showpause::
scr_scale::
Scaling factor of the HUD elements. Takes effect in OpenGL mode only.
- Default value is 1.
+ Default value is 1. Automatically scales depending on current display
+ resolution when set to 0.
scr_alpha::
Opacity of the HUD elements. 0 is fully transparent, 1 is opaque. Default
@@ -944,7 +946,9 @@ ui_background::
just fills the screen with solid black color.
ui_scale::
- Scaling factor of the UI widgets. Takes effect in OpenGL mode only. Default value is 1.
+ Scaling factor of the UI widgets. Takes effect in OpenGL mode only. Default
+ value is 1. Automatically scales depending on current display resolution
+ when set to 0.
ui_sortdemos::
Specifies default sorting order of entries in demo browser. Default value
diff --git a/inc/refresh/refresh.h b/inc/refresh/refresh.h
index a80329f..f4422d3 100644
--- a/inc/refresh/refresh.h
+++ b/inc/refresh/refresh.h
@@ -19,6 +19,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#ifndef REFRESH_H
#define REFRESH_H
+#include "common/cvar.h"
#include "common/error.h"
#define MAX_DLIGHTS 32
@@ -210,7 +211,8 @@ void R_ClearColor(void);
void R_SetAlpha(float clpha);
void R_SetColor(uint32_t color);
void R_SetClipRect(const clipRect_t *clip);
-void R_SetScale(float *scale);
+float R_ClampScale(cvar_t *var);
+void R_SetScale(float scale);
void R_DrawChar(int x, int y, int flags, int ch, qhandle_t font);
int R_DrawString(int x, int y, int flags, size_t maxChars,
const char *string, qhandle_t font); // returns advanced x coord
diff --git a/src/client/client.h b/src/client/client.h
index e4e66ac..8b70259 100644
--- a/src/client/client.h
+++ b/src/client/client.h
@@ -876,6 +876,7 @@ void Con_Close(qboolean force);
void Con_Popup(qboolean force);
void Con_SkipNotify(qboolean skip);
void Con_RegisterMedia(void);
+void Con_CheckResize(void);
void Key_Console(int key);
void Key_Message(int key);
diff --git a/src/client/console.c b/src/client/console.c
index 4cf59f8..cbaebf3 100644
--- a/src/client/console.c
+++ b/src/client/console.c
@@ -364,18 +364,17 @@ Con_CheckResize
If the line width has changed, reformat the buffer.
================
*/
-static void Con_CheckResize(void)
+void Con_CheckResize(void)
{
int width;
+ con.scale = R_ClampScale(con_scale);
+
con.vidWidth = r_config.width * con.scale;
con.vidHeight = r_config.height * con.scale;
width = (con.vidWidth / CHAR_WIDTH) - 2;
- if (width == con.linewidth)
- return;
-
con.linewidth = width > CON_LINEWIDTH ? CON_LINEWIDTH : width;
con.prompt.inputLine.visibleChars = con.linewidth;
con.prompt.widthInChars = con.linewidth - 1; // account for color byte
@@ -408,6 +407,13 @@ static void con_param_changed(cvar_t *self)
}
}
+static void con_scale_changed(cvar_t *self)
+{
+ if (con.initialized && cls.ref_initialized) {
+ Con_CheckResize();
+ }
+}
+
static const cmdreg_t c_console[] = {
{ "toggleconsole", Con_ToggleConsole_f },
{ "togglechat", Con_ToggleChat_f },
@@ -443,6 +449,7 @@ void Con_Init(void)
con_speed = Cvar_Get("scr_conspeed", "3", 0);
con_alpha = Cvar_Get("con_alpha", "1", 0);
con_scale = Cvar_Get("con_scale", "1", 0);
+ con_scale->changed = con_scale_changed;
con_font = Cvar_Get("con_font", "conchars", 0);
con_font->changed = con_param_changed;
con_background = Cvar_Get("con_background", "conback", 0);
@@ -1024,16 +1031,10 @@ SCR_DrawConsole
*/
void Con_DrawConsole(void)
{
- Cvar_ClampValue(con_scale, 1, 9);
-
- con.scale = 1.0f / con_scale->value;
- R_SetScale(&con.scale);
-
- Con_CheckResize();
+ R_SetScale(con.scale);
Con_DrawSolidConsole();
Con_DrawNotify();
-
- R_SetScale(NULL);
+ R_SetScale(1.0f);
}
diff --git a/src/client/screen.c b/src/client/screen.c
index 906d684..7579d17 100644
--- a/src/client/screen.c
+++ b/src/client/screen.c
@@ -46,6 +46,7 @@ static struct {
qhandle_t font_pic;
int hud_width, hud_height;
+ float hud_scale;
} scr;
static cvar_t *scr_viewsize;
@@ -1257,10 +1258,13 @@ void SCR_SetCrosshairColor(void)
void SCR_ModeChanged(void)
{
IN_Activate();
+ Con_CheckResize();
UI_ModeChanged();
// video sync flag may have changed
CL_UpdateFrameTimes();
cls.disable_screen = 0;
+ if (scr.initialized)
+ scr.hud_scale = R_ClampScale(scr_scale);
}
/*
@@ -1298,6 +1302,11 @@ static void scr_font_changed(cvar_t *self)
scr.font_pic = R_RegisterFont(self->string);
}
+static void scr_scale_changed(cvar_t *self)
+{
+ scr.hud_scale = R_ClampScale(self);
+}
+
static const cmdreg_t scr_cmds[] = {
{ "timerefresh", SCR_TimeRefresh_f },
{ "sizeup", SCR_SizeUp_f },
@@ -1331,6 +1340,7 @@ void SCR_Init(void)
scr_font = Cvar_Get("scr_font", "conchars", 0);
scr_font->changed = scr_font_changed;
scr_scale = Cvar_Get("scr_scale", "1", 0);
+ scr_scale->changed = scr_scale_changed;
scr_crosshair = Cvar_Get("crosshair", "0", CVAR_ARCHIVE);
scr_crosshair->changed = scr_crosshair_changed;
@@ -1371,6 +1381,8 @@ void SCR_Init(void)
Cmd_Register(scr_cmds);
+ scr_scale_changed(scr_scale);
+
scr.initialized = qtrue;
}
@@ -1946,7 +1958,6 @@ static void SCR_DrawPause(void)
static void SCR_DrawLoading(void)
{
- float scale;
int x, y;
if (!scr.draw_loading)
@@ -1954,15 +1965,14 @@ static void SCR_DrawLoading(void)
scr.draw_loading = qfalse;
- scale = 1.0f / Cvar_ClampValue(scr_scale, 1, 9);
- R_SetScale(&scale);
+ R_SetScale(scr.hud_scale);
- x = (r_config.width * scale - scr.loading_width) / 2;
- y = (r_config.height * scale - scr.loading_height) / 2;
+ x = (r_config.width * scr.hud_scale - scr.loading_width) / 2;
+ y = (r_config.height * scr.hud_scale - scr.loading_height) / 2;
R_DrawPic(x, y, scr.loading_pic);
- R_SetScale(NULL);
+ R_SetScale(1.0f);
}
static void SCR_DrawCrosshair(void)
@@ -2010,19 +2020,16 @@ draw:
static void SCR_Draw2D(void)
{
- float scale;
-
if (scr_draw2d->integer <= 0)
return; // turn off for screenshots
if (cls.key_dest & KEY_MENU)
return;
- scale = 1.0f / Cvar_ClampValue(scr_scale, 1, 9);
- R_SetScale(&scale);
+ R_SetScale(scr.hud_scale);
- scr.hud_height *= scale;
- scr.hud_width *= scale;
+ scr.hud_height *= scr.hud_scale;
+ scr.hud_width *= scr.hud_scale;
// crosshair has its own color and alpha
SCR_DrawCrosshair();
@@ -2057,7 +2064,7 @@ static void SCR_Draw2D(void)
SCR_DrawDebugPmove();
#endif
- R_SetScale(NULL);
+ R_SetScale(1.0f);
}
static void SCR_DrawActive(void)
diff --git a/src/client/ui/playerconfig.c b/src/client/ui/playerconfig.c
index 280916a..72d5e88 100644
--- a/src/client/ui/playerconfig.c
+++ b/src/client/ui/playerconfig.c
@@ -130,7 +130,7 @@ static void Draw(menuFrameWork_t *self)
R_RenderFrame(&m_player.refdef);
- R_SetScale(&uis.scale);
+ R_SetScale(uis.scale);
}
static void Size(menuFrameWork_t *self)
diff --git a/src/client/ui/q2pro.menu b/src/client/ui/q2pro.menu
index 9296250..952fcde 100644
--- a/src/client/ui/q2pro.menu
+++ b/src/client/ui/q2pro.menu
@@ -148,9 +148,9 @@ begin screen
values "demo bar" scr_demobar no yes verbose
range "HUD opacity" scr_alpha 0 1
range "console opacity" con_alpha 0 1
- pairs "HUD scale" scr_scale 1x 1 2x 2 4x 4
- pairs "console scale" con_scale 1x 1 2x 2 4x 4
- pairs "menu scale" ui_scale 1x 1 2x 2 4x 4
+ pairs "HUD scale" scr_scale auto 0 1x 1 2x 2 4x 4
+ pairs "console scale" con_scale auto 0 1x 1 2x 2 4x 4
+ pairs "menu scale" ui_scale auto 0 1x 1 2x 2 4x 4
blank
action --align "crosshair setup..." pushmenu crosshair
end
diff --git a/src/client/ui/ui.c b/src/client/ui/ui.c
index b63f436..21cb836 100644
--- a/src/client/ui/ui.c
+++ b/src/client/ui/ui.c
@@ -98,15 +98,9 @@ static void UI_Resize(void)
{
int i;
-#if USE_REF == REF_SOFT
- uis.scale = 1;
- uis.width = r_config.width;
- uis.height = r_config.height;
-#else
- uis.scale = 1 / Cvar_ClampValue(ui_scale, 1, 9);
+ uis.scale = R_ClampScale(ui_scale);
uis.width = r_config.width * uis.scale;
uis.height = r_config.height * uis.scale;
-#endif
for (i = 0; i < uis.menuDepth; i++) {
Menu_Init(uis.layers[i]);
@@ -431,7 +425,7 @@ void UI_Draw(int realtime)
}
R_ClearColor();
- R_SetScale(&uis.scale);
+ R_SetScale(uis.scale);
if (1) {
// draw top menu
@@ -471,7 +465,7 @@ void UI_Draw(int realtime)
}
R_ClearColor();
- R_SetScale(NULL);
+ R_SetScale(1.0f);
}
void UI_StartSound(menuSound_t sound)
diff --git a/src/refresh/gl/draw.c b/src/refresh/gl/draw.c
index 60b233f..6beef7b 100644
--- a/src/refresh/gl/draw.c
+++ b/src/refresh/gl/draw.c
@@ -149,20 +149,35 @@ clear:
draw.scissor = qtrue;
}
-void R_SetScale(float *scale)
+float R_ClampScale(cvar_t *var)
{
- float f = scale ? *scale : 1;
+ if (!var)
+ return 1.0f;
- if (draw.scale == f) {
+ if (var->value)
+ return 1.0f / Cvar_ClampValue(var, 1.0f, 10.0f);
+
+ if (r_config.width * r_config.height >= 2560 * 1440)
+ return 0.25f;
+
+ if (r_config.width * r_config.height >= 1280 * 720)
+ return 0.5f;
+
+ return 1.0f;
+}
+
+void R_SetScale(float scale)
+{
+ if (draw.scale == scale) {
return;
}
GL_Flush2D();
- GL_Ortho(0, Q_rint(r_config.width * f),
- Q_rint(r_config.height * f), 0, -1, 1);
+ GL_Ortho(0, Q_rint(r_config.width * scale),
+ Q_rint(r_config.height * scale), 0, -1, 1);
- draw.scale = f;
+ draw.scale = scale;
}
void R_DrawStretchPic(int x, int y, int w, int h, qhandle_t pic)
diff --git a/src/refresh/sw/draw.c b/src/refresh/sw/draw.c
index f4faa84..2f2137f 100644
--- a/src/refresh/sw/draw.c
+++ b/src/refresh/sw/draw.c
@@ -94,11 +94,16 @@ typedef struct {
static drawStatic_t draw;
-void R_SetScale(float *scale)
+float R_ClampScale(cvar_t *var)
{
- if (scale) {
- *scale = 1;
+ if (var) {
+ Cvar_SetValue(var, 1.0f);
}
+ return 1.0f;
+}
+
+void R_SetScale(float scale)
+{
}
void R_InitDraw(void)