]> granicus.if.org Git - nethack/commitdiff
win32: Save and load map colors from registry
authorPasi Kallinen <paxed@alt.org>
Thu, 6 Oct 2016 17:55:30 +0000 (20:55 +0300)
committerPasi Kallinen <paxed@alt.org>
Thu, 6 Oct 2016 18:00:15 +0000 (21:00 +0300)
doc/fixes36.1
win/win32/mhmap.c
win/win32/mswproc.c
win/win32/winMS.h

index 0a6acdfd94307c0527a1a12119a2812e0bda4a66..3cb943939febd922427f0e0a5c29ab3cb989fbd4 100644 (file)
@@ -516,6 +516,7 @@ X11: status display split into three columns to accomodate Stone/Deaf/Lev/&c;
        NetHack*status_condition.foreground, .background, and .showGrip
        resources replaced by status_condition[1-3].*
 X11: more terminal-like default resources
+win32gui: save and load map colors from registry
 
 
 NetHack Community Patches (or Variation) Included
index 821c91802993310bbea7c70c76ee80504228a196..8b301da66cda4923445301a6ff02d5c32c63ab82 100644 (file)
@@ -9,6 +9,7 @@
 #include "mhinput.h"
 #include "mhfont.h"
 
+#include "color.h"
 #include "patchlevel.h"
 
 #define NHMAP_FONT_NAME TEXT("Terminal")
@@ -1025,41 +1026,8 @@ nhglyph2charcolor(short g, uchar *ch, int *color)
 COLORREF
 nhcolor_to_RGB(int c)
 {
-    switch (c) {
-    case CLR_BLACK:
-        return RGB(0x55, 0x55, 0x55);
-    case CLR_RED:
-        return RGB(0xFF, 0x00, 0x00);
-    case CLR_GREEN:
-        return RGB(0x00, 0x80, 0x00);
-    case CLR_BROWN:
-        return RGB(0xA5, 0x2A, 0x2A);
-    case CLR_BLUE:
-        return RGB(0x00, 0x00, 0xFF);
-    case CLR_MAGENTA:
-        return RGB(0xFF, 0x00, 0xFF);
-    case CLR_CYAN:
-        return RGB(0x00, 0xFF, 0xFF);
-    case CLR_GRAY:
-        return RGB(0xC0, 0xC0, 0xC0);
-    case NO_COLOR:
-        return RGB(0xFF, 0xFF, 0xFF);
-    case CLR_ORANGE:
-        return RGB(0xFF, 0xA5, 0x00);
-    case CLR_BRIGHT_GREEN:
-        return RGB(0x00, 0xFF, 0x00);
-    case CLR_YELLOW:
-        return RGB(0xFF, 0xFF, 0x00);
-    case CLR_BRIGHT_BLUE:
-        return RGB(0x00, 0xC0, 0xFF);
-    case CLR_BRIGHT_MAGENTA:
-        return RGB(0xFF, 0x80, 0xFF);
-    case CLR_BRIGHT_CYAN:
-        return RGB(0x80, 0xFF, 0xFF); /* something close to aquamarine */
-    case CLR_WHITE:
-        return RGB(0xFF, 0xFF, 0xFF);
-    default:
-        return RGB(0x00, 0x00, 0x00); /* black */
-    }
+    if (c >= 0 && c < CLR_MAX)
+        return GetNHApp()->regMapColors[c];
+    return RGB(0x00, 0x00, 0x00);
 }
 
index df53f7a88558ce63a8e7d6e2d5f7d93a3c84b11a..fe3ce07b57e6aabf06fdf167599667956f8ea0e3 100644 (file)
@@ -8,6 +8,7 @@
 */
 
 #include "hack.h"
+#include "color.h"
 #include "dlb.h"
 #include "func_tab.h" /* for extended commands */
 #include "winMS.h"
@@ -2278,6 +2279,25 @@ mswin_read_reg()
     DWORD size;
     DWORD safe_buf;
     char keystring[MAX_PATH];
+    int i;
+    COLORREF default_mapcolors[CLR_MAX] = {
+       RGB(0x55, 0x55, 0x55), /* CLR_BLACK */
+       RGB(0xFF, 0x00, 0x00), /* CLR_RED */
+       RGB(0x00, 0x80, 0x00), /* CLR_GREEN */
+       RGB(0xA5, 0x2A, 0x2A), /* CLR_BROWN */
+       RGB(0x00, 0x00, 0xFF), /* CLR_BLUE */
+       RGB(0xFF, 0x00, 0xFF), /* CLR_MAGENTA */
+       RGB(0x00, 0xFF, 0xFF), /* CLR_CYAN */
+       RGB(0xC0, 0xC0, 0xC0), /* CLR_GRAY */
+       RGB(0xFF, 0xFF, 0xFF), /* NO_COLOR */
+       RGB(0xFF, 0xA5, 0x00), /* CLR_ORANGE */
+       RGB(0x00, 0xFF, 0x00), /* CLR_BRIGHT_GREEN */
+       RGB(0xFF, 0xFF, 0x00), /* CLR_YELLOW */
+       RGB(0x00, 0xC0, 0xFF), /* CLR_BRIGHT_BLUE */
+       RGB(0xFF, 0x80, 0xFF), /* CLR_BRIGHT_MAGENTA */
+       RGB(0x80, 0xFF, 0xFF), /* CLR_BRIGHT_CYAN */
+       RGB(0xFF, 0xFF, 0xFF)  /* CLR_WHITE */
+    };
 
     sprintf(keystring, "%s\\%s\\%s\\%s", CATEGORYKEY, COMPANYKEY, PRODUCTKEY,
             SETTINGSKEY);
@@ -2288,6 +2308,9 @@ mswin_read_reg()
     GetNHApp()->saveRegistrySettings = 1; /* Normally, we always save */
     GetNHApp()->regNetHackMode = TRUE;
 
+    for (i = 0; i < CLR_MAX; i++)
+        GetNHApp()->regMapColors[i] = default_mapcolors[i];
+
     if (RegOpenKeyEx(HKEY_CURRENT_USER, keystring, 0, KEY_READ, &key)
         != ERROR_SUCCESS)
         return;
@@ -2340,6 +2363,14 @@ mswin_read_reg()
     NHGETREG_DWORD(INVENTBOTTOM, GetNHApp()->rtInvenWindow.bottom);
 #undef NHGETREG_DWORD
 
+    for (i = 0; i < CLR_MAX; i++) {
+        COLORREF cl;
+        char mapcolorkey[64];
+        sprintf(mapcolorkey, "MapColor%02d", i);
+        if (RegQueryValueEx(key, mapcolorkey, NULL, NULL, (BYTE *)&cl, &size) == ERROR_SUCCESS)
+            GetNHApp()->regMapColors[i] = cl;
+    }
+
     RegCloseKey(key);
 
     /* check the data for validity */
@@ -2358,6 +2389,7 @@ mswin_write_reg()
 {
     HKEY key;
     DWORD disposition;
+    int i;
 
     if (GetNHApp()->saveRegistrySettings) {
         char keystring[MAX_PATH];
@@ -2419,6 +2451,13 @@ mswin_write_reg()
         NHSETREG_DWORD(INVENTBOTTOM, GetNHApp()->rtInvenWindow.bottom);
 #undef NHSETREG_DWORD
 
+        for (i = 0; i < CLR_MAX; i++) {
+            COLORREF cl = GetNHApp()->regMapColors[i];
+            char mapcolorkey[64];
+            sprintf(mapcolorkey, "MapColor%02d", i);
+            RegSetValueEx(key, mapcolorkey, 0, REG_DWORD, (BYTE *)&cl, sizeof(DWORD));
+        }
+
         RegCloseKey(key);
     }
 }
index 7938d83d12598bbb24ba727e3a5fc48bcc860867..f35e601c94cc5bb710a56d3f6bc923ce3e80e40d 100644 (file)
@@ -25,6 +25,7 @@
 #include <commctrl.h>
 #include <tchar.h>
 #include "hack.h"
+#include "color.h"
 
 /* Create an array to keep track of the various windows */
 
@@ -94,6 +95,8 @@ typedef struct mswin_nhwindow_app {
         regNetHackMode; /* NetHack mode means no Windows keys in some places
                            */
 
+    COLORREF regMapColors[CLR_MAX];
+
     LONG regMainMinX;
     LONG regMainMinY;
     LONG regMainMaxX;