Skip to content

Commit

Permalink
Impose checkbox text width limit (#9517)
Browse files Browse the repository at this point in the history
  • Loading branch information
ihhub authored Feb 1, 2025
1 parent 374c996 commit bc2853c
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 27 deletions.
23 changes: 12 additions & 11 deletions src/fheroes2/editor/editor_castle_details_window.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/***************************************************************************
* fheroes2: https://github.com/ihhub/fheroes2 *
* Copyright (C) 2024 *
* Copyright (C) 2024 - 2025 *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
Expand Down Expand Up @@ -313,18 +313,18 @@ namespace Editor

// Use the left part of town construction dialog.
const int32_t rightPartOffsetX = 438;
const int32_t rightPartSizeX = dialogRoi.width - rightPartOffsetX;
const int32_t rightPartWidth = dialogRoi.width - rightPartOffsetX;
fheroes2::Blit( constructionBackground, 0, 0, display, dialogRoi.x, dialogRoi.y, rightPartOffsetX, backgroundHeight );
// Use the right part of standard background dialog.
fheroes2::Copy( fheroes2::AGG::GetICN( isEvilInterface ? ICN::STONEBAK_EVIL : ICN::STONEBAK, 0 ), rightPartOffsetX, 0, display, dialogRoi.x + rightPartOffsetX,
dialogRoi.y, rightPartSizeX, backgroundHeight );
dialogRoi.y, rightPartWidth, backgroundHeight );
// Add horizontal separators.
fheroes2::Copy( constructionBackground, rightPartOffsetX, 251, display, dialogRoi.x + rightPartOffsetX, dialogRoi.y + 226, rightPartSizeX, 4 );
fheroes2::Copy( constructionBackground, rightPartOffsetX, 251, display, dialogRoi.x + rightPartOffsetX, dialogRoi.y + 306, rightPartSizeX, 4 );
fheroes2::Copy( constructionBackground, rightPartOffsetX, 251, display, dialogRoi.x + rightPartOffsetX, dialogRoi.y + 226, rightPartWidth, 4 );
fheroes2::Copy( constructionBackground, rightPartOffsetX, 251, display, dialogRoi.x + rightPartOffsetX, dialogRoi.y + 306, rightPartWidth, 4 );

// Castle name background.
const fheroes2::Sprite & statusBarSprite = fheroes2::AGG::GetICN( ICN::CASLBAR, 0 );
const fheroes2::Rect nameArea( dialogRoi.x + rightPartOffsetX, dialogRoi.y + 1, rightPartSizeX, statusBarSprite.height() - 2 );
const fheroes2::Rect nameArea( dialogRoi.x + rightPartOffsetX, dialogRoi.y + 1, rightPartWidth, statusBarSprite.height() - 2 );
fheroes2::Copy( statusBarSprite, 17, 0, display, nameArea.x, dialogRoi.y, nameArea.width, statusBarSprite.height() );

const bool isTown = std::find( castleMetadata.builtBuildings.begin(), castleMetadata.builtBuildings.end(), BUILD_CASTLE ) == castleMetadata.builtBuildings.end();
Expand All @@ -347,7 +347,7 @@ namespace Editor
fheroes2::MovableSprite allowCastleSign;
fheroes2::Rect allowCastleArea;
if ( isTown ) {
allowCastleArea = drawCheckboxWithText( allowCastleSign, _( "Allow Castle build" ), display, dstPt.x, dstPt.y, isEvilInterface );
allowCastleArea = drawCheckboxWithText( allowCastleSign, _( "Allow Castle build" ), display, dstPt.x, dstPt.y, isEvilInterface, rightPartWidth - 10 );
if ( std::find( castleMetadata.bannedBuildings.begin(), castleMetadata.bannedBuildings.end(), BUILD_CASTLE ) == castleMetadata.bannedBuildings.end() ) {
allowCastleSign.show();
}
Expand All @@ -359,12 +359,13 @@ namespace Editor
// Default buildings checkbox indicator.
dstPt.y += 30;
fheroes2::MovableSprite defaultBuildingsSign;
const fheroes2::Rect defaultBuildingsArea = drawCheckboxWithText( defaultBuildingsSign, _( "Default Buildings" ), display, dstPt.x, dstPt.y, isEvilInterface );
const fheroes2::Rect defaultBuildingsArea
= drawCheckboxWithText( defaultBuildingsSign, _( "Default Buildings" ), display, dstPt.x, dstPt.y, isEvilInterface, rightPartWidth - 10 );
castleMetadata.customBuildings ? defaultBuildingsSign.hide() : defaultBuildingsSign.show();

// Build restrict mode button.
fheroes2::Button buttonRestrictBuilding( 0, 0, isEvilInterface ? ICN::BUTTON_RESTRICT_EVIL : ICN::BUTTON_RESTRICT_GOOD, 0, 1 );
buttonRestrictBuilding.setPosition( dialogRoi.x + rightPartOffsetX + ( rightPartSizeX - buttonRestrictBuilding.area().width ) / 2, dialogRoi.y + 195 );
buttonRestrictBuilding.setPosition( dialogRoi.x + rightPartOffsetX + ( rightPartWidth - buttonRestrictBuilding.area().width ) / 2, dialogRoi.y + 195 );
fheroes2::addGradientShadow( fheroes2::AGG::GetICN( ICN::BUTTON_RESTRICT_GOOD, 0 ), display, buttonRestrictBuilding.area().getPosition(), { -5, 5 } );
buttonRestrictBuilding.draw();

Expand All @@ -375,7 +376,7 @@ namespace Editor
fheroes2::MovableSprite defaultArmySign;
fheroes2::Rect defaultArmyArea;
if ( isNeutral ) {
defaultArmyArea = drawCheckboxWithText( defaultArmySign, _( "Default Army" ), display, dstPt.x, dstPt.y, isEvilInterface );
defaultArmyArea = drawCheckboxWithText( defaultArmySign, _( "Default Army" ), display, dstPt.x, dstPt.y, isEvilInterface, rightPartWidth - 10 );

if ( Maps::isDefaultCastleDefenderArmy( castleMetadata ) ) {
defaultArmySign.show();
Expand All @@ -388,7 +389,7 @@ namespace Editor
defaultArmySign.hide();

const fheroes2::Text armyText( isTown ? _( "Town Army" ) : _( "Castle Army" ), fheroes2::FontType::normalWhite() );
armyText.drawInRoi( dialogRoi.x + rightPartOffsetX + ( rightPartSizeX - armyText.width() ) / 2, dstPt.y + 4, display, dialogRoi );
armyText.drawInRoi( dialogRoi.x + rightPartOffsetX + ( rightPartWidth - armyText.width() ) / 2, dstPt.y + 4, display, dialogRoi );
}

Army castleArmy;
Expand Down
6 changes: 3 additions & 3 deletions src/fheroes2/editor/editor_event_details_window.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/***************************************************************************
* fheroes2: https://github.com/ihhub/fheroes2 *
* Copyright (C) 2024 *
* Copyright (C) 2024 - 2025 *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
Expand Down Expand Up @@ -106,8 +106,8 @@ namespace Editor
const fheroes2::Point recurringEventPos{ messageRoi.x + elementOffset, messageRoi.y + messageRoi.height + 2 * elementOffset };

fheroes2::MovableSprite recurringEventCheckbox;
const fheroes2::Rect recurringEventArea
= drawCheckboxWithText( recurringEventCheckbox, _( "Cancel event after first visit" ), display, recurringEventPos.x, recurringEventPos.y, isEvilInterface );
const fheroes2::Rect recurringEventArea = drawCheckboxWithText( recurringEventCheckbox, _( "Cancel event after first visit" ), display, recurringEventPos.x,
recurringEventPos.y, isEvilInterface, dialogRoi.width - 2 * elementOffset );
if ( eventMetadata.isRecurringEvent ) {
recurringEventCheckbox.hide();
}
Expand Down
12 changes: 6 additions & 6 deletions src/fheroes2/editor/editor_map_specs_window.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/***************************************************************************
* fheroes2: https://github.com/ihhub/fheroes2 *
* Copyright (C) 2024 *
* Copyright (C) 2024 - 2025 *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
Expand Down Expand Up @@ -1006,7 +1006,7 @@ namespace
}

_allowNormalVictoryRoi = Editor::drawCheckboxWithText( _allowNormalVictory, _( "Allow standard victory conditions" ), output, roi.x + 5,
roi.y + _selectConditionRoi.height + 35, _isEvilInterface );
roi.y + _selectConditionRoi.height + 35, _isEvilInterface, roi.width - 5 );

if ( _isNormalVictoryAllowed ) {
_allowNormalVictory.show();
Expand All @@ -1019,7 +1019,7 @@ namespace
}

_allowVictoryConditionForAIRoi = Editor::drawCheckboxWithText( _allowVictoryConditionForAI, _( "Allow this condition also for AI" ), output,
roi.x + 5, roi.y + _selectConditionRoi.height + 10, _isEvilInterface );
roi.x + 5, roi.y + _selectConditionRoi.height + 10, _isEvilInterface, roi.width - 5 );

if ( _isVictoryConditionApplicableForAI ) {
_allowVictoryConditionForAI.show();
Expand Down Expand Up @@ -1097,7 +1097,7 @@ namespace
}

_allowNormalVictoryRoi = Editor::drawCheckboxWithText( _allowNormalVictory, _( "Allow standard victory conditions" ), output, roi.x + 5,
roi.y + _selectConditionRoi.height + 10, _isEvilInterface );
roi.y + _selectConditionRoi.height + 10, _isEvilInterface, roi.width - 5 );
}

const fheroes2::Sprite & artifactImage = fheroes2::AGG::GetICN( ICN::ARTIFACT, Artifact( static_cast<int>( _victoryArtifactId ) ).IndexSprite64() );
Expand Down Expand Up @@ -1169,9 +1169,9 @@ namespace
}

_allowVictoryConditionForAIRoi = Editor::drawCheckboxWithText( _allowVictoryConditionForAI, _( "Allow this condition also for AI" ), output,
roi.x + 5, roi.y + valueSectionUiSize.height + 10, _isEvilInterface );
roi.x + 5, roi.y + valueSectionUiSize.height + 10, _isEvilInterface, roi.width - 5 );
_allowNormalVictoryRoi = Editor::drawCheckboxWithText( _allowNormalVictory, _( "Allow standard victory conditions" ), output, roi.x + 5,
roi.y + valueSectionUiSize.height + 35, _isEvilInterface );
roi.y + valueSectionUiSize.height + 35, _isEvilInterface, roi.width - 5 );
}

_goldAccumulationValue.draw( output );
Expand Down
17 changes: 12 additions & 5 deletions src/fheroes2/editor/editor_ui_helper.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/***************************************************************************
* fheroes2: https://github.com/ihhub/fheroes2 *
* Copyright (C) 2024 *
* Copyright (C) 2024 - 2025 *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
Expand All @@ -20,6 +20,7 @@

#include "editor_ui_helper.h"

#include <cassert>
#include <utility>

#include "agg_image.h"
Expand Down Expand Up @@ -77,19 +78,25 @@ namespace Editor
}

fheroes2::Rect drawCheckboxWithText( fheroes2::MovableSprite & checkSprite, std::string str, fheroes2::Image & output, const int32_t posX, const int32_t posY,
const bool isEvil )
const bool isEvil, const int32_t maxWidth )
{
assert( maxWidth > 0 );

const fheroes2::Sprite & checkboxBackground = fheroes2::AGG::GetICN( isEvil ? ICN::CELLWIN_EVIL : ICN::CELLWIN, 1 );
fheroes2::Copy( checkboxBackground, 0, 0, output, posX, posY, checkboxBackground.width(), checkboxBackground.height() );

fheroes2::addGradientShadow( checkboxBackground, output, { posX, posY }, { -4, 4 } );
const fheroes2::Text checkboxText( std::move( str ), fheroes2::FontType::normalWhite() );
checkboxText.draw( posX + 23, posY + 4, output );

const int32_t textOffsetX{ 23 };

fheroes2::Text checkboxText( std::move( str ), fheroes2::FontType::normalWhite() );
checkboxText.fitToOneRow( maxWidth - textOffsetX );
checkboxText.draw( posX + textOffsetX, posY + 4, output );

checkSprite = fheroes2::AGG::GetICN( ICN::CELLWIN, 2 );
checkSprite.setPosition( posX + 2, posY + 2 );

return { posX, posY, 23 + checkboxText.width(), checkboxBackground.height() };
return { posX, posY, textOffsetX + checkboxText.width(), checkboxBackground.height() };
}

void renderResources( const Funds & resources, const fheroes2::Rect & roi, fheroes2::Image & output, std::array<fheroes2::Rect, 7> & resourceRoi )
Expand Down
4 changes: 2 additions & 2 deletions src/fheroes2/editor/editor_ui_helper.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/***************************************************************************
* fheroes2: https://github.com/ihhub/fheroes2 *
* Copyright (C) 2024 *
* Copyright (C) 2024 - 2025 *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
Expand Down Expand Up @@ -70,7 +70,7 @@ namespace Editor
const int32_t boxOffsetY, fheroes2::Image & output );

fheroes2::Rect drawCheckboxWithText( fheroes2::MovableSprite & checkSprite, std::string str, fheroes2::Image & output, const int32_t posX, const int32_t posY,
const bool isEvil );
const bool isEvil, const int32_t maxWidth );

void renderResources( const Funds & resources, const fheroes2::Rect & roi, fheroes2::Image & output, std::array<fheroes2::Rect, 7> & resourceRoi );

Expand Down

0 comments on commit bc2853c

Please sign in to comment.