Browse Source

vcmi: allow set font size on component

Now it is possible to set arbitrary font size
for CComponent. So, let's use it
Konstantin 2 years ago
parent
commit
8a05f5bed7
2 changed files with 14 additions and 11 deletions
  1. 10 8
      client/widgets/CComponent.cpp
  2. 4 3
      client/widgets/CComponent.h

+ 10 - 8
client/widgets/CComponent.cpp

@@ -33,22 +33,22 @@
 #include "../../lib/NetPacksBase.h"
 #include "../../lib/CArtHandler.h"
 
-CComponent::CComponent(Etype Type, int Subtype, int Val, ESize imageSize)
-	: perDay(false)
+CComponent::CComponent(Etype Type, int Subtype, int Val, ESize imageSize, EFonts font):
+	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)
 {
 	if(c.id == Component::RESOURCE && c.when==-1)
 		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);
 
@@ -58,6 +58,7 @@ void CComponent::init(Etype Type, int Subtype, int Val, ESize imageSize)
 	subtype = Subtype;
 	val = Val;
 	size = imageSize;
+	font = fnt;
 
 	assert(compType < typeInvalid);
 	assert(size < sizeInvalid);
@@ -67,13 +68,14 @@ void CComponent::init(Etype Type, int Subtype, int Val, ESize imageSize)
 	pos.w = image->pos.w;
 	pos.h = image->pos.h;
 
-	EFonts font = FONT_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
 
 	auto max = 80;
+	if (size < large)
+		max = 60;
 	if (size < medium)
 		max = 40;
 	if (size < small)

+ 4 - 3
client/widgets/CComponent.h

@@ -47,13 +47,14 @@ private:
 	void setSurface(std::string defName, int imgPos);
 	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:
 	std::shared_ptr<CAnimImage> image;
 
 	Etype compType; //component type
 	ESize size; //component size.
+	EFonts font; //Font size of label
 	int subtype; //type-dependant subtype. 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
@@ -61,8 +62,8 @@ public:
 	std::string getDescription();
 	std::string getSubtitle();
 
-	CComponent(Etype Type, int Subtype, int Val = 0, ESize imageSize=large);
-	CComponent(const Component &c, 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, EFonts font = FONT_SMALL);
 
 	void clickRight(tribool down, bool previousState) override; //call-in
 };