diff --git a/doc/fixes3-7-0.txt b/doc/fixes3-7-0.txt index 0c160a176..cf880e758 100644 --- a/doc/fixes3-7-0.txt +++ b/doc/fixes3-7-0.txt @@ -2207,7 +2207,7 @@ curses: if user's terminal was set to 'application keypad mode' (DEC VTxxx "ESC SPC G"), nethack wasn't recognizing number pad keys curses: change petattr attributes, dropping support for curses-only ones curses: swap the grey and no-color color initialization -curses: allow changing default colors with the 'palette' config option +curses+Qt: allow changing default colors with the 'palette' config option (only if compiled with CHANGE_COLOR) curses: if messages have been issued during start-up (for instance, warnings about issues in run-time config file), prompt user to press diff --git a/win/Qt/qt_bind.cpp b/win/Qt/qt_bind.cpp index d0128cc62..d66377f3b 100644 --- a/win/Qt/qt_bind.cpp +++ b/win/Qt/qt_bind.cpp @@ -70,6 +70,8 @@ static struct key_macro_rec { { 0, 0U, (const char *) 0, (const char *) 0 } }; +static QPen *pen = (QPen *) 0; + NetHackQtBind::NetHackQtBind(int& argc, char** argv) : #ifdef KDE KApplication(argc,argv) @@ -578,6 +580,45 @@ void NetHackQtBind::qt_raw_print_bold(const char *str) qt_raw_print(str); } +const QPen NetHackQtBind::nhcolor_to_pen(uint32_t c) +{ + if (!pen) { + pen = new QPen[17]; + + pen[ 0] = QColor(64, 64, 64); // black + pen[ 1] = QColor(Qt::red); + pen[ 2] = QColor(0, 191, 0); // green + pen[ 3] = QColor(127, 127, 0); // brownish + pen[ 4] = QColor(Qt::blue); + pen[ 5] = QColor(Qt::magenta); + pen[ 6] = QColor(Qt::cyan); + pen[ 7] = QColor(Qt::gray); + // on tty, "light" variations are "bright" instead; here they're paler + pen[ 8] = QColor(Qt::white); // no color + pen[ 9] = QColor(255, 127, 0); // orange + pen[10] = QColor(127, 255, 127); // light green + pen[11] = QColor(Qt::yellow); + pen[12] = QColor(127, 127, 255); // light blue + pen[13] = QColor(255, 127, 255); // light magenta + pen[14] = QColor(127, 255, 255); // light cyan + pen[15] = QColor(Qt::white); + // ? out of range for 0..15 + pen[16] = QColor(Qt::black); + } + +#ifdef ENHANCED_SYMBOLS + if (c & 0x80000000) { + return QColor( + (c >> 16) & 0xFF, + (c >> 8) & 0xFF, + (c >> 0) & 0xFF); + } else +#endif + { + return pen[c]; + } +} + int NetHackQtBind::qt_nhgetch() { if (main) @@ -901,6 +942,28 @@ void NetHackQtBind::qt_delay_output() #endif } +#ifdef CHANGE_COLOR +void NetHackQtBind::qt_change_color(int color, long rgb, int reverse UNUSED) +{ + int r, g, b; + + r = (rgb >> 16) & 0xFF; + g = (rgb >> 8) & 0xFF; + b = rgb & 0xFF; + if (!pen) { + (void) NetHackQtBind::nhcolor_to_pen(0); /* init pen[] */ + } + pen[color % 16] = QColor(r, g, b); +} + +char * +NetHackQtBind::qt_get_color_string(void) +{ + return (char *) 0; +} + +#endif + void NetHackQtBind::qt_start_screen() { // Ignore. @@ -1158,11 +1221,13 @@ struct window_procs Qt_procs = { nethack_qt_::NetHackQtBind::qt_get_ext_cmd, nethack_qt_::NetHackQtBind::qt_number_pad, nethack_qt_::NetHackQtBind::qt_delay_output, -#ifdef CHANGE_COLOR /* only a Mac option currently */ - donull, - donull, +#ifdef CHANGE_COLOR + nethack_qt_::NetHackQtBind::qt_change_color, +#ifdef MAC /* old OS 9, not OSX */ donull, donull, +#endif + nethack_qt_::NetHackQtBind::qt_get_color_string, #endif /* other defs that really should go away (they're tty specific) */ nethack_qt_::NetHackQtBind::qt_start_screen, diff --git a/win/Qt/qt_bind.h b/win/Qt/qt_bind.h index b0b9f4f3a..6535e637b 100644 --- a/win/Qt/qt_bind.h +++ b/win/Qt/qt_bind.h @@ -71,6 +71,9 @@ public: const glyph_info *bkglyphinfo); static void qt_raw_print(const char *str); static void qt_raw_print_bold(const char *str); + static const QPen nhcolor_to_pen(uint32_t c); + static void qt_change_color(int color, long rgb, int reverse UNUSED); + static char *qt_get_color_string(void); static int qt_nhgetch(); static int qt_nh_poskey(coordxy *x, coordxy *y, int *mod); static void qt_nhbell(); diff --git a/win/Qt/qt_map.cpp b/win/Qt/qt_map.cpp index a2162504f..85817dabf 100644 --- a/win/Qt/qt_map.cpp +++ b/win/Qt/qt_map.cpp @@ -77,47 +77,6 @@ extern int qt_compact_mode; namespace nethack_qt_ { -static const QPen nhcolor_to_pen(uint32_t c) -{ - static QPen *pen = (QPen *) 0; - if (!pen) { - pen = new QPen[17]; - // - // FIXME: these are duplicated in qt_menu.cpp - // - pen[ 0] = QColor(64, 64, 64); // black - pen[ 1] = QColor(Qt::red); - pen[ 2] = QColor(0, 191, 0); // green - pen[ 3] = QColor(127, 127, 0); // brownish - pen[ 4] = QColor(Qt::blue); - pen[ 5] = QColor(Qt::magenta); - pen[ 6] = QColor(Qt::cyan); - pen[ 7] = QColor(Qt::gray); - // on tty, "light" variations are "bright" instead; here they're paler - pen[ 8] = QColor(Qt::white); // no color - pen[ 9] = QColor(255, 127, 0); // orange - pen[10] = QColor(127, 255, 127); // light green - pen[11] = QColor(Qt::yellow); - pen[12] = QColor(127, 127, 255); // light blue - pen[13] = QColor(255, 127, 255); // light magenta - pen[14] = QColor(127, 255, 255); // light cyan - pen[15] = QColor(Qt::white); - // ? out of range for 0..15 - pen[16] = QColor(Qt::black); - } - -#ifdef ENHANCED_SYMBOLS - if (c & 0x80000000) { - return QColor( - (c >> 16) & 0xFF, - (c >> 8) & 0xFF, - (c >> 0) & 0xFF); - } else -#endif - { - return pen[c]; - } -} NetHackQtMapViewport::NetHackQtMapViewport(NetHackQtClickBuffer& click_sink) : QWidget(NULL), @@ -202,7 +161,7 @@ void NetHackQtMapViewport::paintEvent(QPaintEvent* event) ch = cp437(ch); } color = Glyphcolor(i, j); - painter.setPen(nhcolor_to_pen(color)); + painter.setPen(NetHackQtBind::nhcolor_to_pen(color)); if (!DrawWalls(painter, i * gW, j * gH, gW, gH, ch)) { ushort utf16[3]; if (ch < 0x10000) { @@ -226,7 +185,7 @@ void NetHackQtMapViewport::paintEvent(QPaintEvent* event) } framecolor = GlyphFramecolor(i, j); if (framecolor != NO_COLOR) { - painter.setPen(nhcolor_to_pen(framecolor)); + painter.setPen(NetHackQtBind::nhcolor_to_pen(framecolor)); painter.drawRect(i * qt_settings->glyphs().width(), j * qt_settings->glyphs().height(), qt_settings->glyphs().width() - 1, @@ -255,7 +214,7 @@ void NetHackQtMapViewport::paintEvent(QPaintEvent* event) } framecolor = GlyphFramecolor(i, j); if (framecolor != NO_COLOR) { - painter.setPen(nhcolor_to_pen(framecolor)); + painter.setPen(NetHackQtBind::nhcolor_to_pen(framecolor)); painter.drawRect(i * qt_settings->glyphs().width(), j * qt_settings->glyphs().height(), qt_settings->glyphs().width() - 1, diff --git a/win/Qt/qt_menu.cpp b/win/Qt/qt_menu.cpp index 6a0e7a524..69ab6b747 100644 --- a/win/Qt/qt_menu.cpp +++ b/win/Qt/qt_menu.cpp @@ -483,69 +483,11 @@ void NetHackQtMenuWindow::UpdateCountColumn(long newcount) table->repaint(); } -struct qcolor { - QColor q; - const char *nm; -}; -// these match the tty colors, or better versions of same; -// [0] is used for black, and [8] (the first white) corresponds to "no color" -static const struct qcolor colors[] = { - { QColor(64, 64, 64), "64,64,64" }, // black - { QColor(Qt::red), "red" }, - { QColor(0, 191, 0), "0,191,0" }, // green - { QColor(127, 127, 0), "127,127,0" }, // brownish - { QColor(Qt::blue), "blue" }, - { QColor(Qt::magenta), "magenta" }, - { QColor(Qt::cyan), "cyan" }, - { QColor(Qt::gray), "gray" }, - // on tty, the "light" variations are "bright" instead; here they're paler - { QColor(Qt::white), "white" }, // no-color, so not rendered - { QColor(255, 127, 0), "255,127,0" }, // orange - { QColor(127, 255, 127), "127,255,127" }, // light green - { QColor(Qt::yellow), "yellow" }, - { QColor(127, 127, 255), "127,127,255" }, // light blue - { QColor(255, 127, 255), "255,127,255" }, // light magenta - { QColor(127, 255, 255), "127,255,255" }, // light cyan - { QColor(Qt::white), "white" }, -}; - -#if 0 /* available for debugging */ -static const char *color_name(const QColor q) -{ - for (int i = 0; i < SIZE(colors); ++i) - if (q == colors[i].q) - return colors[i].nm; - // these are all the enum GlobalColor values ; - // black and white have been moved in front of color0 and color1 here - const char *nm = (q == Qt::black) ? "black" - : (q == Qt::white) ? "white" - : (q == Qt::color0) ? "color0" // doesn't duplicate white? - : (q == Qt::color1) ? "color1" // does duplicate black - : (q == Qt::darkGray) ? "darkGray" - : (q == Qt::gray) ? "gray" - : (q == Qt::lightGray) ? "lightGray" - : (q == Qt::red) ? "red" - : (q == Qt::green) ? "green" - : (q == Qt::blue) ? "blue" - : (q == Qt::cyan) ? "cyan" - : (q == Qt::magenta) ? "magenta" - : (q == Qt::yellow) ? "yellow" - : (q == Qt::darkRed) ? "darkRed" - : (q == Qt::darkGreen) ? "darkGreen" - : (q == Qt::darkBlue) ? "darkBlue" - : (q == Qt::darkCyan) ? "darkCyan" - : (q == Qt::darkMagenta) ? "darkMagenta" - : (q == Qt::darkYellow) ? "darkYellow" - : (q == Qt::transparent) ? "transparent" - : "other"; - return nm; -} -#endif - void NetHackQtMenuWindow::SetTwiAttr(QTableWidgetItem *twi, int color, int attr) { if (color != NO_COLOR) { - twi->setForeground(colors[color].q); + const QPen qp = NetHackQtBind::nhcolor_to_pen(color); + twi->setForeground(qp.color()); } if (attr != ATR_NONE) {