2012-12-19 20:24:53 +03:00
|
|
|
/*
|
2023-02-01 16:42:03 +02:00
|
|
|
* CBitmapFont.h, part of VCMI engine
|
2012-12-19 20:24:53 +03:00
|
|
|
*
|
|
|
|
* Authors: listed in file AUTHORS in main folder
|
|
|
|
*
|
|
|
|
* License: GNU General Public License v2.0 or later
|
|
|
|
* Full text of license available in license.txt file, in main folder
|
|
|
|
*
|
|
|
|
*/
|
2017-07-13 10:26:03 +02:00
|
|
|
#pragma once
|
2012-12-19 20:24:53 +03:00
|
|
|
|
2023-02-01 20:42:06 +02:00
|
|
|
#include "../render/IFont.h"
|
2013-09-08 19:49:23 +03:00
|
|
|
|
2023-02-25 01:11:42 +02:00
|
|
|
class ResourceID;
|
|
|
|
|
2012-12-19 20:24:53 +03:00
|
|
|
class CBitmapFont : public IFont
|
|
|
|
{
|
2023-02-25 01:11:42 +02:00
|
|
|
using CodePoint = uint32_t;
|
2012-12-19 20:24:53 +03:00
|
|
|
|
2013-10-26 00:45:14 +03:00
|
|
|
struct BitmapChar
|
2012-12-19 20:24:53 +03:00
|
|
|
{
|
2023-02-25 01:11:42 +02:00
|
|
|
int32_t leftOffset;
|
|
|
|
uint32_t width;
|
|
|
|
uint32_t height;
|
|
|
|
int32_t rightOffset;
|
|
|
|
std::vector<uint8_t> pixels; // pixels of this character, part of BitmapFont::data
|
2012-12-19 20:24:53 +03:00
|
|
|
};
|
|
|
|
|
2023-02-25 01:11:42 +02:00
|
|
|
std::unordered_map<CodePoint, BitmapChar> chars;
|
|
|
|
uint32_t maxHeight;
|
2012-12-19 20:24:53 +03:00
|
|
|
|
2023-02-25 01:11:42 +02:00
|
|
|
void loadModFont(const std::string & modName, const ResourceID & resource);
|
2012-12-19 20:24:53 +03:00
|
|
|
|
2013-10-26 00:45:14 +03:00
|
|
|
void renderCharacter(SDL_Surface * surface, const BitmapChar & character, const SDL_Color & color, int &posX, int &posY) const;
|
2013-09-08 19:49:23 +03:00
|
|
|
void renderText(SDL_Surface * surface, const std::string & data, const SDL_Color & color, const Point & pos) const override;
|
2012-12-19 20:24:53 +03:00
|
|
|
public:
|
2023-02-25 01:11:42 +02:00
|
|
|
explicit CBitmapFont(const std::string & filename);
|
2012-12-19 20:24:53 +03:00
|
|
|
|
2013-09-08 19:49:23 +03:00
|
|
|
size_t getLineHeight() const override;
|
|
|
|
size_t getGlyphWidth(const char * data) const override;
|
|
|
|
|
|
|
|
friend class CBitmapHanFont;
|
|
|
|
};
|
|
|
|
|