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
|
|
|
|
2012-12-19 20:24:53 +03:00
|
|
|
class CBitmapFont : public IFont
|
|
|
|
{
|
|
|
|
static const size_t totalChars = 256;
|
|
|
|
|
2013-10-26 00:45:14 +03:00
|
|
|
struct BitmapChar
|
2012-12-19 20:24:53 +03:00
|
|
|
{
|
|
|
|
si32 leftOffset;
|
|
|
|
ui32 width;
|
|
|
|
si32 rightOffset;
|
|
|
|
ui8 *pixels; // pixels of this character, part of BitmapFont::data
|
|
|
|
};
|
|
|
|
|
|
|
|
const std::pair<std::unique_ptr<ui8[]>, ui64> data;
|
|
|
|
|
2013-10-26 00:45:14 +03:00
|
|
|
const std::array<BitmapChar, totalChars> chars;
|
2012-12-19 20:24:53 +03:00
|
|
|
const ui8 height;
|
|
|
|
|
2013-10-26 00:45:14 +03:00
|
|
|
std::array<BitmapChar, totalChars> loadChars() const;
|
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;
|
2012-12-19 20:24:53 +03:00
|
|
|
|
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:
|
|
|
|
CBitmapFont(const std::string & filename);
|
|
|
|
|
2013-09-08 19:49:23 +03:00
|
|
|
size_t getLineHeight() const override;
|
|
|
|
size_t getGlyphWidth(const char * data) const override;
|
|
|
|
|
|
|
|
friend class CBitmapHanFont;
|
|
|
|
};
|
|
|
|
|