/*******************************************************************/ // "Меркурий"-"Правда" - open source переводчик // распространяется в соответсвии с лицензией GNU v 2.0 // // библиотека интерфейса с текстовым терминалом (X-Window) // Анисимов Д.В. сегодня /*******************************************************************/ # include # include # include # include # include # include # include # include # include # include # include # include # include # include "slowo.xbm" # define ACS_ULCORNER 0x101 # define ACS_LLCORNER 0x102 # define ACS_URCORNER 0x103 # define ACS_LRCORNER 0x104 # define ACS_HLINE 0x105 # define ACS_VLINE 0x106 # define ACS_ULCORNER2 0x107 # define ACS_LLCORNER2 0x108 # define ACS_URCORNER2 0x109 # define ACS_LRCORNER2 0x10a # define ACS_HLINE2 0x10b # define ACS_VLINE2 0x10c # define DELTA 5 // величина "увеличения" окна long *Symbol ; uchar *Color ; short max_x,max_y ; short size_x,size_y ; int Symbol_W,Symbol_H; /* Ширина и высота буковки */ int Shiftstatus ; /* Какие нажаты спецклавиши */ char *FontName ; Display *Dis ; int i_Scr ; Window Win ; Colormap Colormap1 ; XColor xColor[16] ; XFontStruct *FontInfo ; Pixmap Pixmap1 ; char F_Rus=0 ; static short T_ang_rus[256] ; short RussKomb=0 ; // -------------------- графический контекст ------------------------------- class t_GC { public : Window Win ; GC GC1 ; t_GC( Window Win ); t_GC( Window Win, unsigned long Color1, unsigned long Color2 ); ~t_GC( void ); void SetForeground( unsigned long Color ); void SetBackground( unsigned long Color ); void DrawImageString( short x, short y, char *Text ); }; class t_Save_Screen { long *stek ; // запоминание областей экрана long l_stek ; // длинна массива Stek long j_stek ; // указатель последнего свободного байта public: t_Save_Screen( long L ); ~t_Save_Screen( void ); void save ( short y1, short x1, short y2, short x2 ); void save_rame( short y1, short x1, short y2, short x2 ); void restore( void ); } ; short Cur_X=0,Cur_Y=0 ; short n_Line,n_Col ; char Run=0 ; // признак того, что графика запущена static char TextFont[100]="" ; t_Save_Screen Save( 60000 ) ; void s_rame( short y1, short x1, short y2, short x2, uchar f ); void s_rame2( short y1, short x1, short y2, short x2, uchar f ); void s_quadro( short y1, short x1, short y2, short x2, uchar f ); void make_ang_rus( void ); /* ----------------------------------------------------------------------- */ void s_begin_schone( int argc, char *argv[] ) { short i,f=0,Size_X,Size_Y ; Window Root ; setlocale( LC_ALL,"" ); max_x=256 ; max_y=100 ; Symbol=(long *)Calloc( max_x*max_y,sizeof(long) ); Color =(uchar *)Calloc( max_x*max_y,1 ); for( i=0 ; imax_bounds.width; Symbol_H = FontInfo->ascent + FontInfo->descent; Size_X=100*Symbol_W+5 ; Size_Y=50*Symbol_H+DELTA ; // --------------- открыть окошко -------------------------- Win = XCreateSimpleWindow( Dis,RootWindow( Dis,i_Scr), 0,0,Size_X,Size_Y,5, BlackPixel(Dis,i_Scr), BlackPixel(Dis,i_Scr) ); // --------------- захватить цвета -------------------------- Colormap1 = DefaultColormap( Dis,DefaultScreen(Dis) ); for( i=0 ; i<16 ; i++ ) { XColor Color1 ; unsigned short V ; if( i>=8 ) V=0x8000 ; else V=0 ; if( (i&0x01)!=0 ) Color1.blue = V+0x7FFF ; else Color1.blue = 0 ; if( (i&0x02)!=0 ) Color1.green = V+0x7FFF ; else Color1.green = 0 ; if( (i&0x04)!=0 ) Color1.red = V+0x7FFF ; else Color1.red = 0 ; if( i==7 ) Color1.red=Color1.green=Color1.blue=0xBFFF ; if( i==8 ) Color1.red=Color1.green=Color1.blue=0xBFFF ; Color1.flags = DoRed|DoGreen|DoBlue ; XAllocColor( Dis,Colormap1,&Color1 ); xColor[i] =Color1 ; } // ------------ сделать иконку чтоб красиво было -------------- Pixmap Pix1 = XCreatePixmapFromBitmapData( Dis,RootWindow( Dis,i_Scr), lingvo_bits,lingvo_width,lingvo_height,1,0,1 ); char *sSlowo="Mercury" ; if( !XStringListToTextProperty( &sSlowo,1,&WinName ) ) exit(1); // -------------- назначить атрибуты окна ----------------------- SizeHints.flags = 0 ; WMHints.flags = StateHint | IconPixmapHint | InputHint ; WMHints.initial_state = NormalState ; WMHints.input = True ; WMHints.icon_pixmap = Pix1 ; ClassHint.res_name = argv[0] ; ClassHint.res_class = "Mercury" ; XSetWMProperties ( Dis,Win, &WinName,&WinName, argv,argc, &SizeHints, &WMHints, &ClassHint ); XSelectInput( Dis,Win,ExposureMask | KeyPressMask | KeyReleaseMask ); XMapWindow( Dis,Win ); XWindowAttributes Attr ; XGetWindowAttributes( Dis,Root,&Attr ); Pixmap1=XCreatePixmap( Dis,Root,Attr.width,Attr.height,Attr.depth ); Run=1 ; } /* ----------------------------------------------------------------------- */ void s_begin_schone( void ) { char *argv[1] ; argv[0]="mercury" ; s_begin_schone( 1,argv ); } /* ----------------------------------------------------------------------- */ void s_end_schone( void ) { XDestroyWindow( Dis,Win ); XCloseDisplay( Dis ); Run=0 ; } /* ----------------------------------------------------------------------- */ void s_nacht( void ) { long i ; for( i=0 ; ifid ); f=Color[0] ; GC.SetForeground( f&0x0f ); GC.SetBackground( (f>>4)&0x0f ); for( i=0 ; i>4)&0x0f ); } if( 256'] ='Ю'; T['^'] =','; T['&'] ='.'; T['$'] ='"'; T['$'] =':'; } /***************************************************************************/ void s_refresh( void ) { s_redraw(); t_GC GC1( Pixmap1,0,0 ) ; XCopyArea( Dis,Pixmap1,Win,GC1.GC1,0,0,n_Col*Symbol_W,n_Line*Symbol_H,0,0 ); } /***************************************************************************/ void s_get_size( short &sx, short &sy ){ sx=n_Col ; sy=n_Line ; } void s_get_size( short *sx, short *sy ){ *sx=n_Col ; *sy=n_Line ; } short s_get_sx( void ) { return n_Col ; } short s_get_sy( void ) { return n_Line ; } void x_set_fonts( void ){;} void s_set_font( char *F ){ Strcpy( TextFont,F,100 ); } char *s_get_font( void ){ return TextFont ; } short s_clear_cursor( void ){ return 0; } void s_set_ruskomb( short Komb ){ RussKomb=Komb ; } char s_run( ){ return Run ; } char s_x_version( ){ return 1 ; } /***************************************************************************/ void s_debug( ) { short i,i1 ; char *Text="Вот так работает Unicode" ; XChar2b Text16[102] ; for( i=0 ; i<100 ; i++ ) { Text16[i].byte1=7 ; Text16[i].byte2=50+i ; } XFontStruct *FontInfo1 ; // "-adobe-courier-bold-r-normal--10-100-75-75-m-60-iso10646-1" ; // "-adobe-helvetica-bold-r-normal--10-100-75-75-p-60-iso10646-1" ; // "-monotype-arial unicode ms-medium-r-normal--0-0-0-0-c-0-iso10646-1" ; // "-b&h-lucida sans unicode-medium-r-normal--0-0-0-0-p-0-iso10646-1" ; // ну так, более или менее, но все равно фигня // "-monotype-courier new-medium-r-normal--0-0-0-0-m-0-iso10646-1"; // этот хорош, да еще и моноширинный // "-misc-fixed-medium-r-semicondensed--13-120-75-75-c-60-iso10646-1" ; // этот хорош, моноширинный, с псевдографикой char *FontName1="-misc-fixed-bold-r-normal--18-120-100-100-c-90-iso10646-1" ; FontInfo1 = XLoadQueryFont( Dis, FontName1 ); GC GC1=XCreateGC( Dis,Win,0,NULL ); XSetFunction( Dis, GC1, GXcopy ); XSetForeground( Dis,GC1, xColor[0].pixel ); XSetBackground( Dis,GC1, xColor[15].pixel ); XSetFont( Dis, GC1, FontInfo1->fid ); for( i1=0 ; i1<16 ; i1++ ) { for( i=0 ; i<100 ; i++ ) { Text16[i].byte1=i1 ; Text16[i].byte2=50+i ; } XDrawImageString16( Dis,Win,GC1,20,20+40*i1,Text16,100 ); for( i=0 ; i<100 ; i++ ) { Text16[i].byte1=i1 ; Text16[i].byte2=151+i ; } XDrawImageString16( Dis,Win,GC1,20,40+40*i1,Text16,100 ); } }