home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / ME22-OS2.ZIP / MACROS.ZIP / DRAW.M < prev    next >
Text File  |  1988-05-02  |  5KB  |  231 lines

  1. /*
  2. DRAW
  3. This macro provides the user with a simple line-drawing facility using the
  4. ASCII line drawing characters. When you press <ALT D>, you are prompted for 
  5. a choice of selecting the type of line drawing chars or going into drawing
  6. mode. You can select from three different styles of drawing characters -
  7. ASCII, single line or double line.
  8.  
  9. Once you are in drawing mode, you can use the cursor keypad to draw your
  10. box characters (keys 1,2,3,4,6,7,8,9). Pressing <ESC> will exit drawing
  11. mode.
  12. */
  13.  
  14. #define  UP       200
  15. #define  DOWN     208
  16. #define  LEFT     203
  17. #define  RIGHT    205
  18. #define  PGDN     209
  19. #define  PGUP     201
  20. #define  HOME     199
  21. #define  END      207
  22. #define  RETURN   10
  23. #define  ESC      27
  24. #define  ALT_D    160
  25.  
  26. int reached_eof;
  27.  
  28. string tl;
  29. string t;
  30. string tr;
  31. string r;
  32. string br;
  33. string b;
  34. string bl;
  35. string l;
  36.  
  37. init()
  38. {
  39.   tl = chr(218);
  40.   t  = chr(196);
  41.   tr = chr(191);
  42.   r  = chr(179);
  43.   br = chr(217);
  44.   b  = chr(196);
  45.   bl = chr(192);
  46.   l  = chr(179);
  47.   assign_key("draw_cmd", ALT_D);
  48. }
  49.  
  50.  
  51. draw_cmd()
  52. {
  53.   message("Draw cmd:  D)raw, T)ype_box");
  54.   key = get_tty_char();
  55.   if (key == 'd' || key == 'D')
  56.     draw();
  57.   else if (key == 't' || key == 'T')
  58.     type_box();
  59. }
  60.  
  61.  
  62. draw()
  63. {
  64.    int   key;
  65.                    
  66.    setprompt(2);
  67.    key = 0;
  68.    while (key != RETURN && key != ESC)
  69.    {
  70.       message(sprintf(" Draw Mode: Use numeric keypad to draw...ESC to quit      col: %d", currcol()));
  71.       key = get_tty_char();
  72.       if (key >= HOME && key <= PGDN)
  73.       {  
  74.          if (key == UP)
  75.          {
  76.             insert(t);
  77.             if (! is_eol()) 
  78.                delchar();
  79.          }
  80.          else if (key == DOWN)
  81.          {
  82.             insert(b);
  83.             if (! is_eol()) 
  84.                delchar();
  85.             left();
  86.             left();
  87.          }
  88.          else if (key == LEFT)
  89.          {
  90.             insert(l);
  91.             if (! is_eol()) 
  92.                delchar();
  93.             left();
  94.             up();
  95.          }
  96.          else if (key == RIGHT)
  97.          {
  98.             insert(r);
  99.             if (! is_eol()) 
  100.                delchar();
  101.             left();
  102.             if (!down())  appnd_line();
  103.          }
  104.          else if (key == PGDN)
  105.          {
  106.             insert(br);
  107.             if (! is_eol()) 
  108.                delchar();
  109.             left();
  110.             left();
  111.          }
  112.          else if (key == PGUP)
  113.          {
  114.             insert(tr);
  115.             if (! is_eol()) 
  116.                delchar();
  117.             left();
  118.             if (!down())  appnd_line();
  119.          }
  120.          else if (key == HOME)
  121.          {
  122.             insert(tl);
  123.             if (! is_eol()) 
  124.                delchar();
  125.          }
  126.          else if (key == END)
  127.          {
  128.             insert(bl);
  129.             if (! is_eol()) 
  130.                delchar();
  131.             left();
  132.             up();
  133.          }
  134.       }
  135.    }
  136.  
  137.    setprompt(0);
  138.    return(key);
  139. }
  140.  
  141.  
  142. /* posn_cursor() - this internal macro lets the user position cursor */
  143. posn_cursor(msg)
  144. string msg;
  145. {
  146.    int   key,
  147.          col;
  148.                    
  149.    key = 0;
  150.    while (key != RETURN && key != ESC)
  151.    {
  152.       message(sprintf(strcat(msg,"  col:  %d  line:  %d"),
  153.                                                  currcol(), currlinenum()));
  154.       key = get_tty_char();
  155.       if (key >= HOME && key <= PGDN)
  156.       {  
  157.          if (key == UP)
  158.             up();
  159.          else if (key == DOWN)
  160.          {
  161.             if (!down())
  162.               append_line();
  163.          }
  164.          else if (key == LEFT)
  165.             left();
  166.          else if (key == RIGHT)
  167.             right();
  168.          else if (key == PGDN)
  169.             nextscreen();
  170.          else if (key == PGUP)
  171.             prevscreen();
  172.          else if (key == HOME)
  173.             gobol();
  174.          else if (key == END)
  175.             goeol();
  176.       }
  177.    }
  178.    return(key);
  179. }
  180.  
  181.  
  182. type_box()
  183. {
  184.    message("Choose box type:  A)scii, D)ouble_line, S)ingle_line");
  185.    key = get_tty_char();
  186.  
  187.    if (key == 'a' || key == 'A')
  188.    {
  189.       tl = chr(45);
  190.       t  = chr(45);
  191.       tr = chr(45);
  192.       r  = chr(124);
  193.       br = chr(45);
  194.       b  = chr(45);
  195.       bl = chr(45);
  196.       l  = chr(124);
  197.    }
  198.    else if (key == 'd' || key == 'D')
  199.    {
  200.       tl = chr(201);
  201.       t  = chr(205);
  202.       tr = chr(187);
  203.       r  = chr(186);
  204.       br = chr(188);
  205.       b  = chr(205);
  206.       bl = chr(200);
  207.       l  = chr(186);
  208.    }
  209.    else if (key == 's' || key == 'S')
  210.    {
  211.       tl = chr(218);
  212.       t  = chr(196);
  213.       tr = chr(191);
  214.       r  = chr(179);
  215.       br = chr(217);
  216.       b  = chr(196);
  217.       bl = chr(192);
  218.       l  = chr(179);
  219.    }
  220. }
  221.  
  222.  
  223. appnd_line()
  224. {
  225.   col = currcol();
  226.   goeol();
  227.   insert("\n");
  228.   setcol(col);
  229. }
  230.  
  231.