📄 xwinplt.c
字号:
/*| | This material contains proprietary software of Entropic Speech,| Inc. Any reproduction, distribution, or publication without the| prior written permission of Entropic Speech, Inc. is strictly| prohibited. Any public distribution of copies of this work | authorized in writing by Entropic Speech, Inc. must bear the| notice | | "Copyright (c) 1987,1988 Entropic Speech, Inc. All rights reserved."| | | xwinplt.c - Unix plotting functions for X windows| | Rodney W. Johnson, Entropic Speech, Inc.| The window plot code came from Rob Jacob at the Naval Research Lab.| Modified for SunViews by Alan Parker. Range functions added by Parker.| Modified for X Windows by Ajaipal S. Virdy, Neural Systems Lab.|*/#ifdef SCCSstatic char *sccs_id = "%W% %G% ESI";#endif/* #include <sys/file.h> */#include <stdio.h>#include <math.h>#include <esps/esps.h>#include <X11/X.h>#include <X11/Xlib.h>#include <X11/Xutil.h>#include <X11/StringDefs.h>#include <X11/Intrinsic.h>#include <X11/cursorfont.h>#include <X11/keysym.h>/* #include <X11/Label.h> */#include "../include/Xw/Xw.h"#include "../include/Xw/SText.h"#include "../include/Xw/VPW.h"#include "../include/Xw/RCManager.h"#include "../include/Xw/PButton.h"#include "../include/Xw/Toggle.h"#include "../include/Xw/Form.h"#include "../include/Xw/WorkSpace.h"#define PI 3.14159265358979323846#define NCIRC 120 /* Normal circles */#define NARC 50 /* Number of segments in arc, if it were 360 * deg. */#define NONE 0#define RIGHT 1#define MIDDLE 2#define LEFT 4#define SPACES \" \ " /* 80 blanks */#define HSPACES \" " /* about 40 spaces *//* WARNING these numbers are from drawbox.c in plotsd */#define BOX_START 500#define BOX_END 5000#define BOX_TOP 500+70#define BOX_BOTTOM 3000-70/* X Window related define's for determining dimensions of a widget */#define DEFAULT_WIDTH 500#define DEFAULT_HEIGHT 500/* G L O B A L * V A R I A B L E S * R E F E R E N C E D */extern char *ProgName;extern int debug;extern char *title;extern int R_flag;extern int P_flag;extern char *icon_name;extern char *play_options;extern Widget toplevel;/* L O C A L * V A R I A B L E S */char *filename;static int width, height;static int xorig, yorig;static int xpos = 0, ypos = 0;static int xlow = 0, ylow = 0, xhigh = 1000, yhigh = 1000;int beginplot; /* read from ESPS Common file */int endplot; /* read from ESPS Common file */int points;int new_start; /* new start point selected */int new_nan; /* new nan point selected */int box_start;int box_end;int box_top;int box_bottom;int mark_x=0;int cursor_x=0;int range_state = 1;int x_start;int x;int first_paint = 1;Pixmap make_icon();void save_common(), get_common();void s_text(), s_imagetext();void play_file(), play_range(), zoom_in(), zoom_out();void quit_proc();void do_plot();#ifndef HPchar *sprintf(), *strcpy(), *strcat();#endifextern char *tmpname;int played=0;char range_arg[100];char buf[512]; /* general purpose buffer */static char *msg1 = "LEFT: select start of range, MIDDLE: play entire plot, RIGHT: zoom out\n";static char *msg1a = "LEFT: select start of range, MIDDLE: <nothing>, RIGHT: zoom out\n";static char *msg2 = "LEFT: zoom in, MIDDLE: play range, RIGHT: reselect range\n";static char *msg3 = "Saving range...\n";static char *msg4 = "LEFT: zoom in, MIDDLE: save range, RIGHT: reselect range\n";int text_offset=0;static char *msg1_ptr;static void repaint_canvas();static intscalex(x) int x;{ return (xorig + width * (x - xlow) / (xhigh - xlow));}static intscaley(y) int y;{ return (yorig + height * (yhigh - y) / (yhigh - ylow)) + text_offset;}Window MCWindow;GC mc_gc;XFontStruct *font_info;Display *display;int screen;int WidgetsCreated = 0;Cursor MousePointer;int Texth;int Button1Down;static int LeftMark_x = 0;static int RightMark_x = 0;static int RangeShown = 0;static char RangeString[100];static int lines_drawn = 0;/* G L O B A L * W I D G E T S */Widget outer;Widget PrevW, QuitW, SRW, PRW, RRW, FormW, WSW, Form2W, ZoomInW;Widget SaveW, RefreshW;Widget ZoomOutW;#define NONE 0#define SELECT_RANGE 1#define PLAY_RANGE 2int OptionSelected = NONE;void SelectRange(widget, closure, callData) Widget widget; /* unused */ caddr_t closure; /* unused */ caddr_t callData; /* unused */{ Arg arg[5]; Cardinal i; if (OptionSelected == PLAY_RANGE) { i = 0; XtSetArg (arg[i], XtNset, False); i++; XtSetValues ((Widget) PRW, arg, (Cardinal) i); } OptionSelected = SELECT_RANGE; /* Load in hand as the mouse pointer font */ MousePointer = XCreateFontCursor (display, XC_hand2); XDefineCursor (display, MCWindow, MousePointer);}void PlayRange(widget, closure, callData) Widget widget; /* unused */ caddr_t closure; /* unused */ caddr_t callData; /* unused */{ Arg arg[5]; Cardinal i; fprintf (stderr, "Play Range\n"); if (OptionSelected == SELECT_RANGE) { i = 0; XtSetArg (arg[i], XtNset, False); i++; XtSetValues ((Widget) SRW, arg, (Cardinal) i); } OptionSelected = PLAY_RANGE; /* Load in watch to indicate D/A progress during play mode */ MousePointer = XCreateFontCursor (display, XC_watch); XDefineCursor (display, MCWindow, MousePointer);}void Quit(widget, closure, callData) Widget widget; /* unused */ caddr_t closure; /* unused */ caddr_t callData; /* unused */{ (void) unlink (tmpname); exit (0);}void Refresh(widget, closure, callData) Widget widget; /* unused */ caddr_t closure; /* unused */ caddr_t callData; /* unused */{ /* Load in watch mouse pointer during screen refresh */ MousePointer = XCreateFontCursor (display, XC_watch); XDefineCursor (display, MCWindow, MousePointer); if (RangeShown) ClearRange (); erase (); repaint_canvas (); MousePointer = XCreateFontCursor (display, XC_top_left_arrow); XDefineCursor (display, MCWindow, MousePointer);}void ZoomIn(widget, closure, callData) Widget widget; /* unused */ caddr_t closure; /* unused */ caddr_t callData; /* unused */{ Arg arg[1]; Cardinal i; if (!RangeShown) return; ClearRange (); /* Load in watch to indicate D/A progress during play mode */ MousePointer = XCreateFontCursor (display, XC_watch); XDefineCursor (display, MCWindow, MousePointer); fprintf (stderr, "Zooming in . . .\n"); zoom_in (); i = 0; XtSetArg (arg[i], XtNset, False); i++; XtSetValues ((Widget) ZoomInW, arg, (Cardinal) i); /* Load in watch to indicate D/A progress during play mode */ MousePointer = XCreateFontCursor (display, XC_top_left_arrow); XDefineCursor (display, MCWindow, MousePointer);}void ZoomOut(widget, closure, callData) Widget widget; /* unused */ caddr_t closure; /* unused */ caddr_t callData; /* unused */{ Arg arg[1]; Cardinal i; if (RangeShown) ClearRange (); /* Load in watch while waiting to zoom out */ MousePointer = XCreateFontCursor (display, XC_watch); XDefineCursor (display, MCWindow, MousePointer); fprintf (stderr, "Zooming out . . .\n"); zoom_out (); i = 0; XtSetArg (arg[i], XtNset, False); i++; XtSetValues ((Widget) ZoomOutW, arg, (Cardinal) i); /* Load in watch to indicate D/A progress during play mode */ MousePointer = XCreateFontCursor (display, XC_top_left_arrow); XDefineCursor (display, MCWindow, MousePointer);}void SaveRange(widget, closure, callData) Widget widget; /* unused */ caddr_t closure; /* unused */ caddr_t callData; /* unused */{ Arg arg[1]; Cardinal i; fprintf (stderr, "Saving range . . .\n"); save_common (); i = 0; XtSetArg (arg[i], XtNset, False); i++; XtSetValues ((Widget) SaveW, arg, (Cardinal) i);}#define undraw_line(display,screen,win,x1,y1,x2,y2) \ draw_line(display, screen, win, x1, y1, x2, y2);ClearRange(){ Arg arg[5]; Cardinal i; /* clear the range and display "Show Range" pb */ s_imagetext (HSPACES, 5, 40); i = 0; XtSetArg (arg[i], XtNlabel, (caddr_t) "Show Range"); i++; XtSetValues ((Widget) RRW, arg, (Cardinal) i); RangeShown = 0; undraw_line (display, screen, MCWindow, LeftMark_x, box_top, LeftMark_x, box_bottom); undraw_line (display, screen, MCWindow, RightMark_x, box_top, RightMark_x, box_bottom); /* We don't need to do the following: */ /* lines_drawn = 0; */}ShowRange(){ Arg arg[5]; Cardinal i; /* show the last selected range and "Clear Range" pb */ s_imagetext (RangeString, 5, 40); i = 0; XtSetArg (arg[i], XtNlabel, (caddr_t) "Clear Range"); i++; XtSetValues ((Widget) RRW, arg, (Cardinal) i); RangeShown = 1; draw_line (display, screen, MCWindow, LeftMark_x, box_top, LeftMark_x, box_bottom); draw_line (display, screen, MCWindow, RightMark_x, box_top, RightMark_x, box_bottom); /* We don't need to do the following: */ /* lines_drawn = 1; */}void ReselectRange(widget, closure, callData) Widget widget; /* unused */ caddr_t closure; /* unused */ caddr_t callData; /* unused */{ if (RangeShown) ClearRange (); else ShowRange ();}void StartRange(widget, closure, callData) Widget widget; /* unused */ caddr_t closure; /* unused */ caddr_t callData; /* unused */{ char *Module = "StartRange"; Window root, child; int root_x, root_y; int win_x, win_y; unsigned int mask; XEvent report; int save_start; static int first_time = 1; if (OptionSelected != SELECT_RANGE) return; if (RangeShown) return; fprintf( stderr, "Start range selected\n" ); /* Load in left arrow as default mouse pointer */ MousePointer = XCreateFontCursor (display, XC_sb_h_double_arrow); XDefineCursor (display, MCWindow, MousePointer);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -