textdraw-0.2+ds/0000755000000000000000000000000012217537346012327 5ustar rootroottextdraw-0.2+ds/td.c0000644000000000000000000004302604171745105013101 0ustar rootroot/* Textdraw (td) is a small utility that allows do draw (ascii-based) line-, rectangle-, ellipse- and text-objects with copy/paste/move features. Homepage of Textdraw: http://web.uta4you.at/shop/td/index.htm (c) July/2002 by Dieter Schoppitsch (shop@uta4you.at) */ #include #include #include #include #define trunc(x) ((int)(x)) #define ESC 27 // escape key #define ENTER 10 // enter key #define DEL 330 // del key #define MAXOBJECTS 100 // maximum of possible objects #define MAXTXTLEN 200 // max string length /* VARIABLES*/ int x=0, y=0; int maxrow=23, maxcol=79, menrow=24; int lastlin=0, lastrec=0, lasttxt=0, lastell=0; char chart[MAXTXTLEN][MAXTXTLEN]; // max chart (console) dimensions char string[MAXTXTLEN]=""; FILE *fil; char *filename; struct _line_ {int x1,y1,x2,y2; char a;}; struct _line_ lin[MAXOBJECTS]; struct _rect_ {int x1,y1,x2,y2;}; struct _rect_ rec[MAXOBJECTS]; struct _ell_ {int x1,y1,x2,y2;}; struct _ell_ ell[MAXOBJECTS]; struct _text_ {int x,y; char a; char t[MAXTXTLEN];}; struct _text_ txt[MAXOBJECTS]; struct _mark_ {char a; int nr;}; struct _mark_ mark; struct _buf_ {int x1,y1,x2,y2; char c,a; char t[MAXTXTLEN];}; struct _buf_ buf; /* SUBPROGRAMS */ int round(float x) // round function { if(x>=0) return trunc(x+0.5); else return trunc(x-0.5); } void clearcomment() // clears comment line { int i; char s[MAXTXTLEN]; for(i=0;i<=maxcol;i++) s[i]=' '; mvprintw(menrow, 0,"%s",s); } void comment(char *txt) // print comment { clearcomment(); mvprintw(menrow, 0,"%s", txt);} void comment_error(char *where) { char buf[128]; snprintf(buf, sizeof(buf), "%s: %s", where, strerror(errno)); comment(buf); } void curpos() //position cursor with printing coordinates { mvprintw(menrow,maxcol-10," "); mvprintw(menrow,maxcol-10,"x=%d y=%d",x,y); mvprintw(y,x,""); } void cursor() // move cursor to a new position { int c; while((c=getch()) != ENTER) { switch(c) { case KEY_UP: y-=1; if(y<0) y=0; curpos(); break; case KEY_DOWN: y+=1; if(y>maxrow) y=maxrow; curpos(); break; case KEY_LEFT: x-=1; if(x<0) x=0; curpos(); break; case KEY_RIGHT: x+=1; if(x>maxcol) x=maxcol; curpos(); break; case KEY_HOME: x=0; curpos(); break; case KEY_END: x=maxcol; curpos(); break; case KEY_PPAGE: y=0; curpos(); break; case KEY_NPAGE: y=maxrow; curpos(); break; } } } void input() // reads (inputs) value for string { clearcomment(); mvprintw(menrow,0,"%s ",string); echo(); getstr(string); noecho(); } void help() // print help screen { int c; clear(); printw("\nTEXTDRAW 0.2 (c) by Dieter Schoppitsch\n\n"); printw("c copy copy marked object to buffer\n"); printw("d delete delete marked object\n"); printw("e ellipse draw ellipse-object\n"); printw("h help this help page\n"); printw("l line draw line-object\n"); printw("m move move marked object\n"); printw("p print print to ascii-file 'print'\n"); printw("q, ESC exit exit (without saving!)\n"); printw("r rectangle draw rectangle-object\n"); printw("s save save file\n"); printw("t text draw text-object\n"); printw("v paste paste buffer\n"); printw("\n"); printw("position cursor with cursor keys\n"); printw("mark object at 'hot spot'\n"); printw("to load existing file: \n"); printw("try also: home, end, pgdn, pgup\n"); refresh(); c=getch(); } /* INIT */ void init() // sets initial values { int i,j; for(i=0;i<=maxrow;i++) for(j=0;j<=maxcol;j++) chart[i][j]=' '; } /* DRAW */ void drawtxt() // draws textobjects to chart-array { int i,j; for(i=0;i=0 && txt[i].x+j<=maxcol) chart[txt[i].y-j][txt[i].x+j]=txt[i].t[j]; } else if(txt[i].a=='v') { if(j+txt[i].y<=maxrow) chart[txt[i].y+j][txt[i].x]=txt[i].t[j]; } else if(txt[i].a=='d') { if(j+txt[i].y<=maxrow && j+txt[i].x<=maxcol) chart[txt[i].y+j][txt[i].x+j]=txt[i].t[j]; } else { if(j+txt[i].x<=maxcol) chart[txt[i].y][txt[i].x+j]=txt[i].t[j]; } } void drawlin() // draws line in chart-array { int i,j; float k,d; for(i=0;iabs(lin[i].y1-lin[i].y2)) { k=(float)(lin[i].y1-lin[i].y2)/(lin[i].x1-lin[i].x2); d=lin[i].y1-k*lin[i].x1; if(lin[i].x1rec[i].x1 && rec[i].y2>rec[i].y1) { for(j=rec[i].y1+1;j<=rec[i].y2;j++) { chart[j][rec[i].x1]='|'; chart[j][rec[i].x2]='|'; } for(j=rec[i].x1+1;j<=rec[i].x2-1;j++) { chart[rec[i].y1][j]='_'; chart[rec[i].y2][j]='_'; } } else if(rec[i].x2>rec[i].x1 && rec[i].y1>rec[i].y2) { for(j=rec[i].y2+1;j<=rec[i].y1;j++) { chart[j][rec[i].x1]='|'; chart[j][rec[i].x2]='|'; } for(j=rec[i].x1+1;j<=rec[i].x2-1;j++) { chart[rec[i].y1][j]='_'; chart[rec[i].y2][j]='_'; } } else if(rec[i].x1>rec[i].x2 && rec[i].y2>rec[i].y1) { for(j=rec[i].y1+1;j<=rec[i].y2;j++) { chart[j][rec[i].x1]='|'; chart[j][rec[i].x2]='|'; } for(j=rec[i].x2+1;j<=rec[i].x1-1;j++) { chart[rec[i].y1][j]='_'; chart[rec[i].y2][j]='_'; } } else { for(j=rec[i].y2+1;j<=rec[i].y1;j++) { chart[j][rec[i].x1]='|'; chart[j][rec[i].x2]='|'; } for(j=rec[i].x2+1;j<=rec[i].x1-1;j++) { chart[rec[i].y1][j]='_'; chart[rec[i].y2][j]='_'; } } } } void drawell() // draws ellipse in chart-array { int i,j; float a,b,s; for(i=0;iabs(ell[i].y1-ell[i].y2)) // y(x) { if(ell[i].x1ell[i].y2) for(j=ell[i].x1;j<=ell[i].x2;j++) { s=sqrt((1-(j-ell[i].x1-a)*(j-ell[i].x1-a)/a/a)*b*b); chart[ell[i].y1-round(b-s)][j]='*'; chart[ell[i].y1-round(b+s)][j]='*'; } else if(ell[i].x1>ell[i].x2 && ell[i].y1ell[i].y2) for(j=ell[i].y2;j<=ell[i].y1;j++) { s=sqrt((1-(j-ell[i].y2-b)*(j-ell[i].y2-b)/b/b)*a*a); chart[j][ell[i].x1+round(a-s)]='*'; chart[j][ell[i].x1+round(a+s)]='*'; } else if(ell[i].x1>ell[i].x2 && ell[i].y1=0) j--; chart[i][j+1]='\0'; } for(i=0;i<=maxrow;i++) fprintf(prnt,"%s\n",chart[i]); comment("file 'print' printed"); fclose(prnt); } int main(int argc, char *argv[]) /* MAIN */ { int c; initscr(); raw(); keypad(stdscr, TRUE); noecho(); getmaxyx(stdscr,maxrow,maxcol); maxrow-=2; maxcol-=1; menrow=maxrow+1; init(); if(argv[1]=='\0') // new file { filename="new"; comment("file 'new' opened - to open existing file: "); } else // open file { filename=argv[1]; load(); } draw(); curpos(); while((c = getch())!=ESC && c!='q' && c!='Q') // quit { switch(c) { case KEY_UP: // up y-=1; if(y<0) y=0; curpos(); break; case KEY_DOWN: // down y+=1; if(y>maxrow) y=maxrow; curpos(); break; case KEY_LEFT: // left x-=1; if(x<0) x=0; curpos(); break; case KEY_RIGHT: // right x+=1; if(x>maxcol) x=maxcol; curpos(); break; case KEY_HOME: // home x=0; curpos(); break; case KEY_END: // end x=maxcol; curpos(); break; case KEY_PPAGE: // pgup y=0; curpos(); break; case KEY_NPAGE: // pgdn y=maxrow; curpos(); break; case 'c': case 'C': // copy copy(); draw(); break; case 'd': case 'D': case DEL: // delete delete(); draw(); break; case 'e': case 'E': // ellipse ellinput(); draw(); break; case 'h': case 'H': // help help(); draw(); break; case 'l': case 'L': // line lineinput(); draw(); break; case 'm': case 'M': // move moving(); draw(); break; case 'p': case 'P': // print print(); draw(); break; case 'r': case 'R': // rectangle recinput(); draw(); break; case 's': case 'S': // save save(); draw(); break; case 't': case 'T': // text textinput(); draw(); break; case 'v': case 'V': // paste paste(); draw(); break; } } endwin(); return 0; } /* IDEAS: * user defineable keys * colors * white surface * mouse support * drop down menus * rotate/mirror object * group object * put object infront/behind * objects with/without frame/filled_color/pattern * object polygon * ascii-art-import (bitmap) * multi windows * presentation features (effects) * save as html */ textdraw-0.2+ds/readme0000644000000000000000000000243704171745134013511 0ustar rootrootTextdraw (td) is a small utility that allows do draw (ascii-based) line-, rectangle-, ellipse- and text-objects with copy/paste/move features. For me it completes existing console-based software to a 'textbased only office' and offers a simple and easy way to draw ascii graphics for documentations, presentations, mails and much more. Read the attached file 'help.txt' to see what's possible and how textdraw works. See also the help page of the program (key: 'h'). For compiling from source (td.c) you have to link ncurses and math - do it with the command: gcc td.c -lncurses -lm There are a lot of ideas for a newer version (i.e. colors, patterns, group/rotate/mirror objects, polygons, ascii-art-import) and the actual version seems to be stable (under 'normal use'). But as it fullfills all I need I don't intend to program a newer version. Feel free to improve this program under the conditions of the general GNU-license-agreement. Homepage of Textdraw: http://web.uta4you.at/shop/td/index.htm Send me comments, suggestions and bugs under: shop@uta4you.at Dieter Schoppitsch, July/2002 "an image says more than thousand words" BUGFIXES: 11/2002 (Version 0.2) Thanks to Rene Engelhard (and other guys from Debian) for fixing some bugs (unused variables, error handling, improved load-procedure).textdraw-0.2+ds/help.txt0000644000000000000000000000362707524310501014013 0ustar rootroot ______________________________________________________________________________ | _________ | | | | _____________ +___ +*** | | | OBJECTS | | | |___| * * | | |_________| | 'HOT SPOTS' | *** | | ___ \ |_____________| | | rectangle |___| \ / +---- +EXT | | \ / | | line ----- \ ******** / __________________ | | ** ** / | | | | text TEXT * TEXTDRAW *-------| PRINT ASCII-FILE |---- 'p' | | ** ** \ |__________________| | | *** ******** \ | | ellipse * * | \ e | | *** | \ t | | __________ \ s | | | | \ __________ a | | - help with 'h' | OTHER | | | p delete | | - exit with 'q' or ESC | FEATURES | | FEATURES |-------- | | - load file: |__________| |__________| c m | | pgup o o | | - fast moving: home end p v | | pgdn y e | |__________________________________Dieter Schoppitsch__________________________| textdraw-0.2+ds/help0000644000000000000000000000144307524310472013176 0ustar rootroot9 14 8 18 8 - 62 6 66 6 - 68 10 71 10 - 41 10 47 10 - 47 16 42 11 \ 35 13 35 15 | 24 5 27 8 \ 41 9 44 6 / 60 18 67 18 - 8 0 0 79 23 14 5 18 6 14 1 24 4 44 2 58 5 62 2 66 3 48 8 67 11 48 16 59 19 30 15 41 19 3 14 12 18 14 71 2 75 4 27 8 40 12 31 2 6 h 9 rectangle 2 8 h 4 line 2 10 h 4 text 2 13 h 7 ellipse 14 10 h 4 TEXT 16 3 h 7 OBJECTS 46 4 h 11 'HOT SPOTS' 71 6 h 4 TEXT 62 2 h 1 + 62 6 h 1 + 71 6 h 1 + 71 2 h 1 + 50 10 h 16 PRINT ASCII-FILE 71 19 d 4 move 68 19 v 4 copy 71 17 h 6 delete 68 17 u 5 paste 50 18 h 8 FEATURES 2 17 h 15 - help with 'h' 2 18 h 22 - exit with 'q' or ESC 2 19 h 22 - load file: 2 21 h 14 - fast moving: 23 20 h 4 pgup 23 22 h 4 pgdn 20 21 h 4 home 26 21 h 3 end 33 17 h 5 OTHER 32 18 h 8 FEATURES 30 10 h 8 TEXTDRAW 35 23 h 18 Dieter Schoppitsch 73 10 h 3 'p'