diff --git a/src/cgame/cg_debriefing.c b/src/cgame/cg_debriefing.c index 19ca0cdec..42940f78c 100644 --- a/src/cgame/cg_debriefing.c +++ b/src/cgame/cg_debriefing.c @@ -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, ""); } diff --git a/src/cgame/cg_draw.c b/src/cgame/cg_draw.c index c62a77596..e41e56ecb 100644 --- a/src/cgame/cg_draw.c +++ b/src/cgame/cg_draw.c @@ -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 diff --git a/src/cgame/cg_limbopanel.c b/src/cgame/cg_limbopanel.c index f6f4f44af..1145da6b0 100644 --- a/src/cgame/cg_limbopanel.c +++ b/src/cgame/cg_limbopanel.c @@ -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); } /** diff --git a/src/cgame/cg_local.h b/src/cgame/cg_local.h index 5ee1fb40b..ff064a09d 100644 --- a/src/cgame/cg_local.h +++ b/src/cgame/cg_local.h @@ -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); diff --git a/src/cgame/cg_main.c b/src/cgame/cg_main.c index eb75f5f64..9a5ea1ed3 100644 --- a/src/cgame/cg_main.c +++ b/src/cgame/cg_main.c @@ -981,7 +981,7 @@ char *CG_generateFilename(void) #endif "" #ifdef FEATURE_MULTIVIEW - : "-MVD" + : "-MVD" #endif )); } @@ -2385,24 +2385,6 @@ float CG_Cvar_Get(const char *cvar) return (float)atof(buff); } -/** - * @brief CG_Text_PaintWithCursor - * @param[in] x - * @param[in] y - * @param[in] scale - * @param[in] color - * @param[in] text - * @param cursorPos - unused - * @param cursor - unused - * @param[in] limit - * @param[in] style - * @todo Unused. Cursor is ignored - */ -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) -{ - CG_Text_Paint(x, y, scale, color, text, 0, limit, style); -} - /** * @brief CG_OwnerDrawWidth * @param ownerDraw - unused @@ -2466,49 +2448,50 @@ static void CG_RunCinematicFrame(int handle) */ void CG_LoadHudMenu(void) { - cgDC.registerShaderNoMip = &trap_R_RegisterShaderNoMip; - cgDC.setColor = &trap_R_SetColor; - cgDC.drawHandlePic = &CG_DrawPic; - cgDC.drawStretchPic = &trap_R_DrawStretchPic; - cgDC.drawText = &CG_Text_Paint; - cgDC.drawTextExt = &CG_Text_Paint_Ext; - cgDC.textWidth = &CG_Text_Width; - cgDC.textWidthExt = &CG_Text_Width_Ext; - cgDC.textHeight = &CG_Text_Height; - cgDC.textHeightExt = &CG_Text_Height_Ext; - cgDC.textFont = &CG_Text_SetActiveFont; - cgDC.registerModel = &trap_R_RegisterModel; - cgDC.modelBounds = &trap_R_ModelBounds; - cgDC.fillRect = &CG_FillRect; - cgDC.drawRect = &CG_DrawRect; - cgDC.drawSides = &CG_DrawSides; - cgDC.drawTopBottom = &CG_DrawTopBottom; - cgDC.clearScene = &trap_R_ClearScene; - cgDC.addRefEntityToScene = &trap_R_AddRefEntityToScene; - cgDC.renderScene = &trap_R_RenderScene; - cgDC.registerFont = &trap_R_RegisterFont; - cgDC.ownerDrawItem = NULL; - cgDC.getValue = &CG_GetValue; - cgDC.ownerDrawVisible = &CG_OwnerDrawVisible; - cgDC.runScript = &CG_RunMenuScript; - cgDC.getTeamColor = &CG_GetTeamColor; - cgDC.setCVar = trap_Cvar_Set; - cgDC.getCVarString = trap_Cvar_VariableStringBuffer; - cgDC.getCVarValue = CG_Cvar_Get; - cgDC.drawTextWithCursor = &CG_Text_PaintWithCursor; - cgDC.setOverstrikeMode = &trap_Key_SetOverstrikeMode; - cgDC.getOverstrikeMode = &trap_Key_GetOverstrikeMode; - cgDC.startLocalSound = &trap_S_StartLocalSound; - cgDC.ownerDrawHandleKey = &CG_OwnerDrawHandleKey; - cgDC.feederCount = &CG_FeederCount; - cgDC.feederItemImage = &CG_FeederItemImage; - cgDC.feederItemText = &CG_FeederItemText; - cgDC.feederSelection = &CG_FeederSelection; - cgDC.setBinding = &trap_Key_SetBinding; - cgDC.getBindingBuf = &trap_Key_GetBindingBuf; - cgDC.getKeysForBinding = &trap_Key_KeysForBinding; - cgDC.keynumToStringBuf = &trap_Key_KeynumToStringBuf; - cgDC.translateString = &CG_TranslateString; + cgDC.registerShaderNoMip = &trap_R_RegisterShaderNoMip; + cgDC.setColor = &trap_R_SetColor; + cgDC.drawHandlePic = &CG_DrawPic; + cgDC.drawStretchPic = &trap_R_DrawStretchPic; + cgDC.drawText = &CG_Text_Paint; + cgDC.drawTextExt = &CG_Text_Paint_Ext; + cgDC.textWidth = &CG_Text_Width; + cgDC.textWidthExt = &CG_Text_Width_Ext; + cgDC.textHeight = &CG_Text_Height; + cgDC.textHeightExt = &CG_Text_Height_Ext; + cgDC.textFont = &CG_Text_SetActiveFont; + cgDC.registerModel = &trap_R_RegisterModel; + cgDC.modelBounds = &trap_R_ModelBounds; + cgDC.fillRect = &CG_FillRect; + cgDC.drawRect = &CG_DrawRect; + cgDC.drawSides = &CG_DrawSides; + cgDC.drawTopBottom = &CG_DrawTopBottom; + cgDC.clearScene = &trap_R_ClearScene; + cgDC.addRefEntityToScene = &trap_R_AddRefEntityToScene; + cgDC.renderScene = &trap_R_RenderScene; + cgDC.registerFont = &trap_R_RegisterFont; + cgDC.ownerDrawItem = NULL; + cgDC.getValue = &CG_GetValue; + cgDC.ownerDrawVisible = &CG_OwnerDrawVisible; + cgDC.runScript = &CG_RunMenuScript; + cgDC.getTeamColor = &CG_GetTeamColor; + cgDC.setCVar = trap_Cvar_Set; + cgDC.getCVarString = trap_Cvar_VariableStringBuffer; + cgDC.getCVarValue = CG_Cvar_Get; + cgDC.drawTextWithCursor = &CG_Text_PaintWithCursor; + cgDC.drawTextWithCursorExt = &CG_Text_PaintWithCursor_Ext; + cgDC.setOverstrikeMode = &trap_Key_SetOverstrikeMode; + cgDC.getOverstrikeMode = &trap_Key_GetOverstrikeMode; + cgDC.startLocalSound = &trap_S_StartLocalSound; + cgDC.ownerDrawHandleKey = &CG_OwnerDrawHandleKey; + cgDC.feederCount = &CG_FeederCount; + cgDC.feederItemImage = &CG_FeederItemImage; + cgDC.feederItemText = &CG_FeederItemText; + cgDC.feederSelection = &CG_FeederSelection; + cgDC.setBinding = &trap_Key_SetBinding; + cgDC.getBindingBuf = &trap_Key_GetBindingBuf; + cgDC.getKeysForBinding = &trap_Key_KeysForBinding; + cgDC.keynumToStringBuf = &trap_Key_KeynumToStringBuf; + cgDC.translateString = &CG_TranslateString; //cgDC.executeText = &trap_Cmd_ExecuteText; cgDC.Error = &Com_Error; cgDC.Print = &Com_Printf; diff --git a/src/ui/ui_main.c b/src/ui/ui_main.c index bf71b748f..366120eeb 100644 --- a/src/ui/ui_main.c +++ b/src/ui/ui_main.c @@ -668,7 +668,7 @@ void Text_Paint(float x, float y, float scale, vec4_t color, const char *text, f } /** - * @brief Text_PaintWithCursor + * @brief Text_PaintWithCursor_Ext * @param[in] x * @param[in] y * @param[in] scale @@ -679,12 +679,11 @@ void Text_Paint(float x, float y, float scale, vec4_t color, const char *text, f * @param[in] limit * @param[in] style */ -void Text_PaintWithCursor(float x, float y, float scale, vec4_t color, const char *text, int cursorPos, const char *cursor, int limit, int style) +void 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; - fontHelper_t *font = &uiInfo.uiDC.Assets.fonts[uiInfo.activeFont]; - float useScale = scale * Q_UTF8_GlyphScale(font); + vec4_t newColor = { 0, 0, 0, 0 }; + glyphInfo_t *glyph, *glyph2; + float useScale = scale * Q_UTF8_GlyphScale(font); if (text) { @@ -774,6 +773,25 @@ void Text_PaintWithCursor(float x, float y, float scale, vec4_t color, const cha } } +/** + * @brief 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 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 = &uiInfo.uiDC.Assets.fonts[uiInfo.activeFont]; + + Text_PaintWithCursor_Ext(x, y, scale, color, text, cursorPos, cursor, limit, style, font); +} + /** * @brief Text_Paint_Limit * @param[in] maxX @@ -8061,70 +8079,71 @@ void UI_Init(int legacyClient, int clientVersion) } //UI_Load(); - uiInfo.uiDC.registerShaderNoMip = &trap_R_RegisterShaderNoMip; - uiInfo.uiDC.setColor = &trap_R_SetColor; - uiInfo.uiDC.drawHandlePic = &UI_DrawHandlePic; - uiInfo.uiDC.drawStretchPic = &trap_R_DrawStretchPic; - uiInfo.uiDC.drawText = &Text_Paint; - uiInfo.uiDC.drawTextExt = &Text_Paint_Ext; - uiInfo.uiDC.textWidth = &Text_Width; - uiInfo.uiDC.textWidthExt = &Text_Width_Ext; - uiInfo.uiDC.multiLineTextWidth = &Multiline_Text_Width; - uiInfo.uiDC.textHeight = &Text_Height; - uiInfo.uiDC.textHeightExt = &Text_Height_Ext; - uiInfo.uiDC.multiLineTextHeight = &Multiline_Text_Height; - uiInfo.uiDC.textFont = &Text_SetActiveFont; - uiInfo.uiDC.registerModel = &trap_R_RegisterModel; - uiInfo.uiDC.modelBounds = &trap_R_ModelBounds; - uiInfo.uiDC.fillRect = &UI_FillRect; - uiInfo.uiDC.drawRect = &_UI_DrawRect; - uiInfo.uiDC.drawSides = &_UI_DrawSides; - uiInfo.uiDC.drawTopBottom = &_UI_DrawTopBottom; - uiInfo.uiDC.clearScene = &trap_R_ClearScene; - uiInfo.uiDC.addRefEntityToScene = &trap_R_AddRefEntityToScene; - uiInfo.uiDC.renderScene = &trap_R_RenderScene; - uiInfo.uiDC.registerFont = &trap_R_RegisterFont; - uiInfo.uiDC.ownerDrawItem = &UI_OwnerDraw; - uiInfo.uiDC.getValue = &UI_GetValue; - uiInfo.uiDC.ownerDrawVisible = &UI_OwnerDrawVisible; - uiInfo.uiDC.runScript = &UI_RunMenuScript; - uiInfo.uiDC.getTeamColor = &UI_GetTeamColor; // not implemented - uiInfo.uiDC.setCVar = trap_Cvar_Set; - uiInfo.uiDC.getCVarString = trap_Cvar_VariableStringBuffer; - uiInfo.uiDC.getCVarValue = trap_Cvar_VariableValue; - uiInfo.uiDC.drawTextWithCursor = &Text_PaintWithCursor; - uiInfo.uiDC.setOverstrikeMode = &trap_Key_SetOverstrikeMode; - uiInfo.uiDC.getOverstrikeMode = &trap_Key_GetOverstrikeMode; - uiInfo.uiDC.startLocalSound = &trap_S_StartLocalSound; - uiInfo.uiDC.ownerDrawHandleKey = &UI_OwnerDrawHandleKey; - uiInfo.uiDC.feederCount = &UI_FeederCount; - uiInfo.uiDC.feederItemImage = &UI_FeederItemImage; - uiInfo.uiDC.feederItemText = &UI_FeederItemText; - uiInfo.uiDC.fileText = &UI_FileText; - uiInfo.uiDC.feederSelection = &UI_FeederSelection; - uiInfo.uiDC.feederSelectionClick = &UI_FeederSelectionClick; - uiInfo.uiDC.feederAddItem = &UI_FeederAddItem; // not implemented - uiInfo.uiDC.setBinding = &trap_Key_SetBinding; - uiInfo.uiDC.getBindingBuf = &trap_Key_GetBindingBuf; - uiInfo.uiDC.getKeysForBinding = &trap_Key_KeysForBinding; - uiInfo.uiDC.keynumToStringBuf = &trap_Key_KeynumToStringBuf; - uiInfo.uiDC.keyIsDown = &trap_Key_IsDown; - uiInfo.uiDC.getClipboardData = &trap_GetClipboardData; - uiInfo.uiDC.executeText = &trap_Cmd_ExecuteText; - uiInfo.uiDC.Error = &Com_Error; - uiInfo.uiDC.Print = &Com_Printf; - uiInfo.uiDC.Pause = &UI_Pause; - uiInfo.uiDC.ownerDrawWidth = &UI_OwnerDrawWidth; - uiInfo.uiDC.registerSound = &trap_S_RegisterSound; - uiInfo.uiDC.startBackgroundTrack = &trap_S_StartBackgroundTrack; - uiInfo.uiDC.stopBackgroundTrack = &trap_S_StopBackgroundTrack; - uiInfo.uiDC.playCinematic = &UI_PlayCinematic; - uiInfo.uiDC.stopCinematic = &UI_StopCinematic; - uiInfo.uiDC.drawCinematic = &UI_DrawCinematic; - uiInfo.uiDC.runCinematicFrame = &UI_RunCinematicFrame; - uiInfo.uiDC.translateString = &trap_TranslateString; - uiInfo.uiDC.checkAutoUpdate = &trap_CheckAutoUpdate; - uiInfo.uiDC.getAutoUpdate = &trap_GetAutoUpdate; + uiInfo.uiDC.registerShaderNoMip = &trap_R_RegisterShaderNoMip; + uiInfo.uiDC.setColor = &trap_R_SetColor; + uiInfo.uiDC.drawHandlePic = &UI_DrawHandlePic; + uiInfo.uiDC.drawStretchPic = &trap_R_DrawStretchPic; + uiInfo.uiDC.drawText = &Text_Paint; + uiInfo.uiDC.drawTextExt = &Text_Paint_Ext; + uiInfo.uiDC.textWidth = &Text_Width; + uiInfo.uiDC.textWidthExt = &Text_Width_Ext; + uiInfo.uiDC.multiLineTextWidth = &Multiline_Text_Width; + uiInfo.uiDC.textHeight = &Text_Height; + uiInfo.uiDC.textHeightExt = &Text_Height_Ext; + uiInfo.uiDC.multiLineTextHeight = &Multiline_Text_Height; + uiInfo.uiDC.textFont = &Text_SetActiveFont; + uiInfo.uiDC.registerModel = &trap_R_RegisterModel; + uiInfo.uiDC.modelBounds = &trap_R_ModelBounds; + uiInfo.uiDC.fillRect = &UI_FillRect; + uiInfo.uiDC.drawRect = &_UI_DrawRect; + uiInfo.uiDC.drawSides = &_UI_DrawSides; + uiInfo.uiDC.drawTopBottom = &_UI_DrawTopBottom; + uiInfo.uiDC.clearScene = &trap_R_ClearScene; + uiInfo.uiDC.addRefEntityToScene = &trap_R_AddRefEntityToScene; + uiInfo.uiDC.renderScene = &trap_R_RenderScene; + uiInfo.uiDC.registerFont = &trap_R_RegisterFont; + uiInfo.uiDC.ownerDrawItem = &UI_OwnerDraw; + uiInfo.uiDC.getValue = &UI_GetValue; + uiInfo.uiDC.ownerDrawVisible = &UI_OwnerDrawVisible; + uiInfo.uiDC.runScript = &UI_RunMenuScript; + uiInfo.uiDC.getTeamColor = &UI_GetTeamColor; // not implemented + uiInfo.uiDC.setCVar = trap_Cvar_Set; + uiInfo.uiDC.getCVarString = trap_Cvar_VariableStringBuffer; + uiInfo.uiDC.getCVarValue = trap_Cvar_VariableValue; + uiInfo.uiDC.drawTextWithCursor = &Text_PaintWithCursor; + uiInfo.uiDC.drawTextWithCursorExt = &Text_PaintWithCursor_Ext; + uiInfo.uiDC.setOverstrikeMode = &trap_Key_SetOverstrikeMode; + uiInfo.uiDC.getOverstrikeMode = &trap_Key_GetOverstrikeMode; + uiInfo.uiDC.startLocalSound = &trap_S_StartLocalSound; + uiInfo.uiDC.ownerDrawHandleKey = &UI_OwnerDrawHandleKey; + uiInfo.uiDC.feederCount = &UI_FeederCount; + uiInfo.uiDC.feederItemImage = &UI_FeederItemImage; + uiInfo.uiDC.feederItemText = &UI_FeederItemText; + uiInfo.uiDC.fileText = &UI_FileText; + uiInfo.uiDC.feederSelection = &UI_FeederSelection; + uiInfo.uiDC.feederSelectionClick = &UI_FeederSelectionClick; + uiInfo.uiDC.feederAddItem = &UI_FeederAddItem; // not implemented + uiInfo.uiDC.setBinding = &trap_Key_SetBinding; + uiInfo.uiDC.getBindingBuf = &trap_Key_GetBindingBuf; + uiInfo.uiDC.getKeysForBinding = &trap_Key_KeysForBinding; + uiInfo.uiDC.keynumToStringBuf = &trap_Key_KeynumToStringBuf; + uiInfo.uiDC.keyIsDown = &trap_Key_IsDown; + uiInfo.uiDC.getClipboardData = &trap_GetClipboardData; + uiInfo.uiDC.executeText = &trap_Cmd_ExecuteText; + uiInfo.uiDC.Error = &Com_Error; + uiInfo.uiDC.Print = &Com_Printf; + uiInfo.uiDC.Pause = &UI_Pause; + uiInfo.uiDC.ownerDrawWidth = &UI_OwnerDrawWidth; + uiInfo.uiDC.registerSound = &trap_S_RegisterSound; + uiInfo.uiDC.startBackgroundTrack = &trap_S_StartBackgroundTrack; + uiInfo.uiDC.stopBackgroundTrack = &trap_S_StopBackgroundTrack; + uiInfo.uiDC.playCinematic = &UI_PlayCinematic; + uiInfo.uiDC.stopCinematic = &UI_StopCinematic; + uiInfo.uiDC.drawCinematic = &UI_DrawCinematic; + uiInfo.uiDC.runCinematicFrame = &UI_RunCinematicFrame; + uiInfo.uiDC.translateString = &trap_TranslateString; + uiInfo.uiDC.checkAutoUpdate = &trap_CheckAutoUpdate; + uiInfo.uiDC.getAutoUpdate = &trap_GetAutoUpdate; uiInfo.uiDC.descriptionForCampaign = &UI_DescriptionForCampaign; uiInfo.uiDC.nameForCampaign = &UI_NameForCampaign; diff --git a/src/ui/ui_shared.c b/src/ui/ui_shared.c index 7c6da43a2..234056e65 100644 --- a/src/ui/ui_shared.c +++ b/src/ui/ui_shared.c @@ -1250,15 +1250,15 @@ void Display_CacheAll(void) * @note Unused qboolean PC_String_Parse_Trans(int handle, const char **out) { - pc_token_t token; + pc_token_t token; - if (!trap_PC_ReadToken(handle, &token)) - { - return qfalse; - } + if (!trap_PC_ReadToken(handle, &token)) + { + return qfalse; + } - *(out) = String_Alloc(DC->translateString(token.string)); - return qtrue; + *(out) = String_Alloc(DC->translateString(token.string)); + return qtrue; } */ @@ -1336,22 +1336,6 @@ void BG_PanelButton_RenderEdit(panel_button_t *button) trap_Cvar_VariableStringBuffer(button->text, buffer, sizeof(buffer)); - if (BG_PanelButtons_GetFocusButton() == button && ((DC->realTime / 1000) % 2)) - { - if (trap_Key_GetOverstrikeMode()) - { - Q_strcat(buffer, sizeof(buffer), "^0|"); - } - else - { - Q_strcat(buffer, sizeof(buffer), "^0_"); - } - } - else - { - Q_strcat(buffer, sizeof(buffer), " "); - } - do { offset++; @@ -1362,27 +1346,18 @@ void BG_PanelButton_RenderEdit(panel_button_t *button) } while (DC->textWidthExt(buffer + offset, button->font->scalex, 0, button->font->font) > button->rect.w); - DC->drawTextExt(button->rect.x, button->rect.y + button->rect.h, button->font->scalex, button->font->scaley, button->font->colour, va("^7%s", buffer + offset), 0, 0, button->font->style, button->font->font); - } - else - { - char *s; - - if (BG_PanelButtons_GetFocusButton() == button && ((DC->realTime / 1000) % 2)) + if (BG_PanelButtons_GetFocusButton() == button) { - if (DC->getOverstrikeMode()) - { - s = va("^7%s^0|", button->text); - } - else - { - s = va("^7%s^0_", button->text); - } + DC->drawTextWithCursorExt(button->rect.x, button->rect.y + button->rect.h, button->font->scalex, button->font->colour, va("%s", buffer + offset), button->data[2], trap_Key_GetOverstrikeMode() ? "_" : "|", offset, button->font->style, button->font->font); } else { - s = va("^7%s ", button->text); // space hack to make the text not blink + DC->drawTextExt(button->rect.x, button->rect.y + button->rect.h, button->font->scalex, button->font->scaley, button->font->colour, va("^7%s", buffer + offset), 0, 0, button->font->style, button->font->font); } + } + else + { + char *s = button->text; do { @@ -1394,7 +1369,14 @@ void BG_PanelButton_RenderEdit(panel_button_t *button) } while (DC->textWidthExt(s + offset, button->font->scalex, 0, button->font->font) > button->rect.w); - DC->drawTextExt(button->rect.x, button->rect.y + button->rect.h, button->font->scalex, button->font->scaley, button->font->colour, s + offset, 0, 0, button->font->style, button->font->font); + if (BG_PanelButtons_GetFocusButton()) + { + DC->drawTextWithCursorExt(button->rect.x, button->rect.y + button->rect.h, button->font->scalex, button->font->colour, s + offset, button->data[2], trap_Key_GetOverstrikeMode() ? "|" : "_", offset, button->font->style, button->font->font); + } + else + { + DC->drawTextExt(button->rect.x, button->rect.y + button->rect.h, button->font->scalex, button->font->scaley, button->font->colour, s + offset, 0, 0, button->font->style, button->font->font); + } } } @@ -1430,7 +1412,7 @@ qboolean BG_PanelButton_EditClick(panel_button_t *button, int key) } else { - char buffer[256]; + char buffer[MAX_EDITFIELD]; char *s = NULL; size_t len, maxlen; qboolean useCvar = button->data[0] ? qfalse : qtrue; @@ -1454,17 +1436,21 @@ qboolean BG_PanelButton_EditClick(panel_button_t *button, int key) if (key == 'h' - 'a' + 1) // ctrl-h is backspace { - if (len) + if (len && button->data[2]) { if (useCvar) { + memmove(&buffer[button->data[2] - 1], &buffer[button->data[2]], len - button->data[2]); buffer[len - 1] = '\0'; - DC->setCVar(button->text, buffer); + trap_Cvar_Set(button->text, buffer); } else { + memmove(&s[button->data[2] - 1], &buffer[button->data[2]], len - button->data[2]); s[len - 1] = '\0'; } + + button->data[2]--; } return qtrue; @@ -1497,21 +1483,108 @@ qboolean BG_PanelButton_EditClick(panel_button_t *button, int key) if (useCvar) { - buffer[len] = (char)key; - buffer[len + 1] = '\0'; + if (button->data[2] == len) + { + buffer[len] = (char)key; + buffer[len + 1] = '\0'; + } + else + { + if (trap_Key_GetOverstrikeMode()) + { + buffer[button->data[2]] = (char)key; + } + else + { + memmove(&buffer[button->data[2] + 1], &buffer[button->data[2]], len - button->data[2]); + buffer[button->data[2]] = (char)key; + buffer[len + 2] = '\0'; + } + } + trap_Cvar_Set(button->text, buffer); } else { - s[len] = (char)key; - s[len + 1] = '\0'; + if (button->data[2] == len) + { + s[len] = (char)key; + s[len + 1] = '\0'; + } + else + { + if (trap_Key_GetOverstrikeMode()) + { + s[button->data[2]] = (char)key; + } + else + { + memmove(&s[button->data[2] + 1], &buffer[button->data[2]], len - button->data[2]); + s[button->data[2]] = (char)key; + s[len + 2] = '\0'; + } + } } + button->data[2]++; + return qtrue; } else { - if (key == K_ENTER || key == K_KP_ENTER) + if (key == K_DEL || key == K_KP_DEL) + { + if (button->data[2] < len) + { + if (useCvar) + { + memmove(&buffer[button->data[2]], &buffer[button->data[2] + 1], len - button->data[2]); + buffer[len] = '\0'; + trap_Cvar_Set(button->text, buffer); + } + else + { + memmove(&s[button->data[2]], &buffer[button->data[2] + 1], len - button->data[2]); + s[len] = '\0'; + } + } + + return qtrue; + } + else if (key == K_RIGHTARROW || key == K_KP_RIGHTARROW) + { + if (button->data[2] < len) + { + button->data[2]++; + } + + return qtrue; + } + else if (key == K_LEFTARROW || key == K_KP_LEFTARROW) + { + if (button->data[2] > 0) + { + button->data[2]--; + } + + return qtrue; + } + else if (key == K_HOME || key == K_KP_HOME) + { + button->data[2] = 0; + return qtrue; + } + else if (key == K_END || key == K_KP_END) + { + button->data[2] = len; + return qtrue; + } + else if (key == K_INS || key == K_KP_INS) + { + trap_Key_SetOverstrikeMode(!trap_Key_GetOverstrikeMode()); + return qtrue; + } + else if (key == K_ENTER || key == K_KP_ENTER) { if (button->onFinish) { diff --git a/src/ui/ui_shared.h b/src/ui/ui_shared.h index f2d69d3f8..6f812c800 100644 --- a/src/ui/ui_shared.h +++ b/src/ui/ui_shared.h @@ -490,6 +490,7 @@ typedef struct float (*getCVarValue)(const char *cvar); void (*setCVar)(const char *cvar, const char *value); void (*drawTextWithCursor)(float x, float y, float scale, vec4_t color, const char *text, int cursorPos, const char *cursor, int limit, int style); + void (*drawTextWithCursorExt)(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 (*setOverstrikeMode)(qboolean b); qboolean (*getOverstrikeMode)(void); void (*startLocalSound)(sfxHandle_t sfx, int channelNum);