33 lines
1.0 KiB
C++
33 lines
1.0 KiB
C++
#include "ImageFont.h"
|
|
|
|
namespace charcoal
|
|
{
|
|
ImageFont::ImageFont(const image_loader::ImageRGBA& image, std::map<char, Rectangle<int>> character_locations)
|
|
{
|
|
for (auto iter = character_locations.begin(); iter != character_locations.end(); ++iter)
|
|
{
|
|
image_loader::ImageRGBA created_image;
|
|
created_image.width = iter->second.right - iter->second.left;
|
|
created_image.height = iter->second.bottom - iter->second.top;
|
|
created_image.data.resize(image.width * image.height * 4);
|
|
for (unsigned int y = 0; y < created_image.height; ++y)
|
|
{
|
|
for (unsigned int x = 0; x < created_image.width; ++x)
|
|
{
|
|
unsigned char red;
|
|
unsigned char green;
|
|
unsigned char blue;
|
|
unsigned char alpha;
|
|
image.get_pixel(x + iter->second.left, y + iter->second.top, red, green, blue, alpha);
|
|
created_image.set_pixel(x, y, red, green, blue, alpha);
|
|
}
|
|
}
|
|
m_character_images.emplace(iter->first, created_image);
|
|
}
|
|
}
|
|
|
|
const image_loader::ImageRGBA& ImageFont::get_character(char character)
|
|
{
|
|
return m_character_images[character];
|
|
}
|
|
} |