libs/libgui/gfx.c
// Using Bresenham's algorithm
// TODO: Better line scaling
Using Bresenham's algorithm
TODO: Better line scaling
Using Bresenham ' s algorithm TODO : Better line scaling
void gfx_draw_line(struct gfx_context *ctx, vec2 pos1, vec2 pos2, u32 scale, u32 c)
{
	int dx = ABS(pos2.x - pos1.x), sx = pos1.x < pos2.x ? 1 : -1;
	int dy = ABS(pos2.y - pos1.y), sy = pos1.y < pos2.y ? 1 : -1;
	int err = (dx > dy ? dx : -dy) / 2, e2;
	while (1) {
		gfx_draw_rectangle(ctx, pos1, vec2_add(pos1, vec2(scale, scale)), c);
		if (pos1.x == pos2.x && pos1.y == pos2.y)
			break;
		e2 = err;
		if (e2 > -dx) {
			err -= dy;
			pos1.x += sx;
		}
		if (e2 < dy) {
			err += dx;
			pos1.y += sy;
		}
	}
}
void gfx_draw_line ( struct gfx_context * ctx , vec2 pos1 , vec2 pos2 , u32 scale , u32 c ) { int dx = ABS ( pos2 . x - pos1 . x ) , sx = pos1 . x < pos2 . x ? 1 : -1 ; int dy = ABS ( pos2 . y - pos1 . y ) , sy = pos1 . y < pos2 . y ? 1 : -1 ; int err = ( dx > dy ? dx : - dy ) / 2 , e2 ; while ( 1 ) { gfx_draw_rectangle ( ctx , pos1 , vec2_add ( pos1 , vec2 ( scale , scale ) ) , c ) ; if ( pos1 . x == pos2 . x && pos1 . y == pos2 . y ) break ; e2 = err ; if ( e2 > - dx ) { err -= dy ; pos1 . x += sx ; } if ( e2 < dy ) { err += dx ; pos1 . y += sy ; } } }
Using Bresenham's algorithm
TODO: Better line scaling
Using Bresenham ' s algorithm TODO : Better line scaling