Mercurial > sdl-ios-xcode
comparison src/video/win32/SDL_win32shape.c @ 4849:0b918c186938
Finally got the Win32 API code for shaping to work! Just need to fix SDL_CalculateShapeTree() now!
author | egottlieb |
---|---|
date | Sat, 14 Aug 2010 16:14:36 -0400 |
parents | 40b46225e3cf |
children | 14870d46ee2d |
comparison
equal
deleted
inserted
replaced
4848:40b46225e3cf | 4849:0b918c186938 |
---|---|
18 | 18 |
19 Eli Gottlieb | 19 Eli Gottlieb |
20 eligottlieb@gmail.com | 20 eligottlieb@gmail.com |
21 */ | 21 */ |
22 | 22 |
23 #include <stdio.h> | |
23 #include "SDL_win32shape.h" | 24 #include "SDL_win32shape.h" |
24 #include "SDL_win32video.h" | 25 #include "SDL_win32video.h" |
25 | 26 |
26 SDL_WindowShaper* | 27 SDL_WindowShaper* |
27 Win32_CreateShaper(SDL_Window * window) { | 28 Win32_CreateShaper(SDL_Window * window) { |
47 void* next; | 48 void* next; |
48 } SDL_ShapeRect; | 49 } SDL_ShapeRect; |
49 | 50 |
50 void | 51 void |
51 CombineRectRegions(SDL_ShapeTree* node,void* closure) { | 52 CombineRectRegions(SDL_ShapeTree* node,void* closure) { |
53 char debug_str[200]; | |
52 SDL_ShapeRect* rect_list = *((SDL_ShapeRect**)closure); | 54 SDL_ShapeRect* rect_list = *((SDL_ShapeRect**)closure); |
53 if(node->kind == OpaqueShape) { | 55 if(node->kind == OpaqueShape) { |
54 SDL_ShapeRect* rect = SDL_malloc(sizeof(SDL_ShapeRect)); | 56 SDL_ShapeRect* rect = SDL_malloc(sizeof(SDL_ShapeRect)); |
57 sprintf_s(&debug_str[0],200,"x: %u y: %u, x+w: %u, y+h: %u\n", | |
58 node->data.shape.x,node->data.shape.y, | |
59 node->data.shape.x + node->data.shape.w,node->data.shape.y + node->data.shape.h); | |
60 OutputDebugStringA(debug_str); | |
61 OutputDebugStringA("Converting SDL_ShapeTree opaque node to Windows rectangle.\n"); | |
55 rect->corners[0].x = node->data.shape.x; rect->corners[0].y = node->data.shape.y; | 62 rect->corners[0].x = node->data.shape.x; rect->corners[0].y = node->data.shape.y; |
56 rect->corners[1].x = node->data.shape.x + node->data.shape.w; rect->corners[1].y = node->data.shape.y; | 63 rect->corners[1].x = node->data.shape.x + node->data.shape.w; rect->corners[1].y = node->data.shape.y; |
57 rect->corners[2].x = node->data.shape.x + node->data.shape.w; rect->corners[2].y = node->data.shape.y + node->data.shape.h; | 64 rect->corners[2].x = node->data.shape.x + node->data.shape.w; rect->corners[2].y = node->data.shape.y + node->data.shape.h; |
58 rect->corners[3].x = node->data.shape.x; rect->corners[3].y = node->data.shape.y + node->data.shape.h; | 65 rect->corners[3].x = node->data.shape.x; rect->corners[3].y = node->data.shape.y + node->data.shape.h; |
59 rect->next = *((SDL_ShapeRect**)closure); | 66 rect->next = *((SDL_ShapeRect**)closure); |
67 else | 74 else |
68 return 1 + num_shape_rects(rect->next); | 75 return 1 + num_shape_rects(rect->next); |
69 } | 76 } |
70 | 77 |
71 int | 78 int |
72 Win32_SetWindowShape(SDL_WindowShaper *shaper,SDL_Surface *shape,SDL_WindowShapeMode *shapeMode) { | 79 Win32_SetWindowShape(SDL_WindowShaper *shaper,SDL_Surface *shape,SDL_WindowShapeMode *shape_mode) { |
73 SDL_ShapeData *data; | 80 SDL_ShapeData *data; |
74 HRGN mask_region; | 81 HRGN mask_region; |
75 SDL_ShapeRect* rects = NULL,*old = NULL; | 82 SDL_ShapeRect* rects = NULL,*old = NULL; |
76 Uint16 num_rects = 0,i = 0; | 83 Uint16 num_rects = 0,i = 0; |
77 int* polygonVertexNumbers = NULL; | 84 int* polygonVertexNumbers = NULL; |
78 POINT* polygons = NULL; | 85 POINT* polygons = NULL; |
86 char debug_str[200]; | |
79 | 87 |
80 if (shaper == NULL || shape == NULL) | 88 if (shaper == NULL || shape == NULL) |
81 return SDL_INVALID_SHAPE_ARGUMENT; | 89 return SDL_INVALID_SHAPE_ARGUMENT; |
82 if(shape->format->Amask == 0 && shapeMode->mode != ShapeModeColorKey || shape->w != shaper->window->w || shape->h != shaper->window->h) | 90 if(shape->format->Amask == 0 && shape_mode->mode != ShapeModeColorKey || shape->w != shaper->window->w || shape->h != shaper->window->h) |
83 return SDL_INVALID_SHAPE_ARGUMENT; | 91 return SDL_INVALID_SHAPE_ARGUMENT; |
84 | 92 |
85 data = (SDL_ShapeData*)shaper->driverdata; | 93 data = (SDL_ShapeData*)shaper->driverdata; |
86 if(data->mask_tree != NULL) | 94 if(data->mask_tree != NULL) |
87 SDL_FreeShapeTree(&data->mask_tree); | 95 SDL_FreeShapeTree(&data->mask_tree); |
88 data->mask_tree = SDL_CalculateShapeTree(*shapeMode,shape); | 96 data->mask_tree = SDL_CalculateShapeTree(*shape_mode,shape); |
89 | 97 |
90 SDL_TraverseShapeTree(data->mask_tree,&CombineRectRegions,&rects); | 98 SDL_TraverseShapeTree(data->mask_tree,&CombineRectRegions,&rects); |
91 num_rects = num_shape_rects(rects); | 99 num_rects = num_shape_rects(rects); |
92 polygonVertexNumbers = (int*)SDL_malloc(sizeof(int)*num_rects); | 100 polygonVertexNumbers = (int*)SDL_malloc(sizeof(int)*num_rects); |
93 for(i=0;i<num_rects;i++) | 101 for(i=0;i<num_rects;i++) |
94 polygonVertexNumbers[i] = 4; | 102 polygonVertexNumbers[i] = 4; |
95 polygons = (POINT*)SDL_malloc(sizeof(POINT)*4*num_rects); | 103 polygons = (POINT*)SDL_malloc(sizeof(POINT)*4*num_rects); |
96 for(i=0;i<num_rects*4;i++) { | 104 for(i=0;i<num_rects*4;i++) { |
97 polygons[i] = rects[i / 4].corners[i % 4]; | 105 polygons[i] = rects->corners[i % 4]; |
98 if(i % 4 == 3) { | 106 if(i % 4 == 3) { |
107 sprintf_s(&debug_str[0],200,"x: %u y: %u, x+w: %u, y+h: %u\n", | |
108 rects->corners[0].x,rects->corners[0].y, | |
109 rects->corners[2].x,rects->corners[2].y); | |
110 OutputDebugStringA(debug_str); | |
99 old = rects; | 111 old = rects; |
100 rects = rects->next; | 112 rects = rects->next; |
101 SDL_free(old); | 113 SDL_free(old); |
102 } | 114 } |
103 } | 115 } |