src/video/SDL_drawline.c
author Sam Lantinga <slouken@libsdl.org>
Sun, 02 Aug 2009 18:39:57 +0000
changeset 3227 458e53d8662c
parent 2910 27d8b12e0e8e
child 3536 0267b8b1595c
permissions -rw-r--r--
Clarified API documentation
slouken@2888
     1
/*
slouken@2888
     2
    SDL - Simple DirectMedia Layer
slouken@2888
     3
    Copyright (C) 1997-2009 Sam Lantinga
slouken@2888
     4
slouken@2888
     5
    This library is free software; you can redistribute it and/or
slouken@2888
     6
    modify it under the terms of the GNU Lesser General Public
slouken@2888
     7
    License as published by the Free Software Foundation; either
slouken@2888
     8
    version 2.1 of the License, or (at your option) any later version.
slouken@2888
     9
slouken@2888
    10
    This library is distributed in the hope that it will be useful,
slouken@2888
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
slouken@2888
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
slouken@2888
    13
    Lesser General Public License for more details.
slouken@2888
    14
slouken@2888
    15
    You should have received a copy of the GNU Lesser General Public
slouken@2888
    16
    License along with this library; if not, write to the Free Software
slouken@2888
    17
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
slouken@2888
    18
slouken@2888
    19
    Sam Lantinga
slouken@2888
    20
    slouken@libsdl.org
slouken@2888
    21
*/
slouken@2888
    22
#include "SDL_config.h"
slouken@2888
    23
slouken@2898
    24
#include "SDL_draw.h"
slouken@2890
    25
slouken@2890
    26
slouken@2901
    27
int
slouken@2888
    28
SDL_DrawLine(SDL_Surface * dst, int x1, int y1, int x2, int y2, Uint32 color)
slouken@2888
    29
{
slouken@2888
    30
    /* This function doesn't work on surfaces < 8 bpp */
slouken@2888
    31
    if (dst->format->BitsPerPixel < 8) {
slouken@2888
    32
        SDL_SetError("SDL_DrawLine(): Unsupported surface format");
slouken@2888
    33
        return (-1);
slouken@2888
    34
    }
slouken@2888
    35
slouken@2888
    36
    /* Perform clipping */
slouken@2910
    37
    if (!SDL_IntersectRectAndLine(&dst->clip_rect, &x1, &y1, &x2, &y2)) {
slouken@2909
    38
        return (0);
slouken@2909
    39
    }
slouken@2888
    40
slouken@2890
    41
    switch (dst->format->BytesPerPixel) {
slouken@2890
    42
    case 1:
slouken@2901
    43
        DRAWLINE(x1, y1, x2, y2, DRAW_FASTSETPIXEL1);
slouken@2890
    44
        break;
slouken@2890
    45
    case 2:
slouken@2901
    46
        DRAWLINE(x1, y1, x2, y2, DRAW_FASTSETPIXEL2);
slouken@2890
    47
        break;
slouken@2890
    48
    case 3:
slouken@2890
    49
        SDL_Unsupported();
slouken@2890
    50
        return -1;
slouken@2890
    51
    case 4:
slouken@2901
    52
        DRAWLINE(x1, y1, x2, y2, DRAW_FASTSETPIXEL4);
slouken@2890
    53
        break;
slouken@2890
    54
    }
slouken@2890
    55
    return 0;
slouken@2888
    56
}
slouken@2888
    57
slouken@2888
    58
/* vi: set ts=4 sw=4 expandtab: */