From 34a0ec991e4985d3ca4719ffc696f681370e14fc Mon Sep 17 00:00:00 2001 From: KatolaZ Date: Fri, 19 Jul 2019 12:04:44 +0100 Subject: initial arrow implementation --- gramscii.c | 139 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 132 insertions(+), 7 deletions(-) (limited to 'gramscii.c') diff --git a/gramscii.c b/gramscii.c index bf988be..2cc7213 100644 --- a/gramscii.c +++ b/gramscii.c @@ -17,6 +17,7 @@ #define TEXT 0x04 +#define DIR_N 0x00 #define DIR_R 0x01 #define DIR_U 0x02 #define DIR_D 0x04 @@ -50,12 +51,12 @@ int y; int step; char cursor; char corner; -char hlines[] = {"-~=#@._"}; -char vlines[] = {"|H#@:;i"}; +char hlines[] = {"-~=#@._ "}; +char vlines[] = {"|H#@:;i "}; char corners[] = {"+'H#@.\""}; -int hlines_sz= sizeof(hlines); -int vlines_sz= sizeof(vlines); -int corners_sz = sizeof(corners); +int hlines_sz= sizeof(hlines) -1; +int vlines_sz= sizeof(vlines) -1; +int corners_sz = sizeof(corners) -1; int cur_hl, cur_vl, cur_corn; char line_h; char line_v; @@ -137,7 +138,6 @@ void redraw(){ } status_bar(); show_cursor(); - step = 1; } void update_current(){ @@ -235,8 +235,8 @@ void draw_box(int x1, int y1, int fix){ void get_box(){ char c; int orig_x=x, orig_y=y; - redraw(); + step = 1; draw_box(x,y,NOFIX); while((c=getchar())!=EOF && c != 27 && c!= 'b'){ switch(c){ @@ -259,6 +259,7 @@ void get_box(){ } check_bound(); redraw(); + step = 1; draw_box(orig_x, orig_y, NOFIX); status_bar(); show_cursor(); @@ -270,6 +271,126 @@ void get_box(){ } +int progr_x(int dir){ + switch(dir){ + case DIR_L: + return -1; + case DIR_R: + return +1; + default: + return 0; + } + return 0; +} + + +int progr_y(int dir){ + switch(dir){ + case DIR_D: + return +1; + case DIR_U: + return -1; + default: + return 0; + } + return 0; +} + + +/* FIXME: fix pointer position */ +/* FIXME: set initial and final markers */ +/* FIXME: draw "corner" as first char after change of dir */ +void draw_arrow(int x, int y, char *a, int a_len, int fix){ + + int i, j; + char line; + void (*f)(int, int, char); + + + if (fix == FIX) + f = set_xy; + else + f = draw_xy; + + if (!a_len){ + f(x,y,corner); + return; + } + line = (a[0] & DIR_L) || (a[0] & DIR_R) ? line_h : line_v; + f(x,y,line); + for (i=0; i