Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wip keymodifiers #601

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Quake/draw.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ void Draw_Fill (cb_context_t *cbx, int x, int y, int w, int h, int c, float alph
void Draw_FadeScreen (cb_context_t *cbx);
void Draw_String (cb_context_t *cbx, int x, int y, const char *str);
void Draw_String_3D (cb_context_t *cbx, vec3_t coords, float size, const char *str);
void Draw_String_WithSize (cb_context_t *cbx, int x, int y, const char *str, float size);
qpic_t *Draw_PicFromWad2 (const char *name, unsigned int texflags);
qpic_t *Draw_PicFromWad (const char *name);
qpic_t *Draw_CachePic (const char *path);
Expand Down
26 changes: 18 additions & 8 deletions Quake/gl_draw.c
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ void Draw_Init (void)
Draw_FillCharacterQuad
================
*/
static void Draw_FillCharacterQuad (int x, int y, char num, basicvertex_t *output, int rotation)
static void Draw_FillCharacterQuad_WithSize (int x, int y, char num, basicvertex_t *output, int rotation, float textSize)
{
int row, col;
float frow, fcol, size;
Expand All @@ -471,9 +471,9 @@ static void Draw_FillCharacterQuad (int x, int y, char num, basicvertex_t *outpu

float texcoords[4][2] = {
{x, y},
{x + 8, y},
{x + 8, y + 8},
{x, y + 8},
{x + textSize, y},
{x + textSize, y + textSize},
{x, y + textSize},
};

corner_verts[0].position[0] = texcoords[(rotation + 0) % 4][0];
Expand Down Expand Up @@ -508,6 +508,11 @@ static void Draw_FillCharacterQuad (int x, int y, char num, basicvertex_t *outpu
output[5] = corner_verts[0];
}

static void Draw_FillCharacterQuad (int x, int y, char num, basicvertex_t *output, int rotation)
{
Draw_FillCharacterQuad_WithSize (x, y, num, output, rotation, 8.f);
}

/*
================
Draw_Character
Expand Down Expand Up @@ -542,13 +547,13 @@ void Draw_Character (cb_context_t *cbx, int x, int y, int num)
Draw_String
================
*/
void Draw_String (cb_context_t *cbx, int x, int y, const char *str)
void Draw_String_WithSize (cb_context_t *cbx, int x, int y, const char *str, float size)
{
int num_verts = 0;
int i;
const char *tmp;

if (y <= -8)
if (y <= -size)
return; // totally off screen

for (tmp = str; *tmp != 0; ++tmp)
Expand All @@ -563,10 +568,10 @@ void Draw_String (cb_context_t *cbx, int x, int y, const char *str)
{
if (*str != 32)
{
Draw_FillCharacterQuad (x, y, *str, vertices + i * 6, 0);
Draw_FillCharacterQuad_WithSize (x, y, *str, vertices + i * 6, 0, size);
i++;
}
x += 8;
x += size;
}

vulkan_globals.vk_cmd_bind_vertex_buffers (cbx->cb, 0, 1, &buffer, &buffer_offset);
Expand All @@ -576,6 +581,11 @@ void Draw_String (cb_context_t *cbx, int x, int y, const char *str)
vulkan_globals.vk_cmd_draw (cbx->cb, num_verts, 1, 0, 0);
}

void Draw_String (cb_context_t *cbx, int x, int y, const char *str)
{
Draw_String_WithSize (cbx, x, y, str, 8.f);
}

/*
=============
Draw_Pic -- johnfitz -- modified
Expand Down
44 changes: 44 additions & 0 deletions Quake/gl_screen.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ cvar_t scr_conscale = {"scr_conscale", "1", CVAR_ARCHIVE};
cvar_t scr_crosshairscale = {"scr_crosshairscale", "1", CVAR_ARCHIVE};
cvar_t scr_showfps = {"scr_showfps", "0", CVAR_NONE};
cvar_t scr_clock = {"scr_clock", "0", CVAR_NONE};
cvar_t scr_showspeed = {"scr_showspeed", "1", CVAR_NONE};
// johnfitz
cvar_t scr_usekfont = {"scr_usekfont", "0", CVAR_NONE}; // 2021 re-release

Expand Down Expand Up @@ -545,6 +546,7 @@ void SCR_Init (void)
Cvar_RegisterVariable (&scr_crosshairscale);
Cvar_RegisterVariable (&scr_showfps);
Cvar_RegisterVariable (&scr_clock);
Cvar_RegisterVariable (&scr_showspeed);
// johnfitz
Cvar_RegisterVariable (&scr_usekfont); // 2021 re-release
Cvar_SetCallback (&scr_fov, SCR_Callback_refdef);
Expand Down Expand Up @@ -698,6 +700,47 @@ void SCR_DrawClock (cb_context_t *cbx)
}
}

/*
==============
SCR_DrawSpeed
==============
*/
void SCR_DrawSpeed (cb_context_t *cbx)
{
if (cl.intermission || !scr_showspeed.value)
return;

float maxSpeedFillWidth = 600; // if speed >= val, then speedometer is completely filled
float scale = scr_sbarscale.value;
float width = 140.f * scale;
float height = 12.f * scale;
float x = ((float)vid.width / 2.f) - (width / 2.f);
float y = (float)vid.height - height - ((float)Sbar_HudHeight () * scale);

float textLeftOffset = 10.f * scale;
float textHeight = 8.f * scale;
float textY = y + (height / 2) - (textHeight / 2);
float textX = x + textLeftOffset;

char st[4];
float speed = VectorLength (cl.velocity);
sprintf (st, "%-3d", (int)speed);
int speedWidth = (int)(fmin (1.f, speed / maxSpeedFillWidth) * width);

static int bgColor = -1;
static int fillColor = -1;
if (bgColor == -1)
{
bgColor = TexMgr_NearestColor (20, 20, 0);
fillColor = TexMgr_NearestColor (40, 30, 15);
}

GL_SetCanvas (cbx, CANVAS_DEFAULT);
Draw_Fill (cbx, x, y, width, height, bgColor, 1.f); // entire speedometer
Draw_Fill (cbx, x, y, speedWidth, height, fillColor, 1.f); // speed fill on speedometer
Draw_String_WithSize (cbx, textX, textY, st, textHeight);
}

/*
==============
SCR_DrawDevStats
Expand Down Expand Up @@ -1142,6 +1185,7 @@ static void SCR_DrawGUI (void *unused)
SCR_DrawFPS (cbx); // johnfitz
SCR_DrawClock (cbx); // johnfitz
SCR_DrawConsole (cbx);
SCR_DrawSpeed (cbx);
M_Draw (cbx);
}

Expand Down
27 changes: 27 additions & 0 deletions Quake/gl_texmgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,33 @@ void TexMgr_LoadPalette (void)
((byte *)&d_8to24table_conchars[0])[3] = 0;
}

/*
================
TexMgr_NearestColor
================
*/
int TexMgr_NearestColor (int r, int g, int b)
{
byte *curColor = (byte *)d_8to24table;
int nearestColor = 0;
int nearestDist = INT_MAX;
int cursor = 0;

while (curColor[3] != 0) // last color is transparent
{
int colorDist = (r - curColor[0]) * (r - curColor[0]) + (g - curColor[1]) * (g - curColor[1]) + (b - curColor[2]) * (b - curColor[2]);
if (colorDist < nearestDist)
{
nearestColor = cursor;
nearestDist = colorDist;
}
curColor += 4;
cursor += 1;
}

return nearestColor;
}

/*
================
TexMgr_NewGame
Expand Down
1 change: 1 addition & 0 deletions Quake/gl_texmgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ void TexMgr_Init (void);
void TexMgr_DeleteTextureObjects (void);
void TexMgr_CollectGarbage (void);
void TexMgr_LoadPalette (void);
int TexMgr_NearestColor (int r, int g, int b);

// IMAGE LOADING
gltexture_t *TexMgr_LoadImage (
Expand Down
18 changes: 9 additions & 9 deletions Quake/in_sdl.c
Original file line number Diff line number Diff line change
Expand Up @@ -420,21 +420,21 @@ static void IN_JoyKeyEvent (qboolean wasdown, qboolean isdown, int key, double *
if (currenttime >= *timer)
{
*timer = currenttime + 0.1;
Key_Event (key, true);
Key_Event (key, true, 0);
}
}
else
{
*timer = 0;
Key_Event (key, false);
Key_Event (key, false, 0);
}
}
else
{
if (isdown)
{
*timer = currenttime + 0.5;
Key_Event (key, true);
Key_Event (key, true, 0);
}
}
}
Expand Down Expand Up @@ -941,7 +941,7 @@ void IN_SendKeyEvents (void)
// are based on key position, not the label on the key cap.
key = IN_SDL2_ScancodeToQuakeKey (event.key.keysym.scancode);

Key_Event (key, down);
Key_Event (key, down, 0);
break;

case SDL_MOUSEBUTTONDOWN:
Expand All @@ -951,19 +951,19 @@ void IN_SendKeyEvents (void)
Con_Printf ("Ignored event for mouse button %d\n", event.button.button);
break;
}
Key_Event (buttonremap[event.button.button - 1], event.button.state == SDL_PRESSED);
Key_Event (buttonremap[event.button.button - 1], event.button.state == SDL_PRESSED, 0);
break;

case SDL_MOUSEWHEEL:
if (event.wheel.y > 0)
{
Key_Event (K_MWHEELUP, true);
Key_Event (K_MWHEELUP, false);
Key_Event (K_MWHEELUP, true, 0);
Key_Event (K_MWHEELUP, false, 0);
}
else if (event.wheel.y < 0)
{
Key_Event (K_MWHEELDOWN, true);
Key_Event (K_MWHEELDOWN, false);
Key_Event (K_MWHEELDOWN, true, 0);
Key_Event (K_MWHEELDOWN, false, 0);
}
break;

Expand Down
Loading