SDL_drawline.h File Reference
`#include "../../SDL_internal.h"`
Include dependency graph for SDL_drawline.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

## Functions

int | SDL_DrawLine (SDL_Surface *dst, int x1, int y1, int x2, int y2, Uint32 color)
int | SDL_DrawLines (SDL_Surface *dst, const SDL_Point *points, int count, Uint32 color)

## Function Documentation

## SDL_DrawLine()

int SDL_DrawLine | ( | SDL_Surface * | dst,
|  | int | x1,
|  | int | y1,
|  | int | x2,
|  | int | y2,
|  | Uint32 | color
| ) |  |

Definition at line 142 of file SDL_drawline.c.

References SDL_Surface::clip_rect, SDL_Surface::format, SDL_CalculateDrawLineFunc(), SDL_IntersectRectAndLine, SDL_SetError, and SDL_TRUE.

{
DrawLineFunc func;
if (!dst) {
return SDL_SetError("SDL_DrawLine(): Passed NULL destination surface");
}
func = SDL_CalculateDrawLineFunc(dst->format);
if (!func) {
return SDL_SetError("SDL_DrawLine(): Unsupported surface format");
}
/* Perform clipping */
/* FIXME: We don't actually want to clip, as it may change line slope */
if (!SDL_IntersectRectAndLine(&dst->clip_rect, &x1, &y1, &x2, &y2)) {
return 0;
}
func(dst, x1, y1, x2, y2, color, SDL_TRUE);
return 0;
}
x1
GLuint GLfloat GLfloat GLfloat x1
Definition: SDL_opengl_glext.h:8583
SDL_TRUE
Definition: SDL_stdinc.h:142
y2
GLfixed GLfixed GLfixed y2
Definition: SDL_opengl_glext.h:4583
x2
GLfixed GLfixed x2
Definition: SDL_opengl_glext.h:4583
DrawLineFunc
void(* DrawLineFunc)(SDL_Surface *dst, int x1, int y1, int x2, int y2, Uint32 color, SDL_bool draw_end)
Definition: SDL_drawline.c:120
y1
GLfixed y1
Definition: SDL_opengl_glext.h:4583
SDL_Surface::clip_rect
SDL_Rect clip_rect
Definition: SDL_surface.h:85
SDL_Surface::format
SDL_PixelFormat * format
Definition: SDL_surface.h:72
SDL_SetError
#define SDL_SetError
Definition: SDL_dynapi_overrides.h:30
func
GLenum func
Definition: SDL_opengl_glext.h:657
color
GLuint color
Definition: SDL_opengl_glext.h:1148
SDL_CalculateDrawLineFunc
static DrawLineFunc SDL_CalculateDrawLineFunc(const SDL_PixelFormat *fmt)
Definition: SDL_drawline.c:125
SDL_IntersectRectAndLine
#define SDL_IntersectRectAndLine
Definition: SDL_dynapi_overrides.h:297

## SDL_DrawLines()

int SDL_DrawLines | ( | SDL_Surface * | dst,
|  | const SDL_Point * | points,
|  | int | count,
|  | Uint32 | color
| ) |  |

Definition at line 166 of file SDL_drawline.c.

References SDL_Surface::clip_rect, SDL_Surface::format, i, SDL_CalculateDrawLineFunc(), SDL_DrawPoint(), SDL_IntersectRectAndLine, SDL_SetError, SDL_Point::x, and SDL_Point::y.

Referenced by SW_RenderDrawLines().

{
int i;
int x1, y1;
int x2, y2;
SDL_bool draw_end;
DrawLineFunc func;
if (!dst) {
return SDL_SetError("SDL_DrawLines(): Passed NULL destination surface");
}
func = SDL_CalculateDrawLineFunc(dst->format);
if (!func) {
return SDL_SetError("SDL_DrawLines(): Unsupported surface format");
}
for (i = 1; i < count; ++i) {
x1 = points[i-1].x;
y1 = points[i-1].y;
x2 = points[i].x;
y2 = points[i].y;
/* Perform clipping */
/* FIXME: We don't actually want to clip, as it may change line slope */
if (!SDL_IntersectRectAndLine(&dst->clip_rect, &x1, &y1, &x2, &y2)) {
continue;
}
/* Draw the end if it was clipped */
draw_end = (x2 != points[i].x || y2 != points[i].y);
func(dst, x1, y1, x2, y2, color, draw_end);
}
if (points[0].x != points[count-1].x || points[0].y != points[count-1].y) {
SDL_DrawPoint(dst, points[count-1].x, points[count-1].y, color);
}
return 0;
}
x1
GLuint GLfloat GLfloat GLfloat x1
Definition: SDL_opengl_glext.h:8583
x
GLint GLint GLint GLint GLint x
Definition: SDL_opengl.h:1574
count
GLuint GLuint GLsizei count
Definition: SDL_opengl.h:1571
y2
GLfixed GLfixed GLfixed y2
Definition: SDL_opengl_glext.h:4583
x2
GLfixed GLfixed x2
Definition: SDL_opengl_glext.h:4583
DrawLineFunc
void(* DrawLineFunc)(SDL_Surface *dst, int x1, int y1, int x2, int y2, Uint32 color, SDL_bool draw_end)
Definition: SDL_drawline.c:120
y1
GLfixed y1
Definition: SDL_opengl_glext.h:4583
SDL_Point::x
int x
Definition: SDL_rect.h:50
SDL_Point::y
int y
Definition: SDL_rect.h:51
y
GLint GLint GLint GLint GLint GLint y
Definition: SDL_opengl.h:1574
SDL_Surface::clip_rect
SDL_Rect clip_rect
Definition: SDL_surface.h:85
i
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
Definition: SDL_x11sym.h:50
SDL_bool
SDL_bool
Definition: SDL_stdinc.h:139
SDL_Surface::format
SDL_PixelFormat * format
Definition: SDL_surface.h:72
SDL_SetError
#define SDL_SetError
Definition: SDL_dynapi_overrides.h:30
func
GLenum func
Definition: SDL_opengl_glext.h:657
color
GLuint color
Definition: SDL_opengl_glext.h:1148
SDL_CalculateDrawLineFunc
static DrawLineFunc SDL_CalculateDrawLineFunc(const SDL_PixelFormat *fmt)
Definition: SDL_drawline.c:125
SDL_IntersectRectAndLine
#define SDL_IntersectRectAndLine
Definition: SDL_dynapi_overrides.h:297
SDL_DrawPoint
int SDL_DrawPoint(SDL_Surface *dst, int x, int y, Uint32 color)
Definition: SDL_drawpoint.c:30