📄 2dview.c
字号:
INPUTDEV = new SMonitorDevice(); RUN::conv_area.set_min_size_x( 10.0 ); RUN::conv_area.set_min_size_y( 10.0 ); double extent= 200; RUN::conv_area.set_max_size_x( extent ); RUN::conv_area.set_max_size_y( extent ); RUN::conv_area.set_min_pos_x( -0.5*extent ); RUN::conv_area.set_min_pos_y( -0.5*extent ); RUN::conv_area.set_max_pos_x( 0.5*extent ); RUN::conv_area.set_max_pos_y( 0.5*extent ); } else INPUTDEV = new AsciiDevice(6010); Options::set_defaults(); INPUTDEV->set_defaults(); const char * HOME = getenv("HOME"); if ( strlen(HOME) + strlen(PACKAGE) + strlen(".conf") + 3 < MAX_NAME_LEN ) { strcpy(Options::conf_file,HOME); strcat(Options::conf_file,"/."); strcat(Options::conf_file,PACKAGE); strcat(Options::conf_file,".conf"); //test for existence of Options::conf_file std::ifstream is(Options::conf_file); if (!is) { std::ofstream out(Options::conf_file); if (!out) { ERROR_OUT << "\ncouldn't open " << Options::conf_file << " to create a conf file"; out.close(); } else { Options::generate_file_options(out,PACKAGE); std::cout << "\ncreated config file, " << Options::conf_file; } Options::conf_file[0]= '\0'; } is.close(); } else ERROR_OUT << "\nHOME path too long"; Options::read(argc,argv); std::cout << std::flush; INPUTDEV->set_initial_area( Options::plane ); ///////////////////////////////////// Colormap cmap; Cursor cursor; Font font; Font font_inside; XSizeHints hint; int screen; unsigned long fg, bg; WIN::disp = XOpenDisplay(0); if (WIN::disp == (Display *) NULL) { ERROR_OUT << "\nCould not open display!"; exit(1); } WIN::x11_fd= XConnectionNumber(WIN::disp); RGB_DB::disp= WIN::disp; //cout << "\n connection fd= " << WIN::x11_fd << flush; screen = DefaultScreen(WIN::disp); fg = BlackPixel(WIN::disp, screen); bg = WhitePixel(WIN::disp, screen); //hint.x = 150; hint.y = 10; hint.x = 200; hint.y = 20; hint.width = Options::window_size_x; hint.height = Options::window_size_y; hint.flags = PPosition | PSize; WIN::win_width = hint.width; WIN::win_height = hint.height;//-letheight-1; WIN::win_depth = DefaultDepth (WIN::disp, screen); WIN::window = XCreateSimpleWindow (WIN::disp, DefaultRootWindow(WIN::disp), hint.x, hint.y, hint.width, hint.height, 5, fg, bg); WIN::pixmap = XCreatePixmap (WIN::disp, WIN::window, WIN::win_width, WIN::win_height, WIN::win_depth); XSetStandardProperties( WIN::disp, WIN::window, PACKAGE_VERSION, PACKAGE, None, //WIN::icon_pixmap, argv, argc, &hint ); WIN::gc = XCreateGC (WIN::disp, WIN::window, 0, 0); XSetGraphicsExposures(WIN::disp, WIN::gc, 0); /* IMPORTANT! If you do not specifically ask not to get Expose events, every XCopyArea will generate one, & the event queue will fill up. */ XSetLineAttributes(WIN::disp, WIN::gc, Options::line_thickness,LineSolid, CapButt,JoinMiter); //XCopyGC(WIN::disp,WIN::gc,0,WIN::xor_gc); WIN::xor_gc= XCreateGC (WIN::disp, WIN::window, 0, 0); //XSetFunction(WIN::disp,WIN::xor_gc,GXxor); XSetFunction(WIN::disp,WIN::xor_gc,GXinvert); //XSetPlaneMask(WIN::disp,WIN::xor_gc,3); //wichtig, aber warum? ;-) font= XLoadFont(WIN::disp,Options::font_name); font_inside= XLoadFont(WIN::disp,Options::font_inside); //font = XLoadFont(WIN::disp, "10x20\0"); /* If you don't have this font, try replacing it with 9x15\0 */ XSetFont(WIN::disp, WIN::gc, font_inside); WIN::bg_gc = XCreateGC (WIN::disp, WIN::window, 0, 0); WIN::sl_gc = XCreateGC (WIN::disp, WIN::window, 0, 0); WIN::bt_gc = XCreateGC (WIN::disp, WIN::window, 0, 0); XSetBackground (WIN::disp, WIN::gc, bg); XSetForeground (WIN::disp, WIN::gc, fg); XSetBackground (WIN::disp, WIN::xor_gc, bg); XSetForeground (WIN::disp, WIN::xor_gc, fg); XSetForeground (WIN::disp, WIN::bg_gc, bg); /* fg of pixmap is bg of window */ XSetBackground (WIN::disp, WIN::bg_gc, fg); XSetForeground (WIN::disp, WIN::sl_gc, bg); XSetBackground (WIN::disp, WIN::sl_gc, fg); XSetForeground (WIN::disp, WIN::bt_gc, fg); XSetBackground (WIN::disp, WIN::bt_gc, bg); XSetFont(WIN::disp, WIN::bg_gc, font); XSetFont(WIN::disp, WIN::sl_gc, font); init_window_hints(WIN::disp,WIN::window); init_window_input(WIN::disp,WIN::window);#if 0 XMoveWindow(WIN::disp, WIN::window, 10,10); XWindowChanges dum; dum.x= 10; dum.y= 10; XConfigureWindow(WIN::disp, WIN::window, CWX | CWY, &dum);#endif XMapRaised (WIN::disp, WIN::window); //XMapWindow(WIN::disp, WIN::window);#if 0 if (Options::set_window_pos) XMoveWindow(WIN::disp, WIN::window, Options::window_left_x,Options::window_top_y);#endif /* Erase cursor. Just delete next 5 lines if any error. */ cmap = XDefaultColormap(WIN::disp, screen);#if 1 //XAllocNamedColor(WIN::disp, cmap, "Black", &exact, &black); cursor = XCreateFontCursor(WIN::disp, XC_crosshair); //XRecolorCursor(WIN::disp, cursor, &black, &black); XDefineCursor(WIN::disp, WIN::window, cursor);#endif //XFillRectangle (WIN::disp, WIN::pixmap, WIN::bg_gc, 0, 0, WIN::win_width, WIN::win_height); { XpmCreatePixmapFromData( WIN::disp, WIN::window, rcssmonitor_xpm, &WIN::icon_pixmap, &WIN::icon_mask, NULL ); XWMHints * h = XGetWMHints( WIN::disp, WIN::window ); XWMHints wm_hints; bool got_hints = ( h != 0 ); if ( ! got_hints ) { h = &wm_hints; h->flags = 0; } h->icon_pixmap = WIN::icon_pixmap; h->icon_mask = WIN::icon_mask; h->flags |= IconPixmapHint | IconMaskHint; XSetWMHints( WIN::disp, WIN::window, h ); if ( got_hints ) { XFree( (char *)h ); } }///////////////////// // View Converter init init_4_tree_and_display(); //init the menu WIN::menu= new MenuX11(WIN::disp,WIN::window,WIN::bt_gc,WIN::win_width,15); WIN::menu->set_background_color(RGBcolor(0xcc,0xcc,0xcc)); WIN::menu->set_foreground_color(RGBcolor(0,0,0)); if (INPUTDEV->init_menu(WIN::menu)) WIN::menu->redraw();#ifdef POPUP //init the popup WIN::popup= new PopupX11(WIN::disp,WIN::window,WIN::bt_gc); WIN::popup->set_background_color(RGBcolor(0xcc,0xcc,0xcc)); WIN::popup->set_foreground_color(RGBcolor(0,0,0)); WIN::popup->set_highlight_color(RGBcolor(0x99,0x99,0x99)); WIN::popup->set_popup_invisible(); INPUTDEV->init_popup(WIN::popup);#endif //init frames INPUTDEV->init_frames(&RUN::builder); if ( RUN::conv_area.needs_update() ) { RUN::conv_area.update(); RUN::conv_area.get_area(Options::plane); //this area will be restored when 'i' is pressed! DDD->ASetPlainArea( Options::plane ); } if (RUN::builder.new_bg_color) { RUN::builder.new_bg_color= false; XSetForeground(WIN::disp, WIN::bg_gc, DDD->AGetColor(RUN::builder.bg_color)); DDD->set_background_color( RUN::builder.bg_color ); //WIN::menu->set_background_color( RUN::builder.bg_color ); } redraw_current_tree(); WIN::menu->redraw(); WIN::clip_rect.set_ratio(WIN::win_width,WIN::win_height); INPUTDEV->init_connection(); bool received = false; int nodata_seconds = 0; int timeover_seconds = 0; std::time_t last_receive_time = std::time( NULL );//Gezieltes Abfragen der sockets fd_set rfds; struct timeval tv; int retval; if (FD_SETSIZE < 4) std::cerr << "\nFD_SETSIZE < 4"; /* Watch stdin (fd 0) to see when it has input. */ while (!RUN::quit) { FD_ZERO(&rfds); //FD_SET(0, &rfds); //Standardeingabe FD_SET(WIN::x11_fd, &rfds); int num= INPUTDEV->set_fds(&rfds); int max_fd_plus_1= max(WIN::x11_fd,num)+1; /* Wait up to five seconds. */ tv.tv_sec = 5; tv.tv_usec = 0; retval = select(max_fd_plus_1, &rfds, NULL, NULL, &tv); /* Don't rely on the value of tv now! */ if (retval>0) { bool redraw= false; nodata_seconds = 0; if ( FD_ISSET(WIN::x11_fd,&rfds) ) { if ( process_x11_events() ) redraw= true; } if ( INPUTDEV->got_fds(&rfds) ) { if (INPUTDEV->process_input(&rfds,&RUN::builder)) { received = true; if (!RUN::freeze) redraw= true; } if (RUN::builder.new_bg_color) { RUN::builder.new_bg_color= false; XSetForeground(WIN::disp, WIN::bg_gc, DDD->AGetColor(RUN::builder.bg_color)); DDD->set_background_color( RUN::builder.bg_color ); //WIN::menu->set_background_color( RUN::builder.bg_color ); redraw= true; } } if (redraw) redraw_current_tree(); if ( Options::auto_quit_mode ) { if ( INPUTDEV->is_timeover() ) { std::time_t current; std::time( ¤t ); timeover_seconds = static_cast< int >( std::difftime( current, last_receive_time ) ); if ( timeover_seconds >= Options::auto_quit_wait ) { std::cout << "\n Game is over." << std::endl; RUN::quit= true; } } else { std::time( &last_receive_time ); } } } else if ( retval == 0) { //cout << "No Data is available now." << endl; nodata_seconds += 5; if ( Options::auto_quit_mode && nodata_seconds + timeover_seconds >= Options::auto_quit_wait ) { if ( received ) { std::cout << "\nNo messeges from server." << std::endl; RUN::quit= true; } } } else {#if 1 ERROR_OUT << "\nselect: error occured"; switch (errno) { case EBADF: ERROR_STREAM << "\n an invalid file descriptor was given in one of the sets"; break; case EINTR: ERROR_STREAM << "\n a non blocked signal was caught"; break; case EINVAL: ERROR_STREAM << "\n n is negative"; break; case ENOMEM: ERROR_STREAM << "\n select was unable to allocate memory for internal tables"; break; default: ERROR_STREAM << "\n error code " << errno; }#endif } } XFreeGC (WIN::disp, WIN::gc); XFreeGC (WIN::disp, WIN::xor_gc); XFreeGC (WIN::disp, WIN::bg_gc); XFreeGC (WIN::disp, WIN::sl_gc); XFreePixmap (WIN::disp, WIN::pixmap); XFreePixmap (WIN::disp, WIN::icon_pixmap); XFreePixmap (WIN::disp, WIN::icon_mask); INPUTDEV->destruct(); delete INPUTDEV; delete WIN::menu; delete DDD; XDestroyWindow (WIN::disp, WIN::window); XCloseDisplay (WIN::disp); /// long t= TOOLS::get_current_ms_time() / 1000; std::cerr << "\n" << PACKAGE << "-" << VERSION << " was active for "; if (t/3600) std::cerr << t/3600 << "h "; if (t/60) std::cerr << (t/60)%60 << "m "; std::cerr << t % 60 << "s\n"; exit(0);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -