#include #include #include #include #include #include #include #include "ml.h" #include "kbd_keys.h" static int monochrome=0; static curs_shape=0; static int scr_height, scr_width; static char far *screen; static boolean init_video_ct(void *dummy) { char vmode; union REGS regs; struct text_info ti; store_scr_state(); vmode = *(char far *) MK_FP(0x0040,0x0049); if(vmode < 7) screen=MK_FP(0xB800,0x0000); else if(vmode==7) { monochrome=1; screen=MK_FP(0xB000,0x0000); error("Monochrome mode is not presented yet"); } else error("Call init_video_ct in bad video mode"); gettextinfo(&ti); scr_height=ti.screenheight; scr_width=ti.screenwidth; regs.h.ah=3; regs.h.bh=0; int86(0x10,®s,®s); curs_shape=regs.x.cx; hide_cursor(); return TRUE; } static boolean close_video_ct(void *dummy) { restore_scr_state(); printf( "Настоящая программа создана с использованием библиотеки оконного интер-\n" "фейса ML, которая позволяет создавать диалоговые приложения, работающие\n" "как в текстовом, так и в графическом режиме.По всем вопросам, связанным\n" "с использованием библиотеки, обращаться к И.И.Чудову, т. (095)962-5614.\n"); return TRUE; } static void hide_cursor_ct(void) { union REGS regs; regs.h.ch=regs.h.cl=0x20; regs.h.ah=1; int86(0x10,®s,®s); errno=0; } static void show_cursor_ct(void) { union REGS regs; regs.x.cx=curs_shape; regs.h.ah=1; int86(0x10,®s,®s); } static void absfwritexy_ct(int x, int y, int color, char *str) { char far *p; for( p=screen+y*160+x*2; *str; ){ *p++=*str++; *p++=color; } } static char *saveframe_ct(int x1, int y1, int x2, int y2) { char *fr,*frp; int linelen; char far *p0, far *ffrp; fr=(char *)Malloc((x2-x1+1)*(y2-y1+1)*2,"Not enough memory to save frame"); linelen=(x2-x1+1)*2; for(frp=fr,p0=screen+y1*160+x1*2; y1 <= y2; y1++, p0+= 160, frp+=linelen ){ ffrp=(char far *)frp; movedata(FP_SEG(p0),FP_OFF(p0),FP_SEG(ffrp),FP_OFF(ffrp),linelen); } return fr; } static void restoreframe_ct(char *fr, int x1, int y1, int x2, int y2) { char *frp; int linelen; char far *p0, far *ffrp; linelen=(x2-x1+1)*2; for(frp=fr,p0=screen+y1*160+x1*2; y1 <= y2; y1++, p0+= 160, frp+=linelen ){ ffrp=(void far *)frp; movedata(FP_SEG(ffrp),FP_OFF(ffrp),FP_SEG(p0),FP_OFF(p0),linelen); } free(fr); } static void drawborder_ct(int x1, int y1, int x2, int y2, int color, border_t border, char *up_name, char *down_name) { static char *dbl_set= "╔═╗" "║ ║" "╚═╝", *sim_set= "┌─┐" "│ │" "└─┘", *thick_set= "▄▄▄" "▌ ▐" "▀▀▀", *very_thick_set= "███" "█ █" "███", *set, buf[83],buf1[83]; int i; if(border == DOUBLE_BORDER) set=dbl_set; else if(border == SIMPLE_BORDER) set=sim_set; else if(border == THICK_BORDER) set=thick_set; else if(border == VERY_THICK_BORDER) set=very_thick_set; else if(border == NO_BORDER) return; else error("Invalid border type"); sprintf(buf,"%c%s%c",set[0],fillchar(buf1,x2-x1-1,set[1]),set[2]); absfwritexy(x1,y1,color,buf); sprintf(buf,"%c%s%c",set[3],fillchar(buf1,x2-x1-1,' '),set[5]); for(i=y1+1; i < y2; i++) absfwritexy(x1,i,color,buf); sprintf(buf,"%c%s%c",set[6],fillchar(buf1,x2-x1-1,set[7]),set[8]); absfwritexy(x1,y2,color,buf); mk_w_str(x1,x2,buf,up_name); absfwritexy((x1+x2-strlen(buf))/2,y1,color,buf); mk_w_str(x1,x2,buf,down_name); absfwritexy((x1+x2-strlen(buf))/2+1,y2,color,buf); } static void set_scr_state_ct(window_t *wnd) { window(wnd->x1+1,wnd->y1+1,wnd->x2+1,wnd->y2+1); textattr(wnd->act_col); ml_gotoxy(wnd->xpos,wnd->ypos); } static void draw_window_ct(window_t *wnd, int x1, int y1, int x2, int y2, int col, int bor_col, border_t border, char *up_name, char *down_name) { char buf[83]; int i; win_check(x1,y1,x2,y2); wnd->active_now=0; set_active_window(wnd); wnd->x1=x1; wnd->y1=y1; wnd->x2=x2; wnd->y2=y2; wnd->act_col=col; wnd->bor_col=bor_col; wnd->active_now=1; wnd->border=border; wnd->xpos=wnd->ypos=0; if(border != NO_BORDER) { drawborder_ct(x1,y1,x2,y2,bor_col,border,up_name,down_name); wnd->x1++; wnd->y1++; wnd->x2--; wnd->y2--; x1++; y1++; x2--; y2--; } fillchar(buf,x2-x1+1,' '); for(i=y1; i <= y2; i++) absfwritexy(x1,i,col,buf); set_scr_state_ct(wnd); } static void clear_window_ct(void) { clrscr(); ml_gotoxy(0,0); } static int getwidth_ct(char *str) { return strlen(str); } static int getheight_ct(char *str) { return 1; } static void settextcolor_ct(int color) { textattr(color); } static int gettextcolor_ct(void) { struct text_info ti; gettextinfo(&ti); return ti.attribute; } static void emulate_cursor_ct(int x, int y) { gotoxy(getcurwin()->xpos+1,getcurwin()->ypos+1); } static int getmaxX_ct(void) { return scr_width; } static int getmaxY_ct(void) { return scr_height; } static boolean mouse2text_ct(int *xt, int *yt) { unsigned x,y; if(!mouse_present) return FALSE; ask_mouse_event(&x,&y); *xt=x/8; *yt=y/8; return TRUE; } static int text2scrX_ct(int x) { return x; } static int text2scrY_ct(int y) { return y; } video_interface_t COL_PC_TEXT_INTERFACE={ VID_TEXT_MODE, absfwritexy_ct, settextcolor_ct, gettextcolor_ct, set_scr_state_ct, draw_window_ct, clear_window_ct, saveframe_ct, restoreframe_ct, getwidth_ct, getheight_ct, show_cursor_ct, hide_cursor_ct, emulate_cursor_ct, getmaxX_ct, getmaxY_ct, mouse2text_ct, text2scrX_ct,text2scrY_ct, init_video_ct, close_video_ct };