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