Finally got the Win32 API code for shaping to work! Just need to fix SDL_CalculateShapeTree() now!
This commit is contained in:
parent
0a86be6abb
commit
4e4cb86ffe
7 changed files with 37 additions and 25 deletions
|
@ -110,7 +110,7 @@ echo #define SDL_REVISION 0 >"$(ProjectDir)\..\..\include\SDL_revision.h"
|
|||
<Culture>0x0409</Culture>
|
||||
</ResourceCompile>
|
||||
<Link>
|
||||
<AdditionalDependencies>msimg32.lib;winmm.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalDependencies>msvcrt.lib;msimg32.lib;winmm.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<OutputFile>$(IntDir)SDL.dll</OutputFile>
|
||||
<IgnoreAllDefaultLibraries>true</IgnoreAllDefaultLibraries>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
|
|
|
@ -112,7 +112,7 @@ typedef struct SDL_WindowShapeMode {
|
|||
*
|
||||
* \param window The shaped window whose parameters should be set.
|
||||
* \param shape A surface encoding the desired shape for the window.
|
||||
* \param shapeMode The parameters to set for the shaped window.
|
||||
* \param shape_mode The parameters to set for the shaped window.
|
||||
*
|
||||
* \return 0 on success, SDL_INVALID_SHAPE_ARGUMENT on invalid an invalid shape argument, or SDL_NONSHAPEABLE_WINDOW
|
||||
* if the SDL_Window* given does not reference a valid shaped window.
|
||||
|
@ -120,22 +120,22 @@ typedef struct SDL_WindowShapeMode {
|
|||
* \sa SDL_WindowShapeMode
|
||||
* \sa SDL_GetShapedWindowMode.
|
||||
*/
|
||||
extern DECLSPEC int SDLCALL SDL_SetWindowShape(SDL_Window *window,SDL_Surface *shape,SDL_WindowShapeMode *shapeMode);
|
||||
extern DECLSPEC int SDLCALL SDL_SetWindowShape(SDL_Window *window,SDL_Surface *shape,SDL_WindowShapeMode *shape_mode);
|
||||
|
||||
/**
|
||||
* \brief Get the shape parameters of a shaped window.
|
||||
*
|
||||
* \param window The shaped window whose parameters should be retrieved.
|
||||
* \param shapeMode An empty shape-mode structure to fill, or NULL to check whether the window has a shape.
|
||||
* \param shape_mode An empty shape-mode structure to fill, or NULL to check whether the window has a shape.
|
||||
*
|
||||
* \return 0 if the window has a shape and, provided shapeMode was not NULL, shapeMode has been filled with the mode
|
||||
* \return 0 if the window has a shape and, provided shape_mode was not NULL, shape_mode has been filled with the mode
|
||||
* data, SDL_NONSHAPEABLE_WINDOW if the SDL_Window given is not a shaped window, or SDL_WINDOW_LACKS_SHAPE if
|
||||
* the SDL_Window* given is a shapeable window currently lacking a shape.
|
||||
*
|
||||
* \sa SDL_WindowShapeMode
|
||||
* \sa SDL_SetWindowShape
|
||||
*/
|
||||
extern DECLSPEC int SDLCALL SDL_GetShapedWindowMode(SDL_Window *window,SDL_WindowShapeMode *shapeMode);
|
||||
extern DECLSPEC int SDLCALL SDL_GetShapedWindowMode(SDL_Window *window,SDL_WindowShapeMode *shape_mode);
|
||||
|
||||
/* Ends C function definitions when using C++ */
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -32,7 +32,7 @@
|
|||
|
||||
SDL_Window*
|
||||
SDL_CreateShapedWindow(const char *title,unsigned int x,unsigned int y,unsigned int w,unsigned int h,Uint32 flags) {
|
||||
SDL_Window *result = SDL_CreateWindow(title,x,y,w,h,SDL_WINDOW_BORDERLESS | flags & !SDL_WINDOW_FULLSCREEN & !SDL_WINDOW_SHOWN);
|
||||
SDL_Window *result = SDL_CreateWindow(title,x,y,w,h,flags | SDL_WINDOW_BORDERLESS & !SDL_WINDOW_FULLSCREEN & !SDL_WINDOW_SHOWN);
|
||||
if(result != NULL) {
|
||||
result->shaper = result->display->device->shape_driver.CreateShaper(result);
|
||||
if(result->shaper != NULL) {
|
||||
|
@ -226,7 +226,7 @@ SDL_FreeShapeTree(SDL_ShapeTree** shapeTree) {
|
|||
}
|
||||
|
||||
int
|
||||
SDL_SetWindowShape(SDL_Window *window,SDL_Surface *shape,SDL_WindowShapeMode *shapeMode) {
|
||||
SDL_SetWindowShape(SDL_Window *window,SDL_Surface *shape,SDL_WindowShapeMode *shape_mode) {
|
||||
int result;
|
||||
if(window == NULL || !SDL_IsShapedWindow(window))
|
||||
//The window given was not a shapeable window.
|
||||
|
@ -235,9 +235,9 @@ SDL_SetWindowShape(SDL_Window *window,SDL_Surface *shape,SDL_WindowShapeMode *sh
|
|||
//Invalid shape argument.
|
||||
return SDL_INVALID_SHAPE_ARGUMENT;
|
||||
|
||||
if(shapeMode != NULL)
|
||||
window->shaper->mode = *shapeMode;
|
||||
result = window->display->device->shape_driver.SetWindowShape(window->shaper,shape,shapeMode);
|
||||
if(shape_mode != NULL)
|
||||
window->shaper->mode = *shape_mode;
|
||||
result = window->display->device->shape_driver.SetWindowShape(window->shaper,shape,shape_mode);
|
||||
window->shaper->hasshape = SDL_TRUE;
|
||||
if((window->shaper->usershownflag & SDL_WINDOW_SHOWN) == SDL_WINDOW_SHOWN) {
|
||||
SDL_SetWindowPosition(window,window->x,window->y);
|
||||
|
@ -255,9 +255,9 @@ SDL_WindowHasAShape(SDL_Window *window) {
|
|||
}
|
||||
|
||||
int
|
||||
SDL_GetShapedWindowMode(SDL_Window *window,SDL_WindowShapeMode *shapeMode) {
|
||||
SDL_GetShapedWindowMode(SDL_Window *window,SDL_WindowShapeMode *shape_mode) {
|
||||
if(window != NULL && SDL_IsShapedWindow(window)) {
|
||||
if(shapeMode == NULL) {
|
||||
if(shape_mode == NULL) {
|
||||
if(SDL_WindowHasAShape(window))
|
||||
//The window given has a shape.
|
||||
return 0;
|
||||
|
@ -266,7 +266,7 @@ SDL_GetShapedWindowMode(SDL_Window *window,SDL_WindowShapeMode *shapeMode) {
|
|||
return SDL_WINDOW_LACKS_SHAPE;
|
||||
}
|
||||
else {
|
||||
*shapeMode = window->shaper->mode;
|
||||
*shape_mode = window->shaper->mode;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -157,7 +157,7 @@ struct SDL_WindowShaper
|
|||
struct SDL_ShapeDriver
|
||||
{
|
||||
SDL_WindowShaper *(*CreateShaper)(SDL_Window * window);
|
||||
int (*SetWindowShape)(SDL_WindowShaper *shaper,SDL_Surface *shape,SDL_WindowShapeMode *shapeMode);
|
||||
int (*SetWindowShape)(SDL_WindowShaper *shaper,SDL_Surface *shape,SDL_WindowShapeMode *shape_mode);
|
||||
int (*ResizeWindowShape)(SDL_Window *window);
|
||||
};
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
eligottlieb@gmail.com
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "SDL_win32shape.h"
|
||||
#include "SDL_win32video.h"
|
||||
|
||||
|
@ -49,9 +50,15 @@ typedef struct {
|
|||
|
||||
void
|
||||
CombineRectRegions(SDL_ShapeTree* node,void* closure) {
|
||||
char debug_str[200];
|
||||
SDL_ShapeRect* rect_list = *((SDL_ShapeRect**)closure);
|
||||
if(node->kind == OpaqueShape) {
|
||||
SDL_ShapeRect* rect = SDL_malloc(sizeof(SDL_ShapeRect));
|
||||
sprintf_s(&debug_str[0],200,"x: %u y: %u, x+w: %u, y+h: %u\n",
|
||||
node->data.shape.x,node->data.shape.y,
|
||||
node->data.shape.x + node->data.shape.w,node->data.shape.y + node->data.shape.h);
|
||||
OutputDebugStringA(debug_str);
|
||||
OutputDebugStringA("Converting SDL_ShapeTree opaque node to Windows rectangle.\n");
|
||||
rect->corners[0].x = node->data.shape.x; rect->corners[0].y = node->data.shape.y;
|
||||
rect->corners[1].x = node->data.shape.x + node->data.shape.w; rect->corners[1].y = node->data.shape.y;
|
||||
rect->corners[2].x = node->data.shape.x + node->data.shape.w; rect->corners[2].y = node->data.shape.y + node->data.shape.h;
|
||||
|
@ -69,23 +76,24 @@ Uint32 num_shape_rects(SDL_ShapeRect* rect) {
|
|||
}
|
||||
|
||||
int
|
||||
Win32_SetWindowShape(SDL_WindowShaper *shaper,SDL_Surface *shape,SDL_WindowShapeMode *shapeMode) {
|
||||
Win32_SetWindowShape(SDL_WindowShaper *shaper,SDL_Surface *shape,SDL_WindowShapeMode *shape_mode) {
|
||||
SDL_ShapeData *data;
|
||||
HRGN mask_region;
|
||||
SDL_ShapeRect* rects = NULL,*old = NULL;
|
||||
Uint16 num_rects = 0,i = 0;
|
||||
int* polygonVertexNumbers = NULL;
|
||||
POINT* polygons = NULL;
|
||||
char debug_str[200];
|
||||
|
||||
if (shaper == NULL || shape == NULL)
|
||||
return SDL_INVALID_SHAPE_ARGUMENT;
|
||||
if(shape->format->Amask == 0 && shapeMode->mode != ShapeModeColorKey || shape->w != shaper->window->w || shape->h != shaper->window->h)
|
||||
if(shape->format->Amask == 0 && shape_mode->mode != ShapeModeColorKey || shape->w != shaper->window->w || shape->h != shaper->window->h)
|
||||
return SDL_INVALID_SHAPE_ARGUMENT;
|
||||
|
||||
data = (SDL_ShapeData*)shaper->driverdata;
|
||||
if(data->mask_tree != NULL)
|
||||
SDL_FreeShapeTree(&data->mask_tree);
|
||||
data->mask_tree = SDL_CalculateShapeTree(*shapeMode,shape);
|
||||
data->mask_tree = SDL_CalculateShapeTree(*shape_mode,shape);
|
||||
|
||||
SDL_TraverseShapeTree(data->mask_tree,&CombineRectRegions,&rects);
|
||||
num_rects = num_shape_rects(rects);
|
||||
|
@ -94,8 +102,12 @@ Win32_SetWindowShape(SDL_WindowShaper *shaper,SDL_Surface *shape,SDL_WindowShape
|
|||
polygonVertexNumbers[i] = 4;
|
||||
polygons = (POINT*)SDL_malloc(sizeof(POINT)*4*num_rects);
|
||||
for(i=0;i<num_rects*4;i++) {
|
||||
polygons[i] = rects[i / 4].corners[i % 4];
|
||||
polygons[i] = rects->corners[i % 4];
|
||||
if(i % 4 == 3) {
|
||||
sprintf_s(&debug_str[0],200,"x: %u y: %u, x+w: %u, y+h: %u\n",
|
||||
rects->corners[0].x,rects->corners[0].y,
|
||||
rects->corners[2].x,rects->corners[2].y);
|
||||
OutputDebugStringA(debug_str);
|
||||
old = rects;
|
||||
rects = rects->next;
|
||||
SDL_free(old);
|
||||
|
|
|
@ -35,7 +35,7 @@ typedef struct {
|
|||
} SDL_ShapeData;
|
||||
|
||||
extern SDL_WindowShaper* Win32_CreateShaper(SDL_Window * window);
|
||||
extern int Win32_SetWindowShape(SDL_WindowShaper *shaper,SDL_Surface *shape,SDL_WindowShapeMode *shapeMode);
|
||||
extern int Win32_SetWindowShape(SDL_WindowShaper *shaper,SDL_Surface *shape,SDL_WindowShapeMode *shape_mode);
|
||||
extern int Win32_ResizeWindowShape(SDL_Window *window);
|
||||
|
||||
#endif /* _SDL_win32shape_h */
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
#define SHAPED_WINDOW_Y 150
|
||||
#define SHAPED_WINDOW_DIMENSION 640
|
||||
|
||||
#define TICK_INTERVAL 1000/60
|
||||
#define TICK_INTERVAL 1000/10
|
||||
|
||||
typedef struct LoadedPicture {
|
||||
SDL_Surface *surface;
|
||||
|
@ -32,11 +32,11 @@ void render(SDL_Window* window,SDL_Texture *texture,SDL_Rect texture_dimensions)
|
|||
static Uint32 next_time;
|
||||
|
||||
Uint32 time_left() {
|
||||
Uint32 now = SDL_GetTicks();
|
||||
if(next_time <= now)
|
||||
return 0;
|
||||
Uint32 now = SDL_GetTicks();
|
||||
if(next_time <= now)
|
||||
return 0;
|
||||
else
|
||||
return next_time - now;
|
||||
return next_time - now;
|
||||
}
|
||||
|
||||
int main(int argc,char** argv) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue