2001-04-26 16:45:43 +00:00
|
|
|
/*
|
|
|
|
SDL - Simple DirectMedia Layer
|
2008-12-08 00:27:32 +00:00
|
|
|
Copyright (C) 1997-2009 Sam Lantinga
|
2001-04-26 16:45:43 +00:00
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
2006-02-01 06:32:25 +00:00
|
|
|
modify it under the terms of the GNU Lesser General Public
|
2001-04-26 16:45:43 +00:00
|
|
|
License as published by the Free Software Foundation; either
|
2006-02-01 06:32:25 +00:00
|
|
|
version 2.1 of the License, or (at your option) any later version.
|
2001-04-26 16:45:43 +00:00
|
|
|
|
|
|
|
This library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
2006-02-01 06:32:25 +00:00
|
|
|
Lesser General Public License for more details.
|
2001-04-26 16:45:43 +00:00
|
|
|
|
2006-02-01 06:32:25 +00:00
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
|
|
License along with this library; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
2001-04-26 16:45:43 +00:00
|
|
|
|
|
|
|
Sam Lantinga
|
2001-12-14 12:38:15 +00:00
|
|
|
slouken@libsdl.org
|
2001-04-26 16:45:43 +00:00
|
|
|
*/
|
2006-02-21 08:46:50 +00:00
|
|
|
#include "SDL_config.h"
|
2001-04-26 16:45:43 +00:00
|
|
|
|
|
|
|
/* The high-level video driver subsystem */
|
|
|
|
|
|
|
|
#include "SDL.h"
|
|
|
|
#include "SDL_sysvideo.h"
|
|
|
|
#include "SDL_blit.h"
|
|
|
|
#include "SDL_pixels_c.h"
|
2006-07-19 07:18:45 +00:00
|
|
|
#include "SDL_renderer_gl.h"
|
2008-09-02 20:19:45 +00:00
|
|
|
#include "SDL_renderer_gles.h"
|
2006-07-10 21:04:37 +00:00
|
|
|
#include "SDL_renderer_sw.h"
|
2006-02-16 10:11:48 +00:00
|
|
|
#include "../events/SDL_sysevents.h"
|
|
|
|
#include "../events/SDL_events_c.h"
|
2001-04-26 16:45:43 +00:00
|
|
|
|
2008-09-02 20:19:45 +00:00
|
|
|
#if SDL_VIDEO_OPENGL_ES
|
|
|
|
#include "SDL_opengles.h"
|
2008-09-15 04:32:36 +00:00
|
|
|
#endif /* SDL_VIDEO_OPENGL_ES */
|
2008-09-02 20:19:45 +00:00
|
|
|
|
2006-07-22 21:58:17 +00:00
|
|
|
#if SDL_VIDEO_OPENGL
|
|
|
|
#include "SDL_opengl.h"
|
|
|
|
|
|
|
|
/* On Windows, windows.h defines CreateWindow */
|
|
|
|
#ifdef CreateWindow
|
|
|
|
#undef CreateWindow
|
|
|
|
#endif
|
2008-09-15 04:32:36 +00:00
|
|
|
#endif /* SDL_VIDEO_OPENGL */
|
2006-07-22 21:58:17 +00:00
|
|
|
|
2001-04-26 16:45:43 +00:00
|
|
|
/* Available video drivers */
|
|
|
|
static VideoBootStrap *bootstrap[] = {
|
2006-07-23 09:11:10 +00:00
|
|
|
#if SDL_VIDEO_DRIVER_COCOA
|
2008-09-15 04:32:36 +00:00
|
|
|
&COCOA_bootstrap,
|
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
To: SDL Developers <sdl@libsdl.org>
From: =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= <afb@algonet.se>
Date: Mon, 30 May 2005 23:29:04 +0200
Subject: [SDL] Mac OS X Video Drivers [patch]
I've updated/added the Carbon and X11 video drivers
to the Mac OS X port of SDL 1.2 (the CVS version),
and made the Cocoa driver and runtime *optional*.
The default is still Cocoa, and the "Quartz" driver.
But you can now also use "toolbox" for Carbon, and
"x11" for running with Apple's (or other) X11 server:
export SDL_VIDEODRIVER=x11
export SDL_VIDEO_GL_DRIVER=/usr/X11R6/lib/libGL.dylib
It also checks if the frameworks are available, by a:
#include <Carbon/Carbon.h> or #import <Cocoa/Cocoa.h>
(this should make it configure on plain Darwin as well?)
Here are the new configure targets:
--enable-video-cocoa use Cocoa/Quartz video driver default=yes
--enable-video-carbon use Carbon/QuickDraw video driver default=yes
--enable-video-x11 use X11 video driver default=no
./configure --enable-video-cocoa --enable-video-carbon
--enable-video-x11 \
--x-includes=/usr/X11R6/include --x-libraries=/usr/X11R6/lib
The Carbon version is just an updated version of the old
SDL driver for Mac OS 9, and could probably be improved...
(but it does work, including the Carbon version of SDLmain)
If you disable cocoa, you can run with -framework Carbon only,
and the C version of SDL_main.c. And if you disable carbon too,
you can still use the X11 version which doesn't require SDLmain.
I updated the DrawSprocket version, but did not include it.
(no blitters or VRAM GWorlds etc. available on OS X anyway)
Besides for Mac OS 9, I don't think there's any use for it ?
And note that any performance on Mac OS X equals OpenGL anyway...
You can get "fair" software SDL results on captured CG displays,
but for decent frame rates you need to be using GL for rendering.
Finally, here is the patch itself:
http://www.algonet.se/~afb/SDL-12CVS-macvideo.patch
--anders
PS. It says "video", but as usual it applies to mouse/keyboard too.
------
To: A list for developers using the SDL library <sdl@libsdl.org>
From: =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= <afb@algonet.se>
Date: Sun, 4 Sep 2005 10:02:15 +0200
Subject: [SDL] Updated Mac patch
Updated the previous Mac patch to disable Carbon by default.
Also "fixed" the SDL.spec again, so that it builds on Darwin.
http://www.algonet.se/~afb/SDL-1.2.9-mac.patch
Also applied fine to SDL12 CVS, when I tried it.
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%401136
2005-09-08 06:16:14 +00:00
|
|
|
#endif
|
2006-02-16 10:11:48 +00:00
|
|
|
#if SDL_VIDEO_DRIVER_X11
|
2008-09-15 04:32:36 +00:00
|
|
|
&X11_bootstrap,
|
2001-04-26 16:45:43 +00:00
|
|
|
#endif
|
2006-02-16 10:11:48 +00:00
|
|
|
#if SDL_VIDEO_DRIVER_NANOX
|
2008-09-15 04:32:36 +00:00
|
|
|
&NX_bootstrap,
|
2001-05-11 01:13:35 +00:00
|
|
|
#endif
|
2006-02-16 10:11:48 +00:00
|
|
|
#if SDL_VIDEO_DRIVER_IPOD
|
2008-09-15 04:32:36 +00:00
|
|
|
&iPod_bootstrap,
|
2005-09-08 07:33:22 +00:00
|
|
|
#endif
|
2006-02-16 10:11:48 +00:00
|
|
|
#if SDL_VIDEO_DRIVER_WSCONS
|
2008-09-15 04:32:36 +00:00
|
|
|
&WSCONS_bootstrap,
|
2005-11-22 15:19:50 +00:00
|
|
|
#endif
|
2006-02-16 10:11:48 +00:00
|
|
|
#if SDL_VIDEO_DRIVER_FBCON
|
2008-09-15 04:32:36 +00:00
|
|
|
&FBCON_bootstrap,
|
2001-04-26 16:45:43 +00:00
|
|
|
#endif
|
2006-02-16 10:11:48 +00:00
|
|
|
#if SDL_VIDEO_DRIVER_DIRECTFB
|
2008-09-15 04:32:36 +00:00
|
|
|
&DirectFB_bootstrap,
|
2001-09-04 22:53:46 +00:00
|
|
|
#endif
|
2006-02-16 10:11:48 +00:00
|
|
|
#if SDL_VIDEO_DRIVER_PS2GS
|
2008-09-15 04:32:36 +00:00
|
|
|
&PS2GS_bootstrap,
|
2001-04-26 16:45:43 +00:00
|
|
|
#endif
|
2006-02-16 10:11:48 +00:00
|
|
|
#if SDL_VIDEO_DRIVER_VGL
|
2008-09-15 04:32:36 +00:00
|
|
|
&VGL_bootstrap,
|
2001-06-19 13:33:54 +00:00
|
|
|
#endif
|
2006-02-16 10:11:48 +00:00
|
|
|
#if SDL_VIDEO_DRIVER_SVGALIB
|
2008-09-15 04:32:36 +00:00
|
|
|
&SVGALIB_bootstrap,
|
2001-04-26 16:45:43 +00:00
|
|
|
#endif
|
2006-02-16 10:11:48 +00:00
|
|
|
#if SDL_VIDEO_DRIVER_GAPI
|
2008-09-15 04:32:36 +00:00
|
|
|
&GAPI_bootstrap,
|
2006-01-19 08:43:00 +00:00
|
|
|
#endif
|
2006-07-10 21:04:37 +00:00
|
|
|
#if SDL_VIDEO_DRIVER_WIN32
|
2008-09-15 04:32:36 +00:00
|
|
|
&WIN32_bootstrap,
|
2006-01-01 23:34:06 +00:00
|
|
|
#endif
|
2006-02-16 10:11:48 +00:00
|
|
|
#if SDL_VIDEO_DRIVER_BWINDOW
|
2008-09-15 04:32:36 +00:00
|
|
|
&BWINDOW_bootstrap,
|
2001-04-26 16:45:43 +00:00
|
|
|
#endif
|
2006-02-16 10:11:48 +00:00
|
|
|
#if SDL_VIDEO_DRIVER_PHOTON
|
2008-09-15 04:32:36 +00:00
|
|
|
&ph_bootstrap,
|
2001-09-11 20:38:49 +00:00
|
|
|
#endif
|
2006-02-16 10:11:48 +00:00
|
|
|
#if SDL_VIDEO_DRIVER_EPOC
|
2008-09-15 04:32:36 +00:00
|
|
|
&EPOC_bootstrap,
|
2001-09-11 20:38:49 +00:00
|
|
|
#endif
|
2006-02-16 10:11:48 +00:00
|
|
|
#if SDL_VIDEO_DRIVER_XBIOS
|
2008-09-15 04:32:36 +00:00
|
|
|
&XBIOS_bootstrap,
|
2002-02-17 19:54:28 +00:00
|
|
|
#endif
|
2006-02-16 10:11:48 +00:00
|
|
|
#if SDL_VIDEO_DRIVER_GEM
|
2008-09-15 04:32:36 +00:00
|
|
|
&GEM_bootstrap,
|
2002-05-19 20:06:01 +00:00
|
|
|
#endif
|
2006-02-16 10:11:48 +00:00
|
|
|
#if SDL_VIDEO_DRIVER_DC
|
2008-09-15 04:32:36 +00:00
|
|
|
&DC_bootstrap,
|
2003-04-15 15:46:56 +00:00
|
|
|
#endif
|
2006-02-16 10:11:48 +00:00
|
|
|
#if SDL_VIDEO_DRIVER_RISCOS
|
2008-09-15 04:32:36 +00:00
|
|
|
&RISCOS_bootstrap,
|
2003-05-29 04:44:13 +00:00
|
|
|
#endif
|
2006-02-16 10:11:48 +00:00
|
|
|
#if SDL_VIDEO_DRIVER_OS2FS
|
2008-09-15 04:32:36 +00:00
|
|
|
&OS2FSLib_bootstrap,
|
2005-11-23 07:29:56 +00:00
|
|
|
#endif
|
2008-09-02 20:05:33 +00:00
|
|
|
#if SDL_VIDEO_DRIVER_NDS
|
2008-09-15 04:32:36 +00:00
|
|
|
&NDS_bootstrap,
|
2008-08-27 15:10:03 +00:00
|
|
|
#endif
|
2008-09-02 20:19:45 +00:00
|
|
|
#if SDL_VIDEO_DRIVER_UIKIT
|
2008-09-15 04:32:36 +00:00
|
|
|
&UIKIT_bootstrap,
|
2008-09-02 20:19:45 +00:00
|
|
|
#endif
|
2006-02-16 10:11:48 +00:00
|
|
|
#if SDL_VIDEO_DRIVER_DUMMY
|
2008-09-15 04:32:36 +00:00
|
|
|
&DUMMY_bootstrap,
|
2001-04-26 16:45:43 +00:00
|
|
|
#endif
|
2008-09-15 04:32:36 +00:00
|
|
|
NULL
|
2001-04-26 16:45:43 +00:00
|
|
|
};
|
2001-09-11 20:38:49 +00:00
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
static SDL_VideoDevice *_this = NULL;
|
2001-04-26 16:45:43 +00:00
|
|
|
|
|
|
|
/* Various local functions */
|
2008-12-17 07:17:54 +00:00
|
|
|
static void SDL_UpdateWindowGrab(SDL_Window *window);
|
2001-04-26 16:45:43 +00:00
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
static int
|
|
|
|
cmpmodes(const void *A, const void *B)
|
|
|
|
{
|
2008-09-15 04:32:36 +00:00
|
|
|
SDL_DisplayMode a = *(const SDL_DisplayMode *) A;
|
|
|
|
SDL_DisplayMode b = *(const SDL_DisplayMode *) B;
|
2006-07-10 21:04:37 +00:00
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
if (a.w != b.w) {
|
|
|
|
return b.w - a.w;
|
|
|
|
}
|
|
|
|
if (a.h != b.h) {
|
|
|
|
return b.h - a.h;
|
|
|
|
}
|
|
|
|
if (SDL_BITSPERPIXEL(a.format) != SDL_BITSPERPIXEL(b.format)) {
|
|
|
|
return SDL_BITSPERPIXEL(b.format) - SDL_BITSPERPIXEL(a.format);
|
|
|
|
}
|
|
|
|
if (a.refresh_rate != b.refresh_rate) {
|
|
|
|
return b.refresh_rate - a.refresh_rate;
|
|
|
|
}
|
|
|
|
return 0;
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
2001-04-26 16:45:43 +00:00
|
|
|
|
2006-07-16 09:34:01 +00:00
|
|
|
static void
|
|
|
|
SDL_UninitializedVideo()
|
|
|
|
{
|
2008-09-15 04:32:36 +00:00
|
|
|
SDL_SetError("Video subsystem has not been initialized");
|
2006-07-16 09:34:01 +00:00
|
|
|
}
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
int
|
|
|
|
SDL_GetNumVideoDrivers(void)
|
|
|
|
{
|
2008-09-15 04:32:36 +00:00
|
|
|
return SDL_arraysize(bootstrap) - 1;
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
const char *
|
2006-07-10 21:04:37 +00:00
|
|
|
SDL_GetVideoDriver(int index)
|
|
|
|
{
|
2008-09-15 04:32:36 +00:00
|
|
|
if (index >= 0 && index < SDL_GetNumVideoDrivers()) {
|
|
|
|
return bootstrap[index]->name;
|
|
|
|
}
|
|
|
|
return NULL;
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
2001-04-26 16:45:43 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize the video and event subsystems -- determine native pixel format
|
|
|
|
*/
|
2006-07-10 21:04:37 +00:00
|
|
|
int
|
|
|
|
SDL_VideoInit(const char *driver_name, Uint32 flags)
|
2001-04-26 16:45:43 +00:00
|
|
|
{
|
2008-09-15 04:32:36 +00:00
|
|
|
SDL_VideoDevice *video;
|
|
|
|
int index;
|
|
|
|
int i;
|
2001-04-26 16:45:43 +00:00
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
/* Toggle the event thread flags, based on OS requirements */
|
2001-04-26 16:45:43 +00:00
|
|
|
#if defined(MUST_THREAD_EVENTS)
|
2008-09-15 04:32:36 +00:00
|
|
|
flags |= SDL_INIT_EVENTTHREAD;
|
2001-04-26 16:45:43 +00:00
|
|
|
#elif defined(CANT_THREAD_EVENTS)
|
2008-09-15 04:32:36 +00:00
|
|
|
if ((flags & SDL_INIT_EVENTTHREAD) == SDL_INIT_EVENTTHREAD) {
|
|
|
|
SDL_SetError("OS doesn't support threaded events");
|
|
|
|
return -1;
|
|
|
|
}
|
2001-04-26 16:45:43 +00:00
|
|
|
#endif
|
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
/* Start the event loop */
|
|
|
|
if (SDL_StartEventLoop(flags) < 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
/* Check to make sure we don't overwrite '_this' */
|
|
|
|
if (_this != NULL) {
|
|
|
|
SDL_VideoQuit();
|
|
|
|
}
|
|
|
|
/* Select the proper video driver */
|
|
|
|
index = 0;
|
|
|
|
video = NULL;
|
|
|
|
if (driver_name == NULL) {
|
|
|
|
driver_name = SDL_getenv("SDL_VIDEODRIVER");
|
|
|
|
}
|
|
|
|
if (driver_name != NULL) {
|
|
|
|
for (i = 0; bootstrap[i]; ++i) {
|
|
|
|
if (SDL_strcasecmp(bootstrap[i]->name, driver_name) == 0) {
|
|
|
|
if (bootstrap[i]->available()) {
|
|
|
|
video = bootstrap[i]->create(index);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (i = 0; bootstrap[i]; ++i) {
|
|
|
|
if (bootstrap[i]->available()) {
|
|
|
|
video = bootstrap[i]->create(index);
|
|
|
|
if (video != NULL) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (video == NULL) {
|
|
|
|
if (driver_name) {
|
|
|
|
SDL_SetError("%s not available", driver_name);
|
|
|
|
} else {
|
|
|
|
SDL_SetError("No available video device");
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
_this = video;
|
|
|
|
_this->name = bootstrap[i]->name;
|
|
|
|
_this->next_object_id = 1;
|
|
|
|
|
|
|
|
|
|
|
|
/* Set some very sane GL defaults */
|
|
|
|
_this->gl_config.driver_loaded = 0;
|
|
|
|
_this->gl_config.dll_handle = NULL;
|
|
|
|
_this->gl_config.red_size = 3;
|
|
|
|
_this->gl_config.green_size = 3;
|
|
|
|
_this->gl_config.blue_size = 2;
|
|
|
|
_this->gl_config.alpha_size = 0;
|
|
|
|
_this->gl_config.buffer_size = 0;
|
|
|
|
_this->gl_config.depth_size = 16;
|
|
|
|
_this->gl_config.stencil_size = 0;
|
|
|
|
_this->gl_config.double_buffer = 1;
|
|
|
|
_this->gl_config.accum_red_size = 0;
|
|
|
|
_this->gl_config.accum_green_size = 0;
|
|
|
|
_this->gl_config.accum_blue_size = 0;
|
|
|
|
_this->gl_config.accum_alpha_size = 0;
|
|
|
|
_this->gl_config.stereo = 0;
|
|
|
|
_this->gl_config.multisamplebuffers = 0;
|
|
|
|
_this->gl_config.multisamplesamples = 0;
|
|
|
|
_this->gl_config.retained_backing = 1;
|
|
|
|
_this->gl_config.accelerated = -1; /* not known, don't set */
|
|
|
|
|
|
|
|
/* Initialize the video subsystem */
|
|
|
|
if (_this->VideoInit(_this) < 0) {
|
|
|
|
SDL_VideoQuit();
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
/* Make sure some displays were added */
|
|
|
|
if (_this->num_displays == 0) {
|
|
|
|
SDL_SetError("The video driver did not add any displays");
|
|
|
|
SDL_VideoQuit();
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
/* The software renderer is always available */
|
|
|
|
for (i = 0; i < _this->num_displays; ++i) {
|
2006-07-28 08:43:17 +00:00
|
|
|
#if SDL_VIDEO_RENDER_OGL
|
2008-09-15 04:32:36 +00:00
|
|
|
SDL_AddRenderDriver(i, &GL_RenderDriver);
|
2006-07-19 07:18:45 +00:00
|
|
|
#endif
|
2008-09-02 20:19:45 +00:00
|
|
|
|
|
|
|
#if SDL_VIDEO_RENDER_OGL_ES
|
2008-09-15 04:32:36 +00:00
|
|
|
SDL_AddRenderDriver(i, &GL_ES_RenderDriver);
|
2008-09-02 20:19:45 +00:00
|
|
|
#endif
|
2008-09-15 04:32:36 +00:00
|
|
|
if (_this->displays[i].num_render_drivers > 0) {
|
|
|
|
SDL_AddRenderDriver(i, &SW_RenderDriver);
|
|
|
|
}
|
|
|
|
}
|
2006-07-10 21:04:37 +00:00
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
/* We're ready to go! */
|
|
|
|
return 0;
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
2001-04-26 16:45:43 +00:00
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
const char *
|
2006-07-10 21:04:37 +00:00
|
|
|
SDL_GetCurrentVideoDriver()
|
|
|
|
{
|
2008-09-15 04:32:36 +00:00
|
|
|
if (!_this) {
|
|
|
|
SDL_UninitializedVideo();
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return _this->name;
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
2001-04-26 16:45:43 +00:00
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
SDL_VideoDevice *
|
|
|
|
SDL_GetVideoDevice()
|
|
|
|
{
|
2008-09-15 04:32:36 +00:00
|
|
|
return _this;
|
2001-04-26 16:45:43 +00:00
|
|
|
}
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
int
|
|
|
|
SDL_AddBasicVideoDisplay(const SDL_DisplayMode * desktop_mode)
|
2001-04-26 16:45:43 +00:00
|
|
|
{
|
2008-09-15 04:32:36 +00:00
|
|
|
SDL_VideoDisplay display;
|
2006-07-10 21:04:37 +00:00
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
SDL_zero(display);
|
|
|
|
if (desktop_mode) {
|
|
|
|
display.desktop_mode = *desktop_mode;
|
|
|
|
}
|
|
|
|
display.current_mode = display.desktop_mode;
|
2006-07-10 21:04:37 +00:00
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
return SDL_AddVideoDisplay(&display);
|
2001-04-26 16:45:43 +00:00
|
|
|
}
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
int
|
|
|
|
SDL_AddVideoDisplay(const SDL_VideoDisplay * display)
|
2001-04-26 16:45:43 +00:00
|
|
|
{
|
2008-09-15 04:32:36 +00:00
|
|
|
SDL_VideoDisplay *displays;
|
|
|
|
int index = -1;
|
2006-07-10 21:04:37 +00:00
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
displays =
|
|
|
|
SDL_realloc(_this->displays,
|
|
|
|
(_this->num_displays + 1) * sizeof(*displays));
|
|
|
|
if (displays) {
|
|
|
|
index = _this->num_displays++;
|
|
|
|
displays[index] = *display;
|
|
|
|
displays[index].device = _this;
|
|
|
|
_this->displays = displays;
|
|
|
|
} else {
|
|
|
|
SDL_OutOfMemory();
|
|
|
|
}
|
|
|
|
return index;
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
2001-04-26 16:45:43 +00:00
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
int
|
|
|
|
SDL_GetNumVideoDisplays(void)
|
|
|
|
{
|
2008-09-15 04:32:36 +00:00
|
|
|
if (!_this) {
|
|
|
|
SDL_UninitializedVideo();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return _this->num_displays;
|
2001-04-26 16:45:43 +00:00
|
|
|
}
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
int
|
|
|
|
SDL_SelectVideoDisplay(int index)
|
2001-04-26 16:45:43 +00:00
|
|
|
{
|
2008-09-15 04:32:36 +00:00
|
|
|
if (!_this) {
|
|
|
|
SDL_UninitializedVideo();
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
if (index < 0 || index >= _this->num_displays) {
|
|
|
|
SDL_SetError("index must be in the range 0 - %d",
|
|
|
|
_this->num_displays - 1);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
_this->current_display = index;
|
|
|
|
return 0;
|
2006-08-02 03:20:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
SDL_GetCurrentVideoDisplay(void)
|
|
|
|
{
|
2008-09-15 04:32:36 +00:00
|
|
|
if (!_this) {
|
|
|
|
SDL_UninitializedVideo();
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
return _this->current_display;
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
2001-04-26 16:45:43 +00:00
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
SDL_bool
|
|
|
|
SDL_AddDisplayMode(int displayIndex, const SDL_DisplayMode * mode)
|
|
|
|
{
|
2008-09-15 04:32:36 +00:00
|
|
|
SDL_VideoDisplay *display = &_this->displays[displayIndex];
|
|
|
|
SDL_DisplayMode *modes;
|
|
|
|
int i, nmodes;
|
|
|
|
|
|
|
|
/* Make sure we don't already have the mode in the list */
|
|
|
|
modes = display->display_modes;
|
|
|
|
nmodes = display->num_display_modes;
|
|
|
|
for (i = nmodes; i--;) {
|
|
|
|
if (SDL_memcmp(mode, &modes[i], sizeof(*mode)) == 0) {
|
|
|
|
return SDL_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Go ahead and add the new mode */
|
|
|
|
if (nmodes == display->max_display_modes) {
|
|
|
|
modes =
|
|
|
|
SDL_realloc(modes,
|
|
|
|
(display->max_display_modes + 32) * sizeof(*modes));
|
|
|
|
if (!modes) {
|
|
|
|
return SDL_FALSE;
|
|
|
|
}
|
|
|
|
display->display_modes = modes;
|
|
|
|
display->max_display_modes += 32;
|
|
|
|
}
|
|
|
|
modes[nmodes] = *mode;
|
|
|
|
display->num_display_modes++;
|
|
|
|
|
|
|
|
return SDL_TRUE;
|
2001-04-26 16:45:43 +00:00
|
|
|
}
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
int
|
|
|
|
SDL_GetNumDisplayModes()
|
2001-04-26 16:45:43 +00:00
|
|
|
{
|
2008-09-15 04:32:36 +00:00
|
|
|
if (_this) {
|
|
|
|
SDL_VideoDisplay *display = &SDL_CurrentDisplay;
|
|
|
|
if (!display->num_display_modes && _this->GetDisplayModes) {
|
|
|
|
_this->GetDisplayModes(_this);
|
|
|
|
SDL_qsort(display->display_modes, display->num_display_modes,
|
|
|
|
sizeof(SDL_DisplayMode), cmpmodes);
|
|
|
|
}
|
|
|
|
return display->num_display_modes;
|
|
|
|
}
|
|
|
|
return 0;
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
2001-04-26 16:45:43 +00:00
|
|
|
|
2006-08-05 22:34:23 +00:00
|
|
|
int
|
|
|
|
SDL_GetDisplayMode(int index, SDL_DisplayMode * mode)
|
2006-07-10 21:04:37 +00:00
|
|
|
{
|
2008-09-15 04:32:36 +00:00
|
|
|
if (index < 0 || index >= SDL_GetNumDisplayModes()) {
|
|
|
|
SDL_SetError("index must be in the range of 0 - %d",
|
|
|
|
SDL_GetNumDisplayModes() - 1);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (mode) {
|
|
|
|
*mode = SDL_CurrentDisplay.display_modes[index];
|
|
|
|
}
|
|
|
|
return 0;
|
2001-04-26 16:45:43 +00:00
|
|
|
}
|
|
|
|
|
2006-08-05 22:34:23 +00:00
|
|
|
int
|
|
|
|
SDL_GetDesktopDisplayMode(SDL_DisplayMode * mode)
|
2006-07-10 21:04:37 +00:00
|
|
|
{
|
2008-09-15 04:32:36 +00:00
|
|
|
if (!_this) {
|
|
|
|
SDL_UninitializedVideo();
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (mode) {
|
|
|
|
*mode = SDL_CurrentDisplay.desktop_mode;
|
|
|
|
}
|
|
|
|
return 0;
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
2001-04-26 16:45:43 +00:00
|
|
|
|
2006-08-05 22:34:23 +00:00
|
|
|
int
|
|
|
|
SDL_GetCurrentDisplayMode(SDL_DisplayMode * mode)
|
2006-07-10 21:04:37 +00:00
|
|
|
{
|
2008-09-15 04:32:36 +00:00
|
|
|
if (!_this) {
|
|
|
|
SDL_UninitializedVideo();
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (mode) {
|
|
|
|
*mode = SDL_CurrentDisplay.current_mode;
|
|
|
|
}
|
|
|
|
return 0;
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
2004-02-24 07:42:19 +00:00
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
SDL_DisplayMode *
|
|
|
|
SDL_GetClosestDisplayMode(const SDL_DisplayMode * mode,
|
2008-09-15 04:32:36 +00:00
|
|
|
SDL_DisplayMode * closest)
|
|
|
|
{
|
|
|
|
Uint32 target_format;
|
|
|
|
int target_refresh_rate;
|
|
|
|
int i;
|
|
|
|
SDL_DisplayMode *current, *match;
|
|
|
|
|
|
|
|
if (!_this || !mode || !closest) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
/* Default to the desktop format */
|
|
|
|
if (mode->format) {
|
|
|
|
target_format = mode->format;
|
|
|
|
} else {
|
|
|
|
target_format = SDL_CurrentDisplay.desktop_mode.format;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Default to the desktop refresh rate */
|
|
|
|
if (mode->refresh_rate) {
|
|
|
|
target_refresh_rate = mode->refresh_rate;
|
|
|
|
} else {
|
|
|
|
target_refresh_rate = SDL_CurrentDisplay.desktop_mode.refresh_rate;
|
|
|
|
}
|
|
|
|
|
|
|
|
match = NULL;
|
|
|
|
for (i = 0; i < SDL_GetNumDisplayModes(); ++i) {
|
|
|
|
current = &SDL_CurrentDisplay.display_modes[i];
|
|
|
|
|
2008-11-25 20:06:27 +00:00
|
|
|
if (current->w && (current->w < mode->w)) {
|
2008-09-15 04:32:36 +00:00
|
|
|
/* Out of sorted modes large enough here */
|
|
|
|
break;
|
|
|
|
}
|
2008-11-25 20:06:27 +00:00
|
|
|
if (current->h && (current->h < mode->h)) {
|
|
|
|
if (current->w && (current->w == mode->w)) {
|
|
|
|
/* Out of sorted modes large enough here */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* Wider, but not tall enough, due to a different
|
|
|
|
aspect ratio. This mode must be skipped, but closer
|
|
|
|
modes may still follow. */
|
|
|
|
continue;
|
|
|
|
}
|
2008-09-15 04:32:36 +00:00
|
|
|
if (!match || current->w < match->w || current->h < match->h) {
|
|
|
|
match = current;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (current->format != match->format) {
|
|
|
|
/* Sorted highest depth to lowest */
|
|
|
|
if (current->format == target_format ||
|
|
|
|
(SDL_BITSPERPIXEL(current->format) >=
|
|
|
|
SDL_BITSPERPIXEL(target_format)
|
|
|
|
&& SDL_PIXELTYPE(current->format) ==
|
|
|
|
SDL_PIXELTYPE(target_format))) {
|
|
|
|
match = current;
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (current->refresh_rate != match->refresh_rate) {
|
|
|
|
/* Sorted highest refresh to lowest */
|
|
|
|
if (current->refresh_rate >= target_refresh_rate) {
|
|
|
|
match = current;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (match) {
|
|
|
|
if (match->format) {
|
|
|
|
closest->format = match->format;
|
|
|
|
} else {
|
|
|
|
closest->format = mode->format;
|
|
|
|
}
|
|
|
|
if (match->w && match->h) {
|
|
|
|
closest->w = match->w;
|
|
|
|
closest->h = match->h;
|
|
|
|
} else {
|
|
|
|
closest->w = mode->w;
|
|
|
|
closest->h = mode->h;
|
|
|
|
}
|
|
|
|
if (match->refresh_rate) {
|
|
|
|
closest->refresh_rate = match->refresh_rate;
|
|
|
|
} else {
|
|
|
|
closest->refresh_rate = mode->refresh_rate;
|
|
|
|
}
|
|
|
|
closest->driverdata = match->driverdata;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Pick some reasonable defaults if the app and driver don't
|
|
|
|
* care
|
|
|
|
*/
|
|
|
|
if (!closest->format) {
|
|
|
|
closest->format = SDL_PIXELFORMAT_RGB888;
|
|
|
|
}
|
|
|
|
if (!closest->w) {
|
|
|
|
closest->w = 640;
|
|
|
|
}
|
|
|
|
if (!closest->h) {
|
|
|
|
closest->h = 480;
|
|
|
|
}
|
|
|
|
return closest;
|
|
|
|
}
|
|
|
|
return NULL;
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
2004-02-24 07:42:19 +00:00
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
int
|
|
|
|
SDL_SetDisplayMode(const SDL_DisplayMode * mode)
|
|
|
|
{
|
2008-09-15 04:32:36 +00:00
|
|
|
SDL_VideoDisplay *display;
|
|
|
|
SDL_DisplayMode display_mode;
|
|
|
|
SDL_DisplayMode current_mode;
|
|
|
|
int i, ncolors;
|
|
|
|
|
|
|
|
if (!_this) {
|
|
|
|
SDL_UninitializedVideo();
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
display = &SDL_CurrentDisplay;
|
|
|
|
if (!mode) {
|
|
|
|
mode = &display->desktop_mode;
|
|
|
|
}
|
|
|
|
display_mode = *mode;
|
|
|
|
|
|
|
|
/* Default to the current mode */
|
|
|
|
if (!display_mode.format) {
|
|
|
|
display_mode.format = display->current_mode.format;
|
|
|
|
}
|
|
|
|
if (!display_mode.w) {
|
|
|
|
display_mode.w = display->current_mode.w;
|
|
|
|
}
|
|
|
|
if (!display_mode.h) {
|
|
|
|
display_mode.h = display->current_mode.h;
|
|
|
|
}
|
|
|
|
if (!display_mode.refresh_rate) {
|
|
|
|
display_mode.refresh_rate = display->current_mode.refresh_rate;
|
|
|
|
}
|
|
|
|
/* Get a good video mode, the closest one possible */
|
|
|
|
if (!SDL_GetClosestDisplayMode(&display_mode, &display_mode)) {
|
|
|
|
SDL_SetError("No video mode large enough for %dx%d",
|
|
|
|
display_mode.w, display_mode.h);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
/* See if there's anything left to do */
|
|
|
|
SDL_GetCurrentDisplayMode(¤t_mode);
|
|
|
|
if (SDL_memcmp(&display_mode, ¤t_mode, sizeof(display_mode)) == 0) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/* Actually change the display mode */
|
|
|
|
if (_this->SetDisplayMode(_this, &display_mode) < 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
display->current_mode = display_mode;
|
|
|
|
|
|
|
|
/* Set up a palette, if necessary */
|
|
|
|
if (SDL_ISPIXELFORMAT_INDEXED(display_mode.format)) {
|
|
|
|
ncolors = (1 << SDL_BITSPERPIXEL(display_mode.format));
|
|
|
|
} else {
|
|
|
|
ncolors = 0;
|
|
|
|
}
|
|
|
|
if ((!ncolors && display->palette) || (ncolors && !display->palette)
|
|
|
|
|| (ncolors && ncolors != display->palette->ncolors)) {
|
|
|
|
if (display->palette) {
|
|
|
|
SDL_FreePalette(display->palette);
|
|
|
|
display->palette = NULL;
|
|
|
|
}
|
|
|
|
if (ncolors) {
|
|
|
|
display->palette = SDL_AllocPalette(ncolors);
|
|
|
|
if (!display->palette) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
SDL_DitherColors(display->palette->colors,
|
|
|
|
SDL_BITSPERPIXEL(display_mode.format));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Move any fullscreen windows into position */
|
|
|
|
for (i = 0; i < display->num_windows; ++i) {
|
|
|
|
SDL_Window *window = &display->windows[i];
|
|
|
|
if (FULLSCREEN_VISIBLE(window)) {
|
2008-12-17 07:17:54 +00:00
|
|
|
SDL_SetWindowPosition(window->id, window->x, window->y);
|
2008-09-15 04:32:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2001-04-26 16:45:43 +00:00
|
|
|
}
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
int
|
|
|
|
SDL_SetFullscreenDisplayMode(const SDL_DisplayMode * mode)
|
|
|
|
{
|
2008-09-15 04:32:36 +00:00
|
|
|
SDL_VideoDisplay *display;
|
|
|
|
SDL_DisplayMode fullscreen_mode;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (!_this) {
|
|
|
|
SDL_UninitializedVideo();
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
display = &SDL_CurrentDisplay;
|
|
|
|
if (!mode) {
|
|
|
|
mode = &display->desktop_mode;
|
|
|
|
}
|
2008-12-13 13:30:11 +00:00
|
|
|
if (!SDL_GetClosestDisplayMode(mode, &fullscreen_mode)) {
|
|
|
|
SDL_SetError("Couldn't find display mode match");
|
|
|
|
return -1;
|
|
|
|
}
|
2008-09-15 04:32:36 +00:00
|
|
|
if (SDL_memcmp
|
|
|
|
(&fullscreen_mode, &display->fullscreen_mode,
|
|
|
|
sizeof(fullscreen_mode)) == 0) {
|
|
|
|
/* Nothing to do... */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
display->fullscreen_mode = fullscreen_mode;
|
|
|
|
|
|
|
|
/* Actually set the mode if we have a fullscreen window visible */
|
|
|
|
for (i = 0; i < display->num_windows; ++i) {
|
|
|
|
SDL_Window *window = &display->windows[i];
|
|
|
|
if (FULLSCREEN_VISIBLE(window)) {
|
|
|
|
if (SDL_SetDisplayMode(&display->fullscreen_mode) < 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (window->flags & SDL_WINDOW_FULLSCREEN) {
|
|
|
|
SDL_OnWindowResized(window);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
2001-04-26 16:45:43 +00:00
|
|
|
}
|
|
|
|
|
2006-08-05 22:34:23 +00:00
|
|
|
int
|
|
|
|
SDL_GetFullscreenDisplayMode(SDL_DisplayMode * mode)
|
2006-07-10 21:04:37 +00:00
|
|
|
{
|
2008-09-15 04:32:36 +00:00
|
|
|
if (!_this) {
|
|
|
|
SDL_UninitializedVideo();
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (mode) {
|
|
|
|
*mode = SDL_CurrentDisplay.fullscreen_mode;
|
|
|
|
}
|
|
|
|
return 0;
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
2004-07-18 19:46:38 +00:00
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
int
|
|
|
|
SDL_SetDisplayPalette(const SDL_Color * colors, int firstcolor, int ncolors)
|
|
|
|
{
|
2008-09-15 04:32:36 +00:00
|
|
|
SDL_Palette *palette;
|
|
|
|
int status = 0;
|
2006-07-10 21:04:37 +00:00
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
if (!_this) {
|
|
|
|
SDL_UninitializedVideo();
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
palette = SDL_CurrentDisplay.palette;
|
|
|
|
if (!palette) {
|
|
|
|
SDL_SetError("Display mode does not have a palette");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
status = SDL_SetPaletteColors(palette, colors, firstcolor, ncolors);
|
2006-07-10 21:04:37 +00:00
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
if (_this->SetDisplayPalette) {
|
|
|
|
if (_this->SetDisplayPalette(_this, palette) < 0) {
|
|
|
|
status = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return status;
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
2001-11-04 04:18:27 +00:00
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
int
|
|
|
|
SDL_GetDisplayPalette(SDL_Color * colors, int firstcolor, int ncolors)
|
|
|
|
{
|
2008-09-15 04:32:36 +00:00
|
|
|
SDL_Palette *palette;
|
|
|
|
|
|
|
|
if (!_this) {
|
|
|
|
SDL_UninitializedVideo();
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
palette = SDL_CurrentDisplay.palette;
|
|
|
|
if (!palette->ncolors) {
|
|
|
|
SDL_SetError("Display mode does not have a palette");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (firstcolor < 0 || (firstcolor + ncolors) > palette->ncolors) {
|
|
|
|
SDL_SetError("Palette indices are out of range");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
SDL_memcpy(colors, &palette->colors[firstcolor],
|
|
|
|
ncolors * sizeof(*colors));
|
|
|
|
return 0;
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
2001-04-26 16:45:43 +00:00
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
SDL_WindowID
|
|
|
|
SDL_CreateWindow(const char *title, int x, int y, int w, int h, Uint32 flags)
|
|
|
|
{
|
2008-09-15 04:32:36 +00:00
|
|
|
const Uint32 allowed_flags = (SDL_WINDOW_FULLSCREEN |
|
|
|
|
SDL_WINDOW_OPENGL |
|
|
|
|
SDL_WINDOW_BORDERLESS |
|
2008-12-17 07:17:54 +00:00
|
|
|
SDL_WINDOW_RESIZABLE |
|
|
|
|
SDL_WINDOW_INPUT_GRABBED);
|
2008-09-15 04:32:36 +00:00
|
|
|
SDL_VideoDisplay *display;
|
|
|
|
SDL_Window window;
|
|
|
|
int num_windows;
|
|
|
|
SDL_Window *windows;
|
|
|
|
|
|
|
|
if (!_this) {
|
|
|
|
SDL_UninitializedVideo();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if ((flags & SDL_WINDOW_OPENGL) && !_this->GL_CreateContext) {
|
|
|
|
SDL_SetError("No OpenGL support in video driver");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
SDL_zero(window);
|
|
|
|
window.id = _this->next_object_id++;
|
|
|
|
window.x = x;
|
|
|
|
window.y = y;
|
|
|
|
window.w = w;
|
|
|
|
window.h = h;
|
|
|
|
window.flags = (flags & allowed_flags);
|
|
|
|
window.display = _this->current_display;
|
|
|
|
|
|
|
|
if (_this->CreateWindow && _this->CreateWindow(_this, &window) < 0) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
display = &SDL_CurrentDisplay;
|
|
|
|
num_windows = display->num_windows;
|
|
|
|
windows =
|
|
|
|
SDL_realloc(display->windows, (num_windows + 1) * sizeof(*windows));
|
|
|
|
if (!windows) {
|
|
|
|
if (_this->DestroyWindow) {
|
|
|
|
_this->DestroyWindow(_this, &window);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
windows[num_windows] = window;
|
|
|
|
display->windows = windows;
|
|
|
|
display->num_windows++;
|
|
|
|
|
|
|
|
if (title) {
|
|
|
|
SDL_SetWindowTitle(window.id, title);
|
|
|
|
}
|
|
|
|
if (flags & SDL_WINDOW_MAXIMIZED) {
|
|
|
|
SDL_MaximizeWindow(window.id);
|
|
|
|
}
|
|
|
|
if (flags & SDL_WINDOW_MINIMIZED) {
|
|
|
|
SDL_MinimizeWindow(window.id);
|
|
|
|
}
|
|
|
|
if (flags & SDL_WINDOW_SHOWN) {
|
|
|
|
SDL_ShowWindow(window.id);
|
|
|
|
}
|
2008-12-17 07:17:54 +00:00
|
|
|
SDL_UpdateWindowGrab(&window);
|
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
return window.id;
|
2001-04-26 16:45:43 +00:00
|
|
|
}
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
SDL_WindowID
|
|
|
|
SDL_CreateWindowFrom(const void *data)
|
|
|
|
{
|
2008-09-15 04:32:36 +00:00
|
|
|
SDL_VideoDisplay *display;
|
|
|
|
SDL_Window window;
|
|
|
|
int num_windows;
|
|
|
|
SDL_Window *windows;
|
|
|
|
|
|
|
|
if (!_this) {
|
|
|
|
SDL_UninitializedVideo();
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
SDL_zero(window);
|
|
|
|
window.id = _this->next_object_id++;
|
|
|
|
window.display = _this->current_display;
|
|
|
|
|
|
|
|
if (!_this->CreateWindowFrom ||
|
|
|
|
_this->CreateWindowFrom(_this, &window, data) < 0) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
display = &SDL_CurrentDisplay;
|
|
|
|
num_windows = display->num_windows;
|
|
|
|
windows =
|
|
|
|
SDL_realloc(display->windows, (num_windows + 1) * sizeof(*windows));
|
|
|
|
if (!windows) {
|
|
|
|
if (_this->DestroyWindow) {
|
|
|
|
_this->DestroyWindow(_this, &window);
|
|
|
|
}
|
|
|
|
if (window.title) {
|
|
|
|
SDL_free(window.title);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
windows[num_windows] = window;
|
|
|
|
display->windows = windows;
|
|
|
|
display->num_windows++;
|
|
|
|
|
|
|
|
return window.id;
|
2001-04-26 16:45:43 +00:00
|
|
|
}
|
|
|
|
|
2006-07-22 21:02:57 +00:00
|
|
|
int
|
2006-07-23 00:19:12 +00:00
|
|
|
SDL_RecreateWindow(SDL_Window * window, Uint32 flags)
|
2006-07-22 21:02:57 +00:00
|
|
|
{
|
2008-09-15 04:32:36 +00:00
|
|
|
char *title = window->title;
|
|
|
|
|
|
|
|
if ((flags & SDL_WINDOW_OPENGL) && !_this->GL_CreateContext) {
|
|
|
|
SDL_SetError("No OpenGL support in video driver");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (_this->DestroyWindow) {
|
|
|
|
_this->DestroyWindow(_this, window);
|
|
|
|
}
|
|
|
|
window->title = NULL;
|
|
|
|
window->flags =
|
|
|
|
(flags &
|
|
|
|
~(SDL_WINDOW_MAXIMIZED | SDL_WINDOW_MINIMIZED | SDL_WINDOW_SHOWN |
|
|
|
|
SDL_WINDOW_INPUT_GRABBED));
|
|
|
|
|
|
|
|
if (_this->CreateWindow && _this->CreateWindow(_this, window) < 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (title) {
|
|
|
|
SDL_SetWindowTitle(window->id, title);
|
|
|
|
SDL_free(title);
|
|
|
|
}
|
|
|
|
if (flags & SDL_WINDOW_MAXIMIZED) {
|
|
|
|
SDL_MaximizeWindow(window->id);
|
|
|
|
}
|
|
|
|
if (flags & SDL_WINDOW_MINIMIZED) {
|
|
|
|
SDL_MinimizeWindow(window->id);
|
|
|
|
}
|
|
|
|
if (flags & SDL_WINDOW_SHOWN) {
|
|
|
|
SDL_ShowWindow(window->id);
|
|
|
|
}
|
2008-12-17 07:17:54 +00:00
|
|
|
SDL_UpdateWindowGrab(window);
|
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
SDL_Window *
|
2006-07-10 21:04:37 +00:00
|
|
|
SDL_GetWindowFromID(SDL_WindowID windowID)
|
|
|
|
{
|
2008-09-15 04:32:36 +00:00
|
|
|
int i, j;
|
2006-07-10 21:04:37 +00:00
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
if (!_this) {
|
|
|
|
SDL_UninitializedVideo();
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
for (i = 0; i < _this->num_displays; ++i) {
|
|
|
|
SDL_VideoDisplay *display = &_this->displays[i];
|
|
|
|
for (j = 0; j < display->num_windows; ++j) {
|
|
|
|
SDL_Window *window = &display->windows[j];
|
|
|
|
if (window->id == windowID) {
|
|
|
|
return window;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
2001-04-26 16:45:43 +00:00
|
|
|
}
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
SDL_VideoDisplay *
|
|
|
|
SDL_GetDisplayFromWindow(SDL_Window * window)
|
|
|
|
{
|
2008-09-15 04:32:36 +00:00
|
|
|
if (!_this) {
|
|
|
|
SDL_UninitializedVideo();
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if (!window) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return &_this->displays[window->display];
|
2001-04-26 16:45:43 +00:00
|
|
|
}
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
Uint32
|
|
|
|
SDL_GetWindowFlags(SDL_WindowID windowID)
|
|
|
|
{
|
2008-09-15 04:32:36 +00:00
|
|
|
SDL_Window *window = SDL_GetWindowFromID(windowID);
|
2006-07-10 21:04:37 +00:00
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
if (!window) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return window->flags;
|
2001-04-26 16:45:43 +00:00
|
|
|
}
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
void
|
|
|
|
SDL_SetWindowTitle(SDL_WindowID windowID, const char *title)
|
|
|
|
{
|
2008-09-15 04:32:36 +00:00
|
|
|
SDL_Window *window = SDL_GetWindowFromID(windowID);
|
2006-07-29 21:51:00 +00:00
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
if (!window || title == window->title) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (window->title) {
|
|
|
|
SDL_free(window->title);
|
|
|
|
}
|
|
|
|
if (title) {
|
|
|
|
window->title = SDL_strdup(title);
|
|
|
|
} else {
|
|
|
|
window->title = NULL;
|
|
|
|
}
|
2006-07-10 21:04:37 +00:00
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
if (_this->SetWindowTitle) {
|
|
|
|
_this->SetWindowTitle(_this, window);
|
|
|
|
}
|
2001-04-26 16:45:43 +00:00
|
|
|
}
|
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
const char *
|
2006-07-10 21:04:37 +00:00
|
|
|
SDL_GetWindowTitle(SDL_WindowID windowID)
|
|
|
|
{
|
2008-09-15 04:32:36 +00:00
|
|
|
SDL_Window *window = SDL_GetWindowFromID(windowID);
|
2006-07-10 21:04:37 +00:00
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
if (!window) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return window->title;
|
2001-04-26 16:45:43 +00:00
|
|
|
}
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
void
|
|
|
|
SDL_SetWindowData(SDL_WindowID windowID, void *userdata)
|
|
|
|
{
|
2008-09-15 04:32:36 +00:00
|
|
|
SDL_Window *window = SDL_GetWindowFromID(windowID);
|
2006-07-10 21:04:37 +00:00
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
if (!window) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
window->userdata = userdata;
|
2001-04-26 16:45:43 +00:00
|
|
|
}
|
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
void *
|
2006-07-10 21:04:37 +00:00
|
|
|
SDL_GetWindowData(SDL_WindowID windowID)
|
2001-04-26 16:45:43 +00:00
|
|
|
{
|
2008-09-15 04:32:36 +00:00
|
|
|
SDL_Window *window = SDL_GetWindowFromID(windowID);
|
2001-04-26 16:45:43 +00:00
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
if (!window) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return window->userdata;
|
2001-04-26 16:45:43 +00:00
|
|
|
}
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
void
|
|
|
|
SDL_SetWindowPosition(SDL_WindowID windowID, int x, int y)
|
|
|
|
{
|
2008-09-15 04:32:36 +00:00
|
|
|
SDL_Window *window = SDL_GetWindowFromID(windowID);
|
|
|
|
SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
|
|
|
|
|
|
|
|
if (!window) {
|
|
|
|
return;
|
|
|
|
}
|
2008-12-17 07:17:54 +00:00
|
|
|
if (x != SDL_WINDOWPOS_UNDEFINED) {
|
2008-09-15 04:32:36 +00:00
|
|
|
window->x = x;
|
|
|
|
}
|
2008-12-17 07:17:54 +00:00
|
|
|
if (y != SDL_WINDOWPOS_UNDEFINED) {
|
2008-09-15 04:32:36 +00:00
|
|
|
window->y = y;
|
|
|
|
}
|
|
|
|
if (_this->SetWindowPosition) {
|
|
|
|
_this->SetWindowPosition(_this, window);
|
|
|
|
}
|
2008-12-17 07:17:54 +00:00
|
|
|
SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_MOVED, x, y);
|
2001-04-26 16:45:43 +00:00
|
|
|
}
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
void
|
|
|
|
SDL_GetWindowPosition(SDL_WindowID windowID, int *x, int *y)
|
2001-04-26 16:45:43 +00:00
|
|
|
{
|
2008-09-15 04:32:36 +00:00
|
|
|
SDL_Window *window = SDL_GetWindowFromID(windowID);
|
2006-07-10 21:04:37 +00:00
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
if (!window) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (x) {
|
|
|
|
*x = window->x;
|
|
|
|
}
|
|
|
|
if (y) {
|
|
|
|
*y = window->y;
|
|
|
|
}
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
2001-04-26 16:45:43 +00:00
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
void
|
|
|
|
SDL_SetWindowSize(SDL_WindowID windowID, int w, int h)
|
|
|
|
{
|
2008-09-15 04:32:36 +00:00
|
|
|
SDL_Window *window = SDL_GetWindowFromID(windowID);
|
2006-07-10 21:04:37 +00:00
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
if (!window) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
window->w = w;
|
|
|
|
window->h = h;
|
2006-07-10 21:04:37 +00:00
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
if (_this->SetWindowSize) {
|
|
|
|
_this->SetWindowSize(_this, window);
|
|
|
|
}
|
2008-12-07 21:53:28 +00:00
|
|
|
SDL_OnWindowResized(window);
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SDL_GetWindowSize(SDL_WindowID windowID, int *w, int *h)
|
|
|
|
{
|
2008-09-15 04:32:36 +00:00
|
|
|
SDL_Window *window = SDL_GetWindowFromID(windowID);
|
2006-07-10 21:04:37 +00:00
|
|
|
|
2008-12-08 00:52:12 +00:00
|
|
|
if (window) {
|
2008-12-07 21:53:28 +00:00
|
|
|
if (w) {
|
|
|
|
*w = window->w;
|
|
|
|
}
|
|
|
|
if (h) {
|
|
|
|
*h = window->h;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (w) {
|
|
|
|
*w = 0;
|
|
|
|
}
|
|
|
|
if (h) {
|
|
|
|
*h = 0;
|
|
|
|
}
|
2008-09-15 04:32:36 +00:00
|
|
|
}
|
2001-04-26 16:45:43 +00:00
|
|
|
}
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
void
|
|
|
|
SDL_ShowWindow(SDL_WindowID windowID)
|
2001-04-26 16:45:43 +00:00
|
|
|
{
|
2008-09-15 04:32:36 +00:00
|
|
|
SDL_Window *window = SDL_GetWindowFromID(windowID);
|
2001-04-26 16:45:43 +00:00
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
if (!window || (window->flags & SDL_WINDOW_SHOWN)) {
|
|
|
|
return;
|
|
|
|
}
|
2006-07-10 21:04:37 +00:00
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
if (_this->ShowWindow) {
|
|
|
|
_this->ShowWindow(_this, window);
|
|
|
|
}
|
2008-12-17 07:17:54 +00:00
|
|
|
SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_SHOWN, 0, 0);
|
2001-04-26 16:45:43 +00:00
|
|
|
}
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
void
|
|
|
|
SDL_HideWindow(SDL_WindowID windowID)
|
|
|
|
{
|
2008-09-15 04:32:36 +00:00
|
|
|
SDL_Window *window = SDL_GetWindowFromID(windowID);
|
2006-07-10 21:04:37 +00:00
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
if (!window || !(window->flags & SDL_WINDOW_SHOWN)) {
|
|
|
|
return;
|
|
|
|
}
|
2006-07-10 21:04:37 +00:00
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
if (_this->HideWindow) {
|
|
|
|
_this->HideWindow(_this, window);
|
|
|
|
}
|
2008-12-17 07:17:54 +00:00
|
|
|
SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_HIDDEN, 0, 0);
|
2001-04-26 16:45:43 +00:00
|
|
|
}
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
void
|
|
|
|
SDL_RaiseWindow(SDL_WindowID windowID)
|
2001-04-26 16:45:43 +00:00
|
|
|
{
|
2008-09-15 04:32:36 +00:00
|
|
|
SDL_Window *window = SDL_GetWindowFromID(windowID);
|
2006-07-10 21:04:37 +00:00
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
if (!window || !(window->flags & SDL_WINDOW_SHOWN)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (_this->RaiseWindow) {
|
|
|
|
_this->RaiseWindow(_this, window);
|
|
|
|
}
|
2001-04-26 16:45:43 +00:00
|
|
|
}
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
void
|
|
|
|
SDL_MaximizeWindow(SDL_WindowID windowID)
|
|
|
|
{
|
2008-09-15 04:32:36 +00:00
|
|
|
SDL_Window *window = SDL_GetWindowFromID(windowID);
|
2006-07-10 21:04:37 +00:00
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
if (!window || (window->flags & SDL_WINDOW_MAXIMIZED)) {
|
|
|
|
return;
|
|
|
|
}
|
2006-07-10 21:04:37 +00:00
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
if (_this->MaximizeWindow) {
|
|
|
|
_this->MaximizeWindow(_this, window);
|
|
|
|
}
|
2008-12-17 07:17:54 +00:00
|
|
|
SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_MAXIMIZED, 0, 0);
|
2001-04-26 16:45:43 +00:00
|
|
|
}
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
void
|
|
|
|
SDL_MinimizeWindow(SDL_WindowID windowID)
|
2001-04-26 16:45:43 +00:00
|
|
|
{
|
2008-09-15 04:32:36 +00:00
|
|
|
SDL_Window *window = SDL_GetWindowFromID(windowID);
|
2001-04-26 16:45:43 +00:00
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
if (!window || (window->flags & SDL_WINDOW_MINIMIZED)) {
|
|
|
|
return;
|
|
|
|
}
|
2001-04-26 16:45:43 +00:00
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
if (_this->MinimizeWindow) {
|
|
|
|
_this->MinimizeWindow(_this, window);
|
|
|
|
}
|
2008-12-17 07:17:54 +00:00
|
|
|
SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_MINIMIZED, 0, 0);
|
2001-04-26 16:45:43 +00:00
|
|
|
}
|
2006-07-10 21:04:37 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
SDL_RestoreWindow(SDL_WindowID windowID)
|
2001-04-26 16:45:43 +00:00
|
|
|
{
|
2008-09-15 04:32:36 +00:00
|
|
|
SDL_Window *window = SDL_GetWindowFromID(windowID);
|
2001-04-26 16:45:43 +00:00
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
if (!window
|
|
|
|
|| (window->flags & (SDL_WINDOW_MAXIMIZED | SDL_WINDOW_MINIMIZED))) {
|
|
|
|
return;
|
|
|
|
}
|
2001-04-26 16:45:43 +00:00
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
if (_this->RestoreWindow) {
|
|
|
|
_this->RestoreWindow(_this, window);
|
|
|
|
}
|
2008-12-17 07:17:54 +00:00
|
|
|
SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_RESTORED, 0, 0);
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
SDL_SetWindowFullscreen(SDL_WindowID windowID, int fullscreen)
|
|
|
|
{
|
2008-09-15 04:32:36 +00:00
|
|
|
SDL_Window *window = SDL_GetWindowFromID(windowID);
|
|
|
|
|
|
|
|
if (!window) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (fullscreen) {
|
|
|
|
fullscreen = SDL_WINDOW_FULLSCREEN;
|
|
|
|
}
|
|
|
|
if ((window->flags & SDL_WINDOW_FULLSCREEN) == fullscreen) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (fullscreen) {
|
|
|
|
window->flags |= SDL_WINDOW_FULLSCREEN;
|
|
|
|
|
|
|
|
if (FULLSCREEN_VISIBLE(window)) {
|
|
|
|
SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
|
|
|
|
|
|
|
|
/* Hide any other fullscreen windows */
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < display->num_windows; ++i) {
|
|
|
|
SDL_Window *other = &display->windows[i];
|
|
|
|
if (other->id != windowID && FULLSCREEN_VISIBLE(other)) {
|
|
|
|
SDL_MinimizeWindow(other->id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SDL_SetDisplayMode(&display->fullscreen_mode);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
window->flags &= ~SDL_WINDOW_FULLSCREEN;
|
|
|
|
|
|
|
|
if (FULLSCREEN_VISIBLE(window)) {
|
|
|
|
SDL_SetDisplayMode(NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
2001-04-26 16:45:43 +00:00
|
|
|
}
|
2006-07-10 21:04:37 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
SDL_SetWindowGrab(SDL_WindowID windowID, int mode)
|
2001-04-26 16:45:43 +00:00
|
|
|
{
|
2008-09-15 04:32:36 +00:00
|
|
|
SDL_Window *window = SDL_GetWindowFromID(windowID);
|
2001-04-26 16:45:43 +00:00
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
if (!window || (!!mode == !!(window->flags & SDL_WINDOW_INPUT_GRABBED))) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (mode) {
|
|
|
|
window->flags |= SDL_WINDOW_INPUT_GRABBED;
|
|
|
|
} else {
|
|
|
|
window->flags &= ~SDL_WINDOW_INPUT_GRABBED;
|
|
|
|
}
|
2008-12-17 07:17:54 +00:00
|
|
|
SDL_UpdateWindowGrab(window);
|
|
|
|
}
|
2001-04-26 16:45:43 +00:00
|
|
|
|
2008-12-17 07:17:54 +00:00
|
|
|
static void
|
|
|
|
SDL_UpdateWindowGrab(SDL_Window *window)
|
|
|
|
{
|
2008-09-15 04:32:36 +00:00
|
|
|
if ((window->flags & SDL_WINDOW_INPUT_FOCUS) && _this->SetWindowGrab) {
|
|
|
|
_this->SetWindowGrab(_this, window);
|
|
|
|
}
|
2001-04-26 16:45:43 +00:00
|
|
|
}
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
int
|
|
|
|
SDL_GetWindowGrab(SDL_WindowID windowID)
|
2001-04-26 16:45:43 +00:00
|
|
|
{
|
2008-09-15 04:32:36 +00:00
|
|
|
SDL_Window *window = SDL_GetWindowFromID(windowID);
|
2001-04-26 16:45:43 +00:00
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
if (!window) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return ((window->flags & SDL_WINDOW_INPUT_GRABBED) != 0);
|
2001-04-26 16:45:43 +00:00
|
|
|
}
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
void
|
|
|
|
SDL_OnWindowShown(SDL_Window * window)
|
|
|
|
{
|
2008-12-17 07:17:54 +00:00
|
|
|
if (window->flags & SDL_WINDOW_FULLSCREEN) {
|
|
|
|
SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_FOCUS_GAINED, 0, 0);
|
|
|
|
}
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SDL_OnWindowHidden(SDL_Window * window)
|
|
|
|
{
|
2008-12-17 07:17:54 +00:00
|
|
|
if (window->flags & SDL_WINDOW_FULLSCREEN) {
|
|
|
|
SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_FOCUS_LOST, 0, 0);
|
|
|
|
}
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
|
|
|
|
2006-08-06 04:39:13 +00:00
|
|
|
void
|
|
|
|
SDL_OnWindowResized(SDL_Window * window)
|
|
|
|
{
|
2008-09-15 04:32:36 +00:00
|
|
|
SDL_Renderer *renderer = window->renderer;
|
2006-08-06 04:39:13 +00:00
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
if (renderer && renderer->DisplayModeChanged) {
|
|
|
|
renderer->DisplayModeChanged(renderer);
|
|
|
|
}
|
2006-08-06 04:39:13 +00:00
|
|
|
}
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
void
|
|
|
|
SDL_OnWindowFocusGained(SDL_Window * window)
|
|
|
|
{
|
2008-09-15 04:32:36 +00:00
|
|
|
SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
|
2006-07-10 21:04:37 +00:00
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
if (window->flags & SDL_WINDOW_FULLSCREEN) {
|
|
|
|
SDL_SetDisplayMode(&display->fullscreen_mode);
|
|
|
|
}
|
|
|
|
if (display->gamma && _this->SetDisplayGammaRamp) {
|
|
|
|
_this->SetDisplayGammaRamp(_this, display->gamma);
|
|
|
|
}
|
2008-12-17 07:17:54 +00:00
|
|
|
if ((window->flags & (SDL_WINDOW_INPUT_GRABBED|SDL_WINDOW_FULLSCREEN)) && _this->SetWindowGrab) {
|
2008-09-15 04:32:36 +00:00
|
|
|
_this->SetWindowGrab(_this, window);
|
|
|
|
}
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SDL_OnWindowFocusLost(SDL_Window * window)
|
|
|
|
{
|
2008-09-15 04:32:36 +00:00
|
|
|
SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
|
2006-07-10 21:04:37 +00:00
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
if (window->flags & SDL_WINDOW_FULLSCREEN) {
|
|
|
|
SDL_MinimizeWindow(window->id);
|
|
|
|
SDL_SetDisplayMode(NULL);
|
|
|
|
}
|
|
|
|
if (display->gamma && _this->SetDisplayGammaRamp) {
|
|
|
|
_this->SetDisplayGammaRamp(_this, display->saved_gamma);
|
|
|
|
}
|
2008-12-17 07:17:54 +00:00
|
|
|
if ((window->flags & (SDL_WINDOW_INPUT_GRABBED|SDL_WINDOW_FULLSCREEN)) && _this->SetWindowGrab) {
|
2008-09-15 04:32:36 +00:00
|
|
|
_this->SetWindowGrab(_this, window);
|
|
|
|
}
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SDL_WindowID
|
|
|
|
SDL_GetFocusWindow(void)
|
|
|
|
{
|
2008-09-15 04:32:36 +00:00
|
|
|
SDL_VideoDisplay *display;
|
|
|
|
int i;
|
2006-07-10 21:04:37 +00:00
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
if (!_this) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
display = &SDL_CurrentDisplay;
|
|
|
|
for (i = 0; i < display->num_windows; ++i) {
|
|
|
|
SDL_Window *window = &display->windows[i];
|
2006-07-10 21:04:37 +00:00
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
if (window->flags & SDL_WINDOW_INPUT_FOCUS) {
|
|
|
|
return window->id;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SDL_DestroyWindow(SDL_WindowID windowID)
|
|
|
|
{
|
2008-09-15 04:32:36 +00:00
|
|
|
int i, j;
|
|
|
|
|
|
|
|
if (!_this) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* Restore video mode, etc. */
|
|
|
|
SDL_SendWindowEvent(windowID, SDL_WINDOWEVENT_FOCUS_LOST, 0, 0);
|
|
|
|
|
|
|
|
for (i = 0; i < _this->num_displays; ++i) {
|
|
|
|
SDL_VideoDisplay *display = &_this->displays[i];
|
|
|
|
for (j = 0; j < display->num_windows; ++j) {
|
|
|
|
SDL_Window *window = &display->windows[j];
|
|
|
|
if (window->id != windowID) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (window->title) {
|
|
|
|
SDL_free(window->title);
|
|
|
|
window->title = NULL;
|
|
|
|
}
|
|
|
|
if (window->renderer) {
|
|
|
|
SDL_DestroyRenderer(window->id);
|
|
|
|
window->renderer = NULL;
|
|
|
|
}
|
|
|
|
if (_this->DestroyWindow) {
|
|
|
|
_this->DestroyWindow(_this, window);
|
|
|
|
}
|
|
|
|
if (j != display->num_windows - 1) {
|
|
|
|
SDL_memcpy(&display->windows[i],
|
|
|
|
&display->windows[i + 1],
|
|
|
|
(display->num_windows - i - 1) * sizeof(*window));
|
|
|
|
}
|
|
|
|
--display->num_windows;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SDL_AddRenderDriver(int displayIndex, const SDL_RenderDriver * driver)
|
|
|
|
{
|
2008-09-15 04:32:36 +00:00
|
|
|
SDL_VideoDisplay *display;
|
|
|
|
SDL_RenderDriver *render_drivers;
|
2006-07-10 21:04:37 +00:00
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
if (displayIndex >= _this->num_displays) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
display = &_this->displays[displayIndex];
|
2007-06-14 06:32:36 +00:00
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
render_drivers =
|
|
|
|
SDL_realloc(display->render_drivers,
|
|
|
|
(display->num_render_drivers +
|
|
|
|
1) * sizeof(*render_drivers));
|
|
|
|
if (render_drivers) {
|
|
|
|
render_drivers[display->num_render_drivers] = *driver;
|
|
|
|
display->render_drivers = render_drivers;
|
|
|
|
display->num_render_drivers++;
|
|
|
|
}
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2006-08-06 00:09:04 +00:00
|
|
|
SDL_GetNumRenderDrivers(void)
|
2006-07-10 21:04:37 +00:00
|
|
|
{
|
2008-09-15 04:32:36 +00:00
|
|
|
if (_this) {
|
|
|
|
return SDL_CurrentDisplay.num_render_drivers;
|
|
|
|
}
|
|
|
|
return 0;
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2006-08-06 00:09:04 +00:00
|
|
|
SDL_GetRenderDriverInfo(int index, SDL_RendererInfo * info)
|
2006-07-10 21:04:37 +00:00
|
|
|
{
|
2008-09-15 04:32:36 +00:00
|
|
|
if (!_this) {
|
|
|
|
SDL_UninitializedVideo();
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (index < 0 || index >= SDL_GetNumRenderDrivers()) {
|
|
|
|
SDL_SetError("index must be in the range of 0 - %d",
|
|
|
|
SDL_GetNumRenderDrivers() - 1);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
*info = SDL_CurrentDisplay.render_drivers[index].info;
|
|
|
|
return 0;
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
SDL_CreateRenderer(SDL_WindowID windowID, int index, Uint32 flags)
|
|
|
|
{
|
2008-09-15 04:32:36 +00:00
|
|
|
SDL_Window *window = SDL_GetWindowFromID(windowID);
|
|
|
|
|
|
|
|
if (!window) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (index < 0) {
|
|
|
|
const char *override = SDL_getenv("SDL_VIDEO_RENDERER");
|
|
|
|
int n = SDL_GetNumRenderDrivers();
|
|
|
|
for (index = 0; index < n; ++index) {
|
|
|
|
SDL_RenderDriver *driver =
|
|
|
|
&SDL_CurrentDisplay.render_drivers[index];
|
|
|
|
|
|
|
|
if (override) {
|
|
|
|
if (SDL_strcasecmp(override, driver->info.name) == 0) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if ((driver->info.flags & flags) == flags) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (index == n) {
|
|
|
|
SDL_SetError("Couldn't find matching render driver");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (index >= SDL_GetNumRenderDrivers()) {
|
|
|
|
SDL_SetError("index must be -1 or in the range of 0 - %d",
|
|
|
|
SDL_GetNumRenderDrivers() - 1);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
/* Free any existing renderer */
|
|
|
|
SDL_DestroyRenderer(windowID);
|
|
|
|
|
|
|
|
/* Create a new renderer instance */
|
|
|
|
window->renderer = SDL_CurrentDisplay.render_drivers[index]
|
|
|
|
.CreateRenderer(window, flags);
|
|
|
|
SDL_SelectRenderer(window->id);
|
|
|
|
|
|
|
|
return 0;
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
SDL_SelectRenderer(SDL_WindowID windowID)
|
|
|
|
{
|
2008-09-15 04:32:36 +00:00
|
|
|
SDL_Window *window = SDL_GetWindowFromID(windowID);
|
|
|
|
SDL_Renderer *renderer;
|
2006-07-10 21:04:37 +00:00
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
if (!window || !window->renderer) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
renderer = window->renderer;
|
|
|
|
if (renderer && renderer->ActivateRenderer) {
|
|
|
|
if (renderer->ActivateRenderer(renderer) < 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SDL_CurrentDisplay.current_renderer = renderer;
|
|
|
|
return 0;
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
|
|
|
|
2006-08-06 00:09:04 +00:00
|
|
|
int
|
|
|
|
SDL_GetRendererInfo(SDL_RendererInfo * info)
|
|
|
|
{
|
2008-09-15 04:32:36 +00:00
|
|
|
if (!_this) {
|
|
|
|
SDL_UninitializedVideo();
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (!SDL_CurrentDisplay.current_renderer) {
|
|
|
|
SDL_SetError("There is no current renderer");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
*info = SDL_CurrentDisplay.current_renderer->info;
|
|
|
|
return 0;
|
2006-08-06 00:09:04 +00:00
|
|
|
}
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
SDL_TextureID
|
|
|
|
SDL_CreateTexture(Uint32 format, int access, int w, int h)
|
|
|
|
{
|
2008-09-15 04:32:36 +00:00
|
|
|
int hash;
|
|
|
|
SDL_Renderer *renderer;
|
|
|
|
SDL_Texture *texture;
|
|
|
|
|
|
|
|
if (!_this) {
|
|
|
|
SDL_UninitializedVideo();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
renderer = SDL_CurrentDisplay.current_renderer;
|
2008-11-30 21:58:23 +00:00
|
|
|
if (!renderer) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (!renderer->CreateTexture) {
|
|
|
|
SDL_Unsupported();
|
2008-09-15 04:32:36 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
texture = (SDL_Texture *) SDL_calloc(1, sizeof(*texture));
|
|
|
|
if (!texture) {
|
|
|
|
SDL_OutOfMemory();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
texture->id = _this->next_object_id++;
|
|
|
|
texture->format = format;
|
|
|
|
texture->access = access;
|
|
|
|
texture->w = w;
|
|
|
|
texture->h = h;
|
|
|
|
texture->r = 255;
|
|
|
|
texture->g = 255;
|
|
|
|
texture->b = 255;
|
|
|
|
texture->a = 255;
|
|
|
|
texture->renderer = renderer;
|
|
|
|
|
|
|
|
if (renderer->CreateTexture(renderer, texture) < 0) {
|
|
|
|
if (renderer->DestroyTexture) {
|
|
|
|
renderer->DestroyTexture(renderer, texture);
|
|
|
|
}
|
|
|
|
SDL_free(texture);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
hash = (texture->id % SDL_arraysize(SDL_CurrentDisplay.textures));
|
|
|
|
texture->next = SDL_CurrentDisplay.textures[hash];
|
|
|
|
SDL_CurrentDisplay.textures[hash] = texture;
|
|
|
|
|
|
|
|
return texture->id;
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SDL_TextureID
|
2007-08-11 20:54:31 +00:00
|
|
|
SDL_CreateTextureFromSurface(Uint32 format, SDL_Surface * surface)
|
2006-07-10 21:04:37 +00:00
|
|
|
{
|
2008-09-15 04:32:36 +00:00
|
|
|
SDL_TextureID textureID;
|
|
|
|
SDL_PixelFormat *fmt;
|
|
|
|
int bpp;
|
|
|
|
Uint32 Rmask, Gmask, Bmask, Amask;
|
|
|
|
|
|
|
|
if (!surface) {
|
|
|
|
SDL_SetError("SDL_CreateTextureFromSurface() passed NULL surface");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
fmt = surface->format;
|
|
|
|
|
|
|
|
if (format) {
|
|
|
|
if (!SDL_PixelFormatEnumToMasks
|
|
|
|
(format, &bpp, &Rmask, &Gmask, &Bmask, &Amask)) {
|
|
|
|
SDL_SetError("Unknown pixel format");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (surface->format->Amask
|
|
|
|
|| !(surface->map->info.flags &
|
|
|
|
(SDL_COPY_COLORKEY | SDL_COPY_MASK | SDL_COPY_BLEND))) {
|
|
|
|
bpp = fmt->BitsPerPixel;
|
|
|
|
Rmask = fmt->Rmask;
|
|
|
|
Gmask = fmt->Gmask;
|
|
|
|
Bmask = fmt->Bmask;
|
|
|
|
Amask = fmt->Amask;
|
|
|
|
} else {
|
|
|
|
/* Need a format with alpha */
|
|
|
|
bpp = 32;
|
|
|
|
Rmask = 0x00FF0000;
|
|
|
|
Gmask = 0x0000FF00;
|
|
|
|
Bmask = 0x000000FF;
|
|
|
|
Amask = 0xFF000000;
|
|
|
|
}
|
|
|
|
format = SDL_MasksToPixelFormatEnum(bpp, Rmask, Gmask, Bmask, Amask);
|
|
|
|
if (!format) {
|
|
|
|
SDL_SetError("Unknown pixel format");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
textureID =
|
|
|
|
SDL_CreateTexture(format, SDL_TEXTUREACCESS_STATIC, surface->w,
|
|
|
|
surface->h);
|
|
|
|
if (!textureID) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (bpp == fmt->BitsPerPixel && Rmask == fmt->Rmask && Gmask == fmt->Gmask
|
|
|
|
&& Bmask == fmt->Bmask && Amask == fmt->Amask) {
|
|
|
|
if (SDL_MUSTLOCK(surface)) {
|
|
|
|
if (SDL_LockSurface(surface) < 0) {
|
|
|
|
SDL_DestroyTexture(textureID);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
SDL_UpdateTexture(textureID, NULL, surface->pixels,
|
|
|
|
surface->pitch);
|
|
|
|
SDL_UnlockSurface(surface);
|
|
|
|
} else {
|
|
|
|
SDL_UpdateTexture(textureID, NULL, surface->pixels,
|
|
|
|
surface->pitch);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
SDL_PixelFormat *dst_fmt;
|
|
|
|
SDL_Surface *dst = NULL;
|
|
|
|
|
|
|
|
/* Set up a destination surface for the texture update */
|
|
|
|
dst_fmt = SDL_AllocFormat(bpp, Rmask, Gmask, Bmask, Amask);
|
|
|
|
if (dst_fmt) {
|
|
|
|
if (SDL_ISPIXELFORMAT_INDEXED(format)) {
|
|
|
|
dst_fmt->palette =
|
|
|
|
SDL_AllocPalette((1 << SDL_BITSPERPIXEL(format)));
|
|
|
|
if (dst_fmt->palette) {
|
|
|
|
/*
|
|
|
|
* FIXME: Should we try to copy
|
|
|
|
* fmt->palette?
|
|
|
|
*/
|
|
|
|
SDL_DitherColors(dst_fmt->palette->colors,
|
|
|
|
SDL_BITSPERPIXEL(format));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
dst = SDL_ConvertSurface(surface, dst_fmt, 0);
|
|
|
|
if (dst) {
|
|
|
|
SDL_UpdateTexture(textureID, NULL, dst->pixels, dst->pitch);
|
|
|
|
SDL_FreeSurface(dst);
|
|
|
|
}
|
|
|
|
if (dst_fmt->palette) {
|
|
|
|
SDL_FreePalette(dst_fmt->palette);
|
|
|
|
}
|
|
|
|
SDL_FreeFormat(dst_fmt);
|
|
|
|
}
|
|
|
|
if (!dst) {
|
|
|
|
SDL_DestroyTexture(textureID);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (SDL_ISPIXELFORMAT_INDEXED(format) && fmt->palette) {
|
|
|
|
SDL_SetTexturePalette(textureID, fmt->palette->colors, 0,
|
|
|
|
fmt->palette->ncolors);
|
|
|
|
}
|
|
|
|
return textureID;
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static __inline__ SDL_Texture *
|
|
|
|
SDL_GetTextureFromID(SDL_TextureID textureID)
|
|
|
|
{
|
2008-09-15 04:32:36 +00:00
|
|
|
int hash;
|
|
|
|
SDL_Texture *texture;
|
2006-07-10 21:04:37 +00:00
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
if (!_this) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
hash = (textureID % SDL_arraysize(SDL_CurrentDisplay.textures));
|
|
|
|
for (texture = SDL_CurrentDisplay.textures[hash]; texture;
|
|
|
|
texture = texture->next) {
|
|
|
|
if (texture->id == textureID) {
|
|
|
|
return texture;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
SDL_QueryTexture(SDL_TextureID textureID, Uint32 * format, int *access,
|
2008-09-15 04:32:36 +00:00
|
|
|
int *w, int *h)
|
|
|
|
{
|
|
|
|
SDL_Texture *texture = SDL_GetTextureFromID(textureID);
|
|
|
|
|
|
|
|
if (!texture) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (format) {
|
|
|
|
*format = texture->format;
|
|
|
|
}
|
|
|
|
if (access) {
|
|
|
|
*access = texture->access;
|
|
|
|
}
|
|
|
|
if (w) {
|
|
|
|
*w = texture->w;
|
|
|
|
}
|
|
|
|
if (h) {
|
|
|
|
*h = texture->h;
|
|
|
|
}
|
|
|
|
return 0;
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
SDL_QueryTexturePixels(SDL_TextureID textureID, void **pixels, int *pitch)
|
|
|
|
{
|
2008-09-15 04:32:36 +00:00
|
|
|
SDL_Texture *texture = SDL_GetTextureFromID(textureID);
|
|
|
|
SDL_Renderer *renderer;
|
2006-07-10 21:04:37 +00:00
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
if (!texture) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
renderer = texture->renderer;
|
|
|
|
if (!renderer->QueryTexturePixels) {
|
2008-11-30 21:58:23 +00:00
|
|
|
SDL_Unsupported();
|
2008-09-15 04:32:36 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return renderer->QueryTexturePixels(renderer, texture, pixels, pitch);
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
SDL_SetTexturePalette(SDL_TextureID textureID, const SDL_Color * colors,
|
2008-09-15 04:32:36 +00:00
|
|
|
int firstcolor, int ncolors)
|
2006-07-10 21:04:37 +00:00
|
|
|
{
|
2008-09-15 04:32:36 +00:00
|
|
|
SDL_Texture *texture = SDL_GetTextureFromID(textureID);
|
|
|
|
SDL_Renderer *renderer;
|
2006-07-10 21:04:37 +00:00
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
if (!texture) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
renderer = texture->renderer;
|
|
|
|
if (!renderer->SetTexturePalette) {
|
2008-11-30 21:58:23 +00:00
|
|
|
SDL_Unsupported();
|
2008-09-15 04:32:36 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return renderer->SetTexturePalette(renderer, texture, colors, firstcolor,
|
|
|
|
ncolors);
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
SDL_GetTexturePalette(SDL_TextureID textureID, SDL_Color * colors,
|
2008-09-15 04:32:36 +00:00
|
|
|
int firstcolor, int ncolors)
|
2006-07-10 21:04:37 +00:00
|
|
|
{
|
2008-09-15 04:32:36 +00:00
|
|
|
SDL_Texture *texture = SDL_GetTextureFromID(textureID);
|
|
|
|
SDL_Renderer *renderer;
|
2006-07-10 21:04:37 +00:00
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
if (!texture) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
renderer = texture->renderer;
|
|
|
|
if (!renderer->GetTexturePalette) {
|
2008-11-30 21:58:23 +00:00
|
|
|
SDL_Unsupported();
|
2008-09-15 04:32:36 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return renderer->GetTexturePalette(renderer, texture, colors, firstcolor,
|
|
|
|
ncolors);
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
|
|
|
|
2006-08-28 03:17:39 +00:00
|
|
|
int
|
|
|
|
SDL_SetTextureColorMod(SDL_TextureID textureID, Uint8 r, Uint8 g, Uint8 b)
|
|
|
|
{
|
2008-09-15 04:32:36 +00:00
|
|
|
SDL_Texture *texture = SDL_GetTextureFromID(textureID);
|
|
|
|
SDL_Renderer *renderer;
|
|
|
|
|
|
|
|
if (!texture) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
renderer = texture->renderer;
|
|
|
|
if (!renderer->SetTextureColorMod) {
|
2008-11-30 21:58:23 +00:00
|
|
|
SDL_Unsupported();
|
2008-09-15 04:32:36 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (r < 255 || g < 255 || b < 255) {
|
|
|
|
texture->modMode |= SDL_TEXTUREMODULATE_COLOR;
|
|
|
|
} else {
|
|
|
|
texture->modMode &= ~SDL_TEXTUREMODULATE_COLOR;
|
|
|
|
}
|
|
|
|
texture->r = r;
|
|
|
|
texture->g = g;
|
|
|
|
texture->b = b;
|
|
|
|
return renderer->SetTextureColorMod(renderer, texture);
|
2006-08-28 03:17:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
SDL_GetTextureColorMod(SDL_TextureID textureID, Uint8 * r, Uint8 * g,
|
2008-09-15 04:32:36 +00:00
|
|
|
Uint8 * b)
|
|
|
|
{
|
|
|
|
SDL_Texture *texture = SDL_GetTextureFromID(textureID);
|
|
|
|
SDL_Renderer *renderer;
|
|
|
|
|
|
|
|
if (!texture) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
renderer = texture->renderer;
|
|
|
|
if (r) {
|
|
|
|
*r = texture->r;
|
|
|
|
}
|
|
|
|
if (g) {
|
|
|
|
*g = texture->g;
|
|
|
|
}
|
|
|
|
if (b) {
|
|
|
|
*b = texture->b;
|
|
|
|
}
|
|
|
|
return 0;
|
2006-08-28 03:17:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
SDL_SetTextureAlphaMod(SDL_TextureID textureID, Uint8 alpha)
|
|
|
|
{
|
2008-09-15 04:32:36 +00:00
|
|
|
SDL_Texture *texture = SDL_GetTextureFromID(textureID);
|
|
|
|
SDL_Renderer *renderer;
|
|
|
|
|
|
|
|
if (!texture) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
renderer = texture->renderer;
|
|
|
|
if (!renderer->SetTextureAlphaMod) {
|
2008-11-30 21:58:23 +00:00
|
|
|
SDL_Unsupported();
|
2008-09-15 04:32:36 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (alpha < 255) {
|
|
|
|
texture->modMode |= SDL_TEXTUREMODULATE_ALPHA;
|
|
|
|
} else {
|
|
|
|
texture->modMode &= ~SDL_TEXTUREMODULATE_ALPHA;
|
|
|
|
}
|
|
|
|
texture->a = alpha;
|
|
|
|
return renderer->SetTextureAlphaMod(renderer, texture);
|
2006-08-28 03:17:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
SDL_GetTextureAlphaMod(SDL_TextureID textureID, Uint8 * alpha)
|
|
|
|
{
|
2008-09-15 04:32:36 +00:00
|
|
|
SDL_Texture *texture = SDL_GetTextureFromID(textureID);
|
2006-08-28 03:17:39 +00:00
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
if (!texture) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (alpha) {
|
|
|
|
*alpha = texture->a;
|
|
|
|
}
|
|
|
|
return 0;
|
2006-08-28 03:17:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
SDL_SetTextureBlendMode(SDL_TextureID textureID, int blendMode)
|
|
|
|
{
|
2008-09-15 04:32:36 +00:00
|
|
|
SDL_Texture *texture = SDL_GetTextureFromID(textureID);
|
|
|
|
SDL_Renderer *renderer;
|
2006-08-28 03:17:39 +00:00
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
if (!texture) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
renderer = texture->renderer;
|
|
|
|
if (!renderer->SetTextureBlendMode) {
|
2008-11-30 21:58:23 +00:00
|
|
|
SDL_Unsupported();
|
2008-09-15 04:32:36 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
texture->blendMode = blendMode;
|
|
|
|
return renderer->SetTextureBlendMode(renderer, texture);
|
2006-08-28 03:17:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
SDL_GetTextureBlendMode(SDL_TextureID textureID, int *blendMode)
|
|
|
|
{
|
2008-09-15 04:32:36 +00:00
|
|
|
SDL_Texture *texture = SDL_GetTextureFromID(textureID);
|
2006-08-28 03:17:39 +00:00
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
if (!texture) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (blendMode) {
|
|
|
|
*blendMode = texture->blendMode;
|
|
|
|
}
|
|
|
|
return 0;
|
2006-08-28 03:17:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
SDL_SetTextureScaleMode(SDL_TextureID textureID, int scaleMode)
|
|
|
|
{
|
2008-09-15 04:32:36 +00:00
|
|
|
SDL_Texture *texture = SDL_GetTextureFromID(textureID);
|
|
|
|
SDL_Renderer *renderer;
|
2006-08-28 03:17:39 +00:00
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
if (!texture) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
renderer = texture->renderer;
|
|
|
|
if (!renderer->SetTextureScaleMode) {
|
2008-11-30 21:58:23 +00:00
|
|
|
SDL_Unsupported();
|
2008-09-15 04:32:36 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
texture->scaleMode = scaleMode;
|
|
|
|
return renderer->SetTextureScaleMode(renderer, texture);
|
2006-08-28 03:17:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
SDL_GetTextureScaleMode(SDL_TextureID textureID, int *scaleMode)
|
|
|
|
{
|
2008-09-15 04:32:36 +00:00
|
|
|
SDL_Texture *texture = SDL_GetTextureFromID(textureID);
|
2006-08-28 03:17:39 +00:00
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
if (!texture) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (scaleMode) {
|
|
|
|
*scaleMode = texture->scaleMode;
|
|
|
|
}
|
|
|
|
return 0;
|
2006-08-28 03:17:39 +00:00
|
|
|
}
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
int
|
|
|
|
SDL_UpdateTexture(SDL_TextureID textureID, const SDL_Rect * rect,
|
2008-09-15 04:32:36 +00:00
|
|
|
const void *pixels, int pitch)
|
|
|
|
{
|
|
|
|
SDL_Texture *texture = SDL_GetTextureFromID(textureID);
|
|
|
|
SDL_Renderer *renderer;
|
|
|
|
SDL_Rect full_rect;
|
|
|
|
|
|
|
|
if (!texture) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
renderer = texture->renderer;
|
|
|
|
if (!renderer->UpdateTexture) {
|
2008-11-30 21:58:23 +00:00
|
|
|
SDL_Unsupported();
|
2008-09-15 04:32:36 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (!rect) {
|
|
|
|
full_rect.x = 0;
|
|
|
|
full_rect.y = 0;
|
|
|
|
full_rect.w = texture->w;
|
|
|
|
full_rect.h = texture->h;
|
|
|
|
rect = &full_rect;
|
|
|
|
}
|
|
|
|
return renderer->UpdateTexture(renderer, texture, rect, pixels, pitch);
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
SDL_LockTexture(SDL_TextureID textureID, const SDL_Rect * rect, int markDirty,
|
2008-09-15 04:32:36 +00:00
|
|
|
void **pixels, int *pitch)
|
|
|
|
{
|
|
|
|
SDL_Texture *texture = SDL_GetTextureFromID(textureID);
|
|
|
|
SDL_Renderer *renderer;
|
|
|
|
SDL_Rect full_rect;
|
|
|
|
|
|
|
|
if (!texture) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (texture->access != SDL_TEXTUREACCESS_STREAMING) {
|
|
|
|
SDL_SetError("SDL_LockTexture(): texture must be streaming");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
renderer = texture->renderer;
|
|
|
|
if (!renderer->LockTexture) {
|
2008-11-30 21:58:23 +00:00
|
|
|
SDL_Unsupported();
|
2008-09-15 04:32:36 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (!rect) {
|
|
|
|
full_rect.x = 0;
|
|
|
|
full_rect.y = 0;
|
|
|
|
full_rect.w = texture->w;
|
|
|
|
full_rect.h = texture->h;
|
|
|
|
rect = &full_rect;
|
|
|
|
}
|
|
|
|
return renderer->LockTexture(renderer, texture, rect, markDirty, pixels,
|
|
|
|
pitch);
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SDL_UnlockTexture(SDL_TextureID textureID)
|
|
|
|
{
|
2008-09-15 04:32:36 +00:00
|
|
|
SDL_Texture *texture = SDL_GetTextureFromID(textureID);
|
|
|
|
SDL_Renderer *renderer;
|
2006-07-10 21:04:37 +00:00
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
if (!texture) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (texture->access != SDL_TEXTUREACCESS_STREAMING) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
renderer = texture->renderer;
|
|
|
|
if (!renderer->UnlockTexture) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
renderer->UnlockTexture(renderer, texture);
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SDL_DirtyTexture(SDL_TextureID textureID, int numrects,
|
2008-09-15 04:32:36 +00:00
|
|
|
const SDL_Rect * rects)
|
2006-07-10 21:04:37 +00:00
|
|
|
{
|
2008-09-15 04:32:36 +00:00
|
|
|
SDL_Texture *texture = SDL_GetTextureFromID(textureID);
|
|
|
|
SDL_Renderer *renderer;
|
2006-07-10 21:04:37 +00:00
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
if (!texture) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (texture->access != SDL_TEXTUREACCESS_STREAMING) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
renderer = texture->renderer;
|
|
|
|
if (!renderer->DirtyTexture) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
renderer->DirtyTexture(renderer, texture, numrects, rects);
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2006-08-28 03:17:39 +00:00
|
|
|
SDL_RenderFill(Uint8 r, Uint8 g, Uint8 b, Uint8 a, const SDL_Rect * rect)
|
2006-07-10 21:04:37 +00:00
|
|
|
{
|
2008-09-15 04:32:36 +00:00
|
|
|
SDL_Renderer *renderer;
|
|
|
|
SDL_Window *window;
|
|
|
|
SDL_Rect real_rect;
|
|
|
|
|
|
|
|
if (!_this) {
|
|
|
|
SDL_UninitializedVideo();
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
renderer = SDL_CurrentDisplay.current_renderer;
|
2008-11-30 21:58:23 +00:00
|
|
|
if (!renderer) {
|
|
|
|
return -1;
|
|
|
|
}
|
2008-12-01 00:07:45 +00:00
|
|
|
if (!renderer->RenderFill) {
|
2008-11-30 21:58:23 +00:00
|
|
|
SDL_Unsupported();
|
2008-09-15 04:32:36 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
window = SDL_GetWindowFromID(renderer->window);
|
|
|
|
real_rect.x = 0;
|
|
|
|
real_rect.y = 0;
|
|
|
|
real_rect.w = window->w;
|
|
|
|
real_rect.h = window->h;
|
|
|
|
if (rect) {
|
|
|
|
if (!SDL_IntersectRect(rect, &real_rect, &real_rect)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return renderer->RenderFill(renderer, r, g, b, a, &real_rect);
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
SDL_RenderCopy(SDL_TextureID textureID, const SDL_Rect * srcrect,
|
2008-09-15 04:32:36 +00:00
|
|
|
const SDL_Rect * dstrect)
|
|
|
|
{
|
|
|
|
SDL_Texture *texture = SDL_GetTextureFromID(textureID);
|
|
|
|
SDL_Renderer *renderer;
|
|
|
|
SDL_Window *window;
|
|
|
|
SDL_Rect real_srcrect;
|
|
|
|
SDL_Rect real_dstrect;
|
|
|
|
|
|
|
|
if (!texture || texture->renderer != SDL_CurrentDisplay.current_renderer) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
renderer = SDL_CurrentDisplay.current_renderer;
|
2008-11-30 21:58:23 +00:00
|
|
|
if (!renderer) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (!renderer->RenderCopy) {
|
|
|
|
SDL_Unsupported();
|
2008-09-15 04:32:36 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
window = SDL_GetWindowFromID(renderer->window);
|
|
|
|
if (srcrect) {
|
|
|
|
real_srcrect = *srcrect;
|
|
|
|
} else {
|
|
|
|
real_srcrect.x = 0;
|
|
|
|
real_srcrect.y = 0;
|
|
|
|
real_srcrect.w = texture->w;
|
|
|
|
real_srcrect.h = texture->h;
|
|
|
|
}
|
|
|
|
if (dstrect) {
|
|
|
|
real_dstrect = *dstrect;
|
|
|
|
} else {
|
|
|
|
real_dstrect.x = 0;
|
|
|
|
real_dstrect.y = 0;
|
|
|
|
real_dstrect.w = window->w;
|
|
|
|
real_dstrect.h = window->h;
|
|
|
|
}
|
|
|
|
|
|
|
|
return renderer->RenderCopy(renderer, texture, &real_srcrect,
|
|
|
|
&real_dstrect);
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SDL_RenderPresent(void)
|
|
|
|
{
|
2008-09-15 04:32:36 +00:00
|
|
|
SDL_Renderer *renderer;
|
2006-07-10 21:04:37 +00:00
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
if (!_this) {
|
|
|
|
SDL_UninitializedVideo();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
renderer = SDL_CurrentDisplay.current_renderer;
|
|
|
|
if (!renderer || !renderer->RenderPresent) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
renderer->RenderPresent(renderer);
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SDL_DestroyTexture(SDL_TextureID textureID)
|
|
|
|
{
|
2008-09-15 04:32:36 +00:00
|
|
|
int hash;
|
|
|
|
SDL_Texture *prev, *texture;
|
|
|
|
SDL_Renderer *renderer;
|
|
|
|
|
|
|
|
if (!_this) {
|
|
|
|
SDL_UninitializedVideo();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* Look up the texture in the hash table */
|
|
|
|
hash = (textureID % SDL_arraysize(SDL_CurrentDisplay.textures));
|
|
|
|
prev = NULL;
|
|
|
|
for (texture = SDL_CurrentDisplay.textures[hash]; texture;
|
|
|
|
prev = texture, texture = texture->next) {
|
|
|
|
if (texture->id == textureID) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!texture) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* Unlink the texture from the list */
|
|
|
|
if (prev) {
|
|
|
|
prev->next = texture->next;
|
|
|
|
} else {
|
|
|
|
SDL_CurrentDisplay.textures[hash] = texture->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Free the texture */
|
|
|
|
renderer = texture->renderer;
|
|
|
|
renderer->DestroyTexture(renderer, texture);
|
|
|
|
SDL_free(texture);
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SDL_DestroyRenderer(SDL_WindowID windowID)
|
|
|
|
{
|
2008-09-15 04:32:36 +00:00
|
|
|
SDL_Window *window = SDL_GetWindowFromID(windowID);
|
|
|
|
SDL_Renderer *renderer;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (!window) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
renderer = window->renderer;
|
|
|
|
if (!renderer) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* Free existing textures for this renderer */
|
|
|
|
for (i = 0; i < SDL_arraysize(SDL_CurrentDisplay.textures); ++i) {
|
|
|
|
SDL_Texture *texture;
|
|
|
|
SDL_Texture *prev = NULL;
|
|
|
|
SDL_Texture *next;
|
|
|
|
for (texture = SDL_CurrentDisplay.textures[i]; texture;
|
|
|
|
texture = next) {
|
|
|
|
next = texture->next;
|
|
|
|
if (texture->renderer == renderer) {
|
|
|
|
if (prev) {
|
|
|
|
prev->next = next;
|
|
|
|
} else {
|
|
|
|
SDL_CurrentDisplay.textures[i] = next;
|
|
|
|
}
|
|
|
|
renderer->DestroyTexture(renderer, texture);
|
|
|
|
SDL_free(texture);
|
|
|
|
} else {
|
|
|
|
prev = texture;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Free the renderer instance */
|
|
|
|
renderer->DestroyRenderer(renderer);
|
|
|
|
|
|
|
|
/* Clear references */
|
|
|
|
window->renderer = NULL;
|
|
|
|
if (SDL_CurrentDisplay.current_renderer == renderer) {
|
|
|
|
SDL_CurrentDisplay.current_renderer = NULL;
|
|
|
|
}
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SDL_VideoQuit(void)
|
|
|
|
{
|
2008-09-15 04:32:36 +00:00
|
|
|
int i, j;
|
|
|
|
|
|
|
|
if (!_this) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* Halt event processing before doing anything else */
|
|
|
|
SDL_StopEventLoop();
|
|
|
|
|
|
|
|
/* Clean up the system video */
|
|
|
|
for (i = _this->num_displays; i--;) {
|
|
|
|
SDL_VideoDisplay *display = &_this->displays[i];
|
|
|
|
for (j = display->num_windows; j--;) {
|
|
|
|
SDL_DestroyWindow(display->windows[i].id);
|
|
|
|
}
|
|
|
|
if (display->windows) {
|
|
|
|
SDL_free(display->windows);
|
|
|
|
display->windows = NULL;
|
|
|
|
}
|
|
|
|
display->num_windows = 0;
|
|
|
|
if (display->render_drivers) {
|
|
|
|
SDL_free(display->render_drivers);
|
|
|
|
display->render_drivers = NULL;
|
|
|
|
}
|
|
|
|
display->num_render_drivers = 0;
|
|
|
|
}
|
|
|
|
_this->VideoQuit(_this);
|
|
|
|
|
|
|
|
for (i = _this->num_displays; i--;) {
|
|
|
|
SDL_VideoDisplay *display = &_this->displays[i];
|
|
|
|
for (j = display->num_display_modes; j--;) {
|
|
|
|
if (display->display_modes[j].driverdata) {
|
|
|
|
SDL_free(display->display_modes[j].driverdata);
|
|
|
|
display->display_modes[j].driverdata = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (display->display_modes) {
|
|
|
|
SDL_free(display->display_modes);
|
|
|
|
display->display_modes = NULL;
|
|
|
|
}
|
|
|
|
if (display->desktop_mode.driverdata) {
|
|
|
|
SDL_free(display->desktop_mode.driverdata);
|
|
|
|
display->desktop_mode.driverdata = NULL;
|
|
|
|
}
|
|
|
|
if (display->palette) {
|
|
|
|
SDL_FreePalette(display->palette);
|
|
|
|
display->palette = NULL;
|
|
|
|
}
|
|
|
|
if (display->gamma) {
|
|
|
|
SDL_free(display->gamma);
|
|
|
|
display->gamma = NULL;
|
|
|
|
}
|
|
|
|
if (display->driverdata) {
|
|
|
|
SDL_free(display->driverdata);
|
|
|
|
display->driverdata = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (_this->displays) {
|
|
|
|
SDL_free(_this->displays);
|
|
|
|
_this->displays = NULL;
|
|
|
|
}
|
|
|
|
_this->free(_this);
|
|
|
|
_this = NULL;
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
SDL_GL_LoadLibrary(const char *path)
|
|
|
|
{
|
2008-09-15 04:32:36 +00:00
|
|
|
int retval;
|
2006-07-16 09:34:01 +00:00
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
if (!_this) {
|
|
|
|
SDL_UninitializedVideo();
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (_this->GL_LoadLibrary) {
|
|
|
|
retval = _this->GL_LoadLibrary(_this, path);
|
|
|
|
} else {
|
|
|
|
SDL_SetError("No dynamic GL support in video driver");
|
|
|
|
retval = -1;
|
|
|
|
}
|
|
|
|
return (retval);
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
void *
|
2006-07-10 21:04:37 +00:00
|
|
|
SDL_GL_GetProcAddress(const char *proc)
|
|
|
|
{
|
2008-09-15 04:32:36 +00:00
|
|
|
void *func;
|
|
|
|
|
|
|
|
if (!_this) {
|
|
|
|
SDL_UninitializedVideo();
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
func = NULL;
|
|
|
|
if (_this->GL_GetProcAddress) {
|
|
|
|
if (_this->gl_config.driver_loaded) {
|
|
|
|
func = _this->GL_GetProcAddress(_this, proc);
|
|
|
|
} else {
|
|
|
|
SDL_SetError("No GL driver has been loaded");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
SDL_SetError("No dynamic GL support in video driver");
|
|
|
|
}
|
|
|
|
return func;
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
|
|
|
|
2006-07-22 21:58:17 +00:00
|
|
|
SDL_bool
|
|
|
|
SDL_GL_ExtensionSupported(const char *extension)
|
|
|
|
{
|
2008-09-02 20:19:45 +00:00
|
|
|
#if SDL_VIDEO_OPENGL || SDL_VIDEO_OPENGL_ES
|
2008-09-15 04:32:36 +00:00
|
|
|
const GLubyte *(APIENTRY * glGetStringFunc) (GLenum);
|
|
|
|
const char *extensions;
|
|
|
|
const char *start;
|
|
|
|
const char *where, *terminator;
|
|
|
|
|
|
|
|
/* Extension names should not have spaces. */
|
|
|
|
where = SDL_strchr(extension, ' ');
|
|
|
|
if (where || *extension == '\0') {
|
|
|
|
return SDL_FALSE;
|
|
|
|
}
|
|
|
|
/* See if there's an environment variable override */
|
|
|
|
start = SDL_getenv(extension);
|
|
|
|
if (start && *start == '0') {
|
|
|
|
return SDL_FALSE;
|
|
|
|
}
|
|
|
|
/* Lookup the available extensions */
|
|
|
|
glGetStringFunc = SDL_GL_GetProcAddress("glGetString");
|
|
|
|
if (glGetStringFunc) {
|
|
|
|
extensions = (const char *) glGetStringFunc(GL_EXTENSIONS);
|
|
|
|
} else {
|
|
|
|
extensions = NULL;
|
|
|
|
}
|
|
|
|
if (!extensions) {
|
|
|
|
return SDL_FALSE;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* It takes a bit of care to be fool-proof about parsing the OpenGL
|
|
|
|
* extensions string. Don't be fooled by sub-strings, etc.
|
|
|
|
*/
|
|
|
|
|
|
|
|
start = extensions;
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
where = SDL_strstr(start, extension);
|
|
|
|
if (!where)
|
|
|
|
break;
|
|
|
|
|
|
|
|
terminator = where + SDL_strlen(extension);
|
|
|
|
if (where == start || *(where - 1) == ' ')
|
|
|
|
if (*terminator == ' ' || *terminator == '\0')
|
|
|
|
return SDL_TRUE;
|
|
|
|
|
|
|
|
start = terminator;
|
|
|
|
}
|
|
|
|
return SDL_FALSE;
|
2006-07-22 21:58:17 +00:00
|
|
|
#else
|
2008-09-15 04:32:36 +00:00
|
|
|
return SDL_FALSE;
|
2006-07-22 21:58:17 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
int
|
|
|
|
SDL_GL_SetAttribute(SDL_GLattr attr, int value)
|
|
|
|
{
|
2008-09-02 20:19:45 +00:00
|
|
|
#if SDL_VIDEO_OPENGL || SDL_VIDEO_OPENGL_ES
|
2008-09-15 04:32:36 +00:00
|
|
|
int retval;
|
|
|
|
|
|
|
|
if (!_this) {
|
|
|
|
SDL_UninitializedVideo();
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
retval = 0;
|
|
|
|
switch (attr) {
|
|
|
|
case SDL_GL_RED_SIZE:
|
|
|
|
_this->gl_config.red_size = value;
|
|
|
|
break;
|
|
|
|
case SDL_GL_GREEN_SIZE:
|
|
|
|
_this->gl_config.green_size = value;
|
|
|
|
break;
|
|
|
|
case SDL_GL_BLUE_SIZE:
|
|
|
|
_this->gl_config.blue_size = value;
|
|
|
|
break;
|
|
|
|
case SDL_GL_ALPHA_SIZE:
|
|
|
|
_this->gl_config.alpha_size = value;
|
|
|
|
break;
|
|
|
|
case SDL_GL_DOUBLEBUFFER:
|
|
|
|
_this->gl_config.double_buffer = value;
|
|
|
|
break;
|
|
|
|
case SDL_GL_BUFFER_SIZE:
|
|
|
|
_this->gl_config.buffer_size = value;
|
|
|
|
break;
|
|
|
|
case SDL_GL_DEPTH_SIZE:
|
|
|
|
_this->gl_config.depth_size = value;
|
|
|
|
break;
|
|
|
|
case SDL_GL_STENCIL_SIZE:
|
|
|
|
_this->gl_config.stencil_size = value;
|
|
|
|
break;
|
|
|
|
case SDL_GL_ACCUM_RED_SIZE:
|
|
|
|
_this->gl_config.accum_red_size = value;
|
|
|
|
break;
|
|
|
|
case SDL_GL_ACCUM_GREEN_SIZE:
|
|
|
|
_this->gl_config.accum_green_size = value;
|
|
|
|
break;
|
|
|
|
case SDL_GL_ACCUM_BLUE_SIZE:
|
|
|
|
_this->gl_config.accum_blue_size = value;
|
|
|
|
break;
|
|
|
|
case SDL_GL_ACCUM_ALPHA_SIZE:
|
|
|
|
_this->gl_config.accum_alpha_size = value;
|
|
|
|
break;
|
|
|
|
case SDL_GL_STEREO:
|
|
|
|
_this->gl_config.stereo = value;
|
|
|
|
break;
|
|
|
|
case SDL_GL_MULTISAMPLEBUFFERS:
|
|
|
|
_this->gl_config.multisamplebuffers = value;
|
|
|
|
break;
|
|
|
|
case SDL_GL_MULTISAMPLESAMPLES:
|
|
|
|
_this->gl_config.multisamplesamples = value;
|
|
|
|
break;
|
|
|
|
case SDL_GL_ACCELERATED_VISUAL:
|
|
|
|
_this->gl_config.accelerated = value;
|
|
|
|
break;
|
|
|
|
case SDL_GL_RETAINED_BACKING:
|
|
|
|
_this->gl_config.retained_backing = value;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
SDL_SetError("Unknown OpenGL attribute");
|
|
|
|
retval = -1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return retval;
|
2006-07-25 06:22:42 +00:00
|
|
|
#else
|
2008-09-15 04:32:36 +00:00
|
|
|
SDL_Unsupported();
|
|
|
|
return -1;
|
|
|
|
#endif /* SDL_VIDEO_OPENGL */
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2006-07-25 06:22:42 +00:00
|
|
|
SDL_GL_GetAttribute(SDL_GLattr attr, int *value)
|
2006-07-10 21:04:37 +00:00
|
|
|
{
|
2008-09-02 20:19:45 +00:00
|
|
|
#if SDL_VIDEO_OPENGL || SDL_VIDEO_OPENGL_ES
|
2008-09-15 04:32:36 +00:00
|
|
|
void (APIENTRY * glGetIntegervFunc) (GLenum pname, GLint * params);
|
|
|
|
GLenum attrib = 0;
|
|
|
|
|
|
|
|
glGetIntegervFunc = SDL_GL_GetProcAddress("glGetIntegerv");
|
|
|
|
if (!glGetIntegervFunc) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
switch (attr) {
|
|
|
|
case SDL_GL_RETAINED_BACKING:
|
|
|
|
*value = _this->gl_config.retained_backing;
|
|
|
|
return 0;
|
|
|
|
case SDL_GL_RED_SIZE:
|
|
|
|
attrib = GL_RED_BITS;
|
|
|
|
break;
|
|
|
|
case SDL_GL_BLUE_SIZE:
|
|
|
|
attrib = GL_BLUE_BITS;
|
|
|
|
break;
|
|
|
|
case SDL_GL_GREEN_SIZE:
|
|
|
|
attrib = GL_GREEN_BITS;
|
|
|
|
break;
|
|
|
|
case SDL_GL_ALPHA_SIZE:
|
|
|
|
attrib = GL_ALPHA_BITS;
|
|
|
|
break;
|
|
|
|
case SDL_GL_DOUBLEBUFFER:
|
2008-09-02 20:19:45 +00:00
|
|
|
#ifndef SDL_VIDEO_OPENGL_ES
|
2008-09-15 04:32:36 +00:00
|
|
|
attrib = GL_DOUBLEBUFFER;
|
|
|
|
break;
|
2008-09-02 20:19:45 +00:00
|
|
|
#else
|
2008-09-15 04:32:36 +00:00
|
|
|
/*
|
|
|
|
* I believe double buffering is the only option in OpenGL ES
|
|
|
|
* -- in any case, GL_DOUBLEBUFFER doesn't exist
|
|
|
|
*/
|
|
|
|
*value = 1;
|
|
|
|
return 0;
|
2008-09-02 20:19:45 +00:00
|
|
|
#endif
|
2008-09-15 04:32:36 +00:00
|
|
|
case SDL_GL_DEPTH_SIZE:
|
|
|
|
attrib = GL_DEPTH_BITS;
|
|
|
|
break;
|
|
|
|
case SDL_GL_STENCIL_SIZE:
|
|
|
|
attrib = GL_STENCIL_BITS;
|
|
|
|
break;
|
2008-09-02 20:19:45 +00:00
|
|
|
#ifndef SDL_VIDEO_OPENGL_ES
|
2008-09-15 04:32:36 +00:00
|
|
|
case SDL_GL_ACCUM_RED_SIZE:
|
|
|
|
attrib = GL_ACCUM_RED_BITS;
|
|
|
|
break;
|
|
|
|
case SDL_GL_ACCUM_GREEN_SIZE:
|
|
|
|
attrib = GL_ACCUM_GREEN_BITS;
|
|
|
|
break;
|
|
|
|
case SDL_GL_ACCUM_BLUE_SIZE:
|
|
|
|
attrib = GL_ACCUM_BLUE_BITS;
|
|
|
|
break;
|
|
|
|
case SDL_GL_ACCUM_ALPHA_SIZE:
|
|
|
|
attrib = GL_ACCUM_ALPHA_BITS;
|
|
|
|
break;
|
|
|
|
case SDL_GL_STEREO:
|
|
|
|
attrib = GL_STEREO;
|
|
|
|
break;
|
2008-09-02 20:19:45 +00:00
|
|
|
#else
|
2008-09-15 04:32:36 +00:00
|
|
|
case SDL_GL_ACCUM_RED_SIZE:
|
|
|
|
case SDL_GL_ACCUM_GREEN_SIZE:
|
|
|
|
case SDL_GL_ACCUM_BLUE_SIZE:
|
|
|
|
case SDL_GL_ACCUM_ALPHA_SIZE:
|
|
|
|
case SDL_GL_STEREO:
|
|
|
|
/* none of these are supported in OpenGL ES */
|
|
|
|
*value = 0;
|
|
|
|
return 0;
|
2008-09-02 20:19:45 +00:00
|
|
|
#endif
|
2008-09-15 04:32:36 +00:00
|
|
|
case SDL_GL_MULTISAMPLEBUFFERS:
|
2008-09-02 20:19:45 +00:00
|
|
|
#ifndef SDL_VIDEO_OPENGL_ES
|
2008-09-15 04:32:36 +00:00
|
|
|
attrib = GL_SAMPLE_BUFFERS_ARB;
|
2008-09-02 20:19:45 +00:00
|
|
|
#else
|
2008-09-15 04:32:36 +00:00
|
|
|
attrib = GL_SAMPLE_BUFFERS;
|
2008-09-02 20:19:45 +00:00
|
|
|
#endif
|
2008-09-15 04:32:36 +00:00
|
|
|
break;
|
|
|
|
case SDL_GL_MULTISAMPLESAMPLES:
|
2008-09-02 20:19:45 +00:00
|
|
|
#ifndef SDL_VIDEO_OPENGL_ES
|
2008-09-15 04:32:36 +00:00
|
|
|
attrib = GL_SAMPLES_ARB;
|
2008-09-02 20:19:45 +00:00
|
|
|
#else
|
2008-09-15 04:32:36 +00:00
|
|
|
attrib = GL_SAMPLES;
|
2008-09-02 20:19:45 +00:00
|
|
|
#endif
|
2008-09-15 04:32:36 +00:00
|
|
|
break;
|
|
|
|
case SDL_GL_BUFFER_SIZE:
|
|
|
|
{
|
|
|
|
GLint bits = 0;
|
|
|
|
GLint component;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* there doesn't seem to be a single flag in OpenGL
|
|
|
|
* for this!
|
|
|
|
*/
|
|
|
|
glGetIntegervFunc(GL_RED_BITS, &component);
|
|
|
|
bits += component;
|
|
|
|
glGetIntegervFunc(GL_GREEN_BITS, &component);
|
|
|
|
bits += component;
|
|
|
|
glGetIntegervFunc(GL_BLUE_BITS, &component);
|
|
|
|
bits += component;
|
|
|
|
glGetIntegervFunc(GL_ALPHA_BITS, &component);
|
|
|
|
bits += component;
|
|
|
|
|
|
|
|
*value = bits;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
case SDL_GL_ACCELERATED_VISUAL:
|
|
|
|
{
|
|
|
|
/* FIXME: How do we get this information? */
|
|
|
|
*value = (_this->gl_config.accelerated != 0);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
SDL_SetError("Unknown OpenGL attribute");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
glGetIntegervFunc(attrib, (GLint *) value);
|
|
|
|
return 0;
|
2006-07-25 06:22:42 +00:00
|
|
|
#else
|
2008-09-15 04:32:36 +00:00
|
|
|
SDL_Unsupported();
|
|
|
|
return -1;
|
|
|
|
#endif /* SDL_VIDEO_OPENGL */
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
|
|
|
|
2006-07-16 09:34:01 +00:00
|
|
|
SDL_GLContext
|
|
|
|
SDL_GL_CreateContext(SDL_WindowID windowID)
|
|
|
|
{
|
2008-09-15 04:32:36 +00:00
|
|
|
SDL_Window *window = SDL_GetWindowFromID(windowID);
|
2006-07-16 09:34:01 +00:00
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
if (!window) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if (!(window->flags & SDL_WINDOW_OPENGL)) {
|
|
|
|
SDL_SetError("The specified window isn't an OpenGL window");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return _this->GL_CreateContext(_this, window);
|
2006-07-16 09:34:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
SDL_GL_MakeCurrent(SDL_WindowID windowID, SDL_GLContext context)
|
|
|
|
{
|
2008-09-15 04:32:36 +00:00
|
|
|
SDL_Window *window = SDL_GetWindowFromID(windowID);
|
2006-07-16 09:34:01 +00:00
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
if (window && !(window->flags & SDL_WINDOW_OPENGL)) {
|
|
|
|
SDL_SetError("The specified window isn't an OpenGL window");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (!context) {
|
|
|
|
window = NULL;
|
|
|
|
}
|
|
|
|
return _this->GL_MakeCurrent(_this, window, context);
|
2006-07-16 09:34:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
SDL_GL_SetSwapInterval(int interval)
|
|
|
|
{
|
2008-09-15 04:32:36 +00:00
|
|
|
if (!_this) {
|
|
|
|
SDL_UninitializedVideo();
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (_this->GL_SetSwapInterval) {
|
|
|
|
return _this->GL_SetSwapInterval(_this, interval);
|
|
|
|
} else {
|
|
|
|
SDL_SetError("Setting the swap interval is not supported");
|
|
|
|
return -1;
|
|
|
|
}
|
2006-07-16 09:34:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
SDL_GL_GetSwapInterval(void)
|
|
|
|
{
|
2008-09-15 04:32:36 +00:00
|
|
|
if (!_this) {
|
|
|
|
SDL_UninitializedVideo();
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (_this->GL_GetSwapInterval) {
|
|
|
|
return _this->GL_GetSwapInterval(_this);
|
|
|
|
} else {
|
|
|
|
SDL_SetError("Getting the swap interval is not supported");
|
|
|
|
return -1;
|
|
|
|
}
|
2006-07-16 09:34:01 +00:00
|
|
|
}
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
void
|
2006-07-16 09:34:01 +00:00
|
|
|
SDL_GL_SwapWindow(SDL_WindowID windowID)
|
2006-07-10 21:04:37 +00:00
|
|
|
{
|
2008-09-15 04:32:36 +00:00
|
|
|
SDL_Window *window = SDL_GetWindowFromID(windowID);
|
2006-07-16 09:34:01 +00:00
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
if (!window) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!(window->flags & SDL_WINDOW_OPENGL)) {
|
|
|
|
SDL_SetError("The specified window isn't an OpenGL window");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_this->GL_SwapWindow(_this, window);
|
2006-07-16 09:34:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SDL_GL_DeleteContext(SDL_GLContext context)
|
|
|
|
{
|
2008-09-15 04:32:36 +00:00
|
|
|
if (!_this || !context) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_this->GL_MakeCurrent(_this, NULL, NULL);
|
|
|
|
_this->GL_DeleteContext(_this, context);
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#if 0 // FIXME
|
2008-09-02 20:11:06 +00:00
|
|
|
/*
|
|
|
|
* Utility function used by SDL_WM_SetIcon(); flags & 1 for color key, flags
|
|
|
|
* & 2 for alpha channel.
|
|
|
|
*/
|
2006-07-10 21:04:37 +00:00
|
|
|
static void
|
|
|
|
CreateMaskFromColorKeyOrAlpha(SDL_Surface * icon, Uint8 * mask, int flags)
|
|
|
|
{
|
2008-09-15 04:32:36 +00:00
|
|
|
int x, y;
|
|
|
|
Uint32 colorkey;
|
2006-07-10 21:04:37 +00:00
|
|
|
#define SET_MASKBIT(icon, x, y, mask) \
|
|
|
|
mask[(y*((icon->w+7)/8))+(x/8)] &= ~(0x01<<(7-(x%8)))
|
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
colorkey = icon->format->colorkey;
|
|
|
|
switch (icon->format->BytesPerPixel) {
|
|
|
|
case 1:
|
|
|
|
{
|
|
|
|
Uint8 *pixels;
|
|
|
|
for (y = 0; y < icon->h; ++y) {
|
|
|
|
pixels = (Uint8 *) icon->pixels + y * icon->pitch;
|
|
|
|
for (x = 0; x < icon->w; ++x) {
|
|
|
|
if (*pixels++ == colorkey) {
|
|
|
|
SET_MASKBIT(icon, x, y, mask);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
{
|
|
|
|
Uint16 *pixels;
|
|
|
|
for (y = 0; y < icon->h; ++y) {
|
|
|
|
pixels = (Uint16 *) icon->pixels + y * icon->pitch / 2;
|
|
|
|
for (x = 0; x < icon->w; ++x) {
|
|
|
|
if ((flags & 1) && *pixels == colorkey) {
|
|
|
|
SET_MASKBIT(icon, x, y, mask);
|
|
|
|
} else if ((flags & 2)
|
|
|
|
&& (*pixels & icon->format->Amask) == 0) {
|
|
|
|
SET_MASKBIT(icon, x, y, mask);
|
|
|
|
}
|
|
|
|
pixels++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 4:
|
|
|
|
{
|
|
|
|
Uint32 *pixels;
|
|
|
|
for (y = 0; y < icon->h; ++y) {
|
|
|
|
pixels = (Uint32 *) icon->pixels + y * icon->pitch / 4;
|
|
|
|
for (x = 0; x < icon->w; ++x) {
|
|
|
|
if ((flags & 1) && *pixels == colorkey) {
|
|
|
|
SET_MASKBIT(icon, x, y, mask);
|
|
|
|
} else if ((flags & 2)
|
|
|
|
&& (*pixels & icon->format->Amask) == 0) {
|
|
|
|
SET_MASKBIT(icon, x, y, mask);
|
|
|
|
}
|
|
|
|
pixels++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2001-04-26 16:45:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2006-07-10 21:04:37 +00:00
|
|
|
* Sets the window manager icon for the display window.
|
2001-04-26 16:45:43 +00:00
|
|
|
*/
|
2006-07-10 21:04:37 +00:00
|
|
|
void
|
|
|
|
SDL_WM_SetIcon(SDL_Surface * icon, Uint8 * mask)
|
|
|
|
{
|
2008-09-15 04:32:36 +00:00
|
|
|
if (icon && _this->SetIcon) {
|
|
|
|
/* Generate a mask if necessary, and create the icon! */
|
|
|
|
if (mask == NULL) {
|
|
|
|
int mask_len = icon->h * (icon->w + 7) / 8;
|
|
|
|
int flags = 0;
|
|
|
|
mask = (Uint8 *) SDL_malloc(mask_len);
|
|
|
|
if (mask == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
SDL_memset(mask, ~0, mask_len);
|
|
|
|
if (icon->flags & SDL_SRCCOLORKEY)
|
|
|
|
flags |= 1;
|
|
|
|
if (icon->flags & SDL_SRCALPHA)
|
|
|
|
flags |= 2;
|
|
|
|
if (flags) {
|
|
|
|
CreateMaskFromColorKeyOrAlpha(icon, mask, flags);
|
|
|
|
}
|
|
|
|
_this->SetIcon(_this, icon, mask);
|
|
|
|
SDL_free(mask);
|
|
|
|
} else {
|
|
|
|
_this->SetIcon(_this, icon, mask);
|
|
|
|
}
|
|
|
|
}
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
SDL_bool
|
2008-09-15 04:32:36 +00:00
|
|
|
SDL_GetWindowWMInfo(SDL_WindowID windowID, struct SDL_SysWMinfo *info)
|
2001-04-26 16:45:43 +00:00
|
|
|
{
|
2008-09-15 04:32:36 +00:00
|
|
|
SDL_Window *window = SDL_GetWindowFromID(windowID);
|
2001-04-26 16:45:43 +00:00
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
if (!window || !_this->GetWindowWMInfo) {
|
|
|
|
return SDL_FALSE;
|
|
|
|
}
|
|
|
|
return (_this->GetWindowWMInfo(_this, window, info));
|
2001-04-26 16:45:43 +00:00
|
|
|
}
|
2006-07-10 21:04:37 +00:00
|
|
|
|
|
|
|
/* vi: set ts=4 sw=4 expandtab: */
|