Skip to content

Commit

Permalink
Merge remote-tracking branch 'yquake2/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
0lvin committed Oct 26, 2024
2 parents 15a5f65 + 07ee830 commit e905ae1
Show file tree
Hide file tree
Showing 10 changed files with 173 additions and 78 deletions.
3 changes: 2 additions & 1 deletion src/client/cl_keyboard.c
Original file line number Diff line number Diff line change
Expand Up @@ -1419,7 +1419,8 @@ Key_Event(int key, qboolean down, qboolean special)
/* FIXME: Better way to do CTRL+<key> actions in the console?
special should be set to true in this case.
*/
if (keydown[K_CTRL] && IsInConsole() &&
if (keydown[K_CTRL] &&
(IsInConsole() || cls.key_dest == key_menu) &&
key >= 'a' && key <= 'z')
{
special = true;
Expand Down
2 changes: 1 addition & 1 deletion src/client/input/sdl3.c
Original file line number Diff line number Diff line change
Expand Up @@ -864,7 +864,7 @@ IN_Update(void)
break;

case SDL_EVENT_GAMEPAD_REMOVED :
if (controller && event.gdevice.which == SDL_GetJoystickInstanceID(SDL_GetGamepadJoystick(controller))) {
if (controller && event.gdevice.which == SDL_GetJoystickID(SDL_GetGamepadJoystick(controller))) {
Cvar_SetValue("paused", 1);
IN_Controller_Shutdown(true);
IN_Controller_Init(false);
Expand Down
2 changes: 1 addition & 1 deletion src/client/menu/header/qmenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ typedef struct
int cursor;
int length;
int visible_length;
int visible_offset;
} menufield_s;

typedef struct
Expand Down Expand Up @@ -139,6 +138,7 @@ typedef struct

void M_PushMenu(menuframework_s* menu);

void Field_ResetCursor(menuframework_s *m);
qboolean Field_Key(menufield_s *field, int key);

void Menu_AddItem(menuframework_s *menu, void *item);
Expand Down
46 changes: 28 additions & 18 deletions src/client/menu/menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -328,29 +328,33 @@ Default_MenuKey(menuframework_s *m, int key)

if (m)
{
menucommon_s *item;
menucommon_s *item = Menu_ItemAtCursor(m);

if ((item = Menu_ItemAtCursor(m)) != 0)
if (item && item->type == MTYPE_FIELD)
{
if (item->type == MTYPE_FIELD)
if (Field_Key((menufield_s *)item, key))
{
if (Field_Key((menufield_s *)item, key))
{
return NULL;
}
return NULL;
}
}
}

switch (menu_key)
{
case K_ESCAPE:
if (m)
{
Field_ResetCursor(m);
}

M_PopMenu();
return menu_out_sound;

case K_UPARROW:
if (m)
{
Field_ResetCursor(m);

m->cursor--;
Menu_AdjustCursor(m, -1);
sound = menu_move_sound;
Expand All @@ -360,6 +364,8 @@ Default_MenuKey(menuframework_s *m, int key)
case K_DOWNARROW:
if (m)
{
Field_ResetCursor(m);

m->cursor++;
Menu_AdjustCursor(m, 1);
sound = menu_move_sound;
Expand Down Expand Up @@ -5247,26 +5253,30 @@ AddressBook_MenuInit(void)

for (i = 0; i < NUM_ADDRESSBOOK_ENTRIES; i++)
{
menufield_s *f;
const cvar_t *adr;
char buffer[20];

Com_sprintf(buffer, sizeof(buffer), "adr%d", i);

adr = Cvar_Get(buffer, "", CVAR_ARCHIVE);

s_addressbook_fields[i].generic.type = MTYPE_FIELD;
s_addressbook_fields[i].generic.name = 0;
s_addressbook_fields[i].generic.callback = 0;
s_addressbook_fields[i].generic.x = 0;
s_addressbook_fields[i].generic.y = i * 18 + 0;
s_addressbook_fields[i].generic.localdata[0] = i;
s_addressbook_fields[i].cursor = 0;
s_addressbook_fields[i].length = 60;
s_addressbook_fields[i].visible_length = 30;
f = &s_addressbook_fields[i];

f->generic.type = MTYPE_FIELD;
f->generic.name = 0;
f->generic.callback = 0;
f->generic.x = 0;
f->generic.y = i * 18 + 0;
f->generic.localdata[0] = i;

f->length = 60;
f->visible_length = 30;

strcpy(s_addressbook_fields[i].buffer, adr->string);
Q_strlcpy(f->buffer, adr->string, f->length);
f->cursor = strlen(f->buffer);

Menu_AddItem(&s_addressbook_menu, &s_addressbook_fields[i]);
Menu_AddItem(&s_addressbook_menu, f);
}
}

Expand Down
150 changes: 109 additions & 41 deletions src/client/menu/qmenu.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
#include "../header/client.h"
#include "header/qmenu.h"

void IN_GetClipboardText(char *out, size_t n);
int IN_SetClipboardText(const char *s);

static void Action_Draw(menuaction_s *a);
static void Menu_DrawStatusBar(const char *string);
static void MenuList_Draw(menulist_s *l);
Expand Down Expand Up @@ -166,7 +169,8 @@ Field_Draw(menufield_s *f)
n = sizeof(tempbuffer);
}

Q_strlcpy(tempbuffer, f->buffer + f->visible_offset, n);
i = (f->cursor > f->visible_length) ? (f->cursor - f->visible_length) : 0;
Q_strlcpy(tempbuffer, f->buffer + i, n);

Draw_CharScaled(x + (16 * scale),
(y - 4) * scale, 18, scale);
Expand All @@ -191,30 +195,36 @@ Field_Draw(menufield_s *f)

if (Menu_ItemAtCursor(f->generic.parent) == f)
{
int offset;

if (f->visible_offset)
if (((int)(Sys_Milliseconds() / 250)) & 1)
{
offset = f->visible_length;
}
int offset;

else
{
offset = f->cursor;
}
if (f->cursor > f->visible_length)
{
offset = f->visible_length;
}
else
{
offset = f->cursor;
}

if (((int)(Sys_Milliseconds() / 250)) & 1)
{
Draw_CharScaled(
x + (24 * scale) + (offset * (8 * scale)),
y * scale, 11, scale);
}
else
{
Draw_CharScaled(
x + (24 * scale) + (offset * (8 * scale)),
y * scale, ' ', scale);
}
}
}

void
Field_ResetCursor(menuframework_s *m)
{
menucommon_s *item = Menu_ItemAtCursor(m);

if (item && item->type == MTYPE_FIELD)
{
menufield_s *f = (menufield_s *)item;

f->cursor = strlen(f->buffer);
}
}

Expand All @@ -223,36 +233,97 @@ extern int keydown[];
qboolean
Field_Key(menufield_s *f, int key)
{
if (key > 127)
char txt[256];

if (keydown[K_CTRL])
{
return false;
if (key == 'l')
{
*f->buffer = '\0';
f->cursor = 0;

return true;
}

if (key == 'c' || key == 'x')
{
if (*f->buffer != '\0')
{
if (IN_SetClipboardText(f->buffer))
{
Com_Printf("Copying menu field to clipboard failed.\n");
}
else if (key == 'x')
{
*f->buffer = '\0';
f->cursor = 0;
}
}

return true;
}

if (key == 'v')
{
IN_GetClipboardText(txt, sizeof(txt));

if (*txt != '\0')
{
if ((f->generic.flags & QMF_NUMBERSONLY) && !Q_strisnum(txt))
{
return false;
}

f->cursor += Q_strins(f->buffer, txt, f->cursor, f->length);
}
}

return true;
}

switch (key)
{
case K_KP_LEFTARROW:
case K_LEFTARROW:
case K_BACKSPACE:

if (f->cursor > 0)
{
memmove(&f->buffer[f->cursor - 1],
&f->buffer[f->cursor],
strlen(&f->buffer[f->cursor]) + 1);
f->cursor--;
}
break;

if (f->visible_offset)
{
f->visible_offset--;
}
case K_KP_RIGHTARROW:
case K_RIGHTARROW:
if (f->buffer[f->cursor] != '\0')
{
f->cursor++;
}
break;

case K_BACKSPACE:
if (f->cursor > 0)
{
Q_strdel(f->buffer, f->cursor - 1, 1);
f->cursor--;
}
break;

case K_END:
if (f->buffer[f->cursor] == '\0')
{
f->cursor = 0;
}
else
{
f->cursor = strlen(f->buffer);
}
break;

case K_KP_DEL:
case K_DEL:
memmove(&f->buffer[f->cursor], &f->buffer[f->cursor + 1],
strlen(&f->buffer[f->cursor + 1]) + 1);
if (f->buffer[f->cursor] != '\0')
{
Q_strdel(f->buffer, f->cursor, 1);
}
break;

case K_KP_ENTER:
Expand All @@ -261,24 +332,21 @@ Field_Key(menufield_s *f, int key)
case K_TAB:
return false;

case K_SPACE:
default:
if (key > 127)
{
return false;
}

if (!isdigit(key) && (f->generic.flags & QMF_NUMBERSONLY))
{
return false;
}

if (f->cursor < f->length)
{
f->buffer[f->cursor++] = key;
f->buffer[f->cursor] = 0;
*txt = key;
*(txt + 1) = '\0';

if (f->cursor > f->visible_length)
{
f->visible_offset++;
}
}
f->cursor += Q_strins(f->buffer, txt, f->cursor, f->length);
}

return true;
Expand Down
8 changes: 8 additions & 0 deletions src/client/refresh/gl1/gl1_sdl.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,11 @@ int RI_PrepareForWindow(void)
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1);

#ifdef USE_SDL3
if (SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8) == 0)
#else
if (SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8))
#endif
{
gl_state.stencil = true;
}
Expand Down Expand Up @@ -309,7 +313,11 @@ int RI_InitContext(void* win)

if (gl_msaa_samples->value)
{
#ifdef USE_SDL3
if (SDL_GL_GetAttribute(SDL_GL_MULTISAMPLESAMPLES, &msaa_samples))
#else
if (SDL_GL_GetAttribute(SDL_GL_MULTISAMPLESAMPLES, &msaa_samples) == 0)
#endif
{
ri.Cvar_SetValue("r_msaa_samples", msaa_samples);
}
Expand Down
4 changes: 4 additions & 0 deletions src/client/refresh/gl3/gl3_sdl.c
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,11 @@ int GL3_InitContext(void* win)

if (gl_msaa_samples->value)
{
#ifdef USE_SDL3
if (SDL_GL_GetAttribute(SDL_GL_MULTISAMPLESAMPLES, &msaa_samples))
#else
if (SDL_GL_GetAttribute(SDL_GL_MULTISAMPLESAMPLES, &msaa_samples) == 0)
#endif
{
ri.Cvar_SetValue("r_msaa_samples", msaa_samples);
}
Expand Down
Loading

0 comments on commit e905ae1

Please sign in to comment.