Space Fighter
A "shmup" game for Computer Programming C++
Loading...
Searching...
No Matches
Font.cpp
Go to the documentation of this file.
1
2/*
3 ██╗ ██╗ █████╗ ████████╗ █████╗ ███╗ ██╗ █████╗
4 ██║ ██╔╝ ██╔══██╗ ╚══██╔══╝ ██╔══██╗ ████╗ ██║ ██╔══██╗
5 █████╔╝ ███████║ ██║ ███████║ ██╔██╗ ██║ ███████║
6 ██╔═██╗ ██╔══██║ ██║ ██╔══██║ ██║╚██╗██║ ██╔══██║
7 ██║ ██╗ ██║ ██║ ██║ ██║ ██║ ██║ ╚████║ ██║ ██║
8 ╚═╝ ╚═╝ ╚═╝ ╚═╝/\ ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═══╝ ╚═╝ ╚═╝
9 /vvvvvvvvvvvvvvvvvvv \=========================================,
10 `^^^^^^^^^^^^^^^^^^^ /---------------------------------------"
11 Katana Engine \/ © 2012 - Shuriken Studios LLC
12 http://www.shurikenstudios.com
13*/
14
15#include "KatanaEngine.h"
16
17namespace KatanaEngine
18{
19 int Font::s_fontSize = 16;
20 int Font::s_restoreSize = 0;
21 bool Font::s_alAddonInitialized = false;
22 int Font::s_rangeCount = 0;
23 int *Font::s_ranges = nullptr;
24
25
26 void Font::SetLoadSize(const int size, const bool restore)
27 {
28 if (restore) s_restoreSize = s_fontSize;
29
30 s_fontSize = size;
31 }
32
33 void Font::SetCharacterRange(const int rangeCount, int ranges[])
34 {
35 s_rangeCount = rangeCount;
36 s_ranges = ranges;
37 }
38
39 bool Font::Load(const std::string &path, ResourceManager *pManager)
40 {
41 if (!s_alAddonInitialized)
42 {
43 al_init_font_addon();
44 al_init_ttf_addon();
45
46 s_alAddonInitialized = true;
47 }
48
49 bool isTTF = (path.find(".ttf") != std::string::npos);
50 bool isPNG = (path.find(".png") != std::string::npos);
51 if (isTTF)
52 {
53 m_pFont = al_load_ttf_font(path.c_str(), s_fontSize, 0);
54 }
55 else if (isPNG)
56 {
57 int ranges[] = { 32, 126 };
58
59 if (s_ranges == nullptr)
60 {
61 s_ranges = ranges;
62 s_rangeCount = 1;
63 }
64
65 Texture *pTexture = pManager->Load<Texture>(path, true, false);
66 if (pTexture)
67 {
68 m_pFont = al_grab_font_from_bitmap(pTexture->GetAllegroBitmap(), s_rangeCount, s_ranges);
69 }
70
71 s_ranges = nullptr;
72 }
73 else
74 {
75 m_pFont = al_load_font(path.c_str(), s_fontSize, 0);
76 }
77
78 if (s_restoreSize > 0) s_fontSize = s_restoreSize;
79
80 return (m_pFont != nullptr);
81 }
82}
static void SetCharacterRange(const int rangeCount, int ranges[])
Sets which characters to use when using a bitmap as a font.
Definition Font.cpp:33
static void SetLoadSize(const int size, const bool restore=false)
Specifies the size of the font when loaded.
Definition Font.cpp:26
virtual bool Load(const std::string &path, ResourceManager *pManager)
Load the desired font into memory.
Definition Font.cpp:39
Loads and manages the lifespan of objects from external files.
T * Load(const std::string &path, const bool cache=true, const bool appendContentPath=true)
Load and manage a resource.
Represents a 2D grid of texels.
Definition Texture.h:21
virtual ALLEGRO_BITMAP * GetAllegroBitmap() const
Get the allegro bitmap representation of the texture.
Definition Texture.h:57
Katana Engine is a library of classes, interfaces, and value types that provides a foundation for dev...
Definition Animation.cpp:18