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
768312f0
Commit
768312f0
authored
Mar 10, 2011
by
Sam Lantinga
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added screenshot support for tests using the common framework.
parent
4f4a283d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
49 additions
and
3 deletions
+49
-3
common.c
test/common.c
+49
-3
No files found.
test/common.c
View file @
768312f0
...
@@ -977,6 +977,41 @@ PrintEvent(SDL_Event * event)
...
@@ -977,6 +977,41 @@ PrintEvent(SDL_Event * event)
fprintf
(
stderr
,
"
\n
"
);
fprintf
(
stderr
,
"
\n
"
);
}
}
static
void
ScreenShot
(
SDL_Renderer
*
renderer
)
{
SDL_Rect
viewport
;
SDL_Surface
*
surface
;
if
(
!
renderer
)
{
return
;
}
SDL_RenderGetViewport
(
renderer
,
&
viewport
);
surface
=
SDL_CreateRGBSurface
(
0
,
viewport
.
w
,
viewport
.
h
,
24
,
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
0x00FF0000
,
0x0000FF00
,
0x000000FF
,
#else
0x000000FF
,
0x0000FF00
,
0x00FF0000
,
#endif
0x00000000
);
if
(
!
surface
)
{
fprintf
(
stderr
,
"Couldn't create surface: %s
\n
"
,
SDL_GetError
());
return
;
}
if
(
SDL_RenderReadPixels
(
renderer
,
NULL
,
surface
->
format
->
format
,
surface
->
pixels
,
surface
->
pitch
)
<
0
)
{
fprintf
(
stderr
,
"Couldn't read screen: %s
\n
"
,
SDL_GetError
());
return
;
}
if
(
SDL_SaveBMP
(
surface
,
"screenshot.bmp"
)
<
0
)
{
fprintf
(
stderr
,
"Couldn't save screenshot.bmp: %s
\n
"
,
SDL_GetError
());
return
;
}
}
void
void
CommonEvent
(
CommonState
*
state
,
SDL_Event
*
event
,
int
*
done
)
CommonEvent
(
CommonState
*
state
,
SDL_Event
*
event
,
int
*
done
)
{
{
...
@@ -991,9 +1026,9 @@ CommonEvent(CommonState * state, SDL_Event * event, int *done)
...
@@ -991,9 +1026,9 @@ CommonEvent(CommonState * state, SDL_Event * event, int *done)
switch
(
event
->
window
.
event
)
{
switch
(
event
->
window
.
event
)
{
case
SDL_WINDOWEVENT_CLOSE
:
case
SDL_WINDOWEVENT_CLOSE
:
{
{
SDL_Window
*
pW
indow
=
SDL_GetWindowFromID
(
event
->
window
.
windowID
);
SDL_Window
*
w
indow
=
SDL_GetWindowFromID
(
event
->
window
.
windowID
);
if
(
pWindow
)
{
if
(
window
)
{
SDL_DestroyWindow
(
pWindow
);
SDL_DestroyWindow
(
window
);
}
}
}
}
break
;
break
;
...
@@ -1002,6 +1037,17 @@ CommonEvent(CommonState * state, SDL_Event * event, int *done)
...
@@ -1002,6 +1037,17 @@ CommonEvent(CommonState * state, SDL_Event * event, int *done)
case
SDL_KEYDOWN
:
case
SDL_KEYDOWN
:
switch
(
event
->
key
.
keysym
.
sym
)
{
switch
(
event
->
key
.
keysym
.
sym
)
{
/* Add hotkeys here */
/* Add hotkeys here */
case
SDLK_PRINTSCREEN
:
{
SDL_Window
*
window
=
SDL_GetWindowFromID
(
event
->
key
.
windowID
);
if
(
window
)
{
for
(
i
=
0
;
i
<
state
->
num_windows
;
++
i
)
{
if
(
window
==
state
->
windows
[
i
])
{
ScreenShot
(
state
->
renderers
[
i
]);
}
}
}
}
break
;
case
SDLK_c
:
case
SDLK_c
:
if
(
event
->
key
.
keysym
.
mod
&
KMOD_CTRL
)
{
if
(
event
->
key
.
keysym
.
mod
&
KMOD_CTRL
)
{
/* Ctrl-C copy awesome text! */
/* Ctrl-C copy awesome text! */
...
...
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