Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
libSDL
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PocketInsanity
libSDL
Commits
4e4cb86f
Commit
4e4cb86f
authored
Aug 14, 2010
by
egottlieb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Finally got the Win32 API code for shaping to work! Just need to fix SDL_CalculateShapeTree() now!
parent
0a86be6a
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
37 additions
and
25 deletions
+37
-25
SDL_VS2010.vcxproj
VisualC/SDL/SDL_VS2010.vcxproj
+1
-1
SDL_shape.h
include/SDL_shape.h
+5
-5
SDL_shape.c
src/video/SDL_shape.c
+8
-8
SDL_sysvideo.h
src/video/SDL_sysvideo.h
+1
-1
SDL_win32shape.c
src/video/win32/SDL_win32shape.c
+16
-4
SDL_win32shape.h
src/video/win32/SDL_win32shape.h
+1
-1
testshape.c
test/testshape.c
+5
-5
No files found.
VisualC/SDL/SDL_VS2010.vcxproj
View file @
4e4cb86f
...
...
@@ -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>
ms
vcrt.lib;ms
img32.lib;winmm.lib;%(AdditionalDependencies)
</AdditionalDependencies>
<OutputFile>
$(IntDir)SDL.dll
</OutputFile>
<IgnoreAllDefaultLibraries>
true
</IgnoreAllDefaultLibraries>
<GenerateDebugInformation>
true
</GenerateDebugInformation>
...
...
include/SDL_shape.h
View file @
4e4cb86f
...
...
@@ -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 shape
M
ode The parameters to set for the shaped window.
* \param shape
_m
ode 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
*
shape
M
ode
);
extern
DECLSPEC
int
SDLCALL
SDL_SetWindowShape
(
SDL_Window
*
window
,
SDL_Surface
*
shape
,
SDL_WindowShapeMode
*
shape
_m
ode
);
/**
* \brief Get the shape parameters of a shaped window.
*
* \param window The shaped window whose parameters should be retrieved.
* \param shape
M
ode An empty shape-mode structure to fill, or NULL to check whether the window has a shape.
* \param shape
_m
ode 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 shape
Mode was not NULL, shapeM
ode has been filled with the mode
* \return 0 if the window has a shape and, provided shape
_mode was not NULL, shape_m
ode 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
*
shape
M
ode
);
extern
DECLSPEC
int
SDLCALL
SDL_GetShapedWindowMode
(
SDL_Window
*
window
,
SDL_WindowShapeMode
*
shape
_m
ode
);
/* Ends C function definitions when using C++ */
#ifdef __cplusplus
...
...
src/video/SDL_shape.c
View file @
4e4cb86f
...
...
@@ -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
*
shape
M
ode
)
{
SDL_SetWindowShape
(
SDL_Window
*
window
,
SDL_Surface
*
shape
,
SDL_WindowShapeMode
*
shape
_m
ode
)
{
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
(
shape
M
ode
!=
NULL
)
window
->
shaper
->
mode
=
*
shape
M
ode
;
result
=
window
->
display
->
device
->
shape_driver
.
SetWindowShape
(
window
->
shaper
,
shape
,
shape
M
ode
);
if
(
shape
_m
ode
!=
NULL
)
window
->
shaper
->
mode
=
*
shape
_m
ode
;
result
=
window
->
display
->
device
->
shape_driver
.
SetWindowShape
(
window
->
shaper
,
shape
,
shape
_m
ode
);
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
*
shape
M
ode
)
{
SDL_GetShapedWindowMode
(
SDL_Window
*
window
,
SDL_WindowShapeMode
*
shape
_m
ode
)
{
if
(
window
!=
NULL
&&
SDL_IsShapedWindow
(
window
))
{
if
(
shape
M
ode
==
NULL
)
{
if
(
shape
_m
ode
==
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
{
*
shape
M
ode
=
window
->
shaper
->
mode
;
*
shape
_m
ode
=
window
->
shaper
->
mode
;
return
0
;
}
}
...
...
src/video/SDL_sysvideo.h
View file @
4e4cb86f
...
...
@@ -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
*
shape
M
ode
);
int
(
*
SetWindowShape
)(
SDL_WindowShaper
*
shaper
,
SDL_Surface
*
shape
,
SDL_WindowShapeMode
*
shape
_m
ode
);
int
(
*
ResizeWindowShape
)(
SDL_Window
*
window
);
};
...
...
src/video/win32/SDL_win32shape.c
View file @
4e4cb86f
...
...
@@ -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
*
shape
M
ode
)
{
Win32_SetWindowShape
(
SDL_WindowShaper
*
shaper
,
SDL_Surface
*
shape
,
SDL_WindowShapeMode
*
shape
_m
ode
)
{
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
&&
shape
M
ode
->
mode
!=
ShapeModeColorKey
||
shape
->
w
!=
shaper
->
window
->
w
||
shape
->
h
!=
shaper
->
window
->
h
)
if
(
shape
->
format
->
Amask
==
0
&&
shape
_m
ode
->
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
(
*
shape
M
ode
,
shape
);
data
->
mask_tree
=
SDL_CalculateShapeTree
(
*
shape
_m
ode
,
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
);
...
...
src/video/win32/SDL_win32shape.h
View file @
4e4cb86f
...
...
@@ -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
*
shape
M
ode
);
extern
int
Win32_SetWindowShape
(
SDL_WindowShaper
*
shaper
,
SDL_Surface
*
shape
,
SDL_WindowShapeMode
*
shape
_m
ode
);
extern
int
Win32_ResizeWindowShape
(
SDL_Window
*
window
);
#endif
/* _SDL_win32shape_h */
test/testshape.c
View file @
4e4cb86f
...
...
@@ -8,7 +8,7 @@
#define SHAPED_WINDOW_Y 150
#define SHAPED_WINDOW_DIMENSION 640
#define TICK_INTERVAL 1000/
6
0
#define TICK_INTERVAL 1000/
1
0
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
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment