/* * Procedure Initialize() is called during the widget creation * process. Initialize() load fonts and calculates window geometry. * The request parameter is filled in by parents to this widget. The * wnew parameter is the request parameter plus data filled in by this * widget. All changes should be done to the wnew parameter. */ static void Initialize(AngbandWidget request, AngbandWidget wnew) { Display *dpy = XtDisplay(wnew); int depth = DefaultDepthOfScreen(XtScreen((Widget) wnew)); XGCValues gcv; TopLevelShellWidget parent = (TopLevelShellWidget)XtParent((Widget) wnew); int i; /* Default background pixel */ unsigned long bg = create_pixel(dpy, angband_color_table[0][1], angband_color_table[0][2], angband_color_table[0][3]); /* Default foreground pixel */ unsigned long fg = create_pixel(dpy, angband_color_table[1][1], angband_color_table[1][2], angband_color_table[1][3]); /* Fix the background color */ wnew->core.background_pixel = bg; /* Get some information about the font */ wnew->angband.fnt = getFont(wnew, wnew->angband.font, TRUE); wnew->angband.fontheight = wnew->angband.fnt->ascent + wnew->angband.fnt->descent; wnew->angband.fontwidth = wnew->angband.fnt->max_bounds.width; wnew->angband.fontascent = wnew->angband.fnt->ascent; /* Create and initialize the graphics contexts */ /* GXset? */ gcv.font = wnew->angband.fnt->fid; gcv.graphics_exposures = FALSE; gcv.background = bg; for (i = 0; i < NUM_COLORS; i++) { unsigned long pixel; /* Acquire Angband colors */ wnew->angband.color[i][0] = angband_color_table[i][0]; wnew->angband.color[i][1] = angband_color_table[i][1]; wnew->angband.color[i][2] = angband_color_table[i][2]; wnew->angband.color[i][3] = angband_color_table[i][3]; if (depth > 1) { /* Create pixel */ pixel = create_pixel(dpy, wnew->angband.color[i][1], wnew->angband.color[i][2], wnew->angband.color[i][3]); } else { /* Use background or foreground */ pixel = ((i == 0) ? bg : fg); } gcv.foreground = pixel; /* Copy */ gcv.function = 3; wnew->angband.gc[i] = XtGetGC((Widget)wnew, (GCFont | GCForeground | GCFunction | GCBackground | GCGraphicsExposures), &gcv); } /* Create a special GC for highlighting */ gcv.foreground = (BlackPixelOfScreen(XtScreen((Widget)wnew)) ^ WhitePixelOfScreen(XtScreen((Widget)wnew))); gcv.background = 0; gcv.function = GXxor; wnew->angband.gc[COLOR_XOR] = XtGetGC((Widget)wnew, (GCFunction | GCForeground | GCBackground | GCGraphicsExposures), &gcv); /* Calculate window geometry */ wnew->core.height = (wnew->angband.start_rows * wnew->angband.fontheight + 2 * wnew->angband.internal_border); wnew->core.width = (wnew->angband.start_columns * wnew->angband.fontwidth + 2 * wnew->angband.internal_border); /* We need to be able to resize the Widget if the user wants to */ /* change font on the fly! */ parent->shell.allow_shell_resize = TRUE; /* Calculates all the size hints */ calculateSizeHints(wnew); }
/* * Font and internal_border can be changed on the fly. * * The entire widget is redrawn if any of those parameters change (all * can potentially have effects that spans the whole widget). * * Color changes are handled elsewhere. * * This function is very underspecified, in terms of how these changes can * occur, and what is true about the various AngbandWidget's passed in. It * is very likely that this code no longer works. */ static Boolean SetValues(AngbandWidget current, AngbandWidget request, AngbandWidget wnew, ArgList args, Cardinal *num_args) { Display *dpy = XtDisplay(wnew); Boolean font_changed = FALSE; Boolean border_changed = FALSE; int height, width; int i; /* Handle font change */ if (wnew->angband.font != current->angband.font) { /* Check if the font exists */ wnew->angband.fnt = getFont(wnew, wnew->angband.font, FALSE); /* The font didn't exist */ if (wnew->angband.fnt == NULL) { wnew->angband.fnt = current->angband.fnt; wnew->angband.font = current->angband.font; XtWarning("Couldn't find the requested font!"); } else { font_changed = TRUE; /* Free the old font */ XFreeFont(XtDisplay((Widget)wnew), current->angband.fnt); /* Update font information */ wnew->angband.fontheight = wnew->angband.fnt->ascent + wnew->angband.fnt->descent; wnew->angband.fontwidth = wnew->angband.fnt->max_bounds.width; wnew->angband.fontascent = wnew->angband.fnt->ascent; } } /* Handle font change */ if (font_changed) { /* Update all GC's */ for (i = 0; i < NUM_COLORS; i++) { /* Steal the old GC */ wnew->angband.gc[i] = current->angband.gc[i]; current->angband.gc[i] = NULL; /* Be sure the correct font is ready */ XSetFont(dpy, wnew->angband.gc[i], wnew->angband.fnt->fid); } /* Steal the old GC */ wnew->angband.gc[NUM_COLORS] = current->angband.gc[NUM_COLORS]; current->angband.gc[NUM_COLORS] = NULL; } /* Check if internal border width has changed, used later */ if (current->angband.internal_border != wnew->angband.internal_border) { border_changed = TRUE; } /* If the font or the internal border has changed, all geometry */ /* has to be recalculated */ if (font_changed || border_changed) { /* Change window size */ height = ((current->core.height - 2 * current->angband.internal_border) / current->angband.fontheight * wnew->angband.fontheight + 2 * current->angband.internal_border); width = ((current->core.width - 2 * current->angband.internal_border) / current->angband.fontwidth * wnew->angband.fontwidth + 2 * wnew->angband.internal_border); /* Get the new width */ if (XtMakeResizeRequest((Widget)wnew, width, height, NULL, NULL) == XtGeometryNo) { /* Not allowed */ XtWarning("Size change denied!"); } else { /* Recalculate size hints */ calculateSizeHints(wnew); } } /* Tell it to redraw the widget if anything has changed */ return (font_changed || border_changed); }
/* * Initialize a term_data */ static errr term_data_init(term_data *td, Widget topLevel, int key_buf, String name, ArgList widget_arg, Cardinal widget_arg_no, int i) { Widget parent; term *t = &td->t; int cols = 80; int rows = 24; char buf[80]; cptr str; int val; /* Create the shell widget */ parent = XtCreatePopupShell(name, topLevelShellWidgetClass, topLevel, NULL, 0); /* Window specific cols */ sprintf(buf, "ANGBAND_X11_COLS_%d", i); str = getenv(buf); val = (str != NULL) ? atoi(str) : -1; if (val > 0) cols = val; /* Window specific rows */ sprintf(buf, "ANGBAND_X11_ROWS_%d", i); str = getenv(buf); val = (str != NULL) ? atoi(str) : -1; if (val > 0) rows = val; /* Hack the main window must be at least 80x24 */ if (i == 0) { if (cols < 80) cols = 80; if (rows < 24) rows = 24; } /* Reset the initial size */ widget_arg[0].value = rows; widget_arg[1].value = cols; /* Hack ox==oy in xaw port */ /* Window specific inner border offset (ox) */ sprintf(buf, "ANGBAND_X11_IBOX_%d", i); str = getenv(buf); val = (str != NULL) ? atoi(str) : -1; if (val > 0) widget_arg[6].value = val; /* Window specific inner border offset (oy) */ sprintf(buf, "ANGBAND_X11_IBOY_%d", i); str = getenv(buf); val = (str != NULL) ? atoi(str) : -1; if (val > 0) widget_arg[6].value = val; /* Create the interior widget */ td->widget = (AngbandWidget) XtCreateManagedWidget(name, angbandWidgetClass, parent, widget_arg, widget_arg_no); /* Initialize the term (full size) */ term_init(t, cols, rows, key_buf); /* Use a "soft" cursor */ t->soft_cursor = TRUE; /* Erase with "white space" */ t->attr_blank = TERM_WHITE; t->char_blank = ' '; /* Hooks */ t->xtra_hook = Term_xtra_xaw; t->curs_hook = Term_curs_xaw; t->wipe_hook = Term_wipe_xaw; t->text_hook = Term_text_xaw; /* Save the data */ t->data = td; /* Register the keypress event handler */ XtAddEventHandler((Widget)td->widget, KeyPressMask, False, (XtEventHandler) handle_event, td); /* Redraw callback */ XtAddCallback((Widget)td->widget, XtNredrawCallback, react_redraw, td); /* Realize the widget */ XtRealizeWidget(parent); /* Have we redefined the font? */ if (streq(td->widget->angband.font, DEFAULT_X11_FONT)) { XFontStruct *fnt; /* Check if the font exists */ fnt = getFont(td->widget, (String) get_default_font(i), FALSE); /* The font didn't exist */ if (fnt == NULL) { XtWarning("Couldn't find the requested font!"); } else { int height, width; /* Free the old font */ XFreeFont(XtDisplay((Widget)td->widget), td->widget->angband.fnt); /* Update font information */ td->widget->angband.fontheight = fnt->ascent + fnt->descent; td->widget->angband.fontwidth = fnt->max_bounds.width; td->widget->angband.fontascent = fnt->ascent; for (i = 0; i < NUM_COLORS; i++) { /* Be sure the correct font is ready */ XSetFont(XtDisplay((Widget)td->widget), td->widget->angband.gc[i], fnt->fid); } /* Get the window shape */ height = (td->widget->angband.start_rows * td->widget->angband.fontheight + 2 * td->widget->angband.internal_border); width = (td->widget->angband.start_columns * td->widget->angband.fontwidth + 2 * td->widget->angband.internal_border); /* Request a change to the new shape */ if (XtMakeResizeRequest((Widget)td->widget, width, height, NULL, NULL) == XtGeometryNo) { /* Not allowed */ XtWarning("Size change denied!"); } else { /* Recalculate size hints */ calculateSizeHints(td->widget); } } } /* Make it visible */ XtPopup(parent, XtGrabNone); /* Activate (important) */ Term_activate(t); Resize_term(td->widget); return 0; }