Changeset - r1177:9acfc6452339
[Not reviewed]
master
0 2 0
bjarni - 19 years ago 2005-01-26 11:23:54
bjarni@openttd.org
(svn r1679) Fix: dropdown menus now returns the index of the string that was clicked even if a previous item is hidden
This bug was not triggered by the current code, but it's easier to code new features if you do not have to think about such limitations
like you can't hide an item in the middle of the list ;)
2 files changed with 28 insertions and 25 deletions:
0 comments (0 inline, 0 general)
vehicle_gui.c
Show inline comments
 
@@ -867,7 +867,6 @@ static void ReplaceVehicleWndProc(Window
 
		} break;
 

	
 
		case WE_DROPDOWN_SELECT: { /* we have selected a dropdown item in the list */
 
			//potiential bug: railtypes needs to be activated 0, 1, 2... If one is skipped, it messes up
 
			WP(w,replaceveh_d).railtype = e->dropdown.index;
 
			SetWindowDirty(w);
 
		} break;
widget.c
Show inline comments
 
@@ -452,6 +452,7 @@ static WindowClass _dropdown_windowclass
 
static WindowNumber _dropdown_windownum;
 
static byte _dropdown_var1;
 
static byte _dropdown_var2;
 
static uint32 _dropdown_disabled_items;
 

	
 
static const Widget _dropdown_menu_widgets[] = {
 
{     WWT_IMGBTN,   RESIZE_NONE,     0,     0, 0,     0, 0, 0x0, STR_NULL},
 
@@ -472,7 +473,7 @@ static int GetDropdownItem(Window *w)
 
		return - 1;
 

	
 
	item = y / 10;
 
	if (item >= _dropdown_item_count || HASBIT(_dropdown_disabled,item) || _dropdown_items[item] == 0)
 
	if (item >= _dropdown_item_count || (HASBIT(_dropdown_disabled,item) && !_dropdown_disabled_items) || _dropdown_items[item] == 0)
 
		return - 1;
 

	
 
	return item;
 
@@ -485,46 +486,48 @@ static void DropdownMenuWndProc(Window *
 
	switch(e->event) {
 
		case WE_PAINT: {
 
			int x,y,i,sel;
 
			uint32 dis;
 
			bool hidden;
 

	
 
			DrawWindowWidgets(w);
 

	
 
			x = 1;
 
			y = 2;
 
			sel    = _dropdown_selindex;
 
			dis    = _dropdown_disabled;
 
			hidden = _dropdown_hide_disabled;
 

	
 

	
 
			for(i=0; _dropdown_items[i] != INVALID_STRING_ID; i++) {
 
				if (!(hidden && (dis & 1))) {
 
					if (_dropdown_items[i] != 0) {
 
						if (sel == 0) {
 
							GfxFillRect(x+1, y, x+w->width-4, y + 9, 0);
 
						}
 
						DrawString(x+2, y, _dropdown_items[i], sel==0 ? 12 : 16);
 
				if (HASBIT(_dropdown_disabled_items, i)) {
 
					sel--;
 
					continue;
 
				}
 
				if (_dropdown_items[i] != 0) {
 
					if (sel == 0) {
 
						GfxFillRect(x+1, y, x+w->width-4, y + 9, 0);
 
					}
 
					DrawString(x+2, y, _dropdown_items[i], sel==0 ? 12 : 16);
 

	
 
						if (dis & 1) {
 
							GfxFillRect(x, y, x+w->width-3, y + 9, 0x8000 +
 
							_color_list[w->widget[0].color].window_color_bga);
 
						}
 
					} else {
 
						int color_1 = _color_list[w->widget[0].color].window_color_1a;
 
						int color_2 = _color_list[w->widget[0].color].window_color_2;
 
						GfxFillRect(x+1, y+3, x+w->width-5, y+3, color_1);
 
						GfxFillRect(x+1, y+4, x+w->width-5, y+4, color_2);
 
					if (HASBIT(_dropdown_disabled, i) && !_dropdown_disabled_items) {
 
						GfxFillRect(x, y, x+w->width-3, y + 9, 0x8000 +
 
									_color_list[_dropdown_menu_widgets[0].color].window_color_bga);
 
					}
 
					y += 10;
 
					sel--;
 
				} else {
 
					int color_1 = _color_list[_dropdown_menu_widgets[0].color].window_color_1a;
 
					int color_2 = _color_list[_dropdown_menu_widgets[0].color].window_color_2;
 
					GfxFillRect(x+1, y+3, x+w->width-5, y+3, color_1);
 
					GfxFillRect(x+1, y+4, x+w->width-5, y+4, color_2);
 
				}
 
				dis>>=1;
 
				y += 10;
 
				sel--;
 
			}
 
		} break;
 

	
 
		case WE_CLICK: {
 
			item = GetDropdownItem(w);
 
			if (item >= 0) {
 
				// make sure that item match the index of the string, that was clicked
 
				// basically we just add one for each hidden item before the clicked one
 
				byte counter;
 
				for (counter = 0 ; item >= counter; ++counter) {
 
					if (HASBIT(_dropdown_disabled_items, counter)) item++;
 
				}
 
				_dropdown_var1 = 4;
 
				_dropdown_selindex = item;
 
				SetWindowDirty(w);
 
@@ -639,6 +642,7 @@ void ShowDropDownMenu(Window *w, const S
 
	w2->widget[0].color = wi->color;
 
	w2->widget[0].right = wi->right - wi[-1].left;
 
	w2->widget[0].bottom = i * 10 + 3;
 
	_dropdown_disabled_items = remove_filtered_strings ? disabled_mask : 0;
 

	
 
	w2->flags4 &= ~WF_WHITE_BORDER_MASK;
 
}
0 comments (0 inline, 0 general)