test/testdragareas.c
author Ryan C. Gordon <icculus@icculus.org>
Tue, 27 May 2014 01:27:42 -0400
changeset 8931 44d8a2f4b431
permissions -rw-r--r--
First shot at SDL_SetWindowDragAreas().

Only Cocoa implemented right now.
     1 #include <stdio.h>
     2 #include "SDL.h"
     3 
     4 /* !!! FIXME: rewrite this to be wired in to test framework. */
     5 
     6 int main(int argc, char **argv)
     7 {
     8     int done = 0;
     9     SDL_Window *window;
    10     SDL_Renderer *renderer;
    11 
    12     const SDL_Rect drag_areas[] = {
    13         { 20, 20, 100, 100 },
    14         { 200, 70, 100, 100 },
    15         { 400, 90, 100, 100 }
    16     };
    17 
    18     const SDL_Rect *areas = drag_areas;
    19     int numareas = SDL_arraysize(drag_areas);
    20 
    21     /* !!! FIXME: check for errors. */
    22     SDL_Init(SDL_INIT_VIDEO);
    23     window = SDL_CreateWindow("Drag the red boxes", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 640, 480, SDL_WINDOW_BORDERLESS);
    24     renderer = SDL_CreateRenderer(window, -1, 0);
    25 
    26     if (SDL_SetWindowDragAreas(window, areas, numareas) == -1) {
    27         fprintf(stderr, "Setting drag areas failed!\n");
    28         SDL_Quit();
    29         return 1;
    30     }
    31 
    32     while (!done)
    33     {
    34         SDL_SetRenderDrawColor(renderer, 0, 0, 127, 255);
    35         SDL_RenderClear(renderer);
    36         SDL_SetRenderDrawColor(renderer, 255, 0, 0, 255);
    37         SDL_RenderFillRects(renderer, areas, SDL_arraysize(drag_areas));
    38         SDL_RenderPresent(renderer);
    39 
    40         SDL_Event e;
    41         int nothing_to_do = 1;
    42         while (SDL_PollEvent(&e)) {
    43             nothing_to_do = 0;
    44 
    45             switch (e.type)
    46             {
    47                 case SDL_MOUSEBUTTONDOWN:
    48                     printf("button down!\n");
    49                     break;
    50 
    51                 case SDL_MOUSEBUTTONUP:
    52                     printf("button up!\n");
    53                     break;
    54 
    55                 case SDL_WINDOWEVENT:
    56                     if (e.window.event == SDL_WINDOWEVENT_MOVED) {
    57                         printf("Window event moved to (%d, %d)!\n", (int) e.window.data1, (int) e.window.data2);
    58                     }
    59                     break;
    60 
    61                 case SDL_KEYDOWN:
    62                     if (e.key.keysym.sym == SDLK_ESCAPE) {
    63                         done = 1;
    64                     } else if (e.key.keysym.sym == SDLK_x) {
    65                         if (!areas) {
    66                             areas = drag_areas;
    67                             numareas = SDL_arraysize(drag_areas);
    68                         } else {
    69                             areas = NULL;
    70                             numareas = 0;
    71                         }
    72                         if (SDL_SetWindowDragAreas(window, areas, numareas) == -1) {
    73                             fprintf(stderr, "Setting drag areas failed!\n");
    74                             SDL_Quit();
    75                             return 1;
    76                         }
    77                     }
    78                     break;
    79 
    80                 case SDL_QUIT:
    81                     done = 1;
    82                     break;
    83             }
    84         }
    85 
    86         if (nothing_to_do) {
    87             SDL_Delay(50);
    88         }
    89     }
    90 
    91     SDL_Quit();
    92     return 0;
    93 }