test/testhittesting.c
changeset 8939 caaa7653f02b
parent 8936 59cbb9959346
child 8940 850e149d02d8
equal deleted inserted replaced
8938:c73bac338b90 8939:caaa7653f02b
    16 hitTest(SDL_Window *window, const SDL_Point *pt, void *data)
    16 hitTest(SDL_Window *window, const SDL_Point *pt, void *data)
    17 {
    17 {
    18     int i;
    18     int i;
    19     for (i = 0; i < numareas; i++) {
    19     for (i = 0; i < numareas; i++) {
    20         if (SDL_PointInRect(pt, &areas[i])) {
    20         if (SDL_PointInRect(pt, &areas[i])) {
    21             printf("HIT-TEST: DRAGGABLE\n");
    21             SDL_Log("HIT-TEST: DRAGGABLE\n");
    22             return SDL_HITTEST_DRAGGABLE;
    22             return SDL_HITTEST_DRAGGABLE;
    23         }
    23         }
    24     }
    24     }
    25 
    25 
    26     printf("HIT-TEST: NORMAL\n");
    26     SDL_Log("HIT-TEST: NORMAL\n");
    27     return SDL_HITTEST_NORMAL;
    27     return SDL_HITTEST_NORMAL;
    28 }
    28 }
    29 
    29 
    30 
    30 
    31 int main(int argc, char **argv)
    31 int main(int argc, char **argv)
    38     SDL_Init(SDL_INIT_VIDEO);
    38     SDL_Init(SDL_INIT_VIDEO);
    39     window = SDL_CreateWindow("Drag the red boxes", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 640, 480, SDL_WINDOW_BORDERLESS);
    39     window = SDL_CreateWindow("Drag the red boxes", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 640, 480, SDL_WINDOW_BORDERLESS);
    40     renderer = SDL_CreateRenderer(window, -1, 0);
    40     renderer = SDL_CreateRenderer(window, -1, 0);
    41 
    41 
    42     if (SDL_SetWindowHitTest(window, hitTest, NULL) == -1) {
    42     if (SDL_SetWindowHitTest(window, hitTest, NULL) == -1) {
    43         fprintf(stderr, "Enabling hit-testing failed!\n");
    43         SDL_Log("Enabling hit-testing failed!\n");
    44         SDL_Quit();
    44         SDL_Quit();
    45         return 1;
    45         return 1;
    46     }
    46     }
    47 
    47 
    48     while (!done)
    48     while (!done)
    59             nothing_to_do = 0;
    59             nothing_to_do = 0;
    60 
    60 
    61             switch (e.type)
    61             switch (e.type)
    62             {
    62             {
    63                 case SDL_MOUSEBUTTONDOWN:
    63                 case SDL_MOUSEBUTTONDOWN:
    64                     printf("button down!\n");
    64                     SDL_Log("button down!\n");
    65                     break;
    65                     break;
    66 
    66 
    67                 case SDL_MOUSEBUTTONUP:
    67                 case SDL_MOUSEBUTTONUP:
    68                     printf("button up!\n");
    68                     SDL_Log("button up!\n");
    69                     break;
    69                     break;
    70 
    70 
    71                 case SDL_WINDOWEVENT:
    71                 case SDL_WINDOWEVENT:
    72                     if (e.window.event == SDL_WINDOWEVENT_MOVED) {
    72                     if (e.window.event == SDL_WINDOWEVENT_MOVED) {
    73                         printf("Window event moved to (%d, %d)!\n", (int) e.window.data1, (int) e.window.data2);
    73                         SDL_Log("Window event moved to (%d, %d)!\n", (int) e.window.data1, (int) e.window.data2);
    74                     }
    74                     }
    75                     break;
    75                     break;
    76 
    76 
    77                 case SDL_KEYDOWN:
    77                 case SDL_KEYDOWN:
    78                     if (e.key.keysym.sym == SDLK_ESCAPE) {
    78                     if (e.key.keysym.sym == SDLK_ESCAPE) {