xvig.c.save

来自「gsac程序包」· SAVE 代码 · 共 1,228 行 · 第 1/3 页

SAVE
1,228
字号
  */  Cleanup();  return 0;}/*------------------------------------------------------------------------------------------------------------------------------------------------------------------*/static void Parse_Commandline(int argc,                              char *argv[],                              int *x,                              int *y,                              unsigned int *width,                              unsigned int *height){  long nr;  char *endptr;  if (argc != 8)  {    fprintf(stderr, "ERROR (XviG) : Wrong number of arguments.\n");    exit(1);  }  if (strcmp(argv[1], XviG_VERSION))  {    fprintf(stderr, "ERROR (XviG) : Wrong version of XviG.\n");    fprintf(stderr, "               Please relink with the correct version.\n");    exit(1);  }  nr = strtol(argv[3], &endptr, 10);  if ((*endptr != '\0') || (nr <= 0))  {    fprintf(stderr, "ERROR (XviG) : Invalid window number.\n");    exit(1);  }  dummy_window = (Window) nr;  *x = (int) strtol(argv[4], &endptr, 10);  if (*endptr != '\0')  {    fprintf(stderr,"WARNING (XviG) : Invalid x-position, assuming not specified.\n");    *x = -1;  }  *y = (int) strtol(argv[5], &endptr, 10);  if (*endptr != '\0')  {    fprintf(stderr,"WARNING (XviG) : Invalid y-position, assuming not specified.\n");    *y = -1;  }  *width = (int) strtol(argv[6], &endptr, 10);  if ((*endptr != '\0') || (*width <= 0))  {    fprintf(stderr,"WARNING (XviG) : Invalid initial window width, setting to 300.\n");    *width = 300;  }  *height = (int) strtol(argv[7], &endptr, 10);  if ((*endptr != '\0') || (*height <= 0))  {    fprintf(stderr,"WARNING (XviG) : Invalid initial window height, setting to 300.\n");    *height = 300;  }}/*------------------------------------------------------------------------------------------------------------------------------------------------------------------*/static void Set_WMproperties(char *window_name,                             int x,                             int y,                             unsigned int width,                             unsigned int height){  XTextProperty text_prop;  XSizeHints size_hints;  XWMHints wm_hints;  text_prop.value = (unsigned char *) window_name;  text_prop.encoding = XA_STRING;  text_prop.format = 8;  text_prop.nitems = strlen(window_name);  XSetWMName(display, window, &text_prop);  text_prop.value = (unsigned char *) window_name;  text_prop.encoding = XA_STRING;  text_prop.format = 8;  text_prop.nitems = strlen(window_name);  XSetWMIconName(display, window, &text_prop);  wm_hints.flags = IconPixmapHint;  wm_hints.icon_pixmap = icon_pixmap                       = XCreateBitmapFromData(display, window,                                (char *) calxvig_bits, calxvig_width, calxvig_height);  XSetWMHints(display, window, &wm_hints);  if (!((x < 0) || (y < 0)))  {    size_hints.flags = USPosition | USSize;    size_hints.x = x;    size_hints.y = y;    size_hints.width = width;    size_hints.height = height;    XSetWMNormalHints(display, window, &size_hints);  }  /*  -- Set the WM_PROTOCOLS property to catch an accidental close of the window  */  wm_protocols_atom = XInternAtom(display, "WM_PROTOCOLS", False);  wm_delete_window_atom = XInternAtom(display, "WM_DELETE_WINDOW", False);  if (XSetWMProtocols(display, window, &wm_delete_window_atom, 1) == 0)    fprintf(stderr,"WARNING (XviG) : Cannot set WM_DELETE_WINDOW protocol.\n");}/*------------------------------------------------------------------------------------------------------------------------------------------------------------------*/static void Create_Cursors(void){  Pixmap bitmap;  XColor color;  if (!(arrow_cursor = XCreateFontCursor(display, XC_left_ptr)))    fprintf(stderr,"WARNING (XviG) : Cannot create arrow cursor.\n");  else    XDefineCursor(display, window, arrow_cursor);  if (!(bitmap = XCreateBitmapFromData(display, window,                                       empty_bits, empty_width, empty_height)))  {    fprintf(stderr,"WARNING (XviG) : Cannot create empty bitmap.\n");    empty_cursor = None;    return;  }  if (!(empty_cursor = XCreatePixmapCursor(display, bitmap, bitmap,                                           &color, &color, 0, 0)))    fprintf(stderr,"WARNING (XviG) : Cannot create empty cursor.\n");  XFreePixmap(display, bitmap);}/*------------------------------------------------------------------------------------------------------------------------------------------------------------------*/static Pixmap New_Pixmap(unsigned int width,                         unsigned int height,                         unsigned int depth){  Pixmap pixmap;  pixmap = XCreatePixmap(display, window, width, height, depth);  XSetForeground(display, gc, BlackPixel(display, screen_nr));  XSetFillStyle(display, gc, FillSolid);  XSetFunction(display, gc, GXcopy);  XFillRectangle(display, pixmap, gc, 0, 0, width, height);  return pixmap;}/*------------------------------------------------------------------------------------------------------------------------------------------------------------------*/static void Border_Pixmaps(unsigned int depth){  border_select = XCreatePixmap(display, window, 4, 4, depth);  XSetForeground(display, gc, WhitePixel(display, screen_nr));  XFillRectangle(display, border_select, gc, 0, 0, 4, 4);  border_noselect = XCreatePixmap(display, window, 4, 4, depth);  XSetForeground(display, gc, BlackPixel(display, screen_nr));  XFillRectangle(display, border_noselect, gc, 0, 0, 4, 4);  XSetForeground(display, gc, WhitePixel(display, screen_nr));  XDrawPoint(display, border_noselect, gc, 0, 0);  XDrawPoint(display, border_noselect, gc, 2, 0);  XDrawPoint(display, border_noselect, gc, 1, 1);  XDrawPoint(display, border_noselect, gc, 3, 1);  XDrawPoint(display, border_noselect, gc, 0, 2);  XDrawPoint(display, border_noselect, gc, 2, 2);  XDrawPoint(display, border_noselect, gc, 1, 3);  XDrawPoint(display, border_noselect, gc, 3, 3);}/*------------------------------------------------------------------------------------------------------------------------------------------------------------------*/static void Refresh_Screen(void){  /*  -- To avoid that any 'rubbish' remains on the window  -- (e.g. from a cursor), we clear the window first  */  XClearWindow(display, window);  XSetFunction(display, gc, GXcopy);  XCopyArea(display, pixmap, window, gc,            0, 0, window_width, window_height, 0, 0);}/*------------------------------------------------------------------------------------------------------------------------------------------------------------------*/static void Window_Size(void){  Window root_rtn;  int x_rtn, y_rtn;  unsigned int width_rtn, height_rtn, bwidth_rtn, depth_rtn;  Pixmap new_pixmap;  event.xclient.message_type = MESSAGE_SIZE_atom;  event.xclient.format = 32;  event.type = ClientMessage;  if (XGetGeometry(display, window, &root_rtn, &x_rtn, &y_rtn,                   &width_rtn, &height_rtn, &bwidth_rtn, &depth_rtn))  {    event.xclient.data.l[0] = (long) width_rtn;    event.xclient.data.l[1] = (long) height_rtn;    if ((width_rtn != window_width) || (height_rtn != window_height))    {      new_pixmap = New_Pixmap(width_rtn, height_rtn, depth_rtn);      XCopyArea(display, pixmap, new_pixmap, gc,                0, 0,                Min(width_rtn, window_width), Min(height_rtn, window_height),                0, 0);      XFreePixmap(display, pixmap);      pixmap = new_pixmap;      window_width = width_rtn;      window_height = height_rtn;    }  }  else  {    fprintf(stderr,"WARNING (XviG) : Cannot get size of window.\n");    event.xclient.data.l[0] = (long) window_width;    event.xclient.data.l[1] = (long) window_height;  }  event.xclient.data.l[2] = (long) pixmap;  if (!XSendEvent(display, dummy_window, False, NoEventMask, &event))    fprintf(stderr, "ERROR (XviG) : Cannot send ClientMessage 'size'.\n");}/*------------------------------------------------------------------------------------------------------------------------------------------------------------------*/static void Cleanup(void){  if (arrow_cursor)    XFreeCursor(display, arrow_cursor);  if (empty_cursor)    XFreeCursor(display, empty_cursor);  XFreePixmap(display, pixmap);  XFreePixmap(display, border_select);  XFreePixmap(display, border_noselect);  if (icon_pixmap)    XFreePixmap(display, icon_pixmap);  XDestroyWindow(display, window);  XCloseDisplay(display);}struct curs {	int yv;	int xlv;	int xhv;} ;struct curs curs_arrow[] = {	{  0, 0, 0 },	{  1, 0, 1 },	{  2, 0, 2 },	{  3, 0, 3 },	{  4, 0, 4 },	{  5, 0, 5 },	{  6, 0, 6 },	{  7, 0, 7 },	{  8, 0, 4 },	{  9, 0, 1 },	{ 10, 0, 0 },	{  9, 3, 4 },	{ 10, 4, 5 },	{ 11, 4, 5 },	{ 12, 5, 5 }};static void draw_cursor(int curstyp, int xc, int yc, 		int xl, int yl, int xh, int yh){/* (xc,yc) is the center point	The xl,yl,xh,yh are screen coordinates of clip region	curstyp	0	arrow		1	arrow		2	cross hair		3	plus		4	rubber box  mode		5	rubber band mode		6	rubber mode off 		7	User pixmap		8	Hyperbola pixmap*/	int nl, i;	int xp,xm,yp,ym;	nl = sizeof(curs_arrow)/sizeof(struct curs);	if(curstyp == 0){              XDefineCursor(display, window, arrow_cursor);/*		for(i=0;i<nl;i++)                	XDrawLine(display, window, gc,				xc+curs_arrow[i].xlv,				yc+curs_arrow[i].yv,				xc+curs_arrow[i].xhv,				yc+curs_arrow[i].yv);*/	} else if (curstyp == 1) {		for(i=0;i<nl;i++)                	XDrawLine(display, window, gc,				xc+curs_arrow[i].xlv,				yc+curs_arrow[i].yv,				xc+curs_arrow[i].xhv,				yc+curs_arrow[i].yv);	} else if (curstyp == 2) {		/* cross hair */                XDrawLine(display, window, gc,			xc, yl, xc, yh);                XDrawLine(display, window, gc,			xl, yc, xh, yc);	} else if (curstyp == 3) {		xp = Min((xc+10),xh);		xm = MAX((xc-10),xl);		yp = Min((yc-10),yh);		ym = MAX((yc+10),yl);                XDrawLine(display, window, gc,			xc, ym, xc, yp);                XDrawLine(display, window, gc,			xm, yc, xp, yc);	} else if (curstyp == 4) {                XDrawLine(display, window, gc,			cur_x, cur_y, xc, cur_y);                XDrawLine(display, window, gc,			xc, cur_y, xc, yc);                XDrawLine(display, window, gc,			xc, yc, cur_x, yc);                XDrawLine(display, window, gc,			cur_x, yc, cur_x, cur_y);	} else if (curstyp == 5) {                XDrawLine(display, window, gc,			cur_x, cur_y, xc, yc);	} else if (curstyp == 8) {                XDrawLine(display, window, gc,			xl, yh, xc, yc);	}}static int inclipregion(int xpos, int ypos){	/* the clip region is in user coordinates */	xpos = xpos - border;	ypos = Ldc_top - border - ypos;	if(ypos < dc_bottom)		return 0;	else {		if(xpos <= dc_ClipRight && xpos >= dc_ClipLeft			&& ypos <=dc_ClipTop && ypos >= dc_ClipBottom)				return 1;		else				return 0;	}}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?