Merge pull request #105 from mackron/ui_scaling_fix

UI scaling fixes.
This commit is contained in:
Yamagi 2015-10-22 18:23:39 +02:00
commit 05dfaf0412
3 changed files with 77 additions and 100 deletions

View file

@ -253,6 +253,8 @@ SCR_DrawCenterString(void)
int x, y;
int remaining;
float scale;
const int char_unscaled_width = 8;
const int char_unscaled_height = 8;
/* the finale prints the characters one at a time */
remaining = 9999;
@ -282,10 +284,10 @@ SCR_DrawCenterString(void)
}
}
x = ((viddef.width - l * 8) / 2) / scale;
x = ((viddef.width / scale) - (l * char_unscaled_width)) / 2;
SCR_AddDirtyPoint(x, y);
for (j = 0; j < l; j++, x += 8)
for (j = 0; j < l; j++, x += char_unscaled_width)
{
Draw_CharScaled(x * scale, y * scale, start[j], scale);
@ -295,9 +297,9 @@ SCR_DrawCenterString(void)
}
}
SCR_AddDirtyPoint(x, y + 8);
SCR_AddDirtyPoint(x, y + char_unscaled_height);
y += 8;
y += char_unscaled_height;
while (*start && *start != '\n')
{

View file

@ -845,12 +845,13 @@ DrawKeyBindingFunc(void *self)
{
int keys[2];
menuaction_s *a = (menuaction_s *)self;
float scale = SCR_GetMenuScale();
M_FindKeysForCommand(bindnames[a->generic.localdata[0]][0], keys);
if (keys[0] == -1)
{
Menu_DrawString(a->generic.x + a->generic.parent->x + 16,
Menu_DrawString(a->generic.x + a->generic.parent->x + 16 * scale,
a->generic.y + a->generic.parent->y, "???");
}
else
@ -860,16 +861,16 @@ DrawKeyBindingFunc(void *self)
name = Key_KeynumToString(keys[0]);
Menu_DrawString(a->generic.x + a->generic.parent->x + 16,
Menu_DrawString(a->generic.x + a->generic.parent->x + 16 * scale,
a->generic.y + a->generic.parent->y, name);
x = strlen(name) * 8;
if (keys[1] != -1)
{
Menu_DrawString(a->generic.x + a->generic.parent->x + 24 + x,
Menu_DrawString(a->generic.x + a->generic.parent->x + 24 * scale + (x * scale),
a->generic.y + a->generic.parent->y, "or");
Menu_DrawString(a->generic.x + a->generic.parent->x + 48 + x,
Menu_DrawString(a->generic.x + a->generic.parent->x + 48 * scale + (x * scale),
a->generic.y + a->generic.parent->y,
Key_KeynumToString(keys[1]));
}
@ -2864,6 +2865,7 @@ StartServer_MenuInit(void)
int length;
int i;
FILE *fp;
float scale = SCR_GetMenuScale();
/* initialize list of maps once, reuse it afterwards (=> it isn't freed) */
if (mapnames == NULL)
@ -3038,7 +3040,7 @@ StartServer_MenuInit(void)
s_startserver_dmoptions_action.generic.type = MTYPE_ACTION;
s_startserver_dmoptions_action.generic.name = " deathmatch flags";
s_startserver_dmoptions_action.generic.flags = QMF_LEFT_JUSTIFY;
s_startserver_dmoptions_action.generic.x = 24;
s_startserver_dmoptions_action.generic.x = 24 * scale;
s_startserver_dmoptions_action.generic.y = 108;
s_startserver_dmoptions_action.generic.statusbar = NULL;
s_startserver_dmoptions_action.generic.callback = DMOptionsFunc;
@ -3046,7 +3048,7 @@ StartServer_MenuInit(void)
s_startserver_start_action.generic.type = MTYPE_ACTION;
s_startserver_start_action.generic.name = " begin";
s_startserver_start_action.generic.flags = QMF_LEFT_JUSTIFY;
s_startserver_start_action.generic.x = 24;
s_startserver_start_action.generic.x = 24 * scale;
s_startserver_start_action.generic.y = 128;
s_startserver_start_action.generic.callback = StartServerActionFunc;
@ -3555,13 +3557,14 @@ DownloadOptions_MenuInit(void)
"no", "yes", 0
};
int y = 0;
float scale = SCR_GetMenuScale();
s_downloadoptions_menu.x = (int)(viddef.width * 0.50f);
s_downloadoptions_menu.nitems = 0;
s_download_title.generic.type = MTYPE_SEPARATOR;
s_download_title.generic.name = "Download Options";
s_download_title.generic.x = 48;
s_download_title.generic.x = 48 * scale;
s_download_title.generic.y = y;
s_allow_download_box.generic.type = MTYPE_SPINCONTROL;
@ -3658,7 +3661,7 @@ AddressBook_MenuInit(void)
int i;
float scale = SCR_GetMenuScale();
s_addressbook_menu.x = viddef.width / 2 - 142;
s_addressbook_menu.x = viddef.width / scale / 2 - 142 / scale;
s_addressbook_menu.y = viddef.height / (2 * scale) - 58;
s_addressbook_menu.nitems = 0;
@ -4107,24 +4110,18 @@ PlayerConfig_MenuInit(void)
s_player_name_field.generic.callback = 0;
s_player_name_field.generic.x = 0;
s_player_name_field.generic.y = 0;
s_player_name_field.length = 20 * scale;
s_player_name_field.visible_length = 20 * scale;
s_player_name_field.length = 20;
s_player_name_field.visible_length = 20;
strcpy(s_player_name_field.buffer, name->string);
s_player_name_field.cursor = strlen(name->string);
s_player_model_title.generic.type = MTYPE_SEPARATOR;
s_player_model_title.generic.name = "model";
if (scale > 1)
s_player_model_title.generic.x = -8 * scale + (8 * scale);
else
s_player_model_title.generic.x = -8;
s_player_model_title.generic.x = -8 * scale;
s_player_model_title.generic.y = 60;
s_player_model_box.generic.type = MTYPE_SPINCONTROL;
if (scale > 1)
s_player_model_box.generic.x = -56 * scale + ((15 + scale) * scale);
else
s_player_model_box.generic.x = -56;
s_player_model_box.generic.x = -56 * scale;
s_player_model_box.generic.y = 70;
s_player_model_box.generic.callback = ModelCallback;
s_player_model_box.generic.cursor_offset = -48;
@ -4133,17 +4130,11 @@ PlayerConfig_MenuInit(void)
s_player_skin_title.generic.type = MTYPE_SEPARATOR;
s_player_skin_title.generic.name = "skin";
if (scale > 1)
s_player_skin_title.generic.x = -16 * scale + (8 * scale);
else
s_player_skin_title.generic.x = -16;
s_player_skin_title.generic.x = -16 * scale;
s_player_skin_title.generic.y = 84;
s_player_skin_box.generic.type = MTYPE_SPINCONTROL;
if (scale > 1)
s_player_skin_box.generic.x = -56 * scale + ((15 + scale) * scale);
else
s_player_skin_box.generic.x = -56;
s_player_skin_box.generic.x = -56 * scale;
s_player_skin_box.generic.y = 94;
s_player_skin_box.generic.name = 0;
s_player_skin_box.generic.callback = 0;
@ -4154,17 +4145,11 @@ PlayerConfig_MenuInit(void)
s_player_hand_title.generic.type = MTYPE_SEPARATOR;
s_player_hand_title.generic.name = "handedness";
if (scale > 1)
s_player_hand_title.generic.x = 32 * scale + (8 * scale);
else
s_player_hand_title.generic.x = 32;
s_player_hand_title.generic.x = 32 * scale;
s_player_hand_title.generic.y = 108;
s_player_handedness_box.generic.type = MTYPE_SPINCONTROL;
if (scale > 1)
s_player_handedness_box.generic.x = -56 * scale + ((15 + scale) * scale);
else
s_player_handedness_box.generic.x = -56;
s_player_handedness_box.generic.x = -56 * scale;
s_player_handedness_box.generic.y = 118;
s_player_handedness_box.generic.name = 0;
s_player_handedness_box.generic.cursor_offset = -48;
@ -4182,17 +4167,11 @@ PlayerConfig_MenuInit(void)
s_player_rate_title.generic.type = MTYPE_SEPARATOR;
s_player_rate_title.generic.name = "connect speed";
if (scale > 1)
s_player_rate_title.generic.x = 56 * scale + (8 * scale);
else
s_player_rate_title.generic.x = 56;
s_player_rate_title.generic.x = 56 * scale;
s_player_rate_title.generic.y = 156;
s_player_rate_box.generic.type = MTYPE_SPINCONTROL;
if (scale > 1)
s_player_rate_box.generic.x = -56 * scale + ((15 + scale) * scale);
else
s_player_rate_box.generic.x = -56;
s_player_rate_box.generic.x = -56 * scale;
s_player_rate_box.generic.y = 166;
s_player_rate_box.generic.name = 0;
s_player_rate_box.generic.cursor_offset = -48;
@ -4203,13 +4182,7 @@ PlayerConfig_MenuInit(void)
s_player_download_action.generic.type = MTYPE_ACTION;
s_player_download_action.generic.name = "download options";
s_player_download_action.generic.flags = QMF_LEFT_JUSTIFY;
if (scale > 1)
{
s_player_download_action.generic.x = -24 * scale;
s_player_download_action.generic.cursor_offset = 16 * scale;
}
else
s_player_download_action.generic.x = -24;
s_player_download_action.generic.x = -24 * scale;
s_player_download_action.generic.y = 186;
s_player_download_action.generic.statusbar = NULL;
s_player_download_action.generic.callback = DownloadOptionsFunc;
@ -4293,7 +4266,7 @@ PlayerConfig_MenuDraw(void)
M_DrawTextBox(((int)(refdef.x) * (320.0F / viddef.width) - 8),
(int)((viddef.height / 2) * (240.0F / viddef.height) - 77),
refdef.width / (8 * scale), refdef.height / (8 * scale));
refdef.height += 4;
refdef.height += 4 * scale;
R_RenderFrame(&refdef);
@ -4301,7 +4274,7 @@ PlayerConfig_MenuDraw(void)
s_pmi[s_player_model_box.curvalue].directory,
s_pmi[s_player_model_box.curvalue].skindisplaynames[
s_player_skin_box.curvalue]);
Draw_PicScaled(s_player_config_menu.x - 40, refdef.y, scratch, scale);
Draw_PicScaled(s_player_config_menu.x - 40*scale, refdef.y, scratch, scale);
}
}

View file

@ -59,19 +59,21 @@ Action_DoEnter(menuaction_s *a)
void
Action_Draw(menuaction_s *a)
{
float scale = SCR_GetMenuScale();
if (a->generic.flags & QMF_LEFT_JUSTIFY)
{
if (a->generic.flags & QMF_GRAYED)
{
Menu_DrawStringDark(a->generic.x + a->generic.parent->x +
LCOLUMN_OFFSET, a->generic.y + a->generic.parent->y,
Menu_DrawStringDark(a->generic.x + a->generic.parent->x + (LCOLUMN_OFFSET * scale),
a->generic.y + a->generic.parent->y,
a->generic.name);
}
else
{
Menu_DrawString(a->generic.x + a->generic.parent->x +
LCOLUMN_OFFSET, a->generic.y + a->generic.parent->y,
Menu_DrawString(a->generic.x + a->generic.parent->x + (LCOLUMN_OFFSET * scale),
a->generic.y + a->generic.parent->y,
a->generic.name);
}
}
@ -79,15 +81,15 @@ Action_Draw(menuaction_s *a)
{
if (a->generic.flags & QMF_GRAYED)
{
Menu_DrawStringR2LDark(a->generic.x + a->generic.parent->x +
LCOLUMN_OFFSET, a->generic.y + a->generic.parent->y,
Menu_DrawStringR2LDark(a->generic.x + a->generic.parent->x + (LCOLUMN_OFFSET * scale),
a->generic.y + a->generic.parent->y,
a->generic.name);
}
else
{
Menu_DrawStringR2L(a->generic.x + a->generic.parent->x +
LCOLUMN_OFFSET, a->generic.y + a->generic.parent->y,
Menu_DrawStringR2L(a->generic.x + a->generic.parent->x + (LCOLUMN_OFFSET * scale),
a->generic.y + a->generic.parent->y,
a->generic.name);
}
}
@ -120,7 +122,7 @@ Field_Draw(menufield_s *f)
if (f->generic.name)
{
Menu_DrawStringR2LDark(f->generic.x + f->generic.parent->x +
LCOLUMN_OFFSET, f->generic.y + f->generic.parent->y,
LCOLUMN_OFFSET * scale, f->generic.y + f->generic.parent->y,
f->generic.name);
}
@ -131,27 +133,25 @@ Field_Draw(menufield_s *f)
}
Q_strlcpy(tempbuffer, f->buffer + f->visible_offset, n);
Draw_CharScaled(f->generic.x + (f->generic.parent->x + 16),
Draw_CharScaled(f->generic.x + f->generic.parent->x + 16 * scale,
(f->generic.y + f->generic.parent->y - 4) * scale, 18, scale);
Draw_CharScaled(f->generic.x + f->generic.parent->x + 16,
Draw_CharScaled(f->generic.x + f->generic.parent->x + 16 * scale,
(f->generic.y + f->generic.parent->y + 4) * scale, 24, scale);
Draw_CharScaled(f->generic.x + f->generic.parent->x + 24 +
f->visible_length * 8, (f->generic.y +
f->generic.parent->y - 4) * scale, 20, scale);
Draw_CharScaled(f->generic.x + f->generic.parent->x + 24 +
f->visible_length * 8, (f->generic.y +
f->generic.parent->y + 4) * scale, 26, scale);
Draw_CharScaled((f->generic.x + f->generic.parent->x + 24 * scale) + (f->visible_length * 8 * scale),
(f->generic.y + f->generic.parent->y - 4) * scale, 20, scale);
Draw_CharScaled((f->generic.x + f->generic.parent->x + 24 * scale) + (f->visible_length * 8 * scale),
(f->generic.y + f->generic.parent->y + 4) * scale, 26, scale);
for (i = 0; i < f->visible_length; i++)
{
Draw_CharScaled(f->generic.x + f->generic.parent->x + 24 + i * 8,
Draw_CharScaled((f->generic.x + f->generic.parent->x + 24 * scale) + (i * 8 * scale),
(f->generic.y + f->generic.parent->y - 4) * scale, 19, scale);
Draw_CharScaled(f->generic.x + f->generic.parent->x + 24 + i * 8,
Draw_CharScaled((f->generic.x + f->generic.parent->x + 24 * scale) + (i * 8 * scale),
(f->generic.y + f->generic.parent->y + 4) * scale, 25, scale);
}
Menu_DrawString(f->generic.x + f->generic.parent->x + 24,
Menu_DrawString(f->generic.x + f->generic.parent->x + 24 * scale,
f->generic.y + f->generic.parent->y, tempbuffer);
if (Menu_ItemAtCursor(f->generic.parent) == f)
@ -170,15 +170,15 @@ Field_Draw(menufield_s *f)
if (((int)(Sys_Milliseconds() / 250)) & 1)
{
Draw_CharScaled(f->generic.x + f->generic.parent->x +
(offset * scale + 2) * 8 + 8, (f->generic.y +
f->generic.parent->y) * scale, 11, scale);
Draw_CharScaled(
f->generic.x + f->generic.parent->x + 24 * scale + (offset * 8 * scale),
(f->generic.y + f->generic.parent->y) * scale, 11, scale);
}
else
{
Draw_CharScaled(f->generic.x + f->generic.parent->x +
(offset * scale + 2) * 8 + 8 *scale, (f->generic.y +
f->generic.parent->y) * scale, ' ', scale);
Draw_CharScaled(
f->generic.x + f->generic.parent->x + 24 * scale + (offset * 8 * scale),
(f->generic.y + f->generic.parent->y) * scale, ' ', scale);
}
}
}
@ -392,7 +392,7 @@ Menu_Center(menuframework_s *menu)
height = ((menucommon_s *)menu->items[menu->nitems - 1])->y;
height += 10;
menu->y = (VID_HEIGHT - height) / (2 * scale);
menu->y = (VID_HEIGHT / scale - height) / 2;
}
void
@ -442,13 +442,14 @@ Menu_Draw(menuframework_s *menu)
{
if (item->flags & QMF_LEFT_JUSTIFY)
{
Draw_CharScaled(menu->x + (item->x - 24 + item->cursor_offset) * scale,
(menu->y + item->y) * scale, 12 + ((int)(Sys_Milliseconds() /
250) & 1), scale);
Draw_CharScaled(menu->x + (item->x / scale - 24 + item->cursor_offset) * scale,
(menu->y + item->y) * scale,
12 + ((int)(Sys_Milliseconds() / 250) & 1), scale);
}
else
{
Draw_CharScaled(menu->x + (item->cursor_offset) * scale, (menu->y + item->y) * scale,
Draw_CharScaled(menu->x + (item->cursor_offset) * scale,
(menu->y + item->y) * scale,
12 + ((int)(Sys_Milliseconds() / 250) & 1), scale);
}
}
@ -484,11 +485,10 @@ Menu_DrawStatusBar(const char *string)
if (string)
{
int l = (int)strlen(string);
int maxcol = VID_WIDTH / 8;
int col = maxcol / 2 - l / 2;
float col = (VID_WIDTH / 2) - (l*8 / 2) * scale;
Draw_Fill(0, VID_HEIGHT - 8 * scale, VID_WIDTH, 8 * scale, 4);
Menu_DrawString(col * 8, VID_HEIGHT / scale - 8, string);
Menu_DrawString(col, VID_HEIGHT / scale - 8, string);
}
else
{
@ -638,9 +638,10 @@ MenuList_Draw(menulist_s *l)
{
const char **n;
int y = 0;
float scale = SCR_GetMenuScale();
Menu_DrawStringR2LDark(l->generic.x + l->generic.parent->x
+ LCOLUMN_OFFSET, l->generic.y + l->generic.parent->y,
+ LCOLUMN_OFFSET * scale, l->generic.y + l->generic.parent->y,
l->generic.name);
n = l->itemnames;
@ -652,7 +653,7 @@ MenuList_Draw(menulist_s *l)
while (*n)
{
Menu_DrawStringR2LDark(l->generic.x + l->generic.parent->x +
LCOLUMN_OFFSET, l->generic.y + l->generic.parent->y +
LCOLUMN_OFFSET * scale, l->generic.y + l->generic.parent->y +
y + 10, *n);
n++;
@ -700,7 +701,7 @@ Slider_Draw(menuslider_s *s)
float scale = SCR_GetMenuScale();
Menu_DrawStringR2LDark(s->generic.x + s->generic.parent->x +
LCOLUMN_OFFSET, s->generic.y + s->generic.parent->y,
LCOLUMN_OFFSET * scale, s->generic.y + s->generic.parent->y,
s->generic.name);
s->range = (s->curvalue - s->minvalue) /
@ -716,19 +717,19 @@ Slider_Draw(menuslider_s *s)
s->range = 1;
}
Draw_CharScaled(s->generic.x + (s->generic.parent->x + RCOLUMN_OFFSET),
Draw_CharScaled(s->generic.x + (s->generic.parent->x + RCOLUMN_OFFSET * scale),
(s->generic.y + s->generic.parent->y) * scale, 128, scale);
for (i = 0; i < SLIDER_RANGE * scale; i++)
{
Draw_CharScaled((RCOLUMN_OFFSET + s->generic.x + i * 8 + s->generic.parent->x + 8),
Draw_CharScaled((RCOLUMN_OFFSET * scale + s->generic.x + i * 8 + s->generic.parent->x + 8),
(s->generic.y + s->generic.parent->y) * scale, 129, scale);
}
Draw_CharScaled((RCOLUMN_OFFSET + s->generic.x + i * 8 +
Draw_CharScaled((RCOLUMN_OFFSET * scale + s->generic.x + i * 8 +
s->generic.parent->x + 8), (s->generic.y +
s->generic.parent->y) * scale, 130, scale);
Draw_CharScaled(((int)(8 + RCOLUMN_OFFSET + s->generic.parent->x +
Draw_CharScaled(((int)(8 + RCOLUMN_OFFSET * scale + s->generic.parent->x +
s->generic.x + (SLIDER_RANGE * scale - 1) * 8 * s->range)),
(s->generic.y + s->generic.parent->y) * scale, 131, scale);
}
@ -757,17 +758,18 @@ void
SpinControl_Draw(menulist_s *s)
{
char buffer[100];
float scale = SCR_GetMenuScale();
if (s->generic.name)
{
Menu_DrawStringR2LDark(s->generic.x + s->generic.parent->x +
LCOLUMN_OFFSET, s->generic.y + s->generic.parent->y,
LCOLUMN_OFFSET * scale, s->generic.y + s->generic.parent->y,
s->generic.name);
}
if (!strchr(s->itemnames[s->curvalue], '\n'))
{
Menu_DrawString(RCOLUMN_OFFSET + s->generic.x +
Menu_DrawString(RCOLUMN_OFFSET * scale + s->generic.x +
s->generic.parent->x, s->generic.y +
s->generic.parent->y,
s->itemnames[s->curvalue]);
@ -776,11 +778,11 @@ SpinControl_Draw(menulist_s *s)
{
strcpy(buffer, s->itemnames[s->curvalue]);
*strchr(buffer, '\n') = 0;
Menu_DrawString(RCOLUMN_OFFSET + s->generic.x +
Menu_DrawString(RCOLUMN_OFFSET * scale + s->generic.x +
s->generic.parent->x, s->generic.y +
s->generic.parent->y, buffer);
strcpy(buffer, strchr(s->itemnames[s->curvalue], '\n') + 1);
Menu_DrawString(RCOLUMN_OFFSET + s->generic.x +
Menu_DrawString(RCOLUMN_OFFSET * scale + s->generic.x +
s->generic.parent->x, s->generic.y +
s->generic.parent->y + 10, buffer);
}