home *** CD-ROM | disk | FTP | other *** search
/ Power Programming / powerprogramming1994.iso / progtool / ega / egapaint.arc / LSTYLE.C < prev    next >
Text File  |  1988-05-26  |  5KB  |  180 lines

  1. /**************************************************************************
  2.  *                                                                        *
  3.  *      Utility to change the line style.  Originally set up to           *
  4.  *      use turbo's internal settings, but I had to modify it when I      *
  5.  *      went to the exclusive OR mode custom lines for the grid           *
  6.  *      function. It still looks real pretty.  All that needs to be done  *
  7.  *      is to set a mask and use it in the line draw routine              *
  8.  *                                                                        *
  9.  **************************************************************************/
  10.  
  11. #define FALSE 0
  12. #define TRUE  1
  13.  
  14. #include <dos.h>
  15. #include <bios.h>
  16. #include <conio.h>
  17. #include <graphics.h>
  18. #include <alloc.h>
  19. #include <stdlib.h>
  20. #include <stdarg.h>
  21.  
  22. extern int bkcolor, cc, maxx, maxy;
  23. extern unsigned scr_size[2];
  24. extern void *scr_buffer[2];
  25. extern int width;
  26. extern int gprintf( int xx, int yy, char *fmt, ... );
  27.  
  28. int lstyle(void)
  29. {
  30.     union {
  31.         int i;
  32.         unsigned char c[2];
  33.     } key;
  34.  
  35.     struct {
  36.         int type;
  37.         int pattern;
  38.     } style[25] = {
  39.         {0, 0},
  40.         {0, 0},
  41.         {1, 0},
  42.         {2, 0},
  43.         {3, 0},
  44.         {4, 0xfffe},
  45.         {4, 0xfffc},
  46.         {4, 0xfff8},
  47.         {4, 0xfff0},
  48.         {4, 0xffe0},
  49.         {4, 0xffc0},
  50.         {4, 0xff80},
  51.         {4, 0xff00},
  52.         {4, 0xfe00},
  53.         {4, 0xfc00},
  54.         {4, 0xf800},
  55.         {4, 0xf000},
  56.         {4, 0xe000},
  57.         {4, 0xc000},
  58.         {4, 0x8000},
  59.         {4, 0x1111},
  60.         {4, 0x3333},
  61.         {4, 0x5555},
  62.         {4, 0x7777},
  63.         {4, 0x9999}
  64.     };
  65.  
  66.  
  67.     struct textsettingstype oldtext;
  68.     struct linesettingstype oldline;
  69.  
  70.     register int i = 10;
  71.     int title_x, title_y;
  72.     int hite, wide, max_i;
  73.     int ret_flag = 0;
  74.     void *text_buf;
  75.     int index = 1;
  76.  
  77.     gettextsettings(&oldtext);
  78.     setusercharsize(1, 1, 7, 8);
  79.     settextstyle(SMALL_FONT, HORIZ_DIR, USER_CHAR_SIZE);
  80.     hite = textheight("H");
  81.     wide = textwidth("H");
  82.  
  83.     text_buf = malloc(hite*320);
  84.  
  85.     /* save the screen */
  86.  
  87.     scr_size[0] = imagesize(0, 0, maxx, ((maxy+1)/2)-1);
  88.     scr_buffer[0] = malloc(scr_size[0]);
  89.     if(scr_buffer[0] == NULL) {
  90.         free(scr_buffer[0]);
  91.         return TRUE;
  92.     }
  93.     getimage(0, 0, maxx, ((maxy+1)/2)-1, scr_buffer[0]);
  94.  
  95.     scr_size[1] = imagesize(0, (maxy+1)/2, maxx, maxy);
  96.     scr_buffer[1] = malloc(scr_size[1]);
  97.     if(scr_buffer[1] == NULL) {
  98.         free(scr_buffer[0]);
  99.         free(scr_buffer[1]);
  100.         return TRUE;
  101.     }
  102.     getimage(0, (maxy+1)/2, maxx, maxy, scr_buffer[1]);
  103.  
  104.     setbkcolor(BLACK);
  105.     setcolor(YELLOW);
  106.     clearviewport();
  107.  
  108.     for(index = 1; index < 25; index++) {
  109.         gprintf(5, i, "%d ",index);
  110.         setlinestyle(style[index].type, style[index].pattern, width);
  111.         line(5*wide, i+4, 300, i+4);
  112.         i += hite;
  113.     }
  114.  
  115.     /* indicate center line */
  116.  
  117.     outtextxy(310, (hite*2)+ 8, "C");
  118.     outtextxy(313, (hite*2)+12, "L");
  119.  
  120.     max_i = (i/hite)-2;
  121.     i = 300;
  122.     outtextxy(170, i, "           Point to style with arrow keys");
  123.     i += hite+4;
  124.     outtextxy(170, i, "           Hit <ESC> to select and return");
  125.  
  126.     i = 0;
  127.     getimage(0, (i*hite)+11, (wide*3)+7, ((i+1)*hite)+11, text_buf);
  128.     putimage(0, (i*hite)+11, text_buf, NOT_PUT);
  129.  
  130.     while(!ret_flag) {
  131.         if(bioskey(1)) {
  132.             key.i = bioskey(0);
  133.             if(key.c[0] == 0x1b) {
  134.                 ret_flag = 1;
  135.                 setlinestyle(style[i+1].type, style[i+1].pattern, width);
  136.             } else {
  137.  
  138.                 /* only use the cursor --- not the mouse  */
  139.  
  140.                 if(!key.c[0]) {
  141.                      if(key.c[1] == 72) {        /* up  */
  142.                         getimage(0, (i*hite)+11, (wide*3)+7, ((i+1)*hite)+11, text_buf);
  143.                         putimage(0, (i*hite)+11, text_buf, NOT_PUT); /* renew the old */
  144.                         i -= 1;
  145.                         if(i < 0) i = 0;
  146.                         getimage(0, (i*hite)+11, (wide*3)+7, ((i+1)*hite)+11, text_buf);
  147.                         putimage(0, (i*hite)+11, text_buf, NOT_PUT);
  148.                     }
  149.                      if(key.c[1] == 80) {        /* down  */
  150.                         getimage(0, (i*hite)+11, (wide*3)+7, ((i+1)*hite)+11, text_buf);
  151.                         putimage(0, (i*hite)+11, text_buf, NOT_PUT); /* renew th old */
  152.                         i += 1;
  153.                         if(i >= max_i) i = max_i;
  154.                         getimage(0, (i*hite)+11, (wide*3)+7, ((i+1)*hite)+11, text_buf);
  155.                         putimage(0, (i*hite)+11, text_buf, NOT_PUT);
  156.                     }
  157.  
  158.                 }
  159.             }
  160.         }
  161.  
  162.     }
  163.     setbkcolor(bkcolor);
  164.     clearviewport();
  165.     setcolor(cc);
  166.     settextjustify(oldtext.horiz, oldtext.vert);
  167.     settextstyle(oldtext.font, oldtext.direction, oldtext.charsize);
  168.  
  169.     /* retun the original picture, and free the buffers  */
  170.  
  171.     putimage(0, 0, scr_buffer[0], COPY_PUT);
  172.     putimage(0, (maxy+1)/2, scr_buffer[1], COPY_PUT);
  173.      free(scr_buffer[0]);
  174.     free(scr_buffer[1]);
  175.      free(text_buf);
  176.  
  177.     return FALSE;
  178. }
  179.  
  180.