home *** CD-ROM | disk | FTP | other *** search
- /*
- * lemmain.c - little editor for mice and other furry rodents (aka lemming)
- *
- * copyright (c) by Alan W. Paeth, 1987. All rights reserved.
- */
-
- #include "lem.h"
-
- main(argc, argv)
- char **argv;
- {
- int x, y, xup, yup, mup;
- int event, near, drag, dragdist;
- char ch;
-
- startup(argc, argv);
-
- while(1)
- {
- event = getevent(&x, &y, &xup, &yup, &ch);
- if (event != NOEVT) msgclear();
- switch(event)
- {
- case NOEVT: idle(); break;
- case ALPHA: charadd(line, ch); break;
- case CNTRL: switch(ch)
- {
- case C(Q): if (quitconfirm()) break;
- case C(A): all(SELECT, 0); break;
- case C(B): remake(BOX); break;
- case C(C): copysel(); break;
- case C(D): objcompress(); all(DELETE, 0); undo=UNDODEL; break;
- case C(E): remake(ELLI); break;
- case C(F): forceattr(); break;
- case C(G): addgroup(); break;
- case '\177': /* <DEL> */
- case C(H): chardel(line,1); break; /* <BS> */
- case C(I): cycleselect(); markdelete(); break; /* <TAB> */
- case C(J): /* <LF>, */
- case C(M): if (markon) stringadd(); break; /* <CR> */
- /* case C(K): curveify(); break; */
- case C(L): redraw(); break;
- case C(N): all(DESELECT, 0); break;
- case C(O): writepic(); break;
- case C(P): removegroup(); break;
- case C(R): readfile(); break;
- case C(S): specialfunc(); break;
- case C(T): tickset(); break;
- case C(U): undocmd(); break;
- case C(V): remake(LINE); break;
- case C(W): writefile(); break;
- case C(X): cutlines(); break;
- case C([): all(DESELECT, 0); markdelete(); break; /* <ESC> */
- case C(^): help(); break; /* ^^ */
- default: break;
- } break;
- case MOUSE: markobj = objnearany(x, y);
- near = markon && (dist(x, y, markx, marky) < MARKTOL);
- dragdist = near ? (anysel ? 0 : MARKTOL) : DRAGTOL;
- drag = dist(x,y,xup,yup) > dragdist;
- if (markobj) objectalign(markobj, &x, &y); else spacealign(&x, &y);
- if (drag) /* drag stuff */
- {
- if (near)
- {
- markhide(); /* for cleaner update */
- mup = objnearany(xup, yup);
- if (mup && (mup != markobj)) objectalign(mup, &xup, &yup);
- else spacealign(&xup, &yup);
- if (anysel) moveselect(xup-markx, yup-marky);
- else if (markobj) tugunselect(markx, marky, xup, yup);
- markupdate(xup, yup);
- }
- else rectselect(x, y, xup, yup);
- }
- else /* draw (move mark) cases */
- {
- if (near) markdelete();
- else
- {
- markhide(); /* for cleaner update */
- if (markon && !anysel) lineadd(markx, marky, x, y);
- markupdate(x, y);
- }
- }
- break;
- }
- }
- }
-