SDL  2.0
SDL_drawline.h File Reference
+ 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.

143 {
145 
146  if (!dst) {
147  return SDL_SetError("SDL_DrawLine(): Passed NULL destination surface");
148  }
149 
150  func = SDL_CalculateDrawLineFunc(dst->format);
151  if (!func) {
152  return SDL_SetError("SDL_DrawLine(): Unsupported surface format");
153  }
154 
155  /* Perform clipping */
156  /* FIXME: We don't actually want to clip, as it may change line slope */
157  if (!SDL_IntersectRectAndLine(&dst->clip_rect, &x1, &y1, &x2, &y2)) {
158  return 0;
159  }
160 
161  func(dst, x1, y1, x2, y2, color, SDL_TRUE);
162  return 0;
163 }
GLuint GLfloat GLfloat GLfloat x1
GLfixed GLfixed GLfixed y2
GLfixed GLfixed x2
void(* DrawLineFunc)(SDL_Surface *dst, int x1, int y1, int x2, int y2, Uint32 color, SDL_bool draw_end)
Definition: SDL_drawline.c:120
GLfixed y1
SDL_Rect clip_rect
Definition: SDL_surface.h:85
SDL_PixelFormat * format
Definition: SDL_surface.h:72
#define SDL_SetError
GLenum func
GLuint color
static DrawLineFunc SDL_CalculateDrawLineFunc(const SDL_PixelFormat *fmt)
Definition: SDL_drawline.c:125
#define SDL_IntersectRectAndLine

◆ 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().

168 {
169  int i;
170  int x1, y1;
171  int x2, y2;
172  SDL_bool draw_end;
174 
175  if (!dst) {
176  return SDL_SetError("SDL_DrawLines(): Passed NULL destination surface");
177  }
178 
179  func = SDL_CalculateDrawLineFunc(dst->format);
180  if (!func) {
181  return SDL_SetError("SDL_DrawLines(): Unsupported surface format");
182  }
183 
184  for (i = 1; i < count; ++i) {
185  x1 = points[i-1].x;
186  y1 = points[i-1].y;
187  x2 = points[i].x;
188  y2 = points[i].y;
189 
190  /* Perform clipping */
191  /* FIXME: We don't actually want to clip, as it may change line slope */
192  if (!SDL_IntersectRectAndLine(&dst->clip_rect, &x1, &y1, &x2, &y2)) {
193  continue;
194  }
195 
196  /* Draw the end if it was clipped */
197  draw_end = (x2 != points[i].x || y2 != points[i].y);
198 
199  func(dst, x1, y1, x2, y2, color, draw_end);
200  }
201  if (points[0].x != points[count-1].x || points[0].y != points[count-1].y) {
202  SDL_DrawPoint(dst, points[count-1].x, points[count-1].y, color);
203  }
204  return 0;
205 }
GLuint GLfloat GLfloat GLfloat x1
GLint GLint GLint GLint GLint x
Definition: SDL_opengl.h:1574
GLuint GLuint GLsizei count
Definition: SDL_opengl.h:1571
GLfixed GLfixed GLfixed y2
GLfixed GLfixed x2
void(* DrawLineFunc)(SDL_Surface *dst, int x1, int y1, int x2, int y2, Uint32 color, SDL_bool draw_end)
Definition: SDL_drawline.c:120
GLfixed y1
int x
Definition: SDL_rect.h:50
int y
Definition: SDL_rect.h:51
GLint GLint GLint GLint GLint GLint y
Definition: SDL_opengl.h:1574
SDL_Rect clip_rect
Definition: SDL_surface.h:85
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
Definition: SDL_stdinc.h:139
SDL_PixelFormat * format
Definition: SDL_surface.h:72
#define SDL_SetError
GLenum func
GLuint color
static DrawLineFunc SDL_CalculateDrawLineFunc(const SDL_PixelFormat *fmt)
Definition: SDL_drawline.c:125
#define SDL_IntersectRectAndLine
int SDL_DrawPoint(SDL_Surface *dst, int x, int y, Uint32 color)
Definition: SDL_drawpoint.c:30