radare2/libr/cons
Julien Nabet 164bbc7333 Some cppcheck reports fixed:
(warning) Logical disjunction always evaluates to true: regnum < 32 || regnum > 31
(style) Same expression on both sides of '||'
(style) Same expression on both sides of '&&'
(style) Expression is always false because 'else if' condition matches previous condition at line 180
2014-12-28 04:20:14 +01:00
..
d Add smyck theme 2014-10-21 00:08:43 +02:00
t Added 'VV' command to run the visual graph mode 2014-04-29 03:54:20 +02:00
2048.c Improves the 2048 implementation 2014-08-30 20:06:09 +02:00
canvas.c Fix the support for 0x0 sized terminals (adb shell) 2014-09-24 03:17:43 +02:00
cons.c Fix #1714 - Add ~{} and ~{}.. RCons filters for JSON indentation 2014-11-22 01:51:51 +01:00
dietline.c Add '!' inside '#!' and make r_core_editor accessible from r_cons_editor. 2014-12-19 03:17:28 +01:00
editor.c Add '!' inside '#!' and make r_core_editor accessible from r_cons_editor. 2014-12-19 03:17:28 +01:00
grep.c Fix static build 2014-11-23 11:03:24 +01:00
hud.c Fix GCC warnings: array subscript has type 'char' 2014-12-04 03:26:08 +00:00
input.c Implement emacs keybindings for Visual mode (thanks jonatanhal) 2014-11-20 01:40:33 +01:00
Jamroot Add some Jam files and merge rsign into ranal 2013-12-31 05:30:39 +01:00
less.c Fix build and some warnings from rap_server 2014-05-05 14:38:47 +02:00
line.c Initial implementation of the wip multiline text editor 2013-08-28 03:06:10 +02:00
Makefile Add r_cons_is_utf8 () and use it to setup scr.utf8 on non-quiet mode 2014-08-25 03:26:02 +02:00
output.c Some cppcheck reports fixed: 2014-12-28 04:20:14 +01:00
pal.c Fix warnings in RCons and update sdb 2014-12-14 01:56:55 +01:00
pipe.c Fix libr_cons building on cygwin 2014-06-25 16:52:01 +04:00
README * Rename MALLOC_STRUCT into R_NEW and deprecate it. 2010-03-12 13:35:10 +01:00
rgb.c Improve colors in webui and fix ans256 to rgb 2014-12-10 21:47:46 +01:00
TODO Better paralelization of build system 2012-10-04 01:20:00 +02:00
utf8.c Fix infinite loop when debugging r2 from lldb 2014-09-10 01:40:43 +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;
}