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

View File

@@ -181,6 +181,11 @@ void NetHackQtMapViewport::paintEvent(QPaintEvent* event)
QPainter painter;
painter.begin(this);
unsigned special, tileidx;
#ifdef TEXTCOLOR
uint32 color;
uint32 framecolor;
#endif
if (Is_rogue_level(&u.uz) || iflags.wc_ascii_map) {
// 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 i = garea.left(); i <= garea.right(); i++) {
uint32 color = Glyphcolor(i, j);
char32_t ch = Glyphttychar(i, j);
unsigned special = Glyphflags(i, j);
uint32 framecolor = GlyphFramecolor(i, j);
/* unsigned short tileidx = Glyphtileidx(i, j); */
special = Glyphflags(i, j);
if (SYMHANDLING(H_IBM)) {
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
painter.setPen( nhcolor_to_pen(color) );
color = Glyphcolor(i, j);
painter.setPen(nhcolor_to_pen(color));
#else
painter.setPen( Qt::green );
painter.setPen(Qt::green);
#endif
if (!DrawWalls(painter, i * gW, j * gH, gW, gH, ch)) {
painter.drawText(i * gW, j * gH, gW, gH, Qt::AlignCenter,
QString(QChar(ch)).left(1));
}
#ifdef TEXTCOLOR
if ((special & MG_PET) != 0 && ::iflags.hilite_pet) {
painter.drawPixmap(QPoint(i * gW, j * gH),
pet_annotation);
@@ -228,12 +222,14 @@ void NetHackQtMapViewport::paintEvent(QPaintEvent* event)
painter.drawPixmap(QPoint(i * gW, j * gH),
pile_annotation);
}
#ifdef TEXTCOLOR
framecolor = GlyphFramecolor(i, j);
if (framecolor != NO_COLOR) {
painter.setPen( nhcolor_to_pen(framecolor) );
painter.drawRect(i*qt_settings->glyphs().width(),
j*qt_settings->glyphs().height(),
qt_settings->glyphs().width()-1,
qt_settings->glyphs().height()-1);
painter.setPen(nhcolor_to_pen(framecolor));
painter.drawRect(i * qt_settings->glyphs().width(),
j * qt_settings->glyphs().height(),
qt_settings->glyphs().width() - 1,
qt_settings->glyphs().height() - 1);
}
#endif
}
@@ -243,11 +239,10 @@ void NetHackQtMapViewport::paintEvent(QPaintEvent* event)
} else { // tiles
for (int j = garea.top(); j <= garea.bottom(); j++) {
for (int i = garea.left(); i <= garea.right(); i++) {
unsigned short g = Glyph(i,j);
unsigned special = Glyphflags(i, j);
unsigned tileidx = Glyphtileidx(i, j);
uint32 framecolor = GlyphFramecolor(i, j);
unsigned short g = Glyph(i, j);
special = Glyphflags(i, j);
tileidx = Glyphtileidx(i, j);
glyphs.drawCell(painter, g, tileidx, i, j);
if ((special & MG_PET) != 0 && ::iflags.hilite_pet) {
@@ -258,13 +253,16 @@ void NetHackQtMapViewport::paintEvent(QPaintEvent* event)
painter.drawPixmap(QPoint(i * gW, j * gH),
pile_annotation);
}
#ifdef TEXTCOLOR
framecolor = GlyphFramecolor(i, j);
if (framecolor != NO_COLOR) {
painter.setPen( nhcolor_to_pen(framecolor) );
painter.drawRect(i*qt_settings->glyphs().width(),
j*qt_settings->glyphs().height(),
qt_settings->glyphs().width()-1,
qt_settings->glyphs().height()-1);
painter.setPen(nhcolor_to_pen(framecolor));
painter.drawRect(i * qt_settings->glyphs().width(),
j * qt_settings->glyphs().height(),
qt_settings->glyphs().width() - 1,
qt_settings->glyphs().height() - 1);
}
#endif
}
}
}

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 */
/* 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 */
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,
X11_color color, boolean inverted);
#ifdef ENHANCED_SYMBOLS
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);
#endif
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.
*/
static void
set_gc(Widget w, Font font, const char *resource_name, Pixel bgpixel,
GC *regular, GC *inverse)
set_gc(
Widget w,
Font font,
const char *resource_name,
Pixel bgpixel,
GC *regular, GC *inverse)
{
XGCValues values;
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 dest_x = (cur_col - COL0_OFFSET) * tile_map->square_width;
int dest_y = row * tile_map->square_height;
unsigned gflags = tile_map->glyphs[row][cur_col].glyphflags;
#if 0
/* 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 */
#endif
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,
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) */
XSetForeground(dpy, tile_map->black_gc,
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);
XSetForeground(dpy, tile_map->black_gc,
BlackPixelOfScreen(screen));
}
if ((tile_map->glyphs[row][cur_col].glyphflags & MG_OBJPILE)) {
} else if ((gflags & MG_OBJPILE) != 0) {
/* draw object pile annotation (a plus sign) */
XSetForeground(dpy, tile_map->black_gc,
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,
BlackPixelOfScreen(screen));
}
if (tile_map->glyphs[row][cur_col].framecolor != NO_COLOR) {
XDrawRectangle(dpy, XtWindow(wp->w),
map_info->text_map.color_gcs[tile_map->glyphs[row][cur_col].framecolor],
dest_x, dest_y,
tile_map->square_width - 1 ,
tile_map->square_height - 1);
#ifdef TEXTCOLOR
{
uint32_t fc = tile_map->glyphs[row][cur_col].framecolor;
if (fc != NO_COLOR)
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
static GC
X11_make_gc(struct xwindow *wp UNUSED, struct text_map_info_t *text_map,
X11_color color, boolean inverted)
X11_make_gc(
struct xwindow *wp UNUSED,
struct text_map_info_t *text_map,
X11_color color,
boolean inverted)
{
boolean cur_inv = inverted;
GC ggc;
@@ -1582,13 +1598,13 @@ X11_make_gc(struct xwindow *wp UNUSED, struct text_map_info_t *text_map,
color -= CLR_MAX;
cur_inv = !cur_inv;
}
ggc = iflags.use_color
? (cur_inv
? text_map->inv_color_gcs[color]
: text_map->color_gcs[color])
: (cur_inv
? text_map->inv_copy_gc
: text_map->copy_gc);
ggc = (iflags.use_color
? (cur_inv
? text_map->inv_color_gcs[color]
: text_map->color_gcs[color])
: (cur_inv
? text_map->inv_copy_gc
: text_map->copy_gc));
}
return ggc;
}
@@ -1606,9 +1622,12 @@ X11_free_gc(struct xwindow *wp, GC ggc, X11_color color)
#endif /* TEXTCOLOR */
static void
X11_draw_image_string(Display *display, Drawable d,
GC ggc, int x, int y,
const X11_map_symbol *string, int length)
X11_draw_image_string(
Display *display,
Drawable d,
GC ggc,
int x, int y,
const X11_map_symbol *string, int length)
{
#ifdef ENHANCED_SYMBOLS
/* 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
struct map_info_t *map_info = wp->map_information;
XFontStruct *fs = map_info->text_map.font;
if (fs == NULL) {
fs = WindowFontStruct(wp->w);
}