Skip to content
Permalink
Browse files

client: add cursor management for edit field UI, refs #442

* Create Text_PaintWithCursor_Ext and CG_Text_PaintWithCursor_Ext
* Add cursor implementation in BG_PanelButton_EditClick
* Add cursor for debriefing chat and limbopanel name editing
  • Loading branch information...
Aranud committed Oct 5, 2019
1 parent d8fbd8d commit f1d7039a00b41247359efab00421d718e6208c8a
Showing with 424 additions and 235 deletions.
  1. +37 −51 src/cgame/cg_debriefing.c
  2. +125 −2 src/cgame/cg_draw.c
  3. +4 −2 src/cgame/cg_limbopanel.c
  4. +2 −0 src/cgame/cg_local.h
  5. +45 −62 src/cgame/cg_main.c
  6. +89 −70 src/ui/ui_main.c
  7. +121 −48 src/ui/ui_shared.c
  8. +1 −0 src/ui/ui_shared.h
@@ -43,7 +43,7 @@ int QDECL CG_SortPlayersByXP(const void *a, const void *b);
panel_button_text_t debriefPlayerHeadingSmallerFont =
{
0.2f, 0.2f,
{ 0.6f, 0.6f, 0.6f, 1.f },
{ 0.6f, 0.6f,0.6f, 1.f },
0, 0,
&cgs.media.limboFont2,
};
@@ -505,7 +505,7 @@ panel_button_t debriefPlayerListScroll =
panel_button_text_t debriefPlayerInfoFont =
{
0.2f, 0.2f,
{ 0.6f, 0.6f, 0.6f, 1.f },
{ 0.6f, 0.6f,0.6f, 1.f },
0, 0,
&cgs.media.limboFont2,
};
@@ -642,11 +642,11 @@ panel_button_t debriefPlayerInfoHitRegions =
{
NULL,
NULL,
{ 146, 156, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0 },
&debriefPlayerInfoFont, // font
NULL, // keyDown
NULL, // keyUp
{ 146, 156, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0},
&debriefPlayerInfoFont, // font
NULL, // keyDown
NULL, // keyUp
CG_Debriefing_PlayerHitRegions_Draw,
NULL,
};
@@ -655,8 +655,8 @@ panel_button_t debriefPlayerInfoHitRegions =
panel_button_t debriefPlayerInfoSkills ## number = { \
NULL, \
NULL, \
{ 24, 136 + (number * 14), 12, 12 }, \
{ number, 0, 0, 0, 0, 0, 0, 0}, \
{ 24, 136 + (number * 14), 12, 12 }, \
{ number, 0, 0, 0, 0, 0, 0, 0}, \
&debriefPlayerInfoFont, /* font */ \
NULL, /* keyDown */ \
NULL, /* keyUp */ \
@@ -844,8 +844,8 @@ panel_button_t chatPanelVoteButton =
{
NULL,
"MAP VOTE",
{ SCREEN_WIDTH - 10 - 60 - 4 - 60 - 4, SCREEN_HEIGHT - 30, 60, 16 },
{ 0, 0, 0, 0, 0, 0, 0, 0},
{ SCREEN_WIDTH - 10 - 60 - 4 - 60 - 4,SCREEN_HEIGHT - 30, 60, 16 },
{ 0, 0, 0, 0, 0, 0, 0, 0},
NULL, // font
CG_Debriefing_VoteButton_KeyDown,// keyDown
NULL, // keyUp
@@ -858,8 +858,8 @@ panel_button_t chatPanelQCButton =
{
NULL,
"QUICK CHAT",
{ SCREEN_WIDTH - 10 - 60 - 4 - 60 - 4 - 80 - 4, SCREEN_HEIGHT - 30, 80, 16 },
{ 0, 0, 0, 0, 0, 0, 0, 0},
{ SCREEN_WIDTH - 10 - 60 - 4 - 60 - 4 - 80 - 4,SCREEN_HEIGHT - 30, 80, 16 },
{ 0, 0, 0, 0, 0, 0, 0, 0},
NULL, // font
CG_Debriefing_QCButton_KeyDown,// keyDown
NULL, // keyUp
@@ -872,8 +872,8 @@ panel_button_t chatPanelReadyButton =
{
NULL,
"READY",
{ SCREEN_WIDTH - 10 - 60 - 4 - 60 - 4 - 80 - 4 - 60 - 4, SCREEN_HEIGHT - 30, 60, 16 },
{ 0, 0, 0, 0, 0, 0, 0, 0},
{ SCREEN_WIDTH - 10 - 60 - 4 - 60 - 4 - 80 - 4 - 60 - 4,SCREEN_HEIGHT - 30, 60, 16 },
{ 0, 0, 0, 0, 0, 0, 0, 0},
NULL, // font
CG_Debriefing_ReadyButton_KeyDown,// keyDown
NULL, // keyUp
@@ -1100,7 +1100,7 @@ void CG_MapVoteList_Draw(panel_button_t *button)
CG_Text_Paint_Ext(DB_MAPVOTE_X + cgs.wideXoffset, y, button->font->scalex,
button->font->scaley, button->font->colour,
va("%3d%% (%d)", cgs.dbMapVotesSum > 0 ? 100 * cgs.dbMapVotes[i + cgs.dbMapVoteListOffset] / cgs.dbMapVotesSum : 0,
cgs.dbMapVotes[i + cgs.dbMapVoteListOffset]),
cgs.dbMapVotes[i + cgs.dbMapVoteListOffset]),
0, 0, 0, button->font->font);
y += 12;
}
@@ -1235,8 +1235,8 @@ panel_button_t mapVoteHeadingVotes =
{
NULL,
"Votes",
{ DB_MAPVOTE_X, DB_MAPVOTE_Y, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0},
{ DB_MAPVOTE_X, DB_MAPVOTE_Y, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0},
&mapVoteFont, // font
NULL, // keyDown
NULL, // keyUp
@@ -1378,28 +1378,12 @@ panel_button_t mapVoteBorder3 =
*/
void CG_Debriefing_ChatEdit_Draw(panel_button_t *button)
{
int offset = -1;
char buffer[256 + 1];
const char *cs;
int offset = -1;
char buffer[MAX_EDITFIELD + 1];
vec4_t *color;

trap_Cvar_VariableStringBuffer(button->text, buffer, sizeof(buffer));

if ((cg.time / 1000) % 2)
{
if (trap_Key_GetOverstrikeMode())
{
Q_strcat(buffer, sizeof(buffer), "^7|");
}
else
{
Q_strcat(buffer, sizeof(buffer), "^7_");
}
}
else
{
Q_strcat(buffer, sizeof(buffer), " ");
}

do
{
offset++;
@@ -1413,20 +1397,20 @@ void CG_Debriefing_ChatEdit_Draw(panel_button_t *button)
switch (cgs.dbChatMode)
{
case 0:
cs = va("^7%s", buffer + offset);
color = &colorWhite;
break;
case 1:
cs = va("^5%s", buffer + offset);
color = &colorCyan;
break;
case 2:
cs = va("^3%s", buffer + offset);
color = &colorYellow;
break;
default:
cs = "";
color = &button->font->colour;
break;
}

CG_Text_Paint_Ext(button->rect.x, button->rect.y + button->rect.h, button->font->scalex, button->font->scaley, button->font->colour, cs, 0, 0, button->font->style, button->font->font);
CG_Text_PaintWithCursor_Ext(button->rect.x, button->rect.y + button->rect.h, button->font->scalex, *color, va("%s", buffer + offset), button->data[2], trap_Key_GetOverstrikeMode() ? "_" : "|", offset, button->font->style, button->font->font);
}

/**
@@ -1493,7 +1477,7 @@ void CG_Debriefing_ChatBox_Draw(panel_button_t *button)
panel_button_t *chatPanelButtons[] =
{
&chatPanelWindow, &chatPanelText,
&chatPanelNextButton, &chatPanelVoteButton, &chatPanelQCButton, &chatTypeButton, &chatPanelReadyButton,
&chatPanelNextButton, &chatPanelVoteButton,&chatPanelQCButton, &chatTypeButton, &chatPanelReadyButton,
&charPanelEditSurround, &charPanelEdit,
NULL
};
@@ -2602,13 +2586,13 @@ qhandle_t imgL;
/**
* @brief
*/
void CG_Debriefing_PlayerHitRegions_Draw(panel_button_t* button)
void CG_Debriefing_PlayerHitRegions_Draw(panel_button_t *button)
{
int totalHits = cgs.dbHitRegions[HR_HEAD] + cgs.dbHitRegions[HR_ARMS] + cgs.dbHitRegions[HR_BODY] + cgs.dbHitRegions[HR_LEGS];
float hitsHead = (totalHits && cgs.dbHitRegions[HR_HEAD]) ? (cgs.dbHitRegions[HR_HEAD]/(float)totalHits) : 0.0f;
float hitsArms = (totalHits && cgs.dbHitRegions[HR_ARMS]) ? (cgs.dbHitRegions[HR_ARMS]/(float)totalHits) : 0.0f;
float hitsBody = (totalHits && cgs.dbHitRegions[HR_BODY]) ? (cgs.dbHitRegions[HR_BODY]/(float)totalHits) : 0.0f;
float hitsLegs = (totalHits && cgs.dbHitRegions[HR_LEGS]) ? (cgs.dbHitRegions[HR_LEGS]/(float)totalHits) : 0.0f;
float hitsHead = (totalHits && cgs.dbHitRegions[HR_HEAD]) ? (cgs.dbHitRegions[HR_HEAD] / (float)totalHits) : 0.0f;
float hitsArms = (totalHits && cgs.dbHitRegions[HR_ARMS]) ? (cgs.dbHitRegions[HR_ARMS] / (float)totalHits) : 0.0f;
float hitsBody = (totalHits && cgs.dbHitRegions[HR_BODY]) ? (cgs.dbHitRegions[HR_BODY] / (float)totalHits) : 0.0f;
float hitsLegs = (totalHits && cgs.dbHitRegions[HR_LEGS]) ? (cgs.dbHitRegions[HR_LEGS] / (float)totalHits) : 0.0f;
float alphaH = hitsHead > 0.f ? (hitsHead * 0.8f) + 0.2f : 0.0f;
float alphaA = hitsArms > 0.f ? (hitsArms * 0.8f) + 0.2f : 0.0f;
float alphaB = hitsBody > 0.f ? (hitsBody * 0.8f) + 0.2f : 0.0f;
@@ -2670,7 +2654,7 @@ void CG_Debriefing_PlayerHitRegions_Draw(panel_button_t* button)

if (alphaA)
{
Vector4Set(colorA, 1.0f, 0.f, 0.f, alphaA );
Vector4Set(colorA, 1.0f, 0.f, 0.f, alphaA);
trap_R_SetColor(colorA);
CG_DrawPic(button->rect.x + 4, button->rect.y + 12, 54, 54, imgA);
trap_R_SetColor(NULL);
@@ -3127,8 +3111,8 @@ void CG_Debriefing_NextButton_Draw(panel_button_t *button)
*/
void CG_Debriefing_ChatEditFinish(panel_button_t *button)
{
char buffer[256];
trap_Cvar_VariableStringBuffer(button->text, buffer, 256);
char buffer[MAX_EDITFIELD];
trap_Cvar_VariableStringBuffer(button->text, buffer, MAX_EDITFIELD);

switch (cgs.dbChatMode)
{
@@ -3143,6 +3127,8 @@ void CG_Debriefing_ChatEditFinish(panel_button_t *button)
break;
}

button->data[2] = 0;

trap_Cvar_Set(button->text, "");
}

@@ -208,8 +208,6 @@ void CG_Text_PaintChar_Ext(float x, float y, float w, float h, float scalex, flo
* @param[in] s2
* @param[in] t2
* @param[in] hShader
*
* @note Unused
*/
void CG_Text_PaintChar(float x, float y, float width, float height, float scale, float s, float t, float s2, float t2, qhandle_t hShader)
{
@@ -334,6 +332,131 @@ void CG_Text_Paint(float x, float y, float scale, vec4_t color, const char *text
CG_Text_Paint_Ext(x, y, scale, scale, color, text, adjust, limit, style, font);
}

/**
* @brief CG_Text_PaintWithCursor_Ext
* @param[in] x
* @param[in] y
* @param[in] scale
* @param[in] color
* @param[in] text
* @param[in] cursorPos
* @param[in] cursor
* @param[in] limit
* @param[in] style
*/
void CG_Text_PaintWithCursor_Ext(float x, float y, float scale, vec4_t color, const char *text, int cursorPos, const char *cursor, int limit, int style, fontHelper_t *font)
{
vec4_t newColor = { 0, 0, 0, 0 };
glyphInfo_t *glyph, *glyph2;
float useScale = scale * Q_UTF8_GlyphScale(font);

if (text)
{
float yadj;
int len = Q_UTF8_Strlen(text);
int count = 0;
const char *s = text;

trap_R_SetColor(color);
Com_Memcpy(&newColor[0], &color[0], sizeof(vec4_t));

if (limit > 0 && len > limit)
{
len = limit;
}

glyph2 = Q_UTF8_GetGlyph(font, cursor);
while (s && *s && count < len)
{
glyph = Q_UTF8_GetGlyph(font, s);
yadj = useScale * glyph->top;

if (style == ITEM_TEXTSTYLE_SHADOWED || style == ITEM_TEXTSTYLE_SHADOWEDMORE)
{
int ofs = style == ITEM_TEXTSTYLE_SHADOWED ? 1 : 2;

colorBlack[3] = newColor[3];
trap_R_SetColor(colorBlack);
CG_Text_PaintChar(x + (glyph->pitch * useScale) + ofs, y - yadj + ofs,
glyph->imageWidth,
glyph->imageHeight,
useScale,
glyph->s,
glyph->t,
glyph->s2,
glyph->t2,
glyph->glyph);
colorBlack[3] = 1.0;
trap_R_SetColor(newColor);
}
CG_Text_PaintChar(x + (glyph->pitch * useScale), y - yadj,
glyph->imageWidth,
glyph->imageHeight,
useScale,
glyph->s,
glyph->t,
glyph->s2,
glyph->t2,
glyph->glyph);

// CG_DrawPic(x, y - yadj, scale * uiDC.Assets.textFont.glyphs[text[i]].imageWidth, scale * uiDC.Assets.textFont.glyphs[text[i]].imageHeight, uiDC.Assets.textFont.glyphs[text[i]].glyph);
yadj = useScale * glyph2->top;
if (count == cursorPos && !((cgDC.realTime / BLINK_DIVISOR) & 1))
{
CG_Text_PaintChar(x + (glyph->pitch * useScale), y - yadj,
glyph2->imageWidth,
glyph2->imageHeight,
useScale,
glyph2->s,
glyph2->t,
glyph2->s2,
glyph2->t2,
glyph2->glyph);
}

x += (glyph->xSkip * useScale);
s += Q_UTF8_Width(s);
count++;

}
// need to paint cursor at end of text
if (cursorPos == len && !((cgDC.realTime / BLINK_DIVISOR) & 1))
{
yadj = useScale * glyph2->top;
CG_Text_PaintChar(x + (glyph2->pitch * useScale), y - yadj,
glyph2->imageWidth,
glyph2->imageHeight,
useScale,
glyph2->s,
glyph2->t,
glyph2->s2,
glyph2->t2,
glyph2->glyph);
}

trap_R_SetColor(NULL);
}
}

/**
* @brief CG_Text_PaintWithCursor
* @param[in] x
* @param[in] y
* @param[in] scale
* @param[in] color
* @param[in] text
* @param[in] cursorPos
* @param[in] cursor
* @param[in] limit
* @param[in] style
*/
void CG_Text_PaintWithCursor(float x, float y, float scale, vec4_t color, const char *text, int cursorPos, const char *cursor, int limit, int style)
{
fontHelper_t *font = &cgDC.Assets.fonts[activeFont];

CG_Text_PaintWithCursor_Ext(x, y, scale, color, text, cursorPos, cursor, limit, style, font);
}

/**
* @brief CG_DrawTeamBackground
* @param[in] x
@@ -1222,10 +1222,12 @@ void CG_LimboPanel_BriefingButton_Draw(panel_button_t *button)
*/
void CG_LimboPanel_NameEditFinish(panel_button_t *button)
{
char buffer[256];
char buffer[MAX_EDITFIELD];

trap_Cvar_VariableStringBuffer(button->text, buffer, 256);
trap_Cvar_VariableStringBuffer(button->text, buffer, MAX_EDITFIELD);
trap_Cvar_Set("name", buffer);

BG_PanelButtons_SetFocusButton(NULL);
}

/**
@@ -2747,6 +2747,8 @@ void CG_DrawTeamBackground(int x, int y, int w, int h, float alpha, int team);
void CG_Text_Paint_Ext(float x, float y, float scalex, float scaley, vec4_t color, const char *text, float adjust, int limit, int style, fontHelper_t *font);
void CG_Text_Paint_Centred_Ext(float x, float y, float scalex, float scaley, vec4_t color, const char *text, float adjust, int limit, int style, fontHelper_t *font);
void CG_Text_Paint(float x, float y, float scale, vec4_t color, const char *text, float adjust, int limit, int style);
void CG_Text_PaintWithCursor_Ext(float x, float y, float scale, vec4_t color, const char *text, int cursorPos, const char *cursor, int limit, int style, fontHelper_t *font);
void CG_Text_PaintWithCursor(float x, float y, float scale, vec4_t color, const char *text, int cursorPos, const char *cursor, int limit, int style);
void CG_Text_SetActiveFont(int font);
int CG_Text_Width_Ext(const char *text, float scale, int limit, fontHelper_t *font);
int CG_Text_Width(const char *text, float scale, int limit);

0 comments on commit f1d7039

Please sign in to comment.
You can’t perform that action at this time.