kick
/Users/morten/Programmering/cpp/kick/src/kick/2d/font.h
00001 //
00002 // Created by morten on 30/06/14.
00003 //
00004 
00005 
00006 #pragma once
00007 #include <string>
00008 #include "kick/core/project_asset.h"
00009 #include "kick/core/project.h"
00010 #include "kick/core/event.h"
00011 
00012 
00013 namespace kick {
00014     class Texture2D;
00015     class Shader;
00016     class Label;
00017 
00018     struct FontChar {
00019 //        int id;
00020         int x;
00021         int y;
00022         int width;
00023         int height;
00024         int xoffset;
00025         int yoffset;
00026         int xadvance;
00027         int page;
00028         int chnl;
00029 //        std::string letter;
00030     };
00031 
00032 class Font : public ProjectAsset {
00033 public:
00034     Font();
00035     ~Font();
00036     // filename is the .fnt file. There must be a .png with the same name containing the bitmap font texture in
00037     // the same folder
00038     bool loadFntFile(std::string filename = "assets/font/open_sans_28.fnt");
00039     int width(std::string text);
00040     int height();
00041 
00042 
00043     std::shared_ptr<Texture2D> texture() const;
00044 
00045     void setTexture(std::shared_ptr<Texture2D> texture);
00046 
00047     const FontChar getChar(char r);
00048 
00049     int scaleW() const;
00050     int scaleH() const;
00051 
00052     std::shared_ptr<Shader> getShader();
00053 
00054     void setShader(std::shared_ptr<Shader> shader);
00055 
00056     int base() const;
00057 
00058     friend class Label;
00059 
00060     bool initialized() const;
00061 
00062     Event<Font*> fontListener;
00063 private:
00064     int getKerning(int t1, int t2);
00065 
00066     std::shared_ptr<Texture2D> mTexture;
00067     int mLineHeight = 0;
00068     int mBase = 0;
00069     int mScaleW = 0;
00070     int mScaleH = 0;
00071     int mPages = 1;
00072     std::map<int, FontChar> mFontMap;
00073     std::shared_ptr<Shader> fShader;
00074     std::map<std::pair<int, int>, int> mKerning;
00075 };
00076 }
 All Classes Functions Variables