File: updatelgtitle.c

package info (click to toggle)
pgplot5 5.2-13
  • links: PTS
  • area: non-free
  • in suites: potato
  • size: 6,280 kB
  • ctags: 5,903
  • sloc: fortran: 37,938; ansic: 18,809; sh: 1,147; objc: 532; makefile: 363; perl: 234; pascal: 233; tcl: 178; awk: 51; csh: 25
file content (72 lines) | stat: -rw-r--r-- 1,984 bytes parent folder | download | duplicates (15)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/* The updatelgtitle image updates the line graphics window's title to */
/* reflect the position of the cursor.  The arguments are the window x and y */
/* position of the cursor event */

/* Sam Southard, Jr. */
/* Created: 12-Feb-1992 (from updatetitle.c) */
/* Modification History: */
/* 14-Feb-1992	SNS/CIT	Now includes the id in the title */
/* 26-Feb-1992	SNS/CIT	Now handles more than 16 colors */
/*  8-Apr-1992	SNS/CIT	Keck title now more appropriate */
/* 10-Apr-1992	SNS/CIT	Can now deal with lg.winxoff and lg.winyoff */
/*  4-Oct-1992	SNS/CIT	No longer needs #ifdef KECK */

#include "figdisp.h"
#include "globals.h"
#include <X11/Xlib.h>
#include <string.h>

void updatelgtitle(x,y)
int x,y;	/* cursor position */
{
	char newtitle[80];
	char tempstr[80];
	char *strptr= &newtitle[0];	/* for the call to set the name */
	double curx,cury;		/* the cursor values */
	int datval;
	XImage *image;
	int i;

#ifndef _AIX
	char *sprintf();
#endif

	/* make sure we don't confuse anything. */
	if (x < lg.winxoff || x >= lg.imwidth+lg.winxoff || y < lg.winyoff ||
	   y >= lg.imheight+lg.winyoff) return;
	else { /* now we can get the transformed values */
		if ((image=XGetImage(display, lg.pixmap, x-lg.winxoff,
			y-lg.winyoff, 1, 1, 0xFFFFFFFF, ZPixmap)) == NULL)
		{
			datval= -1;
		} else {
			datval=XGetPixel(image,0,0);
			XDestroyImage(image);
		}
		for (i=0 ; i < lg.colors ; ++i)
		{
			if (datval==lg.pix[i])
			{
				datval=i;
				break;
			}
		}
		if (i >= lg.colors) datval= -1;
		
		curx=x-lg.winxoff;
		cury=lg.height-(y-lg.winyoff)-1;
		curx=(curx-lg.curxoff)/lg.curxsc;
		cury=(cury-lg.curyoff)/lg.curysc;
		if (datval < 0) (void)sprintf(&newtitle[0],
			"line graphics #%d X: %.6g Y: %.6g", res.id, curx,
			cury);
		else (void)sprintf(&newtitle[0],
			"line graphics #%d X: %.6g Y: %.6g Color Index: %d",
			res.id, curx, cury, datval);
	}
	if (XStringListToTextProperty(&strptr, 1, &lg.winname))
		XSetWMName(display, lg.win, &lg.winname);


	return;
}