home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 12 / CD_ASCQ_12_0294.iso / vrac / pclcjs.zip / PICKCOLR.C < prev    next >
C/C++ Source or Header  |  1992-10-02  |  2KB  |  92 lines

  1. #include <bios.h>
  2. #include <conio.h>
  3.  
  4. /* pick_color function Copyright 1992 by Tay-Jee Software
  5.  
  6. This function presents a 16 by 8 character color selection chart
  7. on the center of the screen.  The user positions the cursor over
  8. a desired color combination and presses enter to select that color.
  9. The decimal value of the selected attribute is returned.  Pressing
  10. escape aborts the function with a return value of -1.  Screen
  11. maintenance is left to the user (i.e., color display chart remains
  12. on screen after function exit).                                   */
  13.  
  14.  
  15.  
  16. int pick_color()
  17.  
  18. {
  19.     /* Define local variables */
  20.     int row, column, input=0;
  21.     
  22.     /* Draw color chart on the screen */
  23.     for (row=8;row<16;row++) {
  24.         for (column=32;column<48;column++) {
  25.             poscurs(row,column);
  26.             writechs(7,(row-8)*16+(47-column),1);
  27.         }
  28.     }
  29.     
  30.     /* Initialize flashing cursor position */
  31.     row=8;
  32.     column=32;
  33.     poscurs(row,column);
  34.     writechs(15,row*16+47-column,1);
  35.     
  36.     /* Main input loop */
  37.     while (input != 13 && input != 27) {
  38.  
  39.         input=getch();
  40.         
  41.         /* Check for extended keypress */
  42.         if (input==0)
  43.             input=300+getch();
  44.     
  45.         /* Restore normal cursor */
  46.         poscurs(row,column);
  47.         writechs(7,(row-8)*16+47-column,1);
  48.     
  49.         /* Increment/decrement row or cursor position */
  50.         switch (input) {
  51.             
  52.             case 372: {  /* Cursor up */
  53.                 row--;
  54.             }
  55.             break;
  56.             case 375: {  /* Cursor left */
  57.                 column--;
  58.             }
  59.             break;
  60.             case 377: {  /* Cursor right */
  61.                 column++;
  62.             }
  63.             break;
  64.             case 380: {  /* Cursor down */
  65.                 row++;
  66.             }
  67.             break;
  68.             
  69.         }
  70.         
  71.         /* Check for "wraparound" */
  72.         if (row>15)
  73.             row=8;
  74.         else if (row<8)
  75.             row=15;
  76.         if (column>47)
  77.             column=32;
  78.         else if (column<32)
  79.             column=47;
  80.         
  81.         /* Draw new flashing cursor */
  82.         poscurs(row,column);
  83.         writechs(15,row*16+47-column,1);
  84.     }
  85.     
  86.     if (input==27)
  87.         return -1;
  88.     else
  89.         return (row-8)*16+47-column;
  90.     
  91. }
  92.