test/testwm2.c
author Gabriel Jacobo <gabomdq@gmail.com>
Tue, 20 Aug 2013 20:34:40 -0300
changeset 7663 53fe1b64eb2d
parent 7639 9406b7dd2f2d
child 8149 681eb46b8ac4
permissions -rw-r--r--
More non C89 compliant comments
     1 /*
     2   Copyright (C) 1997-2013 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 #include <stdlib.h>
    14 #include <stdio.h>
    15 
    16 #include "SDL_test_common.h"
    17 
    18 static SDLTest_CommonState *state;
    19 
    20 /* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
    21 static void
    22 quit(int rc)
    23 {
    24     SDLTest_CommonQuit(state);
    25     exit(rc);
    26 }
    27 
    28 int
    29 main(int argc, char *argv[])
    30 {
    31     static const char *cursorNames[] = {
    32         "arrow",
    33         "ibeam",
    34         "wait",
    35         "crosshair",
    36         "waitarrow",
    37         "sizeNWSE",
    38         "sizeNESW",
    39         "sizeWE",
    40         "sizeNS",
    41         "sizeALL",
    42         "NO",
    43         "hand",
    44     };
    45 
    46     int i, done;
    47     SDL_Event event;
    48     int system_cursor = -1;
    49     SDL_Cursor *cursor = NULL;
    50 
    51 	/* Enable standard application logging */
    52     SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
    53 
    54     SDL_assert(SDL_arraysize(cursorNames) == SDL_NUM_SYSTEM_CURSORS);
    55 
    56     /* Initialize test framework */
    57     state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
    58     if (!state) {
    59         return 1;
    60     }
    61     state->skip_renderer = SDL_TRUE;
    62     for (i = 1; i < argc;) {
    63         int consumed;
    64 
    65         consumed = SDLTest_CommonArg(state, i);
    66         if (consumed == 0) {
    67             consumed = -1;
    68         }
    69         if (consumed < 0) {
    70             SDL_Log("Usage: %s %s\n", argv[0], SDLTest_CommonUsage(state));
    71             quit(1);
    72         }
    73         i += consumed;
    74     }
    75     if (!SDLTest_CommonInit(state)) {
    76         quit(2);
    77     }
    78 
    79     /* Main render loop */
    80     done = 0;
    81     while (!done) {
    82         /* Check for events */
    83         while (SDL_PollEvent(&event)) {
    84             SDLTest_CommonEvent(state, &event, &done);
    85 
    86             if (event.type == SDL_WINDOWEVENT) {
    87                 if (event.window.event == SDL_WINDOWEVENT_RESIZED) {
    88                     SDL_Window *window = SDL_GetWindowFromID(event.window.windowID);
    89                     if (window) {
    90                         SDL_Log("Window %d resized to %dx%d\n",
    91                             event.window.windowID,
    92                             event.window.data1,
    93                             event.window.data2);
    94                     }
    95                 }
    96                 if (event.window.event == SDL_WINDOWEVENT_MOVED) {
    97                     SDL_Window *window = SDL_GetWindowFromID(event.window.windowID);
    98                     if (window) {
    99                         SDL_Log("Window %d moved to %d,%d (display %s)\n",
   100                             event.window.windowID,
   101                             event.window.data1,
   102                             event.window.data2,
   103                             SDL_GetDisplayName(SDL_GetWindowDisplayIndex(window)));
   104                     }
   105                 }
   106             }
   107             if (event.type == SDL_KEYUP) {
   108                 SDL_bool updateCursor = SDL_FALSE;
   109 
   110                 if (event.key.keysym.sym == SDLK_LEFT) {
   111                     --system_cursor;
   112                     if (system_cursor < 0) {
   113                         system_cursor = SDL_NUM_SYSTEM_CURSORS - 1;
   114                     }
   115                     updateCursor = SDL_TRUE;
   116                 } else if (event.key.keysym.sym == SDLK_RIGHT) {
   117                     ++system_cursor;
   118                     if (system_cursor >= SDL_NUM_SYSTEM_CURSORS) {
   119                         system_cursor = 0;
   120                     }
   121                     updateCursor = SDL_TRUE;
   122                 }
   123                 if (updateCursor) {
   124                     SDL_Log("Changing cursor to \"%s\"", cursorNames[system_cursor]);
   125                     SDL_FreeCursor(cursor);
   126                     cursor = SDL_CreateSystemCursor((SDL_SystemCursor)system_cursor);
   127                     SDL_SetCursor(cursor);
   128                 }
   129             }
   130         }
   131     }
   132     SDL_FreeCursor(cursor);
   133 
   134     quit(0);
   135     /* keep the compiler happy ... */
   136     return(0);
   137 }
   138 
   139 /* vi: set ts=4 sw=4 expandtab: */