Changeset - r10674:cd3481e9e96f
[Not reviewed]
master
0 1 0
rubidium - 15 years ago 2009-01-10 19:22:05
rubidium@openttd.org
(svn r14978) -Codechange: simplify the control flow of the OnClick of the settings window
1 file changed with 3 insertions and 4 deletions:
0 comments (0 inline, 0 general)
src/settings_gui.cpp
Show inline comments
 
@@ -1260,26 +1260,26 @@ struct PatchesSelectionWindow : Window {
 
		this->FindWindowPlacementAndResize(desc);
 
	}
 

	
 
	virtual void OnPaint()
 
	{
 
		this->DrawWidgets();
 
		_patches_main_page.Draw(patches_ptr, SETTINGTREE_LEFT_OFFSET, SETTINGTREE_TOP_OFFSET,
 
						this->vscroll.pos, this->vscroll.pos + this->vscroll.cap);
 
	}
 

	
 
	virtual void OnClick(Point pt, int widget)
 
	{
 
		switch (widget) {
 
			case PATCHSEL_OPTIONSPANEL: {
 
		if (widget != PATCHSEL_OPTIONSPANEL) return;
 

	
 
				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
 
				if (y % SETTING_HEIGHT > SETTING_HEIGHT - 2) return;  // Clicked too low at the setting
 

	
 
				uint cur_row = 0;
 
				PatchEntry *pe = _patches_main_page.FindEntry(btn, &cur_row);
 

	
 
				if (pe == NULL) return;  // Clicked below the last setting of the page
 

	
 
				int x = pt.x - SETTINGTREE_LEFT_OFFSET - (pe->level + 1) * LEVEL_WIDTH;  // Shift x coordinate
 
@@ -1338,44 +1338,43 @@ struct PatchesSelectionWindow : Window {
 

	
 
						/* 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) {
 
						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);
 
					}
 
				}
 
			} break;
 
		}
 
	}
 

	
 
	virtual void OnTimeout()
 
	{
 
		if (this->clicked_entry != NULL) { // On timeout, release any depressed buttons
 
			this->clicked_entry->SetButtons(0);
 
			this->clicked_entry = NULL;
 
			this->SetDirty();
 
		}
 
	}
 

	
 
	virtual void OnQueryTextFinished(char *str)
0 comments (0 inline, 0 general)