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