mirror of https://github.com/OpenTTD/OpenTTD
(svn r25929) -Fix [FS#5733]: Position signal sprites size-aware in the signal GUI, that is: Center sprites horizontally, and align the vertical reference point at some baseline which centers the tallest sprite.
parent
7351158b3c
commit
56e5a80f5a
|
@ -1453,6 +1453,7 @@ static void ShowStationBuilder(Window *parent)
|
||||||
struct BuildSignalWindow : public PickerWindowBase {
|
struct BuildSignalWindow : public PickerWindowBase {
|
||||||
private:
|
private:
|
||||||
Dimension sig_sprite_size; ///< Maximum size of signal GUI sprites.
|
Dimension sig_sprite_size; ///< Maximum size of signal GUI sprites.
|
||||||
|
int sig_sprite_bottom_offset; ///< Maximum extent of signal GUI sprite from reference point towards bottom.
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Draw dynamic a signal-sprite in a button in the signal GUI
|
* Draw dynamic a signal-sprite in a button in the signal GUI
|
||||||
|
@ -1463,26 +1464,17 @@ private:
|
||||||
*/
|
*/
|
||||||
void DrawSignalSprite(byte widget_index, SpriteID image) const
|
void DrawSignalSprite(byte widget_index, SpriteID image) const
|
||||||
{
|
{
|
||||||
/* Next get the actual sprite so we can calculate the right offsets. */
|
Point offset;
|
||||||
const Sprite *sprite = GetSprite(image, ST_NORMAL);
|
Dimension sprite_size = GetSpriteSize(image, &offset);
|
||||||
|
|
||||||
/* For the x offset we want the sprite to be centered, so undo the offset
|
|
||||||
* for sprite drawing and add half of the sprite's width. For the y offset
|
|
||||||
* we want the sprite to be aligned on the bottom, so again we undo the
|
|
||||||
* offset for sprite drawing and assume it is the bottom of the sprite. */
|
|
||||||
int sprite_center_x_offset = UnScaleByZoom(sprite->x_offs + sprite->width / 2, ZOOM_LVL_GUI);
|
|
||||||
int sprite_bottom_y_offset = UnScaleByZoom(sprite->height + sprite->y_offs, ZOOM_LVL_GUI);
|
|
||||||
|
|
||||||
/* Next we want to know where on the window to draw. Calculate the center
|
|
||||||
* and the bottom of the area to draw. */
|
|
||||||
const NWidgetBase *widget = this->GetWidget<NWidgetBase>(widget_index);
|
const NWidgetBase *widget = this->GetWidget<NWidgetBase>(widget_index);
|
||||||
int widget_center_x = widget->pos_x + widget->current_x / 2;
|
int x = widget->pos_x - offset.x +
|
||||||
int widget_bottom_y = widget->pos_y + widget->current_y - 2;
|
(widget->current_x - sprite_size.width + offset.x) / 2; // centered
|
||||||
|
int y = widget->pos_y - sig_sprite_bottom_offset + WD_IMGBTN_TOP +
|
||||||
|
(widget->current_y - WD_IMGBTN_TOP - WD_IMGBTN_BOTTOM + sig_sprite_size.height) / 2; // aligned to bottom
|
||||||
|
|
||||||
/* Finally we draw the signal. */
|
|
||||||
DrawSprite(image, PAL_NONE,
|
DrawSprite(image, PAL_NONE,
|
||||||
widget_center_x - sprite_center_x_offset + this->IsWidgetLowered(widget_index),
|
x + this->IsWidgetLowered(widget_index),
|
||||||
widget_bottom_y - sprite_bottom_y_offset + this->IsWidgetLowered(widget_index));
|
y + this->IsWidgetLowered(widget_index));
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -1502,11 +1494,16 @@ public:
|
||||||
/* Calculate maximum signal sprite size. */
|
/* Calculate maximum signal sprite size. */
|
||||||
this->sig_sprite_size.width = 0;
|
this->sig_sprite_size.width = 0;
|
||||||
this->sig_sprite_size.height = 0;
|
this->sig_sprite_size.height = 0;
|
||||||
|
this->sig_sprite_bottom_offset = 0;
|
||||||
const RailtypeInfo *rti = GetRailTypeInfo(_cur_railtype);
|
const RailtypeInfo *rti = GetRailTypeInfo(_cur_railtype);
|
||||||
for (uint type = SIGTYPE_NORMAL; type < SIGTYPE_END; type++) {
|
for (uint type = SIGTYPE_NORMAL; type < SIGTYPE_END; type++) {
|
||||||
for (uint variant = SIG_ELECTRIC; variant <= SIG_SEMAPHORE; variant++) {
|
for (uint variant = SIG_ELECTRIC; variant <= SIG_SEMAPHORE; variant++) {
|
||||||
for (uint lowered = 0; lowered < 2; lowered++) {
|
for (uint lowered = 0; lowered < 2; lowered++) {
|
||||||
this->sig_sprite_size = maxdim(this->sig_sprite_size, GetSpriteSize(rti->gui_sprites.signals[type][variant][lowered]));
|
Point offset;
|
||||||
|
Dimension sprite_size = GetSpriteSize(rti->gui_sprites.signals[type][variant][lowered], &offset);
|
||||||
|
this->sig_sprite_bottom_offset = max<int>(this->sig_sprite_bottom_offset, sprite_size.height);
|
||||||
|
this->sig_sprite_size.width = max<int>(this->sig_sprite_size.width, sprite_size.width - offset.x);
|
||||||
|
this->sig_sprite_size.height = max<int>(this->sig_sprite_size.height, sprite_size.height - offset.y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue