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 >
Wrap
Text File
|
1991-10-10
|
7KB
|
335 lines
/***************************************************************************/
void Update_Time()
{
char time_str[MAX_TIME_STR];
byte minutes,hours,day_o_week,day_o_month,month,am_pm,i,time_len,color;
_asm mov ah,2ch
_asm int 21h
_asm mov minutes,cl
_asm mov hours,ch
if (current_minute != minutes){
if (timer)
if (!--timer){
if (timer_text->first_line != NULL){
Win[win_index].event = TIMER;
current_item = timer_text;
Make_Batch();
}
else{
Blank_Screen();
}
}
current_minute = minutes;
_asm mov ah,2ah
_asm int 21h
_asm mov day_o_week,al
_asm mov day_o_month,dl
_asm mov month,dh
am_pm = 0;
if (hours > 12) {
am_pm = 1;
hours -=12;
}
if (hours == 0)
hours = 12;
switch (day_o_week){
case 0:
strcpy(time_str,"Sunday, ");
break;
case 1:
strcpy(time_str,"Monday, ");
break;
case 2:
strcpy(time_str,"Tuesday, ");
break;
case 3:
strcpy(time_str,"Wednesday, ");
break;
case 4:
strcpy(time_str,"Thursday, ");
break;
case 5:
strcpy(time_str,"Friday, ");
break;
case 6:
strcpy(time_str,"Saturday, ");
break;
}
switch (month){
case 1:
strcat( time_str,"January ");
break;
case 2:
strcat( time_str,"February ");
break;
case 3:
strcat( time_str,"March ");
break;
case 4:
strcat( time_str,"April ");
break;
case 5:
strcat( time_str,"May ");
break;
case 6:
strcat( time_str,"June ");
break;
case 7:
strcat( time_str,"July ");
break;
case 8:
strcat( time_str,"August ");
break;
case 9:
strcat( time_str,"September ");
break;
case 10:
strcat( time_str,"October ");
break;
case 11:
strcat( time_str,"November ");
break;
case 12:
strcat( time_str,"December ");
break;
}
sprintf( (time_str + strlen(time_str)),"%d, %d:%02d ",day_o_month,hours,minutes);
if (am_pm) strcat( time_str,"pm");
else strcat(time_str,"am");
time_len = strlen(time_str);
Hide_Mouse();
color = (byte) (palette[header_palette][BACK] <<4) | (palette[header_palette][TEXT]);
for (i=0;i <= time_len ;i++)
Draw( (byte) (max_screen_x-2-i),1,time_str[time_len-i],color);
for (;i<MAX_TIME_STR;i++)
Draw( (byte) (max_screen_x-2-i),1,' ',color);
Show_Mouse();
}
}
/***************************************************************************/
byte Old_Window(x,y)
byte x,y;
{
byte window = (byte) win_index;
for (window--;window!=255;window--)
if (x>=Win[window].left && x<= Win[window].right &&
y>=Win[window].top && y<= Win[window].bottom)
return( (int) win_index - window);
return( 0);
}
/***************************************************************************/
void Update_Mouse()
{
unsigned int mouse_x,mouse_y,button;
byte choice;
Item *item;
_asm mov ax,3 /* read current mouse position */
_asm sub bx,bx
_asm sub cx,cx
_asm sub dx,dx
_asm int 33h
_asm mov mouse_x,cx
_asm mov mouse_y,dx
_asm mov button,bx
mouse_x = mouse_x >> 3;
mouse_y = mouse_y >> 3;
/* decide what is going on with the mouse */
if (mouse_x == 0 && mouse_y == 0)
return;
if (mouse_x == last_x && mouse_y == last_y && button == last_button)
return;
/* select item if the mouse is over a selectable item */
choice = mouse_y-top-2;
if ( (mouse_x > left) && (mouse_x < right) &&
(choice > 0) && (choice <= current_menu->number_of_items) ){
if ( (choice != current_item->item_number)
&& ( last_x != mouse_x || last_y != mouse_y) ){
item = Number_To_Item( (byte) choice );
if (item->first_line != NULL){
event.action = GOTO_ITEM;
event.data = choice;
}
}
if ( !(last_button & 1) && (button & 1))
event.action = DO_ITEM;
}
/* the following statements improve the selection process */
else if ( (mouse_x > left) && (mouse_x < right) &&
(last_y < bottom ) && ( last_y > (byte) (top + 2) ) ){
if (last_y > mouse_y)
choice = 1;
else
choice = current_menu->number_of_items;
item = Number_To_Item( (byte) choice );
if (item->first_line != NULL){
event.action = GOTO_ITEM;
event.data = choice;
}
}
else if ( !(last_button & 1) && (button & 1)){
if (mouse_y == max_screen_y){
for (choice = 1; choice < 11; choice++){
if ((function_key[choice] != NULL) &&
(mouse_x <= function_key[choice]->title_length)){
event.action = FUNCTION_KEY;
event.data = choice;
break;
}
}
}
else if (mouse_y < top || mouse_y > bottom || mouse_x < left || mouse_x > right){
choice = Old_Window((byte)mouse_x,(byte)mouse_y);
if (choice > 0){
event.action = ESCAPE;
event.data = choice;
}
}
}
if ( !(last_button & 2) && (button & 2) ){
event.action = ESCAPE;
event.data = 1;
}
timer = timer_holder; /* reset timer */
last_x = mouse_x;
last_y = mouse_y;
last_button = button;
Show_Mouse();
}
/***************************************************************************/
void Scan_For_Letter( key_input )
char key_input;
{
Item *item = current_item->next_item;
key_input = key_input | 32;
for (; item != NULL; item = item->next_item)
if (item->first_line != NULL && (*(item->title)|32) == key_input){
event.action = GOTO_ITEM;
event.data = item->item_number;
return;
}
for (item = Home_Item(); item != current_item; item = item->next_item)
if (item->first_line != NULL && (*(item->title)|32) == key_input){
event.action = GOTO_ITEM;
event.data = item->item_number;
return;
}
}
/***************************************************************************/
void Get_Key_Input()
{
char key_input;
timer = timer_holder;
key_input = getch();
if (!key_input) /* if key input == 0 get the extended part */
switch(key_input = getch()){
case 72: /* up arrow */
event.action = MOVE_UP;
return;
case 71: /* home */
case 73: /* page up */
event.action = GOTO_TOP;
return;
case 80: /* down arrow */
event.action = MOVE_DOWN;
return;
case 79: /* end */
case 81: /* page down */
event.action = GOTO_END;
return;
case 75: /* back arrow */
event.action = ESCAPE;
event.data = 1;
return;
default:
if (key_input >58 && key_input < 69){
key_input -= 58;
if (function_key[key_input] != NULL){
event.action = FUNCTION_KEY;
event.data = key_input;
}
return;
}
return;
}
switch(key_input){
case 13:
event.action = DO_ITEM;
return;
case 27:
event.action = ESCAPE;
event.data = 1;
return;
case 32:
event.action = MOVE_DOWN;
return;
default:
Scan_For_Letter(key_input);
return;
}
}
/***************************************************************************/
void Wait_For_Event()
{
Show_Mouse();
event.action = NO_ACTION;
event.data = 0;
timer = timer_holder;
while( event.action == NO_ACTION ){
Update_Mouse();
Update_Time();
if (kbhit())
Get_Key_Input();
}
Hide_Mouse();
}