home *** CD-ROM | disk | FTP | other *** search
/ High Voltage Shareware / high1.zip / high1 / DIR21 / DOUGM.ZIP / DM168SRC.ZIP / DRAW.C < prev    next >
Text File  |  1992-07-26  |  16KB  |  597 lines

  1. /***************************************************************************/
  2. void Hide_Cursor( void )  
  3.  
  4.     _asm mov cx, 1000h
  5.     _asm mov ah, 01h
  6.     _asm mov al, video_mode
  7.     _asm int 10h
  8. }
  9.  
  10. /***************************************************************************/
  11. void Show_Cursor( void )  
  12.  
  13. {
  14.     _asm mov ch, cursor_top
  15.     _asm mov cl, cursor_bottom
  16.     _asm mov ah, 01h
  17.     _asm mov al, video_mode
  18.     _asm int 10h
  19. }
  20.  
  21. /***************************************************************************/
  22. void _fastcall Put_Cursor(col,row)
  23.  
  24. byte col,row;
  25.  
  26. {
  27.     _asm mov ah,02       
  28.     _asm sub bh,bh
  29.     _asm mov dh,row       
  30.     _asm mov dl,col       
  31.     _asm int 10h
  32. }
  33.  
  34. /***************************************************************************/
  35. void Hide_Mouse( void )  
  36.  
  37.     _asm mov ax,2
  38.     _asm int 33h
  39. }
  40.  
  41. /***************************************************************************/
  42. void Show_Mouse( void )  
  43.  
  44. {
  45.     _asm mov ax,1
  46.     _asm int 33h
  47. }
  48.  
  49. /***************************************************************************/
  50. void _fastcall Draw(x,y,thing,color)
  51.  
  52. register byte x,y,color;
  53. register char thing;
  54.  
  55. {
  56.     *(video_start+x+max_screen_x*y) = (int) ( (byte) thing| (int) (color <<8) );
  57. }
  58.  
  59. /***************************************************************************/
  60. byte _fastcall Read_Color(x,y)
  61.  
  62. byte x,y;
  63.  
  64. {
  65.     return( *(video_start+x+max_screen_x*y) >> 8);
  66. }
  67.  
  68. /***************************************************************************/
  69. void _fastcall Put_Color(x,y,color)
  70.  
  71. byte x,y,color;
  72.  
  73. {
  74.     *(video_start+x+max_screen_x*y) = (*(video_start+x+max_screen_x*y) & 255) | (color << 8);
  75. }
  76.  
  77. /***************************************************************************/
  78. void _fastcall Fill_Screen(thing,color)
  79.  
  80. char thing;
  81. byte color;
  82.  
  83. {
  84.     register int x, fill_value;
  85.  
  86.     fill_value = ( (byte) thing | color << 8);
  87.  
  88.     for ( x = max_screen_x * (max_screen_y+1); x>=0 ;x--)
  89.         *(video_start+x) = fill_value;
  90. }
  91.  
  92. /***************************************************************************/
  93. void Draw_Backdrop(void)
  94.  
  95. {
  96.     FILE *Backdrop;
  97.     char buffer[MAX_LINE];
  98.  
  99.     Fill_Screen(backdrop_char,backdrop_color);
  100.  
  101.     if (backdrop_file[0] != '\0'){
  102.         if ( ( Backdrop = fopen(backdrop_file, "r" ) ) != NULL ){
  103.             while ( fgets( buffer, MAX_LINE, Backdrop) != NULL )
  104.                 fprintf(stderr,"%s",buffer);
  105.               fclose(Backdrop);
  106.         }
  107.     }
  108. }
  109.  
  110. /***************************************************************************/
  111. void Draw_Header()
  112.  
  113. {
  114.     byte x;
  115.     byte back   = palette[header_palette][ BACK ] << 4;
  116.     byte text   = palette[header_palette][ TEXT ] | back;
  117.     byte border = palette[header_palette][ HIGHLIGHT ] | back;
  118.  
  119.     if ( header_message == NULL )
  120.         header_message = VERSION_STRING;
  121.  
  122.         /* draw top */
  123.     x=0;
  124.     Draw(x, 0, '┌', border);
  125.     for (x++; x < (byte)(max_screen_x-1); x++)
  126.         Draw(x, 0, '─', border);
  127.     Draw(x, 0,'┐', border);
  128.  
  129.         /* draw filling */
  130.     x=0;
  131.     Draw( x++ , 1, '│', border);
  132.     Draw( x++ , 1, ' ', text);
  133.     while (header_message[x-2] != '\0'){
  134.         Draw(x,1,header_message[x-2],text);
  135.         x++;
  136.     }
  137.     while (x< (byte)(max_screen_x-1) )    
  138.         Draw(x++, 1, ' ', text);
  139.     Draw(x, 1, '│', border);
  140.  
  141.         /* draw bottom */
  142.     x = 0;
  143.     Draw(x, 2, '└', border);
  144.     for(x++; x < (byte)(max_screen_x-1); x++)
  145.         Draw(x, 2, '─', border);
  146.     Draw(x, 2, '┘', border);
  147.  
  148.     Update_Time();
  149. }
  150.  
  151. /***************************************************************************/
  152. void Draw_Footer()
  153.  
  154. {
  155.     register byte x,i,ch;
  156.  
  157.     x=0;
  158.     for ( i=1; i < 11 ; i++){
  159.         if (special_item[i] != NULL){
  160.             Draw (x++,max_screen_y,' ',footer_color);    
  161.             Draw (x++,max_screen_y,'F',footer_color);    
  162.             if ( i == 10 ){
  163.                 Draw (x++,max_screen_y,'1',footer_color);    
  164.                 Draw (x++,max_screen_y,'0',footer_color);    
  165.             }
  166.             else
  167.                 Draw (x++,max_screen_y,(byte)(i+48),footer_color);    
  168.             Draw (x++,max_screen_y,'=',footer_color);    
  169.             Draw (x++,max_screen_y,' ',footer_color);    
  170.             ch =0;
  171.             while ( special_item[i]->title[ch] != '\0' )
  172.                 Draw (x++,max_screen_y,special_item[i]->title[ch++],footer_color);
  173.             Draw (x++,max_screen_y,' ',footer_color);
  174.             special_item[i]->item_number = x;
  175.         }
  176.     }
  177.     if (x > 0){
  178.         while (x < max_screen_x)
  179.             Draw (x++,max_screen_y,' ',footer_color);
  180.     }
  181. }
  182.  
  183. /***************************************************************************/
  184. void Screen_Saver()
  185.  
  186. {
  187.     char i;
  188.  
  189.     current_minute = 61;
  190.     shadow =  NO;    /* turn shadow drawing off */
  191.  
  192.              /* wait until movement resets the timer */
  193.         while (timer == 0){  
  194.         Update_Time();
  195.         Update_Mouse();
  196.         if (kbhit()){
  197.             Get_Key_Input();
  198.         }
  199.         clock_place++;  
  200.             /* increment clock_place -  this is used to simulate a
  201.                a random placement of the screen saver message 
  202.               by moding this number with the number of possible 
  203.               places to put it out.  This is done in update_time() */
  204.     }        
  205.  
  206.     Hide_Mouse();         /* just to be safe */
  207.  
  208.     i=win_index;        /* remember how many windows were open */
  209.                         /* draw back boxes will foul this number */
  210.   
  211.     Draw_Backdrop();    /* lay screen foundation */
  212.     Draw_Header();
  213.     Draw_Footer();
  214.     Draw_Back_Boxes();
  215.  
  216.     win_index = 1;      /* begin at the window #1 */
  217.     Last_Window_Globals();    /* go back to window 0 */
  218.  
  219.                         /* if more windows were open, display them */
  220.     if (do_return){
  221.         while( win_index < i ){  
  222.             Display_Menu( current_item );
  223.             win_index +=2;           /* two steps forward -- */
  224.             Last_Window_Globals();     /* one step back -- what a kludge */
  225.         }
  226.     }
  227.         /* turn shadow drawing back on */
  228.     shadow=draw_shadow;
  229.  
  230.     current_minute = 61;
  231.     event.action = NO_ACTION;
  232.  
  233.         /* current window will be redrawn automaticly upon return */ 
  234. }
  235.  
  236. /***************************************************************************/
  237. int *Store_Screen()
  238.  
  239. {
  240.     int *storage_addr;
  241.     register int *storage_pointer;
  242.     register byte x,y;
  243.  
  244.     if ( (storage_addr = (int *) malloc( (width+1) * (height+1) *2 )) == NULL){
  245.         Critical_Error(MEMORY);
  246.     }
  247.  
  248.     storage_pointer = storage_addr;
  249.  
  250.     for (y = top; y <= bottom; y++){
  251.         for (x = left; x <= right; x++){
  252.             *storage_pointer = *(video_start+x+max_screen_x*y);
  253.             storage_pointer++;
  254.         }
  255.     }
  256.  
  257.     return(storage_addr);
  258. }
  259.  
  260. /***************************************************************************/
  261. void Restore_Screen(storage_addr)
  262.  
  263. int *storage_addr;
  264.  
  265. {
  266.     register byte x,y;
  267.     register int *storage_pointer;
  268.  
  269.     storage_pointer = storage_addr;
  270.  
  271.     for (y = top; y <= bottom; y++){
  272.         for (x = left; x <= right; x++){
  273.             *(video_start + (max_screen_x*y) +x) = *storage_pointer;
  274.             storage_pointer++;
  275.         }
  276.     }
  277.     free (storage_addr);
  278.     return;
  279. }
  280.  
  281. /***************************************************************************/
  282. void Display_Menu(hi_item)
  283.  
  284. Item *hi_item;
  285.  
  286. {
  287.     byte text,border,title,back;
  288.  
  289.     register byte x,y,i;
  290.     char *str,quick_number;
  291.     Item *item;
  292.  
  293.     back  = palette[current_menu->palette][ BACK ] << 4;
  294.     text  = palette[current_menu->palette][ TEXT ] | back;
  295.     title = palette[current_menu->palette][ TITLE ] | back;
  296.  
  297.     if (hi_item == NULL){    /* draw_active menu */
  298.         if (shadow) Display_Shadow();
  299.         border = palette[current_menu->palette][ HIGHLIGHT ] | back;
  300.         last_x = 0;   /* force mouse reset */
  301.     }
  302.     else{                    /* draw inactive menu */
  303.         if (shadow) Remove_Shadow();
  304.         border = palette[current_menu->palette][ BORDER ] | back;
  305.     }
  306.  
  307.         /* draw top line */
  308.     x = left;
  309.     y = top;
  310.  
  311.     Draw(x, y,'╔', border);
  312.     for (x++; x < right; x++)
  313.         Draw(x, y,'═', border);
  314.     Draw(x, y, '╗', border);
  315.  
  316.         /* draw title centered*/
  317.     x = left;
  318.     y++;
  319.     Draw(x, y, '║', border);
  320.     for (i = (width-current_menu->title_length)/2; i!=0; i--)
  321.         Draw(++x, y,' ', title);
  322.     for (str = (char *) current_menu->title; *str != '\0'; str++)
  323.         Draw(++x, y, *str, title);
  324.     while ( x < right )
  325.         Draw(++x, y,' ', title);
  326.     Draw(x, y,'║', border);
  327.  
  328.         /* draw title bar */
  329.     x = left;
  330.     y++;
  331.     Draw(x, y,'╠', border);
  332.     for (x++; x < right; x++)
  333.         Draw(x, y,'═', border);
  334.     Draw(x, y,'╣', border);
  335.  
  336.         /* draw body */
  337.     
  338.     item = current_menu->first_item;
  339.     while (item != NULL){
  340.         y++;
  341.         x = left;
  342.         if ( item->first_line != NULL ){
  343.             if (item == hi_item)
  344.                 text = palette[current_menu->palette][ HIGHLIGHT ] | back;
  345.             Draw(x, y, '║', border);
  346.             Draw(++x, y, ' ', text);
  347.             if (quick_select){
  348.                                         /* make it an asc number */
  349.                 quick_number = 48 + item->item_number; 
  350.                 if (quick_number > 57)
  351.                                         /* make it an asc letter */
  352.                     quick_number += 7;  
  353.                 Draw(++x, y, quick_number, text);
  354.                 Draw(++x, y, ')', text);
  355.                 Draw(++x, y, ' ', text);
  356.             }                
  357.             for( str = (char *) item->title; *str != '\0'; str++)
  358.                 Draw(++x, y, *str, text);
  359.             while( x < right )
  360.                 Draw(++x, y, ' ', text);
  361.             Draw(x, y, '║', border);
  362.             if (item == hi_item) 
  363.                 text = palette[current_menu->palette][ TEXT ] | back;
  364.         }
  365.         else{                            /* draw sub-titles centered*/
  366.             x = left;
  367.             Draw(x, y, '╟', border);
  368.             for (i= (width - item->title_length)/2; i!=0; i--)
  369.                 Draw(++x, y, '─', border);
  370.             for (str = (char *) item->title; *str != '\0'; str++)
  371.                 Draw(++x, y, *str, border);
  372.             while (x < right )
  373.                 Draw(++x, y, '─', border);
  374.             Draw(x, y, '╢', border);
  375.         }
  376.         item = item->next_item;
  377.     }
  378.         /* draw bottom */
  379.     x = left;
  380.     y++;
  381.     Draw(x, y, '╚', border);
  382.     for(x++; x < right; x++)
  383.         Draw(x, y, '═', border);
  384.     Draw(x, y, '╝', border);
  385. }
  386.  
  387. /***************************************************************************/
  388. void Select(new_item)
  389.  
  390. /* unselect current_item and then select new_item */
  391.  
  392. Item *new_item;
  393.  
  394. {
  395.     register byte x,y;
  396.     byte back,text,select;
  397.  
  398.     back   = palette[current_menu->palette][ BACK ] << 4;
  399.     text   = palette[current_menu->palette][ TEXT ] | back;
  400.     back   = palette[current_menu->palette][ S_BACK ] << 4;
  401.     select = palette[current_menu->palette][ SELECT ] | back;
  402.  
  403.     y = top + current_item->item_number + 2;
  404.     x = left + 1;
  405.     while (x < right)
  406.         Put_Color(x++, y, text);
  407.  
  408.     current_item = new_item;
  409.  
  410.     y = top + current_item->item_number + 2;
  411.     x = left + 1;
  412.     while ( x < right)
  413.         Put_Color(x++, y, select);
  414.  
  415.     Win[win_index].item = current_item;
  416. }
  417.  
  418. /***************************************************************************/
  419. void Display_Text_Box(lines,x1,y1,pal)
  420.  
  421. char *lines[];
  422. byte x1,y1,pal;
  423.  
  424. {
  425.     byte text,border,back,x2,y2;
  426.     register byte x,y,i;
  427.     char *str;
  428.     int *storage;
  429.  
  430.     win_index++;
  431.  
  432.         /* determine hight and width */
  433.     width=height=0;
  434.     while(lines[height]!=NULL){
  435.         if (width < strlen(lines[height]))        
  436.             width = strlen(lines[height]);
  437.         height++;
  438.     }
  439.     height++;
  440.     width+=3;
  441.  
  442.     if (x1 == CENTER)
  443.         x1 = (max_screen_x-width)/2;
  444.     if (y1 == CENTER)
  445.         y1 = (max_screen_y-height)/2;
  446.  
  447.     x2 = x1+width;
  448.     y2 = y1+height;
  449.  
  450.     if ( x2 >= (byte)(max_screen_x) ){
  451.         x2 = max_screen_x-1;
  452.         x1 = x2 - width;
  453.     }
  454.  
  455.     if (y2 >= (byte)(max_screen_y) ){
  456.         y2 = max_screen_y-1;
  457.         y1 = y2 - height;
  458.     }
  459.  
  460.     if ( x1 >= x2 || y1 >= y2 ){
  461.         Last_Window_Globals();
  462.         Error_Box("Unable to display text box.","The box is too large.");
  463.         return;
  464.     }
  465.  
  466.     left = Win[win_index].left = x1;  
  467.     right = Win[win_index].right = x2;  
  468.     top = Win[win_index].top = y1;  
  469.     bottom = Win[win_index].bottom = y2;  
  470.     Win[win_index].width = width;
  471.     Win[win_index].height = height;
  472.     Win[win_index].storage = Store_Screen();  
  473.  
  474.     back   = palette[pal][ BACK ] << 4;
  475.     text   = palette[pal][ TEXT ] | back;
  476.     border = palette[pal][ HIGHLIGHT ] | back;
  477.  
  478.         /* draw top */
  479.     Draw(x = x1, y1, '┌', border);
  480.     for (x++; x < x2; x++)
  481.         Draw(x, y1, '─', border);
  482.     Draw(x, y1,'┐', border);
  483.  
  484.         /* draw filling */
  485.     for (y=y1+1;y<y2;y++){
  486.         x = x1;
  487.         Draw(x, y, '│', border);
  488.         str = lines[y-y1-1];
  489.         for( i=( x2-x1-strlen(str)-1 )/2 ;i != 0; i--)
  490.             Draw(++x, y, ' ', text);
  491.  
  492.         while (*str != '\0'){
  493.             Draw(++x, y, *str, text);
  494.             str++;
  495.         }
  496.         while( x < x2 )
  497.             Draw(++x, y, ' ', text);
  498.         Draw(x, y,'│', border);
  499.     }
  500.  
  501.         /* draw bottom */
  502.     Draw(x = x1, y2, '└', border);
  503.     for(x++; x < x2; x++)
  504.         Draw(x, y2, '─', border);
  505.     Draw(x, y2, '┘', border);
  506.  
  507.     if (shadow) Display_Shadow();
  508.     last_x = 0;   /* force mouse reset */
  509. }
  510.  
  511. /***************************************************************************/
  512. void Display_Shadow( )
  513.  
  514. {
  515.     register byte x, y;
  516.  
  517.     if (selected_fn) Unselect_Fn();
  518.  
  519.     right++;
  520.     bottom++;
  521.     for ( x = width+1; x ; x--){
  522.         *(shad_buf+x) = Read_Color( (byte)(left+x), bottom );
  523.         Put_Color( (byte)(left+x), bottom, shadow_color);    
  524.     }
  525.     for (y = height; y ; y--){
  526.         *(shad_buf+max_screen_x+y) = Read_Color(right, (byte)(top+y));
  527.         Put_Color( right, (byte)(top+y), shadow_color);
  528.     }
  529.     right--;
  530.     bottom--;
  531. }
  532.  
  533. /***************************************************************************/
  534. void Remove_Shadow()
  535.  
  536. {
  537.     register byte x, y;
  538.  
  539.     right++;
  540.     bottom++;
  541.     for ( x = width+1; x ; x-- )
  542.         Put_Color( (byte)(left+x), bottom, *(shad_buf+x) );
  543.     for ( y = height; y ; y--)
  544.         Put_Color( right,(byte)(top+y), *(shad_buf+max_screen_x+y) );    
  545.     right--;
  546.     bottom--;
  547. }
  548.  
  549. /***************************************************************************/
  550. void Clean_Up()
  551.  
  552. {
  553.     Fill_Screen(' ',7);
  554.     Put_Cursor(0,0);
  555.     Show_Cursor();
  556.     Hide_Mouse();
  557. }
  558.  
  559. /***************************************************************************/
  560. void Draw_Back_Boxes()
  561.  
  562. {
  563.     char *line[25],*place;
  564.     char temp[MAX_LINE], *checker;
  565.     byte i;
  566.  
  567.     current_text_block = first_text_block;
  568.  
  569.     while( current_text_block != NULL ){
  570.         current_text = current_text_block->first_line;
  571.         i=0;
  572.         while ( current_text != NULL && *(place=current_text->text_line) == '"'){
  573.             if (i <25){
  574.                 place++;
  575.                 Transcribe_String(place,temp);
  576.                 checker=temp;
  577.                 while (*checker != '\0'){
  578.                     if (*checker == '"')
  579.                         *checker = '\0';
  580.                     checker++;
  581.                 }
  582.                 line[i] = strdup(temp);
  583.                 i++;
  584.            }
  585.            current_text = current_text->next_line;
  586.         }
  587.         line[i] = NULL;
  588.  
  589.         Display_Text_Box(line,current_text_block->x1,current_text_block->y1,current_text_block->pal);
  590.         for (i=0;line[i] != NULL;i++)
  591.             free(line[i]);
  592.         current_text_block = current_text_block->next_block;
  593.     }
  594. }
  595.