test/testmessage.c
author Sam Lantinga <slouken@libsdl.org>
Tue, 30 Oct 2012 10:11:25 -0700
changeset 6614 92925281e7ca
child 6722 37283d4416e0
permissions -rw-r--r--
tree 46b4d59cbfb1
parent adac5aad395d
author Edward Rudd <urkle@outoforder.cc> 1351362890 14400
committer Edward Rudd <urkle@outoforder.cc> 1351362890 14400
revision 6611
branch default

add test to show off the new MessageBox API
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
slouken@6614
    52
    {
slouken@6614
    53
        const SDL_MessageBoxButtonData buttons[] = {
slouken@6614
    54
            {
slouken@6614
    55
                SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT,
slouken@6614
    56
                0,
slouken@6614
    57
                "OK"
slouken@6614
    58
            },{
slouken@6614
    59
                SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT,
slouken@6614
    60
                1,
slouken@6614
    61
                "Cancel"
slouken@6614
    62
            },
slouken@6614
    63
        };
slouken@6614
    64
slouken@6614
    65
        SDL_MessageBoxData data = {
slouken@6614
    66
            SDL_MESSAGEBOX_INFORMATION,
slouken@6614
    67
            NULL, // no parent window
slouken@6614
    68
            "Custom MessageBox",
slouken@6614
    69
            "This is a custom messagebox",
slouken@6614
    70
            2,
slouken@6614
    71
            buttons,
slouken@6614
    72
            NULL // Default color scheme
slouken@6614
    73
        };
slouken@6614
    74
slouken@6614
    75
        int button = -1;
slouken@6614
    76
        success = SDL_ShowMessageBox(&data, &button);
slouken@6614
    77
        if (success == -1) {
slouken@6614
    78
            printf("Error Presenting MessageBox: %s\n", SDL_GetError());
slouken@6614
    79
            quit(2);
slouken@6614
    80
        }
slouken@6614
    81
        printf("Pressed button: %d, %s\n", button, button == 1 ? "Cancel" : "OK");
slouken@6614
    82
    }
slouken@6614
    83
slouken@6614
    84
    SDL_Quit();
slouken@6614
    85
    return (0);
slouken@6614
    86
}