Changeset - r28311:87afcc7621db
[Not reviewed]
master
0 4 0
Peter Nelson - 10 months ago 2023-12-20 00:15:33
peter1138@openttd.org
Fix: Prevent picker preview sprites from overflowing button bevel.
4 files changed with 49 insertions and 36 deletions:
0 comments (0 inline, 0 general)
src/dock_gui.cpp
Show inline comments
 
@@ -546,16 +546,17 @@ public:
 

	
 
		switch (widget) {
 
			case WID_BDD_X:
 
			case WID_BDD_Y: {
 
				Axis axis = widget == WID_BDD_X ? AXIS_X : AXIS_Y;
 

	
 
				if (FillDrawPixelInfo(&tmp_dpi, r)) {
 
				Rect ir = r.Shrink(WidgetDimensions::scaled.bevel);
 
				if (FillDrawPixelInfo(&tmp_dpi, ir)) {
 
					AutoRestoreBackup dpi_backup(_cur_dpi, &tmp_dpi);
 
					int x = (r.Width()  - ScaleSpriteTrad(96)) / 2;
 
					int y = (r.Height() - ScaleSpriteTrad(64)) / 2;
 
					int x = (ir.Width()  - ScaleSpriteTrad(96)) / 2;
 
					int y = (ir.Height() - ScaleSpriteTrad(64)) / 2;
 
					int x1 = ScaleSpriteTrad(63);
 
					int x2 = ScaleSpriteTrad(31);
 
					DrawShipDepotSprite(x + (axis == AXIS_X ? x1 : x2), y + ScaleSpriteTrad(17), axis, DEPOT_PART_NORTH);
 
					DrawShipDepotSprite(x + (axis == AXIS_X ? x2 : x1), y + ScaleSpriteTrad(33), axis, DEPOT_PART_SOUTH);
 
				}
 
				break;
src/object_gui.cpp
Show inline comments
 
@@ -334,20 +334,21 @@ public:
 
				 * previews in the layouts with less views we add space homogeneously on all sides, so the 4x4 preview-rectangle
 
				 * is centered in the 2x1, 1x2 resp. 1x1 buttons. */
 
				uint matrix_height = this->GetWidget<NWidgetMatrix>(WID_BO_OBJECT_MATRIX)->current_y;
 

	
 
				DrawPixelInfo tmp_dpi;
 
				/* Set up a clipping area for the preview. */
 
				if (FillDrawPixelInfo(&tmp_dpi, r)) {
 
				Rect ir = r.Shrink(WidgetDimensions::scaled.bevel);
 
				if (FillDrawPixelInfo(&tmp_dpi, ir)) {
 
					AutoRestoreBackup dpi_backup(_cur_dpi, &tmp_dpi);
 
					if (spec->grf_prop.grffile == nullptr) {
 
						extern const DrawTileSprites _objects[];
 
						const DrawTileSprites *dts = &_objects[spec->grf_prop.local_id];
 
						DrawOrigTileSeqInGUI(r.Width() / 2 - 1, (r.Height() + matrix_height / 2) / 2 - this->object_margin - ScaleSpriteTrad(TILE_PIXELS), dts, PAL_NONE);
 
						DrawOrigTileSeqInGUI(ir.Width() / 2 - 1, (ir.Height() + matrix_height / 2) / 2 - this->object_margin - ScaleSpriteTrad(TILE_PIXELS), dts, PAL_NONE);
 
					} else {
 
						DrawNewObjectTileInGUI(r.Width() / 2 - 1, (r.Height() + matrix_height / 2) / 2 - this->object_margin - ScaleSpriteTrad(TILE_PIXELS), spec, GB(widget, 16, 16));
 
						DrawNewObjectTileInGUI(ir.Width() / 2 - 1, (ir.Height() + matrix_height / 2) / 2 - this->object_margin - ScaleSpriteTrad(TILE_PIXELS), spec, GB(widget, 16, 16));
 
					}
 
				}
 
				break;
 
			}
 

	
 
			case WID_BO_SELECT_IMAGE: {
 
@@ -359,20 +360,21 @@ public:
 

	
 
				if (!spec->IsAvailable()) {
 
					GfxFillRect(r.Shrink(WidgetDimensions::scaled.bevel), PC_BLACK, FILLRECT_CHECKER);
 
				}
 
				DrawPixelInfo tmp_dpi;
 
				/* Set up a clipping area for the preview. */
 
				if (FillDrawPixelInfo(&tmp_dpi, r)) {
 
				Rect ir = r.Shrink(WidgetDimensions::scaled.bevel);
 
				if (FillDrawPixelInfo(&tmp_dpi, ir)) {
 
					AutoRestoreBackup dpi_backup(_cur_dpi, &tmp_dpi);
 
					if (spec->grf_prop.grffile == nullptr) {
 
						extern const DrawTileSprites _objects[];
 
						const DrawTileSprites *dts = &_objects[spec->grf_prop.local_id];
 
						DrawOrigTileSeqInGUI(r.Width() / 2 - 1, r.Height() - this->object_margin - ScaleSpriteTrad(TILE_PIXELS), dts, PAL_NONE);
 
						DrawOrigTileSeqInGUI(ir.Width() / 2 - 1, ir.Height() - this->object_margin - ScaleSpriteTrad(TILE_PIXELS), dts, PAL_NONE);
 
					} else {
 
						DrawNewObjectTileInGUI(r.Width() / 2 - 1, r.Height() - this->object_margin - ScaleSpriteTrad(TILE_PIXELS), spec,
 
						DrawNewObjectTileInGUI(ir.Width() / 2 - 1, ir.Height() - this->object_margin - ScaleSpriteTrad(TILE_PIXELS), spec,
 
								std::min<int>(_selected_object_view, spec->views - 1));
 
					}
 
				}
 
				break;
 
			}
 

	
src/rail_gui.cpp
Show inline comments
 
@@ -1238,35 +1238,39 @@ public:
 

	
 
	void DrawWidget(const Rect &r, int widget) const override
 
	{
 
		DrawPixelInfo tmp_dpi;
 

	
 
		switch (GB(widget, 0, 16)) {
 
			case WID_BRAS_PLATFORM_DIR_X:
 
			case WID_BRAS_PLATFORM_DIR_X: {
 
				/* Set up a clipping area for the '/' station preview */
 
				if (FillDrawPixelInfo(&tmp_dpi, r)) {
 
				Rect ir = r.Shrink(WidgetDimensions::scaled.bevel);
 
				if (FillDrawPixelInfo(&tmp_dpi, ir)) {
 
					AutoRestoreBackup dpi_backup(_cur_dpi, &tmp_dpi);
 
					int x = (r.Width()  - ScaleSpriteTrad(64)) / 2 + ScaleSpriteTrad(31);
 
					int y = (r.Height() + ScaleSpriteTrad(58)) / 2 - ScaleSpriteTrad(31);
 
					int x = (ir.Width()  - ScaleSpriteTrad(64)) / 2 + ScaleSpriteTrad(31);
 
					int y = (ir.Height() + ScaleSpriteTrad(58)) / 2 - ScaleSpriteTrad(31);
 
					if (!DrawStationTile(x, y, _cur_railtype, AXIS_X, _railstation.station_class, _railstation.station_type)) {
 
						StationPickerDrawSprite(x, y, STATION_RAIL, _cur_railtype, INVALID_ROADTYPE, 2);
 
					}
 
				}
 
				break;
 
			}
 

	
 
			case WID_BRAS_PLATFORM_DIR_Y:
 
			case WID_BRAS_PLATFORM_DIR_Y: {
 
				/* Set up a clipping area for the '\' station preview */
 
				if (FillDrawPixelInfo(&tmp_dpi, r)) {
 
				Rect ir = r.Shrink(WidgetDimensions::scaled.bevel);
 
				if (FillDrawPixelInfo(&tmp_dpi, ir)) {
 
					AutoRestoreBackup dpi_backup(_cur_dpi, &tmp_dpi);
 
					int x = (r.Width()  - ScaleSpriteTrad(64)) / 2 + ScaleSpriteTrad(31);
 
					int y = (r.Height() + ScaleSpriteTrad(58)) / 2 - ScaleSpriteTrad(31);
 
					int x = (ir.Width()  - ScaleSpriteTrad(64)) / 2 + ScaleSpriteTrad(31);
 
					int y = (ir.Height() + ScaleSpriteTrad(58)) / 2 - ScaleSpriteTrad(31);
 
					if (!DrawStationTile(x, y, _cur_railtype, AXIS_Y, _railstation.station_class, _railstation.station_type)) {
 
						StationPickerDrawSprite(x, y, STATION_RAIL, _cur_railtype, INVALID_ROADTYPE, 3);
 
					}
 
				}
 
				break;
 
			}
 

	
 
			case WID_BRAS_NEWST_LIST: {
 
				Rect ir = r.Shrink(WidgetDimensions::scaled.matrix);
 
				uint statclass = 0;
 
				for (auto station_class : this->station_classes) {
 
					if (this->vscroll->IsVisible(statclass)) {
 
@@ -1287,16 +1291,17 @@ public:
 
				const StationSpec *statspec = StationClass::Get(_railstation.station_class)->GetSpec(type);
 
				if (!IsStationAvailable(statspec)) {
 
					GfxFillRect(r.Shrink(WidgetDimensions::scaled.bevel), PC_BLACK, FILLRECT_CHECKER);
 
				}
 

	
 
				/* Set up a clipping area for the station preview. */
 
				if (FillDrawPixelInfo(&tmp_dpi, r)) {
 
				Rect ir = r.Shrink(WidgetDimensions::scaled.bevel);
 
				if (FillDrawPixelInfo(&tmp_dpi, ir)) {
 
					AutoRestoreBackup dpi_backup(_cur_dpi, &tmp_dpi);
 
					int x = (r.Width()  - ScaleSpriteTrad(64)) / 2 + ScaleSpriteTrad(31);
 
					int y = (r.Height() + ScaleSpriteTrad(58)) / 2 - ScaleSpriteTrad(31);
 
					int x = (ir.Width()  - ScaleSpriteTrad(64)) / 2 + ScaleSpriteTrad(31);
 
					int y = (ir.Height() + ScaleSpriteTrad(58)) / 2 - ScaleSpriteTrad(31);
 
					if (!DrawStationTile(x, y, _cur_railtype, _railstation.orientation, _railstation.station_class, type)) {
 
						StationPickerDrawSprite(x, y, STATION_RAIL, _cur_railtype, INVALID_ROADTYPE, 2 + _railstation.orientation);
 
					}
 
				}
 
				break;
 
			}
 
@@ -1902,16 +1907,17 @@ struct BuildRailDepotWindow : public Pic
 

	
 
	void DrawWidget(const Rect &r, int widget) const override
 
	{
 
		if (!IsInsideMM(widget, WID_BRAD_DEPOT_NE, WID_BRAD_DEPOT_NW + 1)) return;
 

	
 
		DrawPixelInfo tmp_dpi;
 
		if (FillDrawPixelInfo(&tmp_dpi, r)) {
 
		Rect ir = r.Shrink(WidgetDimensions::scaled.bevel);
 
		if (FillDrawPixelInfo(&tmp_dpi, ir)) {
 
			AutoRestoreBackup dpi_backup(_cur_dpi, &tmp_dpi);
 
			int x = (r.Width()  - ScaleSpriteTrad(64)) / 2 + ScaleSpriteTrad(31);
 
			int y = (r.Height() + ScaleSpriteTrad(48)) / 2 - ScaleSpriteTrad(31);
 
			int x = (ir.Width()  - ScaleSpriteTrad(64)) / 2 + ScaleSpriteTrad(31);
 
			int y = (ir.Height() + ScaleSpriteTrad(48)) / 2 - ScaleSpriteTrad(31);
 
			DrawTrainDepotSprite(x, y, widget - WID_BRAD_DEPOT_NE + DIAGDIR_NE, _cur_railtype);
 
		}
 
	}
 

	
 
	void OnClick([[maybe_unused]] Point pt, int widget, [[maybe_unused]] int click_count) override
 
	{
 
@@ -2092,16 +2098,17 @@ struct BuildRailWaypointWindow : PickerW
 
		switch (GB(widget, 0, 16)) {
 
			case WID_BRW_WAYPOINT: {
 
				uint16_t type = this->list.at(GB(widget, 16, 16));
 
				const StationSpec *statspec = this->waypoints->GetSpec(type);
 

	
 
				DrawPixelInfo tmp_dpi;
 
				if (FillDrawPixelInfo(&tmp_dpi, r)) {
 
				Rect ir = r.Shrink(WidgetDimensions::scaled.bevel);
 
				if (FillDrawPixelInfo(&tmp_dpi, ir)) {
 
					AutoRestoreBackup dpi_backup(_cur_dpi, &tmp_dpi);
 
					int x = (r.Width()  - ScaleSpriteTrad(64)) / 2 + ScaleSpriteTrad(31);
 
					int y = (r.Height() + ScaleSpriteTrad(58)) / 2 - ScaleSpriteTrad(31);
 
					int x = (ir.Width()  - ScaleSpriteTrad(64)) / 2 + ScaleSpriteTrad(31);
 
					int y = (ir.Height() + ScaleSpriteTrad(58)) / 2 - ScaleSpriteTrad(31);
 
					DrawWaypointSprite(x, y, type, _cur_railtype);
 
				}
 

	
 
				if (!IsStationAvailable(statspec)) {
 
					GfxFillRect(r.Shrink(WidgetDimensions::scaled.bevel), PC_BLACK, FILLRECT_CHECKER);
 
				}
src/road_gui.cpp
Show inline comments
 
@@ -1026,16 +1026,17 @@ struct BuildRoadDepotWindow : public Pic
 

	
 
	void DrawWidget(const Rect &r, int widget) const override
 
	{
 
		if (!IsInsideMM(widget, WID_BROD_DEPOT_NE, WID_BROD_DEPOT_NW + 1)) return;
 

	
 
		DrawPixelInfo tmp_dpi;
 
		if (FillDrawPixelInfo(&tmp_dpi, r)) {
 
		Rect ir = r.Shrink(WidgetDimensions::scaled.bevel);
 
		if (FillDrawPixelInfo(&tmp_dpi, ir)) {
 
			AutoRestoreBackup dpi_backup(_cur_dpi, &tmp_dpi);
 
			int x = (r.Width()  - ScaleSpriteTrad(64)) / 2 + ScaleSpriteTrad(31);
 
			int y = (r.Height() + ScaleSpriteTrad(48)) / 2 - ScaleSpriteTrad(31);
 
			int x = (ir.Width()  - ScaleSpriteTrad(64)) / 2 + ScaleSpriteTrad(31);
 
			int y = (ir.Height() + ScaleSpriteTrad(48)) / 2 - ScaleSpriteTrad(31);
 
			DrawRoadDepotSprite(x, y, (DiagDirection)(widget - WID_BROD_DEPOT_NE + DIAGDIR_NE), _cur_roadtype);
 
		}
 
	}
 

	
 
	void OnClick([[maybe_unused]] Point pt, int widget, [[maybe_unused]] int click_count) override
 
	{
 
@@ -1414,19 +1415,20 @@ public:
 
			case WID_BROS_STATION_X:
 
			case WID_BROS_STATION_Y: {
 
				StationType st = GetRoadStationTypeByWindowClass(this->window_class);
 
				const RoadStopSpec *spec = RoadStopClass::Get(_roadstop_gui_settings.roadstop_class)->GetSpec(_roadstop_gui_settings.roadstop_type);
 
				bool disabled = (spec != nullptr && widget < WID_BROS_STATION_X && HasBit(spec->flags, RSF_DRIVE_THROUGH_ONLY));
 
				DrawPixelInfo tmp_dpi;
 
				if (FillDrawPixelInfo(&tmp_dpi, r)) {
 
				Rect ir = r.Shrink(WidgetDimensions::scaled.bevel);
 
				if (FillDrawPixelInfo(&tmp_dpi, ir)) {
 
					AutoRestoreBackup dpi_backup(_cur_dpi, &tmp_dpi);
 
					int x = (r.Width()  - ScaleSpriteTrad(64)) / 2 + ScaleSpriteTrad(31);
 
					int y = (r.Height() + ScaleSpriteTrad(48)) / 2 - ScaleSpriteTrad(31);
 
					int x = (ir.Width()  - ScaleSpriteTrad(64)) / 2 + ScaleSpriteTrad(31);
 
					int y = (ir.Height() + ScaleSpriteTrad(48)) / 2 - ScaleSpriteTrad(31);
 
					if (spec == nullptr || disabled) {
 
						StationPickerDrawSprite(x, y, st, INVALID_RAILTYPE, _cur_roadtype, widget - WID_BROS_STATION_NE);
 
						if (disabled) GfxFillRect(1, 1, r.Width() - 1, r.Height() - 1, PC_BLACK, FILLRECT_CHECKER);
 
						if (disabled) GfxFillRect(0, 0, ir.Width(), ir.Height(), PC_BLACK, FILLRECT_CHECKER);
 
					} else {
 
						DrawRoadStopTile(x, y, _cur_roadtype, spec, st, widget - WID_BROS_STATION_NE);
 
					}
 
				}
 
				break;
 
			}
 
@@ -1456,16 +1458,17 @@ public:
 
				if (!IsRoadStopAvailable(spec, st)) {
 
					GfxFillRect(r.Shrink(WidgetDimensions::scaled.bevel), PC_BLACK, FILLRECT_CHECKER);
 
				}
 

	
 
				/* Set up a clipping area for the sprite preview. */
 
				DrawPixelInfo tmp_dpi;
 
				if (FillDrawPixelInfo(&tmp_dpi, r)) {
 
				Rect ir = r.Shrink(WidgetDimensions::scaled.bevel);
 
				if (FillDrawPixelInfo(&tmp_dpi, ir)) {
 
					AutoRestoreBackup dpi_backup(_cur_dpi, &tmp_dpi);
 
					int x = (r.Width()  - ScaleSpriteTrad(64)) / 2 + ScaleSpriteTrad(31);
 
					int y = (r.Height() + ScaleSpriteTrad(48)) / 2 - ScaleSpriteTrad(31);
 
					int x = (ir.Width()  - ScaleSpriteTrad(64)) / 2 + ScaleSpriteTrad(31);
 
					int y = (ir.Height() + ScaleSpriteTrad(48)) / 2 - ScaleSpriteTrad(31);
 
					if (spec == nullptr) {
 
						StationPickerDrawSprite(x, y, st, INVALID_RAILTYPE, _cur_roadtype, _roadstop_gui_settings.orientation);
 
					} else {
 
						DiagDirection orientation = _roadstop_gui_settings.orientation;
 
						if (orientation < DIAGDIR_END && HasBit(spec->flags, RSF_DRIVE_THROUGH_ONLY)) orientation = DIAGDIR_END;
 
						DrawRoadStopTile(x, y, _cur_roadtype, spec, st, (uint8_t)orientation);
0 comments (0 inline, 0 general)