2015-01-19 23:06:43 +01:00
|
|
|
/* radare - LGPL - Copyright 2013-2015 - pancake */
|
2013-08-26 00:51:36 +02:00
|
|
|
|
|
|
|
#include <r_cons.h>
|
|
|
|
|
2014-04-29 03:53:48 +02:00
|
|
|
#define W(y) r_cons_canvas_write(c,y)
|
|
|
|
#define G(x,y) r_cons_canvas_gotoxy(c,x,y)
|
|
|
|
|
2013-08-26 00:51:36 +02:00
|
|
|
R_API void r_cons_canvas_free (RConsCanvas *c) {
|
|
|
|
free (c->b);
|
Initial support for colors in RConsCanvas
started on cons_canvas color support. Still a bit buggy, working out the kinks.
Yanked my old line drawing algo from ward, still working on colors.
Still incomplete, Changed the way that attributes work, still lots of strange behavior, It appears that most attributes aren't where they belong.
still not finished. Ok now the lines and colors are working, but the colors are overwriting other sections. Working on preventing that.
colors are now working, but they are _so. slow._
woops, removed the debugging printf
Figured out the big evil function that has to be optimized, attr_at takes aprox 91% of the cpu, so he needs to be fixed
Signed-off-by: r0nk <r00nk@simplecpu.com>
Signed-off-by: r0nk <r00nk@simplecpu.com>
2015-02-10 22:06:27 +00:00
|
|
|
free (c->attrs);
|
2013-08-26 00:51:36 +02:00
|
|
|
free (c);
|
|
|
|
}
|
|
|
|
|
|
|
|
R_API void r_cons_canvas_clear (RConsCanvas *c) {
|
|
|
|
int y;
|
2014-09-24 03:17:43 +02:00
|
|
|
if (c && c->b) {
|
2014-09-08 17:10:53 +02:00
|
|
|
memset (c->b, '\n', c->blen);
|
|
|
|
c->b[c->blen] = 0;
|
|
|
|
for (y = 0; y<c->h; y++)
|
|
|
|
c->b[ y * c->w ] = '\n';
|
Initial support for colors in RConsCanvas
started on cons_canvas color support. Still a bit buggy, working out the kinks.
Yanked my old line drawing algo from ward, still working on colors.
Still incomplete, Changed the way that attributes work, still lots of strange behavior, It appears that most attributes aren't where they belong.
still not finished. Ok now the lines and colors are working, but the colors are overwriting other sections. Working on preventing that.
colors are now working, but they are _so. slow._
woops, removed the debugging printf
Figured out the big evil function that has to be optimized, attr_at takes aprox 91% of the cpu, so he needs to be fixed
Signed-off-by: r0nk <r00nk@simplecpu.com>
Signed-off-by: r0nk <r00nk@simplecpu.com>
2015-02-10 22:06:27 +00:00
|
|
|
if(c->attrs){
|
|
|
|
c->attrslen=0;
|
2015-02-15 21:34:12 +01:00
|
|
|
memset (c->attrs, 0, sizeof (*c->attrs)*c->blen);
|
Initial support for colors in RConsCanvas
started on cons_canvas color support. Still a bit buggy, working out the kinks.
Yanked my old line drawing algo from ward, still working on colors.
Still incomplete, Changed the way that attributes work, still lots of strange behavior, It appears that most attributes aren't where they belong.
still not finished. Ok now the lines and colors are working, but the colors are overwriting other sections. Working on preventing that.
colors are now working, but they are _so. slow._
woops, removed the debugging printf
Figured out the big evil function that has to be optimized, attr_at takes aprox 91% of the cpu, so he needs to be fixed
Signed-off-by: r0nk <r00nk@simplecpu.com>
Signed-off-by: r0nk <r00nk@simplecpu.com>
2015-02-10 22:06:27 +00:00
|
|
|
}
|
2014-09-08 17:10:53 +02:00
|
|
|
}
|
2013-08-26 00:51:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
R_API RConsCanvas* r_cons_canvas_new (int w, int h) {
|
|
|
|
RConsCanvas *c;
|
|
|
|
if (w<1||h<1)
|
|
|
|
return NULL;
|
|
|
|
c = R_NEW0 (RConsCanvas);
|
|
|
|
if (!c) return NULL;
|
2015-02-14 04:50:29 +01:00
|
|
|
c->color = 0;
|
2014-05-05 03:15:28 +02:00
|
|
|
c->sx = 0;
|
|
|
|
c->sy = 0;
|
2013-08-26 00:51:36 +02:00
|
|
|
c->blen = (w+1)*h;
|
|
|
|
c->b = malloc (c->blen+1);
|
|
|
|
if (!c->b) {
|
|
|
|
free (c);
|
|
|
|
return NULL;
|
|
|
|
}
|
Initial support for colors in RConsCanvas
started on cons_canvas color support. Still a bit buggy, working out the kinks.
Yanked my old line drawing algo from ward, still working on colors.
Still incomplete, Changed the way that attributes work, still lots of strange behavior, It appears that most attributes aren't where they belong.
still not finished. Ok now the lines and colors are working, but the colors are overwriting other sections. Working on preventing that.
colors are now working, but they are _so. slow._
woops, removed the debugging printf
Figured out the big evil function that has to be optimized, attr_at takes aprox 91% of the cpu, so he needs to be fixed
Signed-off-by: r0nk <r00nk@simplecpu.com>
Signed-off-by: r0nk <r00nk@simplecpu.com>
2015-02-10 22:06:27 +00:00
|
|
|
c->attrslen = 0;
|
|
|
|
c->attrs = calloc(sizeof(*c->attrs),c->blen+1);
|
|
|
|
if (!c->attrs) {
|
|
|
|
free (c->b);
|
|
|
|
free (c);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
c->attr=Color_RESET;
|
2013-08-26 00:51:36 +02:00
|
|
|
c->w = w;
|
|
|
|
c->h = h;
|
|
|
|
c->x = c->y = 0;
|
|
|
|
r_cons_canvas_clear (c);
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
2014-05-05 03:15:28 +02:00
|
|
|
R_API int r_cons_canvas_gotoxy(RConsCanvas *c, int x, int y) {
|
2015-09-14 02:08:31 +02:00
|
|
|
int ret = true;
|
2014-09-24 03:17:43 +02:00
|
|
|
if (!c) return 0;
|
2014-05-05 03:15:28 +02:00
|
|
|
x += c->sx;
|
|
|
|
y += c->sy;
|
2015-05-31 20:05:41 +02:00
|
|
|
if (x > c->w * 2) return 0;
|
|
|
|
if (y > c->h * 2) return 0;
|
2014-08-01 00:54:04 +02:00
|
|
|
if (x >= c->w) {
|
2014-05-05 03:15:28 +02:00
|
|
|
c->x = c->w;
|
2015-09-14 02:08:31 +02:00
|
|
|
ret = false;
|
2014-05-05 03:15:28 +02:00
|
|
|
}
|
2014-08-01 00:54:04 +02:00
|
|
|
if (y >= c->h) {
|
2014-05-05 03:15:28 +02:00
|
|
|
c->y = c->h;
|
2015-09-14 02:08:31 +02:00
|
|
|
ret = false;
|
2014-05-05 03:15:28 +02:00
|
|
|
}
|
2015-05-31 20:05:41 +02:00
|
|
|
if (x < 0) {
|
2015-01-11 02:28:59 +01:00
|
|
|
//c->x = 0;
|
2015-09-14 02:08:31 +02:00
|
|
|
ret = false;
|
2014-05-05 03:15:28 +02:00
|
|
|
}
|
2015-05-31 20:05:41 +02:00
|
|
|
if (y < 0) {
|
2014-05-08 02:26:42 +02:00
|
|
|
c->y = 0;
|
2015-09-14 02:08:31 +02:00
|
|
|
ret = false;
|
2014-05-05 03:15:28 +02:00
|
|
|
}
|
2015-05-31 20:05:41 +02:00
|
|
|
if (x < c->w && x >= 0) c->x = x;
|
|
|
|
if (y < c->h && y >= 0) c->y = y;
|
2014-05-05 03:15:28 +02:00
|
|
|
return ret;
|
2013-08-26 00:51:36 +02:00
|
|
|
}
|
|
|
|
|
2015-07-30 00:50:37 +02:00
|
|
|
static int is_ansi_seq(const char *s) {
|
|
|
|
return s && *s == 0x1b && *(s + 1) == '[';
|
2013-08-26 00:51:36 +02:00
|
|
|
}
|
|
|
|
|
2015-07-30 00:50:37 +02:00
|
|
|
static int get_piece (const char *p, char *chr) {
|
|
|
|
const char *q = p;
|
|
|
|
if (!p) return 0;
|
2015-07-31 00:05:56 +02:00
|
|
|
while (p && *p && *p != '\n' && !is_ansi_seq(p)) p++;
|
2015-07-30 23:18:28 -04:00
|
|
|
if (chr) *chr = *p;
|
2015-07-30 00:50:37 +02:00
|
|
|
return p - q;
|
2013-08-26 00:51:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static char *prefixline(RConsCanvas *c, int *left) {
|
2015-07-31 22:56:48 +02:00
|
|
|
int x, len;
|
2014-09-24 03:17:43 +02:00
|
|
|
char *p;
|
2015-03-23 10:19:53 +01:00
|
|
|
if (!c) return NULL;
|
2015-07-31 22:56:48 +02:00
|
|
|
if (strlen (c->b) < (c->y * c->w)) return NULL;
|
2014-09-24 03:17:43 +02:00
|
|
|
p = c->b + (c->y * c->w);
|
2015-07-31 22:56:48 +02:00
|
|
|
len = strlen(p)-1;
|
|
|
|
for (x = 0; (p[x] && x<c->x) && x < len; x++) {
|
2013-08-26 00:51:36 +02:00
|
|
|
if (p[x] == '\n')
|
|
|
|
p[x] = ' ';
|
|
|
|
}
|
|
|
|
if (left) *left = c->w - c->x;
|
|
|
|
return p+x;
|
|
|
|
}
|
|
|
|
|
2015-02-15 21:48:46 +01:00
|
|
|
static const char ** attr_at(RConsCanvas *c,int loc){
|
2015-02-19 03:04:36 +00:00
|
|
|
int i, j, delta;
|
2015-02-15 21:48:46 +01:00
|
|
|
if (!c->color || c->attrslen==0)
|
2015-02-14 04:50:29 +01:00
|
|
|
return NULL;
|
2015-02-15 21:48:46 +01:00
|
|
|
j = c->attrslen / 2;
|
2015-02-19 03:04:36 +00:00
|
|
|
delta = c->attrslen / 2;
|
2015-02-15 21:48:46 +01:00
|
|
|
for (i=0; i<(c->attrslen); i++){
|
2015-02-19 03:04:36 +00:00
|
|
|
delta/=2;
|
|
|
|
if(delta == 0)
|
|
|
|
delta=1;
|
2015-02-15 21:48:46 +01:00
|
|
|
if (c->attrs[j].loc == loc)
|
2015-02-15 02:21:32 +00:00
|
|
|
return &c->attrs[j].a;
|
2015-02-15 21:48:46 +01:00
|
|
|
if(c->attrs[j].loc < loc) {
|
2015-02-19 03:04:36 +00:00
|
|
|
j+=delta;
|
2015-02-15 02:21:32 +00:00
|
|
|
if(j>=c->attrslen)
|
|
|
|
break;
|
2015-02-19 03:04:36 +00:00
|
|
|
if(c->attrs[j].loc > loc && delta==1)
|
2015-02-15 02:21:32 +00:00
|
|
|
break;
|
2015-02-15 21:48:46 +01:00
|
|
|
} else if(c->attrs[j].loc > loc) {
|
2015-02-19 03:04:36 +00:00
|
|
|
j-=delta;
|
2015-02-15 02:21:32 +00:00
|
|
|
if(j<=0)
|
|
|
|
break;
|
2015-02-19 03:04:36 +00:00
|
|
|
if(c->attrs[j].loc < loc && delta==1)
|
2015-02-15 02:21:32 +00:00
|
|
|
break;
|
|
|
|
}
|
Initial support for colors in RConsCanvas
started on cons_canvas color support. Still a bit buggy, working out the kinks.
Yanked my old line drawing algo from ward, still working on colors.
Still incomplete, Changed the way that attributes work, still lots of strange behavior, It appears that most attributes aren't where they belong.
still not finished. Ok now the lines and colors are working, but the colors are overwriting other sections. Working on preventing that.
colors are now working, but they are _so. slow._
woops, removed the debugging printf
Figured out the big evil function that has to be optimized, attr_at takes aprox 91% of the cpu, so he needs to be fixed
Signed-off-by: r0nk <r00nk@simplecpu.com>
Signed-off-by: r0nk <r00nk@simplecpu.com>
2015-02-10 22:06:27 +00:00
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-02-15 21:48:46 +01:00
|
|
|
static void sort_attrs(RConsCanvas *c) {
|
Initial support for colors in RConsCanvas
started on cons_canvas color support. Still a bit buggy, working out the kinks.
Yanked my old line drawing algo from ward, still working on colors.
Still incomplete, Changed the way that attributes work, still lots of strange behavior, It appears that most attributes aren't where they belong.
still not finished. Ok now the lines and colors are working, but the colors are overwriting other sections. Working on preventing that.
colors are now working, but they are _so. slow._
woops, removed the debugging printf
Figured out the big evil function that has to be optimized, attr_at takes aprox 91% of the cpu, so he needs to be fixed
Signed-off-by: r0nk <r00nk@simplecpu.com>
Signed-off-by: r0nk <r00nk@simplecpu.com>
2015-02-10 22:06:27 +00:00
|
|
|
int i,j;
|
|
|
|
RConsCanvasAttr value;
|
2015-02-17 17:01:00 +01:00
|
|
|
for (i = 1; i < c->attrslen; i++) {
|
Initial support for colors in RConsCanvas
started on cons_canvas color support. Still a bit buggy, working out the kinks.
Yanked my old line drawing algo from ward, still working on colors.
Still incomplete, Changed the way that attributes work, still lots of strange behavior, It appears that most attributes aren't where they belong.
still not finished. Ok now the lines and colors are working, but the colors are overwriting other sections. Working on preventing that.
colors are now working, but they are _so. slow._
woops, removed the debugging printf
Figured out the big evil function that has to be optimized, attr_at takes aprox 91% of the cpu, so he needs to be fixed
Signed-off-by: r0nk <r00nk@simplecpu.com>
Signed-off-by: r0nk <r00nk@simplecpu.com>
2015-02-10 22:06:27 +00:00
|
|
|
value = c->attrs[i];
|
2015-02-15 21:48:46 +01:00
|
|
|
for (j = i-1; j>=0 && c->attrs[j].loc>value.loc; j--) {
|
Initial support for colors in RConsCanvas
started on cons_canvas color support. Still a bit buggy, working out the kinks.
Yanked my old line drawing algo from ward, still working on colors.
Still incomplete, Changed the way that attributes work, still lots of strange behavior, It appears that most attributes aren't where they belong.
still not finished. Ok now the lines and colors are working, but the colors are overwriting other sections. Working on preventing that.
colors are now working, but they are _so. slow._
woops, removed the debugging printf
Figured out the big evil function that has to be optimized, attr_at takes aprox 91% of the cpu, so he needs to be fixed
Signed-off-by: r0nk <r00nk@simplecpu.com>
Signed-off-by: r0nk <r00nk@simplecpu.com>
2015-02-10 22:06:27 +00:00
|
|
|
c->attrs[j+1] = c->attrs[j];
|
|
|
|
}
|
|
|
|
c->attrs[j+1] = value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void stamp_attr(RConsCanvas *c,int length){
|
|
|
|
int i;
|
2015-02-15 21:48:46 +01:00
|
|
|
const char ** s;
|
2015-02-17 17:01:00 +01:00
|
|
|
const int loc = c->x + (c->y * c->w);
|
|
|
|
s = attr_at(c, loc);
|
Initial support for colors in RConsCanvas
started on cons_canvas color support. Still a bit buggy, working out the kinks.
Yanked my old line drawing algo from ward, still working on colors.
Still incomplete, Changed the way that attributes work, still lots of strange behavior, It appears that most attributes aren't where they belong.
still not finished. Ok now the lines and colors are working, but the colors are overwriting other sections. Working on preventing that.
colors are now working, but they are _so. slow._
woops, removed the debugging printf
Figured out the big evil function that has to be optimized, attr_at takes aprox 91% of the cpu, so he needs to be fixed
Signed-off-by: r0nk <r00nk@simplecpu.com>
Signed-off-by: r0nk <r00nk@simplecpu.com>
2015-02-10 22:06:27 +00:00
|
|
|
|
2015-02-17 17:01:00 +01:00
|
|
|
if (s) {
|
Initial support for colors in RConsCanvas
started on cons_canvas color support. Still a bit buggy, working out the kinks.
Yanked my old line drawing algo from ward, still working on colors.
Still incomplete, Changed the way that attributes work, still lots of strange behavior, It appears that most attributes aren't where they belong.
still not finished. Ok now the lines and colors are working, but the colors are overwriting other sections. Working on preventing that.
colors are now working, but they are _so. slow._
woops, removed the debugging printf
Figured out the big evil function that has to be optimized, attr_at takes aprox 91% of the cpu, so he needs to be fixed
Signed-off-by: r0nk <r00nk@simplecpu.com>
Signed-off-by: r0nk <r00nk@simplecpu.com>
2015-02-10 22:06:27 +00:00
|
|
|
//If theres already an attr there, just replace it.
|
|
|
|
*s = c->attr;
|
2015-02-17 17:01:00 +01:00
|
|
|
} else {
|
Initial support for colors in RConsCanvas
started on cons_canvas color support. Still a bit buggy, working out the kinks.
Yanked my old line drawing algo from ward, still working on colors.
Still incomplete, Changed the way that attributes work, still lots of strange behavior, It appears that most attributes aren't where they belong.
still not finished. Ok now the lines and colors are working, but the colors are overwriting other sections. Working on preventing that.
colors are now working, but they are _so. slow._
woops, removed the debugging printf
Figured out the big evil function that has to be optimized, attr_at takes aprox 91% of the cpu, so he needs to be fixed
Signed-off-by: r0nk <r00nk@simplecpu.com>
Signed-off-by: r0nk <r00nk@simplecpu.com>
2015-02-10 22:06:27 +00:00
|
|
|
c->attrs[c->attrslen].loc = loc;
|
|
|
|
c->attrs[c->attrslen].a = c->attr;
|
|
|
|
c->attrslen++;
|
|
|
|
sort_attrs(c);
|
|
|
|
}
|
|
|
|
|
|
|
|
for(i=0;i<length;i++){
|
|
|
|
s = attr_at(c,loc+i);
|
|
|
|
if(s)
|
|
|
|
*s = c->attr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-09 19:36:00 +02:00
|
|
|
/* check for ANSI sequences and use them as attr */
|
2015-07-30 00:50:37 +02:00
|
|
|
static const char *set_attr(RConsCanvas *c, const char *s) {
|
2015-08-09 19:36:00 +02:00
|
|
|
const char *p = s;
|
2015-07-30 00:50:37 +02:00
|
|
|
char *color;
|
2015-05-30 17:55:11 +02:00
|
|
|
|
2015-08-09 19:36:00 +02:00
|
|
|
while (is_ansi_seq(p)) {
|
|
|
|
p += 2;
|
|
|
|
while (*p && *p != 'J' && *p != 'm' && *p != 'H') {
|
|
|
|
p++;
|
|
|
|
}
|
2015-07-30 00:50:37 +02:00
|
|
|
p++;
|
2015-08-09 19:36:00 +02:00
|
|
|
}
|
2015-05-30 17:55:11 +02:00
|
|
|
|
2015-08-09 19:36:00 +02:00
|
|
|
if (p != s) {
|
2015-07-30 15:40:15 +02:00
|
|
|
color = r_str_ndup(s, p - s);
|
2015-07-30 00:50:37 +02:00
|
|
|
c->attr = color;
|
|
|
|
}
|
2015-08-09 19:36:00 +02:00
|
|
|
return p;
|
2015-07-30 00:50:37 +02:00
|
|
|
}
|
2015-05-30 17:55:11 +02:00
|
|
|
|
2015-07-30 00:50:37 +02:00
|
|
|
R_API void r_cons_canvas_write(RConsCanvas *c, const char *s) {
|
|
|
|
char *p, ch;
|
|
|
|
int orig_x, x;
|
2015-08-09 19:36:00 +02:00
|
|
|
int left, slen, attr_len, piece_len;
|
2015-05-30 17:55:11 +02:00
|
|
|
|
2015-07-30 00:50:37 +02:00
|
|
|
if (!c || !s || !*s) return;
|
2015-05-30 17:55:11 +02:00
|
|
|
|
2015-07-30 00:50:37 +02:00
|
|
|
/* split the string into pieces of non-ANSI chars and print them normally,
|
|
|
|
* using the ANSI chars to set the attr of the canvas */
|
|
|
|
orig_x = c->x;
|
|
|
|
do {
|
2015-08-09 19:36:00 +02:00
|
|
|
const char *s_part = set_attr (c, s);
|
2015-11-08 23:38:42 +01:00
|
|
|
ch = 0;
|
2015-08-09 19:36:00 +02:00
|
|
|
piece_len = get_piece (s_part, &ch);
|
|
|
|
if (piece_len == 0 && ch == '\0' && s_part == s) break;
|
2015-05-30 17:55:11 +02:00
|
|
|
|
2015-11-08 23:38:42 +01:00
|
|
|
left = 0;
|
2015-08-09 19:36:00 +02:00
|
|
|
p = prefixline (c, &left);
|
|
|
|
slen = R_MIN (left, piece_len);
|
|
|
|
attr_len = slen <= 0 && s_part != s ? 1 : slen;
|
|
|
|
if (attr_len > 0) {
|
|
|
|
stamp_attr (c, attr_len);
|
|
|
|
}
|
|
|
|
|
|
|
|
x = c->x - c->sx;
|
|
|
|
if (G (x, c->y - c->sy)) {
|
|
|
|
memcpy (p, s_part, slen);
|
2015-07-30 00:50:37 +02:00
|
|
|
}
|
2015-05-30 17:55:11 +02:00
|
|
|
|
2015-08-09 19:36:00 +02:00
|
|
|
s = s_part;
|
2015-07-30 00:50:37 +02:00
|
|
|
if (ch == '\n') {
|
|
|
|
c->y++;
|
|
|
|
c->x = orig_x;
|
|
|
|
s++;
|
|
|
|
if (*s == '\0') break;
|
|
|
|
} else {
|
|
|
|
c->x += slen;
|
|
|
|
}
|
|
|
|
s += piece_len;
|
|
|
|
} while (*s);
|
2015-08-09 19:36:00 +02:00
|
|
|
c->x = orig_x;
|
2013-08-26 00:51:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
R_API char *r_cons_canvas_to_string(RConsCanvas *c) {
|
|
|
|
int x, y, olen = 0;
|
2015-02-17 17:01:00 +01:00
|
|
|
char *o;
|
|
|
|
const char* b;
|
2015-02-15 21:48:46 +01:00
|
|
|
const char**atr;
|
2015-09-14 02:08:31 +02:00
|
|
|
int is_first = true;
|
2015-06-04 01:30:33 +02:00
|
|
|
|
2014-09-24 03:17:43 +02:00
|
|
|
if (!c) return NULL;
|
|
|
|
b = c->b;
|
Initial support for colors in RConsCanvas
started on cons_canvas color support. Still a bit buggy, working out the kinks.
Yanked my old line drawing algo from ward, still working on colors.
Still incomplete, Changed the way that attributes work, still lots of strange behavior, It appears that most attributes aren't where they belong.
still not finished. Ok now the lines and colors are working, but the colors are overwriting other sections. Working on preventing that.
colors are now working, but they are _so. slow._
woops, removed the debugging printf
Figured out the big evil function that has to be optimized, attr_at takes aprox 91% of the cpu, so he needs to be fixed
Signed-off-by: r0nk <r00nk@simplecpu.com>
Signed-off-by: r0nk <r00nk@simplecpu.com>
2015-02-10 22:06:27 +00:00
|
|
|
o = calloc (sizeof(char),
|
2015-02-17 17:01:00 +01:00
|
|
|
(c->w * (c->h + 1)) * (CONS_MAX_ATTR_SZ));
|
2014-09-24 03:17:43 +02:00
|
|
|
if (!o) return NULL;
|
2015-02-17 17:01:00 +01:00
|
|
|
for (y = 0; y < c->h; y++) {
|
2015-06-04 01:30:33 +02:00
|
|
|
if (!is_first) {
|
|
|
|
o[olen++] = '\n';
|
|
|
|
}
|
2015-09-14 02:08:31 +02:00
|
|
|
is_first = false;
|
2015-06-04 01:30:33 +02:00
|
|
|
|
2013-08-26 00:51:36 +02:00
|
|
|
for (x = 0; x<c->w; x++) {
|
2015-02-17 17:01:00 +01:00
|
|
|
const int p = x + (y * c->w);
|
|
|
|
atr = attr_at (c,p);
|
Initial support for colors in RConsCanvas
started on cons_canvas color support. Still a bit buggy, working out the kinks.
Yanked my old line drawing algo from ward, still working on colors.
Still incomplete, Changed the way that attributes work, still lots of strange behavior, It appears that most attributes aren't where they belong.
still not finished. Ok now the lines and colors are working, but the colors are overwriting other sections. Working on preventing that.
colors are now working, but they are _so. slow._
woops, removed the debugging printf
Figured out the big evil function that has to be optimized, attr_at takes aprox 91% of the cpu, so he needs to be fixed
Signed-off-by: r0nk <r00nk@simplecpu.com>
Signed-off-by: r0nk <r00nk@simplecpu.com>
2015-02-10 22:06:27 +00:00
|
|
|
if(atr) {
|
2015-02-17 17:01:00 +01:00
|
|
|
strcat (o, *atr);
|
|
|
|
olen += strlen (*atr);
|
Initial support for colors in RConsCanvas
started on cons_canvas color support. Still a bit buggy, working out the kinks.
Yanked my old line drawing algo from ward, still working on colors.
Still incomplete, Changed the way that attributes work, still lots of strange behavior, It appears that most attributes aren't where they belong.
still not finished. Ok now the lines and colors are working, but the colors are overwriting other sections. Working on preventing that.
colors are now working, but they are _so. slow._
woops, removed the debugging printf
Figured out the big evil function that has to be optimized, attr_at takes aprox 91% of the cpu, so he needs to be fixed
Signed-off-by: r0nk <r00nk@simplecpu.com>
Signed-off-by: r0nk <r00nk@simplecpu.com>
2015-02-10 22:06:27 +00:00
|
|
|
}
|
2013-08-26 00:51:36 +02:00
|
|
|
if (!b[p] || b[p]=='\n')
|
|
|
|
break;
|
|
|
|
o[olen++] = b[p];
|
|
|
|
}
|
|
|
|
}
|
Initial support for colors in RConsCanvas
started on cons_canvas color support. Still a bit buggy, working out the kinks.
Yanked my old line drawing algo from ward, still working on colors.
Still incomplete, Changed the way that attributes work, still lots of strange behavior, It appears that most attributes aren't where they belong.
still not finished. Ok now the lines and colors are working, but the colors are overwriting other sections. Working on preventing that.
colors are now working, but they are _so. slow._
woops, removed the debugging printf
Figured out the big evil function that has to be optimized, attr_at takes aprox 91% of the cpu, so he needs to be fixed
Signed-off-by: r0nk <r00nk@simplecpu.com>
Signed-off-by: r0nk <r00nk@simplecpu.com>
2015-02-10 22:06:27 +00:00
|
|
|
o[olen] = '\0';
|
2013-08-26 00:51:36 +02:00
|
|
|
return o;
|
|
|
|
}
|
|
|
|
|
2015-06-11 03:55:15 +02:00
|
|
|
R_API void r_cons_canvas_print_region(RConsCanvas *c) {
|
|
|
|
char *o = r_cons_canvas_to_string (c);
|
|
|
|
if (o) {
|
|
|
|
char *p = r_str_trim_tail (o);
|
|
|
|
if(p) {
|
|
|
|
r_cons_strcat (p);
|
|
|
|
free (p);
|
|
|
|
} else {
|
|
|
|
free (o);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-26 00:51:36 +02:00
|
|
|
R_API void r_cons_canvas_print(RConsCanvas *c) {
|
|
|
|
char *o = r_cons_canvas_to_string (c);
|
2014-09-08 17:10:53 +02:00
|
|
|
if (o) {
|
|
|
|
r_cons_strcat (o);
|
|
|
|
free (o);
|
|
|
|
}
|
2013-08-26 00:51:36 +02:00
|
|
|
}
|
2014-04-29 01:55:10 +02:00
|
|
|
|
2014-05-05 03:15:28 +02:00
|
|
|
R_API int r_cons_canvas_resize(RConsCanvas *c, int w, int h) {
|
2015-03-21 02:04:49 +01:00
|
|
|
void *newbuf = NULL;
|
2015-02-17 17:01:00 +01:00
|
|
|
const int blen = (w+1) * h;
|
2014-05-06 01:28:57 +04:00
|
|
|
char *b = NULL;
|
2015-09-14 02:08:31 +02:00
|
|
|
if (!c || w < 0) return false;
|
2014-09-08 17:10:53 +02:00
|
|
|
b = realloc (c->b, blen+1);
|
2015-09-14 02:08:31 +02:00
|
|
|
if (!b) return false;
|
2015-03-21 02:04:49 +01:00
|
|
|
c->b = b;
|
|
|
|
newbuf = realloc (c->attrs, sizeof (*c->attrs)*blen+1);
|
|
|
|
if (!newbuf) {
|
2015-03-21 01:27:54 +01:00
|
|
|
free (c->b);
|
|
|
|
free (c->attrs);
|
2015-09-14 02:08:31 +02:00
|
|
|
return false;
|
2015-03-21 01:27:54 +01:00
|
|
|
}
|
2015-03-21 02:04:49 +01:00
|
|
|
c->attrs = newbuf;
|
2014-09-08 17:10:53 +02:00
|
|
|
c->blen = blen;
|
2014-05-05 03:15:28 +02:00
|
|
|
c->b = b;
|
|
|
|
c->w = w;
|
|
|
|
c->h = h;
|
|
|
|
c->x = 0;
|
|
|
|
c->y = 0;
|
|
|
|
r_cons_canvas_clear (c);
|
2015-09-14 02:08:31 +02:00
|
|
|
return true;
|
2014-04-29 01:55:10 +02:00
|
|
|
}
|
|
|
|
|
2015-02-15 21:48:46 +01:00
|
|
|
R_API void r_cons_canvas_box(RConsCanvas *c, int x, int y, int w, int h, const char *color) {
|
2015-05-31 20:05:41 +02:00
|
|
|
int i, x_mod;
|
2014-04-29 03:53:48 +02:00
|
|
|
int roundcorners = 0;
|
2015-05-31 20:05:41 +02:00
|
|
|
char *row = NULL, *row_ptr;
|
2014-04-29 03:53:48 +02:00
|
|
|
char corner = '=';
|
|
|
|
|
2015-10-13 23:04:44 +02:00
|
|
|
if (w < 1 || h < 1) return;
|
2014-05-06 01:28:57 +04:00
|
|
|
|
2015-10-13 23:04:44 +02:00
|
|
|
if (color) c->attr = color;
|
|
|
|
if (!c->color) c->attr = Color_RESET;
|
2014-05-06 01:28:57 +04:00
|
|
|
row = malloc (w+1);
|
2015-03-05 02:07:53 +01:00
|
|
|
if (!row)
|
|
|
|
return;
|
2014-04-29 03:53:48 +02:00
|
|
|
row[0] = roundcorners?'.':corner;
|
2015-03-05 02:07:53 +01:00
|
|
|
if (w>2)
|
|
|
|
memset (row+1, '-', w-2);
|
|
|
|
if (w>1)
|
|
|
|
row[w-1] = roundcorners?'.':corner;
|
2015-05-31 20:04:55 +02:00
|
|
|
row[w] = 0;
|
2015-05-31 20:05:41 +02:00
|
|
|
|
|
|
|
row_ptr = row;
|
|
|
|
x_mod = x;
|
|
|
|
if (x < -c->sx) {
|
|
|
|
x_mod = R_MIN(-c->sx, x_mod + w);
|
|
|
|
row_ptr += x_mod - x;
|
|
|
|
}
|
|
|
|
if (G(x_mod, y)) {
|
|
|
|
W(row_ptr);
|
Initial support for colors in RConsCanvas
started on cons_canvas color support. Still a bit buggy, working out the kinks.
Yanked my old line drawing algo from ward, still working on colors.
Still incomplete, Changed the way that attributes work, still lots of strange behavior, It appears that most attributes aren't where they belong.
still not finished. Ok now the lines and colors are working, but the colors are overwriting other sections. Working on preventing that.
colors are now working, but they are _so. slow._
woops, removed the debugging printf
Figured out the big evil function that has to be optimized, attr_at takes aprox 91% of the cpu, so he needs to be fixed
Signed-off-by: r0nk <r00nk@simplecpu.com>
Signed-off-by: r0nk <r00nk@simplecpu.com>
2015-02-10 22:06:27 +00:00
|
|
|
}
|
2015-05-31 20:05:41 +02:00
|
|
|
if (G(x_mod, y+h-1)) {
|
2014-05-05 03:15:28 +02:00
|
|
|
row[0] = roundcorners?'\'':corner;
|
|
|
|
row[w-1] = roundcorners?'\'':corner;
|
2015-05-31 20:05:41 +02:00
|
|
|
W(row_ptr);
|
2014-05-05 03:15:28 +02:00
|
|
|
}
|
2014-04-29 01:55:10 +02:00
|
|
|
|
|
|
|
for (i=1;i<h-1;i++) {
|
2014-05-05 03:15:28 +02:00
|
|
|
if (G(x, y+i)) W("|");
|
|
|
|
if (G(x+w-1, y+i)) W("|");
|
2014-04-29 01:55:10 +02:00
|
|
|
}
|
2014-05-06 01:28:57 +04:00
|
|
|
free (row);
|
2015-10-13 23:04:44 +02:00
|
|
|
if (color) c->attr = Color_RESET;
|
2014-04-29 01:55:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
R_API void r_cons_canvas_fill(RConsCanvas *c, int x, int y, int w, int h, char ch, int replace) {
|
|
|
|
int i;
|
2014-05-06 01:28:57 +04:00
|
|
|
char *row = NULL;
|
|
|
|
|
|
|
|
if (w < 0) return;
|
|
|
|
|
|
|
|
row = malloc (w+1);
|
2014-04-29 03:53:48 +02:00
|
|
|
memset (row, ch, w);
|
2014-04-29 01:55:10 +02:00
|
|
|
row[w] = 0;
|
|
|
|
|
2014-04-29 03:53:48 +02:00
|
|
|
for (i=0;i<h;i++) {
|
2014-05-05 03:15:28 +02:00
|
|
|
if (G(x, y+i))
|
|
|
|
W(row);
|
2014-04-29 01:55:10 +02:00
|
|
|
}
|
2014-05-06 01:28:57 +04:00
|
|
|
free (row);
|
2014-04-29 01:55:10 +02:00
|
|
|
}
|
|
|
|
|
2015-07-26 13:26:08 +02:00
|
|
|
R_API void r_cons_canvas_line (RConsCanvas *c, int x, int y, int x2, int y2,
|
|
|
|
RCanvasLineStyle *style) {
|
2015-02-15 21:34:12 +01:00
|
|
|
if (c->linemode) {
|
|
|
|
r_cons_canvas_line_square (c, x, y, x2, y2, style);
|
|
|
|
} else {
|
|
|
|
r_cons_canvas_line_diagonal (c, x, y, x2, y2, style);
|
Initial support for colors in RConsCanvas
started on cons_canvas color support. Still a bit buggy, working out the kinks.
Yanked my old line drawing algo from ward, still working on colors.
Still incomplete, Changed the way that attributes work, still lots of strange behavior, It appears that most attributes aren't where they belong.
still not finished. Ok now the lines and colors are working, but the colors are overwriting other sections. Working on preventing that.
colors are now working, but they are _so. slow._
woops, removed the debugging printf
Figured out the big evil function that has to be optimized, attr_at takes aprox 91% of the cpu, so he needs to be fixed
Signed-off-by: r0nk <r00nk@simplecpu.com>
Signed-off-by: r0nk <r00nk@simplecpu.com>
2015-02-10 22:06:27 +00:00
|
|
|
}
|
2014-04-29 01:55:10 +02:00
|
|
|
}
|