home *** CD-ROM | disk | FTP | other *** search
/ Black Box 4 / BlackBox.cdr / editors / tde150.arj / CFGCOLOR.C < prev    next >
C/C++ Source or Header  |  1992-04-01  |  12KB  |  464 lines

  1. /*
  2.  * Customize the colors in tde.
  3.  *
  4.  * Author:        Frank Davis
  5.  * Date:          July 21, 1991
  6.  * Compiler:      MSC 6.0a and QuickC 2.51
  7.  *
  8.  * This program is released into the public domain.  You may distribute
  9.  * it freely, Frank Davis
  10.  */
  11.  
  12.  
  13. /********    EXTREMELY IMPORTANT   ************/
  14. /*
  15.  * If you modify tde, it is your responsibility to find the offset of
  16.  * "static int colors" in function "hw_initialize" in file "main.c" in your
  17.  * new executable, tde.exe.
  18.  *
  19.  * If you don't change the default colors, search for the following string (a
  20.  * hexadecimal integer array) in your new executable file:
  21.  *
  22.  *  7000 0700
  23.  *
  24.  * Then, replace COLOR_OFFSET with your new one and recompile tdecfg
  25.  * with the new offset.
  26.  */
  27.  
  28. #define  COLOR_OFFSET   76502l
  29.  
  30. /*******     EXTREMELY IMPORTANT   ************/
  31.  
  32.  
  33. #include <bios.h>
  34. #include <dos.h>
  35. #include <stdlib.h>
  36. #include <stdio.h>
  37. #include <string.h>
  38.  
  39. #include "tdecfg.h"
  40. #include "cfgcolor.h"
  41.  
  42.  
  43. /*
  44.  * Default color settings.  Incidentally, I'm color blind (mild red-green) and
  45.  * the default colors look fine to me. ;*)
  46.  */
  47. static int colors[2][12] = {
  48.    { HERC_REVERSE, HERC_NORMAL, HERC_REVERSE, HERC_REVERSE, HERC_HIGH,
  49.      HERC_NORMAL, HERC_NORMAL, HERC_HIGH, HERC_HIGH },
  50.    { COLOR_HEAD, COLOR_TEXT, COLOR_MODE, COLOR_BLOCK, COLOR_MESSAGE,
  51.      COLOR_HELP, COLOR_WRAP, COLOR_EOF, COLOR_CURL }
  52. };
  53.  
  54. extern struct vcfg cfg;         /* video stuff */
  55. extern FILE *tde_exe;           /* FILE pointer to tde.exe */
  56.  
  57. static int temp_colors[2][12];  /* play around with colors in this array */
  58. static int index;               /* 0 = Monochrome colors, 1 = color colors */
  59.  
  60.  
  61. /*
  62.  * Name:    tdecolor
  63.  * Date:    July 21, 1991
  64.  * Notes:   Strategy is fairly straight forward -  1) initialize all the
  65.  *          variables  2) show the user a color sample  3) make the changes
  66.  *          permanent if desired.
  67.  */
  68. void tdecolor( void )
  69. {
  70.    initialize_color( );
  71.    show_init_sample( );
  72.    change_colors( );
  73. }
  74.  
  75.  
  76. /*
  77.  * Name:    initialize
  78.  * Date:    July 21, 1991
  79.  * Notes:   Set up all of the global variables.
  80.  */
  81. void initialize_color( void )
  82. {
  83. int i, j;
  84.  
  85.    fseek( tde_exe, COLOR_OFFSET, SEEK_SET );
  86.    fread( (void *)temp_colors, sizeof( temp_colors ), 1, tde_exe );
  87.  
  88.    if (cfg.color == FALSE)
  89.       index = 0;
  90.    else
  91.       index = 1;
  92.  
  93.    fields[0].color = temp_colors[index][HELP];
  94.    fields[1].color = temp_colors[index][HEAD];
  95.    fields[2].color = temp_colors[index][TEXT];
  96.    fields[3].color = temp_colors[index][CURL];
  97.    fields[4].color = temp_colors[index][WARNING];
  98.    fields[5].color = temp_colors[index][MODE];
  99.    fields[6].color = temp_colors[index][WRAP];
  100.    fields[7].color = temp_colors[index][CEOF];
  101.    fields[8].color = temp_colors[index][RULER];
  102.    fields[9].color = temp_colors[index][RULER_PTR];
  103.    fields[10].color = temp_colors[index][BLOCK];
  104.    fields[11].color = temp_colors[index][HILITED_FILE];
  105.  
  106.    fields[0].show_me = show_help_color;
  107.    fields[1].show_me = show_fileheader_color;
  108.    fields[2].show_me = show_text_color;
  109.    fields[3].show_me = show_curl_color;
  110.    fields[4].show_me = show_warning_color;
  111.    fields[5].show_me = show_mode_color;
  112.    fields[6].show_me = show_wrapped_color;
  113.    fields[7].show_me = show_eof_color;
  114.    fields[8].show_me = show_ruler_color;
  115.    fields[9].show_me = show_rulerptr_color;
  116.    fields[10].show_me = show_block_color;
  117.    fields[11].show_me = show_hilitedfile_color;
  118. }
  119.  
  120.  
  121. /*
  122.  * Name:    show_init_sample
  123.  * Date:    July 21, 1991
  124.  * Notes:   Draw all of the sample screens.
  125.  */
  126. void show_init_sample( void )
  127. {
  128. char *sample;
  129. int line, i, j, k, l;
  130. char temp[6], num[6];
  131. char far *p;
  132.  
  133.    xygoto( -1, -1 );
  134.    sample = sample_screen[0];
  135.    for (line=0; sample != NULL; ) {
  136.       s_output( (char far *)sample, line, 0, 7 );
  137.       sample = sample_screen[++line];
  138.    }
  139.    for (i=0; i<12; i++)
  140.       (*fields[i].show_me)();
  141.    sample = field_screen[0];
  142.    for (line=12, i=1; sample != NULL; line++,i++) {
  143.       s_output( (char far *)sample, line, 0, 7 );
  144.       sample = field_screen[i];
  145.    }
  146.    p = (char far *)temp;
  147.    for (i=0,k=0,line=17; i<8; i++, line++) {
  148.       for (j=0,l=0; j<16; j++, k++,l+=5) {
  149.          color_number( temp, k );
  150.          s_output( p, line, l, k );
  151.       }
  152.    }
  153.    for (i=0; i<12; i++) {
  154.       color_number( temp, fields[i].color );
  155.       s_output( p, fields[i].line, fields[i].col, fields[i].color );
  156.    }
  157. }
  158.  
  159.  
  160. /*
  161.  * Name:    color_number
  162.  * Date:    July 21, 1991
  163.  * Passed:  dest:  buffer to store the color sample
  164.  *          num:   attribute number
  165.  * Notes:   Show the use what the foreground and background colors look like.
  166.  */
  167. void color_number( char *dest, int num )
  168. {
  169. int i, j, k;
  170. char temp[6];
  171.  
  172.    strcpy( dest, "[   ]" );
  173.    itoa( num, temp, 10 );
  174.    i = strlen( temp );
  175.    j = 4 - i;
  176.    for (k=0; i > 0; i--,j++, k++)
  177.       dest[j] = temp[k];
  178. }
  179.  
  180.  
  181. /*
  182.  * Name:    current_color_number
  183.  * Date:    July 21, 1991
  184.  * Passed:  dest:  buffer to store the color sample
  185.  *          num:   attribute number
  186.  * Notes:   Put '*' around the sample color to give the user an idea of where
  187.  *          the current field is.
  188.  */
  189. void current_color_number( char *dest, int num )
  190. {
  191. int i, j, k;
  192. char temp[6];
  193.  
  194.    strcpy( dest, "*   *" );
  195.    itoa( num, temp, 10 );
  196.    i = strlen( temp );
  197.    j = 4 - i;
  198.    for (k=0; i > 0; i--,j++, k++)
  199.       dest[j] = temp[k];
  200. }
  201.  
  202.  
  203. /*
  204.  * Name:    show_help_color
  205.  * Date:    July 21, 1991
  206.  */
  207. void show_help_color( void )
  208. {
  209. int color;
  210. int line, len;
  211.  
  212.    color = fields[0].color;
  213.    for (line=1; line <10; line++)
  214.       hlight_line( 1, line, 37, color );
  215.    hlight_line( 1,  10, 13, color );
  216.    hlight_line( 25, 10, 13, color );
  217. }
  218.  
  219.  
  220. /*
  221.  * Name:    show_fileheader_color
  222.  * Date:    July 21, 1991
  223.  */
  224. void show_fileheader_color( void )
  225. {
  226.    hlight_line( 41, 1, 38, fields[1].color );
  227. }
  228.  
  229.  
  230. /*
  231.  * Name:    show_text_color
  232.  * Date:    July 21, 1991
  233.  */
  234. void show_text_color( void )
  235. {
  236. int color;
  237.  
  238.    color = fields[2].color;
  239.    hlight_line( 41, 3, 38, color );
  240.    hlight_line( 41, 5, 38, color );
  241. }
  242.  
  243.  
  244. /*
  245.  * Name:    show_curl_color
  246.  * Date:    July 21, 1991
  247.  */
  248. void show_curl_color( void )
  249. {
  250.    hlight_line( 41, 4, 38, fields[3].color );
  251. }
  252.  
  253.  
  254. /*
  255.  * Name:    show_warning_color
  256.  * Date:    July 21, 1991
  257.  */
  258. void show_warning_color( void )
  259. {
  260.    hlight_line( 41, 9, 38, fields[4].color );
  261. }
  262.  
  263.  
  264. /*
  265.  * Name:    show_mode_color
  266.  * Date:    July 21, 1991
  267.  */
  268. void show_mode_color( void )
  269. {
  270.    hlight_line( 41, 10, 26, fields[5].color );
  271. }
  272.  
  273.  
  274. /*
  275.  * Name:    show_wrapped_color
  276.  * Date:    July 21, 1991
  277.  */
  278. void show_wrapped_color( void )
  279. {
  280.    hlight_line( 67, 10, 12, fields[6].color );
  281. }
  282.  
  283.  
  284. /*
  285.  * Name:    show_eof_color
  286.  * Date:    July 21, 1991
  287.  */
  288. void show_eof_color( void )
  289. {
  290.    hlight_line( 41, 8, 38, fields[7].color );
  291. }
  292.  
  293.  
  294. /*
  295.  * Name:    show_ruler_color
  296.  * Date:    July 21, 1991
  297.  */
  298. void show_ruler_color( void )
  299. {
  300.    hlight_line( 41, 2, 21, fields[8].color );
  301.    hlight_line( 63, 2, 16, fields[8].color );
  302. }
  303.  
  304.  
  305. /*
  306.  * Name:    show_rulerptr_color
  307.  * Date:    July 21, 1991
  308.  */
  309. void show_rulerptr_color( void )
  310. {
  311.    hlight_line( 62, 2, 1, fields[9].color );
  312. }
  313.  
  314.  
  315. /*
  316.  * Name:    show_block_color
  317.  * Date:    July 21, 1991
  318.  */
  319. void show_block_color( void )
  320. {
  321. int color;
  322. int line;
  323.  
  324.    color = fields[10].color;
  325.    for (line=6; line <8; line++)
  326.       hlight_line( 41, line, 38, color );
  327. }
  328.  
  329.  
  330. /*
  331.  * Name:    show_hilitedfile_color
  332.  * Date:    July 21, 1991
  333.  */
  334. void show_hilitedfile_color( void )
  335. {
  336.    hlight_line( 14, 10, 11, fields[11].color );
  337. }
  338.  
  339.  
  340. /*
  341.  * Name:    change_colors
  342.  * Date:    July 21, 1991
  343.  * Notes:   Real workhorse function of the utility.  Get a key and then
  344.  *          figure out what to do with it.
  345.  */
  346. void change_colors( void )
  347. {
  348. int c;
  349. int area;
  350. int color;
  351. int new_color;
  352. int i;
  353. char temp[6];
  354. char far *p;
  355.  
  356.    p = (char far *)temp;
  357.    area = 0;
  358.    current_color_number( temp, fields[area].color );
  359.    s_output( p, fields[area].line, fields[area].col, fields[area].color );
  360.    xygoto( fields[area].col+3, fields[area].line );
  361.    for (c=0; c != F3  &&  c != F10  &&  c != ESC;) {
  362.       new_color = FALSE;
  363.       c = getkey( );
  364.       switch (c) {
  365.          case RTURN :
  366.          case DOWN  :
  367.             color_number( temp, fields[area].color );
  368.             s_output( p, fields[area].line, fields[area].col, fields[area].color );
  369.             ++area;
  370.             if (area > 11)
  371.                area = 0;
  372.             current_color_number( temp, fields[area].color );
  373.             s_output( p, fields[area].line, fields[area].col, fields[area].color );
  374.             xygoto( fields[area].col+3, fields[area].line );
  375.             break;
  376.          case UP    :
  377.             color_number( temp, fields[area].color );
  378.             s_output( p, fields[area].line, fields[area].col, fields[area].color );
  379.             --area;
  380.             if (area < 0)
  381.                area = 11;
  382.             current_color_number( temp, fields[area].color );
  383.             s_output( p, fields[area].line, fields[area].col, fields[area].color );
  384.             xygoto( fields[area].col+3, fields[area].line );
  385.             break;
  386.          case LEFT :
  387.             --fields[area].color;
  388.             if (fields[area].color < 0)
  389.                fields[area].color = 127;
  390.             new_color = TRUE;
  391.             break;
  392.          case RIGHT :
  393.             ++fields[area].color;
  394.             if (fields[area].color > 127)
  395.                fields[area].color = 0;
  396.             new_color = TRUE;
  397.             break;
  398.          case PGUP :
  399.             fields[area].color -= 16;
  400.             if (fields[area].color < 0)
  401.                fields[area].color = (fields[area].color & 0x000f) + 0x70;
  402.             new_color = TRUE;
  403.             break;
  404.          case PGDN :
  405.             fields[area].color += 16;
  406.             if (fields[area].color > 127)
  407.                fields[area].color = fields[area].color & 0x000f;
  408.             new_color = TRUE;
  409.             break;
  410.          case F2 :
  411.  
  412.             /*
  413.              * get back the original colors and display
  414.              */
  415.             fields[0].color = colors[index][HELP];
  416.             fields[1].color = colors[index][HEAD];
  417.             fields[2].color = colors[index][TEXT];
  418.             fields[3].color = colors[index][CURL];
  419.             fields[4].color = colors[index][WARNING];
  420.             fields[5].color = colors[index][MODE];
  421.             fields[6].color = colors[index][WRAP];
  422.             fields[7].color = colors[index][CEOF];
  423.             fields[8].color = colors[index][RULER];
  424.             fields[9].color = colors[index][RULER_PTR];
  425.             fields[10].color = colors[index][BLOCK];
  426.             fields[11].color = colors[index][HILITED_FILE];
  427.             for (i=0; i<12; i++) {
  428.                color_number( temp, fields[i].color );
  429.                s_output( p, fields[i].line, fields[i].col, fields[i].color );
  430.                (*fields[i].show_me)();
  431.             }
  432.             current_color_number( temp, fields[area].color );
  433.             s_output( p, fields[area].line, fields[area].col, fields[area].color );
  434.             break;
  435.       }
  436.       if (new_color) {
  437.          current_color_number( temp, fields[area].color );
  438.          s_output( p, fields[area].line, fields[area].col, fields[area].color );
  439.          (*fields[area].show_me)();
  440.       }
  441.    }
  442.  
  443.    /*
  444.     * write changes to "tde.exe" if user presses F10.
  445.     */
  446.    if (c == F10) {
  447.       temp_colors[index][HELP]         = fields[0].color;
  448.       temp_colors[index][HEAD]         = fields[1].color;
  449.       temp_colors[index][TEXT]         = fields[2].color;
  450.       temp_colors[index][CURL]         = fields[3].color;
  451.       temp_colors[index][WARNING]      = fields[4].color;
  452.       temp_colors[index][MODE]         = fields[5].color;
  453.       temp_colors[index][WRAP]         = fields[6].color;
  454.       temp_colors[index][CEOF]         = fields[7].color;
  455.       temp_colors[index][RULER]        = fields[8].color;
  456.       temp_colors[index][RULER_PTR]    = fields[9].color;
  457.       temp_colors[index][BLOCK]        = fields[10].color;
  458.       temp_colors[index][HILITED_FILE] = fields[11].color;
  459.       fseek( tde_exe, COLOR_OFFSET, SEEK_SET );
  460.       fwrite( (void *)temp_colors, sizeof( temp_colors ), 1, tde_exe );
  461.    }
  462.    cls( );
  463. }
  464.