1
0
Fork 0

(svn r14978) -Codechange: simplify the control flow of the OnClick of the settings window

release/0.7
rubidium 2009-01-10 19:22:05 +00:00
parent e1a351cb1a
commit 238c0a5d1f
1 changed files with 78 additions and 79 deletions

View File

@ -1269,103 +1269,102 @@ struct PatchesSelectionWindow : Window {
virtual void OnClick(Point pt, int widget) virtual void OnClick(Point pt, int widget)
{ {
switch (widget) { if (widget != PATCHSEL_OPTIONSPANEL) return;
case PATCHSEL_OPTIONSPANEL: {
int y = pt.y - SETTINGTREE_TOP_OFFSET; // Shift y coordinate
if (y < 0) return; // Clicked above first entry
byte btn = this->vscroll.pos + y / SETTING_HEIGHT; // Compute which setting is selected int y = pt.y - SETTINGTREE_TOP_OFFSET; // Shift y coordinate
if (y % SETTING_HEIGHT > SETTING_HEIGHT - 2) return; // Clicked too low at the setting if (y < 0) return; // Clicked above first entry
uint cur_row = 0; byte btn = this->vscroll.pos + y / SETTING_HEIGHT; // Compute which setting is selected
PatchEntry *pe = _patches_main_page.FindEntry(btn, &cur_row); if (y % SETTING_HEIGHT > SETTING_HEIGHT - 2) return; // Clicked too low at the setting
if (pe == NULL) return; // Clicked below the last setting of the page uint cur_row = 0;
PatchEntry *pe = _patches_main_page.FindEntry(btn, &cur_row);
int x = pt.x - SETTINGTREE_LEFT_OFFSET - (pe->level + 1) * LEVEL_WIDTH; // Shift x coordinate if (pe == NULL) return; // Clicked below the last setting of the page
if (x < 0) return; // Clicked left of the entry
if ((pe->flags & PEF_KIND_MASK) == PEF_SUBTREE_KIND) { int x = pt.x - SETTINGTREE_LEFT_OFFSET - (pe->level + 1) * LEVEL_WIDTH; // Shift x coordinate
pe->d.sub.folded = !pe->d.sub.folded; // Flip 'folded'-ness of the sub-page if (x < 0) return; // Clicked left of the entry
SetVScrollCount(this, _patches_main_page.Length()); if ((pe->flags & PEF_KIND_MASK) == PEF_SUBTREE_KIND) {
this->SetDirty(); pe->d.sub.folded = !pe->d.sub.folded; // Flip 'folded'-ness of the sub-page
return;
}
assert((pe->flags & PEF_KIND_MASK) == PEF_SETTING_KIND); SetVScrollCount(this, _patches_main_page.Length());
const SettingDesc *sd = pe->d.entry.setting; this->SetDirty();
return;
}
/* return if action is only active in network, or only settable by server */ assert((pe->flags & PEF_KIND_MASK) == PEF_SETTING_KIND);
if (!(sd->save.conv & SLF_NETWORK_NO) && _networking && !_network_server) return; const SettingDesc *sd = pe->d.entry.setting;
if ((sd->desc.flags & SGF_NETWORK_ONLY) && !_networking) return;
if ((sd->desc.flags & SGF_NO_NETWORK) && _networking) return;
void *var = GetVariableAddress(patches_ptr, &sd->save); /* return if action is only active in network, or only settable by server */
int32 value = (int32)ReadValue(var, sd->save.conv); if (!(sd->save.conv & SLF_NETWORK_NO) && _networking && !_network_server) return;
if ((sd->desc.flags & SGF_NETWORK_ONLY) && !_networking) return;
if ((sd->desc.flags & SGF_NO_NETWORK) && _networking) return;
/* clicked on the icon on the left side. Either scroller or bool on/off */ void *var = GetVariableAddress(patches_ptr, &sd->save);
if (x < 21) { int32 value = (int32)ReadValue(var, sd->save.conv);
const SettingDescBase *sdb = &sd->desc;
int32 oldvalue = value;
switch (sdb->cmd) { /* clicked on the icon on the left side. Either scroller or bool on/off */
case SDT_BOOLX: value ^= 1; break; if (x < 21) {
case SDT_ONEOFMANY: const SettingDescBase *sdb = &sd->desc;
case SDT_NUMX: { int32 oldvalue = value;
/* Add a dynamic step-size to the scroller. In a maximum of
* 50-steps you should be able to get from min to max,
* unless specified otherwise in the 'interval' variable
* of the current patch. */
uint32 step = (sdb->interval == 0) ? ((sdb->max - sdb->min) / 50) : sdb->interval;
if (step == 0) step = 1;
/* don't allow too fast scrolling */ switch (sdb->cmd) {
if ((this->flags4 & WF_TIMEOUT_MASK) > WF_TIMEOUT_TRIGGER) { case SDT_BOOLX: value ^= 1; break;
_left_button_clicked = false; case SDT_ONEOFMANY:
return; case SDT_NUMX: {
} /* Add a dynamic step-size to the scroller. In a maximum of
* 50-steps you should be able to get from min to max,
* unless specified otherwise in the 'interval' variable
* of the current patch. */
uint32 step = (sdb->interval == 0) ? ((sdb->max - sdb->min) / 50) : sdb->interval;
if (step == 0) step = 1;
/* Increase or decrease the value and clamp it to extremes */ /* don't allow too fast scrolling */
if (x >= 10) { if ((this->flags4 & WF_TIMEOUT_MASK) > WF_TIMEOUT_TRIGGER) {
value += step; _left_button_clicked = false;
if (value > sdb->max) value = sdb->max; return;
if (value < sdb->min) value = sdb->min; // skip between "disabled" and minimum
} else {
value -= step;
if (value < sdb->min) value = (sdb->flags & SGF_0ISDISABLED) ? 0 : sdb->min;
}
/* Set up scroller timeout for numeric values */
if (value != oldvalue && !(sd->desc.flags & SGF_MULTISTRING)) {
if (this->clicked_entry != NULL) { // Release previous buttons if any
this->clicked_entry->SetButtons(0);
}
this->clicked_entry = pe;
this->clicked_entry->SetButtons((x >= 10) ? PEF_RIGHT_DEPRESSED : PEF_LEFT_DEPRESSED);
this->flags4 |= WF_TIMEOUT_BEGIN;
_left_button_clicked = false;
}
} break;
default: NOT_REACHED();
} }
if (value != oldvalue) { /* Increase or decrease the value and clamp it to extremes */
SetPatchValue(pe->d.entry.index, value); if (x >= 10) {
this->SetDirty(); value += step;
if (value > sdb->max) value = sdb->max;
if (value < sdb->min) value = sdb->min; // skip between "disabled" and minimum
} else {
value -= step;
if (value < sdb->min) value = (sdb->flags & SGF_0ISDISABLED) ? 0 : sdb->min;
} }
} else {
/* only open editbox for types that its sensible for */
if (sd->desc.cmd != SDT_BOOLX && !(sd->desc.flags & SGF_MULTISTRING)) {
/* Show the correct currency-translated value */
if (sd->desc.flags & SGF_CURRENCY) value *= _currency->rate;
this->valuewindow_entry = pe; /* Set up scroller timeout for numeric values */
SetDParam(0, value); if (value != oldvalue && !(sd->desc.flags & SGF_MULTISTRING)) {
ShowQueryString(STR_CONFIG_PATCHES_INT32, STR_CONFIG_PATCHES_QUERY_CAPT, 10, 100, this, CS_NUMERAL, QSF_NONE); if (this->clicked_entry != NULL) { // Release previous buttons if any
this->clicked_entry->SetButtons(0);
}
this->clicked_entry = pe;
this->clicked_entry->SetButtons((x >= 10) ? PEF_RIGHT_DEPRESSED : PEF_LEFT_DEPRESSED);
this->flags4 |= WF_TIMEOUT_BEGIN;
_left_button_clicked = false;
} }
} } break;
} break;
default: NOT_REACHED();
}
if (value != oldvalue) {
SetPatchValue(pe->d.entry.index, value);
this->SetDirty();
}
} else {
/* only open editbox for types that its sensible for */
if (sd->desc.cmd != SDT_BOOLX && !(sd->desc.flags & SGF_MULTISTRING)) {
/* Show the correct currency-translated value */
if (sd->desc.flags & SGF_CURRENCY) value *= _currency->rate;
this->valuewindow_entry = pe;
SetDParam(0, value);
ShowQueryString(STR_CONFIG_PATCHES_INT32, STR_CONFIG_PATCHES_QUERY_CAPT, 10, 100, this, CS_NUMERAL, QSF_NONE);
}
} }
} }