win32: Save and load map colors from registry

This commit is contained in:
Pasi Kallinen
2016-10-06 21:00:15 +03:00
parent 580c18bb7e
commit f95747e3ef
4 changed files with 47 additions and 36 deletions
+1
View 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 NetHack*status_condition.foreground, .background, and .showGrip
resources replaced by status_condition[1-3].* resources replaced by status_condition[1-3].*
X11: more terminal-like default resources X11: more terminal-like default resources
win32gui: save and load map colors from registry
NetHack Community Patches (or Variation) Included NetHack Community Patches (or Variation) Included
+4 -36
View File
@@ -9,6 +9,7 @@
#include "mhinput.h" #include "mhinput.h"
#include "mhfont.h" #include "mhfont.h"
#include "color.h"
#include "patchlevel.h" #include "patchlevel.h"
#define NHMAP_FONT_NAME TEXT("Terminal") #define NHMAP_FONT_NAME TEXT("Terminal")
@@ -1025,41 +1026,8 @@ nhglyph2charcolor(short g, uchar *ch, int *color)
COLORREF COLORREF
nhcolor_to_RGB(int c) nhcolor_to_RGB(int c)
{ {
switch (c) { if (c >= 0 && c < CLR_MAX)
case CLR_BLACK: return GetNHApp()->regMapColors[c];
return RGB(0x55, 0x55, 0x55); return RGB(0x00, 0x00, 0x00);
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 */
}
} }
+39
View File
@@ -8,6 +8,7 @@
*/ */
#include "hack.h" #include "hack.h"
#include "color.h"
#include "dlb.h" #include "dlb.h"
#include "func_tab.h" /* for extended commands */ #include "func_tab.h" /* for extended commands */
#include "winMS.h" #include "winMS.h"
@@ -2278,6 +2279,25 @@ mswin_read_reg()
DWORD size; DWORD size;
DWORD safe_buf; DWORD safe_buf;
char keystring[MAX_PATH]; 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, sprintf(keystring, "%s\\%s\\%s\\%s", CATEGORYKEY, COMPANYKEY, PRODUCTKEY,
SETTINGSKEY); SETTINGSKEY);
@@ -2288,6 +2308,9 @@ mswin_read_reg()
GetNHApp()->saveRegistrySettings = 1; /* Normally, we always save */ GetNHApp()->saveRegistrySettings = 1; /* Normally, we always save */
GetNHApp()->regNetHackMode = TRUE; 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) if (RegOpenKeyEx(HKEY_CURRENT_USER, keystring, 0, KEY_READ, &key)
!= ERROR_SUCCESS) != ERROR_SUCCESS)
return; return;
@@ -2340,6 +2363,14 @@ mswin_read_reg()
NHGETREG_DWORD(INVENTBOTTOM, GetNHApp()->rtInvenWindow.bottom); NHGETREG_DWORD(INVENTBOTTOM, GetNHApp()->rtInvenWindow.bottom);
#undef NHGETREG_DWORD #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); RegCloseKey(key);
/* check the data for validity */ /* check the data for validity */
@@ -2358,6 +2389,7 @@ mswin_write_reg()
{ {
HKEY key; HKEY key;
DWORD disposition; DWORD disposition;
int i;
if (GetNHApp()->saveRegistrySettings) { if (GetNHApp()->saveRegistrySettings) {
char keystring[MAX_PATH]; char keystring[MAX_PATH];
@@ -2419,6 +2451,13 @@ mswin_write_reg()
NHSETREG_DWORD(INVENTBOTTOM, GetNHApp()->rtInvenWindow.bottom); NHSETREG_DWORD(INVENTBOTTOM, GetNHApp()->rtInvenWindow.bottom);
#undef NHSETREG_DWORD #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); RegCloseKey(key);
} }
} }
+3
View File
@@ -25,6 +25,7 @@
#include <commctrl.h> #include <commctrl.h>
#include <tchar.h> #include <tchar.h>
#include "hack.h" #include "hack.h"
#include "color.h"
/* Create an array to keep track of the various windows */ /* 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 regNetHackMode; /* NetHack mode means no Windows keys in some places
*/ */
COLORREF regMapColors[CLR_MAX];
LONG regMainMinX; LONG regMainMinX;
LONG regMainMinY; LONG regMainMinY;
LONG regMainMaxX; LONG regMainMaxX;