#include #include #include #include #include #include #include #include #include "ml.h" #include "ml_mouse.h" #include "kbd_keys.h" static int scr_height, scr_width, char_height, char_width; static char *old_text_screen; static boolean cursor_on; static boolean init_video_gt(void *vp) /* vp - í⮠㪠§ â¥«ì ­  áâàãªâãàã init_video_par_t …᫨ vp=NULL, â® £à ä¨ª  ­¥ ¨­¨æ¨ «¨§¨àã¥âáï. */ { init_video_par_t *ivp=(init_video_par_t *)vp; int GrErr; store_scr_state(); store_scr(&old_text_screen); if(ivp) { if(ivp->mem_driver) registerbgidriver(ivp->mem_driver); initgraph(&ivp->gd,&ivp->gm,ivp->bgidir); if(GrErr=graphresult()) { restore_scr(&old_text_screen); restore_scr_state(); return FALSE; } } char_height=textheight("W"); char_width=textwidth("W"); scr_height=getmaxy()/char_height; scr_width=getmaxx()/char_width; if(mouse_present) { ms_set_vminmax(0,getmaxy()); ms_set_hminmax(0,getmaxx()); } cursor_on=FALSE; return TRUE; } static boolean close_video_gt(void *cp) { /* restorecrtmode(); */ closegraph(); restore_scr(&old_text_screen); restore_scr_state(); return TRUE; } static void hide_cursor_gt(void) { cursor_on=FALSE; } static void show_cursor_gt(void) { cursor_on=TRUE; } static void __chk_gr_error(int color, int xg, int yg, int i) { int k; string buf; if(k=graphresult()){ setcolor(color); sprintf(buf,"c=%d, k=%s, i=%d",color,grapherrormsg(k),i); outtextxy(xg,yg+15,buf); } } static void absfwritexy_gt(int x, int y, int color, char *str) { struct fillsettingstype old_fs; int old_col; int xg,yg; struct viewporttype vp; if(strlen(str)==0) return; getviewsettings(&vp); xg=x*char_width-vp.left; yg=y*char_height-vp.top; getfillsettings(&old_fs); old_col=getcolor(); setfillstyle(SOLID_FILL,color >> 4); bar(xg,yg,xg+textwidth(str)-1,yg+textheight(str)-1); setcolor(color); outtextxy(xg,yg,str); setcolor(old_col); setfillstyle(old_fs.pattern,old_fs.color); } static char *saveframe_gt(int x1, int y1, int x2, int y2) { unsigned len,h=char_height,w=char_width; void *mem; setviewport(0,0,scr_width*w,scr_height*h,FALSE); len=imagesize(x1*w,y1*h,(x2+1)*w-1,(y2+1)*h-1); if(len==0xFFFF) error("Window size is too big for saveframe"); mem=Malloc(len,"Not enough memory to save frame"); getimage(x1*w,y1*h,(x2+1)*w-1,(y2+1)*h-1,mem); return mem; } static void restoreframe_gt(char *fr, int x1, int y1, int x2, int y2) { unsigned h=char_height,w=char_width; if(fr) { setviewport(0,0,scr_width*w,scr_height*h,FALSE); putimage(x1*w,y1*h,fr,COPY_PUT); free(fr); } } static void drawborder_gt(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; chkinit(); 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]); */ buf[1]=0; for(i=y1+1; i < y2; i++) { buf[0]=set[3]; absfwritexy(x1,i,color,buf); buf[0]=set[5]; absfwritexy(x2,i,color,buf); } /* 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,y2,color,buf); } static void set_scr_state_gt(window_t *wnd) { int w,h; string buf; h=char_height; w=char_width; setcolor(wnd->act_col); setviewport(w*(wnd->x1),h*(wnd->y1),w*(wnd->x2+1)-1,h*(wnd->y2+1)-1,1); moveto(wnd->xpos,wnd->ypos); } static void clear_window_gt(void) { struct viewporttype vp; int col; window_t *w; getviewsettings(&vp); w=getcurwin(); col=w->act_col; setfillstyle(SOLID_FILL,col >> 4); bar(0,0,char_width*(w->x2-w->x1+1),char_height*(w->y2-w->y1+1)-1); } static void draw_window_gt(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) { int i,h,w; win_check(x1,y1,x2,y2); wnd->active_now=0; /* */ 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) { setviewport(0,0,scr_width*char_width,scr_height*char_height,FALSE); drawborder_gt(x1,y1,x2,y2,bor_col,border,up_name,down_name); wnd->x1++; wnd->y1++; wnd->x2--; wnd->y2--; } set_active_window(wnd); clear_window_gt(); } static int getwidth_gt(char *str) { return strlen(str); } static int getheight_gt(char *str) { return 1; } static void settextcolor_gt(int color) { setcolor(color); } static int gettextcolor_gt(void) { return getcolor(); } static void emulate_cursor_gt(int x, int y) { char buf[85]; int xg,yg,oc; window_t *w=getcurwin(); if(!cursor_on) return; xg=x*char_width; yg=(y+1)*char_height-1; getimage(xg,yg-1,xg+char_width,yg-1,buf); oc=getcolor(); setcolor(~w->act_col); line(xg,yg-1,xg+char_width,yg-1); setcolor(oc); while(!ml_issignal()); putimage(xg,yg-1,buf,COPY_PUT); } static int getmaxX_gt(void) { return scr_width; } static int getmaxY_gt(void) { return scr_height; } static boolean mouse2text_gt(int *xt, int *yt) { unsigned x,y; if(!mouse_present) return FALSE; ask_mouse_event(&x,&y); *xt=x/char_width; *yt=y/char_height; return TRUE; } static int text2scrX_gt(int x) { return x*char_width; } static int text2scrY_gt(int y) { return y*char_height; } video_interface_t COL_PC_GRAPH_INTERFACE={ VID_GRAPH_MODE, absfwritexy_gt, settextcolor_gt, gettextcolor_gt, set_scr_state_gt, draw_window_gt, clear_window_gt, saveframe_gt, restoreframe_gt, getwidth_gt, getheight_gt, show_cursor_gt, hide_cursor_gt, emulate_cursor_gt, getmaxX_gt, getmaxY_gt, mouse2text_gt, text2scrX_gt,text2scrY_gt, init_video_gt, close_video_gt };