~rabbits/nasu

3e0ac650ef708149d5d06bdb0c12c01b4f22a534 — Devine Lu Linvega 2 years ago c9dd407
Fixed scaling issue
1 files changed, 33 insertions(+), 20 deletions(-)

M chr6.c
M chr6.c => chr6.c +33 -20
@@ 61,6 61,12 @@ inspt(Point* p, int w, int h)
	return p->x >= 0 && p->y >= 0 && p->x < w && p->y < h;
}

int
dispt(Point* a, Point* b)
{
	return ((b->x - a->x) * (b->x - a->x)) + ((b->y - a->y) * (b->y - a->y));
}

/* Draw */

void


@@ 134,13 140,13 @@ write(int tx, int ty, int px, int py, int color)
void
edit(int x, int y, int color)
{
	if(x < 0 || y < 0 || x > 8 * HOR * ZOOM || y > 8 * VER * ZOOM)
	if(x < 0 || y < 0 || x > 8 * HOR || y > 8 * VER)
		return;
	write(
	    x / (8 * ZOOM),
	    y / (8 * ZOOM),
	    (x / ZOOM) % 8,
	    (y / ZOOM) % 8,
	    x / (8),
	    y / (8),
	    x % 8,
	    y % 8,
	    color);
}



@@ 173,7 179,7 @@ fill(Brush* b, int mode, int size, Point p0, int color)
		for(y = -size / 2; y < size; ++y) {
			setpt(&p, p0.x + x, p0.y + y);
			if(patt(p.x, p.y, mode, size))
				edit(p.x - PAD, p.y - PAD, color);
				edit(p.x, p.y, color);
		}
	b->edit = 1;
	redraw(pixels);


@@ 182,11 188,11 @@ fill(Brush* b, int mode, int size, Point p0, int color)
void
line(Point* p0, Point* p1, int color)
{
	double dx = abs(p1->x - p0->x), sx = p0->x < p1->x ? 1 : -1;
	double dy = -abs(p1->y - p0->y), sy = p0->y < p1->y ? 1 : -1;
	double err = dx + dy, e2;
	int dx = abs(p1->x - p0->x), sx = p0->x < p1->x ? 1 : -1;
	int dy = -abs(p1->y - p0->y), sy = p0->y < p1->y ? 1 : -1;
	int err = dx + dy, e2;
	for(;;) {
		edit(p0->x - PAD, p0->y - PAD, color);
		edit(p0->x, p0->y, color);
		if(p0->x == p1->x && p0->y == p1->y)
			break;
		e2 = 2 * err;


@@ 207,10 213,10 @@ erase(Brush* b)
{
	int i, id;
	Point p1;
	setpt(&p1, b->pos.x - PAD, b->pos.y - PAD);
	if(!inspt(&p1, 8 * HOR * ZOOM, 8 * VER * ZOOM))
	setpt(&p1, b->pos.x, b->pos.y);
	if(!inspt(&p1, 8 * HOR, 8 * VER))
		return;
	id = (p1.x / (8 * ZOOM)) + (p1.y / (8 * ZOOM)) * 16;
	id = (p1.x / 8) + (p1.y / 8) * 16;
	for(i = 0; i < 8; ++i) {
		buffer[(id * 16) + i] = 0x00;
		buffer[(id * 16) + i + 8] = 0x00;


@@ 305,15 311,21 @@ domouse(SDL_Event* event, Brush* b)
			b->down = 1;
		if(event->button.button == SDL_BUTTON_RIGHT)
			b->erase = 1;
		setpt(&b->prev, event->motion.x, event->motion.y);
		setpt(&b->prev,
		      (event->motion.x - PAD) / ZOOM,
		      (event->motion.y - PAD) / ZOOM);
	case SDL_MOUSEMOTION:
		if(b->down) {
			setpt(&b->pos, event->motion.x, event->motion.y);
			if(b->mode == 0)
				line(&b->prev, &b->pos, b->erase ? 0 : b->color);
			else
				fill(b, b->mode, b->size, b->pos, b->erase ? 0 : b->color);
			setpt(&b->prev, b->pos.x, b->pos.y);
			setpt(&b->pos,
			      (event->motion.x - PAD) / ZOOM,
			      (event->motion.y - PAD) / ZOOM);
			if(dispt(&b->pos, &b->prev) > ZOOM * 2) {
				if(b->mode == 0)
					line(&b->prev, &b->pos, b->erase ? 0 : b->color);
				else
					fill(b, b->mode, b->size, b->pos, b->erase ? 0 : b->color);
				setpt(&b->prev, b->pos.x, b->pos.y);
			}
		}
		break;
	}


@@ 399,6 411,7 @@ int
main(int argc, char** argv)
{
	int ticknext = 0;
	Point a, b;
	Brush brush;
	brush.down = 0;
	brush.color = 1;