summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKatolaZ <katolaz@freaknet.org>2019-08-14 07:59:53 +0100
committerKatolaZ <katolaz@freaknet.org>2019-08-14 07:59:53 +0100
commita95019dfe0b64ed01051f2f059af7d7756d0dcdb (patch)
tree6bdf12f44cdbfa116ff0320e31d4afb37e0b317a
parent257ec5d56fbe0ac65b04ae10bf36dd14e86c95a5 (diff)
add parallelogram mode
-rw-r--r--TODO5
-rw-r--r--draw.c58
-rw-r--r--gramscii.c6
-rw-r--r--gramscii.h12
-rw-r--r--screen.c2
5 files changed, 63 insertions, 20 deletions
diff --git a/TODO b/TODO
index 54225d6..48e2395 100644
--- a/TODO
+++ b/TODO
@@ -1,10 +1,10 @@
+ optimize redraws (redraw only the modified rectangle)
+- implement comment (#: ignore everything until the end of the line)
- add screen geometry option (-g 25x80?)
-- maybe move "text" mode to "t"
+- (?)maybe move "text" mode to "t"
- implement ellipse
- (?) filled box (B)
- (?) manage filled box character (as for other styles)
-- implement comment (#: ignore until the end of the line)
+ parse control characters
+ parse arrows (text-mode will allow movements as well)
- (?) implement CTRL+G as abort (aside ESC)
@@ -14,6 +14,7 @@
- allow scrolling (both vertical and horizontal)
- catch SIGWINCH and react appropriately (after scrolling is
enabled)
+* implement parallelogram mode (z/Z)
* fix bug in reading commands from files
* fix bug in visual crop
* read file at point
diff --git a/draw.c b/draw.c
index 0cb50a1..c361acb 100644
--- a/draw.c
+++ b/draw.c
@@ -143,8 +143,9 @@ void draw_box(int x1, int y1, int fix){
void draw_parallelogram(int x1, int y1, char st, char fix){
int xmin, ymin, xmax, ymax;
- int dy;
+ int dy, minoff, maxoff, xoff, xincr;
int i;
+ char lean;
void (*f)(int, int, char);
@@ -160,27 +161,47 @@ void draw_parallelogram(int x1, int y1, char st, char fix){
}
else
f = draw_xy;
- /*FIXME: INCOMPLETE -- CONTINUE HERE */
- for(i=xmin+1; i<=xmax; i++){
- f(i, ymin, line_h);
- f(i, ymax, line_h);
+ if (st & BOX_PARR){
+ minoff = dy;
+ maxoff = 0;
+ lean = '/';
+ xincr = -1;
}
- for(i=ymin+1; i<=ymax; i++){
- f(xmin, i, line_v);
- f(xmax, i, line_v);
+ else {
+ minoff = 0;
+ maxoff = dy;
+ lean = '\\';
+ xincr = +1;
}
- f(xmin, ymin, corner);
- f(xmin, ymax, corner);
- f(xmax, ymin, corner);
- f(xmax, ymax, corner);
+ for(i=xmin+1; i<=xmax-dy; i++){
+ f(i+minoff, ymin, line_h);
+ f(i+maxoff, ymax, line_h);
+ }
+
+ for(i=ymin+1, xoff=minoff; i<=ymax; i++, xoff += xincr){
+ f(xmin+(xoff+xincr), i, lean);
+ if (minoff)
+ f(xmax - (minoff - xoff - xincr), i, lean);
+ else
+ f(xmax - (maxoff - xoff - xincr), i, lean);
+ }
+ f(xmin+minoff, ymin, corner);
+ f(xmin+maxoff, ymax, corner);
+ f(xmax-maxoff, ymin, corner);
+ f(xmax-minoff, ymax, corner);
if (fix == FIX)
copy_lines_to_ring(ymin, ymax, NEW_STATE);
show_cursor();
-
-
}
+char flip_lean(char st){
+ if (st & BOX_PARR)
+ return BOX_PARL;
+ else if (st & BOX_PARL)
+ return BOX_PARR;
+ return st;
+}
void get_box(FILE *fc, char st){
char c;
@@ -189,6 +210,11 @@ void get_box(FILE *fc, char st){
step = 1;
draw_box(x,y,NOFIX);
while((c=fgetc(fc))!=EOF && c != 27 && c!= 'b' && c != '\n'){
+ if (c == 'Z'){
+ st = flip_lean(st);
+ redraw();
+ goto update_box;
+ }
if (change_style(c))
goto update_box;
if (!move_around(c, fc, 1))
@@ -208,8 +234,8 @@ update_box:
draw_box(orig_x, orig_y, FIX);
modified = 1;
}
- else if ((st & (BOX_PAR1 | BOX_PAR2)) && (c == 'z' || c == 'Z' || c == '\n')){
- draw_parallelogram(orig_x, orig_y, FIX);
+ else if ((st & (BOX_PARR | BOX_PARL)) && (c == 'z' || c == '\n')){
+ draw_parallelogram(orig_x, orig_y, st, FIX);
modified = 1;
}
redraw();
diff --git a/gramscii.c b/gramscii.c
index 2181d48..29b3f04 100644
--- a/gramscii.c
+++ b/gramscii.c
@@ -90,7 +90,7 @@ void commands(FILE *fc){
break;
case 'b':
mode = BOX;
- get_box(fc);
+ get_box(fc, BOX_RECT);
break;
case 'A': autoend=1;
case 'a':
@@ -134,6 +134,10 @@ void commands(FILE *fc){
case 'r':
read_file_at(fc, x, y);
break;
+ case 'z':
+ mode = PAR;
+ get_box(fc, BOX_PARR);
+ break;
case 'q':
check_modified(fc);/** FALLTHROUGH **/
case 'Q':
diff --git a/gramscii.h b/gramscii.h
index 0bad4f2..6adea42 100644
--- a/gramscii.h
+++ b/gramscii.h
@@ -18,6 +18,7 @@
#define TEXT 0x04
#define DEL 0x08
#define VIS 0x10
+#define PAR 0x20
/**/
/* directions */
@@ -31,6 +32,15 @@
#define DIR_VER (DIR_D | DIR_U)
/**/
+/** box style **/
+/* rectangular box */
+#define BOX_RECT 0x00
+/* parallelogram (leaning right) */
+#define BOX_PARR 0x01
+/* parallelogram (leaning left) */
+#define BOX_PARL 0x02
+/**/
+
#define NOFIX 0x0
#define FIX 0x1
@@ -169,7 +179,7 @@ int _isblank(int c);
/** drawing-related functions **/
int change_style(char c);
void get_text(FILE *fc);
-void get_box(FILE *fc);
+void get_box(FILE *fc, char st);
void get_arrow(FILE *fc);
void erase(FILE *fc);
void visual_box(FILE *fc);
diff --git a/screen.c b/screen.c
index d85ff81..21289c1 100644
--- a/screen.c
+++ b/screen.c
@@ -35,6 +35,8 @@ char* mode_str(){
return "del";
case VIS:
return "vis";
+ case PAR:
+ return "par";
default:
return "ERR";
}