📄 2dview.c
字号:
/* * Copyright (c) 1999 - 2001, Artur Merke <amerke@ira.uka.de> * * This file is part of FrameView2d. * * FrameView2d is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * FrameView2d is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with FrameView2d; see the file COPYING. If not, write to * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */#ifdef HAVE_CONFIG_H#include "config.h"#endif#include <cstdio>#include <cstdlib>#include <cmath>#include <ctime> #include <iostream>#include <X11/Xlib.h>#include <X11/Xutil.h>#include <X11/cursorfont.h> /* For erasing cursor - not important */#include <X11/keysym.h> /* ART! */#include <X11/keysymdef.h> /* ART! */#include <X11/xpm.h>#include <csignal>#include <sys/time.h>#include <fstream>#include "global_defs.h"#include "tools.h"#include "display_x11.h"#include "menu_x11.h"#include "popup_x11.h"#include "structure.h"#include "builder_direct.h"#include "valueparser.h"#include "udpsocket.h"#include "rgb_db.h"#include "smonitor_dev.h"#include "ascii_dev.h"#include <cerrno> //for return values of select#include <unistd.h>#include "rcssmonitor.xpm"DisplayX11 *DDD;InputDevice * INPUTDEV;#define POPUPstruct Pointer { Pointer(int xx, int yy) { x= xx; y= yy;} int x; int y;};struct Rectangle { bool active; int x,y; unsigned int width,height; Rectangle(); Rectangle(int window_width, int window_height); void set_ratio(int window_width, int widow_height); void set_origin(int px,int py) { p1x= px; p1y= py; p2x= p1x; p2y= p1y; conform();} void set_point(int px,int py) { p2x= px; p2y= py; conform();}private: void conform(); bool use_ratio; bool use_center; int win_width, win_height; int p1x,p1y,p2x,p2y;};namespace Options { //specifies the clip of euclidean plane Area2d plane; bool set_window_pos; int window_left_x; int window_top_y; int window_size_x; int window_size_y; int line_thickness; char font_name[MAX_NAME_LEN]; char font_inside[MAX_NAME_LEN];bool auto_quit_mode;int auto_quit_wait; char conf_file[MAX_NAME_LEN]; /* =========================================================================*/ bool set_defaults(); bool process_options(ValueParser & vp); bool read(int argc,char **argv); void show_available_options(std::ostream & o, const char *fname) { o << "\n/*****************************************************************************/" << "\n " << PACKAGE << "-" << VERSION << std::endl << "\nUsage: " << fname << " options" << "\n" << "\nOptions can be read from a configuration file or from the command line." << "\nValues in square brackets represent default values." << "\n" << "\nCommand line options:" << "\n" << "\n-h this page" << "\n-help this page" << "\n-copyleft shows program information" << "\n-gen_conf_file generate a configuration file on standard output" << "\n-keys shows key bindings" << "\n" << "\n-conf_file [\"\"] configuration file to be read|" << "\n" << "\nCommand line options and configuration file options (command line has priority):" << "\n" << "\ngeneral options:" << "\n" << "\n-plane_origin_x [" << plane.center.x << "]" << "\n-plane_origin_y [" << plane.center.y << "]" << "\n-plane_size_x [" << plane.size_x << "]" << "\n-plane_size_y [" << plane.size_y << "]" << "\n"#if 0 << "\n-window_left_x [not set]" << "\n-window_top_y [not set]"#endif << "\n-window_size_x [" << window_size_x << "]" << "\n-window_size_y [" << window_size_y << "]" << "\n" << "\n-line_thickness [" << line_thickness << "]" << "\nthis is the font in the status line" << "\n-font_name [" << font_name << "]" << "\nthis is the font used in objects (like players in SMonitorDevice)" << "\n-font_inside [" << font_inside << "]" << "\n" << "\n-auto_quit_mode [" << auto_quit_mode << "]" << "\n-auto_quit_wait [" << auto_quit_wait << "]" << "\n"; INPUTDEV->help_options(o); o << "\n/*****************************************************************************/" << "\n"; } void generate_file_options(std::ostream & o, const char *fname) { o << "#############################################################################" << "# " << PACKAGE << "-" << VERSION << std::endl << "#" << "# this configuration file was autamaticly generated by calling " << "\n" << "\n# " << fname << " -gen_conf_file" << "\n# you can use it to customize " << PACKAGE << "-" << VERSION << std::endl << "\n" << "\n# general options:" << "\n" << "\n### plane is the smallest part of the euclidean plane you wish to be set es default" << "\n# x coordinate of the plane center (default " << plane.center.x << ")" << "\nplane_origin_x = " //<< plane.center.x << "\n# y coordinate of the plane center (default " << plane.center.x << ")" << "\nplane_origin_y = " //<< plane.center.y << "\n# width of the plane (default " << plane.size_x << ")" << "\nplane_size_x = " //<< plane.size_x << "\n# height of the plane (default " << plane.size_y << ")" << "\nplane_size_y = " //<< plane.size_y << "\n"#if 0 << "\n# left-top corner x pos of the window (default not set)" << "\nwindow_left_x = " //<< window_left_x << "\n# left-top corner y pos of the window (default not set)" << "\nwindow_top_y = " //<< window_top_y#endif << "\n# window width (default " << window_size_x << ")" << "\nwindow_size_x = " //<< window_size_x << "\n# window height (default " << window_size_y << ")" << "\nwindow_size_y = " //<< window_size_y << "\n" << "\n# thickness of lines (default " << line_thickness << ")" << "\nline_thickness = " //<< line_thickness << "\n" << "\n# font which is used in the status line (default " << font_name << ")" << "\nfont_name = " //<< font_name << "\n# this is the font used in objects [like players in SMonitorDevice] (default " << font_inside << ")" << "\nfont_inside = " //<< font_inside << "\n" << "\n# determins whether monitor program quits automatically (default 0)." << "\nauto_quit_mode = " << "\n# wait seconds in auto_quit_mode (default " << auto_quit_wait << ")" << "\nauto_quit_wait = " << "\n"; INPUTDEV->generate_file_options(o); }}namespace RUN { DrawTree tree; ConvArea2d conv_area; BuilderDirect builder(tree,conv_area); bool quit= false; bool freeze= false; void toggle_freeze() { freeze= !freeze; } void show_key_bindings(std::ostream & o) { o << "\n" << "/*****************************************************************************/\n" << "\n" << " " << PACKAGE << "-" << VERSION << std::endl << "\n" << "viewer commands:\n" << "f = freeze the screen\n" << "i = set viewing clip to the initial clip\n" << "k = show key bindings\n" << "q = quit viewer\n" << "+ = zoom in\n" << "- = zoom out\n" << "single mouse click = change view center to mouse pointer position\n" << "drag & drop = define new rectangle view area (too small regions will be rejected)\n"; INPUTDEV->help_char_command(o); o << "\n" << "\n" << "/*****************************************************************************/\n"; } void show_copyright_notice(std::ostream & o) { o << "\n" << "/*****************************************************************************/\n" << " "<< PACKAGE << "-" << VERSION << std::endl << "\n" << "Copyright (c) 1999 - 2001, Artur Merke\n" << "\t<amerke@ira.uka.de>\n" << "Copyright (c) 2001 - 2007, The RoboCup Soccer Simulator Maintainance Group.\n" << "\t<sserver-admin@lists.sourceforge.net>\n" << "\n" << PACKAGE << "-" << VERSION << " is free software; you can redistribute it and/or modify\n" << "it under the terms of the GNU General Public License as published by\n" << "the Free Software Foundation; either version 2, or (at your option)\n" << "any later version.\n" << "\n" << PACKAGE << "-" << VERSION << " is distributed in the hope that it will be useful,\n" << "but WITHOUT ANY WARRANTY; without even the implied warranty of\n" << "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n" << "GNU General Public License for more details.\n" << "/*****************************************************************************/\n"; }}namespace WIN { int win_width, win_height; int win_depth; Display *disp; Pixmap pixmap; Window window; MenuX11 * menu= 0; PopupX11 * popup= 0;Pixmap icon_pixmap;Pixmap icon_mask; GC gc, xor_gc, bg_gc, sl_gc, bt_gc; //sl= status line, bt= button Rectangle clip_rect; Pointer mouse_point(0,0); unsigned int mouse_button= 0; bool rect_was_drawn= false; int x11_fd;}bool Options::set_defaults() { plane= Area2d(Point2d(0.0,2.0),112.0,85.0); set_window_pos= false; window_left_x= 5; window_top_y= 5; window_size_x= 600; window_size_y= 450; line_thickness= 1; strcpy(font_name,"6x13bold"); strcpy(font_inside,"6x13bold"); auto_quit_mode = false; auto_quit_wait = 5; conf_file[0]= '\0'; return true;}bool Options::process_options(ValueParser & vp) { vp.get("plane_origin_x",plane.center.x); vp.get("plane_origin_y",plane.center.y); vp.get("plane_size_x",plane.size_x); vp.get("plane_size_y",plane.size_y); #if 0 if ( vp.get("window_left_x",window_left_x) > 0 ) set_window_pos= true; if ( vp.get("window_top_y",window_top_y) > 0 ) set_window_pos= true;#endif vp.get("window_size_y",window_size_y); vp.get("window_size_x",window_size_x); vp.get("window_size_y",window_size_y); int tmp= line_thickness; vp.get("line_thickness",tmp); if (tmp < 4 && tmp > 0) line_thickness= tmp; vp.get("font_name",font_name,MAX_NAME_LEN); vp.get("font_inside",font_inside,MAX_NAME_LEN); vp.get( "auto_quit_mode", auto_quit_mode ); vp.get( "auto_quit_wait", auto_quit_wait ); return true;}bool Options::read(int argc,char **argv) { bool res= true; bool dum= true; ValueParser cl(argc,argv); //cl.set_verbose(true); if ( cl.get("help",dum) >= 0 || cl.get("h",dum) >= 0) { show_available_options(std::cout,PACKAGE); exit(0); } if (cl.get("gen_conf_file",dum) >= 0) { generate_file_options(std::cout,PACKAGE); exit(0); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -