(svn r7310) -Codechange: Change scrolling dropdown box to use 1 scroll unit = 1 line
of text, instead of 1 row of pixels. This fixes behaviour of scrolling with the scrollbar buttons and the mouse wheel.
This commit is contained in:
		
							
								
								
									
										67
									
								
								widget.c
									
									
									
									
									
								
							
							
						
						
									
										67
									
								
								widget.c
									
									
									
									
									
								
							@@ -486,7 +486,7 @@ static int GetDropdownItem(const Window *w)
 | 
				
			|||||||
	if (GetWidgetFromPos(w, _cursor.pos.x - w->left, _cursor.pos.y - w->top) < 0)
 | 
						if (GetWidgetFromPos(w, _cursor.pos.x - w->left, _cursor.pos.y - w->top) < 0)
 | 
				
			||||||
		return -1;
 | 
							return -1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	y = _cursor.pos.y - w->top - 2 + w->vscroll.pos;
 | 
						y = _cursor.pos.y - w->top - 2 + w->vscroll.pos * 10;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (y < 0)
 | 
						if (y < 0)
 | 
				
			||||||
		return - 1;
 | 
							return - 1;
 | 
				
			||||||
@@ -509,56 +509,40 @@ static void DropdownMenuWndProc(Window *w, WindowEvent *e)
 | 
				
			|||||||
	switch (e->event) {
 | 
						switch (e->event) {
 | 
				
			||||||
		case WE_PAINT: {
 | 
							case WE_PAINT: {
 | 
				
			||||||
			int x,y,i,sel;
 | 
								int x,y,i,sel;
 | 
				
			||||||
			int width;
 | 
								int width, height;
 | 
				
			||||||
			bool scroll = w->vscroll.count > 0;
 | 
					 | 
				
			||||||
			DrawPixelInfo tmp_dpi, *old_dpi = NULL;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
			DrawWindowWidgets(w);
 | 
								DrawWindowWidgets(w);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			x = 1;
 | 
								x = 1;
 | 
				
			||||||
			y = 2 - w->vscroll.pos;
 | 
								y = 2 - w->vscroll.pos * 10;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			if (scroll) {
 | 
								sel    = WP(w,dropdown_d).selected_index;
 | 
				
			||||||
				/* Set up the bounding box for drawing the list content */
 | 
								width  = w->widget[0].right - 3;
 | 
				
			||||||
				if (!FillDrawPixelInfo(&tmp_dpi, w->widget[0].left + 1, w->widget[0].top + 1, w->widget[0].right - 1, w->widget[0].bottom - 1)) return;
 | 
								height = w->widget[0].bottom - 3;
 | 
				
			||||||
				old_dpi = _cur_dpi;
 | 
					 | 
				
			||||||
				_cur_dpi = &tmp_dpi;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
				/* Adjust x and y for the 1 pixel offset of the bounding box */
 | 
								for (i = 0; WP(w,dropdown_d).items[i] != INVALID_STRING_ID; i++, sel--) {
 | 
				
			||||||
				x--;
 | 
									if (HASBIT(WP(w,dropdown_d).hidden_state, i)) continue;
 | 
				
			||||||
				y--;
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
			sel   = WP(w,dropdown_d).selected_index;
 | 
									if (y >= 0 && y <= height) {
 | 
				
			||||||
			width = w->widget[0].right - 3;
 | 
										if (WP(w,dropdown_d).items[i] != STR_NULL) {
 | 
				
			||||||
 | 
											if (sel == 0) GfxFillRect(x + 1, y, x + width, y + 9, 0);
 | 
				
			||||||
 | 
											DrawStringTruncated(x + 2, y, WP(w,dropdown_d).items[i], sel == 0 ? 12 : 16, x + width);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			for (i = 0; WP(w,dropdown_d).items[i] != INVALID_STRING_ID; i++) {
 | 
											if (HASBIT(WP(w,dropdown_d).disabled_state, i)) {
 | 
				
			||||||
				if (HASBIT(WP(w,dropdown_d).hidden_state, i)) {
 | 
												GfxFillRect(x, y, x + width, y + 9,
 | 
				
			||||||
					sel--;
 | 
													PALETTE_MODIFIER_GREYOUT | _colour_gradient[_dropdown_menu_widgets[0].color][5]
 | 
				
			||||||
					continue;
 | 
												);
 | 
				
			||||||
				}
 | 
											}
 | 
				
			||||||
				if (WP(w,dropdown_d).items[i] != STR_NULL) {
 | 
										} else {
 | 
				
			||||||
					if (sel == 0) GfxFillRect(x + 1, y, x + width, y + 9, 0);
 | 
											int c1 = _colour_gradient[_dropdown_menu_widgets[0].color][3];
 | 
				
			||||||
					DrawStringTruncated(x + 2, y, WP(w,dropdown_d).items[i], sel == 0 ? 12 : 16, x + width);
 | 
											int c2 = _colour_gradient[_dropdown_menu_widgets[0].color][7];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
					if (HASBIT(WP(w,dropdown_d).disabled_state, i)) {
 | 
											GfxFillRect(x + 1, y + 3, x + w->width - 5, y + 3, c1);
 | 
				
			||||||
						GfxFillRect(x, y, x + width, y + 9,
 | 
											GfxFillRect(x + 1, y + 4, x + w->width - 5, y + 4, c2);
 | 
				
			||||||
							PALETTE_MODIFIER_GREYOUT | _colour_gradient[_dropdown_menu_widgets[0].color][5]
 | 
					 | 
				
			||||||
						);
 | 
					 | 
				
			||||||
					}
 | 
										}
 | 
				
			||||||
				} else {
 | 
					 | 
				
			||||||
					int c1 = _colour_gradient[_dropdown_menu_widgets[0].color][3];
 | 
					 | 
				
			||||||
					int c2 = _colour_gradient[_dropdown_menu_widgets[0].color][7];
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
					GfxFillRect(x + 1, y + 3, x + w->width - 5, y + 3, c1);
 | 
					 | 
				
			||||||
					GfxFillRect(x + 1, y + 4, x + w->width - 5, y + 4, c2);
 | 
					 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
				y += 10;
 | 
									y += 10;
 | 
				
			||||||
				sel--;
 | 
					 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
					 | 
				
			||||||
			/* Reset the bounding box if we had set it up */
 | 
					 | 
				
			||||||
			if (scroll) _cur_dpi = old_dpi;
 | 
					 | 
				
			||||||
		} break;
 | 
							} break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		case WE_CLICK: {
 | 
							case WE_CLICK: {
 | 
				
			||||||
@@ -664,7 +648,8 @@ void ShowDropDownMenu(Window *w, const StringID *strings, int selected, int butt
 | 
				
			|||||||
		} else {
 | 
							} else {
 | 
				
			||||||
			/* ... and lastly if it won't, enable the scroll bar and fit the
 | 
								/* ... and lastly if it won't, enable the scroll bar and fit the
 | 
				
			||||||
			 * list in below the widget */
 | 
								 * list in below the widget */
 | 
				
			||||||
			height = screen_bottom - top;
 | 
								int rows = (screen_bottom - 4 - top) / 10;
 | 
				
			||||||
 | 
								height = rows * 10 + 4;
 | 
				
			||||||
			scroll = true;
 | 
								scroll = true;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -693,8 +678,8 @@ void ShowDropDownMenu(Window *w, const StringID *strings, int selected, int butt
 | 
				
			|||||||
		w2->widget[1].bottom = height - 1;
 | 
							w2->widget[1].bottom = height - 1;
 | 
				
			||||||
		w2->widget[0].right -= 12;
 | 
							w2->widget[0].right -= 12;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		w2->vscroll.cap   = height - 1;
 | 
							w2->vscroll.cap   = (height - 4) / 10;
 | 
				
			||||||
		w2->vscroll.count = i * 10 + 3;
 | 
							w2->vscroll.count = i;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	w2->desc_flags = WDF_DEF_WIDGET;
 | 
						w2->desc_flags = WDF_DEF_WIDGET;
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user