tree 46b4d59cbfb1
authorSam Lantinga <slouken@libsdl.org>
Tue, 30 Oct 2012 10:11:25 -0700
changeset 661492925281e7ca
parent 6613 0a8672b04b00
child 6615 d7a463bde4d7
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
test/Makefile.in
test/testmessage.c
     1.1 --- a/test/Makefile.in	Tue Oct 30 10:07:32 2012 -0700
     1.2 +++ b/test/Makefile.in	Tue Oct 30 10:11:25 2012 -0700
     1.3 @@ -47,6 +47,7 @@
     1.4  	testwm2$(EXE) \
     1.5  	torturethread$(EXE) \
     1.6  	testrendercopyex$(EXE) \
     1.7 +	testmessage$(EXE) \
     1.8  
     1.9  all: Makefile $(TARGETS)
    1.10  
    1.11 @@ -189,7 +190,10 @@
    1.12  
    1.13  testrendercopyex$(EXE): $(srcdir)/testrendercopyex.c $(srcdir)/common.c
    1.14  	$(CC) -o $@ $^ $(CFLAGS) $(LIBS) @MATHLIB@
    1.15 -	
    1.16 +
    1.17 +testmessage$(EXE): $(srcdir)/testmessage.c
    1.18 +	$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
    1.19 +
    1.20  clean:
    1.21  	rm -f $(TARGETS)
    1.22  
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/test/testmessage.c	Tue Oct 30 10:11:25 2012 -0700
     2.3 @@ -0,0 +1,86 @@
     2.4 +/*
     2.5 +  Copyright (C) 1997-2011 Sam Lantinga <slouken@libsdl.org>
     2.6 +
     2.7 +  This software is provided 'as-is', without any express or implied
     2.8 +  warranty.  In no event will the authors be held liable for any damages
     2.9 +  arising from the use of this software.
    2.10 +
    2.11 +  Permission is granted to anyone to use this software for any purpose,
    2.12 +  including commercial applications, and to alter it and redistribute it
    2.13 +  freely.
    2.14 +*/
    2.15 +
    2.16 +/* Simple test of the SDL MessageBox API*/
    2.17 +
    2.18 +#include <stdio.h>
    2.19 +#include <stdlib.h>
    2.20 +#include <signal.h>
    2.21 +
    2.22 +#include "SDL.h"
    2.23 +#include "SDL_thread.h"
    2.24 +
    2.25 +static int alive = 0;
    2.26 +
    2.27 +/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
    2.28 +static void
    2.29 +quit(int rc)
    2.30 +{
    2.31 +    SDL_Quit();
    2.32 +    exit(rc);
    2.33 +}
    2.34 +
    2.35 +int
    2.36 +main(int argc, char *argv[])
    2.37 +{
    2.38 +    int success;
    2.39 +
    2.40 +    /* Load the SDL library */
    2.41 +    if (SDL_Init(0) < 0) {
    2.42 +        fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
    2.43 +        return (1);
    2.44 +    }
    2.45 +
    2.46 +    success = SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR,
    2.47 +                "Simple MessageBox",
    2.48 +                "This is a simple error MessageBox",
    2.49 +                NULL);
    2.50 +    if (success == -1) {
    2.51 +        printf("Error Presenting MessageBox: %s\n", SDL_GetError());
    2.52 +        quit(1);
    2.53 +    }
    2.54 +
    2.55 +    {
    2.56 +        const SDL_MessageBoxButtonData buttons[] = {
    2.57 +            {
    2.58 +                SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT,
    2.59 +                0,
    2.60 +                "OK"
    2.61 +            },{
    2.62 +                SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT,
    2.63 +                1,
    2.64 +                "Cancel"
    2.65 +            },
    2.66 +        };
    2.67 +
    2.68 +        SDL_MessageBoxData data = {
    2.69 +            SDL_MESSAGEBOX_INFORMATION,
    2.70 +            NULL, // no parent window
    2.71 +            "Custom MessageBox",
    2.72 +            "This is a custom messagebox",
    2.73 +            2,
    2.74 +            buttons,
    2.75 +            NULL // Default color scheme
    2.76 +        };
    2.77 +
    2.78 +        int button = -1;
    2.79 +        success = SDL_ShowMessageBox(&data, &button);
    2.80 +        if (success == -1) {
    2.81 +            printf("Error Presenting MessageBox: %s\n", SDL_GetError());
    2.82 +            quit(2);
    2.83 +        }
    2.84 +        printf("Pressed button: %d, %s\n", button, button == 1 ? "Cancel" : "OK");
    2.85 +    }
    2.86 +
    2.87 +    SDL_Quit();
    2.88 +    return (0);
    2.89 +}