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 >
Wrap
Text File
|
1991-10-15
|
11KB
|
505 lines
/***************************************************************************/
void Hide_Cursor( void )
{
_asm mov cx, 1000h
_asm mov ax, 0100h
_asm int 10h
}
/***************************************************************************/
void Show_Cursor( void )
{
_asm mov cx, 0607h
_asm mov ax, 0100h
_asm int 10h
}
/***************************************************************************/
void _fastcall Put_Cursor(col,row)
byte col,row;
{
_asm mov ah,02
_asm sub bh,bh
_asm mov dh,row
_asm mov dl,col
_asm int 10h
}
/***************************************************************************/
void Hide_Mouse( void )
{
_asm mov ax,2
_asm int 33h
}
/***************************************************************************/
void Show_Mouse( void )
{
_asm mov ax,1
_asm int 33h
}
/***************************************************************************/
void _fastcall Draw(x,y,thing,color)
register byte x,y,color;
char thing;
{
*(video_start+x+max_screen_x*y) = (int) ( (byte) thing| (int) (color <<8) );
}
/***************************************************************************/
byte _fastcall Read_Color(x,y)
byte x,y;
{
return( *(video_start+x+max_screen_x*y) >> 8);
}
/***************************************************************************/
void _fastcall Put_Color(x,y,color)
byte x,y,color;
{
*(video_start+x+max_screen_x*y) = (*(video_start+x+max_screen_x*y) & 255) | (color << 8);
}
/***************************************************************************/
void _fastcall Fill_Screen(thing,color)
char thing;
byte color;
{
register int x, fill_value;
fill_value = ( (byte) thing | color << 8);
for ( x = max_screen_x * (max_screen_y+1); x>=0 ;x--)
*(video_start+x) = fill_value;
}
/***************************************************************************/
void Blank_Screen()
{
byte *storage;
register byte x,y;
storage = (byte *) malloc( (max_screen_x)*(max_screen_y+1));
if (storage == NULL) return;
for ( y = 0; y<= max_screen_y; y++)
for (x = 0; x< max_screen_x; x++)
*(storage + max_screen_x*y+x ) = Read_Color(x,y);
for ( y = 0; y<= max_screen_y; y++)
for (x = 0; x< max_screen_x; x++)
Put_Color(x,y,0);
Hide_Mouse();
Wait_For_Event();
event.action = NO_ACTION;
Show_Mouse();
for ( y = 0; y<= max_screen_y; y++)
for (x = 0; x< max_screen_x; x++)
Put_Color( x,y, *(storage+max_screen_x*y+x) );
free(storage);
}
/***************************************************************************/
void Clean_Up()
{
Fill_Screen(' ',7);
Put_Cursor(0,0);
Show_Cursor();
Hide_Mouse();
}
/***************************************************************************/
int *Store_Screen(x1,x2,y1,y2)
byte x1,x2,y1,y2;
{
int *storage_addr;
register int *storage_pointer;
register byte x,y;
if ( (storage_addr = (int *) malloc( (x2-x1+1) * (y2-y1+1) *2 )) == NULL){
Critical_Error(MEMORY,"Screen Storing");
}
storage_pointer = storage_addr;
for (y = y1; y <= y2; y++){
for (x = x1; x <= x2; x++){
*storage_pointer = *(video_start+x+max_screen_x*y);
storage_pointer++;
}
}
return(storage_addr);
}
/***************************************************************************/
void Restore_Screen(storage_addr,x1,x2,y1,y2)
byte x1,x2,y1,y2;
int *storage_addr;
{
register byte x,y;
register int *storage_pointer;
storage_pointer = storage_addr;
for (y = y1; y <= y2; y++){
for (x = x1; x <= x2; x++){
*(video_start + (max_screen_x*y) +x) = *storage_pointer;
storage_pointer++;
}
}
free (storage_addr);
return;
}
/***************************************************************************/
void Display_Menu(hi_item)
Item *hi_item;
{
byte text,border,title,back;
register byte x,y,i;
char *str;
Item *item;
back = palette[current_menu->palette][ BACK ] << 4;
text = palette[current_menu->palette][ TEXT ] | back;
title = palette[current_menu->palette][ TITLE ] | back;
if (hi_item == NULL){
border = palette[current_menu->palette][ HIGHLIGHT ] | back;
if (shadow) Display_Shadow(left,right,top,bottom);
}
else
border = palette[current_menu->palette][ BORDER ] | back;
/* draw top line */
x = left;
y = top;
Draw(x, y,'╔', border);
for (x++; x < right; x++)
Draw(x, y,'═', border);
Draw(x, y, '╗', border);
/* draw title centered*/
x = left;
y++;
Draw(x, y, '║', border);
for (i = (width-current_menu->title_length)/2; i!=0; i--)
Draw(++x, y,' ', title);
for (str = (char *) current_menu->title; *str != '\0'; str++)
Draw(++x, y, *str, title);
while ( x < right )
Draw(++x, y,' ', title);
Draw(x, y,'║', border);
/* draw title bar */
x = left;
y++;
Draw(x, y,'╠', border);
for (x++; x < right; x++)
Draw(x, y,'═', border);
Draw(x, y,'╣', border);
/* draw body */
item = current_menu->first_item;
while (item != NULL){
y++;
x = left;
if ( item->first_line != NULL ){
if (item == hi_item)
text = palette[current_menu->palette][ HIGHLIGHT ] | back;
Draw(x, y, '║', border);
Draw(++x, y, ' ', text);
for( str = (char *) item->title; *str != '\0'; str++)
Draw(++x, y, *str, text);
while( x < right )
Draw(++x, y, ' ', text);
Draw(x, y, '║', border);
if (item == hi_item)
text = palette[current_menu->palette][ TEXT ] | back;
}
else{ /* draw sub-titles centered*/
x = left;
Draw(x, y, '╟', border);
for (i= (width - item->title_length)/2-1; i!=0; i--)
Draw(++x, y, '─', border);
for (str = (char *) item->title; *str != '\0'; str++)
Draw(++x, y, *str, border);
while (x < right )
Draw(++x, y, '─', border);
Draw(x, y, '╢', border);
}
item = item->next_item;
}
/* draw bottom */
x = left;
y++;
Draw(x, y, '╚', border);
for(x++; x < right; x++)
Draw(x, y, '═', border);
Draw(x, y, '╝', border);
}
/***************************************************************************/
void Select(new_item)
/* unselect current_item and then select new_item */
Item *new_item;
{
register byte x,y;
byte back,text,select;
char *str;
back = palette[current_menu->palette][ BACK ] << 4;
text = palette[current_menu->palette][ TEXT ] | back;
back = palette[current_menu->palette][ S_BACK ] << 4;
select = palette[current_menu->palette][ SELECT ] | back;
y = top + current_item->item_number + 2;
x = left + 1;
Draw(x++, y, ' ', text);
for(str = (char *)current_item->title; *str != '\0';str++)
Draw(x++, y, *str, text);
while (x < right)
Draw(x++, y, ' ', text);
current_item = new_item;
y = top + current_item->item_number + 2;
x = left + 1;
Draw(x++, y, ' ', select);
for(str = (char *) current_item->title; *str != '\0';str++)
Draw(x++, y, *str, select);
while ( x < right)
Draw(x++, y, ' ', select);
Win[win_index].item = current_item;
}
/***************************************************************************/
void Display_Text_Box(lines,x1,width,y1,height,pal)
char *lines[];
byte x1,width,y1,height,pal;
{
byte text,border,back,x2,y2;
register byte x,y,i;
char *str;
int *storage;
if (x1 == CENTER)
x1 = (max_screen_x-width)/2;
if (y1 == CENTER)
y1 = max_screen_y/2 - 2;
x2 = x1+width;
y2 = y1+height;
if ( x2 >= (byte)(max_screen_x-1) ){
x2 = max_screen_x-2;
x1 = x2 - width;
}
if (y2 > (byte)(max_screen_y-1) ){
y2 = max_screen_y-1;
y1 = y2 - height;
}
if ( x1 >= x2 || y1 >= y2 ){
Error_Box("Unable to display text box.","The box is too large.");
return;
}
storage = Store_Screen(x1,x2,y1,y2);
back = palette[pal][ BACK ] << 4;
text = palette[pal][ TEXT ] | back;
border = palette[pal][ HIGHLIGHT ] | back;
/* draw top */
Draw(x = x1, y1, '┌', border);
for (x++; x < x2; x++)
Draw(x, y1, '─', border);
Draw(x, y1,'┐', border);
/* draw filling */
for (y=y1+1;y<y2;y++){
x = x1;
Draw(x, y, '│', border);
str = lines[y-y1-1];
for( i=( x2-x1-strlen(str)-1 )/2 ;i != 0; i--)
Draw(++x, y, ' ', text);
while (*str != '\0'){
Draw(++x, y, *str, text);
str++;
}
while( x < x2 )
Draw(++x, y, ' ', text);
Draw(x, y,'│', border);
}
/* draw bottom */
Draw(x = x1, y2, '└', border);
for(x++; x < x2; x++)
Draw(x, y2, '─', border);
Draw(x, y2, '┘', border);
if (shadow) Display_Shadow(x1,x2,y1,y2);
do
Wait_For_Event();
while (event.action == GOTO_ITEM);
if (shadow) Remove_Shadow(x1,x2,y1,y2);
Restore_Screen(storage,x1,x2,y1,y2);
/* force mouse reset */
last_x = 0;
}
/**************************************************************************/
void Display_Item_Text()
{
char *line[25];
byte x,y,width=0,i=0,color;
char *place = current_item->first_line->text_line;
current_text = current_item->first_line->next_line;
while (current_text != NULL){
line[i] = current_text->text_line;
if ( strlen(line[i]) > width)
width = strlen(line[i]);
current_text = current_text->next_line;
i++;
if ( i == 25)
current_text = NULL;
}
line[i] = NULL;
width +=3;
i++;
place = After_Comma(place);
x = Get_Value(place, CENTER );
place = After_Comma(place);
y = Get_Value(place, CENTER );
place = After_Comma(place);
color = Get_Palette(place,message_palette);
if (cascade && x == CENTER && y == CENTER ){
x = left + cascade_x;
y = top + cascade_y;
}
Display_Text_Box(line,x,width,y, i ,color);
}
/***************************************************************************/
void Error_Box(line1,line2)
char line1[],line2[];
{
byte x,y,width;
char title[] = "Error - Error - Error - Error";
char foot[] = "Press any key to continue.";
char blank[] = " ";
char *lines[7];
width = strlen(title);
if (width < strlen(line1) )
width = strlen(line1);
if (width < strlen(line2) )
width = strlen(line2);
width +=3;
x = CENTER;
y = CENTER;
lines[0] = title;
lines[1] = blank;
lines[2] = line1;
lines[3] = line2;
lines[4] = blank;
lines[5] = foot;
lines[6] = NULL;
Display_Text_Box(lines,x,width,y,7,error_palette);
}
/***************************************************************************/
void Display_Shadow( x1, x2, y1, y2)
byte x1,x2,y1,y2;
{
byte x, y;
++x1;
++x2;
++y1;
++y2;
for ( x = x1; x <= x2; x++){
*(shad_buf+x) = Read_Color( x, y2 );
Put_Color( x, y2, shadow_color);
}
for (y = y1; y < y2; y++){
*(shad_buf+max_screen_x+y) = Read_Color( x2 , y );
Put_Color( x2 ,y, shadow_color);
}
}
/***************************************************************************/
void Remove_Shadow( x1, x2, y1, y2)
byte x1, x2, y1, y2;
{
byte x, y;
++x1;
++x2;
++y1;
++y2;
for ( x = x1; x <= x2; x++ )
Put_Color( x, y2, *(shad_buf+x) );
x =- x1;
for ( y = y1; y < y2; y++)
Put_Color( x2, y, *(shad_buf+max_screen_x+y) );
}