radare2/libr/cons
pancake 542de1b426 Avoid dup load of DEX, reduce calls to r_meta_cleanup
- Nicer output for command 'fd'
- Cache methods to avoi dup loading
- Fix delimiter in internal grep (allow '/')
- Faster r_meta processing (reduce calls to meta_cleanup
2013-04-05 02:55:47 +02:00
..
color.c * Use strncpy instead of strcpy in asm and util 2011-07-06 01:29:18 +02:00
cons.c Initial support for UTF8 in r_cons and r_util 2013-04-04 01:42:12 +02:00
dietline.c Initial support for UTF8 in r_cons and r_util 2013-04-04 01:42:12 +02:00
grep.c Avoid dup load of DEX, reduce calls to r_meta_cleanup 2013-04-05 02:55:47 +02:00
hud.c Initial support for UTF8 in r_cons and r_util 2013-04-04 01:42:12 +02:00
input.c Fix #55 and add Cj to list metadata in json format 2013-03-01 12:20:18 +01:00
line.c Fix mmap and other minor issues on w32 2013-01-23 18:38:08 +01:00
Makefile Initial import of r_cons_rgb API (ansi 256 color) 2013-04-01 04:42:14 +02:00
output.c Implement dynamic graph for the embedded web UI 2012-09-21 03:05:00 +02:00
pipe.c Fix mmap and other minor issues on w32 2013-01-23 18:38:08 +01:00
README * Rename MALLOC_STRUCT into R_NEW and deprecate it. 2010-03-12 13:35:10 +01:00
rgb.c Initial import of r_cons_rgb API (ansi 256 color) 2013-04-01 04:42:14 +02:00
test-rgb.c Initial import of r_cons_rgb API (ansi 256 color) 2013-04-01 04:42:14 +02:00
TODO Better paralelization of build system 2012-10-04 01:20:00 +02:00

+--------+
| r_cons |
+--------+

r_cons_fb

r_cons_frame
r_cons_frame_add
r_cons_frame_del

struct r_cons_frame_t {
	int w, h; // should be the same as text|draw->w and text|draw->h 
	int rw, rh;
	struct r_cons_buffer_t *text;
	struct r_cons_buffer_t *draw;
	struct
};

struct r_cons_buffer_t {
	int alpha; /* ' ' chars in buffers are not written */
	int w, h;
	ut8 *buf;
};

struct r_cons_t {
	struct r_cons_buffer_t *b;
	int w, h;
	struct list_head frames;
};

struct r_cons_frame_t *r_cons_frame_new(int x, int y, int w, int h)
{
	struct r_cons_frame_t *f = R_NEW(struct r_cons_frame_t);
	f->text = r_cons_buffer_new(w, h);
	f->draw = r_cons_buffer_new(w, h);
	f->w = w;
	f->h = h;
	return f;
}

void r_cons_frame_add(struct r_cons_t *cons, struct r_cons_frame_t *f, int head)
{
	if (head) list_add(&(f->list), &cons->frames);
	else list_add_tail(&(f->list), &cons->frames);
}


int r_cons_frame_render(struct r_cons_frame_t *frame, struct r_cons_buffer_t *buf)
{
	/* foreach pixel resolve matching frame (Z-ordered) and draw */
}

/* <{:api-prefix r_cons_}> */
/* <{:doc Draws a line between two points in a buffer}> */
/* <{:api int,buffer_line,int,int,int,int}> */
void r_cons_buffer_line(struct r_cons_buffer_t *buf, int x0, int y0, int x1, int y1)
{
	/* XXX PURE SHIT */
	char onechars[9] = {
		'.', '_',',',
		'\\', '|','/',
		'\'', '^','\'',
	};
	double x = x0;
	double y = y0;
	double xi = x1-x0;
	double yi = y1-y0;
	for(;x<x1;x++) {
		r_cons_buffer_putch(buf, x, y, '.');
		x+=xi;
	}
}

/* buffers */

struct r_cons_buffer *r_cons_buffer_new(int w, int h)
{
	struct r_cons_buffer_t *buf = R_NEW(struct r_cons_buffer_t);
	if (w<1) w=1;
	if (h<1) h=1;
	buf->rw = buf->w = w;
	buf->rh = buf->h = h;
	buf->buf = (ut8*)malloc(w*h);
	return buf;
}

int r_cons_buffer_set_size(struct r_cons_buffer *buf, int w, int h)
{
	struct r_cons_buffer_t *buf = R_NEW(struct r_cons_buffer_t);
	if (w<1) w=1;
	if (h<1) h=1;
	if (w>buf->rw) {
		/* must resize internal buffer */
		buf->rw = w;
		buf->buf = (ut8*) realloc(buf->buf, w*h);
	}
	buf->rw = buf->w = w;
	buf->rh = buf->h = h;
	buf->buf = (ut8*)malloc(w*h);
	return buf;
}