5 #define DEFINE_COLORS TRUE
24 static float xtickb, xticke, xinterval, ytickb, yticke, yinterval;
33 static int local_malloc();
40 static unsigned long getColor();
51 #define insque(e,p) (e)->next=((e)->prev=(p))->next; \
52 (p)->next=(p)->next->prev=(e)
60 #define remque(e) (e)->prev->next=(e)->next; \
61 (e)->next->prev=(e)->prev; \
62 (e)->next = (e)->prev = (e)
64 #define MAX_GRAY_SCALE 256
78 XSetWindowBackground(s->dpy, s->cur->win, s->colors[s->cur->background]);
80 XSetBackground(s->dpy, s->cur->gc, s->colors[s->cur->background]);
82 XClearWindow(s->dpy, s->cur->win);
96 if( n == 16 || n == 32 || n == 64 || n == 128 || n == 256)
115 s = (
struct XGR_ *)p;
131 XFreeColors(s->dpy, s->def_cmap, s->grayScale,
max_gray_scale, AllPlanes);
142 s->colors[i] = getColor(s,
colorsTxt[i], 1, 0, 0, 0);
160 log_msg(
"allocColors(): Done");
182 sprintf(buf,
"gray%d", i*fac);
183 s->grayScale[i] = getColor(s, buf, 0, i*fac, i*fac, i*fac);
202 ret = (int)rint(a * sqrt(x-b));
221 static double aa[] = { 17.084, 18.80, 29.456 };
222 static double bb[] = { 0.0, 115.0, 202.0 };
231 r =
flame(aa[0], bb[0], (
double)i);
232 g =
flame(aa[1], bb[1], (
double)i);
233 b =
flame(aa[2], bb[2], (
double)i);
237 r =
flame(aa[0], bb[0], (
double)i);
238 b =
flame(aa[1], bb[1], (
double)i);
239 g =
flame(aa[2], bb[2], (
double)i);
243 g =
flame(aa[0], bb[0], (
double)i);
244 r =
flame(aa[1], bb[1], (
double)i);
245 b =
flame(aa[2], bb[2], (
double)i);
249 b =
flame(aa[0], bb[0], (
double)i);
250 g =
flame(aa[1], bb[1], (
double)i);
251 r =
flame(aa[2], bb[2], (
double)i);
255 g =
flame(aa[0], bb[0], (
double)i);
256 b =
flame(aa[1], bb[1], (
double)i);
257 r =
flame(aa[2], bb[2], (
double)i);
261 b =
flame(aa[0], bb[0], (
double)i);
262 r =
flame(aa[1], bb[1], (
double)i);
263 g =
flame(aa[2], bb[2], (
double)i);
271 sprintf(buf,
"color%d", i);
272 s->grayScale[k++] = getColor(s, buf, 0, r, g, b);
282 int r,g,b, i, k=0,
dx;
296 g = (int)((
float)i * 255.0 / (float)b1);
301 r = (int)((
float)(i-b1) * 255.0 / (
float)(b2-b1));
308 g = 255 - (int)((
float)(i-b2) * 255.0 / (
float)(255-b2));
316 sprintf(buf,
"color%d", i);
317 s->grayScale[k++] = getColor(s, buf, 0, r, g, b);
324 static int loadFont(s, fn)
330 if(s->invalidServerFonts)
334 if(( s->fontInfo[fn] = XLoadQueryFont(s->dpy, s->fontNames[fn])) == NULL)
336 sprintf( errBuf,
"Cannot open %s font", s->fontNames[fn]);
337 log_msg(
"loadFont(): %s", DisplayString(s->dpy), errBuf);
339 s->invalidServerFonts = 1;
358 XDestroyImage(s->userXimage);
360 for(p2=s->windows.
next;p2!=&s->windows;p2=p2->
next)
365 XFreePixmap(s->dpy, w->
pixmap);
372 free((
char *)s->fontNames);
389 int w, h, ww, x1, yy1;
391 XSizeHints size_hints;
392 static int oldw=-1, oldh=-1;
394 log_msg(
"xgr_setWindowSize(): X = %f, y = %f", x, y);
398 s = (
struct XGR_ *)p;
406 ww = WidthOfScreen(XDefaultScreenOfDisplay(s->
dpy));
408 log_msg(
"WidthOfScreen(): returns %d", ww);
411 if( x == 1.0 && y == 1.0)
425 w = (int)((
float)h * fac);
430 h = (int)((
float)w / fac);
437 if(!
strcmp(name,
"Spectral Plot Window"))
445 if(!
strcmp(name,
"OTF Gridder"))
455 if(w != oldw && h != oldh)
457 log_msg(
"xgr_setWindowSize(): Setting %s window to %d %d %d %d", name, x1, yy1, w, h);
461 size_hints.flags = PMinSize | PSize;
462 size_hints.min_width = w / 4;
463 size_hints.min_height = h / 4;
464 size_hints.width = w;
465 size_hints.height = h;
467 XSetWMNormalHints(s->
dpy, s2->
win, &size_hints);
469 XResizeWindow(s->
dpy, s2->
win, w, h);
493 s = (
struct XGR_ *)p;
505 fprintf(stderr,
"Unknown Window: %d; exiting\n", win);
541 s = (
struct XGR_ *)p;
552 0, 0, (
unsigned int)s2->
canw,
553 (
unsigned int)s2->
canh,
579 s = (
struct XGR_ *)p;
589 XMapWindow(s->
dpy, s2->
win);
590 XMapRaised(s->
dpy, s2->
win);
614 s = (
struct XGR_ *)p;
632 w = (
struct WINDOW **)NULL;
653 s = (
struct XGR_ *)p;
663 log_msg(
"xgr_putXimage(): Error in create of pixmap for %s\n", DisplayString(s->
dpy));
685 x = (int)(fx * (
float)s2->
canw);
686 y = (int)(fy * (
float)s2->
canh);
707 log_msg(
"xgr_reSizeProc(): Window Resizing: %d x %d", width, height);
711 s = (
struct XGR_ *)p;
715 if(s2->
win == window)
717 if(s2->
canw != width || s2->
canh != height)
723 log_msg(
"xgr_reSizeProc(): Freeing Window %p, Pixmap %p", s2->
win, s2->
pixmap);
730 if(!(s2->
pixmap=XCreatePixmap(s->
dpy, s2->
win, (
unsigned int)width, (
unsigned int)height, s->
depth)))
732 log_msg(
"xgr_reSizeProc(): Error in create of pixmap for %s\n", DisplayString(s->
dpy));
739 log_msg(
"xgr_reSizeProc(): New Pixmap, %p for Window %p", s2->
pixmap, s2->
win);
750 log_msg(
"xgr_reSizeProc(): Calling resize proc for win: %p", window);
774 s = (
struct XGR_ *)p;
779 if(s2->
win == window)
804 s = (
struct XGR_ *)p;
808 if(s2->
win == window)
836 s = (
struct XGR_ *)p;
847 return((
struct WINDOW *)NULL);
860 if(win == NULL || file == NULL)
865 s = (
struct XGR_ *)p;
869 if(!strncasecmp(s2->
frameTitle, win, strlen(win)))
876 fprintf(stderr,
"PRINT_DONE\n");
895 if(win == NULL || file == NULL)
900 s = (
struct XGR_ *)p;
904 if(!strncasecmp(s2->
frameTitle, win, strlen(win)))
910 fprintf(stderr,
"GIF_DONE\n");
928 s = (
struct XGR_ *)p;
954 int x1, x2, yy1, w1, h1;
958 s = (
struct XGR_ *)p;
962 x1 = (int)( (
float)s->
cur->
canw * x);
972 (
unsigned int)w1, (
unsigned int)h1);
987 int scn, ncells, i, j;
989 int dc, d, mdist, close;
990 int rd, gd,
bd, ri, gi, bi;
992 scn = DefaultScreen(dpy);
993 ncells = DisplayCells(dpy, scn);
996 dc = (ncells<256) ? ncells : 256;
998 ctab[i].pixel = (
unsigned long)i;
1000 XQueryColors(dpy, cmap, ctab, dc);
1004 ri = exact_color->red>>8;
1005 gi = exact_color->green>>8;
1006 bi = exact_color->blue>>8;
1010 rd = ri - (ctab[j].red >>8);
1011 gd = gi - (ctab[j].green>>8);
1012 bd = bi - (ctab[j].blue >>8);
1015 d = rd*rd + gd*gd + bd*
bd;
1024 log_msg(
"find_close_color(): Can't allocate %s", color );
1026 if(strstr(color,
"black"))
1027 return(XBlackPixel(dpy, scn));
1029 return(XWhitePixel(dpy, scn));
1031 if( XAllocColor( dpy, cmap, &ctab[close]))
1032 return(ctab[close].pixel);
1035 log_msg(
"find_close_color(): Can't allocate %s", color );
1037 if(strstr(color,
"black"))
1038 return(XBlackPixel(dpy, scn));
1040 return(XWhitePixel(dpy, scn));
1048 static unsigned long getColor(s, color, flag, red, green, blue)
1051 int flag, red, green, blue;
1057 s->
def_cmap = DefaultColormap(s->dpy, s->scr_num);
1062 if( !XParseColor( s->dpy, s->def_cmap, color, &exact_color ) )
1064 log_msg(
"getColor(): %s is not in %s color database", DisplayString(s->dpy), color);
1066 if(strstr(color,
"black"))
1068 return(XBlackPixel(s->dpy, s->scr_num));
1072 return(XWhitePixel(s->dpy, s->scr_num));
1078 exact_color.red = red * 255;
1079 exact_color.green = green * 255;
1080 exact_color.blue = blue * 255;
1081 exact_color.flags = DoRed | DoGreen | DoBlue;
1084 if( !XAllocColor( s->dpy, s->def_cmap, &exact_color ) )
1086 log_msg(
"getColor(): Can't allocate %s for %s\n", color, DisplayString(s->dpy));
1091 return(exact_color.pixel);
1100 if(!s->cur->invalid || s->cur->foreground == color)
1107 XSetForeground(s->dpy,s->cur->gc, s->colors[color] );
1111 XSetForeground(s->dpy,s->cur->gc, s->grayScale[color * -1] );
1114 s->cur->foreground = color;
1131 static XPoint *temp=NULL;
1133 float MaxY, MinY, MaxX, MinX;
1134 float xmax, xmin, ymax, ymin;
1142 if( (temp = (XPoint *)malloc((
unsigned)(n*
sizeof(XPoint))) ) == NULL)
1151 s = (
struct XGR_ *)p;
1172 tickGet(xdata,n, &xtickb, &xticke, &
xntick, &xinterval, &xmin, &xmax);
1176 tickGet(ydata,n, &ytickb, &yticke, &
yntick, &yinterval, &ymin, &ymax);
1186 yinterval = 2.0 / 6.0;
1202 temp[i].x = (int)(MinX+((MaxX-MinX)/(xmax -xmin ))*(xdata[i]-xmin ));
1203 temp[i].y = (int)(MaxY-((MaxY-MinY)/(yticke-ytickb))*(ydata[i]-ytickb));
1208 if((ytickb < 0.0 && yticke > 0.0) || ytickb == 0.0 || yticke == 0.0)
1214 temp[i].y = (int)(MaxY-((MaxY-MinY)/(yticke-ytickb))*(0.0-ytickb));
1235 float xmin, xmax, ymin, ymax;
1242 static XPoint *temp=NULL;
1244 float MaxY, MinY, MaxX, MinX;
1246 if( (temp = (XPoint *)malloc((
unsigned)(n*
sizeof(XPoint))) ) == NULL) {
1247 fprintf(stderr,
"%s: Error in xgr_drawLineDirect(malloc())\n",
prgName);
1253 s = (
struct XGR_ *)p;
1265 temp[i].x = (int)(MinX+((MaxX-MinX)/(xmax-xmin))*(xdata[i]-xmin));
1266 temp[i].y = (int)(MaxY-((MaxY-MinY)/(ymax-ymin))*(ydata[i]-ymin));
1280 float xmin, xmax, ymin, ymax;
1287 static XPoint *temp=NULL;
1289 float MaxY, MinY, MaxX, MinX;
1291 if( (temp = (XPoint *)malloc((
unsigned)(n*
sizeof(XPoint))) ) == NULL) {
1292 fprintf(stderr,
"%s: Error in xgr_drawPoint( malloc() )\n",
prgName);
1298 s = (
struct XGR_ *)p;
1310 temp[i].x = (int)(MinX+((MaxX-MinX)/(xmax-xmin))*(xdata[i]-xmin));
1311 temp[i].y = (int)(MaxY-((MaxY-MinY)/(ymax-ymin))*(ydata[i]-ymin));
1324 static int drawXticks(s, n)
1330 int i, delta, sl, save_color;
1339 delta = (s->cur->plotxe-s->cur->plotxb)/(n);
1348 deltaF = (f1 - f) / (
float)n;
1350 for(i=s->cur->plotxb;i<=s->
cur->
plotxe;i+=delta)
1353 sprintf(buf,
"%.2f",f);
1355 sprintf(buf,
"%.0f",f);
1359 XDrawString(s->dpy, s->cur->act, s->cur->gc, i-(s->fontW*sl)/2,s->cur->plotye+s->fontH,buf,sl);
1365 XDrawLine( s->dpy, s->cur->act, s->cur->gc, i, s->cur->plotyb, i, s->cur->plotye );
1370 XDrawLine( s->dpy, s->cur->act, s->cur->gc, i, s->cur->plotyb, i, s->cur->plotyb+5);
1371 XDrawLine( s->dpy, s->cur->act, s->cur->gc, i, s->cur->plotye-5, i, s->cur->plotye );
1388 int i, delta, sl, save_color;
1395 delta = (s->cur->plotye-s->cur->plotyb)/(
yntick+2);
1404 for(i=s->cur->plotye;i>=s->cur->plotyb;i-=delta)
1406 if( yinterval < 0.01)
1408 sprintf(buf,
"%4.3f",f);
1411 if( yinterval < 0.1)
1413 sprintf(buf,
"%4.2f",f);
1416 if( yinterval < 1.0)
1418 sprintf(buf,
"%4.1f",f);
1421 if( yinterval > 50.0)
1423 sprintf(buf,
"%.0f",f);
1427 sprintf(buf,
"%4.1f",f);
1432 XDrawString(s->dpy,s->cur->act,s->cur->gc,s->cur->plotxb-(sl*s->fontW)-2,i+s->fontH/2-2,buf,sl);
1438 XDrawLine(s->dpy, s->cur->act, s->cur->gc, s->cur->plotxb, i, s->cur->plotxe, i);
1443 XDrawLine(s->dpy, s->cur->act, s->cur->gc, s->cur->plotxb, i, s->cur->plotxb+5,i);
1444 XDrawLine(s->dpy, s->cur->act, s->cur->gc, s->cur->plotxe-5, i, s->cur->plotxe, i);
1461 static float *x=NULL,*y=NULL;
1478 if(local_malloc(
"xgr_drawBin", &x, &y,
m))
1485 if(!(i != 0 && j == 0))
1487 x[j+(i*k)] = (
float)l;
1488 y[j+(i*k)] = ydata[i];
1504 int xgr_drawGrid(f1b, f1e, f2b, f2e, n1, n2,
dx,
dy, tick, label, clr1, clr2,format)
1505 float f1b,f1e,f2b,f2e;
1506 int n1, n2,
dx,
dy, tick, label, clr1, clr2, format;
1510 float i_delta, j, deltaF,f;
1512 int n, i, k, sl, ddx, ddy;
1514 XSegment *segments = NULL;
1523 if((segments = (XSegment *)malloc(n *
sizeof(XSegment))) == NULL){
1524 log_msg(
"xgr_drawGrid: Error in (malloc(%d))", n *
sizeof(XSegment));
1531 s = (
struct XGR_ *)p;
1547 segments[segIndx].x1 = (short)i;
1548 segments[segIndx].y1 = (short)s->
cur->
plotyb;
1549 segments[segIndx].x2 = (
short)i;
1550 segments[segIndx++].y2 = (short)s->
cur->
plotye;
1559 segments[segIndx].x1 = (short)i;
1560 segments[segIndx].y1 = (short)s->
cur->
plotyb;
1561 segments[segIndx].x2 = (
short)i;
1562 segments[segIndx++].y2 = (short)s->
cur->
plotyb+5;
1563 segments[segIndx].x1 = (
short)i;
1564 segments[segIndx].y1 = (short)s->
cur->
plotye-5;
1565 segments[segIndx].x2 = (
short)i;
1566 segments[segIndx++].y2 = (short)s->
cur->
plotye;
1575 XDrawSegments(s->
dpy, s->
cur->
act, s->
cur->
gc, segments, segIndx);
1581 deltaF = (f1e - f1b) / (
float)n1;
1605 if(fabs(deltaF) < 0.100)
1606 sprintf(buf+4,
" %.3f ",f);
1608 sprintf(buf+4,
" %.1f ",f);
1620 f += deltaF*(float)ddx;
1636 segments[segIndx].x1 = (short)s->
cur->
plotxb;
1637 segments[segIndx].y1 = (
short)i;
1638 segments[segIndx].x2 = (short)s->
cur->
plotxe;
1639 segments[segIndx++].y2 = (
short)i;
1648 segments[segIndx].x1 = (short)s->
cur->
plotxb;
1649 segments[segIndx].y1 = (
short)i;
1650 segments[segIndx].x2 = (short)s->
cur->
plotxb+5;
1651 segments[segIndx++].y2 = (
short)i;
1652 segments[segIndx].x1 = (short)s->
cur->
plotxe-5;
1653 segments[segIndx].y1 = (
short)i;
1654 segments[segIndx].x2 = (short)s->
cur->
plotxe;
1655 segments[segIndx++].y2 = (
short)i;
1662 XDrawSegments(s->
dpy, s->
cur->
act, s->
cur->
gc, segments, segIndx);
1667 deltaF = (f2e - f2b) / (
float)n2;
1691 if(fabs(deltaF) < 0.100)
1692 sprintf(buf+4,
" %.3f ",f);
1694 sprintf(buf+4,
" %.1f ",f);
1706 f += deltaF*(float)ddy;
1726 if( (*xdata = (
float *)malloc((
unsigned)(dl*
sizeof(
float))) ) == NULL) {
1727 fprintf(stderr,
"%s: Error in %s( malloc() )\n",
prgName, who);
1730 if( (*ydata = (
float *)malloc((
unsigned)(dl*
sizeof(
float))) ) == NULL) {
1731 fprintf(stderr,
"%s: Error in %s( malloc() )\n",
prgName, who);
1753 s = (
struct XGR_ *)p;
1769 w = (
unsigned int)abs(xe-xb);
1770 h = (
unsigned int)abs(ye-yb);
1790 s = (
struct XGR_ *)p;
1803 float xmin, xmax, ymin, ymax;
1804 float xl, yt, xr, yb;
1809 int x1, x2, yy1, y2;
1810 float MaxY, MinY, MaxX, MinX;
1811 unsigned int dx,
dy;
1815 s = (
struct XGR_ *)p;
1821 XSetFillStyle(s->
dpy, s->
cur->
gc, FillSolid);
1826 x1 = (int)(MinX+((MaxX-MinX)/(xmax-xmin))*(xl-xmin));
1827 x2 = (int)(MinX+((MaxX-MinX)/(xmax-xmin))*(xr-xmin));
1828 dx = (
unsigned int)(x2 - x1);
1829 yy1 = (int)(MaxY-((MaxY-MinY)/(ymax-ymin))*(yb-ymin));
1830 y2 = (int)(MaxY-((MaxY-MinY)/(ymax-ymin))*(yt-ymin));
1831 dy = (
unsigned int)(y2 - yy1);
1835 XFillRectangle(s->
dpy, s->
cur->
act, s->
cur->
gc, x1, yy1, (
unsigned int)dx, (
unsigned int)dy);
1843 float xmin, xmax, ymin, ymax;
1844 float xl, yt, xr, yb;
1849 int x1, x2, yy1, y2;
1850 float MaxY, MinY, MaxX, MinX;
1851 unsigned int dx,
dy;
1855 s = (
struct XGR_ *)p;
1869 x1 = (int)(MinX+((MaxX-MinX)/(xmax-xmin))*(xl-xmin));
1870 x2 = (int)(MinX+((MaxX-MinX)/(xmax-xmin))*(xr-xmin));
1871 dx = (
unsigned int)(x2 - x1);
1872 yy1 = (int)(MaxY-((MaxY-MinY)/(ymax-ymin))*(yb-ymin));
1873 y2 = (int)(MaxY-((MaxY-MinY)/(ymax-ymin))*(yt-ymin));
1874 dy = (
unsigned int)(y2 - yy1);
1878 log_msg(
"xgr_drawRectangle(): %d %d %d %d", x1, yy1, dx, dy);
1881 XDrawRectangle(s->
dpy, s->
cur->
act, s->
cur->
gc, x1, yy1, dx, dy);
1885 XDrawRectangle(s->
dpy, s->
cur->
act, s->
cur->
gc, x1+1, yy1+1, dx, dy);
1894 float xmin, xmax, ymin, ymax;
1902 float MaxY, MinY, MaxX, MinX;
1906 s = (
struct XGR_ *)p;
1922 x1 = (int)(MinX+((MaxX-MinX)/(xmax-xmin))*(x-xmin));
1923 yy1 = (int)(MaxY-((MaxY-MinY)/(ymax-ymin))*(y-ymin));
1927 log_msg(
"xgr_drawTextInGrid(): %d %d %s", x1, yy1, msg);
1930 XDrawString(s->
dpy, s->
cur->
act, s->
cur->
gc, x1, yy1, msg, strlen(msg));
1939 float xmin, xmax, ymin, ymax;
1946 float MaxY, MinY, MaxX, MinX;
1947 unsigned int dx,
dy;
1951 log_msg(
"xgr_drawCircle(%.4f, %.4f, %.4f, %.4f, %.4f, %.4f, %.4f, %.4f)", xmin, xmax, ymin, ymax, x, y, w, h);
1956 s = (
struct XGR_ *)p;
1970 x1 = (int)(MinX+((MaxX-MinX)/(xmax-xmin))*(x-xmin));
1971 x2 = (int)(MinX+((MaxX-MinX)/(xmax-xmin))*(w-xmin));
1972 dx = (
unsigned int)abs(x2 - x1);
1974 y1 = (int)(MaxY-((MaxY-MinY)/(ymax-ymin))*(y-ymin));
1975 y2 = (int)(MaxY-((MaxY-MinY)/(ymax-ymin))*(h-ymin));
1976 dy = (
unsigned int)abs(y2 - y1);
1980 log_msg(
"xgr_drawCircle(): x1 = %d, x2 = %d, y1 = %d, y2 = %d, dx = %d, dy = %d", x1, x2, y1, y2, dx, dy);
1983 XSetLineAttributes(s->
dpy, s->
cur->
gc, size, LineSolid, CapRound, JoinRound);
1985 XDrawArc(s->
dpy, s->
cur->
act, s->
cur->
gc, x1, y1, dx, dy, 0*64, 360*64);
1987 XSetLineAttributes(s->
dpy, s->
cur->
gc, 1, LineSolid, CapRound, JoinRound);
2002 int x1, yy1, canw, canh;
2006 s = (
struct XGR_ *)p;
2016 x1 = (int)(x * (
float)canw)+s->
cur->
plotxb;
2017 yy1 = (
int)(y * (float)canh)+s->
cur->
plotyb;
2019 XDrawString(s->
dpy, s->
cur->
act, s->
cur->
gc, x1, yy1, msg, strlen(msg));
2038 s = (
struct XGR_ *)p;
2046 (
int)(x * (
float)s->
cur->
canw),
2065 s = (
struct XGR_ *)p;
2073 (
int)(x * (
float)s->
cur->
canw),
2098 s = (
struct XGR_ *)p;
2105 tickGet(xdata,n, &xtickb, &xticke, &
xntick, &xinterval, &xmin, &xmax);
2111 * (xdata[i] - xmin));
2114 / (yticke - ytickb))
2115 * (ydata[i] - ytickb));
2116 temp.x -= (s->
fontW / 2);
2117 temp.y += (s->
fontH / 2) -2;
2118 XDrawString(s->
dpy, s->
cur->
act, s->
cur->
gc, temp.x, temp.y, msg, strlen(msg));
2136 float MaxY, MinY, MaxX, MinX;
2141 s = (
struct XGR_ *)p;
2152 temp.x = (int)(MinX+((MaxX-MinX)/(xmax-xmin))*(x-xmin));
2153 temp.y = (int)(MaxY-((MaxY-MinY)/(yticke-ytickb))*(y-ytickb));
2154 temp.x -= (s->
fontW / 2);
2155 temp.y += (s->
fontH / 2) -2;
2156 XDrawString(s->
dpy, s->
cur->
act, s->
cur->
gc, temp.x, temp.y, msg, strlen(msg));
2176 s = (
struct XGR_ *)p;
2184 f = 0.5 - ((float)l * ff) / 2.0;
2185 x1 = (int)(f * (
float)s->
cur->
canw);
2187 XDrawString(s->
dpy, s->
cur->
act, s->
cur->
gc, x1, yy1, b1, strlen(b1));
2192 f = 0.5 - ((float)l * ff) / 2.0;
2193 x1 = (int)(f * (
float)s->
cur->
canw);
2195 XDrawString(s->
dpy, s->
cur->
act, s->
cur->
gc, x1, yy1, b2, strlen(b2));
2203 static int tickGet(x,n, start, end, tks, interval,
min,
max)
2206 float *start, *end, *interval, *
min, *
max;
2208 *tks =
find_ticks(x, n, start, end, interval ,min, max);
2213 static int find_ticks(f, n, pstart, pend, ptickint, mn, mx)
2216 float *pstart, *pend, *ptickint, *mn, *mx;
2218 double min,
max, tickint, diff;
2225 for( i=0; i< n; i++ ) {
2236 order = (int)rint(log10(diff))-1;
2245 tickint = pow(10, (
double)order);
2246 ticks = (int)rint(diff/tickint);
2272 if(fabs(min) > fabs(max))
2279 *ptickint = maxval*2 / 6.0;
2284 *pend = ((int)floor((max + tickint) / tickint)) * tickint;
2286 *pstart = *pend - (ticks +2) * tickint;
2287 *ptickint = tickint;
2312 d=(float)s->
cur->
canw/(
float)WidthOfScreen(XDefaultScreenOfDisplay(s->dpy));
2313 fx = f + (int)rint( (
float)s->numFonts * d) - 1;
2314 if(fx >= s->numFonts)
2319 if( s->fontInfo[fx] == NULL)
2320 if(!loadFont(s, fx))
2323 s->font_info = s->fontInfo[fx];
2325 XSetFont(s->dpy, s->cur->gc, s->font_info->fid);
2326 s->fontW = s->font_info->max_bounds.width;
2327 s->fontH = s->font_info->max_bounds.ascent+s->font_info->max_bounds.descent;
2341 s = (
struct XGR_ *)p;
2355 int i=0, j=0, k=0, n=0, nn=0, found=0;
2358 static char tempNames[40][40];
2362 tempNames[i][0] =
'\0';
2366 log_msg(
"findFixedFonts(): Num of Fixed Fonts == Zero");
2372 fontNames = XListFonts(dpy,
"?x?bold", 100, &n);
2376 for(i=0,k=0;i<nn;i++)
2381 if(!strncmp(tempNames[j], fontNames[i], 2))
2384 if(!found && strlen(fontNames[i]) < 16)
2385 strcpy(tempNames[k++], fontNames[i]);
2391 fontNames = XListFonts(dpy,
"?x??bold", 100, &n);
2400 if(!strncmp(tempNames[j], fontNames[i], 2))
2403 if(!found && strlen(fontNames[i]) < 16)
2404 strcpy(tempNames[k++], fontNames[i]);
2410 fontNames = XListFonts(dpy,
"??x??bold", 100, &n);
2419 if(!strncmp(tempNames[j], fontNames[i], 2))
2422 if(!strstr(fontNames[i],
"fixed") && !found && strlen(fontNames[i]) < 16)
2423 strcpy(tempNames[k++], fontNames[i]);
2430 log_msg(
"findFixedFonts(): No Fixed Fonts Found");
2436 if((fN = (
char **)malloc((
unsigned)(nn*
sizeof(
char *)))) == NULL)
2438 log_msg(
"findFixedFonts(): Error in malloc() of Fixed Fonts");
2445 fN[i] = (
char *)tempNames[i];
2447 qsort((
char *)&fN[0], nn,
sizeof(
char *), (__compar_fn_t)charcompare);
2463 char t1[40], t2[40];
2477 cp1 = strtok(t1,
"xX");
2480 cp1 = strtok((
char *)NULL,
"xX");
2489 cp2 = strtok(t2,
"xX");
2492 cp2 = strtok((
char *)NULL,
"xX");
2531 s = (
struct XGR_ *)p;
2554 s = (
struct XGR_ *)p;
2555 if(XPending(s->
dpy))
struct WINDOW_HEAD windows
unsigned long colors[MAX_COLORS]
int xgr_drawGrid(double f1b, double f1e, double f2b, double f2e, int n1, int n2, int dx, int dy, int tick, int label, int clr1, int clr2, int format)
int xgr_drawLine(float *xdata, float *ydata, int n, int color)
int xgr_drawBin(float *xdata, float *ydata, int n, int color)
int xgr_drawPosText(double x, double y, char *msg, int clr, int f)
int find_close_color(Display *dpy, Colormap cmap, XColor *exact_color, char *color)
int xgr_drawBox(double x, double y, double x2, double y2, int color)
int xgr_drawLabel(char *b1, char *b2, char *b3, int color)
int xgr_makeGif(char *win, char *file)
int log_perror(char *msg)
int xgr_drawTextInGrid(double xmin, double xmax, double ymin, double ymax, double x, double y, char *msg, int color, int f)
int xgr_drawText(double x, double y, char *msg, int clr, int f)
int xgr_freeWindows(struct XGR_ *s)
int xgr_putXimage(char *win_name, double fx, double fy, int w, int h, unsigned char *data)
int xgr_drawLineDirect(double xmin, double xmax, double ymin, double ymax, float *xdata, float *ydata, int n, int color)
int flame(double a, double b, double x)
int find_ticks(struct LP_IMAGE_INFO *image)
int sexagesimal(double dang, char *str, int prec)
int log_msg(const char *fmt,...)
int xgr_setNumColors(int n)
XImage * createXimage(Display *display, int w, int h, int depth)
int xgr_drawFillBox(double xmin, double xmax, double ymin, double ymax, double xl, double yt, double xr, double yb, int color)
unsigned long grayScale[MAX_GRAY_SCALE]
struct WINDOW * xgr_getWin(Window win)
int xgr_hardCopy(char *win, int land, int rev, char *file)
int xgr_setWindowSize(char *name, double x, double y)
int xgr_drawPoint(float *xdata, float *ydata, int n, double xmin, double xmax, char *msg, int color, int f)
int loadGrayScale(struct XGR_ *s)
int xgr_findWindow(Display *dpy, Window win, struct WINDOW **w)
int charcompare(char **s1, char **s2)
int xgr_drawPoints(double xmin, double xmax, double ymin, double ymax, float *xdata, float *ydata, int n, int color)
int xgr_graphInit(struct XGR_ *s)
int xgr_reSizeProc(Window window, int width, int height)
int xgr_drawTextClear(double x, double y, char *msg, int clr, int f)
int xgr_eventProc(XEvent *event, Window window, unsigned int mask)
int loadFlameScale(struct XGR_ *s, int cindx)
int loadPseudoScale(struct XGR_ *s)
int xgr_setFont(struct XGR_ *s, int f)
int xgr_setColorChoice(int c)
float xdata[MAX_ATM_ELEMENTS]
struct WINDOW_HEAD * next
int xgr_pixmapToWindow(char *name)
int setFrameFooter(char *msg, int lr)
int xgr_clearArea(double x, double y, double dx, double dy)
int xgr_setBox(double x, double y, double dx, double dy)
int xgr_drawCircle(double xmin, double xmax, double ymin, double ymax, double x, double y, double w, double h, int color, int size)
char ** findFixedFonts(Display *dpy, int *num)
int xgr_drawOn(double x, double y, int n, double xmin, double xmax, char *msg, int color, int f)
float ydata[MAX_ATM_ELEMENTS]
int xgr_mapUnmapWindow(char *name, int map)
int xgr_drawRectangle(double xmin, double xmax, double ymin, double ymax, double xl, double yt, double xr, double yb, int color, int bold)
int xgr_rePaintProc(Window window)
int xgr_checkForEvents(void)
int xgr_clearScreen(void)
int processEvent(struct XGR_ *s)
int xgr_setCurWindow(int win, int which)