Changeset - r26625:305bf9c06c64
[Not reviewed]
master
0 1 0
PeterN - 2 years ago 2022-12-03 09:31:52
peter1138@openttd.org
Fix #10114: Incorrect drag-highlight position with non-power-of-2 scaling. (#10211)
1 file changed with 9 insertions and 5 deletions:
0 comments (0 inline, 0 general)
src/train_gui.cpp
Show inline comments
 
@@ -53,11 +53,12 @@ void CcBuildWagon(Commands cmd, const Co
 
 * Highlight the position where a rail vehicle is dragged over by drawing a light gray background.
 
 * @param px        The current x position to draw from.
 
 * @param max_width The maximum space available to draw.
 
 * @param y         The vertical centre position to draw from.
 
 * @param selection Selected vehicle that is dragged.
 
 * @param chain     Whether a whole chain is dragged.
 
 * @return The width of the highlight mark.
 
 */
 
static int HighlightDragPosition(int px, int max_width, VehicleID selection, bool chain)
 
static int HighlightDragPosition(int px, int max_width, int y, VehicleID selection, bool chain)
 
{
 
	bool rtl = _current_text_dir == TD_RTL;
 

	
 
@@ -72,8 +73,11 @@ static int HighlightDragPosition(int px,
 
	int drag_hlight_width = std::max(drag_hlight_right - drag_hlight_left + 1, 0);
 

	
 
	if (drag_hlight_width > 0) {
 
		GfxFillRect(drag_hlight_left + WidgetDimensions::scaled.framerect.left, WidgetDimensions::scaled.framerect.top + 1,
 
				drag_hlight_right - WidgetDimensions::scaled.framerect.right, ScaleSpriteTrad(13) - WidgetDimensions::scaled.framerect.bottom, _colour_gradient[COLOUR_GREY][7]);
 
		int height = ScaleSpriteTrad(12);
 
		int top = y - height / 2;
 
		Rect r = {drag_hlight_left, top, drag_hlight_right, top + height - 1};
 
		/* Sprite-scaling is used here as the area is from sprite size */
 
		GfxFillRect(r.Shrink(ScaleSpriteTrad(1)), _colour_gradient[COLOUR_GREY][7]);
 
	}
 

	
 
	return drag_hlight_width;
 
@@ -111,7 +115,7 @@ void DrawTrainImage(const Train *v, cons
 
	for (; v != nullptr && (rtl ? px > 0 : px < max_width); v = v->Next()) {
 
		if (dragging && !drag_at_end_of_train && drag_dest == v->index) {
 
			/* Highlight the drag-and-drop destination inside the train. */
 
			int drag_hlight_width = HighlightDragPosition(px, max_width, selection, _cursor.vehchain);
 
			int drag_hlight_width = HighlightDragPosition(px, max_width, y, selection, _cursor.vehchain);
 
			px += rtl ? -drag_hlight_width : drag_hlight_width;
 
		}
 

	
 
@@ -145,7 +149,7 @@ void DrawTrainImage(const Train *v, cons
 

	
 
	if (dragging && drag_at_end_of_train) {
 
		/* Highlight the drag-and-drop destination at the end of the train. */
 
		HighlightDragPosition(px, max_width, selection, _cursor.vehchain);
 
		HighlightDragPosition(px, max_width, y, selection, _cursor.vehchain);
 
	}
 

	
 
	_cur_dpi = old_dpi;
0 comments (0 inline, 0 general)