diff --git a/src/fheroes2/dialog/dialog_selectscenario.cpp b/src/fheroes2/dialog/dialog_selectscenario.cpp index 506d255877..36e95a3b2f 100644 --- a/src/fheroes2/dialog/dialog_selectscenario.cpp +++ b/src/fheroes2/dialog/dialog_selectscenario.cpp @@ -286,7 +286,8 @@ void ScenarioListBox::_renderSelectedScenarioInfo( fheroes2::Display & display, _renderMapIcon( info.width, display, dst.x + SELECTED_SCENARIO_MAP_SIZE_OFFSET_X, dst.y + SELECTED_SCENARIO_GENERAL_OFFSET_Y ); fheroes2::Blit( _getMapTypeIcon( info.version ), display, dst.x + SELECTED_SCENARIO_MAP_TYPE_OFFSET_X, dst.y + SELECTED_SCENARIO_GENERAL_OFFSET_Y ); - const fheroes2::Text mapNameText{ info.name, fheroes2::FontType::normalWhite(), info.getSupportedLanguage() }; + fheroes2::Text mapNameText{ info.name, fheroes2::FontType::normalWhite(), info.getSupportedLanguage() }; + mapNameText.fitToOneRow( SCENARIO_LIST_MAP_NAME_WIDTH ); mapNameText.draw( GetCenteredTextXCoordinate( dst.x + SELECTED_SCENARIO_MAP_NAME_OFFSET_X, SELECTED_SCENARIO_MAP_NAME_WIDTH, mapNameText.width() ), dst.y + SELECTED_SCENARIO_GENERAL_OFFSET_Y + 2, display ); @@ -310,9 +311,10 @@ void ScenarioListBox::_renderSelectedScenarioInfo( fheroes2::Display & display, void ScenarioListBox::_renderMapName( const Maps::FileInfo & info, bool selected, const int32_t & baseYOffset, fheroes2::Display & display ) const { - const fheroes2::Text mapName{ info.name, - { fheroes2::FontSize::NORMAL, ( selected ? fheroes2::FontColor::YELLOW : fheroes2::FontColor::WHITE ) }, - info.getSupportedLanguage() }; + fheroes2::Text mapName{ info.name, + { fheroes2::FontSize::NORMAL, ( selected ? fheroes2::FontColor::YELLOW : fheroes2::FontColor::WHITE ) }, + info.getSupportedLanguage() }; + mapName.fitToOneRow( SCENARIO_LIST_MAP_NAME_WIDTH ); const int32_t xCoordinate = GetCenteredTextXCoordinate( _offsetX + SCENARIO_LIST_MAP_NAME_OFFSET_X, SCENARIO_LIST_MAP_NAME_WIDTH, mapName.width() ); const int32_t yCoordinate = baseYOffset + MAP_LIST_ROW_SPACING_Y - 1; mapName.draw( xCoordinate, yCoordinate, display ); diff --git a/src/fheroes2/game/game_scenarioinfo.cpp b/src/fheroes2/game/game_scenarioinfo.cpp index cf8750ca5b..32a41cda2e 100644 --- a/src/fheroes2/game/game_scenarioinfo.cpp +++ b/src/fheroes2/game/game_scenarioinfo.cpp @@ -110,8 +110,9 @@ namespace void RedrawMapTitle( const fheroes2::Rect & roi ) { const auto & info = Settings::Get().getCurrentMapInfo(); - const fheroes2::Text text{ info.name, fheroes2::FontType::normalWhite(), info.getSupportedLanguage() }; - text.draw( roi.x, roi.y + 8, roi.width, fheroes2::Display::instance() ); + fheroes2::Text text{ info.name, fheroes2::FontType::normalWhite(), info.getSupportedLanguage() }; + text.fitToOneRow( roi.width ); + text.draw( roi.x, roi.y + 3, roi.width, fheroes2::Display::instance() ); } void RedrawDifficultyInfo( const fheroes2::Point & dst ) @@ -245,8 +246,15 @@ namespace fheroes2::addGradientShadow( icon, display, { coordDifficulty[i].x, coordDifficulty[i].y }, { -5, 5 } ); } + // We calculate the allowed text width according to the select button's width while ensuring symmetric placement of the map title. + const int32_t boxBorder = 6; + const int32_t halfBoxTextAreaWidth = ( scenarioBoxRoi.width - ( 2 * boxBorder ) ) / 2; + const int32_t rightSideAvailableTextWidth + = halfBoxTextAreaWidth > buttonSelectWidth ? halfBoxTextAreaWidth - buttonSelectWidth : buttonSelectWidth - halfBoxTextAreaWidth; + // Set up restorers. - fheroes2::ImageRestorer mapTitleArea( display, scenarioBoxRoi.x + 6, scenarioBoxRoi.y + 5, 279, scenarioBoxRoi.height ); + fheroes2::ImageRestorer mapTitleArea( display, scenarioBoxRoi.x + boxBorder + buttonSelectWidth, scenarioBoxRoi.y + 5, 2 * rightSideAvailableTextWidth, + scenarioBoxRoi.height ); fheroes2::ImageRestorer opponentsArea( display, roi.x, pointOpponentInfo.y, roi.width, 65 ); fheroes2::ImageRestorer classArea( display, roi.x, pointClassInfo.y, roi.width, 69 ); fheroes2::ImageRestorer handicapArea( display, roi.x, pointClassInfo.y + 69, roi.width, 31 ); @@ -254,7 +262,7 @@ namespace roi.width - buttonOk.area().width - buttonCancel.area().width - 20 * 2, buttonOk.area().height ); // Map name - RedrawMapTitle( scenarioBoxRoi ); + RedrawMapTitle( mapTitleArea.rect() ); playersInfo.RedrawInfo( false ); @@ -318,7 +326,7 @@ namespace conf.setCurrentMapInfo( *fi ); mapTitleArea.restore(); - RedrawMapTitle( scenarioBoxRoi ); + RedrawMapTitle( mapTitleArea.rect() ); Game::LoadPlayers( fi->filename, players ); opponentsArea.restore();