Repurpose ST_DrawTextInput into M_DrawTextInputScroll, and move its definition into m_textinput.c. M_DrawTextInput is now a macro using M_DrawTextInputScroll
This commit is contained in:
1 parent
8da59dc288
commit
bb3a65f8ff
5 files changed
+82
-105
No files matched your search
+5
-31
@@ -4980,33 +4980,6 @@ void M_DrawTextBoxFlags(INT32 x, INT32 y, INT32 width, INT32 boxlines, INT32 fla
|
||||
V_DrawFill(x+5, y+5, width*8+6, boxlines*8+6, 239|flags);
|
||||
}
|
||||
|
||||
void M_DrawTextInput(INT32 x, INT32 y, textinput_t *input, INT32 flags)
|
||||
{
|
||||
INT32 skullx = x;
|
||||
|
||||
V_DrawString(x, y, V_ALLOWLOWERCASE|flags, input->buffer);
|
||||
|
||||
// draw text cursor for name
|
||||
if (input->length)
|
||||
skullx = x+V_SubStringWidth(input->buffer, input->cursor, V_ALLOWLOWERCASE);
|
||||
|
||||
if (skullAnimCounter < 4) // blink cursor
|
||||
V_DrawCharacter(skullx, y+3, '_'|flags, false);
|
||||
|
||||
// draw selection
|
||||
if (input->select != input->cursor)
|
||||
{
|
||||
size_t start = min(input->select, input->cursor);
|
||||
size_t end = max(input->select, input->cursor);
|
||||
|
||||
size_t len = end - start;
|
||||
|
||||
INT32 startx = V_SubStringWidth(input->buffer, start, V_ALLOWLOWERCASE);
|
||||
|
||||
V_DrawFill(x+startx, y, V_SubStringWidth(input->buffer+start, len, V_ALLOWLOWERCASE), 8, 103|V_TRANSLUCENT|flags);
|
||||
}
|
||||
}
|
||||
|
||||
// horizontally centered text
|
||||
static void M_CentreText(INT32 y, const char *string)
|
||||
{
|
||||
@@ -10195,7 +10168,8 @@ static void M_StartServerMenu(INT32 choice)
|
||||
// CONNECT VIA IP
|
||||
// ==============
|
||||
|
||||
static char setupm_ip[28];
|
||||
#define SETUPM_IP_MAXSIZE ((28-1)*8)
|
||||
static char setupm_ip[64];
|
||||
static textinput_t setupm_input_ip;
|
||||
#endif
|
||||
|
||||
@@ -10203,8 +10177,8 @@ void M_Multiplayer(INT32 choice)
|
||||
{
|
||||
(void)choice;
|
||||
#ifndef NONET
|
||||
memset(setupm_ip, 0, 28);
|
||||
M_TextInputInit(&setupm_input_ip, setupm_ip, 28);
|
||||
memset(setupm_ip, 0, sizeof(setupm_ip));
|
||||
M_TextInputInit(&setupm_input_ip, setupm_ip, sizeof(setupm_ip));
|
||||
#endif
|
||||
M_SetupNextMenu(&MP_MainDef);
|
||||
}
|
||||
@@ -10243,7 +10217,7 @@ Update the maxplayers label...
|
||||
if (itemOn != 9)
|
||||
V_DrawString(x+8,y+12, V_ALLOWLOWERCASE, setupm_ip);
|
||||
else
|
||||
M_DrawTextInput(x+8, y+12, &setupm_input_ip, 0);
|
||||
M_DrawTextInputScroll(x+8, y+12, &setupm_input_ip, 0, SETUPM_IP_MAXSIZE);
|
||||
#endif
|
||||
|
||||
// character bar, ripped off the color bar :V
|
||||
|
||||
@@ -64,10 +64,6 @@ void M_DrawTextBox(INT32 x, INT32 y, INT32 width, INT32 boxlines);
|
||||
// Same but with extra flags applied
|
||||
void M_DrawTextBoxFlags(INT32 x, INT32 y, INT32 width, INT32 boxlines, INT32 flags);
|
||||
|
||||
// Draw text input
|
||||
typedef struct textinput_s textinput_t;
|
||||
void M_DrawTextInput(INT32 x, INT32 y, textinput_t *input, INT32 flags);
|
||||
|
||||
// Used in d_netcmd to restart time attack
|
||||
void M_ModeAttackRetry(INT32 choice);
|
||||
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
#include "m_textinput.h"
|
||||
#include "m_menu.h" // MAXSTRINGLENGTH
|
||||
#include "v_video.h"
|
||||
#include "r_main.h" // renderisnewtic
|
||||
#include "i_system.h"
|
||||
#include "keys.h"
|
||||
#include "console.h"
|
||||
@@ -132,6 +135,8 @@ void M_TextInputInit(textinput_t *input, char *buffer, size_t buffer_size)
|
||||
input->buffer = buffer;
|
||||
input->buffer_size = buffer_size;
|
||||
|
||||
input->skull = 0;
|
||||
|
||||
M_TextInputClear(input);
|
||||
}
|
||||
|
||||
@@ -314,3 +319,69 @@ boolean M_TextInputHandle(textinput_t *input, INT32 key)
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void M_DrawTextInputScroll(INT32 x, INT32 y, textinput_t *input, INT32 flags, INT32 MAXINPUTWIDTH)
|
||||
{
|
||||
if (renderisnewtic)
|
||||
input->skull++;
|
||||
input->skull %= 8;
|
||||
|
||||
char nametodraw[MAXSTRINGLENGTH*2+1] = {0};
|
||||
|
||||
size_t drawstart = 0;
|
||||
size_t drawend = 0; // Only used for selection
|
||||
|
||||
INT32 skullx = x;
|
||||
|
||||
while (V_SubStringWidth(input->buffer+drawstart, input->cursor-drawstart, V_ALLOWLOWERCASE) > MAXINPUTWIDTH)
|
||||
++drawstart;
|
||||
|
||||
size_t drawlength = V_SubStringLengthToFit(input->buffer+drawstart, MAXINPUTWIDTH+8, V_ALLOWLOWERCASE)+1;
|
||||
drawend = drawstart + drawlength;
|
||||
|
||||
memcpy(nametodraw, input->buffer+drawstart, drawlength);
|
||||
|
||||
if (input->length)
|
||||
skullx += V_SubStringWidth(nametodraw, input->cursor-drawstart, V_ALLOWLOWERCASE);
|
||||
|
||||
V_DrawString(x, y, V_ALLOWLOWERCASE|flags, nametodraw);
|
||||
|
||||
// draw text cursor for name
|
||||
if (input->skull < 4) // blink cursor
|
||||
V_DrawCharacter(skullx, y+3, '_'|flags, false);
|
||||
|
||||
// draw selection
|
||||
if (input->select != input->cursor)
|
||||
{
|
||||
size_t start = min(input->select, input->cursor);
|
||||
size_t end = max(input->select, input->cursor);
|
||||
|
||||
INT32 startx = 0;
|
||||
INT32 width = 0;
|
||||
|
||||
// I couldn't figure out one formula so here's bunch of separate cases
|
||||
if (start < drawstart && end > drawend) // Selection covers whole visible portion of demo name
|
||||
{
|
||||
startx = -2;
|
||||
width = V_StringWidth(nametodraw, V_ALLOWLOWERCASE)+4;
|
||||
}
|
||||
else if (start < drawstart) // Only left side of selection is off visible part
|
||||
{
|
||||
startx = -2;
|
||||
size_t len = (end - start) - (drawstart - start);
|
||||
width = V_SubStringWidth(nametodraw, len, V_ALLOWLOWERCASE)+2;
|
||||
}
|
||||
else if (end > drawend) // Only right side of selection is off visible part
|
||||
{
|
||||
startx = V_SubStringWidth(nametodraw, start-drawstart, V_ALLOWLOWERCASE);
|
||||
width = V_StringWidth(nametodraw+(start-drawstart), V_ALLOWLOWERCASE)+2;
|
||||
}
|
||||
else // All selection is on visible part
|
||||
{
|
||||
startx = V_SubStringWidth(nametodraw, start-drawstart, V_ALLOWLOWERCASE);
|
||||
width = V_SubStringWidth(nametodraw+(start-drawstart), end-start, V_ALLOWLOWERCASE);
|
||||
}
|
||||
|
||||
V_DrawFill(x+startx, y, width, 8, 103|V_TRANSLUCENT|flags);
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,8 @@ typedef struct textinput_s {
|
||||
|
||||
char *buffer;
|
||||
size_t buffer_size;
|
||||
|
||||
unsigned skull;
|
||||
} textinput_t;
|
||||
|
||||
void M_TextInputInit(textinput_t *input, char *buffer, size_t buffer_size);
|
||||
@@ -20,4 +22,7 @@ void M_TextInputSetString(textinput_t *input, const char *c);
|
||||
|
||||
boolean M_TextInputHandle(textinput_t *input, INT32 key);
|
||||
|
||||
#define M_DrawTextInput(x, y, input, flags) M_DrawTextInputScroll((x), (y), (input), (flags), ((input)->buffer_size-1)*8)
|
||||
void M_DrawTextInputScroll(INT32 x, INT32 y, textinput_t *input, INT32 flags, INT32 MAXINPUTWIDTH);
|
||||
|
||||
#endif
|
||||
+1
-70
@@ -829,82 +829,13 @@ static void ST_overlayDrawer(void)
|
||||
}
|
||||
}
|
||||
|
||||
static void ST_DrawTextInput(INT32 x, INT32 y, textinput_t *input, INT32 flags)
|
||||
{
|
||||
static UINT8 skullAnimCounter = 0;
|
||||
static const INT32 MAXINPUTWIDTH = (MAXSTRINGLENGTH-1)*8;
|
||||
|
||||
if (renderisnewtic)
|
||||
skullAnimCounter++;
|
||||
skullAnimCounter %= 8;
|
||||
|
||||
char nametodraw[MAXSTRINGLENGTH*2+1] = {0};
|
||||
|
||||
size_t drawstart = 0;
|
||||
size_t drawend = 0; // Only used for selection
|
||||
|
||||
INT32 skullx = x;
|
||||
|
||||
while (V_SubStringWidth(input->buffer+drawstart, input->cursor-drawstart, V_ALLOWLOWERCASE) > MAXINPUTWIDTH)
|
||||
++drawstart;
|
||||
|
||||
size_t drawlength = V_SubStringLengthToFit(input->buffer+drawstart, MAXINPUTWIDTH+8, V_ALLOWLOWERCASE)+1;
|
||||
drawend = drawstart + drawlength;
|
||||
|
||||
memcpy(nametodraw, input->buffer+drawstart, drawlength);
|
||||
|
||||
if (input->length)
|
||||
skullx += V_SubStringWidth(nametodraw, input->cursor-drawstart, V_ALLOWLOWERCASE);
|
||||
|
||||
V_DrawString(x, y, V_ALLOWLOWERCASE|flags, nametodraw);
|
||||
|
||||
// draw text cursor for name
|
||||
if (skullAnimCounter < 4) // blink cursor
|
||||
V_DrawCharacter(skullx, y+3, '_'|flags, false);
|
||||
|
||||
// draw selection
|
||||
if (input->select != input->cursor)
|
||||
{
|
||||
size_t start = min(input->select, input->cursor);
|
||||
size_t end = max(input->select, input->cursor);
|
||||
|
||||
INT32 startx = 0;
|
||||
INT32 width = 0;
|
||||
|
||||
// I couldn't figure out one formula so here's bunch of separate cases
|
||||
if (start < drawstart && end > drawend) // Selection covers whole visible portion of demo name
|
||||
{
|
||||
startx = -2;
|
||||
width = V_StringWidth(nametodraw, V_ALLOWLOWERCASE)+4;
|
||||
}
|
||||
else if (start < drawstart) // Only left side of selection is off visible part
|
||||
{
|
||||
startx = -2;
|
||||
size_t len = (end - start) - (drawstart - start);
|
||||
width = V_SubStringWidth(nametodraw, len, V_ALLOWLOWERCASE)+2;
|
||||
}
|
||||
else if (end > drawend) // Only right side of selection is off visible part
|
||||
{
|
||||
startx = V_SubStringWidth(nametodraw, start-drawstart, V_ALLOWLOWERCASE);
|
||||
width = V_StringWidth(nametodraw+(start-drawstart), V_ALLOWLOWERCASE)+2;
|
||||
}
|
||||
else // All selection is on visible part
|
||||
{
|
||||
startx = V_SubStringWidth(nametodraw, start-drawstart, V_ALLOWLOWERCASE);
|
||||
width = V_SubStringWidth(nametodraw+(start-drawstart), end-start, V_ALLOWLOWERCASE);
|
||||
}
|
||||
|
||||
V_DrawFill(x+startx, y, width, 8, 103|V_TRANSLUCENT|flags);
|
||||
}
|
||||
}
|
||||
|
||||
void ST_DrawDemoTitleEntry(void)
|
||||
{
|
||||
#define x (BASEVIDWIDTH/2 - 139)
|
||||
#define y (BASEVIDHEIGHT/2)
|
||||
M_DrawTextBox(x, y + 4, MAXSTRINGLENGTH, 1);
|
||||
|
||||
ST_DrawTextInput(x + 8, y + 12, &demo.titlenameinput, 0);
|
||||
M_DrawTextInputScroll(x + 8, y + 12, &demo.titlenameinput, 0, (MAXSTRINGLENGTH-1)*8);
|
||||
|
||||
M_DrawTextBox(x + 30, y - 24, 26, 1);
|
||||
V_DrawString(x + 38, y - 16, V_ALLOWLOWERCASE, "Enter the name of the replay.");
|
||||
|
||||
Reference in new issue
Block a user