summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--draw.c88
-rw-r--r--gramscii.h14
2 files changed, 77 insertions, 25 deletions
diff --git a/draw.c b/draw.c
index 1c74a94..e1ee63b 100644
--- a/draw.c
+++ b/draw.c
@@ -161,7 +161,7 @@ void draw_parallelogram(int x1, int y1, char st, char fix){
}
else
f = draw_xy;
- if (st & BOX_PARR){
+ if (st == BOX_PARR){
minoff = dy;
maxoff = 0;
lean = '/';
@@ -195,47 +195,89 @@ void draw_parallelogram(int x1, int y1, char st, char fix){
}
-char flip_lean(char st){
- if (st & BOX_PARR)
+char flip_par_lean(char st){
+ if (st == BOX_PARR)
return BOX_PARL;
- else if (st & BOX_PARL)
+ else if (st == BOX_PARL)
return BOX_PARR;
return st;
}
+void draw_trapezium(int x1, int y1, char st, char fix){
+
+}
+
+/*
+ * draw the current box, being it an actual box, a parallelogram, or a
+ * trapezium
+ */
+void update_box(int x1, int y1, char st, char fix){
+
+ if (st == BOX_RECT)
+ draw_box(x1, y1, fix);
+ else if (st & BOX_PAR)
+ draw_parallelogram(x1, y1, st, fix);
+ else if (st & BOX_TRAP)
+ draw_trapezium(x1, y1, st, fix);
+ status_bar();
+ show_cursor();
+}
+
+char toggle_trap_type(char st){
+ return st;
+}
+
+int box_end(char c, char st){
+ if (c == '\n' ||
+ c == 27 ||
+ ((st == BOX_RECT) && c == 'b') ||
+ ((st & BOX_PAR) && c == 'z') ||
+ ((st & BOX_TRAP) && c == 't'))
+ return 1;
+ return 0;
+}
+
+/* draw boxes, parallelograms, and trapezia */
void get_box(FILE *fc, char st){
char c;
int orig_x=x, orig_y=y;
redraw();
step = 1;
+#ifdef DEBUG
+ fprintf(stderr, "box style: %d\n", st);
+#endif
draw_box(x,y,NOFIX);
- while((c=fgetc(fc))!=EOF && c != 27 && c!= 'b' && c != '\n'){
- if (c == 'Z'){
- st = flip_lean(st);
+ while((c=fgetc(fc))!=EOF && !box_end(c, st)){
+ if (c == 'Z' && (st & BOX_PAR)){
+ st = flip_par_lean(st);
redraw();
- goto update_box;
+#ifdef DEBUG
+ fprintf(stderr, "new parallelogram style: %d\n", st);
+#endif
+ update_box(orig_x, orig_y, st, NOFIX);
+ continue;
+ }
+ else if (c == 'T' && (st & BOX_TRAP)){
+ st = toggle_trap_type(st);
+ redraw();
+ update_box(orig_x, orig_y, st, NOFIX);
+ continue;
+ }
+ if (change_style(c)){
+ update_box(orig_x, orig_y, st, NOFIX);
+ continue;
}
- if (change_style(c))
- goto update_box;
if (!move_around(c, fc, 1))
continue;
check_bound(&x, &y);
redraw();
step = 1;
-update_box:
- if (st == BOX_RECT)
- draw_box(orig_x, orig_y, NOFIX);
- else
- draw_parallelogram(orig_x, orig_y, st, NOFIX);
- status_bar();
- show_cursor();
- }
- if (st == BOX_RECT && (c == 'b' || c == '\n')){
- draw_box(orig_x, orig_y, FIX);
- modified = 1;
+ update_box(orig_x, orig_y, st, NOFIX);
}
- else if ((st & (BOX_PARR | BOX_PARL)) && (c == 'z' || c == '\n')){
- draw_parallelogram(orig_x, orig_y, st, FIX);
+ if (((st == BOX_RECT ) && (c == 'b' || c == '\n')) ||
+ ( (st & BOX_PAR ) && (c == 'z' || c == '\n')) ||
+ ( (st & BOX_TRAP ) && (c == 't' || c == '\n'))){
+ update_box(orig_x, orig_y, st, FIX);
modified = 1;
}
redraw();
diff --git a/gramscii.h b/gramscii.h
index c2b9170..b8c2161 100644
--- a/gramscii.h
+++ b/gramscii.h
@@ -36,10 +36,20 @@
/** box style **/
/* rectangular box */
#define BOX_RECT 0x00
+/* parallelograms */
+#define BOX_PAR 0x04
/* parallelogram (leaning right) */
-#define BOX_PARR 0x01
+#define BOX_PARR 0x05
/* parallelogram (leaning left) */
-#define BOX_PARL 0x02
+#define BOX_PARL 0x06
+/* trapezium */
+#define BOX_TRAP 0x10
+#define BOX_TRAP_UR 0x11
+#define BOX_TRAP_UC 0x12
+#define BOX_TRAP_UL 0x13
+#define BOX_TRAP_DL 0x14
+#define BOX_TRAP_DC 0x15
+#define BOX_TRAP_DR 0x16
/**/
#define NOFIX 0x0