~rabbits/nasu

b4a02d95ee60801297f114d7899191c3fd81eb4d — Devine Lu Linvega 2 years ago cc729c8
Added title update
1 files changed, 32 insertions(+), 7 deletions(-)

M chr6.c
M chr6.c => chr6.c +32 -7
@@ 19,6 19,7 @@ typedef struct Point {
typedef struct Brush {
	int color;
	int down;
	int edit;
	Point pos;
} Brush;



@@ 41,6 42,12 @@ setpt(Point* p, int x, int y)
	return p;
}

int
inspt(Point* p, int w, int h)
{
	return p->x >= 0 && p->y >= 0 && p->x < w && p->y < h;
}

void
pixel(uint32_t* dst, Point p, int c)
{


@@ 112,7 119,7 @@ edit(Brush* b)
{
	Point p1;
	setpt(&p1, b->pos.x - PAD, b->pos.y - PAD);
	if(p1.x < 0 || p1.y < 0 || p1.x > (8 * HOR) * ZOOM || p1.y > (8 * VER) * ZOOM)
	if(!inspt(&p1, 8 * HOR * ZOOM, 8 * VER * ZOOM))
		return;
	write(
	    p1.x / (8 * ZOOM),


@@ 120,7 127,8 @@ edit(Brush* b)
	    (p1.x / ZOOM) % 8,
	    (p1.y / ZOOM) % 8,
	    b->color);
	SDL_SetWindowTitle(gWindow, "chr6*");
	b->edit = 1;
	update(b);
	redraw();
}



@@ 130,17 138,26 @@ erase(Brush* b)
	int i, id;
	Point p1;
	setpt(&p1, b->pos.x - PAD, b->pos.y - PAD);
	if(p1.x < 0 || p1.y < 0 || p1.x > 128 * ZOOM || p1.y > 128 * ZOOM)
	if(!inspt(&p1, 8 * HOR * ZOOM, 8 * VER * ZOOM))
		return;
	id = (p1.x / (8 * ZOOM)) + (p1.y / (8 * ZOOM)) * 16;
	for(i = 0; i < 8; ++i) {
		buffer[(id * 16) + i] = 0x00;
		buffer[(id * 16) + i + 8] = 0x00;
	}
	SDL_SetWindowTitle(gWindow, "chr6*");
	b->edit = 1;
	update(b);
	redraw();
}

void
update(Brush* b)
{
	char title[512];
	snprintf(title, 512, "chr6 | c%d %d:%d^%d%c", b->color, HOR, VER, ZOOM, b->edit ? '*' : ' ');
	SDL_SetWindowTitle(gWindow, title);
}

int
error(char* msg, const char* err)
{


@@ 158,13 175,14 @@ create(void)
}

void
save(void)
save(Brush* b)
{
	FILE* f = fopen("output.chr", "wb");
	if(!fwrite(buffer, sizeof(buffer), 1, f))
		error("Save", "Invalid output file");
	fclose(f);
	SDL_SetWindowTitle(gWindow, "chr6");
	b->edit = 0;
	update(b);
}

void


@@ 234,11 252,15 @@ dokey(SDL_Event* event, Brush* b)
		quit();
		break;
	case SDLK_e:
		save();
		save(b);
		break;
	case SDLK_r:
		render();
		break;
	case SDLK_TAB:
		b->color = b->color > 2 ? 0 : b->color + 1;
		update(b);
		break;
	case SDLK_h:
		GUIDES = !GUIDES;
		redraw();


@@ 296,7 318,9 @@ main(int argc, char** argv)
{
	int ticknext = 0;
	Brush brush;
	brush.down = 0;
	brush.color = 1;
	brush.edit = 0;

	if(!init())
		return error("SDL", "failure");


@@ 307,6 331,7 @@ main(int argc, char** argv)
		load(argv[1]);
	else
		create();
	update(&brush);

	/* main loop */