summaryrefslogtreecommitdiff
path: root/draw.c
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 /draw.c
parent257ec5d56fbe0ac65b04ae10bf36dd14e86c95a5 (diff)
add parallelogram mode
Diffstat (limited to 'draw.c')
-rw-r--r--draw.c58
1 files changed, 42 insertions, 16 deletions
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();