Cleanup add brace (#6545)
* Add braces after if conditions
* More add braces after if conditions
* Add braces after while() conditions
* Fix compilation because of macro being modified
* Add braces to for loop
* Add braces after if/goto
* Move comments up
* Remove extra () in the 'return ...;' statements
* More remove extra () in the 'return ...;' statements
* More remove extra () in the 'return ...;' statements after merge
* Fix inconsistent patterns are xxx == NULL vs !xxx
* More "{}" for "if() break;" and "if() continue;"
* More "{}" after if() short statement
* More "{}" after "if () return;" statement
* More fix inconsistent patterns are xxx == NULL vs !xxx
* Revert some modificaion on SDL_RLEaccel.c
* SDL_RLEaccel: no short statement
* Cleanup 'if' where the bracket is in a new line
* Cleanup 'while' where the bracket is in a new line
* Cleanup 'for' where the bracket is in a new line
* Cleanup 'else' where the bracket is in a new line
This commit is contained in:
220
test/testime.c
220
test/testime.c
@@ -67,12 +67,13 @@ static Uint8 unifontTextureLoaded[UNIFONT_NUM_TEXTURES] = {0};
|
||||
|
||||
static Uint8 dehex(char c)
|
||||
{
|
||||
if (c >= '0' && c <= '9')
|
||||
if (c >= '0' && c <= '9') {
|
||||
return c - '0';
|
||||
else if (c >= 'a' && c <= 'f')
|
||||
} else if (c >= 'a' && c <= 'f') {
|
||||
return c - 'a' + 10;
|
||||
else if (c >= 'A' && c <= 'F')
|
||||
} else if (c >= 'A' && c <= 'F') {
|
||||
return c - 'A' + 10;
|
||||
}
|
||||
return 255;
|
||||
}
|
||||
|
||||
@@ -84,15 +85,16 @@ static Uint8 dehex2(char c1, char c2)
|
||||
static Uint8 validate_hex(const char *cp, size_t len, Uint32 *np)
|
||||
{
|
||||
Uint32 n = 0;
|
||||
for (; len > 0; cp++, len--)
|
||||
{
|
||||
for (; len > 0; cp++, len--) {
|
||||
Uint8 c = dehex(*cp);
|
||||
if (c == 255)
|
||||
if (c == 255) {
|
||||
return 0;
|
||||
}
|
||||
n = (n << 4) | c;
|
||||
}
|
||||
if (np != NULL)
|
||||
if (np != NULL) {
|
||||
*np = n;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -109,8 +111,7 @@ static int unifont_init(const char *fontname)
|
||||
|
||||
/* Allocate memory for the glyph data so the file can be closed after initialization. */
|
||||
unifontGlyph = (struct UnifontGlyph *)SDL_malloc(unifontGlyphSize);
|
||||
if (unifontGlyph == NULL)
|
||||
{
|
||||
if (unifontGlyph == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "unifont: Failed to allocate %d KiB for glyph data.\n", (int)(unifontGlyphSize + 1023) / 1024);
|
||||
return -1;
|
||||
}
|
||||
@@ -118,8 +119,7 @@ static int unifont_init(const char *fontname)
|
||||
|
||||
/* Allocate memory for texture pointers for all renderers. */
|
||||
unifontTexture = (SDL_Texture **)SDL_malloc(unifontTextureSize);
|
||||
if (unifontTexture == NULL)
|
||||
{
|
||||
if (unifontTexture == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "unifont: Failed to allocate %d KiB for texture pointer data.\n", (int)(unifontTextureSize + 1023) / 1024);
|
||||
return -1;
|
||||
}
|
||||
@@ -132,8 +132,7 @@ static int unifont_init(const char *fontname)
|
||||
}
|
||||
hexFile = SDL_RWFromFile(filename, "rb");
|
||||
SDL_free(filename);
|
||||
if (hexFile == NULL)
|
||||
{
|
||||
if (hexFile == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "unifont: Failed to open font file: %s\n", fontname);
|
||||
return -1;
|
||||
}
|
||||
@@ -146,10 +145,10 @@ static int unifont_init(const char *fontname)
|
||||
Uint32 codepoint;
|
||||
|
||||
bytesRead = SDL_RWread(hexFile, hexBuffer, 1, 9);
|
||||
if (numGlyphs > 0 && bytesRead == 0)
|
||||
if (numGlyphs > 0 && bytesRead == 0) {
|
||||
break; /* EOF */
|
||||
if ((numGlyphs == 0 && bytesRead == 0) || (numGlyphs > 0 && bytesRead < 9))
|
||||
{
|
||||
}
|
||||
if ((numGlyphs == 0 && bytesRead == 0) || (numGlyphs > 0 && bytesRead < 9)) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "unifont: Unexpected end of hex file.\n");
|
||||
return -1;
|
||||
}
|
||||
@@ -163,59 +162,54 @@ static int unifont_init(const char *fontname)
|
||||
codepointHexSize = 6;
|
||||
else if (hexBuffer[8] == ':')
|
||||
codepointHexSize = 8;
|
||||
else
|
||||
{
|
||||
else {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "unifont: Could not find codepoint and glyph data separator symbol in hex file on line %d.\n", lineNumber);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!validate_hex((const char *)hexBuffer, codepointHexSize, &codepoint))
|
||||
{
|
||||
if (!validate_hex((const char *)hexBuffer, codepointHexSize, &codepoint)) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "unifont: Malformed hexadecimal number in hex file on line %d.\n", lineNumber);
|
||||
return -1;
|
||||
}
|
||||
if (codepoint > UNIFONT_MAX_CODEPOINT)
|
||||
if (codepoint > UNIFONT_MAX_CODEPOINT) {
|
||||
SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, "unifont: Codepoint on line %d exceeded limit of 0x%x.\n", lineNumber, UNIFONT_MAX_CODEPOINT);
|
||||
}
|
||||
|
||||
/* If there was glyph data read in the last file read, move it to the front of the buffer. */
|
||||
bytesOverread = 8 - codepointHexSize;
|
||||
if (codepointHexSize < 8)
|
||||
if (codepointHexSize < 8) {
|
||||
SDL_memmove(hexBuffer, hexBuffer + codepointHexSize + 1, bytesOverread);
|
||||
}
|
||||
bytesRead = SDL_RWread(hexFile, hexBuffer + bytesOverread, 1, 33 - bytesOverread);
|
||||
if (bytesRead < (33 - bytesOverread))
|
||||
{
|
||||
if (bytesRead < (33 - bytesOverread)) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "unifont: Unexpected end of hex file.\n");
|
||||
return -1;
|
||||
}
|
||||
if (hexBuffer[32] == '\n')
|
||||
glyphWidth = 8;
|
||||
else
|
||||
{
|
||||
else {
|
||||
glyphWidth = 16;
|
||||
bytesRead = SDL_RWread(hexFile, hexBuffer + 33, 1, 32);
|
||||
if (bytesRead < 32)
|
||||
{
|
||||
if (bytesRead < 32) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "unifont: Unexpected end of hex file.\n");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (!validate_hex((const char *)hexBuffer, glyphWidth * 4, NULL))
|
||||
{
|
||||
if (!validate_hex((const char *)hexBuffer, glyphWidth * 4, NULL)) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "unifont: Malformed hexadecimal glyph data in hex file on line %d.\n", lineNumber);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (codepoint <= UNIFONT_MAX_CODEPOINT)
|
||||
{
|
||||
if (codepoint <= UNIFONT_MAX_CODEPOINT) {
|
||||
if (unifontGlyph[codepoint].width > 0)
|
||||
SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, "unifont: Ignoring duplicate codepoint 0x%08" SDL_PRIx32 " in hex file on line %d.\n", codepoint, lineNumber);
|
||||
else
|
||||
{
|
||||
else {
|
||||
unifontGlyph[codepoint].width = glyphWidth;
|
||||
/* Pack the hex data into a more compact form. */
|
||||
for (i = 0; i < glyphWidth * 2; i++)
|
||||
for (i = 0; i < glyphWidth * 2; i++) {
|
||||
unifontGlyph[codepoint].data[i] = dehex2(hexBuffer[i * 2], hexBuffer[i * 2 + 1]);
|
||||
}
|
||||
numGlyphs++;
|
||||
}
|
||||
}
|
||||
@@ -233,20 +227,15 @@ static void unifont_make_rgba(Uint8 *src, Uint8 *dst, Uint8 width)
|
||||
int i, j;
|
||||
Uint8 *row = dst;
|
||||
|
||||
for (i = 0; i < width * 2; i++)
|
||||
{
|
||||
for (i = 0; i < width * 2; i++) {
|
||||
Uint8 data = src[i];
|
||||
for (j = 0; j < 8; j++)
|
||||
{
|
||||
if (data & 0x80)
|
||||
{
|
||||
for (j = 0; j < 8; j++) {
|
||||
if (data & 0x80) {
|
||||
row[0] = textColor.r;
|
||||
row[1] = textColor.g;
|
||||
row[2] = textColor.b;
|
||||
row[3] = textColor.a;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
row[0] = 0;
|
||||
row[1] = 0;
|
||||
row[2] = 0;
|
||||
@@ -256,8 +245,7 @@ static void unifont_make_rgba(Uint8 *src, Uint8 *dst, Uint8 width)
|
||||
row += 4;
|
||||
}
|
||||
|
||||
if (width == 8 || (width == 16 && i % 2 == 1))
|
||||
{
|
||||
if (width == 8 || (width == 16 && i % 2 == 1)) {
|
||||
dst += UNIFONT_TEXTURE_PITCH;
|
||||
row = dst;
|
||||
}
|
||||
@@ -269,26 +257,22 @@ static int unifont_load_texture(Uint32 textureID)
|
||||
int i;
|
||||
Uint8 * textureRGBA;
|
||||
|
||||
if (textureID >= UNIFONT_NUM_TEXTURES)
|
||||
{
|
||||
if (textureID >= UNIFONT_NUM_TEXTURES) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "unifont: Tried to load out of range texture %" SDL_PRIu32 "\n", textureID);
|
||||
return -1;
|
||||
}
|
||||
|
||||
textureRGBA = (Uint8 *)SDL_malloc(UNIFONT_TEXTURE_SIZE);
|
||||
if (textureRGBA == NULL)
|
||||
{
|
||||
if (textureRGBA == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "unifont: Failed to allocate %d MiB for a texture.\n", UNIFONT_TEXTURE_SIZE / 1024 / 1024);
|
||||
return -1;
|
||||
}
|
||||
SDL_memset(textureRGBA, 0, UNIFONT_TEXTURE_SIZE);
|
||||
|
||||
/* Copy the glyphs into memory in RGBA format. */
|
||||
for (i = 0; i < UNIFONT_GLYPHS_IN_TEXTURE; i++)
|
||||
{
|
||||
for (i = 0; i < UNIFONT_GLYPHS_IN_TEXTURE; i++) {
|
||||
Uint32 codepoint = UNIFONT_GLYPHS_IN_TEXTURE * textureID + i;
|
||||
if (unifontGlyph[codepoint].width > 0)
|
||||
{
|
||||
if (unifontGlyph[codepoint].width > 0) {
|
||||
const Uint32 cInTex = codepoint % UNIFONT_GLYPHS_IN_TEXTURE;
|
||||
const size_t offset = (cInTex / UNIFONT_GLYPHS_IN_ROW) * UNIFONT_TEXTURE_PITCH * 16 + (cInTex % UNIFONT_GLYPHS_IN_ROW) * 16 * 4;
|
||||
unifont_make_rgba(unifontGlyph[codepoint].data, textureRGBA + offset, unifontGlyph[codepoint].width);
|
||||
@@ -296,22 +280,20 @@ static int unifont_load_texture(Uint32 textureID)
|
||||
}
|
||||
|
||||
/* Create textures and upload the RGBA data from above. */
|
||||
for (i = 0; i < state->num_windows; ++i)
|
||||
{
|
||||
for (i = 0; i < state->num_windows; ++i) {
|
||||
SDL_Renderer *renderer = state->renderers[i];
|
||||
SDL_Texture *tex = unifontTexture[UNIFONT_NUM_TEXTURES * i + textureID];
|
||||
if (state->windows[i] == NULL || renderer == NULL || tex != NULL)
|
||||
if (state->windows[i] == NULL || renderer == NULL || tex != NULL) {
|
||||
continue;
|
||||
}
|
||||
tex = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STATIC, UNIFONT_TEXTURE_WIDTH, UNIFONT_TEXTURE_WIDTH);
|
||||
if (tex == NULL)
|
||||
{
|
||||
if (tex == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "unifont: Failed to create texture %" SDL_PRIu32 " for renderer %d.\n", textureID, i);
|
||||
return -1;
|
||||
}
|
||||
unifontTexture[UNIFONT_NUM_TEXTURES * i + textureID] = tex;
|
||||
SDL_SetTextureBlendMode(tex, SDL_BLENDMODE_BLEND);
|
||||
if (SDL_UpdateTexture(tex, NULL, textureRGBA, UNIFONT_TEXTURE_PITCH) != 0)
|
||||
{
|
||||
if (SDL_UpdateTexture(tex, NULL, textureRGBA, UNIFONT_TEXTURE_PITCH) != 0) {
|
||||
SDL_Log("unifont error: Failed to update texture %" SDL_PRIu32 " data for renderer %d.\n", textureID, i);
|
||||
}
|
||||
}
|
||||
@@ -336,8 +318,7 @@ static Sint32 unifont_draw_glyph(Uint32 codepoint, int rendererID, SDL_Rect *dst
|
||||
}
|
||||
}
|
||||
texture = unifontTexture[UNIFONT_NUM_TEXTURES * rendererID + textureID];
|
||||
if (texture != NULL)
|
||||
{
|
||||
if (texture != NULL) {
|
||||
const Uint32 cInTex = codepoint % UNIFONT_GLYPHS_IN_TEXTURE;
|
||||
srcrect.x = cInTex % UNIFONT_GLYPHS_IN_ROW * 16;
|
||||
srcrect.y = cInTex / UNIFONT_GLYPHS_IN_ROW * 16;
|
||||
@@ -349,21 +330,22 @@ static Sint32 unifont_draw_glyph(Uint32 codepoint, int rendererID, SDL_Rect *dst
|
||||
static void unifont_cleanup()
|
||||
{
|
||||
int i, j;
|
||||
for (i = 0; i < state->num_windows; ++i)
|
||||
{
|
||||
for (i = 0; i < state->num_windows; ++i) {
|
||||
SDL_Renderer *renderer = state->renderers[i];
|
||||
if (state->windows[i] == NULL || renderer == NULL)
|
||||
if (state->windows[i] == NULL || renderer == NULL) {
|
||||
continue;
|
||||
for (j = 0; j < UNIFONT_NUM_TEXTURES; j++)
|
||||
{
|
||||
}
|
||||
for (j = 0; j < UNIFONT_NUM_TEXTURES; j++) {
|
||||
SDL_Texture *tex = unifontTexture[UNIFONT_NUM_TEXTURES * i + j];
|
||||
if (tex != NULL)
|
||||
if (tex != NULL) {
|
||||
SDL_DestroyTexture(tex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (j = 0; j < UNIFONT_NUM_TEXTURES; j++)
|
||||
unifontTextureLoaded[j] = 0;
|
||||
for (j = 0; j < UNIFONT_NUM_TEXTURES; j++) {
|
||||
unifontTextureLoaded[j] = 0;
|
||||
}
|
||||
|
||||
SDL_free(unifontTexture);
|
||||
SDL_free(unifontGlyph);
|
||||
@@ -391,14 +373,15 @@ char *utf8_next(char *p)
|
||||
{
|
||||
size_t len = utf8_length(*p);
|
||||
size_t i = 0;
|
||||
if (!len)
|
||||
if (!len) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (; i < len; ++i)
|
||||
{
|
||||
for (; i < len; ++i) {
|
||||
++p;
|
||||
if (!*p)
|
||||
if (!*p) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return p;
|
||||
}
|
||||
@@ -406,8 +389,7 @@ char *utf8_next(char *p)
|
||||
char *utf8_advance(char *p, size_t distance)
|
||||
{
|
||||
size_t i = 0;
|
||||
for (; i < distance && p; ++i)
|
||||
{
|
||||
for (; i < distance && p; ++i) {
|
||||
p = utf8_next(p);
|
||||
}
|
||||
return p;
|
||||
@@ -417,20 +399,20 @@ Uint32 utf8_decode(char *p, size_t len)
|
||||
{
|
||||
Uint32 codepoint = 0;
|
||||
size_t i = 0;
|
||||
if (!len)
|
||||
if (!len) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (; i < len; ++i)
|
||||
{
|
||||
for (; i < len; ++i) {
|
||||
if (i == 0)
|
||||
codepoint = (0xff >> len) & *p;
|
||||
else
|
||||
{
|
||||
else {
|
||||
codepoint <<= 6;
|
||||
codepoint |= 0x3f & *p;
|
||||
}
|
||||
if (!*p)
|
||||
if (!*p) {
|
||||
return 0;
|
||||
}
|
||||
p++;
|
||||
}
|
||||
|
||||
@@ -477,8 +459,7 @@ void _Redraw(int rendererID)
|
||||
SDL_SetRenderDrawColor(renderer, backColor.r, backColor.g, backColor.b, backColor.a);
|
||||
SDL_RenderFillRect(renderer,&textRect);
|
||||
|
||||
if (*text)
|
||||
{
|
||||
if (*text) {
|
||||
#ifdef HAVE_SDL_TTF
|
||||
SDL_Surface *textSur = TTF_RenderUTF8_Blended(font, text, textColor);
|
||||
SDL_Texture *texture;
|
||||
@@ -506,8 +487,7 @@ void _Redraw(int rendererID)
|
||||
drawnTextRect.y = dstrect.y;
|
||||
drawnTextRect.h = dstrect.h;
|
||||
|
||||
while ((codepoint = utf8_decode(utext, len = utf8_length(*utext))))
|
||||
{
|
||||
while ((codepoint = utf8_decode(utext, len = utf8_length(*utext)))) {
|
||||
Sint32 advance = unifont_draw_glyph(codepoint, rendererID, &dstrect) * UNIFONT_DRAW_SCALE;
|
||||
dstrect.x += advance;
|
||||
drawnTextRect.w += advance;
|
||||
@@ -518,14 +498,11 @@ void _Redraw(int rendererID)
|
||||
|
||||
markedRect.x = textRect.x + drawnTextRect.w;
|
||||
markedRect.w = textRect.w - drawnTextRect.w;
|
||||
if (markedRect.w < 0)
|
||||
{
|
||||
if (markedRect.w < 0) {
|
||||
/* Stop text input because we cannot hold any more characters */
|
||||
SDL_StopTextInput();
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
SDL_StartTextInput();
|
||||
}
|
||||
|
||||
@@ -540,17 +517,16 @@ void _Redraw(int rendererID)
|
||||
SDL_SetRenderDrawColor(renderer, backColor.r, backColor.g, backColor.b, backColor.a);
|
||||
SDL_RenderFillRect(renderer,&markedRect);
|
||||
|
||||
if (markedText[0])
|
||||
{
|
||||
if (markedText[0]) {
|
||||
#ifdef HAVE_SDL_TTF
|
||||
SDL_Surface *textSur;
|
||||
SDL_Texture *texture;
|
||||
if (cursor)
|
||||
{
|
||||
if (cursor) {
|
||||
char *p = utf8_advance(markedText, cursor);
|
||||
char c = 0;
|
||||
if (!p)
|
||||
if (p == NULL) {
|
||||
p = &markedText[SDL_strlen(markedText)];
|
||||
}
|
||||
|
||||
c = *p;
|
||||
*p = 0;
|
||||
@@ -583,20 +559,19 @@ void _Redraw(int rendererID)
|
||||
drawnTextRect.y = dstrect.y;
|
||||
drawnTextRect.h = dstrect.h;
|
||||
|
||||
while ((codepoint = utf8_decode(utext, len = utf8_length(*utext))))
|
||||
{
|
||||
while ((codepoint = utf8_decode(utext, len = utf8_length(*utext)))) {
|
||||
Sint32 advance = unifont_draw_glyph(codepoint, rendererID, &dstrect) * UNIFONT_DRAW_SCALE;
|
||||
dstrect.x += advance;
|
||||
drawnTextRect.w += advance;
|
||||
if (i < cursor)
|
||||
if (i < cursor) {
|
||||
cursorRect.x += advance;
|
||||
}
|
||||
i++;
|
||||
utext += len;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (cursor > 0)
|
||||
{
|
||||
if (cursor > 0) {
|
||||
cursorRect.y = drawnTextRect.y;
|
||||
cursorRect.h = drawnTextRect.h;
|
||||
}
|
||||
@@ -621,8 +596,9 @@ void Redraw()
|
||||
int i;
|
||||
for (i = 0; i < state->num_windows; ++i) {
|
||||
SDL_Renderer *renderer = state->renderers[i];
|
||||
if (state->windows[i] == NULL)
|
||||
if (state->windows[i] == NULL) {
|
||||
continue;
|
||||
}
|
||||
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0);
|
||||
SDL_RenderClear(renderer);
|
||||
|
||||
@@ -644,21 +620,19 @@ int main(int argc, char *argv[])
|
||||
|
||||
/* Initialize test framework */
|
||||
state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
|
||||
if (!state) {
|
||||
if (state == NULL) {
|
||||
return 1;
|
||||
}
|
||||
for (i = 1; i < argc;i++) {
|
||||
SDLTest_CommonArg(state, i);
|
||||
}
|
||||
for (argc--, argv++; argc > 0; argc--, argv++)
|
||||
{
|
||||
for (argc--, argv++; argc > 0; argc--, argv++) {
|
||||
if (SDL_strcmp(argv[0], "--help") == 0) {
|
||||
usage();
|
||||
return 0;
|
||||
}
|
||||
|
||||
else if (SDL_strcmp(argv[0], "--font") == 0)
|
||||
{
|
||||
else if (SDL_strcmp(argv[0], "--font") == 0) {
|
||||
argc--;
|
||||
argv++;
|
||||
|
||||
@@ -681,8 +655,7 @@ int main(int argc, char *argv[])
|
||||
TTF_Init();
|
||||
|
||||
font = TTF_OpenFont(fontname, DEFAULT_PTSIZE);
|
||||
if (! font)
|
||||
{
|
||||
if (font == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to find font: %s\n", TTF_GetError());
|
||||
return -1;
|
||||
}
|
||||
@@ -719,42 +692,36 @@ int main(int argc, char *argv[])
|
||||
break;
|
||||
case SDLK_BACKSPACE:
|
||||
/* Only delete text if not in editing mode. */
|
||||
if (!markedText[0])
|
||||
{
|
||||
if (!markedText[0]) {
|
||||
size_t textlen = SDL_strlen(text);
|
||||
|
||||
do {
|
||||
if (textlen==0)
|
||||
{
|
||||
if (textlen==0) {
|
||||
break;
|
||||
}
|
||||
if ((text[textlen-1] & 0x80) == 0x00)
|
||||
{
|
||||
if ((text[textlen-1] & 0x80) == 0x00) {
|
||||
/* One byte */
|
||||
text[textlen-1]=0x00;
|
||||
break;
|
||||
}
|
||||
if ((text[textlen-1] & 0xC0) == 0x80)
|
||||
{
|
||||
if ((text[textlen-1] & 0xC0) == 0x80) {
|
||||
/* Byte from the multibyte sequence */
|
||||
text[textlen-1]=0x00;
|
||||
textlen--;
|
||||
}
|
||||
if ((text[textlen-1] & 0xC0) == 0xC0)
|
||||
{
|
||||
if ((text[textlen-1] & 0xC0) == 0xC0) {
|
||||
/* First byte of multibyte sequence */
|
||||
text[textlen-1]=0x00;
|
||||
break;
|
||||
}
|
||||
} while(1);
|
||||
} while (1);
|
||||
|
||||
Redraw();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (done)
|
||||
{
|
||||
if (done) {
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -766,14 +733,15 @@ int main(int argc, char *argv[])
|
||||
break;
|
||||
|
||||
case SDL_TEXTINPUT:
|
||||
if (event.text.text[0] == '\0' || event.text.text[0] == '\n' ||
|
||||
markedRect.w < 0)
|
||||
if (event.text.text[0] == '\0' || event.text.text[0] == '\n' || markedRect.w < 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
SDL_Log("Keyboard: text input \"%s\"\n", event.text.text);
|
||||
|
||||
if (SDL_strlen(text) + SDL_strlen(event.text.text) < sizeof(text))
|
||||
if (SDL_strlen(text) + SDL_strlen(event.text.text) < sizeof(text)) {
|
||||
SDL_strlcat(text, event.text.text, sizeof(text));
|
||||
}
|
||||
|
||||
SDL_Log("text inputed: %s\n", text);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user