src/SDL_compat.c
author Sam Lantinga <slouken@libsdl.org>
Wed, 07 Jun 2006 16:10:28 +0000
branchSDL-1.3
changeset 1670 eef792d31de8
parent 1669 9857d21967bb
child 1675 d33dcfc3fde7
permissions -rw-r--r--
Work in progress. :)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1667
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     1
/*
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     2
    SDL - Simple DirectMedia Layer
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     3
    Copyright (C) 1997-2006 Sam Lantinga
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     4
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     5
    This library is free software; you can redistribute it and/or
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     6
    modify it under the terms of the GNU Lesser General Public
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     7
    License as published by the Free Software Foundation; either
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     8
    version 2.1 of the License, or (at your option) any later version.
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     9
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    10
    This library is distributed in the hope that it will be useful,
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    13
    Lesser General Public License for more details.
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    14
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    15
    You should have received a copy of the GNU Lesser General Public
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    16
    License along with this library; if not, write to the Free Software
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    17
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    18
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    19
    Sam Lantinga
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    20
    slouken@libsdl.org
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    21
*/
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    22
#include "SDL_config.h"
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    23
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    24
/* This file contains functions for backwards compatibility with SDL 1.2 */
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    25
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    26
#include "SDL.h"
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    27
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    28
#include "video/SDL_sysvideo.h"
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    29
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    30
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    31
static SDL_WindowID window;
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    32
static char *wm_title;
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    33
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    34
char *
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1667
diff changeset
    35
SDL_AudioDriverName(char *namebuf, int maxlen)
1667
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    36
{
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1667
diff changeset
    37
    const char *name = SDL_GetCurrentAudioDriver();
1667
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    38
    if (name) {
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1667
diff changeset
    39
        SDL_strlcpy(namebuf, name, maxlen);
1667
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    40
        return namebuf;
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    41
    }
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    42
    return NULL;
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    43
}
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    44
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    45
char *
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1667
diff changeset
    46
SDL_VideoDriverName(char *namebuf, int maxlen)
1667
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    47
{
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1667
diff changeset
    48
    const char *name = SDL_GetCurrentVideoDriver();
1667
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    49
    if (name) {
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1667
diff changeset
    50
        SDL_strlcpy(namebuf, name, maxlen);
1667
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    51
        return namebuf;
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    52
    }
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    53
    return NULL;
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    54
}
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    55
1670
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
    56
const SDL_VideoInfo *
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
    57
SDL_GetVideoInfo(void)
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
    58
{
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
    59
    static SDL_VideoInfo info;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
    60
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
    61
    /* Memory leak, compatibility code, who cares? */
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
    62
    if (!info.vfmt && SDL_GetDesktopDisplayMode()) {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
    63
        int bpp;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
    64
        Uint32 Rmask, Gmask, Bmask, Amask;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
    65
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
    66
        SDL_PixelFormatEnumToMasks(SDL_GetDesktopDisplayMode()->format, &bpp,
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
    67
                                   &Rmask, &Gmask, &Bmask, &Amask);
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
    68
        info.vfmt = SDL_AllocFormat(bpp, Rmask, Gmask, Bmask, Amask);
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
    69
    }
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
    70
    return &info;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
    71
}
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
    72
1667
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    73
int
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1667
diff changeset
    74
SDL_VideoModeOK(int width, int height, int bpp, Uint32 flags)
1667
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    75
{
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    76
    int i, actual_bpp = 0;
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    77
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1667
diff changeset
    78
    if (!SDL_GetVideoDevice()) {
1667
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    79
        return 0;
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    80
    }
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    81
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    82
    if (!(flags & SDL_FULLSCREEN)) {
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1667
diff changeset
    83
        return SDL_BITSPERPIXEL(SDL_GetDesktopDisplayMode()->format);
1667
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    84
    }
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    85
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1667
diff changeset
    86
    for (i = 0; i < SDL_GetNumDisplayModes(); ++i) {
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1667
diff changeset
    87
        const SDL_DisplayMode *mode = SDL_GetDisplayMode(i);
1667
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    88
        if (!mode->w || !mode->h || (width == mode->w && height == mode->h)) {
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    89
            if (!mode->format) {
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    90
                return bpp;
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    91
            }
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1667
diff changeset
    92
            if (SDL_BITSPERPIXEL(mode->format) >= bpp) {
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1667
diff changeset
    93
                actual_bpp = SDL_BITSPERPIXEL(mode->format);
1667
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    94
            }
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    95
        }
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    96
    }
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    97
    return actual_bpp;
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    98
}
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    99
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   100
SDL_Rect **
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1667
diff changeset
   101
SDL_ListModes(SDL_PixelFormat * format, Uint32 flags)
1667
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   102
{
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   103
    int i, nmodes;
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   104
    SDL_Rect **modes;
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   105
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1667
diff changeset
   106
    if (!SDL_GetVideoDevice()) {
1667
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   107
        return NULL;
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   108
    }
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   109
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   110
    if (!(flags & SDL_FULLSCREEN)) {
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   111
        return (SDL_Rect **) (-1);
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   112
    }
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   113
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   114
    /* Memory leak, but this is a compatibility function, who cares? */
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   115
    nmodes = 0;
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1667
diff changeset
   116
    for (i = 0; i < SDL_GetNumDisplayModes(); ++i) {
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1667
diff changeset
   117
        const SDL_DisplayMode *mode = SDL_GetDisplayMode(i);
1667
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   118
        if (!mode->w || !mode->h) {
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   119
            return (SDL_Rect **) (-1);
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   120
        }
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1667
diff changeset
   121
        if (SDL_BITSPERPIXEL(mode->format) != format->BitsPerPixel) {
1667
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   122
            continue;
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   123
        }
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   124
        if (nmodes > 0 && modes[nmodes - 1]->w == mode->w
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   125
            && modes[nmodes - 1]->h == mode->h) {
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   126
            continue;
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   127
        }
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   128
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1667
diff changeset
   129
        modes = SDL_realloc(modes, (nmodes + 2) * sizeof(*modes));
1667
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   130
        if (!modes) {
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   131
            return NULL;
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   132
        }
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1667
diff changeset
   133
        modes[nmodes] = (SDL_Rect *) SDL_malloc(sizeof(SDL_Rect));
1667
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   134
        if (!modes[nmodes]) {
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   135
            return NULL;
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   136
        }
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   137
        modes[nmodes]->x = 0;
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   138
        modes[nmodes]->y = 0;
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   139
        modes[nmodes]->w = mode->w;
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   140
        modes[nmodes]->h = mode->h;
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   141
        ++nmodes;
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   142
    }
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   143
    if (modes) {
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   144
        modes[nmodes] = NULL;
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   145
    }
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   146
    return modes;
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   147
}
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   148
1669
9857d21967bb The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
   149
static int (*orig_eventfilter) (const SDL_Event * event);
9857d21967bb The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
   150
9857d21967bb The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
   151
static int
9857d21967bb The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
   152
SDL_CompatEventFilter(const SDL_Event * event)
9857d21967bb The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
   153
{
9857d21967bb The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
   154
    SDL_Event fake;
9857d21967bb The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
   155
9857d21967bb The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
   156
    switch (event->type) {
9857d21967bb The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
   157
    case SDL_WINDOWEVENT:
9857d21967bb The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
   158
        switch (event->window.event) {
9857d21967bb The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
   159
        case SDL_WINDOWEVENT_RESIZED:
9857d21967bb The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
   160
            fake.type = SDL_VIDEORESIZE;
9857d21967bb The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
   161
            fake.resize.w = event->window.data1;
9857d21967bb The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
   162
            fake.resize.h = event->window.data2;
9857d21967bb The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
   163
            SDL_PushEvent(&fake);
9857d21967bb The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
   164
            break;
9857d21967bb The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
   165
        case SDL_WINDOWEVENT_MINIMIZED:
9857d21967bb The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
   166
            fake.type = SDL_ACTIVEEVENT;
9857d21967bb The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
   167
            fake.active.gain = 0;
9857d21967bb The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
   168
            fake.active.state = SDL_APPACTIVE;
9857d21967bb The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
   169
            SDL_PushEvent(&fake);
9857d21967bb The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
   170
            break;
9857d21967bb The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
   171
        case SDL_WINDOWEVENT_RESTORED:
9857d21967bb The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
   172
            fake.type = SDL_ACTIVEEVENT;
9857d21967bb The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
   173
            fake.active.gain = 1;
9857d21967bb The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
   174
            fake.active.state = SDL_APPACTIVE;
9857d21967bb The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
   175
            SDL_PushEvent(&fake);
9857d21967bb The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
   176
            break;
9857d21967bb The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
   177
        case SDL_WINDOWEVENT_ENTER:
9857d21967bb The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
   178
            fake.type = SDL_ACTIVEEVENT;
9857d21967bb The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
   179
            fake.active.gain = 1;
9857d21967bb The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
   180
            fake.active.state = SDL_APPMOUSEFOCUS;
9857d21967bb The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
   181
            SDL_PushEvent(&fake);
9857d21967bb The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
   182
            break;
9857d21967bb The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
   183
        case SDL_WINDOWEVENT_LEAVE:
9857d21967bb The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
   184
            fake.type = SDL_ACTIVEEVENT;
9857d21967bb The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
   185
            fake.active.gain = 0;
9857d21967bb The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
   186
            fake.active.state = SDL_APPMOUSEFOCUS;
9857d21967bb The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
   187
            SDL_PushEvent(&fake);
9857d21967bb The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
   188
            break;
9857d21967bb The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
   189
        case SDL_WINDOWEVENT_FOCUS_GAINED:
9857d21967bb The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
   190
            fake.type = SDL_ACTIVEEVENT;
9857d21967bb The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
   191
            fake.active.gain = 1;
9857d21967bb The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
   192
            fake.active.state = SDL_APPINPUTFOCUS;
9857d21967bb The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
   193
            SDL_PushEvent(&fake);
9857d21967bb The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
   194
            break;
9857d21967bb The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
   195
        case SDL_WINDOWEVENT_FOCUS_LOST:
9857d21967bb The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
   196
            fake.type = SDL_ACTIVEEVENT;
9857d21967bb The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
   197
            fake.active.gain = 1;
9857d21967bb The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
   198
            fake.active.state = SDL_APPINPUTFOCUS;
9857d21967bb The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
   199
            SDL_PushEvent(&fake);
9857d21967bb The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
   200
            break;
9857d21967bb The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
   201
        }
9857d21967bb The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
   202
    }
9857d21967bb The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
   203
    return orig_eventfilter(event);
9857d21967bb The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
   204
}
9857d21967bb The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
   205
1667
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   206
SDL_Surface *
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1667
diff changeset
   207
SDL_SetVideoMode(int width, int height, int bpp, Uint32 flags)
1667
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   208
{
1669
9857d21967bb The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
   209
    int (*filter) (const SDL_Event * event);
9857d21967bb The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
   210
    const SDL_DisplayMode *desktop_mode;
1667
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   211
    SDL_DisplayMode mode;
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   212
    int i;
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   213
    Uint32 window_flags;
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   214
    Uint32 desktop_format;
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   215
    Uint32 desired_format;
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   216
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1667
diff changeset
   217
    if (!SDL_GetVideoDevice()) {
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1667
diff changeset
   218
        if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE) < 0) {
1667
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   219
            return NULL;
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   220
        }
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   221
    }
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   222
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   223
    /* Destroy existing window */
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1667
diff changeset
   224
    SDL_DestroyWindow(window);
1667
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   225
1669
9857d21967bb The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
   226
    /* Set up the event filter */
9857d21967bb The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
   227
    filter = SDL_GetEventFilter();
9857d21967bb The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
   228
    if (filter != SDL_CompatEventFilter) {
9857d21967bb The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
   229
        orig_eventfilter = filter;
9857d21967bb The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
   230
    }
9857d21967bb The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
   231
    SDL_SetEventFilter(SDL_CompatEventFilter);
9857d21967bb The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
   232
1667
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   233
    /* Create a new window */
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   234
    window_flags = SDL_WINDOW_SHOWN;
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   235
    if (flags & SDL_FULLSCREEN) {
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   236
        window_flags |= SDL_WINDOW_FULLSCREEN;
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   237
    }
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   238
    if (flags & SDL_OPENGL) {
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   239
        window_flags |= SDL_WINDOW_OPENGL;
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   240
    }
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   241
    if (flags & SDL_RESIZABLE) {
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   242
        window_flags |= SDL_WINDOW_RESIZABLE;
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   243
    }
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   244
    if (flags & SDL_NOFRAME) {
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   245
        window_flags |= SDL_WINDOW_BORDERLESS;
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   246
    }
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1667
diff changeset
   247
    window = SDL_CreateWindow(wm_title, 0, 0, width, height, window_flags);
1667
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   248
    if (!window) {
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   249
        return NULL;
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   250
    }
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   251
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   252
    /* Set up the desired display mode */
1669
9857d21967bb The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
   253
    desktop_mode = SDL_GetDesktopDisplayMode();
9857d21967bb The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
   254
    desktop_format = desktop_mode->format;
9857d21967bb The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
   255
    if (desktop_format && ((flags & SDL_ANYFORMAT)
9857d21967bb The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
   256
                           || (bpp == SDL_BITSPERPIXEL(desktop_format)))) {
1667
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   257
        desired_format = desktop_format;
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   258
    } else {
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   259
        switch (bpp) {
1669
9857d21967bb The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
   260
        case 0:
9857d21967bb The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
   261
            if (desktop_format) {
9857d21967bb The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
   262
                desired_format = desktop_format;
9857d21967bb The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
   263
            } else {
9857d21967bb The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
   264
                desired_format = SDL_PixelFormat_RGB888;
9857d21967bb The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
   265
            }
9857d21967bb The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
   266
            break;
1667
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   267
        case 8:
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   268
            desired_format = SDL_PixelFormat_Index8;
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   269
            break;
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   270
        case 15:
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   271
            desired_format = SDL_PixelFormat_RGB555;
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   272
            break;
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   273
        case 16:
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   274
            desired_format = SDL_PixelFormat_RGB565;
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   275
            break;
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   276
        case 24:
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   277
            desired_format = SDL_PixelFormat_RGB24;
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   278
            break;
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   279
        case 32:
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   280
            desired_format = SDL_PixelFormat_RGB888;
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   281
            break;
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   282
        default:
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1667
diff changeset
   283
            SDL_SetError("Unsupported bpp in SDL_SetVideoMode()");
1667
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   284
            return NULL;
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   285
        }
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   286
    }
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   287
    mode.format = desired_format;
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   288
    mode.w = width;
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   289
    mode.h = height;
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   290
    mode.refresh_rate = 0;
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   291
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   292
    /* Set the desired display mode */
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   293
    if (flags & SDL_FULLSCREEN) {
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1667
diff changeset
   294
        if (!SDL_GetClosestDisplayMode(&mode, &mode)) {
1667
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   295
            return NULL;
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   296
        }
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   297
    } else {
1669
9857d21967bb The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
   298
        if (desktop_format) {
9857d21967bb The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
   299
            mode.format = desktop_format;
9857d21967bb The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
   300
        }
9857d21967bb The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
   301
        if (desktop_mode->w && desktop_mode->h) {
9857d21967bb The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
   302
            mode.w = desktop_mode->w;
9857d21967bb The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
   303
            mode.h = desktop_mode->h;
9857d21967bb The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
   304
        }
9857d21967bb The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
   305
        mode.refresh_rate = desktop_mode->refresh_rate;
1667
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   306
    }
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1667
diff changeset
   307
    if (SDL_SetDisplayMode(&mode) < 0) {
1667
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   308
        return NULL;
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   309
    }
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   310
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   311
    /* Create the display surface */
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1667
diff changeset
   312
    return SDL_CreateWindowSurface(window, desired_format, flags);
1667
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   313
}
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   314
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   315
SDL_Surface *
1670
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   316
SDL_CreateWindowSurface(SDL_WindowID windowID, Uint32 format, Uint32 flags)
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   317
{
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   318
    SDL_Window *window = SDL_GetWindowFromID(windowID);
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   319
    Uint32 black;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   320
    SDL_Surface *surface;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   321
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   322
    if (!window) {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   323
        return NULL;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   324
    }
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   325
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   326
    if (!_this->CreateWindowSurface) {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   327
        return NULL;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   328
    }
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   329
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   330
    if (!window->surface) {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   331
        _this->CreateWindowSurface(_this, window, flags);
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   332
        if (!window->surface) {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   333
            return NULL;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   334
        }
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   335
        window->surface->flags |= SDL_SCREEN_SURFACE;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   336
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   337
        /* If we have a palettized surface, create a default palette */
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   338
        if (window->surface->format->palette) {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   339
            SDL_Color colors[256];
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   340
            SDL_PixelFormat *vf = window->surface->format;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   341
            SDL_DitherColors(colors, vf->BitsPerPixel);
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   342
            SDL_SetColors(window->surface, colors, 0, vf->palette->ncolors);
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   343
        }
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   344
    }
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   345
    surface = window->surface;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   346
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   347
    if (window->shadow) {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   348
        SDL_FreeSurface(window->shadow);
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   349
        window->shadow = NULL;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   350
    }
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   351
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   352
    /* Create a shadow surface if necessary */
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   353
    if ((!(flags & SDL_ANYFORMAT)
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   354
         && (format != SDL_GetCurrentDisplayMode()->format))
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   355
        || ((flags & SDL_HWPALETTE)
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   356
            && !(window->surface->flags & SDL_HWPALETTE))) {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   357
        int bpp;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   358
        Uint32 Rmask, Gmask, Bmask, Amask;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   359
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   360
        SDL_PixelFormatEnumToMasks(format, &bpp, &Amask, &Gmask, &Bmask,
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   361
                                   &Amask);
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   362
        window->shadow =
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   363
            SDL_CreateRGBSurface(SDL_SWSURFACE, surface->w, surface->h, bpp,
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   364
                                 Rmask, Gmask, Bmask, Amask);
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   365
        if (window->shadow == NULL) {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   366
            return NULL;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   367
        }
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   368
        window->shadow->flags |= SDL_SHADOW_SURFACE;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   369
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   370
        surface = window->shadow;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   371
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   372
        /* 8-bit shadow surfaces report that they have exclusive palette */
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   373
        if (surface->format->palette) {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   374
            surface->flags |= SDL_HWPALETTE;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   375
            if (format == SDL_GetCurrentDisplayMode()->format) {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   376
                SDL_memcpy(surface->format->palette->colors,
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   377
                           window->surface->format->palette->colors,
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   378
                           window->surface->format->palette->ncolors *
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   379
                           sizeof(SDL_Color));
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   380
            } else {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   381
                SDL_DitherColors(surface->format->palette->colors, bpp);
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   382
            }
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   383
        }
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   384
    }
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   385
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   386
    /* Clear the surface for display */
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   387
    {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   388
        Uint32 black = SDL_MapRGB(surface->format, 0, 0, 0);
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   389
        SDL_FillRect(surface, NULL, black);
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   390
        if (surface->flags & SDL_DOUBLEBUF) {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   391
            SDL_Flip(surface);
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   392
            SDL_FillRect(surface, NULL, black);
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   393
        }
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   394
        SDL_Flip(surface);
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   395
    }
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   396
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   397
    return surface;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   398
}
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   399
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   400
SDL_Surface *
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1667
diff changeset
   401
SDL_GetVideoSurface(void)
1667
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   402
{
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1667
diff changeset
   403
    SDL_VideoDevice *_this = SDL_GetVideoDevice();
1667
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   404
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   405
    return SDL_VideoSurface;
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   406
}
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   407
1670
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   408
SDL_Surface *
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   409
SDL_DisplayFormat(SDL_Surface * surface)
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   410
{
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   411
    Uint32 flags;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   412
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   413
    if (!SDL_PublicSurface) {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   414
        SDL_SetError("No video mode has been set");
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   415
        return (NULL);
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   416
    }
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   417
    /* Set the flags appropriate for copying to display surface */
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   418
    if (((SDL_PublicSurface->flags & SDL_HWSURFACE) == SDL_HWSURFACE)
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   419
        && _this->info.blit_hw)
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   420
        flags = SDL_HWSURFACE;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   421
    else
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   422
        flags = SDL_SWSURFACE;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   423
#ifdef AUTORLE_DISPLAYFORMAT
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   424
    flags |= (surface->flags & (SDL_SRCCOLORKEY | SDL_SRCALPHA));
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   425
    flags |= SDL_RLEACCELOK;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   426
#else
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   427
    flags |=
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   428
        surface->flags & (SDL_SRCCOLORKEY | SDL_SRCALPHA | SDL_RLEACCELOK);
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   429
#endif
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   430
    return (SDL_ConvertSurface(surface, SDL_PublicSurface->format, flags));
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   431
}
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   432
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   433
SDL_Surface *
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   434
SDL_DisplayFormatAlpha(SDL_Surface * surface)
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   435
{
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   436
    SDL_PixelFormat *vf;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   437
    SDL_PixelFormat *format;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   438
    SDL_Surface *converted;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   439
    Uint32 flags;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   440
    /* default to ARGB8888 */
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   441
    Uint32 amask = 0xff000000;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   442
    Uint32 rmask = 0x00ff0000;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   443
    Uint32 gmask = 0x0000ff00;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   444
    Uint32 bmask = 0x000000ff;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   445
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   446
    if (!SDL_PublicSurface) {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   447
        SDL_SetError("No video mode has been set");
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   448
        return (NULL);
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   449
    }
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   450
    vf = SDL_PublicSurface->format;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   451
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   452
    switch (vf->BytesPerPixel) {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   453
    case 2:
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   454
        /* For XGY5[56]5, use, AXGY8888, where {X, Y} = {R, B}.
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   455
           For anything else (like ARGB4444) it doesn't matter
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   456
           since we have no special code for it anyway */
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   457
        if ((vf->Rmask == 0x1f) &&
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   458
            (vf->Bmask == 0xf800 || vf->Bmask == 0x7c00)) {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   459
            rmask = 0xff;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   460
            bmask = 0xff0000;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   461
        }
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   462
        break;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   463
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   464
    case 3:
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   465
    case 4:
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   466
        /* Keep the video format, as long as the high 8 bits are
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   467
           unused or alpha */
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   468
        if ((vf->Rmask == 0xff) && (vf->Bmask == 0xff0000)) {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   469
            rmask = 0xff;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   470
            bmask = 0xff0000;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   471
        }
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   472
        break;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   473
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   474
    default:
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   475
        /* We have no other optimised formats right now. When/if a new
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   476
           optimised alpha format is written, add the converter here */
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   477
        break;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   478
    }
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   479
    format = SDL_AllocFormat(32, rmask, gmask, bmask, amask);
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   480
    flags = SDL_PublicSurface->flags & SDL_HWSURFACE;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   481
    flags |= surface->flags & (SDL_SRCALPHA | SDL_RLEACCELOK);
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   482
    converted = SDL_ConvertSurface(surface, format, flags);
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   483
    SDL_FreeFormat(format);
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   484
    return (converted);
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   485
}
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   486
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   487
void
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   488
SDL_UpdateRect(SDL_Surface * screen, Sint32 x, Sint32 y, Uint32 w, Uint32 h)
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   489
{
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   490
    if (screen) {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   491
        SDL_Rect rect;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   492
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   493
        /* Perform some checking */
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   494
        if (w == 0)
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   495
            w = screen->w;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   496
        if (h == 0)
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   497
            h = screen->h;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   498
        if ((int) (x + w) > screen->w)
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   499
            return;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   500
        if ((int) (y + h) > screen->h)
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   501
            return;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   502
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   503
        /* Fill the rectangle */
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   504
        rect.x = (Sint16) x;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   505
        rect.y = (Sint16) y;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   506
        rect.w = (Uint16) w;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   507
        rect.h = (Uint16) h;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   508
        SDL_UpdateRects(screen, 1, &rect);
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   509
    }
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   510
}
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   511
void
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   512
SDL_UpdateRects(SDL_Surface * screen, int numrects, SDL_Rect * rects)
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   513
{
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   514
    int i;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   515
    SDL_Window *window;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   516
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   517
    /* Find the window corresponding to this surface */
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   518
    window = SDL_GetWindowFromSurface(screen);
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   519
    if (!window) {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   520
        SDL_SetError("Couldn't find window associated with surface");
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   521
        return;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   522
    }
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   523
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   524
    if (screen->flags & SDL_SHADOW_SURFACE) {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   525
        if (SHOULD_DRAWCURSOR(SDL_cursorstate)) {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   526
            SDL_LockCursor();
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   527
            SDL_DrawCursor(screen);
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   528
            for (i = 0; i < numrects; ++i) {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   529
                SDL_LowerBlit(screen, &rects[i], window->surface, &rects[i]);
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   530
            }
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   531
            SDL_EraseCursor(screen);
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   532
            SDL_UnlockCursor();
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   533
        } else {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   534
            for (i = 0; i < numrects; ++i) {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   535
                SDL_LowerBlit(screen, &rects[i], window->surface, &rects[i]);
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   536
            }
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   537
        }
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   538
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   539
        /* Fall through to video surface update */
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   540
        screen = window->surface;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   541
    }
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   542
    if ((screen->flags & SDL_SCREEN_SURFACE) && _this->UpdateWindowSurface) {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   543
        /* Update the video surface */
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   544
        if (screen->offset) {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   545
            int offset_y = screen->offset / screen->pitch;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   546
            int offset_x = screen->offset % screen->pitch;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   547
            for (i = 0; i < numrects; ++i) {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   548
                rects[i].x += offset_x;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   549
                rects[i].y += offset_y;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   550
            }
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   551
            _this->UpdateWindowSurface(_this, window, numrects, rects);
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   552
            for (i = 0; i < numrects; ++i) {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   553
                rects[i].x -= offset_x;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   554
                rects[i].y -= offset_y;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   555
            }
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   556
        } else {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   557
            _this->UpdateWindowSurface(_this, window, numrects, rects);
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   558
        }
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   559
    }
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   560
}
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   561
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   562
int
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   563
SDL_Flip(SDL_Surface * screen)
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   564
{
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   565
    SDL_Window *window;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   566
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   567
    /* Find the window corresponding to this surface */
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   568
    window = SDL_GetWindowFromSurface(screen);
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   569
    if (!window) {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   570
        SDL_SetError("Couldn't find window associated with surface");
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   571
        return;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   572
    }
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   573
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   574
    /* Copy the shadow surface to the video surface */
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   575
    if (screen->flags & SDL_SHADOW_SURFACE) {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   576
        SDL_Rect rect;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   577
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   578
        rect.x = 0;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   579
        rect.y = 0;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   580
        rect.w = screen->w;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   581
        rect.h = screen->h;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   582
        if (SHOULD_DRAWCURSOR(SDL_cursorstate)) {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   583
            SDL_LockCursor();
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   584
            SDL_DrawCursor(screen);
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   585
            SDL_LowerBlit(screen, &rect, window->surface, &rect);
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   586
            SDL_EraseCursor(screen);
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   587
            SDL_UnlockCursor();
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   588
        } else {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   589
            SDL_LowerBlit(screen, &rect, window->surface, &rect);
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   590
        }
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   591
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   592
        /* Fall through to video surface update */
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   593
        screen = window->surface;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   594
    }
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   595
    if (screen->flags & SDL_DOUBLEBUF) {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   596
        _this->FlipWindowSurface(_this, window);
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   597
    } else {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   598
        SDL_UpdateRect(screen, 0, 0, 0, 0);
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   599
    }
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   600
    return (0);
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   601
}
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   602
1667
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   603
void
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1667
diff changeset
   604
SDL_WM_SetCaption(const char *title, const char *icon)
1667
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   605
{
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   606
    if (wm_title) {
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1667
diff changeset
   607
        SDL_free(wm_title);
1667
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   608
    } else {
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1667
diff changeset
   609
        wm_title = SDL_strdup(title);
1667
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   610
    }
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1667
diff changeset
   611
    SDL_SetWindowTitle(window, wm_title);
1667
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   612
}
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   613
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   614
void
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1667
diff changeset
   615
SDL_WM_GetCaption(char **title, char **icon)
1667
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   616
{
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   617
    if (title) {
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   618
        *title = wm_title;
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   619
    }
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   620
    if (icon) {
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   621
        *icon = "";
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   622
    }
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   623
}
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   624
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   625
void
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1667
diff changeset
   626
SDL_WM_SetIcon(SDL_Surface * icon, Uint8 * mask)
1667
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   627
{
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   628
    /* FIXME */
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   629
}
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   630
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   631
int
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1667
diff changeset
   632
SDL_WM_IconifyWindow(void)
1667
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   633
{
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1667
diff changeset
   634
    SDL_MinimizeWindow(window);
1667
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   635
}
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   636
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   637
int
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1667
diff changeset
   638
SDL_WM_ToggleFullScreen(SDL_Surface * surface)
1667
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   639
{
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   640
    return 0;
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   641
}
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   642
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   643
SDL_GrabMode
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1667
diff changeset
   644
SDL_WM_GrabInput(SDL_GrabMode mode)
1667
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   645
{
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   646
    if (mode != SDL_GRAB_QUERY) {
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1667
diff changeset
   647
        SDL_SetWindowGrab(window, mode);
1667
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   648
    }
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1667
diff changeset
   649
    return (SDL_GrabMode) SDL_GetWindowGrab(window);
1667
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   650
}
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   651
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   652
Uint8
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1667
diff changeset
   653
SDL_GetAppState(void)
1667
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   654
{
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   655
    Uint8 state = 0;
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   656
    Uint32 flags = 0;
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   657
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1667
diff changeset
   658
    flags = SDL_GetWindowFlags(window);
1667
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   659
    if ((flags & SDL_WINDOW_SHOWN) && !(flags & SDL_WINDOW_MINIMIZED)) {
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   660
        state |= SDL_APPACTIVE;
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   661
    }
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   662
    if (flags & SDL_WINDOW_KEYBOARD_FOCUS) {
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   663
        state |= SDL_APPINPUTFOCUS;
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   664
    }
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   665
    if (flags & SDL_WINDOW_MOUSE_FOCUS) {
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   666
        state |= SDL_APPMOUSEFOCUS;
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   667
    }
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   668
    return state;
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   669
}
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   670
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   671
const SDL_version *
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1667
diff changeset
   672
SDL_Linked_Version(void)
1667
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   673
{
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   674
    static SDL_version version;
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1667
diff changeset
   675
    SDL_VERSION(&version);
1667
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   676
    return &version;
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   677
}
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   678
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   679
int
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1667
diff changeset
   680
SDL_SetPalette(SDL_Surface * surface, int flags, SDL_Color * colors,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1667
diff changeset
   681
               int firstcolor, int ncolors)
1667
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   682
{
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1667
diff changeset
   683
    SDL_SetColors(surface, colors, firstcolor, ncolors);
1667
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   684
}
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   685
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   686
int
1670
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   687
SDL_SetScreenColors(SDL_Surface * screen, SDL_Color * colors, int firstcolor,
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   688
                    int ncolors)
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   689
{
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   690
    SDL_Window *window = NULL;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   691
    SDL_Palette *pal;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   692
    int gotall;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   693
    int palsize;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   694
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   695
    /* Verify the parameters */
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   696
    pal = screen->format->palette;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   697
    if (!pal) {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   698
        return 0;               /* not a palettized surface */
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   699
    }
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   700
    gotall = 1;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   701
    palsize = 1 << screen->format->BitsPerPixel;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   702
    if (ncolors > (palsize - firstcolor)) {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   703
        ncolors = (palsize - firstcolor);
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   704
        gotall = 0;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   705
    }
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   706
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   707
    if (screen->flags & (SDL_SHADOW_SURFACE | SDL_SCREEN_SURFACE)) {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   708
        window = SDL_GetWindowFromSurface(screen);
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   709
        if (!window) {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   710
            return 0;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   711
        }
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   712
    }
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   713
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   714
    if (screen->flags & SDL_SHADOW_SURFACE) {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   715
        SDL_Palette *vidpal;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   716
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   717
        vidpal = window->surface->format->palette;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   718
        if (vidpal && vidpal->ncolors == pal->ncolors) {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   719
            /* This is a shadow surface, and the physical
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   720
             * framebuffer is also indexed. Propagate the
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   721
             * changes to its logical palette so that
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   722
             * updates are always identity blits
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   723
             */
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   724
            SDL_memcpy(vidpal->colors + firstcolor, colors,
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   725
                       ncolors * sizeof(*colors));
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   726
        }
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   727
        if (window->surface->flags & SDL_HWPALETTE) {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   728
            /* Set the physical palette */
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   729
            screen = window->surface;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   730
        } else {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   731
            SDL_UpdateRect(screen, 0, 0, 0, 0);
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   732
        }
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   733
    }
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   734
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   735
    if (screen->flags & SDL_SCREEN_SURFACE) {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   736
        if (_this->SetWindowColors) {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   737
            gotall =
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   738
                _this->SetWindowColors(_this, window, firstcolor, ncolors,
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   739
                                       colors);
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   740
            if (!gotall) {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   741
                /* The video flags shouldn't have SDL_HWPALETTE, and
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   742
                   the video driver is responsible for copying back the
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   743
                   correct colors into the video surface palette.
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   744
                 */
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   745
                ;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   746
            }
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   747
        }
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   748
        SDL_CursorPaletteChanged();
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   749
    }
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   750
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   751
    return gotall;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   752
}
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   753
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   754
int
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1667
diff changeset
   755
SDL_GetWMInfo(SDL_SysWMinfo * info)
1667
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   756
{
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1667
diff changeset
   757
    return SDL_GetWindowWMInfo(window, info);
1667
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   758
}
1fddae038bc8 Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   759
1670
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   760
void
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   761
SDL_MoveCursor(int x, int y)
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   762
{
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   763
    SDL_VideoDevice *_this = SDL_GetVideoDevice();
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   764
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   765
    /* Erase and update the current mouse position */
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   766
    if (SHOULD_DRAWCURSOR(SDL_cursorstate)) {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   767
        /* Erase and redraw mouse cursor in new position */
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   768
        SDL_LockCursor();
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   769
        SDL_EraseCursor(SDL_VideoSurface);
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   770
        SDL_cursor->area.x = (x - SDL_cursor->hot_x);
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   771
        SDL_cursor->area.y = (y - SDL_cursor->hot_y);
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   772
        SDL_DrawCursor(SDL_VideoSurface);
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   773
        SDL_UnlockCursor();
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   774
    } else if (_this->MoveWMCursor) {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   775
        _this->MoveWMCursor(_this, x, y);
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   776
    }
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   777
}
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   778
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   779
/* Keep track of the current cursor colors */
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   780
static int palette_changed = 1;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   781
static Uint8 pixels8[2];
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   782
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   783
void
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   784
SDL_CursorPaletteChanged(void)
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   785
{
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   786
    palette_changed = 1;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   787
}
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   788
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   789
void
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   790
SDL_MouseRect(SDL_Rect * area)
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   791
{
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   792
    SDL_VideoDevice *_this = SDL_GetVideoDevice();
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   793
    int clip_diff;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   794
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   795
    *area = SDL_cursor->area;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   796
    if (area->x < 0) {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   797
        area->w += area->x;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   798
        area->x = 0;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   799
    }
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   800
    if (area->y < 0) {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   801
        area->h += area->y;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   802
        area->y = 0;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   803
    }
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   804
    clip_diff = (area->x + area->w) - SDL_VideoSurface->w;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   805
    if (clip_diff > 0) {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   806
        area->w = area->w < clip_diff ? 0 : area->w - clip_diff;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   807
    }
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   808
    clip_diff = (area->y + area->h) - SDL_VideoSurface->h;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   809
    if (clip_diff > 0) {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   810
        area->h = area->h < clip_diff ? 0 : area->h - clip_diff;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   811
    }
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   812
}
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   813
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   814
static void
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   815
SDL_DrawCursorFast(SDL_Surface * screen, SDL_Rect * area)
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   816
{
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   817
    const Uint32 pixels[2] = { 0xFFFFFFFF, 0x00000000 };
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   818
    int i, w, h;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   819
    Uint8 *data, datab;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   820
    Uint8 *mask, maskb;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   821
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   822
    data = SDL_cursor->data + area->y * SDL_cursor->area.w / 8;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   823
    mask = SDL_cursor->mask + area->y * SDL_cursor->area.w / 8;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   824
    switch (screen->format->BytesPerPixel) {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   825
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   826
    case 1:
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   827
        {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   828
            Uint8 *dst;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   829
            int dstskip;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   830
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   831
            if (palette_changed) {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   832
                pixels8[0] =
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   833
                    (Uint8) SDL_MapRGB(screen->format, 255, 255, 255);
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   834
                pixels8[1] = (Uint8) SDL_MapRGB(screen->format, 0, 0, 0);
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   835
                palette_changed = 0;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   836
            }
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   837
            dst = (Uint8 *) screen->pixels +
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   838
                (SDL_cursor->area.y + area->y) * screen->pitch +
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   839
                SDL_cursor->area.x;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   840
            dstskip = screen->pitch - area->w;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   841
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   842
            for (h = area->h; h; h--) {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   843
                for (w = area->w / 8; w; w--) {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   844
                    maskb = *mask++;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   845
                    datab = *data++;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   846
                    for (i = 0; i < 8; ++i) {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   847
                        if (maskb & 0x80) {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   848
                            *dst = pixels8[datab >> 7];
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   849
                        }
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   850
                        maskb <<= 1;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   851
                        datab <<= 1;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   852
                        dst++;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   853
                    }
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   854
                }
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   855
                dst += dstskip;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   856
            }
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   857
        }
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   858
        break;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   859
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   860
    case 2:
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   861
        {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   862
            Uint16 *dst;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   863
            int dstskip;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   864
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   865
            dst = (Uint16 *) screen->pixels +
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   866
                (SDL_cursor->area.y + area->y) * screen->pitch / 2 +
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   867
                SDL_cursor->area.x;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   868
            dstskip = (screen->pitch / 2) - area->w;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   869
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   870
            for (h = area->h; h; h--) {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   871
                for (w = area->w / 8; w; w--) {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   872
                    maskb = *mask++;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   873
                    datab = *data++;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   874
                    for (i = 0; i < 8; ++i) {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   875
                        if (maskb & 0x80) {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   876
                            *dst = (Uint16) pixels[datab >> 7];
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   877
                        }
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   878
                        maskb <<= 1;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   879
                        datab <<= 1;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   880
                        dst++;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   881
                    }
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   882
                }
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   883
                dst += dstskip;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   884
            }
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   885
        }
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   886
        break;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   887
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   888
    case 3:
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   889
        {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   890
            Uint8 *dst;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   891
            int dstskip;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   892
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   893
            dst = (Uint8 *) screen->pixels +
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   894
                (SDL_cursor->area.y + area->y) * screen->pitch +
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   895
                SDL_cursor->area.x * 3;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   896
            dstskip = screen->pitch - area->w * 3;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   897
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   898
            for (h = area->h; h; h--) {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   899
                for (w = area->w / 8; w; w--) {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   900
                    maskb = *mask++;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   901
                    datab = *data++;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   902
                    for (i = 0; i < 8; ++i) {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   903
                        if (maskb & 0x80) {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   904
                            SDL_memset(dst, pixels[datab >> 7], 3);
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   905
                        }
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   906
                        maskb <<= 1;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   907
                        datab <<= 1;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   908
                        dst += 3;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   909
                    }
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   910
                }
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   911
                dst += dstskip;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   912
            }
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   913
        }
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   914
        break;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   915
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   916
    case 4:
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   917
        {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   918
            Uint32 *dst;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   919
            int dstskip;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   920
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   921
            dst = (Uint32 *) screen->pixels +
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   922
                (SDL_cursor->area.y + area->y) * screen->pitch / 4 +
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   923
                SDL_cursor->area.x;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   924
            dstskip = (screen->pitch / 4) - area->w;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   925
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   926
            for (h = area->h; h; h--) {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   927
                for (w = area->w / 8; w; w--) {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   928
                    maskb = *mask++;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   929
                    datab = *data++;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   930
                    for (i = 0; i < 8; ++i) {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   931
                        if (maskb & 0x80) {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   932
                            *dst = pixels[datab >> 7];
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   933
                        }
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   934
                        maskb <<= 1;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   935
                        datab <<= 1;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   936
                        dst++;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   937
                    }
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   938
                }
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   939
                dst += dstskip;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   940
            }
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   941
        }
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   942
        break;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   943
    }
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   944
}
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   945
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   946
static void
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   947
SDL_DrawCursorSlow(SDL_Surface * screen, SDL_Rect * area)
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   948
{
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   949
    const Uint32 pixels[2] = { 0xFFFFFF, 0x000000 };
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   950
    int h;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   951
    int x, minx, maxx;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   952
    Uint8 *data, datab = 0;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   953
    Uint8 *mask, maskb = 0;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   954
    Uint8 *dst;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   955
    int dstbpp, dstskip;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   956
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   957
    data = SDL_cursor->data + area->y * SDL_cursor->area.w / 8;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   958
    mask = SDL_cursor->mask + area->y * SDL_cursor->area.w / 8;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   959
    dstbpp = screen->format->BytesPerPixel;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   960
    dst = (Uint8 *) screen->pixels +
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   961
        (SDL_cursor->area.y + area->y) * screen->pitch +
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   962
        SDL_cursor->area.x * dstbpp;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   963
    dstskip = screen->pitch - SDL_cursor->area.w * dstbpp;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   964
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   965
    minx = area->x;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   966
    maxx = area->x + area->w;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   967
    if (screen->format->BytesPerPixel == 1) {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   968
        if (palette_changed) {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   969
            pixels8[0] = (Uint8) SDL_MapRGB(screen->format, 255, 255, 255);
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   970
            pixels8[1] = (Uint8) SDL_MapRGB(screen->format, 0, 0, 0);
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   971
            palette_changed = 0;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   972
        }
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   973
        for (h = area->h; h; h--) {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   974
            for (x = 0; x < SDL_cursor->area.w; ++x) {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   975
                if ((x % 8) == 0) {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   976
                    maskb = *mask++;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   977
                    datab = *data++;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   978
                }
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   979
                if ((x >= minx) && (x < maxx)) {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   980
                    if (maskb & 0x80) {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   981
                        SDL_memset(dst, pixels8[datab >> 7], dstbpp);
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   982
                    }
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   983
                }
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   984
                maskb <<= 1;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   985
                datab <<= 1;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   986
                dst += dstbpp;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   987
            }
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   988
            dst += dstskip;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   989
        }
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   990
    } else {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   991
        for (h = area->h; h; h--) {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   992
            for (x = 0; x < SDL_cursor->area.w; ++x) {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   993
                if ((x % 8) == 0) {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   994
                    maskb = *mask++;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   995
                    datab = *data++;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   996
                }
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   997
                if ((x >= minx) && (x < maxx)) {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   998
                    if (maskb & 0x80) {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
   999
                        SDL_memset(dst, pixels[datab >> 7], dstbpp);
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1000
                    }
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1001
                }
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1002
                maskb <<= 1;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1003
                datab <<= 1;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1004
                dst += dstbpp;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1005
            }
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1006
            dst += dstskip;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1007
        }
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1008
    }
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1009
}
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1010
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1011
/* This handles the ugly work of converting the saved cursor background from
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1012
   the pixel format of the shadow surface to that of the video surface.
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1013
   This is only necessary when blitting from a shadow surface of a different
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1014
   pixel format than the video surface, and using a software rendered cursor.
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1015
*/
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1016
static void
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1017
SDL_ConvertCursorSave(SDL_Surface * screen, int w, int h)
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1018
{
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1019
    SDL_VideoDevice *_this = SDL_GetVideoDevice();
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1020
    SDL_BlitInfo info;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1021
    SDL_loblit RunBlit;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1022
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1023
    /* Make sure we can steal the blit mapping */
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1024
    if (screen->map->dst != SDL_VideoSurface) {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1025
        return;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1026
    }
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1027
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1028
    /* Set up the blit information */
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1029
    info.s_pixels = SDL_cursor->save[1];
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1030
    info.s_width = w;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1031
    info.s_height = h;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1032
    info.s_skip = 0;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1033
    info.d_pixels = SDL_cursor->save[0];
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1034
    info.d_width = w;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1035
    info.d_height = h;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1036
    info.d_skip = 0;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1037
    info.aux_data = screen->map->sw_data->aux_data;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1038
    info.src = screen->format;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1039
    info.table = screen->map->table;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1040
    info.dst = SDL_VideoSurface->format;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1041
    RunBlit = screen->map->sw_data->blit;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1042
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1043
    /* Run the actual software blit */
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1044
    RunBlit(&info);
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1045
}
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1046
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1047
void
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1048
SDL_DrawCursorNoLock(SDL_Surface * screen)
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1049
{
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1050
    SDL_VideoDevice *_this = SDL_GetVideoDevice();
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1051
    SDL_Rect area;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1052
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1053
    /* Get the mouse rectangle, clipped to the screen */
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1054
    SDL_MouseRect(&area);
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1055
    if ((area.w == 0) || (area.h == 0)) {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1056
        return;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1057
    }
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1058
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1059
    /* Copy mouse background */
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1060
    {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1061
        int w, h, screenbpp;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1062
        Uint8 *src, *dst;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1063
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1064
        /* Set up the copy pointers */
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1065
        screenbpp = screen->format->BytesPerPixel;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1066
        if ((screen == SDL_VideoSurface) ||
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1067
            FORMAT_EQUAL(screen->format, SDL_VideoSurface->format)) {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1068
            dst = SDL_cursor->save[0];
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1069
        } else {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1070
            dst = SDL_cursor->save[1];
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1071
        }
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1072
        src = (Uint8 *) screen->pixels + area.y * screen->pitch +
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1073
            area.x * screenbpp;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1074
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1075
        /* Perform the copy */
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1076
        w = area.w * screenbpp;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1077
        h = area.h;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1078
        while (h--) {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1079
            SDL_memcpy(dst, src, w);
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1080
            dst += w;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1081
            src += screen->pitch;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1082
        }
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1083
    }
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1084
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1085
    /* Draw the mouse cursor */
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1086
    area.x -= SDL_cursor->area.x;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1087
    area.y -= SDL_cursor->area.y;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1088
    if ((area.x == 0) && (area.w == SDL_cursor->area.w)) {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1089
        SDL_DrawCursorFast(screen, &area);
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1090
    } else {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1091
        SDL_DrawCursorSlow(screen, &area);
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1092
    }
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1093
}
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1094
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1095
void
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1096
SDL_DrawCursor(SDL_Surface * screen)
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1097
{
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1098
    /* Lock the screen if necessary */
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1099
    if (screen == NULL) {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1100
        return;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1101
    }
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1102
    if (SDL_MUSTLOCK(screen)) {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1103
        if (SDL_LockSurface(screen) < 0) {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1104
            return;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1105
        }
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1106
    }
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1107
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1108
    SDL_DrawCursorNoLock(screen);
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1109
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1110
    /* Unlock the screen and update if necessary */
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1111
    if (SDL_MUSTLOCK(screen)) {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1112
        SDL_UnlockSurface(screen);
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1113
    }
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1114
    if ((screen->flags & SDL_SCREEN_SURFACE) &&
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1115
        !(screen->flags & SDL_HWSURFACE)) {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1116
        SDL_VideoDevice *_this = SDL_GetVideoDevice();
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1117
        SDL_Window *window;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1118
        SDL_Rect area;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1119
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1120
        window = SDL_GetWindowFromSurface(screen);
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1121
        if (!window) {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1122
            return;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1123
        }
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1124
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1125
        SDL_MouseRect(&area);
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1126
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1127
        if (_this->UpdateWindowSurface) {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1128
            _this->UpdateWindowSurface(_this, window, 1, &area);
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1129
        }
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1130
    }
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1131
}
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1132
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1133
void
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1134
SDL_EraseCursorNoLock(SDL_Surface * screen)
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1135
{
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1136
    SDL_VideoDevice *_this = SDL_GetVideoDevice();
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1137
    SDL_Window *window;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1138
    SDL_Rect area;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1139
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1140
    /* Get the window associated with the surface */
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1141
    window = SDL_GetWindowFromSurface(screen);
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1142
    if (!window || !window->surface) {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1143
        return;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1669
diff changeset
  1144
    }
eef792d31de8 Work in progress. :)
Sam Lantinga &