diff options
author | peter1138 <peter1138@openttd.org> | 2005-09-23 07:44:03 +0000 |
---|---|---|
committer | peter1138 <peter1138@openttd.org> | 2005-09-23 07:44:03 +0000 |
commit | 9c2700b14ca96b76a357ee27ae1abbc2a3736658 (patch) | |
tree | 9dc6feea02a86c189e304662e0168b31a20fa5ec | |
parent | 313fcfbd83e45f8b4d6041402306685ab787d42e (diff) | |
download | openttd-9c2700b14ca96b76a357ee27ae1abbc2a3736658.tar.xz |
(svn r2974) -Fix: Drag and drop selection on drop down boxes didn't select correct item when some items were hidden.
-Separate disabled and hidden masks in drop downs to support both hidden and disabled items.
-rw-r--r-- | vehicle_gui.c | 2 | ||||
-rw-r--r-- | widget.c | 34 | ||||
-rw-r--r-- | window.h | 2 |
3 files changed, 17 insertions, 21 deletions
diff --git a/vehicle_gui.c b/vehicle_gui.c index 5cf2b5dae..1d44f03f9 100644 --- a/vehicle_gui.c +++ b/vehicle_gui.c @@ -906,7 +906,7 @@ static void ReplaceVehicleWndProc(Window *w, WindowEvent *e) switch (e->click.widget) { case 14: case 15: { /* Select sorting criteria dropdown menu */ - ShowDropDownMenu(w, _rail_types_list, _railtype_selected_in_replace_gui, 15, ~GetPlayer(_local_player)->avail_railtypes, 1); + ShowDropDownMenu(w, _rail_types_list, _railtype_selected_in_replace_gui, 15, 0, ~GetPlayer(_local_player)->avail_railtypes); break; } case 4: { /* Start replacing */ @@ -442,7 +442,7 @@ draw_default:; static uint _dropdown_item_count; static uint32 _dropdown_disabled; -static bool _dropdown_hide_disabled; +static uint32 _dropdown_hidden; static const StringID *_dropdown_items; static int _dropdown_selindex; static byte _dropdown_button; @@ -450,7 +450,6 @@ 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}, @@ -459,7 +458,7 @@ static const Widget _dropdown_menu_widgets[] = { static int GetDropdownItem(const Window *w) { - uint item; + byte item, counter; int y; if (GetWidgetFromPos(w, _cursor.pos.x - w->left, _cursor.pos.y - w->top) < 0) @@ -471,9 +470,13 @@ static int GetDropdownItem(const Window *w) return - 1; item = y / 10; - if (item >= _dropdown_item_count || (HASBIT(_dropdown_disabled,item) && !_dropdown_disabled_items) || _dropdown_items[item] == 0) + if (item >= _dropdown_item_count || (HASBIT(_dropdown_disabled, item) && !HASBIT(_dropdown_hidden, item)) || _dropdown_items[item] == 0) return - 1; + // Skip hidden items -- +1 for each hidden item before the clicked item. + for (counter = 0; item >= counter; ++counter) + if (HASBIT(_dropdown_hidden, counter)) item++; + return item; } @@ -492,7 +495,7 @@ static void DropdownMenuWndProc(Window *w, WindowEvent *e) sel = _dropdown_selindex; for(i=0; _dropdown_items[i] != INVALID_STRING_ID; i++) { - if (HASBIT(_dropdown_disabled_items, i)) { + if (HASBIT(_dropdown_hidden, i)) { sel--; continue; } @@ -502,7 +505,7 @@ static void DropdownMenuWndProc(Window *w, WindowEvent *e) } DrawString(x+2, y, _dropdown_items[i], sel==0 ? 12 : 16); - if (HASBIT(_dropdown_disabled, i) && !_dropdown_disabled_items) { + if (HASBIT(_dropdown_disabled, i)) { GfxFillRect(x, y, x+w->width-3, y + 9, PALETTE_MODIFIER_GREYOUT | _color_list[_dropdown_menu_widgets[0].color].window_color_bga); } @@ -520,12 +523,6 @@ static void DropdownMenuWndProc(Window *w, WindowEvent *e) 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); @@ -577,7 +574,7 @@ static void DropdownMenuWndProc(Window *w, WindowEvent *e) } } -void ShowDropDownMenu(Window *w, const StringID *strings, int selected, int button, uint32 disabled_mask, bool remove_filtered_strings) +void ShowDropDownMenu(Window *w, const StringID *strings, int selected, int button, uint32 disabled_mask, uint32 hidden_mask) { WindowNumber num; WindowClass cls; @@ -587,7 +584,7 @@ void ShowDropDownMenu(Window *w, const StringID *strings, int selected, int butt uint32 old_click_state = w->click_state; _dropdown_disabled = disabled_mask; - _dropdown_hide_disabled = remove_filtered_strings; + _dropdown_hidden = hidden_mask; cls = w->window_class; num = w->window_number; @@ -606,7 +603,6 @@ void ShowDropDownMenu(Window *w, const StringID *strings, int selected, int butt return; _dropdown_items = strings; - _dropdown_item_count = i; _dropdown_selindex = selected; _dropdown_windowclass = w->window_class; @@ -618,16 +614,17 @@ void ShowDropDownMenu(Window *w, const StringID *strings, int selected, int butt wi = &w->widget[button]; - if ( remove_filtered_strings ) { + if (hidden_mask != 0) { int j; for(j=0; _dropdown_items[j] != INVALID_STRING_ID; j++) { - if ( disabled_mask & ( 1 << j )) { - _dropdown_item_count--; + if (HASBIT(hidden_mask, j)) { i--; } } } + _dropdown_item_count = i; + w2 = AllocateWindow( w->left + wi[-1].left + 1, w->top + wi->bottom + 2, @@ -640,7 +637,6 @@ void ShowDropDownMenu(Window *w, const StringID *strings, int selected, int butt 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; } @@ -617,7 +617,7 @@ int PositionMainToolbar(Window *w); /* widget.c */ int GetWidgetFromPos(const Window *w, int x, int y); void DrawWindowWidgets(const Window *w); -void ShowDropDownMenu(Window *w, const StringID *strings, int selected, int button, uint32 disabled_mask, bool remove_filtered_strings); +void ShowDropDownMenu(Window *w, const StringID *strings, int selected, int button, uint32 disabled_mask, uint32 hidden_mask); void HandleButtonClick(Window *w, byte widget); |