📄 lutdialog.cpp
字号:
WS_CHILD | ES_AUTOHSCROLL | WS_TABSTOP | WS_CLIPSIBLINGS |
WS_VISIBLE,
x+30, y, 80, 21, LutDialog, NULL, Instance, NULL);
NiceFont(ValuesTextbox[i]);
if(forPwl) {
sprintf(buf, "%c%d:", (i & 1) ? 'y' : 'x', i/2);
} else {
sprintf(buf, "%2d:", i);
}
ValuesLabel[i] = CreateWindowEx(0, WC_STATIC, buf,
WS_CHILD | WS_CLIPSIBLINGS | WS_VISIBLE,
x, y+3, 100, 21, LutDialog, NULL, Instance, NULL);
FixedFont(ValuesLabel[i]);
PrevValuesProc[i] = SetWindowLongPtr(ValuesTextbox[i],
GWLP_WNDPROC, (LONG_PTR)MyNumberProc);
}
if(count > 16) count = 16;
SendMessage(CountTextbox, EM_SETREADONLY, (WPARAM)FALSE, 0);
MoveWindow(LutDialog, 100, 30, 320, base + 30 + count*30, TRUE);
}
}
//-----------------------------------------------------------------------------
// Decode a string into a look-up table; store the values in ValuesCache[],
// and update the count checkbox (which in string mode is read-only) to
// reflect the new length. Returns FALSE if the new string is too long, else
// TRUE.
//-----------------------------------------------------------------------------
BOOL StringToValuesCache(char *str, int *c)
{
int count = 0;
while(*str) {
if(*str == '\\') {
str++;
switch(*str) {
case 'r': ValuesCache[count++] = '\r'; break;
case 'n': ValuesCache[count++] = '\n'; break;
case 'f': ValuesCache[count++] = '\f'; break;
case 'b': ValuesCache[count++] = '\b'; break;
default: ValuesCache[count++] = *str; break;
}
} else {
ValuesCache[count++] = *str;
}
if(*str) {
str++;
}
if(count >= 32) {
return FALSE;
}
}
char buf[10];
sprintf(buf, "%d", count);
SendMessage(CountTextbox, WM_SETTEXT, 0, (LPARAM)(buf));
*c = count;
return TRUE;
}
//-----------------------------------------------------------------------------
// Show the look-up table dialog. This one is nasty, mostly because there are
// two ways to enter a look-up table: as a table, or as a string. Presumably
// I should convert between those two representations on the fly, as the user
// edit things, so I do.
//-----------------------------------------------------------------------------
void ShowLookUpTableDialog(ElemLeaf *l)
{
ElemLookUpTable *t = &(l->d.lookUpTable);
// First copy over all the stuff from the leaf structure; in particular,
// we need our own local copy of the table entries, because it would be
// bad to update those in the leaf before the user clicks okay (as he
// might cancel).
int count = t->count;
BOOL asString = t->editAsString;
memset(ValuesCache, 0, sizeof(ValuesCache));
int i;
for(i = 0; i < count; i++) {
ValuesCache[i] = t->vals[i];
}
// Now create the dialog's fixed controls, plus the changing (depending
// on show style/entry count) controls for the initial configuration.
LutDialog = CreateWindowClient(0, "LDmicroDialog",
_("Look-Up Table"), WS_OVERLAPPED | WS_SYSMENU,
100, 100, 320, 375, NULL, NULL, Instance, NULL);
MakeFixedControls(FALSE);
MakeLutControls(asString, count, FALSE);
// Set up the controls to reflect the initial configuration.
SendMessage(DestTextbox, WM_SETTEXT, 0, (LPARAM)(t->dest));
SendMessage(IndexTextbox, WM_SETTEXT, 0, (LPARAM)(t->index));
char buf[30];
sprintf(buf, "%d", t->count);
SendMessage(CountTextbox, WM_SETTEXT, 0, (LPARAM)buf);
if(asString) {
SendMessage(AsStringCheckbox, BM_SETCHECK, BST_CHECKED, 0);
}
// And show the window
EnableWindow(MainWindow, FALSE);
ShowWindow(LutDialog, TRUE);
SetFocus(DestTextbox);
SendMessage(DestTextbox, EM_SETSEL, 0, -1);
char PrevTableAsString[1024] = "";
MSG msg;
DWORD ret;
DialogDone = FALSE;
DialogCancel = FALSE;
while((ret = GetMessage(&msg, NULL, 0, 0)) && !DialogDone) {
if(msg.message == WM_KEYDOWN) {
if(msg.wParam == VK_RETURN) {
DialogDone = TRUE;
break;
} else if(msg.wParam == VK_ESCAPE) {
DialogDone = TRUE;
DialogCancel = TRUE;
break;
}
}
if(!IsDialogMessage(LutDialog, &msg)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
// Are we in table mode? In that case watch the (user-editable) count
// field, and use that to determine how many textboxes to show.
char buf[20];
SendMessage(CountTextbox, WM_GETTEXT, (WPARAM)16, (LPARAM)buf);
if(atoi(buf) != count && !asString) {
count = atoi(buf);
if(count < 0 || count > 32) {
count = 0;
SendMessage(CountTextbox, WM_SETTEXT, 0, (LPARAM)"");
}
DestroyLutControls();
MakeLutControls(asString, count, FALSE);
}
// Are we in string mode? In that case watch the string textbox,
// and use that to update the (read-only) count field.
if(asString) {
char scratch[1024];
SendMessage(StringTextbox, WM_GETTEXT, (WPARAM)sizeof(scratch),
(LPARAM)scratch);
if(strcmp(scratch, PrevTableAsString)!=0) {
if(StringToValuesCache(scratch, &count)) {
strcpy(PrevTableAsString, scratch);
} else {
// Too long; put back the old one
SendMessage(StringTextbox, WM_SETTEXT, 0,
(LPARAM)PrevTableAsString);
}
}
}
// Did we just change modes?
BOOL x = SendMessage(AsStringCheckbox, BM_GETCHECK, 0, 0)==BST_CHECKED;
if((x && !asString) || (!x && asString)) {
asString = x;
DestroyLutControls();
MakeLutControls(asString, count, FALSE);
}
}
if(!DialogCancel) {
SendMessage(DestTextbox, WM_GETTEXT, (WPARAM)16, (LPARAM)(t->dest));
SendMessage(IndexTextbox, WM_GETTEXT, (WPARAM)16, (LPARAM)(t->index));
DestroyLutControls();
// The call to DestroyLutControls updated ValuesCache, so just read
// them out of there (whichever mode we were in before).
int i;
for(i = 0; i < count; i++) {
t->vals[i] = ValuesCache[i];
}
t->count = count;
t->editAsString = asString;
}
EnableWindow(MainWindow, TRUE);
DestroyWindow(LutDialog);
}
//-----------------------------------------------------------------------------
// Show the piecewise linear table dialog. This one can only be edited in
// only a single format, which makes things easier than before.
//-----------------------------------------------------------------------------
void ShowPiecewiseLinearDialog(ElemLeaf *l)
{
ElemPiecewiseLinear *t = &(l->d.piecewiseLinear);
// First copy over all the stuff from the leaf structure; in particular,
// we need our own local copy of the table entries, because it would be
// bad to update those in the leaf before the user clicks okay (as he
// might cancel).
int count = t->count;
memset(ValuesCache, 0, sizeof(ValuesCache));
int i;
for(i = 0; i < count*2; i++) {
ValuesCache[i] = t->vals[i];
}
// Now create the dialog's fixed controls, plus the changing (depending
// on show style/entry count) controls for the initial configuration.
LutDialog = CreateWindowClient(0, "LDmicroDialog",
_("Piecewise Linear Table"), WS_OVERLAPPED | WS_SYSMENU,
100, 100, 320, 375, NULL, NULL, Instance, NULL);
MakeFixedControls(TRUE);
MakeLutControls(FALSE, count*2, TRUE);
// Set up the controls to reflect the initial configuration.
SendMessage(DestTextbox, WM_SETTEXT, 0, (LPARAM)(t->dest));
SendMessage(IndexTextbox, WM_SETTEXT, 0, (LPARAM)(t->index));
char buf[30];
sprintf(buf, "%d", t->count);
SendMessage(CountTextbox, WM_SETTEXT, 0, (LPARAM)buf);
// And show the window
EnableWindow(MainWindow, FALSE);
ShowWindow(LutDialog, TRUE);
SetFocus(DestTextbox);
SendMessage(DestTextbox, EM_SETSEL, 0, -1);
MSG msg;
DWORD ret;
DialogDone = FALSE;
DialogCancel = FALSE;
while((ret = GetMessage(&msg, NULL, 0, 0)) && !DialogDone) {
if(msg.message == WM_KEYDOWN) {
if(msg.wParam == VK_RETURN) {
DialogDone = TRUE;
break;
} else if(msg.wParam == VK_ESCAPE) {
DialogDone = TRUE;
DialogCancel = TRUE;
break;
}
}
if(!IsDialogMessage(LutDialog, &msg)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
// Watch the (user-editable) count field, and use that to
// determine how many textboxes to show.
char buf[20];
SendMessage(CountTextbox, WM_GETTEXT, (WPARAM)16, (LPARAM)buf);
if(atoi(buf) != count) {
count = atoi(buf);
if(count < 0 || count > 10) {
count = 0;
SendMessage(CountTextbox, WM_SETTEXT, 0, (LPARAM)"");
}
DestroyLutControls();
MakeLutControls(FALSE, count*2, TRUE);
}
}
if(!DialogCancel) {
SendMessage(DestTextbox, WM_GETTEXT, (WPARAM)16, (LPARAM)(t->dest));
SendMessage(IndexTextbox, WM_GETTEXT, (WPARAM)16, (LPARAM)(t->index));
DestroyLutControls();
// The call to DestroyLutControls updated ValuesCache, so just read
// them out of there.
int i;
for(i = 0; i < count*2; i++) {
t->vals[i] = ValuesCache[i];
}
t->count = count;
}
EnableWindow(MainWindow, TRUE);
DestroyWindow(LutDialog);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -