Revision Log
Revision: 1.1 - (view) (download) (as text)
| 1 : | ktanaka | 1.1 | #ifndef _BITMAP_FONT_H |
| 2 : | #define _BITMAP_FONT_H | ||
| 3 : | |||
| 4 : | #include <vector> | ||
| 5 : | #include <string> | ||
| 6 : | |||
| 7 : | class BitmapFont{ | ||
| 8 : | friend ostream& operator<<(ostream &os,const BitmapFont &bf); | ||
| 9 : | private: | ||
| 10 : | int width, height; | ||
| 11 : | vector<bool> bitmap; | ||
| 12 : | public: | ||
| 13 : | int getWidth() const { return width; } | ||
| 14 : | int getHeight() const { return height; } | ||
| 15 : | BitmapFont(){} | ||
| 16 : | BitmapFont(const BitmapFont& b){ | ||
| 17 : | width=b.width; | ||
| 18 : | height=b.height; | ||
| 19 : | bitmap=b.bitmap; | ||
| 20 : | } | ||
| 21 : | BitmapFont(int w,int h) :width(w),height(h),bitmap(w*h,false){ | ||
| 22 : | } | ||
| 23 : | // 暗黙のうちに幅が4ビットの倍数だと仮定している。 | ||
| 24 : | BitmapFont(int w,int h,const string& hex) :width(w),height(h),bitmap(){ | ||
| 25 : | for(string::const_iterator it=hex.begin();it!=hex.end();it++){ | ||
| 26 : | string s; | ||
| 27 : | s+= *it; | ||
| 28 : | long val=strtol(s.c_str(),0,16); | ||
| 29 : | assert(val>=0 && val<16); | ||
| 30 : | for(int i=0;i<4;i++){ | ||
| 31 : | bool pixel=false; | ||
| 32 : | if((val&(1<<(3-i)))!=0) pixel=true; | ||
| 33 : | bitmap.push_back(pixel); | ||
| 34 : | } | ||
| 35 : | } | ||
| 36 : | } | ||
| 37 : | bool get(int x, int y) const{ | ||
| 38 : | if(x<0 || x>=width || y<0 || y>=height){ | ||
| 39 : | return false; | ||
| 40 : | } | ||
| 41 : | return bitmap[y*width+x]; | ||
| 42 : | } | ||
| 43 : | }; | ||
| 44 : | #endif /* _BITMAP_FONT_H */ |
|
ktanaka Powered by ViewCVS 1.0-dev |
ViewCVS and CVS Help |