t_logo *init_logo(t_x11 *x11,Window parent,gmx_bool bQuitOnClick) { static const char *bfname[]= { "-b&h-lucida-bold-i-normal-sans-34-240-100-100-p-215-iso8859-1", "-b&h-lucida-bold-i-normal-sans-26-190-100-100-p-166-iso8859-1", "lucidasans-bolditalic-24", "lucidasans-italic-24", "10x20", "fixed" }; #define NBF asize(bfname) static const char *sfname[]= { "lucidasans-bold-18", "10x20", "fixed" }; #define NSF asize(sfname) int i; unsigned long bg; char *newcol; t_logo *logo; snew(logo,1); logo->bQuitOnClick = bQuitOnClick; InitWin(&logo->wd,0,0,360,270,1,"GROMACS"); bg=LIGHTGREY; if ((newcol=getenv("LOGO"))!=NULL) GetNamedColor(x11,newcol,&bg); logo->wd.self=XCreateSimpleWindow(x11->disp,parent, logo->wd.x, logo->wd.y, logo->wd.width,logo->wd.height, logo->wd.bwidth,WHITE,bg); for (i=0,logo->bigfont=NULL; (i<NBF); i++) if ((logo->bigfont=XLoadQueryFont(x11->disp,bfname[i]))!=NULL) break; if (i==NBF) { perror(bfname[i-1]); exit(1); } #ifdef DEBUG fprintf(stderr,"Big Logofont: %s\n",bfname[i]); #endif for (i=0,logo->smallfont=NULL; (i<NSF); i++) if ((logo->smallfont=XLoadQueryFont(x11->disp,sfname[i]))!=NULL) break; if (i==NSF) { perror(sfname[i-1]); exit(1); } #ifdef DEBUG fprintf(stderr,"Small Logofont: %s\n",sfname[i]); #endif x11->RegisterCallback(x11,logo->wd.self,parent,LogoCallBack,logo); x11->SetInputMask(x11,logo->wd.self,ButtonPressMask | ExposureMask); return logo; }
t_x11 *GetX11(int *argc, char *argv[]) { static const char *v_name[] = { "DirectColor", "TrueColor", "PseudoColor", "StaticColor", "GrayScale", "StaticGray" }; static int v_class[] = { DirectColor, TrueColor, PseudoColor, StaticColor, GrayScale, StaticGray }; #define NCLASS (sizeof(v_class)/sizeof(v_class[0])) XVisualInfo v_info; t_x11 *x11; int ARGC; char **ARGV; char *display; char *fontname; char *title, *FG = NULL, *BG = NULL; gmx_bool bVerbose = FALSE; int i; title = strdup(argv[0]); /* First check environment */ fontname = getenv("GMXFONT"); display = getenv("DISPLAY"); snew(ARGV, *argc); ARGC = 1; for (i = 1; (i < *argc); i++) { if (argv[i][0] == '-') { if (strlen(argv[i]) > 1) { if ((*argc) > i+1) { switch (argv[i][1]) { case 'b': BG = argv[++i]; break; case 'd': display = argv[++i]; break; case 'f': switch (argv[i][2]) { case 'o': fontname = argv[++i]; break; case 'g': FG = argv[++i]; break; } break; case 't': sfree(title); title = strdup(argv[++i]); break; case 'v': bVerbose = TRUE; break; default: ARGV[ARGC++] = argv[i]; break; } } } } else { ARGV[ARGC++] = argv[i]; } } for (i = 1; (i < ARGC); i++) { argv[i] = ARGV[i]; } *argc = ARGC; argv[ARGC] = NULL; snew(x11, 1); x11->dispname = display; if (bVerbose) { x11->console = stderr; } else if ((x11->console = fopen("/dev/null", "w")) == NULL) { x11->console = stderr; } if ((x11->disp = XOpenDisplay(display)) == NULL) { if (bVerbose) { fprintf(x11->console, "Display %s invalid\n", display); } return NULL; } if ((x11->font = GetFont(x11->console, x11->disp, fontname)) == NULL) { return NULL; } if ((x11->gc = GetGC(x11->disp, x11->font)) == NULL) { return NULL; } x11->root = DefaultRootWindow(x11->disp); x11->screen = DefaultScreen(x11->disp); x11->depth = DefaultDepth(x11->disp, x11->screen); x11->cmap = DefaultColormap(x11->disp, x11->screen); /* These colours will be mapped to black on a monochrome screen */ x11->fg = BLACK = BLUE = GREEN = CYAN = RED = BROWN = GREY = DARKGREY = BlackPixel(x11->disp, x11->screen); /* These colours will be mapped to white on a monochrome screen */ x11->bg = LIGHTBLUE = LIGHTGREY = LIGHTGREEN = LIGHTCYAN = LIGHTRED = VIOLET = YELLOW = WHITE = WhitePixel(x11->disp, x11->screen); if (x11->depth > 1) { /* Not B & W, Look what kind of screen we've got... */ for (i = 0; (i < NCLASS); i++) { if (!XMatchVisualInfo(x11->disp, x11->screen, x11->depth, v_class[i], &v_info)) { break; } } if ((i == 4) || (i == 5)) { fprintf(x11->console, "Greyscale screen, using B & W only\n"); } else { /* We have real color! */ fprintf(x11->console, "%s screen with depth %d.\n", (i == NCLASS) ? "Unknown" : v_name[i], x11->depth); GetNamedColor(x11, "midnight blue", &BLUE); GetNamedColor(x11, "DarkGreen", &GREEN); GetNamedColor(x11, "SeaGreen", &CYAN); GetNamedColor(x11, "red4", &RED); GetNamedColor(x11, "Gray", &GREY); GetNamedColor(x11, "Gray", &DARKGREY); GetNamedColor(x11, "LightGray", &LIGHTGREY); GetNamedColor(x11, "green", &LIGHTGREEN); GetNamedColor(x11, "cyan", &LIGHTCYAN); GetNamedColor(x11, "tomato1", &LIGHTRED); GetNamedColor(x11, "violet", &VIOLET); GetNamedColor(x11, "yellow", &YELLOW); GetNamedColor(x11, "brown", &BROWN); GetNamedColor(x11, "CornFlowerBlue", &LIGHTBLUE); } } else { fprintf(x11->console, "Monochrome screen.\n"); } /* We should use Xrm here... */ if (FG) { GetNamedColor(x11, FG, &(x11->fg)); } else { x11->fg = BLACK; } if (BG) { GetNamedColor(x11, BG, &(x11->bg)); } else { x11->bg = LIGHTGREY; } x11->title = strdup(title); sfree(title); x11->wlist = NULL; x11->GetNamedColor = &GetNamedColor; x11->MainLoop = &MainLoop; x11->RegisterCallback = &RegisterCallback; x11->UnRegisterCallback = &UnRegisterCallback; x11->SetInputMask = &SetInputMask; x11->GetInputMask = &GetInputMask; x11->CleanUp = &CleanUp; x11->Flush = &Flush; x11->Flush(x11); return x11; }
int init_display(int argc, char **argv, MyProgram *me) { Widget w[25]; argc = OpenDisplay(argc, argv); if (argc == FALSE) return argc; w[0] = MakeMenu("File"); w[1] = MakeMenuItem(w[0], "Load...", load, me); w[2] = MakeMenuItem(w[0], "Save...", save, me); w[3] = MakeMenuItem(w[0], "Quit", quit, me); w[4] = MakeMenu("Edit"); w[5] = MakeMenuItem(w[4], "Check me", check_me, me); w[6] = MakeMenuItem(w[4], "Copy", NULL, NULL); w[7] = MakeMenuItem(w[4], "Paste", NULL, NULL); w[8] = MakeButton("Color Stuff", do_stuff, me); w[9] = MakeButton("More Stuff", more_stuff, me); w[10] = MakeButton("Quit!", quit, me); w[11] = MakeDrawArea(X_SIZE, Y_SIZE, redisplay, me); w[12] = MakeScrollList(string_table, 125, 275, list_callback, NULL); w[13] = MakeHorizScrollbar(X_SIZE, scroll_func, me); w[14] = MakeHorizScrollbar(X_SIZE, scroll_func, me); w[15] = MakeVertScrollbar(Y_SIZE, scroll_func, me); w[16] = MakeToggle("Slow", TRUE, NULL, toggle1, me); w[17] = MakeToggle("Fast", FALSE, w[16], toggle2, me); w[18] = MakeToggle("Faster", FALSE, w[16], toggle3, me); w[19] = MakeToggle("Fastest", FALSE, w[16], toggle4, me); w[20] = MakeToggle("Toggle me", FALSE, NULL, other_toggle, me); w[21] = MakeStringEntry("button.c", 435, string_func, me); w[22] = MakeTextWidget("button.c", TRUE, TRUE, 435, 200); w[23] = MakeLabel(" A Sample Libsx Demo Program (cool huh?)"); SetWidgetPos(w[4], PLACE_RIGHT, w[0], NO_CARE, NULL); SetWidgetPos(w[8], PLACE_UNDER, w[0], NO_CARE, NULL); SetWidgetPos(w[9], PLACE_UNDER, w[0], PLACE_RIGHT, w[8]); SetWidgetPos(w[10], PLACE_UNDER, w[0], PLACE_RIGHT, w[9]); SetWidgetPos(w[11], PLACE_UNDER, w[8], NO_CARE, NULL); SetWidgetPos(w[13], PLACE_UNDER, w[11], NO_CARE, NULL); SetWidgetPos(w[14], PLACE_UNDER, w[13], NO_CARE, NULL); SetWidgetPos(w[15], PLACE_RIGHT, w[11], PLACE_UNDER, w[8]); SetWidgetPos(w[12], PLACE_RIGHT, w[15], PLACE_UNDER, w[8]); SetWidgetPos(w[16], PLACE_RIGHT, w[13], PLACE_UNDER, w[15]); SetWidgetPos(w[17], PLACE_RIGHT, w[16], PLACE_UNDER, w[15]); SetWidgetPos(w[18], PLACE_RIGHT, w[13], PLACE_UNDER, w[16]); SetWidgetPos(w[19], PLACE_RIGHT, w[18], PLACE_UNDER, w[16]); SetWidgetPos(w[20], PLACE_RIGHT, w[10], PLACE_UNDER, w[0]); SetWidgetPos(w[21], PLACE_UNDER, w[18], NO_CARE, NULL); SetWidgetPos(w[22], PLACE_UNDER, w[21], NO_CARE, NULL); SetWidgetPos(w[23], PLACE_RIGHT, w[4], NO_CARE, NULL); /* * initialize the state of the toggle variables. */ me->toggle1 = TRUE; me->toggle2 = me->toggle3 = me->toggle4 = me->other_toggle = FALSE; me->list = w[12]; /* save these widget values for later */ me->str_entry = w[21]; me->text_widget = w[22]; me->draw_widget = w[11]; me->quit = w[10]; me->color_widget = w[8]; me->draw_font = GetFont("10x20"); if (me->draw_font == NULL) me->draw_font = GetFont("fixed"); SetWidgetFont(me->draw_widget, me->draw_font); SetButtonDownCB(w[11], button_down); SetButtonUpCB(w[11], button_up); SetKeypressCB(w[11], keypress); SetScrollbar(w[13], 3.0, 14.0, 14.0); SetScrollbar(w[14], 250.0, 255.0, 1.0); SetScrollbar(w[15], 30.0, 100.0, 25.0); /* * Now actually put the display on the screen. */ ShowDisplay(); /* * Get some colors for drawing with. */ GetStandardColors(); me->col1 = GetNamedColor("peachpuff2"); if (me->col1 == -1) fprintf(stderr, "Error getting color peachpuff\n"); me->col2 = GetRGBColor(255, 0, 255); if (me->col2 == -1) fprintf(stderr, "Error getting RGB color 0 255 255\n"); return argc; }