-
Notifications
You must be signed in to change notification settings - Fork 0
/
DlgTheme.cpp
executable file
·160 lines (122 loc) · 3.52 KB
/
DlgTheme.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#include "DlgTheme.h"
#include "Resource.h"
#include "Main.h"
BOOL CALLBACK ThemeSettingsProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
void ThemeSettingsDialog()
{
DialogBox (Main.App.GetInstance(), MAKEINTRESOURCE(IDD_THEME), Main.App.GetWnd(), &ThemeSettingsProc);
}
void ExtractColor(ifstream& fin, COLORREF& rgb)
{
char szBuffer[4];
int r,g,b;
fin.getline(szBuffer, 4);
r = atoi(szBuffer);
fin.ignore();
fin.getline(szBuffer, 4);
g = atoi(szBuffer);
fin.ignore();
fin.getline(szBuffer, 4);
b = atoi(szBuffer);
fin.ignore();
rgb = RGB(r, g, b);
}
void ExtractColor(ifstream& fin, BYTE& r, BYTE& g, BYTE& b)
{
char szBuffer[4];
fin.getline(szBuffer, 4);
r = atoi(szBuffer);
fin.ignore();
fin.getline(szBuffer, 4);
g = atoi(szBuffer);
fin.ignore();
fin.getline(szBuffer, 4);
b = atoi(szBuffer);
fin.ignore();
}
BOOL CALLBACK ThemeSettingsProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
ifstream fin;
long sel;
char szBuffer [128];
char szBuffer2[128];
int i;
RECT rect, rect2;
switch (message)
{
case WM_INITDIALOG:
// Center dialog
GetWindowRect(Main.App.GetWnd(), &rect);
GetWindowRect(hWnd , &rect2);
SetWindowPos (hWnd, HWND_TOP, ((rect.left + rect.right) / 2) - ((rect2.right - rect2.left) / 2), ((rect.top + rect.bottom) / 2) - ((rect2.bottom - rect2.top) / 2), 0, 0, SWP_NOSIZE);
// Setup listbox
fin.open("themes.idx");
// Ignore comments
while (fin.peek() == ';')
fin.ignore(1280,'\n');
while (!fin.eof())
{
fin.getline(szBuffer, 128);
SendDlgItemMessage(hWnd, IDC_LIST , LB_ADDSTRING, 0, (LPARAM)&szBuffer);
// Ignore lines
for (i = 0; i < 6; i++)
fin.ignore(1280,'\n');
}
fin.close();
return 1;
case WM_COMMAND:
switch (LOWORD(wParam))
{
case IDC_LIST:
if (HIWORD(wParam) == LBN_SELCHANGE)
{
// Extract tilset dirrectory from themes.idx
sel = SendDlgItemMessage(hWnd, IDC_LIST, LB_GETCURSEL, 0, 0);
if (sel != LB_ERR)
{
SendDlgItemMessage(hWnd, IDC_LIST, LB_GETTEXT, sel, (LPARAM)&szBuffer);
fin.open("themes.idx");
// Ignore lines
while (fin.peek() == ';')
fin.ignore(1280,'\n');
while (!fin.eof())
{
fin.getline(szBuffer2, 128);
if (strcmp(szBuffer, szBuffer2) == 0)
{
fin.getline(szBuffer, 128);
if (szBuffer[0] != NULL)
{
sprintf(Main.Settings.szThemeDir, "%s", szBuffer);
// Main.DirectX.ReleaseTheme();
Main.DirectX.LoadTheme();
fin.getline(Main.Settings.szGameBackCopyright, 128);
fin.getline(Main.Settings.szHighBackCopyright, 128);
ExtractColor(fin, Main.Settings.rgbGame);
ExtractColor(fin, Main.Settings.rgbHighscores);
ExtractColor(fin, Main.Settings.rGrid, Main.Settings.gGrid, Main.Settings.bGrid);
fin.close();
if (Main.Desktop.Game->IsVisible())
Main.Desktop.Stats.SetAllForeColors(Main.Settings.rgbGame);
else
Main.Desktop.Stats.SetAllForeColors(Main.Settings.rgbHighscores);
}
break;
}
}
fin.close();
}
SendMessage(hWnd, WM_DESTROY, 0, 0);
}
break;
case IDCANCEL:
SendMessage(hWnd, WM_DESTROY, 0, 0);
return 1;
}
break;
case WM_DESTROY:
EndDialog(hWnd, 0);
return 1;
}
return 0;
}