mirror of
https://github.com/love2d/megasource.git
synced 2026-08-17 19:24:09 +02:00
Update SDL2 to version 2.28.1.
This commit is contained in:
+47
-38
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
@@ -49,8 +49,8 @@ print_string(char **text, size_t *maxlen, const char *fmt, ...)
|
||||
len = SDL_vsnprintf(*text, *maxlen, fmt, ap);
|
||||
if (len > 0) {
|
||||
*text += len;
|
||||
if ( ((size_t) len) < *maxlen ) {
|
||||
*maxlen -= (size_t) len;
|
||||
if (((size_t)len) < *maxlen) {
|
||||
*maxlen -= (size_t)len;
|
||||
} else {
|
||||
*maxlen = 0;
|
||||
}
|
||||
@@ -68,30 +68,42 @@ print_modifiers(char **text, size_t *maxlen)
|
||||
print_string(text, maxlen, " (none)");
|
||||
return;
|
||||
}
|
||||
if (mod & KMOD_LSHIFT)
|
||||
if (mod & KMOD_LSHIFT) {
|
||||
print_string(text, maxlen, " LSHIFT");
|
||||
if (mod & KMOD_RSHIFT)
|
||||
}
|
||||
if (mod & KMOD_RSHIFT) {
|
||||
print_string(text, maxlen, " RSHIFT");
|
||||
if (mod & KMOD_LCTRL)
|
||||
}
|
||||
if (mod & KMOD_LCTRL) {
|
||||
print_string(text, maxlen, " LCTRL");
|
||||
if (mod & KMOD_RCTRL)
|
||||
}
|
||||
if (mod & KMOD_RCTRL) {
|
||||
print_string(text, maxlen, " RCTRL");
|
||||
if (mod & KMOD_LALT)
|
||||
}
|
||||
if (mod & KMOD_LALT) {
|
||||
print_string(text, maxlen, " LALT");
|
||||
if (mod & KMOD_RALT)
|
||||
}
|
||||
if (mod & KMOD_RALT) {
|
||||
print_string(text, maxlen, " RALT");
|
||||
if (mod & KMOD_LGUI)
|
||||
}
|
||||
if (mod & KMOD_LGUI) {
|
||||
print_string(text, maxlen, " LGUI");
|
||||
if (mod & KMOD_RGUI)
|
||||
}
|
||||
if (mod & KMOD_RGUI) {
|
||||
print_string(text, maxlen, " RGUI");
|
||||
if (mod & KMOD_NUM)
|
||||
}
|
||||
if (mod & KMOD_NUM) {
|
||||
print_string(text, maxlen, " NUM");
|
||||
if (mod & KMOD_CAPS)
|
||||
}
|
||||
if (mod & KMOD_CAPS) {
|
||||
print_string(text, maxlen, " CAPS");
|
||||
if (mod & KMOD_MODE)
|
||||
}
|
||||
if (mod & KMOD_MODE) {
|
||||
print_string(text, maxlen, " MODE");
|
||||
if (mod & KMOD_SCROLL)
|
||||
}
|
||||
if (mod & KMOD_SCROLL) {
|
||||
print_string(text, maxlen, " SCROLL");
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -109,7 +121,7 @@ PrintModifierState()
|
||||
}
|
||||
|
||||
static void
|
||||
PrintKey(SDL_Keysym * sym, SDL_bool pressed, SDL_bool repeat)
|
||||
PrintKey(SDL_Keysym *sym, SDL_bool pressed, SDL_bool repeat)
|
||||
{
|
||||
char message[512];
|
||||
char *spot;
|
||||
@@ -121,17 +133,17 @@ PrintKey(SDL_Keysym * sym, SDL_bool pressed, SDL_bool repeat)
|
||||
/* Print the keycode, name and state */
|
||||
if (sym->sym) {
|
||||
print_string(&spot, &left,
|
||||
"Key %s: scancode %d = %s, keycode 0x%08X = %s ",
|
||||
pressed ? "pressed " : "released",
|
||||
sym->scancode,
|
||||
SDL_GetScancodeName(sym->scancode),
|
||||
sym->sym, SDL_GetKeyName(sym->sym));
|
||||
"Key %s: scancode %d = %s, keycode 0x%08X = %s ",
|
||||
pressed ? "pressed " : "released",
|
||||
sym->scancode,
|
||||
SDL_GetScancodeName(sym->scancode),
|
||||
sym->sym, SDL_GetKeyName(sym->sym));
|
||||
} else {
|
||||
print_string(&spot, &left,
|
||||
"Unknown Key (scancode %d = %s) %s ",
|
||||
sym->scancode,
|
||||
SDL_GetScancodeName(sym->scancode),
|
||||
pressed ? "pressed " : "released");
|
||||
"Unknown Key (scancode %d = %s) %s ",
|
||||
sym->scancode,
|
||||
SDL_GetScancodeName(sym->scancode),
|
||||
pressed ? "pressed " : "released");
|
||||
}
|
||||
print_modifiers(&spot, &left);
|
||||
if (repeat) {
|
||||
@@ -147,16 +159,14 @@ PrintText(const char *eventtype, const char *text)
|
||||
char expanded[1024];
|
||||
|
||||
expanded[0] = '\0';
|
||||
for ( spot = text; *spot; ++spot )
|
||||
{
|
||||
for (spot = text; *spot; ++spot) {
|
||||
size_t length = SDL_strlen(expanded);
|
||||
SDL_snprintf(expanded + length, sizeof(expanded) - length, "\\x%.2x", (unsigned char)*spot);
|
||||
(void)SDL_snprintf(expanded + length, sizeof(expanded) - length, "\\x%.2x", (unsigned char)*spot);
|
||||
}
|
||||
SDL_Log("%s Text (%s): \"%s%s\"\n", eventtype, expanded, *text == '"' ? "\\" : "", text);
|
||||
}
|
||||
|
||||
void
|
||||
loop()
|
||||
void loop()
|
||||
{
|
||||
SDL_Event event;
|
||||
/* Check for events */
|
||||
@@ -238,8 +248,7 @@ loop()
|
||||
#endif
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
/* Enable standard application logging */
|
||||
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
|
||||
@@ -253,23 +262,23 @@ main(int argc, char *argv[])
|
||||
/* Initialize SDL */
|
||||
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
|
||||
return (1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Set 640x480 video mode */
|
||||
window = SDL_CreateWindow("CheckKeys Test",
|
||||
SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
|
||||
640, 480, 0);
|
||||
if (!window) {
|
||||
if (window == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create 640x480 window: %s\n",
|
||||
SDL_GetError());
|
||||
SDL_GetError());
|
||||
quit(2);
|
||||
}
|
||||
|
||||
renderer = SDL_CreateRenderer(window, -1, 0);
|
||||
if (!renderer) {
|
||||
if (renderer == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create renderer: %s\n",
|
||||
SDL_GetError());
|
||||
SDL_GetError());
|
||||
quit(2);
|
||||
}
|
||||
|
||||
@@ -298,7 +307,7 @@ main(int argc, char *argv[])
|
||||
#endif
|
||||
|
||||
SDL_Quit();
|
||||
return (0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
||||
Reference in New Issue
Block a user