build fixes for !TEXTCOLOR

Neither X11 nor Qt would compile with TEXTCOLOR disabled.  With this
they build and seem to work, but no promises, particularly for the
ENHANCED_SYMBOLS config.
This commit is contained in:
PatR
2023-04-22 16:37:48 -07:00
parent 7105f0a7d9
commit efd6b4081b
2 changed files with 73 additions and 55 deletions
+28 -30
View File
@@ -181,6 +181,11 @@ void NetHackQtMapViewport::paintEvent(QPaintEvent* event)
QPainter painter; QPainter painter;
painter.begin(this); painter.begin(this);
unsigned special, tileidx;
#ifdef TEXTCOLOR
uint32 color;
uint32 framecolor;
#endif
if (Is_rogue_level(&u.uz) || iflags.wc_ascii_map) { if (Is_rogue_level(&u.uz) || iflags.wc_ascii_map) {
// You enter a VERY primitive world! // You enter a VERY primitive world!
@@ -193,33 +198,22 @@ void NetHackQtMapViewport::paintEvent(QPaintEvent* event)
for (int j = garea.top(); j <= garea.bottom(); j++) { for (int j = garea.top(); j <= garea.bottom(); j++) {
for (int i = garea.left(); i <= garea.right(); i++) { for (int i = garea.left(); i <= garea.right(); i++) {
uint32 color = Glyphcolor(i, j);
char32_t ch = Glyphttychar(i, j); char32_t ch = Glyphttychar(i, j);
unsigned special = Glyphflags(i, j);
uint32 framecolor = GlyphFramecolor(i, j); special = Glyphflags(i, j);
/* unsigned short tileidx = Glyphtileidx(i, j); */
if (SYMHANDLING(H_IBM)) { if (SYMHANDLING(H_IBM)) {
ch = cp437(ch); ch = cp437(ch);
} }
if (framecolor != NO_COLOR) {
painter.fillRect(i*qt_settings->glyphs().width(),
j*qt_settings->glyphs().height(),
qt_settings->glyphs().width()-1,
qt_settings->glyphs().height()-1,
nhcolor_to_pen(framecolor).color());
}
#ifdef TEXTCOLOR #ifdef TEXTCOLOR
color = Glyphcolor(i, j);
painter.setPen( nhcolor_to_pen(color) ); painter.setPen(nhcolor_to_pen(color));
#else #else
painter.setPen( Qt::green ); painter.setPen(Qt::green);
#endif #endif
if (!DrawWalls(painter, i * gW, j * gH, gW, gH, ch)) { if (!DrawWalls(painter, i * gW, j * gH, gW, gH, ch)) {
painter.drawText(i * gW, j * gH, gW, gH, Qt::AlignCenter, painter.drawText(i * gW, j * gH, gW, gH, Qt::AlignCenter,
QString(QChar(ch)).left(1)); QString(QChar(ch)).left(1));
} }
#ifdef TEXTCOLOR
if ((special & MG_PET) != 0 && ::iflags.hilite_pet) { if ((special & MG_PET) != 0 && ::iflags.hilite_pet) {
painter.drawPixmap(QPoint(i * gW, j * gH), painter.drawPixmap(QPoint(i * gW, j * gH),
pet_annotation); pet_annotation);
@@ -228,12 +222,14 @@ void NetHackQtMapViewport::paintEvent(QPaintEvent* event)
painter.drawPixmap(QPoint(i * gW, j * gH), painter.drawPixmap(QPoint(i * gW, j * gH),
pile_annotation); pile_annotation);
} }
#ifdef TEXTCOLOR
framecolor = GlyphFramecolor(i, j);
if (framecolor != NO_COLOR) { if (framecolor != NO_COLOR) {
painter.setPen( nhcolor_to_pen(framecolor) ); painter.setPen(nhcolor_to_pen(framecolor));
painter.drawRect(i*qt_settings->glyphs().width(), painter.drawRect(i * qt_settings->glyphs().width(),
j*qt_settings->glyphs().height(), j * qt_settings->glyphs().height(),
qt_settings->glyphs().width()-1, qt_settings->glyphs().width() - 1,
qt_settings->glyphs().height()-1); qt_settings->glyphs().height() - 1);
} }
#endif #endif
} }
@@ -243,11 +239,10 @@ void NetHackQtMapViewport::paintEvent(QPaintEvent* event)
} else { // tiles } else { // tiles
for (int j = garea.top(); j <= garea.bottom(); j++) { for (int j = garea.top(); j <= garea.bottom(); j++) {
for (int i = garea.left(); i <= garea.right(); i++) { for (int i = garea.left(); i <= garea.right(); i++) {
unsigned short g = Glyph(i,j); unsigned short g = Glyph(i, j);
unsigned special = Glyphflags(i, j);
unsigned tileidx = Glyphtileidx(i, j);
uint32 framecolor = GlyphFramecolor(i, j);
special = Glyphflags(i, j);
tileidx = Glyphtileidx(i, j);
glyphs.drawCell(painter, g, tileidx, i, j); glyphs.drawCell(painter, g, tileidx, i, j);
if ((special & MG_PET) != 0 && ::iflags.hilite_pet) { if ((special & MG_PET) != 0 && ::iflags.hilite_pet) {
@@ -258,13 +253,16 @@ void NetHackQtMapViewport::paintEvent(QPaintEvent* event)
painter.drawPixmap(QPoint(i * gW, j * gH), painter.drawPixmap(QPoint(i * gW, j * gH),
pile_annotation); pile_annotation);
} }
#ifdef TEXTCOLOR
framecolor = GlyphFramecolor(i, j);
if (framecolor != NO_COLOR) { if (framecolor != NO_COLOR) {
painter.setPen( nhcolor_to_pen(framecolor) ); painter.setPen(nhcolor_to_pen(framecolor));
painter.drawRect(i*qt_settings->glyphs().width(), painter.drawRect(i * qt_settings->glyphs().width(),
j*qt_settings->glyphs().height(), j * qt_settings->glyphs().height(),
qt_settings->glyphs().width()-1, qt_settings->glyphs().width() - 1,
qt_settings->glyphs().height()-1); qt_settings->glyphs().height() - 1);
} }
#endif
} }
} }
} }
+45 -25
View File
@@ -1,4 +1,4 @@
/* NetHack 3.7 winmap.c $NHDT-Date: 1643328598 2022/01/28 00:09:58 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.49 $ */ /* NetHack 3.7 winmap.c $NHDT-Date: 1682206649 2023/04/22 23:37:29 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.59 $ */
/* Copyright (c) Dean Luick, 1992 */ /* Copyright (c) Dean Luick, 1992 */
/* NetHack may be freely redistributed. See license for details. */ /* NetHack may be freely redistributed. See license for details. */
@@ -57,10 +57,14 @@ extern int total_tiles_used, Tile_corr;
#define COL0_OFFSET 1 /* change to 0 to revert to displaying unused column 0 */ #define COL0_OFFSET 1 /* change to 0 to revert to displaying unused column 0 */
static X11_map_symbol glyph_char(const glyph_info *glyphinfo); static X11_map_symbol glyph_char(const glyph_info *glyphinfo);
#ifdef TEXTCOLOR
static GC X11_make_gc(struct xwindow *wp, struct text_map_info_t *text_map, static GC X11_make_gc(struct xwindow *wp, struct text_map_info_t *text_map,
X11_color color, boolean inverted); X11_color color, boolean inverted);
#ifdef ENHANCED_SYMBOLS #ifdef ENHANCED_SYMBOLS
static void X11_free_gc(struct xwindow *wp, GC gc, X11_color color); static void X11_free_gc(struct xwindow *wp, GC gc, X11_color color);
#endif
#endif /* TEXTCOLOR */
#ifdef ENHANCED_SYMBOLS
static void X11_set_map_font(struct xwindow *wp); static void X11_set_map_font(struct xwindow *wp);
#endif #endif
static void X11_draw_image_string(Display *display, Drawable d, static void X11_draw_image_string(Display *display, Drawable d,
@@ -894,8 +898,12 @@ map_check_size_change(struct xwindow *wp)
* by querying the widget with the resource name. * by querying the widget with the resource name.
*/ */
static void static void
set_gc(Widget w, Font font, const char *resource_name, Pixel bgpixel, set_gc(
GC *regular, GC *inverse) Widget w,
Font font,
const char *resource_name,
Pixel bgpixel,
GC *regular, GC *inverse)
{ {
XGCValues values; XGCValues values;
XtGCMask mask = GCFunction | GCForeground | GCBackground | GCFont; XtGCMask mask = GCFunction | GCForeground | GCBackground | GCFont;
@@ -1392,10 +1400,11 @@ map_update(struct xwindow *wp, int start_row, int stop_row, int start_col, int s
int src_x, src_y; int src_x, src_y;
int dest_x = (cur_col - COL0_OFFSET) * tile_map->square_width; int dest_x = (cur_col - COL0_OFFSET) * tile_map->square_width;
int dest_y = row * tile_map->square_height; int dest_y = row * tile_map->square_height;
unsigned gflags = tile_map->glyphs[row][cur_col].glyphflags;
#if 0 #if 0
/* not required with the new glyph representations */ /* not required with the new glyph representations */
if ((tile_map->glyphs[row][cur_col].glyphflags & MG_FEMALE)) if ((gflags & MG_FEMALE) != 0)
tile++; /* advance to the female tile variation */ tile++; /* advance to the female tile variation */
#endif #endif
src_x = (tile % TILES_PER_ROW) * tile_width; src_x = (tile % TILES_PER_ROW) * tile_width;
@@ -1405,7 +1414,7 @@ map_update(struct xwindow *wp, int start_row, int stop_row, int start_col, int s
src_x, src_y, tile_width, tile_height, src_x, src_y, tile_width, tile_height,
dest_x, dest_y); dest_x, dest_y);
if ((tile_map->glyphs[row][cur_col].glyphflags & MG_PET) && iflags.hilite_pet) { if ((gflags & MG_PET) != 0 && iflags.hilite_pet) {
/* draw pet annotation (a heart) */ /* draw pet annotation (a heart) */
XSetForeground(dpy, tile_map->black_gc, XSetForeground(dpy, tile_map->black_gc,
pet_annotation.foreground); pet_annotation.foreground);
@@ -1419,8 +1428,7 @@ map_update(struct xwindow *wp, int start_row, int stop_row, int start_col, int s
XSetClipMask(dpy, tile_map->black_gc, None); XSetClipMask(dpy, tile_map->black_gc, None);
XSetForeground(dpy, tile_map->black_gc, XSetForeground(dpy, tile_map->black_gc,
BlackPixelOfScreen(screen)); BlackPixelOfScreen(screen));
} } else if ((gflags & MG_OBJPILE) != 0) {
if ((tile_map->glyphs[row][cur_col].glyphflags & MG_OBJPILE)) {
/* draw object pile annotation (a plus sign) */ /* draw object pile annotation (a plus sign) */
XSetForeground(dpy, tile_map->black_gc, XSetForeground(dpy, tile_map->black_gc,
pile_annotation.foreground); pile_annotation.foreground);
@@ -1436,13 +1444,18 @@ map_update(struct xwindow *wp, int start_row, int stop_row, int start_col, int s
XSetForeground(dpy, tile_map->black_gc, XSetForeground(dpy, tile_map->black_gc,
BlackPixelOfScreen(screen)); BlackPixelOfScreen(screen));
} }
if (tile_map->glyphs[row][cur_col].framecolor != NO_COLOR) { #ifdef TEXTCOLOR
XDrawRectangle(dpy, XtWindow(wp->w), {
map_info->text_map.color_gcs[tile_map->glyphs[row][cur_col].framecolor], uint32_t fc = tile_map->glyphs[row][cur_col].framecolor;
dest_x, dest_y,
tile_map->square_width - 1 , if (fc != NO_COLOR)
tile_map->square_height - 1); XDrawRectangle(dpy, XtWindow(wp->w),
map_info->text_map.color_gcs[fc],
dest_x, dest_y,
tile_map->square_width - 1 ,
tile_map->square_height - 1);
} }
#endif
} }
} }
@@ -1538,8 +1551,11 @@ map_update(struct xwindow *wp, int start_row, int stop_row, int start_col, int s
#ifdef TEXTCOLOR #ifdef TEXTCOLOR
static GC static GC
X11_make_gc(struct xwindow *wp UNUSED, struct text_map_info_t *text_map, X11_make_gc(
X11_color color, boolean inverted) struct xwindow *wp UNUSED,
struct text_map_info_t *text_map,
X11_color color,
boolean inverted)
{ {
boolean cur_inv = inverted; boolean cur_inv = inverted;
GC ggc; GC ggc;
@@ -1582,13 +1598,13 @@ X11_make_gc(struct xwindow *wp UNUSED, struct text_map_info_t *text_map,
color -= CLR_MAX; color -= CLR_MAX;
cur_inv = !cur_inv; cur_inv = !cur_inv;
} }
ggc = iflags.use_color ggc = (iflags.use_color
? (cur_inv ? (cur_inv
? text_map->inv_color_gcs[color] ? text_map->inv_color_gcs[color]
: text_map->color_gcs[color]) : text_map->color_gcs[color])
: (cur_inv : (cur_inv
? text_map->inv_copy_gc ? text_map->inv_copy_gc
: text_map->copy_gc); : text_map->copy_gc));
} }
return ggc; return ggc;
} }
@@ -1606,9 +1622,12 @@ X11_free_gc(struct xwindow *wp, GC ggc, X11_color color)
#endif /* TEXTCOLOR */ #endif /* TEXTCOLOR */
static void static void
X11_draw_image_string(Display *display, Drawable d, X11_draw_image_string(
GC ggc, int x, int y, Display *display,
const X11_map_symbol *string, int length) Drawable d,
GC ggc,
int x, int y,
const X11_map_symbol *string, int length)
{ {
#ifdef ENHANCED_SYMBOLS #ifdef ENHANCED_SYMBOLS
/* This doesn't support the supplementary planes. The basic Xlib seems /* This doesn't support the supplementary planes. The basic Xlib seems
@@ -1878,6 +1897,7 @@ X11_get_map_font_struct(struct xwindow *wp)
#ifdef ENHANCED_SYMBOLS #ifdef ENHANCED_SYMBOLS
struct map_info_t *map_info = wp->map_information; struct map_info_t *map_info = wp->map_information;
XFontStruct *fs = map_info->text_map.font; XFontStruct *fs = map_info->text_map.font;
if (fs == NULL) { if (fs == NULL) {
fs = WindowFontStruct(wp->w); fs = WindowFontStruct(wp->w);
} }