test/testmessage.c
author Ryan C. Gordon <icculus@icculus.org>
Fri, 07 Dec 2012 19:59:30 -0500
changeset 6722 37283d4416e0
parent 6614 92925281e7ca
child 6758 2a218048b45f
permissions -rw-r--r--
testmessage should test Unicode strings.
     1 /*
     2   Copyright (C) 1997-2011 Sam Lantinga <slouken@libsdl.org>
     3 
     4   This software is provided 'as-is', without any express or implied
     5   warranty.  In no event will the authors be held liable for any damages
     6   arising from the use of this software.
     7 
     8   Permission is granted to anyone to use this software for any purpose,
     9   including commercial applications, and to alter it and redistribute it
    10   freely.
    11 */
    12 
    13 /* Simple test of the SDL MessageBox API*/
    14 
    15 #include <stdio.h>
    16 #include <stdlib.h>
    17 #include <signal.h>
    18 
    19 #include "SDL.h"
    20 #include "SDL_thread.h"
    21 
    22 static int alive = 0;
    23 
    24 /* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
    25 static void
    26 quit(int rc)
    27 {
    28     SDL_Quit();
    29     exit(rc);
    30 }
    31 
    32 int
    33 main(int argc, char *argv[])
    34 {
    35     int success;
    36 
    37     /* Load the SDL library */
    38     if (SDL_Init(0) < 0) {
    39         fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
    40         return (1);
    41     }
    42 
    43     success = SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR,
    44                 "Simple MessageBox",
    45                 "This is a simple error MessageBox",
    46                 NULL);
    47     if (success == -1) {
    48         printf("Error Presenting MessageBox: %s\n", SDL_GetError());
    49         quit(1);
    50     }
    51 
    52     /* Google says this is Traditional Chinese for "beef with broccoli" */
    53     success = SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR,
    54                 "UTF-8 Simple MessageBox",
    55                 "Unicode text: '牛肉西蘭花' ...",
    56                 NULL);
    57     if (success == -1) {
    58         printf("Error Presenting MessageBox: %s\n", SDL_GetError());
    59         quit(1);
    60     }
    61 
    62     {
    63         const SDL_MessageBoxButtonData buttons[] = {
    64             {
    65                 SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT,
    66                 0,
    67                 "OK"
    68             },{
    69                 SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT,
    70                 1,
    71                 "Cancel"
    72             },
    73         };
    74 
    75         SDL_MessageBoxData data = {
    76             SDL_MESSAGEBOX_INFORMATION,
    77             NULL, // no parent window
    78             "Custom MessageBox",
    79             "This is a custom messagebox",
    80             2,
    81             buttons,
    82             NULL // Default color scheme
    83         };
    84 
    85         int button = -1;
    86         success = SDL_ShowMessageBox(&data, &button);
    87         if (success == -1) {
    88             printf("Error Presenting MessageBox: %s\n", SDL_GetError());
    89             quit(2);
    90         }
    91         printf("Pressed button: %d, %s\n", button, button == 1 ? "Cancel" : "OK");
    92     }
    93 
    94     SDL_Quit();
    95     return (0);
    96 }