home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / d / dmenu1.zip / DM10SRC.ZIP / DRAW.C < prev    next >
Text File  |  1991-10-15  |  11KB  |  505 lines

  1. /***************************************************************************/
  2. void Hide_Cursor( void )  
  3.  
  4.     _asm mov cx, 1000h
  5.     _asm mov ax, 0100h
  6.     _asm int 10h
  7. }
  8.  
  9. /***************************************************************************/
  10. void Show_Cursor( void )  
  11.  
  12. {
  13.      _asm mov cx, 0607h
  14.      _asm mov ax, 0100h
  15.      _asm int 10h
  16. }
  17.  
  18. /***************************************************************************/
  19. void _fastcall Put_Cursor(col,row)
  20.  
  21. byte col,row;
  22.  
  23. {
  24.     _asm mov ah,02       
  25.     _asm sub bh,bh
  26.     _asm mov dh,row       
  27.     _asm mov dl,col       
  28.     _asm int 10h
  29. }
  30.  
  31. /***************************************************************************/
  32. void Hide_Mouse( void )  
  33.  
  34.     _asm mov ax,2
  35.     _asm int 33h
  36. }
  37.  
  38. /***************************************************************************/
  39. void Show_Mouse( void )  
  40.  
  41. {
  42.     _asm mov ax,1
  43.     _asm int 33h
  44. }
  45.  
  46. /***************************************************************************/
  47. void _fastcall Draw(x,y,thing,color)
  48.  
  49. register byte x,y,color;
  50. char thing;
  51.  
  52. {
  53.     *(video_start+x+max_screen_x*y) = (int) ( (byte) thing| (int) (color <<8) );
  54. }
  55.  
  56. /***************************************************************************/
  57. byte _fastcall Read_Color(x,y)
  58.  
  59. byte x,y;
  60.  
  61. {
  62.     return( *(video_start+x+max_screen_x*y) >> 8);
  63. }
  64.  
  65. /***************************************************************************/
  66. void _fastcall Put_Color(x,y,color)
  67.  
  68. byte x,y,color;
  69.  
  70. {
  71.     *(video_start+x+max_screen_x*y) = (*(video_start+x+max_screen_x*y) & 255) | (color << 8);
  72. }
  73.  
  74. /***************************************************************************/
  75. void _fastcall Fill_Screen(thing,color)
  76.  
  77. char thing;
  78. byte color;
  79.  
  80. {
  81.     register int x, fill_value;
  82.  
  83.     fill_value = ( (byte) thing | color << 8);
  84.  
  85.     for ( x = max_screen_x * (max_screen_y+1); x>=0 ;x--)
  86.         *(video_start+x) = fill_value;
  87. }
  88.  
  89. /***************************************************************************/
  90. void Blank_Screen()
  91.  
  92. {
  93.     byte *storage;
  94.     register byte x,y;
  95.              
  96.     storage = (byte *) malloc( (max_screen_x)*(max_screen_y+1));
  97.     if (storage == NULL) return;
  98.  
  99.     for ( y = 0; y<=  max_screen_y; y++)
  100.         for (x = 0; x< max_screen_x; x++)
  101.             *(storage + max_screen_x*y+x ) = Read_Color(x,y);
  102.  
  103.     for ( y = 0; y<=  max_screen_y; y++)
  104.         for (x = 0; x< max_screen_x; x++)
  105.             Put_Color(x,y,0);
  106.  
  107.     Hide_Mouse();
  108.     Wait_For_Event();
  109.     event.action = NO_ACTION;
  110.     Show_Mouse();
  111.  
  112.     for ( y = 0; y<=  max_screen_y; y++)
  113.         for (x = 0; x< max_screen_x; x++)
  114.             Put_Color( x,y, *(storage+max_screen_x*y+x) );
  115.  
  116.     free(storage); 
  117. }
  118.  
  119. /***************************************************************************/
  120. void Clean_Up()
  121.  
  122. {
  123.     Fill_Screen(' ',7);
  124.     Put_Cursor(0,0);
  125.     Show_Cursor();
  126.     Hide_Mouse();
  127. }
  128.  
  129. /***************************************************************************/
  130. int *Store_Screen(x1,x2,y1,y2)
  131.  
  132. byte x1,x2,y1,y2;
  133.  
  134. {
  135.     int *storage_addr;
  136.     register int *storage_pointer;
  137.     register byte x,y;
  138.  
  139.     if ( (storage_addr = (int *) malloc( (x2-x1+1) * (y2-y1+1) *2 )) == NULL){
  140.         Critical_Error(MEMORY,"Screen Storing");
  141.     }
  142.  
  143.     storage_pointer = storage_addr;
  144.  
  145.     for (y = y1; y <= y2; y++){
  146.         for (x = x1; x <= x2; x++){
  147.             *storage_pointer = *(video_start+x+max_screen_x*y);
  148.             storage_pointer++;
  149.         }
  150.     }
  151.  
  152.     return(storage_addr);
  153. }
  154.  
  155. /***************************************************************************/
  156. void Restore_Screen(storage_addr,x1,x2,y1,y2)
  157.  
  158. byte x1,x2,y1,y2;
  159. int *storage_addr;
  160.  
  161. {
  162.     register byte x,y;
  163.     register int *storage_pointer;
  164.  
  165.     storage_pointer = storage_addr;
  166.  
  167.     for (y = y1; y <= y2; y++){
  168.         for (x = x1; x <= x2; x++){
  169.             *(video_start + (max_screen_x*y) +x) = *storage_pointer;
  170.             storage_pointer++;
  171.         }
  172.     }
  173.     free (storage_addr);
  174.     return;
  175. }
  176.  
  177. /***************************************************************************/
  178. void Display_Menu(hi_item)
  179.  
  180. Item *hi_item;
  181.  
  182. {
  183.     byte text,border,title,back;
  184.  
  185.     register byte x,y,i;
  186.     char *str;
  187.     Item *item;
  188.  
  189.     back  = palette[current_menu->palette][ BACK ] << 4;
  190.     text  = palette[current_menu->palette][ TEXT ] | back;
  191.     title = palette[current_menu->palette][ TITLE ] | back;
  192.  
  193.     if (hi_item == NULL){
  194.         border = palette[current_menu->palette][ HIGHLIGHT ] | back;
  195.         if (shadow) Display_Shadow(left,right,top,bottom);
  196.     }
  197.     else
  198.         border = palette[current_menu->palette][ BORDER ] | back;
  199.  
  200.         /* draw top line */
  201.     x = left;
  202.     y = top;
  203.  
  204.     Draw(x, y,'╔', border);
  205.     for (x++; x < right; x++)
  206.         Draw(x, y,'═', border);
  207.     Draw(x, y, '╗', border);
  208.  
  209.         /* draw title centered*/
  210.     x = left;
  211.     y++;
  212.     Draw(x, y, '║', border);
  213.     for (i = (width-current_menu->title_length)/2; i!=0; i--)
  214.         Draw(++x, y,' ', title);
  215.     for (str = (char *) current_menu->title; *str != '\0'; str++)
  216.         Draw(++x, y, *str, title);
  217.     while ( x < right )
  218.         Draw(++x, y,' ', title);
  219.     Draw(x, y,'║', border);
  220.  
  221.         /* draw title bar */
  222.     x = left;
  223.     y++;
  224.     Draw(x, y,'╠', border);
  225.     for (x++; x < right; x++)
  226.         Draw(x, y,'═', border);
  227.     Draw(x, y,'╣', border);
  228.  
  229.         /* draw body */
  230.     
  231.     item = current_menu->first_item;
  232.     while (item != NULL){
  233.         y++;
  234.         x = left;
  235.         if ( item->first_line != NULL ){
  236.             if (item == hi_item)
  237.                 text = palette[current_menu->palette][ HIGHLIGHT ] | back;
  238.             Draw(x, y, '║', border);
  239.             Draw(++x, y, ' ', text);
  240.             for( str = (char *) item->title; *str != '\0'; str++)
  241.                 Draw(++x, y, *str, text);
  242.             while( x < right )
  243.                 Draw(++x, y, ' ', text);
  244.             Draw(x, y, '║', border);
  245.             if (item == hi_item) 
  246.                 text = palette[current_menu->palette][ TEXT ] | back;
  247.         }
  248.         else{                            /* draw sub-titles centered*/
  249.             x = left;
  250.             Draw(x, y, '╟', border);
  251.             for (i= (width - item->title_length)/2-1; i!=0; i--)
  252.                 Draw(++x, y, '─', border);
  253.             for (str = (char *) item->title; *str != '\0'; str++)
  254.                 Draw(++x, y, *str, border);
  255.             while (x < right )
  256.                 Draw(++x, y, '─', border);
  257.             Draw(x, y, '╢', border);
  258.         }
  259.         item = item->next_item;
  260.     }
  261.         /* draw bottom */
  262.     x = left;
  263.     y++;
  264.     Draw(x, y, '╚', border);
  265.     for(x++; x < right; x++)
  266.         Draw(x, y, '═', border);
  267.     Draw(x, y, '╝', border);
  268. }
  269.  
  270. /***************************************************************************/
  271. void Select(new_item)
  272.  
  273. /* unselect current_item and then select new_item */
  274.  
  275. Item *new_item;
  276.  
  277. {
  278.     register byte x,y;
  279.     byte back,text,select;
  280.     char *str;
  281.  
  282.     back   = palette[current_menu->palette][ BACK ] << 4;
  283.     text   = palette[current_menu->palette][ TEXT ] | back;
  284.     back   = palette[current_menu->palette][ S_BACK ] << 4;
  285.     select = palette[current_menu->palette][ SELECT ] | back;
  286.  
  287.     y = top + current_item->item_number + 2;
  288.     x = left + 1;
  289.     Draw(x++, y, ' ', text);
  290.     for(str = (char *)current_item->title; *str != '\0';str++)
  291.         Draw(x++, y, *str, text);
  292.     while (x < right)
  293.         Draw(x++, y, ' ', text);
  294.  
  295.     current_item = new_item;
  296.  
  297.     y = top + current_item->item_number + 2;
  298.     x = left + 1;
  299.     Draw(x++, y, ' ', select);
  300.     for(str = (char *) current_item->title; *str != '\0';str++)
  301.         Draw(x++, y, *str, select);
  302.     while ( x < right)
  303.         Draw(x++, y, ' ', select);
  304.  
  305.     Win[win_index].item = current_item;
  306. }
  307.  
  308. /***************************************************************************/
  309. void Display_Text_Box(lines,x1,width,y1,height,pal)
  310.  
  311. char *lines[];
  312. byte x1,width,y1,height,pal;
  313.  
  314. {
  315.     byte text,border,back,x2,y2;
  316.     register byte x,y,i;
  317.     char *str;
  318.     int *storage;
  319.  
  320.     if (x1 == CENTER)
  321.         x1 = (max_screen_x-width)/2;
  322.     if (y1 == CENTER)
  323.         y1 = max_screen_y/2 - 2;
  324.  
  325.     x2 = x1+width;
  326.     y2 = y1+height;
  327.  
  328.     if ( x2 >= (byte)(max_screen_x-1) ){
  329.         x2 = max_screen_x-2;
  330.         x1 = x2 - width;
  331.     }
  332.  
  333.     if (y2 > (byte)(max_screen_y-1) ){
  334.         y2 = max_screen_y-1;
  335.         y1 = y2 - height;
  336.     }
  337.  
  338.     if ( x1 >= x2 || y1 >= y2 ){
  339.         Error_Box("Unable to display text box.","The box is too large.");
  340.         return;
  341.     }
  342.  
  343.     storage = Store_Screen(x1,x2,y1,y2);  
  344.  
  345.     back   = palette[pal][ BACK ] << 4;
  346.     text   = palette[pal][ TEXT ] | back;
  347.     border = palette[pal][ HIGHLIGHT ] | back;
  348.  
  349.         /* draw top */
  350.     Draw(x = x1, y1, '┌', border);
  351.     for (x++; x < x2; x++)
  352.         Draw(x, y1, '─', border);
  353.     Draw(x, y1,'┐', border);
  354.  
  355.         /* draw filling */
  356.     for (y=y1+1;y<y2;y++){
  357.         x = x1;
  358.         Draw(x, y, '│', border);
  359.         str = lines[y-y1-1];
  360.         for( i=( x2-x1-strlen(str)-1 )/2 ;i != 0; i--)
  361.             Draw(++x, y, ' ', text);
  362.  
  363.         while (*str != '\0'){
  364.             Draw(++x, y, *str, text);
  365.             str++;
  366.         }
  367.         while( x < x2 )
  368.             Draw(++x, y, ' ', text);
  369.         Draw(x, y,'│', border);
  370.     }
  371.  
  372.         /* draw bottom */
  373.     Draw(x = x1, y2, '└', border);
  374.     for(x++; x < x2; x++)
  375.         Draw(x, y2, '─', border);
  376.     Draw(x, y2, '┘', border);
  377.  
  378.     if (shadow) Display_Shadow(x1,x2,y1,y2);
  379.  
  380.     do
  381.         Wait_For_Event();
  382.     while (event.action == GOTO_ITEM);
  383.  
  384.     if (shadow) Remove_Shadow(x1,x2,y1,y2);
  385.     Restore_Screen(storage,x1,x2,y1,y2);
  386.  
  387.         /* force mouse reset */
  388.     last_x = 0;
  389. }
  390.  
  391. /**************************************************************************/
  392. void Display_Item_Text()
  393.  
  394. {
  395.     char *line[25];
  396.     byte x,y,width=0,i=0,color;
  397.     char *place = current_item->first_line->text_line;
  398.  
  399.     current_text = current_item->first_line->next_line;
  400.  
  401.     while (current_text != NULL){
  402.         line[i] = current_text->text_line;
  403.         if ( strlen(line[i]) > width)
  404.             width = strlen(line[i]);
  405.         current_text = current_text->next_line;
  406.         i++;
  407.         if ( i == 25)
  408.             current_text = NULL;
  409.     }
  410.     line[i] = NULL;
  411.     width +=3;
  412.     i++;
  413.  
  414.     place = After_Comma(place);
  415.     x = Get_Value(place, CENTER );
  416.     place = After_Comma(place);
  417.     y = Get_Value(place, CENTER );
  418.     place = After_Comma(place);
  419.     color = Get_Palette(place,message_palette);
  420.  
  421.     if (cascade && x == CENTER && y == CENTER ){
  422.         x = left + cascade_x;
  423.         y = top + cascade_y;
  424.     }    
  425.  
  426.     Display_Text_Box(line,x,width,y, i ,color);
  427. }    
  428.  
  429. /***************************************************************************/
  430. void Error_Box(line1,line2)
  431.  
  432. char line1[],line2[];
  433.  
  434. {
  435.     byte x,y,width;
  436.     char title[] = "Error - Error - Error - Error";
  437.     char foot[] = "Press any key to continue.";
  438.     char blank[] = " ";
  439.     char *lines[7];    
  440.  
  441.     width = strlen(title);
  442.     if (width < strlen(line1) )
  443.         width = strlen(line1);
  444.     if (width < strlen(line2) )
  445.         width = strlen(line2);
  446.  
  447.     width +=3;
  448.     x = CENTER;
  449.     y = CENTER;
  450.  
  451.     lines[0] = title;
  452.     lines[1] = blank;
  453.     lines[2] = line1;
  454.     lines[3] = line2;
  455.     lines[4] = blank;
  456.     lines[5] = foot;
  457.     lines[6] = NULL;
  458.  
  459.     Display_Text_Box(lines,x,width,y,7,error_palette);
  460. }
  461.  
  462. /***************************************************************************/
  463. void Display_Shadow( x1, x2, y1, y2)
  464.  
  465. byte x1,x2,y1,y2;
  466.  
  467. {
  468.     byte x, y;
  469.  
  470.     ++x1;
  471.     ++x2;
  472.     ++y1;
  473.     ++y2;
  474.  
  475.     for ( x = x1; x <= x2; x++){
  476.         *(shad_buf+x) = Read_Color( x, y2 );    
  477.         Put_Color( x, y2, shadow_color);    
  478.     }
  479.     for (y = y1; y < y2; y++){
  480.         *(shad_buf+max_screen_x+y) = Read_Color( x2 , y );    
  481.         Put_Color( x2 ,y, shadow_color);
  482.     }
  483. }
  484. /***************************************************************************/
  485. void Remove_Shadow( x1, x2, y1, y2)
  486.  
  487. byte x1, x2, y1, y2;
  488.  
  489. {
  490.     byte x, y;
  491.  
  492.     ++x1;
  493.     ++x2;
  494.     ++y1;
  495.     ++y2;
  496.  
  497.     for ( x = x1; x <= x2; x++ )
  498.         Put_Color( x, y2, *(shad_buf+x) );
  499.     x =- x1;
  500.     for ( y = y1; y < y2; y++)
  501.         Put_Color( x2, y, *(shad_buf+max_screen_x+y) );    
  502. }
  503.