#include #include #include #include #include #include "hisview_misc.h" #define WIDGET_STORAGE #include "hisview_widgets.h" MrmHierarchy Hierarchie; XtAppContext app; Display *display; int screen; Screen *ecran; Window fenrac; Visual *visual; unsigned int depth; Colormap cmap, default_cmap; int pixmapdim[2], cpixmapdim[2]; Pixmap pixmap, HSVpixmap, Hpixmap, Spixmap, Vpixmap, cpixmap; GC gc; static XColor cdef; static char dumstr[80]; #define REGISTERCALLBACKS #include "hisview_callbacks.h" extern void cursor_input(); XtActionsRec actions[] = { {"cursor_input", cursor_input}, }; extern void (*phys_coord)(); extern int which_image; void cursor_input(w, event) Widget w; XEvent *event; { int x, y, j, k, n; char userchain[512], dum[512]; char chainx[80], chainy[80], chainv[80]; if (event->type == LeaveNotify) { XmTextSetString(params, NULL); return; } x = event->xmotion.x/zoom; y = (pixmapdim[1] - 1 - event->xmotion.y)/zoom; x++; y++; phys_coord(&which_image, &x, &y, chainx, chainy, chainv, strlen(chainx), strlen(chainy), strlen(chainv)); sprintf(dum, "POS %d,%d RA%s DEC%s VAL%s", x, y, chainx, chainy, chainv); n = strlen(dum); k = 0; /* Leave only one blank between chains */ for (j = 0; j < n; j++) { if (dum[j] == ' ') { if (dum[j+1] == ' ') continue; } userchain[k] = dum[j]; k++; } userchain[k] = 0; XmTextSetString(params, userchain); } static char cursor_translations[] = ": cursor_input()\n\ : cursor_input()\n"; void create(w, w_code, cbs) Widget w; int *w_code; XmAnyCallbackStruct *cbs; { switch (*w_code) { case k_radec: radec = w; XtVaSetValues(w, XmNwidth, pixmapdim[0], XmNheight, pixmapdim[1], XmNtranslations, XtParseTranslationTable(cursor_translations), NULL); pixmap = XCreatePixmap(display, fenrac, pixmapdim[0], pixmapdim[1], depth); HSVpixmap = XCreatePixmap(display, fenrac, pixmapdim[0], pixmapdim[1], depth); Hpixmap = XCreatePixmap(display, fenrac, pixmapdim[0], pixmapdim[1], depth); Spixmap = XCreatePixmap(display, fenrac, pixmapdim[0], pixmapdim[1], depth); Vpixmap = XCreatePixmap(display, fenrac, pixmapdim[0], pixmapdim[1], depth); break; case k_params: params = w; break; case k_wedge: wedge = w; XtVaSetValues(w, XmNwidth, cpixmapdim[0], XmNheight, cpixmapdim[1], NULL); cpixmap = XCreatePixmap(display, fenrac, cpixmapdim[0], cpixmapdim[1], depth); if (!(gc = XCreateGC(display, fenrac, (unsigned long int) 0, NULL))) { printf("creates_itt : could not get a graphic context. Aborting !\n"); exit(0); } XSetForeground(display, gc, BlackPixelOfScreen(ecran)); XFillRectangle(display, cpixmap, gc, 0, 0, cpixmapdim[0], cpixmapdim[1]); break; case k_lowcut: lowcut = w; sprintf(dumstr, "lowcut = %f", Hclip[0]); XmTextSetString(w, dumstr); break; case k_highcut: highcut = w; sprintf(dumstr, "highcut = %f", Hclip[1]); XmTextSetString(w, dumstr); break; case k_showhsv: showb[0] = w; break; case k_showhue: showb[1] = w; break; case k_showsat: showb[2] = w; break; case k_showval: showb[3] = w; break; case k_lowscale: lowscale = w; break; case k_highscale: highscale = w; break; } } void expose(w, area, cbs) Widget w; int *area; XmDrawingAreaCallbackStruct *cbs; { switch(*area) { case k_radec: XCopyArea(cbs->event->xexpose.display, pixmap, cbs->window, gc, 0, 0, pixmapdim[0], pixmapdim[1], 0, 0); break; case k_wedge: XCopyArea(cbs->event->xexpose.display, cpixmap, cbs->window, gc, 0, 0, cpixmapdim[0], cpixmapdim[1], 0, 0); break; } } void inidisplay(char *uidlocation, int size[2]) { MrmCode code; char *db_filename_vec[1]; char uidname[128]; Widget main_w; int narg=0; char *name[10]; name[0] = (char *) malloc(80*sizeof(char)); strcpy(name[0], "hisview"); MrmInitialize(); if (!(toplevel = XtVaAppInitialize(&app, NULL, NULL, 0, &narg, name, NULL, XmNtitle, "hisview", XmNmwmDecorations, MWM_DECOR_TITLE | MWM_DECOR_BORDER | MWM_DECOR_MINIMIZE, NULL))) { printf("Failed to start X Window\n"); exit(0); } display = XtDisplay(toplevel); ecran = XtScreen(toplevel); screen = DefaultScreen(display); fenrac = RootWindowOfScreen(ecran); visual = DefaultVisual(display, screen); depth = DefaultDepthOfScreen(ecran); default_cmap = DefaultColormapOfScreen(ecran); cmap = XCopyColormapAndFree(display, default_cmap); cpixmapdim[0] = 102; cpixmapdim[1] = size[1]; pixmapdim[0] = size[0]; pixmapdim[1] = size[1]; sprintf(uidname, "%s%s", uidlocation, "hisview.uid"); /* printf("uidlocation %s\n", uidlocation); fflush(stdout); */ db_filename_vec[0] = &uidname[0]; if (MrmOpenHierarchy (1, db_filename_vec, NULL, &Hierarchie) !=MrmSUCCESS) { printf("Can't open uid files.\n"); exit(0); } /* Registering callbacks before fetching */ MrmRegisterNames(reglist, sizeof(reglist)/sizeof(reglist[0])); if (MrmFetchWidget(Hierarchie, "MAIN_W", toplevel, &main_w, &code) != MrmSUCCESS ){ printf("Can't fetch widget.\n"); exit(0); } XtManageChild(main_w); XtAppAddActions(app, actions, XtNumber(actions)); } void realize_top() { Cursor circle_cursor; if (!(circle_cursor = XCreateFontCursor(display, XC_circle))) { circle_cursor = None; } /* Actually map the window */ XtRealizeWidget(toplevel); XSetWindowColormap(display, XtWindow(toplevel), cmap); XDefineCursor(display, XtWindow(radec), circle_cursor); /* loop on X-Window events */ XtAppMainLoop(app); } void quit() { exit(0); }