1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-26 03:52:01 +02:00

vcmi: allow set font size on component

Now it is possible to set arbitrary font size
for CComponent. So, let's use it
This commit is contained in:
Konstantin 2023-03-10 01:26:44 +03:00
parent 716dd9a43b
commit 8a05f5bed7
2 changed files with 14 additions and 11 deletions

View File

@ -33,22 +33,22 @@
#include "../../lib/NetPacksBase.h" #include "../../lib/NetPacksBase.h"
#include "../../lib/CArtHandler.h" #include "../../lib/CArtHandler.h"
CComponent::CComponent(Etype Type, int Subtype, int Val, ESize imageSize) CComponent::CComponent(Etype Type, int Subtype, int Val, ESize imageSize, EFonts font):
: perDay(false) perDay(false)
{ {
init(Type, Subtype, Val, imageSize); init(Type, Subtype, Val, imageSize, font);
} }
CComponent::CComponent(const Component & c, ESize imageSize) CComponent::CComponent(const Component & c, ESize imageSize, EFonts font)
: perDay(false) : perDay(false)
{ {
if(c.id == Component::RESOURCE && c.when==-1) if(c.id == Component::RESOURCE && c.when==-1)
perDay = true; perDay = true;
init((Etype)c.id, c.subtype, c.val, imageSize); init((Etype)c.id, c.subtype, c.val, imageSize, font);
} }
void CComponent::init(Etype Type, int Subtype, int Val, ESize imageSize) void CComponent::init(Etype Type, int Subtype, int Val, ESize imageSize, EFonts fnt)
{ {
OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE); OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
@ -58,6 +58,7 @@ void CComponent::init(Etype Type, int Subtype, int Val, ESize imageSize)
subtype = Subtype; subtype = Subtype;
val = Val; val = Val;
size = imageSize; size = imageSize;
font = fnt;
assert(compType < typeInvalid); assert(compType < typeInvalid);
assert(size < sizeInvalid); assert(size < sizeInvalid);
@ -67,13 +68,14 @@ void CComponent::init(Etype Type, int Subtype, int Val, ESize imageSize)
pos.w = image->pos.w; pos.w = image->pos.w;
pos.h = image->pos.h; pos.h = image->pos.h;
EFonts font = FONT_SMALL;
if (imageSize < small) if (imageSize < small)
font = FONT_TINY; //other sizes? font = FONT_TINY; //for tiny images - tiny font
pos.h += 4; //distance between text and image pos.h += 4; //distance between text and image
auto max = 80; auto max = 80;
if (size < large)
max = 60;
if (size < medium) if (size < medium)
max = 40; max = 40;
if (size < small) if (size < small)

View File

@ -47,13 +47,14 @@ private:
void setSurface(std::string defName, int imgPos); void setSurface(std::string defName, int imgPos);
std::string getSubtitleInternal(); std::string getSubtitleInternal();
void init(Etype Type, int Subtype, int Val, ESize imageSize); void init(Etype Type, int Subtype, int Val, ESize imageSize, EFonts font = FONT_SMALL);
public: public:
std::shared_ptr<CAnimImage> image; std::shared_ptr<CAnimImage> image;
Etype compType; //component type Etype compType; //component type
ESize size; //component size. ESize size; //component size.
EFonts font; //Font size of label
int subtype; //type-dependant subtype. See getSomething methods for details int subtype; //type-dependant subtype. See getSomething methods for details
int val; // value \ strength \ amount of component. See getSomething methods for details int val; // value \ strength \ amount of component. See getSomething methods for details
bool perDay; // add "per day" text to subtitle bool perDay; // add "per day" text to subtitle
@ -61,8 +62,8 @@ public:
std::string getDescription(); std::string getDescription();
std::string getSubtitle(); std::string getSubtitle();
CComponent(Etype Type, int Subtype, int Val = 0, ESize imageSize=large); CComponent(Etype Type, int Subtype, int Val = 0, ESize imageSize=large, EFonts font = FONT_SMALL);
CComponent(const Component &c, ESize imageSize=large); CComponent(const Component &c, ESize imageSize=large, EFonts font = FONT_SMALL);
void clickRight(tribool down, bool previousState) override; //call-in void clickRight(tribool down, bool previousState) override; //call-in
}; };