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