Changeset - r26651:737202ebbd5c
[Not reviewed]
master
0 3 0
Peter Nelson - 18 months ago 2022-12-11 23:45:07
peter1138@openttd.org
Add: Sprite centre and crosshair toggles on sprite aligner.
3 files changed with 47 insertions and 6 deletions:
0 comments (0 inline, 0 general)
src/lang/english.txt
Show inline comments
 
@@ -3325,6 +3325,13 @@ STR_SPRITE_ALIGNER_PREVIOUS_BUTTON      
 
STR_SPRITE_ALIGNER_PREVIOUS_TOOLTIP                             :{BLACK}Proceed to the previous normal sprite, skipping any pseudo/recolour/font sprites and wrapping around from the first sprite to the last
 
STR_SPRITE_ALIGNER_SPRITE_TOOLTIP                               :{BLACK}Representation of the currently selected sprite. The alignment is ignored when drawing this sprite
 
STR_SPRITE_ALIGNER_MOVE_TOOLTIP                                 :{BLACK}Move the sprite around, changing the X and Y offsets. Ctrl+Click to move the sprite eight units at a time
 

	
 
###length 2
 
STR_SPRITE_ALIGNER_CENTRE_OFFSET                                :{BLACK}Offset centred
 
STR_SPRITE_ALIGNER_CENTRE_SPRITE                                :{BLACK}Sprite centred
 

	
 
STR_SPRITE_ALIGNER_CROSSHAIR                                    :{BLACK}Crosshair
 

	
 
STR_SPRITE_ALIGNER_RESET_BUTTON                                 :{BLACK}Reset relative
 
STR_SPRITE_ALIGNER_RESET_TOOLTIP                                :{BLACK}Reset the current relative offsets
 
STR_SPRITE_ALIGNER_OFFSETS_ABS                                  :{BLACK}X offset: {NUM}, Y offset: {NUM} (Absolute)
src/newgrf_debug_gui.cpp
Show inline comments
 
@@ -808,12 +808,18 @@ struct SpriteAlignerWindow : Window {
 
	Scrollbar *vscroll;
 
	SmallMap<SpriteID, XyOffs> offs_start_map; ///< Mapping of starting offsets for the sprites which have been aligned in the sprite aligner window.
 

	
 
	static bool centre;
 
	static bool crosshair;
 

	
 
	SpriteAlignerWindow(WindowDesc *desc, WindowNumber wno) : Window(desc)
 
	{
 
		this->CreateNestedTree();
 
		this->vscroll = this->GetScrollbar(WID_SA_SCROLLBAR);
 
		this->FinishInitNested(wno);
 

	
 
		this->SetWidgetLoweredState(WID_SA_CENTRE, SpriteAlignerWindow::centre);
 
		this->SetWidgetLoweredState(WID_SA_CROSSHAIR, SpriteAlignerWindow::crosshair);
 

	
 
		/* Oh yes, we assume there is at least one normal sprite! */
 
		while (GetSpriteType(this->current_sprite) != ST_NORMAL) this->current_sprite++;
 
	}
 
@@ -875,8 +881,15 @@ struct SpriteAlignerWindow : Window {
 
				/* Center the sprite ourselves */
 
				const Sprite *spr = GetSprite(this->current_sprite, ST_NORMAL);
 
				Rect ir = r.Shrink(WidgetDimensions::scaled.bevel);
 
				int x = -UnScaleGUI(spr->x_offs) + (ir.Width()  - UnScaleGUI(spr->width) ) / 2;
 
				int y = -UnScaleGUI(spr->y_offs) + (ir.Height() - UnScaleGUI(spr->height)) / 2;
 
				int x;
 
				int y;
 
				if (SpriteAlignerWindow::centre) {
 
					x = -UnScaleGUI(spr->x_offs) + (ir.Width() - UnScaleGUI(spr->width)) / 2;
 
					y = -UnScaleGUI(spr->y_offs) + (ir.Height() - UnScaleGUI(spr->height)) / 2;
 
				} else {
 
					x = ir.Width() / 2;
 
					y = ir.Height() / 2;
 
				}
 

	
 
				DrawPixelInfo new_dpi;
 
				if (!FillDrawPixelInfo(&new_dpi, ir.left, ir.top, ir.Width(), ir.Height())) break;
 
@@ -884,6 +897,10 @@ struct SpriteAlignerWindow : Window {
 
				_cur_dpi = &new_dpi;
 

	
 
				DrawSprite(this->current_sprite, PAL_NONE, x, y, nullptr, ZOOM_LVL_GUI);
 
				if (this->crosshair) {
 
					GfxDrawLine(x, 0, x, ir.Height() - 1, PC_WHITE, 1, 1);
 
					GfxDrawLine(0, y, ir.Width() - 1, y, PC_WHITE, 1, 1);
 
				}
 

	
 
				_cur_dpi = old_dpi;
 

	
 
@@ -989,6 +1006,18 @@ struct SpriteAlignerWindow : Window {
 
				this->offs_start_map.Erase(this->current_sprite);
 
				this->SetDirty();
 
				break;
 

	
 
			case WID_SA_CENTRE:
 
				SpriteAlignerWindow::centre = !SpriteAlignerWindow::centre;
 
				this->SetWidgetLoweredState(widget, SpriteAlignerWindow::centre);
 
				this->SetDirty();
 
				break;
 

	
 
			case WID_SA_CROSSHAIR:
 
				SpriteAlignerWindow::crosshair = !SpriteAlignerWindow::crosshair;
 
				this->SetWidgetLoweredState(widget, SpriteAlignerWindow::crosshair);
 
				this->SetDirty();
 
				break;
 
		}
 
	}
 

	
 
@@ -1025,6 +1054,9 @@ struct SpriteAlignerWindow : Window {
 
	}
 
};
 

	
 
bool SpriteAlignerWindow::centre = true;
 
bool SpriteAlignerWindow::crosshair = true;
 

	
 
static const NWidgetPart _nested_sprite_aligner_widgets[] = {
 
	NWidget(NWID_HORIZONTAL),
 
		NWidget(WWT_CLOSEBOX, COLOUR_GREY),
 
@@ -1066,10 +1098,10 @@ static const NWidgetPart _nested_sprite_
 
				EndContainer(),
 
				NWidget(WWT_LABEL, COLOUR_GREY, WID_SA_OFFSETS_ABS), SetDataTip(STR_SPRITE_ALIGNER_OFFSETS_ABS, STR_NULL), SetFill(1, 0), SetPadding(0, 10, 0, 10),
 
				NWidget(WWT_LABEL, COLOUR_GREY, WID_SA_OFFSETS_REL), SetDataTip(STR_SPRITE_ALIGNER_OFFSETS_REL, STR_NULL), SetFill(1, 0), SetPadding(0, 10, 0, 10),
 
				NWidget(NWID_HORIZONTAL), SetPIP(10, 5, 10),
 
					NWidget(NWID_SPACER), SetFill(1, 1),
 
					NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SA_RESET_REL), SetDataTip(STR_SPRITE_ALIGNER_RESET_BUTTON, STR_SPRITE_ALIGNER_RESET_TOOLTIP), SetFill(0, 0),
 
					NWidget(NWID_SPACER), SetFill(1, 1),
 
				NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(10, 5, 10),
 
					NWidget(WWT_TEXTBTN_2, COLOUR_GREY, WID_SA_CENTRE), SetDataTip(STR_SPRITE_ALIGNER_CENTRE_OFFSET, STR_NULL), SetFill(1, 0),
 
					NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SA_RESET_REL), SetDataTip(STR_SPRITE_ALIGNER_RESET_BUTTON, STR_SPRITE_ALIGNER_RESET_TOOLTIP), SetFill(1, 0),
 
					NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_SA_CROSSHAIR), SetDataTip(STR_SPRITE_ALIGNER_CROSSHAIR, STR_NULL), SetFill(1, 0),
 
				EndContainer(),
 
			EndContainer(),
 
			NWidget(NWID_VERTICAL), SetPIP(10, 5, 10),
src/widgets/newgrf_debug_widget.h
Show inline comments
 
@@ -38,6 +38,8 @@ enum SpriteAlignerWidgets {
 
	WID_SA_LIST,        ///< Queried sprite list.
 
	WID_SA_SCROLLBAR,   ///< Scrollbar for sprite list.
 
	WID_SA_RESET_REL,   ///< Reset relative sprite offset
 
	WID_SA_CENTRE,      ///< Toggle centre sprite.
 
	WID_SA_CROSSHAIR,   ///< Toggle crosshair.
 
};
 

	
 
#endif /* WIDGETS_NEWGRF_DEBUG_WIDGET_H */
0 comments (0 inline, 0 general)