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
ada38635
Commit
ada38635
authored
Feb 22, 2011
by
Sam Lantinga
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
parent
eb66b35c
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
96 additions
and
0 deletions
+96
-0
SDL_surface.h
include/SDL_surface.h
+2
-0
SDL_surface.c
src/video/SDL_surface.c
+15
-0
SDL_video.c
src/video/SDL_video.c
+4
-0
SDL_cocoavideo.h
src/video/cocoa/SDL_cocoavideo.h
+3
-0
SDL_cocoavideo.m
src/video/cocoa/SDL_cocoavideo.m
+58
-0
SDL_cocoawindow.h
src/video/cocoa/SDL_cocoawindow.h
+1
-0
SDL_cocoawindow.m
src/video/cocoa/SDL_cocoawindow.m
+13
-0
No files found.
include/SDL_surface.h
View file @
ada38635
...
...
@@ -351,6 +351,8 @@ extern DECLSPEC void SDLCALL SDL_GetClipRect(SDL_Surface * surface,
*/
extern
DECLSPEC
SDL_Surface
*
SDLCALL
SDL_ConvertSurface
(
SDL_Surface
*
src
,
SDL_PixelFormat
*
fmt
,
Uint32
flags
);
extern
DECLSPEC
SDL_Surface
*
SDLCALL
SDL_ConvertSurfaceFormat
(
SDL_Surface
*
src
,
Uint32
pixel_format
,
Uint32
flags
);
/**
* \brief Copy a block of pixels of one format to another format
...
...
src/video/SDL_surface.c
View file @
ada38635
...
...
@@ -814,6 +814,21 @@ SDL_ConvertSurface(SDL_Surface * surface, SDL_PixelFormat * format,
return
(
convert
);
}
SDL_Surface
*
SDL_ConvertSurfaceFormat
(
SDL_Surface
*
surface
,
Uint32
pixel_format
,
Uint32
flags
)
{
SDL_PixelFormat
*
fmt
;
SDL_Surface
*
convert
;
fmt
=
SDL_AllocFormat
(
pixel_format
);
if
(
fmt
)
{
convert
=
SDL_ConvertSurface
(
surface
,
fmt
,
flags
);
SDL_FreeFormat
(
fmt
);
}
return
convert
;
}
/*
* Create a surface on the stack for quick blit operations
*/
...
...
src/video/SDL_video.c
View file @
ada38635
...
...
@@ -1300,6 +1300,10 @@ SDL_SetWindowIcon(SDL_Window * window, SDL_Surface * icon)
{
CHECK_WINDOW_MAGIC
(
window
,
);
if
(
!
icon
)
{
return
;
}
if
(
_this
->
SetWindowIcon
)
{
_this
->
SetWindowIcon
(
_this
,
window
,
icon
);
}
...
...
src/video/cocoa/SDL_cocoavideo.h
View file @
ada38635
...
...
@@ -64,6 +64,9 @@ typedef struct SDL_VideoData
Uint32
screensaver_activity
;
}
SDL_VideoData
;
/* Utility functions */
NSImage
*
Cocoa_CreateImage
(
SDL_Surface
*
surface
);
#endif
/* _SDL_cocoavideo_h */
/* vi: set ts=4 sw=4 expandtab: */
src/video/cocoa/SDL_cocoavideo.m
View file @
ada38635
...
...
@@ -21,6 +21,7 @@
*/
#include "SDL_config.h"
#include "SDL_endian.h"
#include "SDL_cocoavideo.h"
#include "SDL_cocoashape.h"
#include "SDL_assert.h"
...
...
@@ -82,6 +83,7 @@ Cocoa_CreateDevice(int devindex)
device
->
CreateWindow
=
Cocoa_CreateWindow
;
device
->
CreateWindowFrom
=
Cocoa_CreateWindowFrom
;
device
->
SetWindowTitle
=
Cocoa_SetWindowTitle
;
device
->
SetWindowIcon
=
Cocoa_SetWindowIcon
;
device
->
SetWindowPosition
=
Cocoa_SetWindowPosition
;
device
->
SetWindowSize
=
Cocoa_SetWindowSize
;
device
->
ShowWindow
=
Cocoa_ShowWindow
;
...
...
@@ -147,6 +149,62 @@ Cocoa_VideoQuit(_THIS)
Cocoa_QuitMouse
(
_this
);
}
/* This function assumes that it's called from within an autorelease pool */
NSImage
*
Cocoa_CreateImage
(
SDL_Surface
*
surface
)
{
SDL_Surface
*
converted
;
NSBitmapImageRep
*
imgrep
;
Uint8
*
pixels
;
int
i
;
NSImage
*
img
;
converted
=
SDL_ConvertSurfaceFormat
(
surface
,
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
SDL_PIXELFORMAT_RGBA8888
,
#else
SDL_PIXELFORMAT_ABGR8888
,
#endif
0
);
if
(
!
converted
)
{
return
nil
;
}
imgrep
=
[[[
NSBitmapImageRep
alloc
]
initWithBitmapDataPlanes
:
NULL
pixelsWide
:
converted
->
w
pixelsHigh
:
converted
->
h
bitsPerSample
:
8
samplesPerPixel:
4
hasAlpha:
YES
isPlanar:
NO
colorSpaceName:
NSDeviceRGBColorSpace
bytesPerRow:
converted
->
pitch
bitsPerPixel:
converted
->
format
->
BitsPerPixel
]
autorelease
];
if
(
imgrep
==
nil
)
{
SDL_FreeSurface
(
converted
);
return
nil
;
}
/* Copy the pixels */
pixels
=
[
imgrep
bitmapData
];
SDL_memcpy
(
pixels
,
converted
->
pixels
,
converted
->
h
*
converted
->
pitch
);
SDL_FreeSurface
(
converted
);
/* Premultiply the alpha channel */
for
(
i
=
(
converted
->
h
*
converted
->
w
);
i
--
;
)
{
Uint8
alpha
=
pixels
[
3
];
pixels
[
0
]
=
(
Uint8
)(((
Uint16
)
pixels
[
0
]
*
alpha
)
/
255
);
pixels
[
1
]
=
(
Uint8
)(((
Uint16
)
pixels
[
1
]
*
alpha
)
/
255
);
pixels
[
2
]
=
(
Uint8
)(((
Uint16
)
pixels
[
2
]
*
alpha
)
/
255
);
pixels
+=
4
;
}
img
=
[[[
NSImage
alloc
]
initWithSize
:
NSMakeSize
(
surface
->
w
,
surface
->
h
)]
autorelease
];
if
(
img
!=
nil
)
{
[
img
addRepresentation
:
imgrep
];
}
return
img
;
}
/*
* Mac OS X assertion support.
...
...
src/video/cocoa/SDL_cocoawindow.h
View file @
ada38635
...
...
@@ -96,6 +96,7 @@ extern int Cocoa_CreateWindow(_THIS, SDL_Window * window);
extern
int
Cocoa_CreateWindowFrom
(
_THIS
,
SDL_Window
*
window
,
const
void
*
data
);
extern
void
Cocoa_SetWindowTitle
(
_THIS
,
SDL_Window
*
window
);
extern
void
Cocoa_SetWindowIcon
(
_THIS
,
SDL_Window
*
window
,
SDL_Surface
*
icon
);
extern
void
Cocoa_SetWindowPosition
(
_THIS
,
SDL_Window
*
window
);
extern
void
Cocoa_SetWindowSize
(
_THIS
,
SDL_Window
*
window
);
extern
void
Cocoa_ShowWindow
(
_THIS
,
SDL_Window
*
window
);
...
...
src/video/cocoa/SDL_cocoawindow.m
View file @
ada38635
...
...
@@ -636,6 +636,19 @@ Cocoa_SetWindowTitle(_THIS, SDL_Window * window)
[
pool
release
];
}
void
Cocoa_SetWindowIcon
(
_THIS
,
SDL_Window
*
window
,
SDL_Surface
*
icon
)
{
NSAutoreleasePool
*
pool
=
[[
NSAutoreleasePool
alloc
]
init
];
NSImage
*
nsimage
=
Cocoa_CreateImage
(
icon
);
if
(
nsimage
)
{
[
NSApp
setApplicationIconImage
:
nsimage
];
}
[
pool
release
];
}
void
Cocoa_SetWindowPosition
(
_THIS
,
SDL_Window
*
window
)
{
...
...
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