1
0
mirror of https://github.com/OpenTTD/OpenTTD.git synced 2025-08-22 14:09:10 +00:00

Compare commits

...

4 Commits

Author SHA1 Message Date
58c252b81a Cleanup: Remove unnecessary pressed button offset code. 2023-12-05 21:12:35 +00:00
884b9e6690 Change: Revert pressed-button content shifting introduced in r2161.
This restores original behaviour, and prevents all image buttons being slightly too large.
2023-12-05 21:12:35 +00:00
translators
a92d0da8b4 Update: Translations from eints
finnish: 5 changes by hpiirai
polish: 5 changes by pAter-exe
2023-12-05 18:38:33 +00:00
Loïc Guilloux
e86eb25447 Change: [CMake] Use explicit list for regression (#11541) 2023-12-05 15:37:53 +01:00
20 changed files with 106 additions and 101 deletions

View File

@@ -454,8 +454,9 @@ if(CMAKE_SIZEOF_VOID_P EQUAL 8)
add_definitions(-DPOINTER_IS_64BIT)
endif()
include(CreateRegression)
create_regression()
enable_testing()
add_subdirectory(regression)
if(APPLE OR WIN32)
find_package(Pandoc)

View File

@@ -3,20 +3,15 @@
# 'ctest'. The first is prefered, as it is more verbose, and takes care of
# dependencies correctly.
#
# create_regression()
# create_regression(file1 ...)
#
macro(create_regression)
# Find all the files in the regression folder; they need to be copied to the
# build folder before we can run the regression
file(GLOB_RECURSE REGRESSION_SOURCE_FILES ${CMAKE_SOURCE_DIR}/regression/*)
set(REGRESSION_SOURCE_FILES ${ARGN})
foreach(REGRESSION_SOURCE_FILE IN LISTS REGRESSION_SOURCE_FILES)
string(REPLACE "${CMAKE_SOURCE_DIR}/regression/" "" REGRESSION_SOURCE_FILE_NAME "${REGRESSION_SOURCE_FILE}")
string(CONCAT REGRESSION_BINARY_FILE "${CMAKE_BINARY_DIR}/ai/" "${REGRESSION_SOURCE_FILE_NAME}")
if("${REGRESSION_SOURCE_FILE_NAME}" STREQUAL "regression.cfg")
continue()
endif()
add_custom_command(OUTPUT ${REGRESSION_BINARY_FILE}
COMMAND ${CMAKE_COMMAND} -E copy
${REGRESSION_SOURCE_FILE}
@@ -28,59 +23,36 @@ macro(create_regression)
list(APPEND REGRESSION_BINARY_FILES ${REGRESSION_BINARY_FILE})
endforeach()
# Copy the regression configuration in a special folder, so all autogenerated
# folders end up in the same place after running regression.
add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/regression/regression.cfg
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_SOURCE_DIR}/regression/regression.cfg
${CMAKE_BINARY_DIR}/regression/regression.cfg
MAIN_DEPENDENCY ${CMAKE_SOURCE_DIR}/regression/regression.cfg
COMMENT "Copying ${REGRESSION_SOURCE_FILE_NAME} regression file"
)
list(APPEND REGRESSION_BINARY_FILES ${CMAKE_BINARY_DIR}/regression/regression.cfg)
get_filename_component(REGRESSION_TEST_NAME "${CMAKE_CURRENT_SOURCE_DIR}" NAME)
# Create a new target which copies all regression files
add_custom_target(regression_files
ALL # this is needed because 'make test' doesn't resolve dependencies, and otherwise this is never executed
# Create a new target which copies regression files
add_custom_target(regression_${REGRESSION_TEST_NAME}_files
DEPENDS
${REGRESSION_BINARY_FILES}
)
enable_testing()
add_dependencies(regression_files regression_${REGRESSION_TEST_NAME}_files)
# Find all the tests we have, and create a target for them
file(GLOB REGRESSION_TESTS ${CMAKE_SOURCE_DIR}/regression/*)
foreach(REGRESSION_TEST IN LISTS REGRESSION_TESTS)
get_filename_component(REGRESSION_TEST_NAME "${REGRESSION_TEST}" NAME)
add_custom_target(regression_${REGRESSION_TEST_NAME}
COMMAND ${CMAKE_COMMAND}
-DOPENTTD_EXECUTABLE=$<TARGET_FILE:openttd>
-DEDITBIN_EXECUTABLE=${EDITBIN_EXECUTABLE}
-DREGRESSION_TEST=${REGRESSION_TEST_NAME}
-P "${CMAKE_SOURCE_DIR}/cmake/scripts/Regression.cmake"
DEPENDS openttd regression_${REGRESSION_TEST_NAME}_files
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
COMMENT "Running regression test ${REGRESSION_TEST_NAME}"
)
if("${REGRESSION_TEST_NAME}" STREQUAL "regression.cfg")
continue()
endif()
# Also make sure that 'make test' runs the regression
add_test(NAME regression_${REGRESSION_TEST_NAME}
COMMAND ${CMAKE_COMMAND}
-DOPENTTD_EXECUTABLE=$<TARGET_FILE:openttd>
-DEDITBIN_EXECUTABLE=${EDITBIN_EXECUTABLE}
-DREGRESSION_TEST=${REGRESSION_TEST_NAME}
-P "${CMAKE_SOURCE_DIR}/cmake/scripts/Regression.cmake"
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)
add_custom_target(regression_${REGRESSION_TEST_NAME}
COMMAND ${CMAKE_COMMAND}
-DOPENTTD_EXECUTABLE=$<TARGET_FILE:openttd>
-DEDITBIN_EXECUTABLE=${EDITBIN_EXECUTABLE}
-DREGRESSION_TEST=${REGRESSION_TEST_NAME}
-P "${CMAKE_SOURCE_DIR}/cmake/scripts/Regression.cmake"
DEPENDS openttd regression_files
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
COMMENT "Running regression test ${REGRESSION_TEST_NAME}"
)
# Also make sure that 'make test' runs the regression
add_test(NAME regression_${REGRESSION_TEST_NAME}
COMMAND ${CMAKE_COMMAND}
-DOPENTTD_EXECUTABLE=$<TARGET_FILE:openttd>
-DEDITBIN_EXECUTABLE=${EDITBIN_EXECUTABLE}
-DREGRESSION_TEST=${REGRESSION_TEST_NAME}
-P "${CMAKE_SOURCE_DIR}/cmake/scripts/Regression.cmake"
WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
list(APPEND REGRESSION_TARGETS regression_${REGRESSION_TEST_NAME})
endforeach()
# Create a new target which runs the regression
add_custom_target(regression
DEPENDS ${REGRESSION_TARGETS})
add_dependencies(regression regression_${REGRESSION_TEST_NAME})
endmacro()

24
regression/CMakeLists.txt Normal file
View File

@@ -0,0 +1,24 @@
# Copy the regression configuration in a special folder, so all autogenerated
# folders end up in the same place after running regression.
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/regression.cfg
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_CURRENT_SOURCE_DIR}/regression.cfg
${CMAKE_CURRENT_BINARY_DIR}/regression.cfg
MAIN_DEPENDENCY ${CMAKE_CURRENT_SOURCE_DIR}/regression.cfg
COMMENT "Copying regression.cfg regression file"
)
# Create a new target which copies all regression files
# Subdirectory targets will add themselves as dependencies
add_custom_target(regression_files
ALL # this is needed because 'make test' doesn't resolve dependencies, and otherwise this is never executed
DEPENDS
${CMAKE_BINARY_DIR}/regression/regression.cfg
)
# Create a new target which runs the regression
# Subdirectory targets will add themselves as dependencies
add_custom_target(regression)
add_subdirectory(regression)
add_subdirectory(stationlist)

View File

@@ -0,0 +1,8 @@
include(CreateRegression)
create_regression(
${CMAKE_CURRENT_SOURCE_DIR}/info.nut
${CMAKE_CURRENT_SOURCE_DIR}/main.nut
${CMAKE_CURRENT_SOURCE_DIR}/require.nut
${CMAKE_CURRENT_SOURCE_DIR}/result.txt
${CMAKE_CURRENT_SOURCE_DIR}/test.sav
)

View File

@@ -0,0 +1,7 @@
include(CreateRegression)
create_regression(
${CMAKE_CURRENT_SOURCE_DIR}/info.nut
${CMAKE_CURRENT_SOURCE_DIR}/main.nut
${CMAKE_CURRENT_SOURCE_DIR}/result.txt
${CMAKE_CURRENT_SOURCE_DIR}/test.sav
)

View File

@@ -234,7 +234,7 @@ public:
for (int i = this->vscroll->GetPosition(); this->vscroll->IsVisible(i) && i < (int)this->bridges.size(); i++) {
const BuildBridgeData &bridge_data = this->bridges.at(i);
const BridgeSpec *b = bridge_data.spec;
DrawSpriteIgnorePadding(b->sprite, b->pal, tr.WithWidth(this->icon_width, rtl), false, SA_HOR_CENTER | SA_BOTTOM);
DrawSpriteIgnorePadding(b->sprite, b->pal, tr.WithWidth(this->icon_width, rtl), SA_HOR_CENTER | SA_BOTTOM);
DrawStringMultiLine(tr.Indent(this->icon_width + WidgetDimensions::scaled.hsep_normal, rtl), GetBridgeSelectString(bridge_data));
tr = tr.Translate(0, this->resize.step_height);
}

View File

@@ -1080,7 +1080,7 @@ void DrawEngineList(VehicleType type, const Rect &r, const GUIEngineList &eng_li
}
if (has_variants) {
Rect fr = ir.Indent(indent, rtl).WithWidth(circle_width, rtl);
DrawSpriteIgnorePadding(is_folded ? SPR_CIRCLE_FOLDED : SPR_CIRCLE_UNFOLDED, PAL_NONE, {fr.left, y, fr.right, y + ir.Height() - 1}, false, SA_CENTER);
DrawSpriteIgnorePadding(is_folded ? SPR_CIRCLE_FOLDED : SPR_CIRCLE_UNFOLDED, PAL_NONE, {fr.left, y, fr.right, y + ir.Height() - 1}, SA_CENTER);
}
if (indent > 0) {
/* Draw tree lines */

View File

@@ -356,7 +356,7 @@ struct DepotWindow : Window {
DrawString(text, STR_DEPOT_NO_ENGINE);
} else {
Rect flag = r.WithWidth(this->flag_size.width, rtl).WithHeight(this->flag_size.height).Translate(0, diff_y);
DrawSpriteIgnorePadding((v->vehstatus & VS_STOPPED) ? SPR_FLAG_VEH_STOPPED : SPR_FLAG_VEH_RUNNING, PAL_NONE, flag, false, SA_CENTER);
DrawSpriteIgnorePadding((v->vehstatus & VS_STOPPED) ? SPR_FLAG_VEH_STOPPED : SPR_FLAG_VEH_RUNNING, PAL_NONE, flag, SA_CENTER);
SetDParam(0, v->unitnumber);
DrawString(text, STR_JUST_COMMA, (v->max_age - CalendarTime::DAYS_IN_LEAP_YEAR) >= v->age ? TC_BLACK : TC_RED);

View File

@@ -89,7 +89,7 @@ Dimension GetSpriteSize(SpriteID sprid, Point *offset = nullptr, ZoomLevel zoom
Dimension GetScaledSpriteSize(SpriteID sprid); /* widget.cpp */
void DrawSpriteViewport(SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub = nullptr);
void DrawSprite(SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub = nullptr, ZoomLevel zoom = ZOOM_LVL_GUI);
void DrawSpriteIgnorePadding(SpriteID img, PaletteID pal, const Rect &r, bool clicked, StringAlignment align); /* widget.cpp */
void DrawSpriteIgnorePadding(SpriteID img, PaletteID pal, const Rect &r, StringAlignment align); /* widget.cpp */
std::unique_ptr<uint32_t[]> DrawSpriteToRgbaBuffer(SpriteID spriteId, ZoomLevel zoom = ZOOM_LVL_GUI);
int DrawString(int left, int right, int top, std::string_view str, TextColour colour = TC_FROMSTRING, StringAlignment align = SA_LEFT, bool underline = false, FontSize fontsize = FS_NORMAL);

View File

@@ -961,7 +961,7 @@ struct PaymentRatesGraphWindow : BaseGraphWindow {
/* Redraw frame if lowered */
if (lowered) DrawFrameRect(line, COLOUR_BROWN, FR_LOWERED);
const Rect text = line.Shrink(WidgetDimensions::scaled.framerect).Translate(lowered ? WidgetDimensions::scaled.pressed : 0, lowered ? WidgetDimensions::scaled.pressed : 0);
const Rect text = line.Shrink(WidgetDimensions::scaled.framerect);
/* Cargo-colour box with outline */
const Rect cargo = text.WithWidth(this->legend_width, rtl);
@@ -1209,9 +1209,8 @@ struct PerformanceRatingDetailWindow : Window {
if (IsInsideMM(widget, WID_PRD_COMPANY_FIRST, WID_PRD_COMPANY_LAST + 1)) {
if (this->IsWidgetDisabled(widget)) return;
CompanyID cid = (CompanyID)(widget - WID_PRD_COMPANY_FIRST);
int offset = (cid == this->company) ? WidgetDimensions::scaled.pressed : 0;
Dimension sprite_size = GetSpriteSize(SPR_COMPANY_ICON);
DrawCompanyIcon(cid, CenterBounds(r.left, r.right, sprite_size.width) + offset, CenterBounds(r.top, r.bottom, sprite_size.height) + offset);
DrawCompanyIcon(cid, CenterBounds(r.left, r.right, sprite_size.width), CenterBounds(r.top, r.bottom, sprite_size.height));
return;
}

View File

@@ -2581,7 +2581,7 @@ STR_CONTENT_SEARCH_EXTERNAL_TOOLTIP :{BLACK}Etsi Ope
STR_CONTENT_SEARCH_EXTERNAL_DISCLAIMER_CAPTION :{WHITE}Olet poistumassa OpenTTD:stä!
STR_CONTENT_SEARCH_EXTERNAL_DISCLAIMER :{WHITE}Ulkopuolisilta verkkosivuilta ladattaessa käyttöehdot voivat vaihdella.{}Sinun on noudatettava ulkopuolisen sivuston ohjeita sisällön asentamiseksi OpenTTD:hen.{}Haluatko jatkaa?
STR_CONTENT_FILTER_TITLE :{BLACK}Suodata avainsanalla tai nimellä:
STR_CONTENT_OPEN_URL :{BLACK}Vieraile verkkosivulla
STR_CONTENT_OPEN_URL :{BLACK}Verkkosivu
STR_CONTENT_OPEN_URL_TOOLTIP :{BLACK}Vieraile sisällön verkkosivulla
STR_CONTENT_DOWNLOAD_CAPTION :{BLACK}Lataa
STR_CONTENT_DOWNLOAD_CAPTION_TOOLTIP :{BLACK}Aloita valitun sisällön lataaminen
@@ -4707,9 +4707,12 @@ STR_TEXTFILE_NAVBACK_TOOLTIP :{BLACK}Siirry t
STR_TEXTFILE_NAVFORWARD_TOOLTIP :{BLACK}Siirry eteenpäin selaushistoriassa
STR_TEXTFILE_WRAP_TEXT :{WHITE}Tekstin rivitys
STR_TEXTFILE_WRAP_TEXT_TOOLTIP :{BLACK}Rivitä teksti ikkunaan niin, että se näkyy kokonaan rullaamatta
STR_TEXTFILE_VIEW_README :{BLACK}Näytä readme-tiedosto
STR_TEXTFILE_VIEW_README :{BLACK}Readme-tiedosto
STR_TEXTFILE_VIEW_README_TOOLTIP :Katso tämän sisällön readme-tiedosto
STR_TEXTFILE_VIEW_CHANGELOG :{BLACK}Muutosloki
STR_TEXTFILE_VIEW_CHANGELOG_TOOLTIP :Katso tämän sisällön muutosloki
STR_TEXTFILE_VIEW_LICENCE :{BLACK}Lisenssi
STR_TEXTFILE_VIEW_LICENCE_TOOLTIP :Katso tämän sisällön lisenssi
###length 5
STR_TEXTFILE_README_CAPTION :{WHITE}{STRING}:n {STRING} readme-tiedosto
STR_TEXTFILE_CHANGELOG_CAPTION :{WHITE}{STRING}:n {STRING} muutosloki

View File

@@ -2961,7 +2961,7 @@ STR_CONTENT_SEARCH_EXTERNAL_TOOLTIP :{BLACK}Przeszuk
STR_CONTENT_SEARCH_EXTERNAL_DISCLAIMER_CAPTION :{WHITE}Opuszczasz OpenTTD!
STR_CONTENT_SEARCH_EXTERNAL_DISCLAIMER :{WHITE}Warunki pobierania dodatków z zewnętrznych stron internetowych są inne.{}Będziesz musiał(a) odnieść się do zewnętrznych stron w celu uzyskania wskazówek dotyczących instalacji dodatku w OpenTTD.{}Czy chcesz kontynuować?
STR_CONTENT_FILTER_TITLE :{BLACK}Filtr etykiety/nazwy:
STR_CONTENT_OPEN_URL :{BLACK}Wejdź na stronę
STR_CONTENT_OPEN_URL :{BLACK}Strona internetowa
STR_CONTENT_OPEN_URL_TOOLTIP :{BLACK}Wejdź na stronę, by pobrać tę zawartość
STR_CONTENT_DOWNLOAD_CAPTION :{BLACK}Pobierz
STR_CONTENT_DOWNLOAD_CAPTION_TOOLTIP :{BLACK}Rozpocznij pobieranie zaznaczonych danych
@@ -5093,9 +5093,12 @@ STR_TEXTFILE_NAVBACK_TOOLTIP :{BLACK}Cofnij s
STR_TEXTFILE_NAVFORWARD_TOOLTIP :{BLACK}Powrót do przodu w historii nawigacji
STR_TEXTFILE_WRAP_TEXT :{WHITE}Zawijaj tekst
STR_TEXTFILE_WRAP_TEXT_TOOLTIP :{BLACK}Zawiń tekst w oknie, aby zmieścił się bez konieczności przewijania
STR_TEXTFILE_VIEW_README :{BLACK}Odczytaj plik „readme”
STR_TEXTFILE_VIEW_README :{BLACK}Plik „readme”
STR_TEXTFILE_VIEW_README_TOOLTIP :Wyświetl plik „readme” dla tej zawartości
STR_TEXTFILE_VIEW_CHANGELOG :{BLACK}Lista zmian
STR_TEXTFILE_VIEW_CHANGELOG_TOOLTIP :Wyświetl listę zmian dla tej zawartości
STR_TEXTFILE_VIEW_LICENCE :{BLACK}Licencja
STR_TEXTFILE_VIEW_LICENCE_TOOLTIP :Wyświetl licencję dla tej zawartości
###length 5
STR_TEXTFILE_README_CAPTION :{WHITE}{STRING} {STRING} - plik „readme”
STR_TEXTFILE_CHANGELOG_CAPTION :{WHITE}{STRING} {STRING} - lista zmian

View File

@@ -614,7 +614,6 @@ void LinkGraphLegendWindow::UpdateWidgetSize(int widget, Dimension *size, [[mayb
void LinkGraphLegendWindow::DrawWidget(const Rect &r, int widget) const
{
Rect br = r.Shrink(WidgetDimensions::scaled.bevel);
if (this->IsWidgetLowered(widget)) br = br.Translate(WidgetDimensions::scaled.pressed, WidgetDimensions::scaled.pressed);
if (IsInsideMM(widget, WID_LGL_COMPANY_FIRST, WID_LGL_COMPANY_LAST + 1)) {
if (this->IsWidgetDisabled(widget)) return;
CompanyID cid = (CompanyID)(widget - WID_LGL_COMPANY_FIRST);

View File

@@ -790,7 +790,7 @@ void QueryString::DrawEditBox(const Window *w, int wid) const
Rect fr = r.Indent(clearbtn_width, !rtl);
DrawFrameRect(cr, wi->colour, wi->IsLowered() ? FR_LOWERED : FR_NONE);
DrawSpriteIgnorePadding(rtl ? SPR_IMG_DELETE_RIGHT : SPR_IMG_DELETE_LEFT, PAL_NONE, cr, wi->IsLowered(), SA_CENTER);
DrawSpriteIgnorePadding(rtl ? SPR_IMG_DELETE_RIGHT : SPR_IMG_DELETE_LEFT, PAL_NONE, cr, SA_CENTER);
if (this->text.bytes == 1) GfxFillRect(cr.Shrink(WidgetDimensions::scaled.bevel), _colour_gradient[wi->colour & 0xF][2], FILLRECT_CHECKER);
DrawFrameRect(fr, wi->colour, FR_LOWERED | FR_DARKENED);

View File

@@ -853,9 +853,8 @@ struct ScriptDebugWindow : public Window {
{
if (this->IsWidgetDisabled(widget)) return;
CompanyID cid = (CompanyID)(widget - start);
int offset = (cid == script_debug_company) ? WidgetDimensions::scaled.pressed : 0;
Dimension sprite_size = GetSpriteSize(SPR_COMPANY_ICON);
DrawCompanyIcon(cid, CenterBounds(r.left, r.right, sprite_size.width) + offset, CenterBounds(r.top, r.bottom, sprite_size.height) + offset);
DrawCompanyIcon(cid, CenterBounds(r.left, r.right, sprite_size.width), CenterBounds(r.top, r.bottom, sprite_size.height));
}
/**

View File

@@ -2667,8 +2667,8 @@ void DrawArrowButtons(int x, int y, Colours button_colour, byte state, bool clic
DrawFrameRect(lr, button_colour, (state == 1) ? FR_LOWERED : FR_NONE);
DrawFrameRect(rr, button_colour, (state == 2) ? FR_LOWERED : FR_NONE);
DrawSpriteIgnorePadding(SPR_ARROW_LEFT, PAL_NONE, lr, (state == 1), SA_CENTER);
DrawSpriteIgnorePadding(SPR_ARROW_RIGHT, PAL_NONE, rr, (state == 2), SA_CENTER);
DrawSpriteIgnorePadding(SPR_ARROW_LEFT, PAL_NONE, lr, SA_CENTER);
DrawSpriteIgnorePadding(SPR_ARROW_RIGHT, PAL_NONE, rr, SA_CENTER);
/* Grey out the buttons that aren't clickable */
bool rtl = _current_text_dir == TD_RTL;
@@ -2695,7 +2695,7 @@ void DrawDropDownButton(int x, int y, Colours button_colour, bool state, bool cl
Rect r = {x, y, x + SETTING_BUTTON_WIDTH - 1, y + SETTING_BUTTON_HEIGHT - 1};
DrawFrameRect(r, button_colour, state ? FR_LOWERED : FR_NONE);
DrawSpriteIgnorePadding(SPR_ARROW_DOWN, PAL_NONE, r, state, SA_CENTER);
DrawSpriteIgnorePadding(SPR_ARROW_DOWN, PAL_NONE, r, SA_CENTER);
if (!clickable) {
GfxFillRect(r.Shrink(WidgetDimensions::scaled.bevel), colour, FILLRECT_CHECKER);

View File

@@ -517,8 +517,6 @@ public:
if (widget >= WID_STL_CARGOSTART) {
Rect br = r.Shrink(WidgetDimensions::scaled.bevel);
const CargoSpec *cs = _sorted_cargo_specs[widget - WID_STL_CARGOSTART];
int cg_ofst = HasBit(this->filter.cargoes, cs->Index()) ? WidgetDimensions::scaled.pressed : 0;
br = br.Translate(cg_ofst, cg_ofst);
GfxFillRect(br, cs->rating_colour);
TextColour tc = GetContrastColour(cs->rating_colour);
DrawString(br.left, br.right, CenterBounds(br.top, br.bottom, GetCharacterHeight(FS_SMALL)), cs->abbrev, tc, SA_HOR_CENTER, false, FS_SMALL);

View File

@@ -3080,10 +3080,9 @@ public:
/* Draw the flag plus orders. */
bool rtl = (_current_text_dir == TD_RTL);
uint icon_width = std::max({GetScaledSpriteSize(SPR_WARNING_SIGN).width, GetScaledSpriteSize(SPR_FLAG_VEH_STOPPED).width, GetScaledSpriteSize(SPR_FLAG_VEH_RUNNING).width});
int lowered = this->IsWidgetLowered(widget) ? WidgetDimensions::scaled.pressed : 0;
Rect tr = r.Shrink(WidgetDimensions::scaled.framerect).Translate(lowered, lowered);
Rect tr = r.Shrink(WidgetDimensions::scaled.framerect);
SpriteID image = ((v->vehstatus & VS_STOPPED) != 0) ? SPR_FLAG_VEH_STOPPED : (HasBit(v->vehicle_flags, VF_PATHFINDER_LOST)) ? SPR_WARNING_SIGN : SPR_FLAG_VEH_RUNNING;
DrawSpriteIgnorePadding(image, PAL_NONE, tr.WithWidth(icon_width, rtl), false, SA_CENTER);
DrawSpriteIgnorePadding(image, PAL_NONE, tr.WithWidth(icon_width, rtl), SA_CENTER);
tr = tr.Indent(icon_width + WidgetDimensions::scaled.imgbtn.Horizontal(), rtl);
DrawString(tr.left, tr.right, CenterBounds(tr.top, tr.bottom, GetCharacterHeight(FS_NORMAL)), str, text_colour, SA_HOR_CENTER);
}

View File

@@ -29,9 +29,9 @@
enum WidgetDrawDistances {
/* WWT_IMGBTN(_2) */
WD_IMGBTN_LEFT = 1, ///< Left offset of the image in the button.
WD_IMGBTN_RIGHT = 2, ///< Right offset of the image in the button.
WD_IMGBTN_RIGHT = 1, ///< Right offset of the image in the button.
WD_IMGBTN_TOP = 1, ///< Top offset of image in the button.
WD_IMGBTN_BOTTOM = 2, ///< Bottom offset of image in the button.
WD_IMGBTN_BOTTOM = 1, ///< Bottom offset of image in the button.
/* WWT_INSET */
WD_INSET_LEFT = 2, ///< Left offset of string.
@@ -154,7 +154,6 @@ const WidgetDimensions WidgetDimensions::unscaled = {
{3, 3, 3, 3}, ///< picker
{10, 8, 10, 8}, ///< sparse window padding
{10, 8, 10, 1}, ///< resizable sparse window padding
1, ///< pressed
1, ///< vsep_picker
WD_PAR_VSEP_NORMAL, ///< vsep_normal
4, ///< vsep_sparse
@@ -227,7 +226,6 @@ void SetupWidgetDimensions()
WidgetDimensions::scaled.dropdowntext = ScaleGUITrad(WidgetDimensions::unscaled.dropdowntext);
WidgetDimensions::scaled.modalpopup = ScaleGUITrad(WidgetDimensions::unscaled.modalpopup);
WidgetDimensions::scaled.pressed = ScaleGUITrad(WidgetDimensions::unscaled.pressed);
WidgetDimensions::scaled.vsep_normal = ScaleGUITrad(WidgetDimensions::unscaled.vsep_normal);
WidgetDimensions::scaled.vsep_wide = ScaleGUITrad(WidgetDimensions::unscaled.vsep_wide);
WidgetDimensions::scaled.hsep_normal = ScaleGUITrad(WidgetDimensions::unscaled.hsep_normal);
@@ -453,7 +451,7 @@ void DrawFrameRect(int left, int top, int right, int bottom, Colours colour, Fra
}
}
void DrawSpriteIgnorePadding(SpriteID img, PaletteID pal, const Rect &r, bool clicked, StringAlignment align)
void DrawSpriteIgnorePadding(SpriteID img, PaletteID pal, const Rect &r, StringAlignment align)
{
Point offset;
Dimension d = GetSpriteSize(img, &offset);
@@ -461,8 +459,7 @@ void DrawSpriteIgnorePadding(SpriteID img, PaletteID pal, const Rect &r, bool cl
d.height -= offset.y;
Point p = GetAlignedPosition(r, d, align);
int o = clicked ? WidgetDimensions::scaled.pressed : 0;
DrawSprite(img, pal, p.x + o - offset.x, p.y + o - offset.y);
DrawSprite(img, pal, p.x - offset.x, p.y - offset.y);
}
/**
@@ -470,7 +467,7 @@ void DrawSpriteIgnorePadding(SpriteID img, PaletteID pal, const Rect &r, bool cl
* @param r Rectangle of the button.
* @param type Widget type (#WWT_IMGBTN or #WWT_IMGBTN_2).
* @param colour Colour of the button.
* @param clicked Button is lowered.
* @param clicked Button is clicked.
* @param img Sprite to draw.
* @param align Alignment of the sprite.
*/
@@ -480,14 +477,14 @@ static inline void DrawImageButtons(const Rect &r, WidgetType type, Colours colo
DrawFrameRect(r.left, r.top, r.right, r.bottom, colour, (clicked) ? FR_LOWERED : FR_NONE);
if ((type & WWT_MASK) == WWT_IMGBTN_2 && clicked) img++; // Show different image when clicked for #WWT_IMGBTN_2.
DrawSpriteIgnorePadding(img, PAL_NONE, r, clicked, align);
DrawSpriteIgnorePadding(img, PAL_NONE, r, align);
}
/**
* Draw the label-part of a widget.
* @param r Rectangle of the label background.
* @param type Widget type (#WWT_TEXTBTN, #WWT_TEXTBTN_2, or #WWT_LABEL).
* @param clicked Label is rendered lowered.
* @param clicked Label is clicked.
* @param colour Colour of the text.
* @param str Text to draw.
* @param align Alignment of the text.
@@ -499,8 +496,7 @@ static inline void DrawLabel(const Rect &r, WidgetType type, bool clicked, TextC
if ((type & WWT_MASK) == WWT_TEXTBTN_2 && clicked) str++;
Dimension d = GetStringBoundingBox(str, fs);
Point p = GetAlignedPosition(r, d, align);
int o = clicked ? WidgetDimensions::scaled.pressed : 0;
DrawString(r.left + o, r.right + o, p.y + o, str, colour, align, false, fs);
DrawString(r.left, r.right, p.y, str, colour, align, false, fs);
}
/**
@@ -783,7 +779,7 @@ static inline void DrawDebugBox(const Rect &r, Colours colour, bool clicked)
static inline void DrawResizeBox(const Rect &r, Colours colour, bool at_left, bool clicked)
{
DrawFrameRect(r.left, r.top, r.right, r.bottom, colour, (clicked) ? FR_LOWERED : FR_NONE);
DrawSpriteIgnorePadding(at_left ? SPR_WINDOW_RESIZE_LEFT : SPR_WINDOW_RESIZE_RIGHT, PAL_NONE, r.Shrink(ScaleGUITrad(2)), clicked, at_left ? (SA_LEFT | SA_BOTTOM | SA_FORCE) : (SA_RIGHT | SA_BOTTOM | SA_FORCE));
DrawSpriteIgnorePadding(at_left ? SPR_WINDOW_RESIZE_LEFT : SPR_WINDOW_RESIZE_RIGHT, PAL_NONE, r.Shrink(ScaleGUITrad(2)), at_left ? (SA_LEFT | SA_BOTTOM | SA_FORCE) : (SA_RIGHT | SA_BOTTOM | SA_FORCE));
}
/**
@@ -835,8 +831,8 @@ void DrawCaption(const Rect &r, Colours colour, Owner owner, TextColour text_col
* Draw a button with a dropdown (#WWT_DROPDOWN and #NWID_BUTTON_DROPDOWN).
* @param r Rectangle containing the widget.
* @param colour Background colour of the widget.
* @param clicked_button The button-part is lowered.
* @param clicked_dropdown The drop-down part is lowered.
* @param clicked_button The button-part is clicked.
* @param clicked_dropdown The drop-down part is clicked.
* @param str Text of the button.
* @param align Alignment of the text within the dropdown.
*
@@ -850,15 +846,13 @@ static inline void DrawButtonDropdown(const Rect &r, Colours colour, bool clicke
DrawFrameRect(r.left, r.top, r.right - dd_width, r.bottom, colour, clicked_button ? FR_LOWERED : FR_NONE);
DrawImageButtons(r.WithWidth(dd_width, true), WWT_DROPDOWN, colour, clicked_dropdown, SPR_ARROW_DOWN, SA_CENTER);
if (str != STR_NULL) {
int o = clicked_button ? WidgetDimensions::scaled.pressed : 0;
DrawString(r.left + WidgetDimensions::scaled.dropdowntext.left + o, r.right - dd_width - WidgetDimensions::scaled.dropdowntext.right + o, CenterBounds(r.top, r.bottom, GetCharacterHeight(FS_NORMAL)) + o, str, TC_BLACK, align);
DrawString(r.left + WidgetDimensions::scaled.dropdowntext.left, r.right - dd_width - WidgetDimensions::scaled.dropdowntext.right, CenterBounds(r.top, r.bottom, GetCharacterHeight(FS_NORMAL)), str, TC_BLACK, align);
}
} else {
DrawFrameRect(r.left + dd_width, r.top, r.right, r.bottom, colour, clicked_button ? FR_LOWERED : FR_NONE);
DrawImageButtons(r.WithWidth(dd_width, false), WWT_DROPDOWN, colour, clicked_dropdown, SPR_ARROW_DOWN, SA_CENTER);
if (str != STR_NULL) {
int o = clicked_button ? WidgetDimensions::scaled.pressed : 0;
DrawString(r.left + dd_width + WidgetDimensions::scaled.dropdowntext.left + o, r.right - WidgetDimensions::scaled.dropdowntext.right + o, CenterBounds(r.top, r.bottom, GetCharacterHeight(FS_NORMAL)) + o, str, TC_BLACK, align);
DrawString(r.left + dd_width + WidgetDimensions::scaled.dropdowntext.left, r.right - WidgetDimensions::scaled.dropdowntext.right, CenterBounds(r.top, r.bottom, GetCharacterHeight(FS_NORMAL)), str, TC_BLACK, align);
}
}
}
@@ -908,7 +902,7 @@ void Window::DrawSortButtonState(int widget, SortButtonState state) const
/* Sort button uses the same sprites as vertical scrollbar */
Dimension dim = NWidgetScrollbar::GetVerticalDimension();
DrawSpriteIgnorePadding(state == SBS_DOWN ? SPR_ARROW_DOWN : SPR_ARROW_UP, PAL_NONE, r.WithWidth(dim.width, _current_text_dir == TD_LTR), this->IsWidgetLowered(widget), SA_CENTER);
DrawSpriteIgnorePadding(state == SBS_DOWN ? SPR_ARROW_DOWN : SPR_ARROW_UP, PAL_NONE, r.WithWidth(dim.width, _current_text_dir == TD_LTR), SA_CENTER);
}
/**

View File

@@ -54,7 +54,6 @@ struct WidgetDimensions {
RectPadding sparse; ///< Padding used for 'sparse' widget window, usually containing multiple frames.
RectPadding sparse_resize; ///< Padding used for a resizeable 'sparse' widget window, usually containing multiple frames.
int pressed; ///< Offset for contents of depressed widget.
int vsep_picker; ///< Vertical spacing of picker-window widgets.
int vsep_normal; ///< Normal vertical spacing.
int vsep_sparse; ///< Normal vertical spacing for 'sparse' widget window.