home *** CD-ROM | disk | FTP | other *** search
/ Best Objectech Shareware Selections / UNTITLED.iso / boss / word / text / 024 / cfgcolor.c < prev    next >
C/C++ Source or Header  |  1993-06-04  |  15KB  |  532 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. /*******     EXTREMELY IMPORTANT   ************/
  28.  
  29.  
  30. #include <bios.h>
  31. #include <dos.h>
  32. #include <stdlib.h>
  33. #include <stdio.h>
  34. #include <string.h>
  35.  
  36. #include "tdecfg.h"
  37. #include "cfgcolor.h"
  38.  
  39.  
  40. /*
  41.  * Default color settings.  Incidentally, I'm color blind (mild red-green) and
  42.  * the default colors look fine to me.
  43.  */
  44. COLORS colour = {
  45.    "$colors",
  46.    { { HERC_REVERSE, HERC_NORMAL, HERC_UNDER, HERC_REVERSE, HERC_REVERSE,
  47.      HERC_HIGH, HERC_NORMAL, HERC_NORMAL, HERC_HIGH, HERC_HIGH, HERC_HIGH,
  48.      HERC_REVERSE, HERC_REVERSE, HERC_NORMAL },
  49.    { COLOR_HEAD, COLOR_TEXT, COLOR_DIRTY, COLOR_MODE, COLOR_BLOCK,
  50.      COLOR_MESSAGE, COLOR_HELP, COLOR_WRAP, COLOR_EOF, COLOR_CURL, COLOR_RULER,
  51.      COLOR_POINTER, COLOR_TEXT, COLOR_OVRS } }
  52. };
  53.  
  54.  
  55. extern struct vcfg cfg;         /* video stuff */
  56. extern FILE *tde_exe;           /* FILE pointer to tde.exe */
  57. extern long color_offset;
  58.  
  59. COLORS temp_colours;            /* play around with colors in this array */
  60. static int index;               /* 0 = Monochrome colors, 1 = color colors */
  61.  
  62.  
  63. /*
  64.  * Name:    tdecolor
  65.  * Date:    July 21, 1991
  66.  * Notes:   Strategy is fairly straight forward -  1) initialize all the
  67.  *          variables  2) show the user a color sample  3) make the changes
  68.  *          permanent if desired.
  69.  */
  70. void tdecolor( void )
  71. {
  72.    initialize_color( );
  73.    show_init_sample( );
  74.    change_colors( );
  75.    restore_overscan( cfg.overscan );
  76. }
  77.  
  78.  
  79. /*
  80.  * Name:    initialize
  81.  * Date:    July 21, 1991
  82.  * Notes:   Set up all of the global variables.
  83.  */
  84. void initialize_color( void )
  85. {
  86.  
  87.    fseek( tde_exe, color_offset, SEEK_SET );
  88.    fread( (void *)&temp_colours, sizeof( COLORS ), 1, tde_exe );
  89.  
  90.    if (cfg.color == FALSE)
  91.       index = 0;
  92.    else
  93.       index = 1;
  94.  
  95.    fields[0].color = temp_colours.clr[index][HELP];
  96.    fields[1].color = temp_colours.clr[index][HEAD];
  97.    fields[2].color = temp_colours.clr[index][TEXT];
  98.    fields[3].color = temp_colours.clr[index][CURL];
  99.    fields[4].color = temp_colours.clr[index][DIRTY];
  100.    fields[5].color = temp_colours.clr[index][WARNING];
  101.    fields[6].color = temp_colours.clr[index][MODE];
  102.    fields[7].color = temp_colours.clr[index][WRAP];
  103.    fields[8].color = temp_colours.clr[index][CEOF];
  104.    fields[9].color = temp_colours.clr[index][OVERSCAN];
  105.    fields[10].color = temp_colours.clr[index][RULER];
  106.    fields[11].color = temp_colours.clr[index][RULER_PTR];
  107.    fields[12].color = temp_colours.clr[index][BLOCK];
  108.    fields[13].color = temp_colours.clr[index][HILITED_FILE];
  109.  
  110.    fields[0].show_me = show_help_color;
  111.    fields[1].show_me = show_fileheader_color;
  112.    fields[2].show_me = show_text_color;
  113.    fields[3].show_me = show_curl_color;
  114.    fields[4].show_me = show_dirty_color;
  115.    fields[5].show_me = show_warning_color;
  116.    fields[6].show_me = show_mode_color;
  117.    fields[7].show_me = show_wrapped_color;
  118.    fields[8].show_me = show_eof_color;
  119.    fields[9].show_me = show_overscan_color;
  120.    fields[10].show_me = show_ruler_color;
  121.    fields[11].show_me = show_rulerptr_color;
  122.    fields[12].show_me = show_block_color;
  123.    fields[13].show_me = show_hilitedfile_color;
  124. }
  125.  
  126.  
  127. /*
  128.  * Name:    restore_overscan
  129.  * Date:    April 1, 1993
  130.  */
  131. void restore_overscan( int overscan )
  132. {
  133.    ASSEMBLE {
  134.         mov     ah, 0x0b                /* function 0x0b */
  135.         mov     bl, BYTE PTR overscan   /* get new overscan color */
  136.         xor     bh, bh
  137.         push    bp
  138.         int     VIDEO_INT               /* video interrupt = 10h */
  139.         pop     bp
  140.    }
  141. }
  142.  
  143.  
  144. /*
  145.  * Name:    show_init_sample
  146.  * Date:    July 21, 1991
  147.  * Notes:   Draw all of the sample screens.
  148.  */
  149. void show_init_sample( void )
  150. {
  151. char *sample;
  152. int  line;
  153. int  i;
  154. int  j;
  155. int  k;
  156. int  l;
  157. char temp[6];
  158. char far *p;
  159.  
  160.    xygoto( -1, -1 );
  161.    sample = sample_screen[0];
  162.    for (line=0; sample != NULL; ) {
  163.       s_output( (char far *)sample, line, 0, 7 );
  164.       sample = sample_screen[++line];
  165.    }
  166.    for (i=0; i<NUM_COLORS; i++)
  167.       (*fields[i].show_me)();
  168.    sample = field_screen[0];
  169.    for (line=12, i=1; sample != NULL; line++,i++) {
  170.       s_output( (char far *)sample, line, 0, 7 );
  171.       sample = field_screen[i];
  172.    }
  173.    p = (char far *)temp;
  174.    for (i=0,k=0,line=17; i<8; i++, line++) {
  175.       for (j=0,l=0; j<16; j++, k++,l+=5) {
  176.          color_number( temp, k );
  177.          s_output( p, line, l, k );
  178.       }
  179.    }
  180.    for (i=0; i<NUM_COLORS; i++) {
  181.       color_number( temp, fields[i].color );
  182.       s_output( p, fields[i].line, fields[i].col, fields[i].color );
  183.    }
  184. }
  185.  
  186.  
  187. /*
  188.  * Name:    color_number
  189.  * Date:    July 21, 1991
  190.  * Passed:  dest:  buffer to store the color sample
  191.  *          num:   attribute number
  192.  * Notes:   Show the use what the foreground and background colors look like.
  193.  */
  194. void color_number( char *dest, int num )
  195. {
  196. int i, j, k;
  197. char temp[6];
  198.  
  199.    strcpy( dest, "[   ]" );
  200.    itoa( num, temp, 10 );
  201.    i = strlen( temp );
  202.    j = 4 - i;
  203.    for (k=0; i > 0; i--,j++, k++)
  204.       dest[j] = temp[k];
  205. }
  206.  
  207.  
  208. /*
  209.  * Name:    current_color_number
  210.  * Date:    July 21, 1991
  211.  * Passed:  dest:  buffer to store the color sample
  212.  *          num:   attribute number
  213.  * Notes:   Put '*' around the sample color to give the user an idea of where
  214.  *          the current field is.
  215.  */
  216. void current_color_number( char *dest, int num )
  217. {
  218. int i, j, k;
  219. char temp[6];
  220.  
  221.    strcpy( dest, "*   *" );
  222.    itoa( num, temp, 10 );
  223.    i = strlen( temp );
  224.    j = 4 - i;
  225.    for (k=0; i > 0; i--,j++, k++)
  226.       dest[j] = temp[k];
  227. }
  228.  
  229.  
  230. /*
  231.  * Name:    show_help_color
  232.  * Date:    July 21, 1991
  233.  */
  234. void show_help_color( void )
  235. {
  236. int color;
  237. int line;
  238.  
  239.    color = fields[0].color;
  240.    for (line=1; line <10; line++)
  241.       hlight_line( 1, line, 37, color );
  242.    hlight_line( 1,  10, 13, color );
  243.    hlight_line( 25, 10, 13, color );
  244. }
  245.  
  246.  
  247. /*
  248.  * Name:    show_fileheader_color
  249.  * Date:    July 21, 1991
  250.  */
  251. void show_fileheader_color( void )
  252. {
  253.    hlight_line( 41, 1, 38, fields[1].color );
  254. }
  255.  
  256.  
  257. /*
  258.  * Name:    show_text_color
  259.  * Date:    July 21, 1991
  260.  */
  261. void show_text_color( void )
  262. {
  263. int color;
  264.  
  265.    color = fields[2].color;
  266.    hlight_line( 41, 3, 38, color );
  267. /*   hlight_line( 41, 5, 38, color );  */
  268. }
  269.  
  270.  
  271. /*
  272.  * Name:    show_curl_color
  273.  * Date:    July 21, 1991
  274.  */
  275. void show_curl_color( void )
  276. {
  277.    hlight_line( 41, 4, 38, fields[3].color );
  278. }
  279.  
  280.  
  281. /*
  282.  * Name:    show_dirty_color
  283.  * Date:    July 21, 1991
  284.  */
  285. void show_dirty_color( void )
  286. {
  287.    hlight_line( 41, 5, 38, fields[4].color );
  288. }
  289.  
  290.  
  291. /*
  292.  * Name:    show_warning_color
  293.  * Date:    July 21, 1991
  294.  */
  295. void show_warning_color( void )
  296. {
  297.    hlight_line( 41, 9, 38, fields[5].color );
  298. }
  299.  
  300.  
  301. /*
  302.  * Name:    show_mode_color
  303.  * Date:    July 21, 1991
  304.  */
  305. void show_mode_color( void )
  306. {
  307.    hlight_line( 41, 10, 26, fields[6].color );
  308. }
  309.  
  310.  
  311. /*
  312.  * Name:    show_wrapped_color
  313.  * Date:    July 21, 1991
  314.  */
  315. void show_wrapped_color( void )
  316. {
  317.    hlight_line( 67, 10, 12, fields[7].color );
  318. }
  319.  
  320.  
  321. /*
  322.  * Name:    show_eof_color
  323.  * Date:    July 21, 1991
  324.  */
  325. void show_eof_color( void )
  326. {
  327.    hlight_line( 41, 8, 38, fields[8].color );
  328. }
  329.  
  330.  
  331. /*
  332.  * Name:    show_overcan_color
  333.  restore_overscan
  334.  * Date:    April 1, 1993
  335.  */
  336. void show_overscan_color( void )
  337. {
  338. int overscan;
  339.  
  340.    overscan = fields[9].color;
  341.    restore_overscan( overscan