1.Fixed a memory leak inside XInput2 code
2.Replaced XKeycodeToKeysym with XkbKeycodeToKeysym since XKeycodeToKeysym is deprecated in newer X11 version 3.Rewrote testime.c since it was disabled after SDL_compat.c removal 4.Take into account common arguments also in testrelative.c
This commit is contained in:
parent
5c45be466b
commit
f39fe05937
11 changed files with 238 additions and 235 deletions
|
@ -1111,6 +1111,7 @@ XextAddDisplay(XExtensionInfo* a,Display* b,_Xconst char* c,XExtensionHooks* d,i
|
||||||
AC_MSG_RESULT($have_const_param_XextAddDisplay)
|
AC_MSG_RESULT($have_const_param_XextAddDisplay)
|
||||||
|
|
||||||
AC_CHECK_LIB(X11, XGetEventData, AC_DEFINE(SDL_VIDEO_DRIVER_X11_SUPPORTS_GENERIC_EVENTS, 1, [Have XGenericEvent]))
|
AC_CHECK_LIB(X11, XGetEventData, AC_DEFINE(SDL_VIDEO_DRIVER_X11_SUPPORTS_GENERIC_EVENTS, 1, [Have XGenericEvent]))
|
||||||
|
AC_CHECK_LIB(X11, XkbKeycodeToKeysym, AC_DEFINE(SDL_VIDEO_DRIVER_X11_HAS_XKBKEYCODETOKEYSYM, 1, [Have XkbKeycodeToKeysym]))
|
||||||
|
|
||||||
AC_ARG_ENABLE(video-x11-xcursor,
|
AC_ARG_ENABLE(video-x11-xcursor,
|
||||||
AC_HELP_STRING([--enable-video-x11-xcursor], [enable X11 Xcursor support [[default=yes]]]),
|
AC_HELP_STRING([--enable-video-x11-xcursor], [enable X11 Xcursor support [[default=yes]]]),
|
||||||
|
|
|
@ -271,6 +271,7 @@
|
||||||
#undef SDL_VIDEO_DRIVER_X11_XVIDMODE
|
#undef SDL_VIDEO_DRIVER_X11_XVIDMODE
|
||||||
#undef SDL_VIDEO_DRIVER_X11_SUPPORTS_GENERIC_EVENTS
|
#undef SDL_VIDEO_DRIVER_X11_SUPPORTS_GENERIC_EVENTS
|
||||||
#undef SDL_VIDEO_DRIVER_X11_CONST_PARAM_XEXTADDDISPLAY
|
#undef SDL_VIDEO_DRIVER_X11_CONST_PARAM_XEXTADDDISPLAY
|
||||||
|
#undef SDL_VIDEO_DRIVER_X11_HAS_XKBKEYCODETOKEYSYM
|
||||||
|
|
||||||
#undef SDL_VIDEO_RENDER_D3D
|
#undef SDL_VIDEO_RENDER_D3D
|
||||||
#undef SDL_VIDEO_RENDER_OGL
|
#undef SDL_VIDEO_RENDER_OGL
|
||||||
|
|
|
@ -146,6 +146,7 @@
|
||||||
#define SDL_VIDEO_DRIVER_X11_XSHAPE 1
|
#define SDL_VIDEO_DRIVER_X11_XSHAPE 1
|
||||||
#define SDL_VIDEO_DRIVER_X11_XVIDMODE 1
|
#define SDL_VIDEO_DRIVER_X11_XVIDMODE 1
|
||||||
#define SDL_VIDEO_DRIVER_X11_SUPPORTS_GENERIC_EVENTS 1
|
#define SDL_VIDEO_DRIVER_X11_SUPPORTS_GENERIC_EVENTS 1
|
||||||
|
#define SDL_VIDEO_DRIVER_X11_HAS_XKBKEYCODETOKEYSYM 1
|
||||||
|
|
||||||
#ifndef SDL_VIDEO_RENDER_OGL
|
#ifndef SDL_VIDEO_RENDER_OGL
|
||||||
#define SDL_VIDEO_RENDER_OGL 1
|
#define SDL_VIDEO_RENDER_OGL 1
|
||||||
|
|
|
@ -27,6 +27,10 @@
|
||||||
#include <X11/Xutil.h>
|
#include <X11/Xutil.h>
|
||||||
#include <X11/Xatom.h>
|
#include <X11/Xatom.h>
|
||||||
|
|
||||||
|
#if SDL_VIDEO_DRIVER_X11_HAS_XKBKEYCODETOKEYSYM
|
||||||
|
#include <X11/XKBlib.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Apparently some X11 systems can't include this multiple times... */
|
/* Apparently some X11 systems can't include this multiple times... */
|
||||||
#ifndef SDL_INCLUDED_XLIBINT_H
|
#ifndef SDL_INCLUDED_XLIBINT_H
|
||||||
#define SDL_INCLUDED_XLIBINT_H 1
|
#define SDL_INCLUDED_XLIBINT_H 1
|
||||||
|
|
|
@ -265,7 +265,11 @@ X11_DispatchEvent(_THIS)
|
||||||
if (videodata->key_layout[keycode] == SDL_SCANCODE_UNKNOWN) {
|
if (videodata->key_layout[keycode] == SDL_SCANCODE_UNKNOWN) {
|
||||||
int min_keycode, max_keycode;
|
int min_keycode, max_keycode;
|
||||||
XDisplayKeycodes(display, &min_keycode, &max_keycode);
|
XDisplayKeycodes(display, &min_keycode, &max_keycode);
|
||||||
|
#if SDL_VIDEO_DRIVER_X11_HAS_XKBKEYCODETOKEYSYM
|
||||||
|
keysym = XkbKeycodeToKeysym(display, keycode, 0, 0);
|
||||||
|
#else
|
||||||
keysym = XKeycodeToKeysym(display, keycode, 0);
|
keysym = XKeycodeToKeysym(display, keycode, 0);
|
||||||
|
#endif
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"The key you just pressed is not recognized by SDL. To help get this fixed, please report this to the SDL mailing list <sdl@libsdl.org> X11 KeyCode %d (%d), X11 KeySym 0x%lX (%s).\n",
|
"The key you just pressed is not recognized by SDL. To help get this fixed, please report this to the SDL mailing list <sdl@libsdl.org> X11 KeyCode %d (%d), X11 KeySym 0x%lX (%s).\n",
|
||||||
keycode, keycode - min_keycode, keysym,
|
keycode, keycode - min_keycode, keysym,
|
||||||
|
|
|
@ -151,7 +151,11 @@ X11_KeyCodeToSDLKey(Display *display, KeyCode keycode)
|
||||||
unsigned int ucs4;
|
unsigned int ucs4;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
#if SDL_VIDEO_DRIVER_X11_HAS_XKBKEYCODETOKEYSYM
|
||||||
|
keysym = XkbKeycodeToKeysym(display, keycode, 0, 0);
|
||||||
|
#else
|
||||||
keysym = XKeycodeToKeysym(display, keycode, 0);
|
keysym = XKeycodeToKeysym(display, keycode, 0);
|
||||||
|
#endif
|
||||||
if (keysym == NoSymbol) {
|
if (keysym == NoSymbol) {
|
||||||
return SDLK_UNKNOWN;
|
return SDLK_UNKNOWN;
|
||||||
}
|
}
|
||||||
|
@ -232,7 +236,11 @@ X11_InitKeyboard(_THIS)
|
||||||
SDL_GetDefaultKeymap(keymap);
|
SDL_GetDefaultKeymap(keymap);
|
||||||
for (i = min_keycode; i <= max_keycode; ++i) {
|
for (i = min_keycode; i <= max_keycode; ++i) {
|
||||||
KeySym sym;
|
KeySym sym;
|
||||||
|
#if SDL_VIDEO_DRIVER_X11_HAS_XKBKEYCODETOKEYSYM
|
||||||
|
sym = XkbKeycodeToKeysym(data->display, i, 0, 0);
|
||||||
|
#else
|
||||||
sym = XKeycodeToKeysym(data->display, i, 0);
|
sym = XKeycodeToKeysym(data->display, i, 0);
|
||||||
|
#endif
|
||||||
if (sym != NoSymbol) {
|
if (sym != NoSymbol) {
|
||||||
SDL_Keycode key;
|
SDL_Keycode key;
|
||||||
printf("code = %d, sym = 0x%X (%s) ", i - min_keycode,
|
printf("code = %d, sym = 0x%X (%s) ", i - min_keycode,
|
||||||
|
|
|
@ -132,6 +132,14 @@ SDL_X11_SYM(Bool,XGetEventData,(Display* a,XGenericEventCookie* b),(a,b),return)
|
||||||
SDL_X11_SYM(void,XFreeEventData,(Display* a,XGenericEventCookie* b),(a,b),)
|
SDL_X11_SYM(void,XFreeEventData,(Display* a,XGenericEventCookie* b),(a,b),)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if SDL_VIDEO_DRIVER_X11_HAS_XKBKEYCODETOKEYSYM
|
||||||
|
#if NeedWidePrototypes
|
||||||
|
SDL_X11_SYM(KeySym,XkbKeycodeToKeysym,(Display* a,unsigned int b,int c,int d),(a,b,c,d),return)
|
||||||
|
#else
|
||||||
|
SDL_X11_SYM(KeySym,XkbKeycodeToKeysym,(Display* a,KeyCode b,int c,int d),(a,b,c,d),return)
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
#if NeedWidePrototypes
|
#if NeedWidePrototypes
|
||||||
SDL_X11_SYM(KeySym,XKeycodeToKeysym,(Display* a,unsigned int b,int c),(a,b,c),return)
|
SDL_X11_SYM(KeySym,XKeycodeToKeysym,(Display* a,unsigned int b,int c),(a,b,c),return)
|
||||||
#else
|
#else
|
||||||
|
|
|
@ -210,6 +210,7 @@ X11_InitXinput2Multitouch(_THIS) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
XIFreeDeviceInfo(info);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -105,8 +105,8 @@ testthread$(EXE): $(srcdir)/testthread.c
|
||||||
testiconv$(EXE): $(srcdir)/testiconv.c
|
testiconv$(EXE): $(srcdir)/testiconv.c
|
||||||
$(CC) -o $@ $? $(CFLAGS) $(LIBS)
|
$(CC) -o $@ $? $(CFLAGS) $(LIBS)
|
||||||
|
|
||||||
testime$(EXE): $(srcdir)/testime.c
|
testime$(EXE): $(srcdir)/testime.c $(srcdir)/common.c
|
||||||
$(CC) -o $@ $? $(CFLAGS) $(LIBS) @SDL_TTF_LIB@
|
$(CC) -o $@ $(srcdir)/testime.c $(srcdir)/common.c $(CFLAGS) $(LIBS) @SDL_TTF_LIB@
|
||||||
|
|
||||||
testjoystick$(EXE): $(srcdir)/testjoystick.c
|
testjoystick$(EXE): $(srcdir)/testjoystick.c
|
||||||
$(CC) -o $@ $? $(CFLAGS) $(LIBS)
|
$(CC) -o $@ $? $(CFLAGS) $(LIBS)
|
||||||
|
|
278
test/testime.c
278
test/testime.c
|
@ -11,15 +11,6 @@
|
||||||
*/
|
*/
|
||||||
/* A simple program to test the Input Method support in the SDL library (2.0+) */
|
/* A simple program to test the Input Method support in the SDL library (2.0+) */
|
||||||
|
|
||||||
#if 1 /* FIXME: Rework this using the 2.0 API */
|
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
|
||||||
{
|
|
||||||
printf("FIXME\n");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
@ -29,20 +20,22 @@ int main(int argc, char *argv[])
|
||||||
#include "SDL_ttf.h"
|
#include "SDL_ttf.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include "common.h"
|
||||||
|
|
||||||
#define DEFAULT_PTSIZE 30
|
#define DEFAULT_PTSIZE 30
|
||||||
#define DEFAULT_FONT "/System/Library/Fonts/华文细黑.ttf"
|
#define DEFAULT_FONT "/System/Library/Fonts/华文细黑.ttf"
|
||||||
#define MAX_TEXT_LENGTH 256
|
#define MAX_TEXT_LENGTH 256
|
||||||
|
|
||||||
SDL_Surface *screen;
|
static CommonState *state;
|
||||||
|
static SDL_Rect textRect, markedRect;
|
||||||
|
static SDL_Color lineColor = {0,0,0,0};
|
||||||
|
static SDL_Color backColor = {255,255,255,0};
|
||||||
|
static SDL_Color textColor = {0,0,0,0};
|
||||||
|
static char text[MAX_TEXT_LENGTH], markedText[SDL_TEXTEDITINGEVENT_TEXT_SIZE];
|
||||||
|
static int cursor = 0;
|
||||||
#ifdef HAVE_SDL_TTF
|
#ifdef HAVE_SDL_TTF
|
||||||
TTF_Font *font;
|
static TTF_Font *font;
|
||||||
#endif
|
#endif
|
||||||
SDL_Rect textRect, markedRect;
|
|
||||||
Uint32 lineColor, backColor;
|
|
||||||
SDL_Color textColor = { 0, 0, 0 };
|
|
||||||
char text[MAX_TEXT_LENGTH], markedText[SDL_TEXTEDITINGEVENT_TEXT_SIZE];
|
|
||||||
int cursor = 0;
|
|
||||||
|
|
||||||
size_t utf8_length(unsigned char c)
|
size_t utf8_length(unsigned char c)
|
||||||
{
|
{
|
||||||
|
@ -87,75 +80,23 @@ char *utf8_advance(char *p, size_t distance)
|
||||||
|
|
||||||
void usage()
|
void usage()
|
||||||
{
|
{
|
||||||
printf("usage: testime [--font fontfile] [--fullscreen]\n");
|
printf("usage: testime [--font fontfile]\n");
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void InitVideo(int argc, char *argv[])
|
void InitInput()
|
||||||
{
|
{
|
||||||
int width = 640, height = 480;
|
|
||||||
int flags = SDL_HWSURFACE;
|
|
||||||
const char *fontname = DEFAULT_FONT;
|
|
||||||
int fullscreen = 0;
|
|
||||||
|
|
||||||
for (argc--, argv++; argc > 0; argc--, argv++)
|
/* Prepare a rect for text input */
|
||||||
{
|
textRect.x = textRect.y = 100;
|
||||||
if (strcmp(argv[0], "--help") == 0)
|
textRect.w = DEFAULT_WINDOW_WIDTH - 2 * textRect.x;
|
||||||
usage();
|
textRect.h = 50;
|
||||||
|
|
||||||
else if (strcmp(argv[0], "--fullscreen") == 0)
|
text[0] = 0;
|
||||||
fullscreen = 1;
|
markedRect = textRect;
|
||||||
|
markedText[0] = 0;
|
||||||
|
|
||||||
else if (strcmp(argv[0], "--font") == 0)
|
SDL_StartTextInput();
|
||||||
{
|
|
||||||
argc--;
|
|
||||||
argv++;
|
|
||||||
|
|
||||||
if (argc > 0)
|
|
||||||
fontname = argv[0];
|
|
||||||
else
|
|
||||||
usage();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
SDL_setenv("SDL_VIDEO_WINDOW_POS", "center", 1);
|
|
||||||
if (SDL_Init(SDL_INIT_VIDEO) < 0)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "Unable to init SDL: %s\n", SDL_GetError());
|
|
||||||
exit(-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef HAVE_SDL_TTF
|
|
||||||
/* Initialize fonts */
|
|
||||||
TTF_Init();
|
|
||||||
|
|
||||||
font = TTF_OpenFont(fontname, DEFAULT_PTSIZE);
|
|
||||||
if (! font)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "Failed to find font: %s\n", TTF_GetError());
|
|
||||||
exit(-1);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
printf("Using font: %s\n", fontname);
|
|
||||||
atexit(SDL_Quit);
|
|
||||||
|
|
||||||
if (fullscreen)
|
|
||||||
{
|
|
||||||
/* Use the desktop mode */
|
|
||||||
width = 0;
|
|
||||||
height = 0;
|
|
||||||
flags |= SDL_FULLSCREEN;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Create window */
|
|
||||||
screen = SDL_SetVideoMode(width, height, 32, flags);
|
|
||||||
if (screen == NULL)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "Unable to set %dx%d video: %s\n",
|
|
||||||
width, height, SDL_GetError());
|
|
||||||
exit(-1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CleanupVideo()
|
void CleanupVideo()
|
||||||
|
@ -167,51 +108,25 @@ void CleanupVideo()
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void InitInput()
|
|
||||||
{
|
|
||||||
backColor = SDL_MapRGB(screen->format, 0xFF, 0xFF, 0xFF);
|
|
||||||
lineColor = SDL_MapRGB(screen->format, 0x0, 0x0, 0x0);
|
|
||||||
|
|
||||||
/* Prepare a rect for text input */
|
void _Redraw(SDL_Renderer * renderer) {
|
||||||
textRect.x = textRect.y = 100;
|
|
||||||
textRect.w = screen->w - 2 * textRect.x;
|
|
||||||
textRect.h = 50;
|
|
||||||
|
|
||||||
text[0] = 0;
|
|
||||||
markedRect = textRect;
|
|
||||||
markedText[0] = 0;
|
|
||||||
|
|
||||||
SDL_StartTextInput();
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef HAVE_SDL_TTF
|
|
||||||
static void RenderText(SDL_Surface *sur,
|
|
||||||
TTF_Font *font,
|
|
||||||
const char *text,
|
|
||||||
int x, int y,
|
|
||||||
SDL_Color color)
|
|
||||||
{
|
|
||||||
if (text && *text) {
|
|
||||||
SDL_Surface *textSur = TTF_RenderUTF8_Blended(font, text, color);
|
|
||||||
SDL_Rect dest = { x, y, textSur->w, textSur->h };
|
|
||||||
|
|
||||||
SDL_BlitSurface(textSur, NULL, sur, &dest);
|
|
||||||
SDL_FreeSurface(textSur);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void Redraw()
|
|
||||||
{
|
|
||||||
int w = 0, h = textRect.h;
|
int w = 0, h = textRect.h;
|
||||||
SDL_Rect cursorRect, underlineRect;
|
SDL_Rect cursorRect, underlineRect;
|
||||||
|
|
||||||
SDL_FillRect(screen, &textRect, backColor);
|
SDL_SetRenderDrawColor(renderer, 255,255,255,255);
|
||||||
|
SDL_RenderFillRect(renderer,&textRect);
|
||||||
|
|
||||||
#ifdef HAVE_SDL_TTF
|
#ifdef HAVE_SDL_TTF
|
||||||
if (*text)
|
if (*text)
|
||||||
{
|
{
|
||||||
RenderText(screen, font, text, textRect.x, textRect.y, textColor);
|
SDL_Surface *textSur = TTF_RenderUTF8_Blended(font, text, textColor);
|
||||||
|
SDL_Rect dest = {textRect.x, textRect.y, textSur->w, textSur->h };
|
||||||
|
|
||||||
|
SDL_Texture *texture = SDL_CreateTextureFromSurface(renderer,textSur);
|
||||||
|
SDL_FreeSurface(textSur);
|
||||||
|
|
||||||
|
SDL_RenderCopy(renderer,texture,NULL,&dest);
|
||||||
|
SDL_DestroyTexture(texture);
|
||||||
TTF_SizeUTF8(font, text, &w, &h);
|
TTF_SizeUTF8(font, text, &w, &h);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -220,7 +135,6 @@ void Redraw()
|
||||||
markedRect.w = textRect.w - w;
|
markedRect.w = textRect.w - w;
|
||||||
if (markedRect.w < 0)
|
if (markedRect.w < 0)
|
||||||
{
|
{
|
||||||
SDL_Flip(screen);
|
|
||||||
// Stop text input because we cannot hold any more characters
|
// Stop text input because we cannot hold any more characters
|
||||||
SDL_StopTextInput();
|
SDL_StopTextInput();
|
||||||
return;
|
return;
|
||||||
|
@ -234,7 +148,9 @@ void Redraw()
|
||||||
cursorRect.w = 2;
|
cursorRect.w = 2;
|
||||||
cursorRect.h = h;
|
cursorRect.h = h;
|
||||||
|
|
||||||
SDL_FillRect(screen, &markedRect, backColor);
|
SDL_SetRenderDrawColor(renderer, 255,255,255,255);
|
||||||
|
SDL_RenderFillRect(renderer,&markedRect);
|
||||||
|
|
||||||
if (markedText[0])
|
if (markedText[0])
|
||||||
{
|
{
|
||||||
#ifdef HAVE_SDL_TTF
|
#ifdef HAVE_SDL_TTF
|
||||||
|
@ -251,8 +167,14 @@ void Redraw()
|
||||||
cursorRect.x += w;
|
cursorRect.x += w;
|
||||||
*p = c;
|
*p = c;
|
||||||
}
|
}
|
||||||
RenderText(screen, font, markedText, markedRect.x, markedRect.y, textColor);
|
SDL_Surface *textSur = TTF_RenderUTF8_Blended(font, markedText, textColor);
|
||||||
|
SDL_Rect dest = {markedRect.x, markedRect.y, textSur->w, textSur->h };
|
||||||
TTF_SizeUTF8(font, markedText, &w, &h);
|
TTF_SizeUTF8(font, markedText, &w, &h);
|
||||||
|
SDL_Texture *texture = SDL_CreateTextureFromSurface(renderer,textSur);
|
||||||
|
SDL_FreeSurface(textSur);
|
||||||
|
|
||||||
|
SDL_RenderCopy(renderer,texture,NULL,&dest);
|
||||||
|
SDL_DestroyTexture(texture);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
underlineRect = markedRect;
|
underlineRect = markedRect;
|
||||||
|
@ -260,49 +182,102 @@ void Redraw()
|
||||||
underlineRect.h = 2;
|
underlineRect.h = 2;
|
||||||
underlineRect.w = w;
|
underlineRect.w = w;
|
||||||
|
|
||||||
SDL_FillRect(screen, &underlineRect, lineColor);
|
SDL_SetRenderDrawColor(renderer, 0,0,0,0);
|
||||||
|
SDL_RenderFillRect(renderer,&markedRect);
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_FillRect(screen, &cursorRect, lineColor);
|
SDL_SetRenderDrawColor(renderer, 0,0,0,0);
|
||||||
|
SDL_RenderFillRect(renderer,&cursorRect);
|
||||||
SDL_Flip(screen);
|
|
||||||
|
|
||||||
SDL_SetTextInputRect(&markedRect);
|
SDL_SetTextInputRect(&markedRect);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void Redraw() {
|
||||||
HotKey_ToggleFullScreen(void)
|
int i;
|
||||||
{
|
for (i = 0; i < state->num_windows; ++i) {
|
||||||
SDL_Surface *screen;
|
SDL_Renderer *renderer = state->renderers[i];
|
||||||
|
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0);
|
||||||
|
SDL_RenderClear(renderer);
|
||||||
|
|
||||||
screen = SDL_GetVideoSurface();
|
_Redraw(renderer);
|
||||||
if (SDL_WM_ToggleFullScreen(screen)) {
|
|
||||||
printf("Toggled fullscreen mode - now %s\n",
|
SDL_RenderPresent(renderer);
|
||||||
(screen->flags & SDL_FULLSCREEN) ? "fullscreen" : "windowed");
|
|
||||||
} else {
|
|
||||||
printf("Unable to toggle fullscreen mode\n");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[]) {
|
||||||
{
|
int i, done;
|
||||||
SDL_Event event;
|
SDL_Event event;
|
||||||
int done = 0;
|
const char *fontname = DEFAULT_FONT;
|
||||||
|
|
||||||
|
/* Initialize test framework */
|
||||||
|
state = CommonCreateState(argv, SDL_INIT_VIDEO);
|
||||||
|
if (!state) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
for (i = 1; i < argc;i++) {
|
||||||
|
CommonArg(state, i);
|
||||||
|
}
|
||||||
|
for (argc--, argv++; argc > 0; argc--, argv++)
|
||||||
|
{
|
||||||
|
if (strcmp(argv[0], "--help") == 0) {
|
||||||
|
usage();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (strcmp(argv[0], "--font") == 0)
|
||||||
|
{
|
||||||
|
argc--;
|
||||||
|
argv++;
|
||||||
|
|
||||||
|
if (argc > 0)
|
||||||
|
fontname = argv[0];
|
||||||
|
else {
|
||||||
|
usage();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!CommonInit(state)) {
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef HAVE_SDL_TTF
|
||||||
|
/* Initialize fonts */
|
||||||
|
TTF_Init();
|
||||||
|
|
||||||
|
font = TTF_OpenFont(fontname, DEFAULT_PTSIZE);
|
||||||
|
if (! font)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "Failed to find font: %s\n", TTF_GetError());
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
printf("Using font: %s\n", fontname);
|
||||||
|
atexit(SDL_Quit);
|
||||||
|
|
||||||
InitVideo(argc, argv);
|
|
||||||
InitInput();
|
InitInput();
|
||||||
|
/* Create the windows and initialize the renderers */
|
||||||
|
for (i = 0; i < state->num_windows; ++i) {
|
||||||
|
SDL_Renderer *renderer = state->renderers[i];
|
||||||
|
SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_NONE);
|
||||||
|
SDL_SetRenderDrawColor(renderer, 0xA0, 0xA0, 0xA0, 0xFF);
|
||||||
|
SDL_RenderClear(renderer);
|
||||||
|
}
|
||||||
Redraw();
|
Redraw();
|
||||||
|
/* Main render loop */
|
||||||
while (! done && SDL_WaitEvent(&event))
|
done = 0;
|
||||||
{
|
while (!done) {
|
||||||
switch (event.type)
|
/* Check for events */
|
||||||
{
|
while (SDL_PollEvent(&event)) {
|
||||||
case SDL_KEYDOWN:
|
CommonEvent(state, &event, &done);
|
||||||
|
switch(event.type) {
|
||||||
|
case SDL_KEYDOWN: {
|
||||||
switch (event.key.keysym.sym)
|
switch (event.key.keysym.sym)
|
||||||
{
|
{
|
||||||
case SDLK_ESCAPE:
|
|
||||||
done = 1;
|
|
||||||
break;
|
|
||||||
case SDLK_RETURN:
|
case SDLK_RETURN:
|
||||||
text[0]=0x00;
|
text[0]=0x00;
|
||||||
Redraw();
|
Redraw();
|
||||||
|
@ -379,19 +354,16 @@ int main(int argc, char *argv[])
|
||||||
cursor = event.edit.start;
|
cursor = event.edit.start;
|
||||||
Redraw();
|
Redraw();
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case SDL_QUIT:
|
|
||||||
done = 1;
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
CleanupVideo();
|
CleanupVideo();
|
||||||
|
CommonQuit(state);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
/* vi: set ts=4 sw=4 expandtab: */
|
/* vi: set ts=4 sw=4 expandtab: */
|
||||||
|
|
|
@ -41,6 +41,9 @@ main(int argc, char *argv[])
|
||||||
if (!state) {
|
if (!state) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
for (i = 1; i < argc;i++) {
|
||||||
|
CommonArg(state, i);
|
||||||
|
}
|
||||||
if (!CommonInit(state)) {
|
if (!CommonInit(state)) {
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue