2023-10-03 20:37:00 +02:00
|
|
|
// Copyright (C) 2002-2012 Nikolaus Gebhardt
|
|
|
|
// This file is part of the "Irrlicht Engine".
|
|
|
|
// For conditions of distribution and use, see copyright notice in irrlicht.h
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "IGUIFontBitmap.h"
|
|
|
|
#include "irrString.h"
|
|
|
|
#include "IReadFile.h"
|
|
|
|
#include "irrArray.h"
|
|
|
|
#include <map>
|
|
|
|
|
|
|
|
namespace irr
|
|
|
|
{
|
|
|
|
|
|
|
|
namespace video
|
|
|
|
{
|
2024-03-20 19:35:52 +01:00
|
|
|
class IVideoDriver;
|
|
|
|
class IImage;
|
2023-10-03 20:37:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
namespace gui
|
|
|
|
{
|
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
class IGUIEnvironment;
|
2023-10-03 20:37:00 +02:00
|
|
|
|
|
|
|
class CGUIFont : public IGUIFontBitmap
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
//! constructor
|
2024-03-20 19:35:52 +01:00
|
|
|
CGUIFont(IGUIEnvironment *env, const io::path &filename);
|
2023-10-03 20:37:00 +02:00
|
|
|
|
|
|
|
//! destructor
|
|
|
|
virtual ~CGUIFont();
|
|
|
|
|
|
|
|
//! loads a font from a texture file
|
2024-03-20 19:35:52 +01:00
|
|
|
bool load(const io::path &filename);
|
2023-10-03 20:37:00 +02:00
|
|
|
|
|
|
|
//! loads a font from a texture file
|
2024-03-20 19:35:52 +01:00
|
|
|
bool load(io::IReadFile *file);
|
2023-10-03 20:37:00 +02:00
|
|
|
|
|
|
|
//! draws an text and clips it to the specified rectangle if wanted
|
2024-03-20 19:35:52 +01:00
|
|
|
virtual void draw(const core::stringw &text, const core::rect<s32> &position,
|
|
|
|
video::SColor color, bool hcenter = false,
|
|
|
|
bool vcenter = false, const core::rect<s32> *clip = 0) override;
|
2023-10-03 20:37:00 +02:00
|
|
|
|
|
|
|
//! returns the dimension of a text
|
2024-03-20 19:35:52 +01:00
|
|
|
core::dimension2d<u32> getDimension(const wchar_t *text) const override;
|
2023-10-03 20:37:00 +02:00
|
|
|
|
|
|
|
//! Calculates the index of the character in the text which is on a specific position.
|
2024-03-20 19:35:52 +01:00
|
|
|
s32 getCharacterFromPos(const wchar_t *text, s32 pixel_x) const override;
|
2023-10-03 20:37:00 +02:00
|
|
|
|
|
|
|
//! Returns the type of this font
|
|
|
|
EGUI_FONT_TYPE getType() const override { return EGFT_BITMAP; }
|
|
|
|
|
|
|
|
//! set an Pixel Offset on Drawing ( scale position on width )
|
2024-03-20 19:35:52 +01:00
|
|
|
void setKerningWidth(s32 kerning) override;
|
|
|
|
void setKerningHeight(s32 kerning) override;
|
2023-10-03 20:37:00 +02:00
|
|
|
|
|
|
|
//! set an Pixel Offset on Drawing ( scale position on width )
|
2024-03-20 19:35:52 +01:00
|
|
|
s32 getKerningWidth(const wchar_t *thisLetter = 0, const wchar_t *previousLetter = 0) const override;
|
2023-10-03 20:37:00 +02:00
|
|
|
s32 getKerningHeight() const override;
|
|
|
|
|
|
|
|
//! gets the sprite bank
|
2024-03-20 19:35:52 +01:00
|
|
|
IGUISpriteBank *getSpriteBank() const override;
|
2023-10-03 20:37:00 +02:00
|
|
|
|
|
|
|
//! returns the sprite number from a given character
|
|
|
|
u32 getSpriteNoFromChar(const wchar_t *c) const override;
|
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
void setInvisibleCharacters(const wchar_t *s) override;
|
2023-10-03 20:37:00 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
struct SFontArea
|
|
|
|
{
|
2024-03-20 19:35:52 +01:00
|
|
|
SFontArea() :
|
|
|
|
underhang(0), overhang(0), width(0), spriteno(0) {}
|
|
|
|
s32 underhang;
|
|
|
|
s32 overhang;
|
|
|
|
s32 width;
|
|
|
|
u32 spriteno;
|
2023-10-03 20:37:00 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
//! load & prepare font from ITexture
|
2024-03-20 19:35:52 +01:00
|
|
|
bool loadTexture(video::IImage *image, const io::path &name);
|
2023-10-03 20:37:00 +02:00
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
void readPositions(video::IImage *texture, s32 &lowerRightPositions);
|
2023-10-03 20:37:00 +02:00
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
s32 getAreaFromCharacter(const wchar_t c) const;
|
2023-10-03 20:37:00 +02:00
|
|
|
void setMaxHeight();
|
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
void pushTextureCreationFlags(bool (&flags)[3]);
|
|
|
|
void popTextureCreationFlags(const bool (&flags)[3]);
|
|
|
|
|
|
|
|
core::array<SFontArea> Areas;
|
|
|
|
std::map<wchar_t, s32> CharacterMap;
|
|
|
|
video::IVideoDriver *Driver;
|
|
|
|
IGUISpriteBank *SpriteBank;
|
|
|
|
IGUIEnvironment *Environment;
|
|
|
|
u32 WrongCharacter;
|
|
|
|
s32 MaxHeight;
|
|
|
|
s32 GlobalKerningWidth, GlobalKerningHeight;
|
2023-10-03 20:37:00 +02:00
|
|
|
|
|
|
|
core::stringw Invisible;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // end namespace gui
|
|
|
|
} // end namespace irr
|