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 / INPUT.C < prev    next >
Text File  |  1991-10-10  |  7KB  |  335 lines

  1. /***************************************************************************/
  2. void Update_Time()
  3.  
  4. {
  5.      char time_str[MAX_TIME_STR];
  6.       
  7.     byte minutes,hours,day_o_week,day_o_month,month,am_pm,i,time_len,color;
  8.  
  9.     _asm mov ah,2ch
  10.     _asm int 21h
  11.     _asm mov minutes,cl
  12.     _asm mov hours,ch
  13.  
  14.      if (current_minute != minutes){
  15.         if (timer)
  16.             if (!--timer){
  17.                 if (timer_text->first_line != NULL){
  18.                     Win[win_index].event = TIMER;
  19.                     current_item = timer_text;    
  20.                     Make_Batch();
  21.                 }
  22.                 else{
  23.                     Blank_Screen();
  24.                 }    
  25.             }    
  26.  
  27.         current_minute = minutes;
  28.          _asm mov ah,2ah        
  29.         _asm int 21h
  30.         _asm mov day_o_week,al
  31.         _asm mov day_o_month,dl
  32.         _asm mov month,dh
  33.  
  34.         am_pm = 0;
  35.          if (hours > 12) {
  36.             am_pm = 1;
  37.             hours -=12;
  38.         }
  39.         if (hours == 0)
  40.             hours = 12; 
  41.             
  42.         switch (day_o_week){
  43.             case  0:
  44.                 strcpy(time_str,"Sunday, ");
  45.                 break;
  46.             case  1:
  47.                 strcpy(time_str,"Monday, ");
  48.                 break;
  49.             case  2:
  50.                 strcpy(time_str,"Tuesday, ");
  51.                 break;
  52.             case  3:
  53.                 strcpy(time_str,"Wednesday, ");
  54.                 break;
  55.             case  4:
  56.                 strcpy(time_str,"Thursday, ");
  57.                 break;
  58.             case  5:
  59.                 strcpy(time_str,"Friday, ");
  60.                 break;
  61.             case  6:
  62.                 strcpy(time_str,"Saturday, ");
  63.                 break;
  64.         }
  65.         switch (month){
  66.             case  1:
  67.                 strcat( time_str,"January ");
  68.                 break;
  69.             case  2:
  70.                 strcat( time_str,"February ");
  71.                 break;
  72.             case  3:
  73.                 strcat( time_str,"March ");
  74.                 break;
  75.             case  4:
  76.                 strcat( time_str,"April ");
  77.                 break;
  78.             case  5:
  79.                 strcat( time_str,"May ");
  80.                 break;
  81.             case  6:
  82.                 strcat( time_str,"June ");
  83.                 break;
  84.             case  7:
  85.                 strcat( time_str,"July ");
  86.                 break;
  87.             case  8:
  88.                 strcat( time_str,"August ");
  89.                 break;
  90.             case  9:
  91.                 strcat( time_str,"September ");
  92.                 break;
  93.             case  10:
  94.                 strcat( time_str,"October ");
  95.                 break;
  96.             case  11:
  97.                 strcat( time_str,"November ");
  98.                 break;
  99.             case  12:
  100.                 strcat( time_str,"December ");
  101.                 break;
  102.         }
  103.         sprintf( (time_str + strlen(time_str)),"%d, %d:%02d ",day_o_month,hours,minutes);
  104.         
  105.         if (am_pm) strcat( time_str,"pm");
  106.         else strcat(time_str,"am");
  107.  
  108.         time_len = strlen(time_str);
  109.  
  110.         Hide_Mouse();
  111.  
  112.         color = (byte) (palette[header_palette][BACK] <<4) | (palette[header_palette][TEXT]);
  113.  
  114.         for (i=0;i <= time_len ;i++)
  115.             Draw( (byte) (max_screen_x-2-i),1,time_str[time_len-i],color);
  116.  
  117.         for (;i<MAX_TIME_STR;i++)
  118.             Draw( (byte) (max_screen_x-2-i),1,' ',color);
  119.  
  120.         Show_Mouse();
  121.     }
  122. }
  123.  
  124. /***************************************************************************/
  125. byte Old_Window(x,y)
  126.  
  127. byte x,y;
  128.  
  129. {
  130.     byte window = (byte) win_index;
  131.  
  132.     for (window--;window!=255;window--)
  133.         if (x>=Win[window].left && x<= Win[window].right &&
  134.                 y>=Win[window].top && y<= Win[window].bottom)
  135.             return( (int) win_index - window);
  136.     return( 0);
  137. }
  138.  
  139. /***************************************************************************/
  140. void Update_Mouse()
  141.  
  142. {
  143.     unsigned int mouse_x,mouse_y,button;
  144.     byte choice;
  145.     Item *item;
  146.  
  147.     _asm mov ax,3        /* read current mouse position */
  148.     _asm sub bx,bx            
  149.     _asm sub cx,cx            
  150.     _asm sub dx,dx
  151.     _asm int 33h
  152.     _asm mov mouse_x,cx
  153.     _asm mov mouse_y,dx
  154.     _asm mov button,bx
  155.  
  156.     mouse_x = mouse_x >> 3;
  157.     mouse_y = mouse_y >> 3;
  158.  
  159.             /* decide what is going on with the mouse */
  160.  
  161.     if (mouse_x == 0 && mouse_y == 0)
  162.         return;
  163.  
  164.     if (mouse_x == last_x && mouse_y == last_y && button == last_button)
  165.         return;
  166.  
  167.         /* select item if the mouse is over a selectable item */
  168.  
  169.     choice = mouse_y-top-2;
  170.  
  171.     if ( (mouse_x > left)  && (mouse_x < right) &&
  172.         (choice > 0) && (choice <= current_menu->number_of_items) ){ 
  173.  
  174.         if ( (choice != current_item->item_number) 
  175.                 && ( last_x != mouse_x || last_y != mouse_y) ){
  176.             item = Number_To_Item( (byte) choice );
  177.             if (item->first_line != NULL){
  178.                 event.action = GOTO_ITEM;
  179.                 event.data = choice;
  180.             }
  181.           }
  182.         if ( !(last_button & 1) && (button & 1))
  183.             event.action = DO_ITEM;
  184.     }
  185.  
  186.         /*  the following statements improve the selection process */
  187.  
  188.     else if ( (mouse_x > left) && (mouse_x < right) &&
  189.             (last_y < bottom ) && ( last_y > (byte) (top + 2) ) ){
  190.         if (last_y > mouse_y) 
  191.             choice = 1;
  192.         else
  193.             choice = current_menu->number_of_items;
  194.         item = Number_To_Item( (byte) choice );
  195.          if (item->first_line != NULL){
  196.             event.action = GOTO_ITEM;
  197.             event.data = choice;
  198.         }
  199.     }
  200.  
  201.     else if ( !(last_button & 1) && (button & 1)){
  202.         if (mouse_y == max_screen_y){
  203.             for (choice = 1; choice < 11; choice++){
  204.                 if ((function_key[choice] != NULL) && 
  205.                         (mouse_x <= function_key[choice]->title_length)){
  206.                     event.action = FUNCTION_KEY;
  207.                     event.data = choice;
  208.                     break;
  209.                 }
  210.             }
  211.         }        
  212.         else if (mouse_y < top || mouse_y > bottom || mouse_x < left || mouse_x > right){
  213.             choice = Old_Window((byte)mouse_x,(byte)mouse_y);
  214.             if (choice > 0){
  215.                 event.action = ESCAPE;
  216.                 event.data = choice;
  217.             }
  218.         }
  219.     }
  220.  
  221.     if ( !(last_button & 2) && (button & 2) ){
  222.         event.action = ESCAPE;
  223.         event.data = 1;
  224.     }
  225.  
  226.     timer = timer_holder;   /* reset timer */
  227.  
  228.     last_x      = mouse_x;
  229.     last_y      = mouse_y;
  230.     last_button = button;
  231.  
  232.     Show_Mouse();
  233. }
  234.  
  235. /***************************************************************************/
  236. void Scan_For_Letter( key_input )
  237.  
  238. char key_input;
  239.  
  240. {
  241.     Item *item = current_item->next_item;
  242.     key_input = key_input | 32;
  243.     for (; item != NULL; item = item->next_item)
  244.         if (item->first_line != NULL && (*(item->title)|32) == key_input){
  245.             event.action = GOTO_ITEM;
  246.             event.data = item->item_number;
  247.             return;
  248.         }
  249.     for (item = Home_Item(); item != current_item; item = item->next_item)
  250.         if (item->first_line != NULL && (*(item->title)|32) == key_input){
  251.             event.action = GOTO_ITEM;
  252.             event.data = item->item_number;
  253.             return;
  254.           }
  255. }            
  256.  
  257. /***************************************************************************/
  258. void Get_Key_Input()
  259.  
  260. {
  261.     char key_input;
  262.  
  263.     timer = timer_holder;
  264.  
  265.     key_input = getch();
  266.  
  267.     if (!key_input)     /* if key input == 0 get the extended part */
  268.         switch(key_input = getch()){
  269.             case 72:   /* up arrow */
  270.                 event.action = MOVE_UP;
  271.                 return;
  272.             case 71:   /* home */
  273.             case 73:   /* page up */
  274.                 event.action = GOTO_TOP;
  275.                 return;
  276.             case 80:   /* down arrow */
  277.                 event.action = MOVE_DOWN;
  278.                 return;
  279.             case 79:   /* end */
  280.             case 81:   /* page down */
  281.                 event.action = GOTO_END;
  282.                 return;
  283.             case 75:   /* back arrow */
  284.                 event.action = ESCAPE;
  285.                 event.data = 1;
  286.                 return;
  287.             default:
  288.                 if (key_input >58 && key_input < 69){
  289.                     key_input -= 58;
  290.                     if (function_key[key_input] != NULL){
  291.                         event.action = FUNCTION_KEY;
  292.                         event.data = key_input;
  293.                     }
  294.                     return;
  295.                 }            
  296.                 return;
  297.         }
  298.     switch(key_input){
  299.         case 13:
  300.             event.action = DO_ITEM;
  301.             return;
  302.         case 27:
  303.             event.action = ESCAPE;
  304.             event.data = 1;
  305.             return;
  306.         case 32:
  307.             event.action = MOVE_DOWN;
  308.             return;
  309.         default:
  310.             Scan_For_Letter(key_input);            
  311.             return;
  312.     }
  313. }
  314.  
  315. /***************************************************************************/
  316. void Wait_For_Event()
  317.  
  318. {
  319.     Show_Mouse();
  320.  
  321.     event.action = NO_ACTION;
  322.     event.data = 0;
  323.     timer = timer_holder;
  324.  
  325.     while( event.action == NO_ACTION ){
  326.         Update_Mouse();
  327.         Update_Time();
  328.         if (kbhit())
  329.             Get_Key_Input();
  330.     }
  331.  
  332.     Hide_Mouse();
  333. }
  334.  
  335.