#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "SDL.h"
#include "SDL_test_common.h"
Go to the source code of this file.
|
static Uint8 | dehex (char c) |
|
static Uint8 | dehex2 (char c1, char c2) |
|
static Uint8 | validate_hex (const char *cp, size_t len, Uint32 *np) |
|
static int | unifont_init (const char *fontname) |
|
static void | unifont_make_rgba (Uint8 *src, Uint8 *dst, Uint8 width) |
|
static int | unifont_load_texture (Uint32 textureID) |
|
static Sint32 | unifont_draw_glyph (Uint32 codepoint, int rendererID, SDL_Rect *dstrect) |
|
static void | unifont_cleanup () |
|
size_t | utf8_length (unsigned char c) |
|
char * | utf8_next (char *p) |
|
char * | utf8_advance (char *p, size_t distance) |
|
Uint32 | utf8_decode (char *p, size_t len) |
|
void | usage () |
|
void | InitInput () |
|
void | CleanupVideo () |
|
void | _Redraw (int rendererID) |
|
void | Redraw () |
|
int | main (int argc, char *argv[]) |
|
◆ DEFAULT_FONT
#define DEFAULT_FONT "unifont-9.0.02.hex" |
◆ DEFAULT_PTSIZE
#define DEFAULT_PTSIZE 30 |
◆ MAX_TEXT_LENGTH
#define MAX_TEXT_LENGTH 256 |
◆ UNIFONT_DRAW_SCALE
#define UNIFONT_DRAW_SCALE 2 |
◆ UNIFONT_GLYPHS_IN_ROW
◆ UNIFONT_GLYPHS_IN_TEXTURE
◆ UNIFONT_MAX_CODEPOINT
#define UNIFONT_MAX_CODEPOINT 0x1ffff |
◆ UNIFONT_NUM_GLYPHS
#define UNIFONT_NUM_GLYPHS 0x20000 |
◆ UNIFONT_NUM_TEXTURES
◆ UNIFONT_TEXTURE_PITCH
◆ UNIFONT_TEXTURE_SIZE
◆ UNIFONT_TEXTURE_WIDTH
#define UNIFONT_TEXTURE_WIDTH 512 |
◆ _Redraw()
void _Redraw |
( |
int |
rendererID | ) |
|
Definition at line 466 of file testime.c.
469 SDL_Rect drawnTextRect, cursorRect, underlineRect;
484 drawnTextRect.
w = textSur->
w;
485 drawnTextRect.
h = textSur->
h;
502 drawnTextRect.
y = dstrect.
y;
503 drawnTextRect.
h = dstrect.
h;
508 dstrect.
x += advance;
509 drawnTextRect.
w += advance;
528 cursorRect = drawnTextRect;
529 cursorRect.
x += cursorRect.
w;
531 cursorRect.
h = drawnTextRect.
h;
533 drawnTextRect.
x += drawnTextRect.
w;
554 cursorRect.
x += drawnTextRect.
w;
560 drawnTextRect.
w = textSur->
w;
561 drawnTextRect.
h = textSur->
h;
575 dstrect.
x = drawnTextRect.
x;
579 drawnTextRect.
y = dstrect.
y;
580 drawnTextRect.
h = dstrect.
h;
585 dstrect.
x += advance;
586 drawnTextRect.
w += advance;
588 cursorRect.
x += advance;
596 cursorRect.
y = drawnTextRect.
y;
597 cursorRect.
h = drawnTextRect.
h;
601 underlineRect.
y = drawnTextRect.
y + drawnTextRect.
h - 2;
603 underlineRect.
w = drawnTextRect.
w;
References SDL_Color::a, SDL_Color::b, backColor, cursor, SDL_Color::g, SDL_Surface::h, SDL_Rect::h, i, lineColor, markedRect, markedText, NULL, SDL_Color::r, renderer, SDLTest_CommonState::renderers, SDL_CreateTextureFromSurface, SDL_DestroyTexture, SDL_FreeSurface, SDL_RenderCopy, SDL_RenderFillRect, SDL_SetRenderDrawColor, SDL_SetTextInputRect, SDL_StartTextInput, SDL_StopTextInput, SDL_strlen, state, text, textColor, textRect, unifont_draw_glyph(), UNIFONT_DRAW_SCALE, utf8_advance(), utf8_decode(), utf8_length(), SDL_Surface::w, SDL_Rect::w, SDL_Rect::x, and SDL_Rect::y.
Referenced by Redraw().
◆ CleanupVideo()
◆ dehex()
static Uint8 dehex |
( |
char |
c | ) |
|
|
static |
◆ dehex2()
static Uint8 dehex2 |
( |
char |
c1, |
|
|
char |
c2 |
|
) |
| |
|
static |
◆ InitInput()
◆ main()
int main |
( |
int |
argc, |
|
|
char * |
argv[] |
|
) |
| |
Definition at line 632 of file testime.c.
646 for (
i = 1;
i < argc;
i++) {
649 for (argc--, argv++; argc > 0; argc--, argv++)
651 if (strcmp(argv[0],
"--help") == 0) {
656 else if (strcmp(argv[0],
"--font") == 0)
691 SDL_Log(
"Using font: %s\n", fontname);
710 switch (
event.key.keysym.sym)
727 if ((
text[textlen-1] & 0x80) == 0x00)
730 text[textlen-1]=0x00;
733 if ((
text[textlen-1] & 0xC0) == 0x80)
736 text[textlen-1]=0x00;
739 if ((
text[textlen-1] & 0xC0) == 0xC0)
742 text[textlen-1]=0x00;
757 SDL_Log(
"Keyboard: scancode 0x%08X = %s, keycode 0x%08X = %s\n",
758 event.key.keysym.scancode,
764 if (
event.text.text[0] ==
'\0' ||
event.text.text[0] ==
'\n' ||
768 SDL_Log(
"Keyboard: text input \"%s\"\n",
event.text.text);
782 SDL_Log(
"text editing \"%s\", selected range (%d, %d)\n",
786 cursor =
event.edit.start;
References CleanupVideo(), cursor, DEFAULT_FONT, DEFAULT_PTSIZE, done, i, InitInput(), markedRect, markedText, SDLTest_CommonState::num_windows, Redraw(), renderer, SDLTest_CommonState::renderers, SDL_BLENDMODE_NONE, SDL_GetKeyName, SDL_GetScancodeName, SDL_INIT_VIDEO, SDL_KEYDOWN, SDL_Log, SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, SDL_LogError, SDL_LogSetPriority, SDL_PollEvent, SDL_RenderClear, SDL_SetRenderDrawBlendMode, SDL_SetRenderDrawColor, SDL_strlcat, SDL_strlcpy, SDL_strlen, SDL_TEXTEDITING, SDL_TEXTEDITINGEVENT_TEXT_SIZE, SDL_TEXTINPUT, SDLK_BACKSPACE, SDLK_RETURN, SDLTest_CommonArg(), SDLTest_CommonCreateState(), SDLTest_CommonEvent(), SDLTest_CommonInit(), SDLTest_CommonQuit(), state, text, unifont_init(), usage(), and SDL_Rect::w.
◆ Redraw()
Definition at line 615 of file testime.c.
References _Redraw(), i, NULL, SDLTest_CommonState::num_windows, renderer, SDLTest_CommonState::renderers, SDL_RenderClear, SDL_RenderPresent, SDL_SetRenderDrawColor, state, and SDLTest_CommonState::windows.
Referenced by main().
◆ unifont_cleanup()
static void unifont_cleanup |
( |
| ) |
|
|
static |
Definition at line 345 of file testime.c.
References i, j, NULL, SDLTest_CommonState::num_windows, renderer, SDLTest_CommonState::renderers, SDL_DestroyTexture, SDL_free, state, UNIFONT_NUM_TEXTURES, unifontGlyph, unifontTexture, unifontTextureLoaded, and SDLTest_CommonState::windows.
Referenced by CleanupVideo().
◆ unifont_draw_glyph()
Definition at line 320 of file testime.c.
325 srcrect.
w = srcrect.
h = 16;
References SDL_Rect::h, NULL, SDLTest_CommonState::renderers, SDL_RenderCopy, state, UNIFONT_GLYPHS_IN_ROW, UNIFONT_GLYPHS_IN_TEXTURE, unifont_load_texture(), UNIFONT_MAX_CODEPOINT, UNIFONT_NUM_TEXTURES, unifontGlyph, unifontTexture, unifontTextureLoaded, SDL_Rect::w, UnifontGlyph::width, SDL_Rect::x, and SDL_Rect::y.
Referenced by _Redraw().
◆ unifont_init()
static int unifont_init |
( |
const char * |
fontname | ) |
|
|
static |
Definition at line 102 of file testime.c.
139 int i, codepointHexSize;
140 size_t bytesOverread;
144 bytesRead =
SDL_RWread(hexFile, hexBuffer, 1, 9);
154 if (hexBuffer[2] ==
':')
155 codepointHexSize = 2;
156 else if (hexBuffer[4] ==
':')
157 codepointHexSize = 4;
158 else if (hexBuffer[6] ==
':')
159 codepointHexSize = 6;
160 else if (hexBuffer[8] ==
':')
161 codepointHexSize = 8;
168 if (!
validate_hex((
const char *)hexBuffer, codepointHexSize, &codepoint))
177 bytesOverread = 8 - codepointHexSize;
178 if (codepointHexSize < 8)
179 SDL_memmove(hexBuffer, hexBuffer + codepointHexSize + 1, bytesOverread);
180 bytesRead =
SDL_RWread(hexFile, hexBuffer + bytesOverread, 1, 33 - bytesOverread);
181 if (bytesRead < (33 - bytesOverread))
186 if (hexBuffer[32] ==
'\n')
191 bytesRead =
SDL_RWread(hexFile, hexBuffer + 33, 1, 32);
213 for (
i = 0;
i < glyphWidth * 2;
i++)
220 }
while (bytesRead > 0);
References dehex2(), i, NULL, SDLTest_CommonState::num_windows, SDL_Log, SDL_LOG_CATEGORY_APPLICATION, SDL_LogError, SDL_LogWarn, SDL_malloc, SDL_memmove, SDL_memset, SDL_RWclose, SDL_RWFromFile, SDL_RWread, state, UNIFONT_MAX_CODEPOINT, UNIFONT_NUM_GLYPHS, UNIFONT_NUM_TEXTURES, unifontGlyph, unifontTexture, validate_hex(), and UnifontGlyph::width.
Referenced by main().
◆ unifont_load_texture()
static int unifont_load_texture |
( |
Uint32 |
textureID | ) |
|
|
static |
Definition at line 263 of file testime.c.
275 if (textureRGBA ==
NULL)
311 SDL_Log(
"unifont error: Failed to update texture %u data for renderer %d.\n", textureID,
i);
References i, NULL, SDLTest_CommonState::num_windows, renderer, SDLTest_CommonState::renderers, SDL_BLENDMODE_BLEND, SDL_CreateTexture, SDL_free, SDL_Log, SDL_LOG_CATEGORY_APPLICATION, SDL_LogError, SDL_malloc, SDL_memset, SDL_PIXELFORMAT_ARGB8888, SDL_SetTextureBlendMode, SDL_TEXTUREACCESS_STATIC, SDL_UpdateTexture, state, UNIFONT_GLYPHS_IN_ROW, UNIFONT_GLYPHS_IN_TEXTURE, unifont_make_rgba(), UNIFONT_NUM_TEXTURES, UNIFONT_TEXTURE_PITCH, UNIFONT_TEXTURE_SIZE, UNIFONT_TEXTURE_WIDTH, unifontGlyph, unifontTexture, unifontTextureLoaded, and SDLTest_CommonState::windows.
Referenced by unifont_draw_glyph().
◆ unifont_make_rgba()
◆ usage()
◆ utf8_advance()
char* utf8_advance |
( |
char * |
p, |
|
|
size_t |
distance |
|
) |
| |
◆ utf8_decode()
Definition at line 412 of file testime.c.
422 codepoint = (0xff >>
len) & *
p;
426 codepoint |= 0x3f & *
p;
References i.
Referenced by _Redraw().
◆ utf8_length()
size_t utf8_length |
( |
unsigned char |
c | ) |
|
Definition at line 371 of file testime.c.
373 c = (
unsigned char)(0xff &
c);
376 else if ((
c >> 5) ==0x6)
378 else if ((
c >> 4) == 0xe)
380 else if ((
c >> 3) == 0x1e)
Referenced by _Redraw(), and utf8_next().
◆ utf8_next()
char* utf8_next |
( |
char * |
p | ) |
|
◆ validate_hex()
◆ backColor
◆ cursor
◆ lineColor
◆ markedRect
◆ markedText
◆ state
◆ text
Definition at line 47 of file testime.c.
Referenced by SDL_BApp::_HandleKey(), _Redraw(), clipboard_testClipboardTextFunctions(), clipboard_testSetClipboardText(), InitInput(), main(), print_modifiers(), print_string(), PrintText(), SDL_GetClipboardText(), SDL_LogOutput(), SDL_PrintFloat(), SDL_PrintLong(), SDL_PrintLongLong(), SDL_PrintString(), SDL_PrintUnsignedLong(), SDL_PrintUnsignedLongLong(), SDL_ScanFloat(), SDL_ScanLong(), SDL_ScanLongLong(), SDL_ScanUintPtrT(), SDL_ScanUnsignedLong(), SDL_ScanUnsignedLongLong(), SDL_SendDropText(), SDL_SendEditingText(), SDL_SendKeyboardText(), SDL_SetClipboardText(), SDL_snprintf(), SDL_snprintfcat(), SDL_sscanf(), SDL_vsnprintf(), SDL_vsscanf(), SDLTest_CommonEvent(), SDLTest_CommonInit(), SDLTest_PrintPixelFormat(), SDLTest_PrintRenderer(), SDLTest_PrintRendererFlag(), stdlib_getsetenv(), stdlib_snprintf(), and stdlib_strlcpy().
◆ textColor
◆ textRect
◆ unifontGlyph
◆ unifontTexture
◆ unifontTextureLoaded
#define SDL_RenderPresent
A collection of pixels used in software blitting.
#define UNIFONT_NUM_GLYPHS
@ SDL_LOG_CATEGORY_APPLICATION
GLint GLint GLsizei width
static SDL_Color textColor
#define SDL_SetRenderDrawBlendMode
static SDL_Color backColor
void _Redraw(int rendererID)
static SDL_Color lineColor
#define SDL_RenderFillRect
static SDL_Texture ** unifontTexture
#define SDL_SetTextureBlendMode
SDL_Renderer ** renderers
#define UNIFONT_MAX_CODEPOINT
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
SDLTest_CommonState * SDLTest_CommonCreateState(char **argv, Uint32 flags)
Parse command line parameters and create common state.
void SDLTest_CommonQuit(SDLTest_CommonState *state)
Close test window.
static Uint8 dehex(char c)
#define SDL_StopTextInput
#define SDL_CreateTextureFromSurface
#define SDL_UpdateTexture
static Sint32 unifont_draw_glyph(Uint32 codepoint, int rendererID, SDL_Rect *dstrect)
static void unifont_cleanup()
@ SDL_TEXTUREACCESS_STATIC
#define DEFAULT_WINDOW_WIDTH
int SDLTest_CommonArg(SDLTest_CommonState *state, int index)
Process one common argument.
#define UNIFONT_NUM_TEXTURES
#define UNIFONT_TEXTURE_PITCH
static char text[MAX_TEXT_LENGTH]
static SDLTest_CommonState * state
struct UnifontGlyph * unifontGlyph
@ SDL_PIXELFORMAT_ARGB8888
#define SDL_TEXTEDITINGEVENT_TEXT_SIZE
#define UNIFONT_TEXTURE_SIZE
#define SDL_StartTextInput
static Uint8 unifontTextureLoaded[UNIFONT_NUM_TEXTURES]
#define SDL_DestroyTexture
GLsizei GLsizei GLfloat distance
SDL_bool SDLTest_CommonInit(SDLTest_CommonState *state)
Open test window.
size_t utf8_length(unsigned char c)
#define SDL_GetScancodeName
#define SDL_SetTextInputRect
#define UNIFONT_TEXTURE_WIDTH
#define UNIFONT_GLYPHS_IN_TEXTURE
static SDL_Renderer * renderer
#define SDL_LogSetPriority
static int unifont_init(const char *fontname)
#define UNIFONT_DRAW_SCALE
char * utf8_advance(char *p, size_t distance)
A rectangle, with the origin at the upper left (integer).
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int int in j)
GLenum const void GLbitfield GLsizei numGlyphs
static void unifont_make_rgba(Uint8 *src, Uint8 *dst, Uint8 width)
static int unifont_load_texture(Uint32 textureID)
#define SDL_SetRenderDrawColor
static SDL_Rect markedRect
#define UNIFONT_GLYPHS_IN_ROW
static Uint8 dehex2(char c1, char c2)
Uint32 utf8_decode(char *p, size_t len)
char * utf8_next(char *p)
static char markedText[SDL_TEXTEDITINGEVENT_TEXT_SIZE]
void SDLTest_CommonEvent(SDLTest_CommonState *state, SDL_Event *event, int *done)
Common event handler for test windows.
static Uint8 validate_hex(const char *cp, size_t len, Uint32 *np)
GLenum GLenum GLuint texture
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
#define SDL_CreateTexture