|
|
#include <vector> |
#include <vector> |
#include <string> |
#include <string> |
|
#include <algorithm> |
|
|
|
typedef pair<int,int> pixel; |
|
|
class BitmapFont{ |
class BitmapFont{ |
friend ostream& operator<<(ostream &os,const BitmapFont &bf); |
friend ostream& operator<<(ostream &os,const BitmapFont &bf); |
private: |
private: |
int width, height; |
int width, height; |
vector<bool> bitmap; |
vector<bool> bitmap; |
|
vector<pixel> pixels; |
public: |
public: |
int getWidth() const { return width; } |
int getWidth() const { return width; } |
int getHeight() const { return height; } |
int getHeight() const { return height; } |
|
int getSize() const { return width*height; } |
|
int getPixelSize() const { return pixels.size(); } |
BitmapFont(){} |
BitmapFont(){} |
BitmapFont(const BitmapFont& b){ |
BitmapFont(const BitmapFont& b){ |
width=b.width; |
width=b.width; |
height=b.height; |
height=b.height; |
bitmap=b.bitmap; |
bitmap=b.bitmap; |
|
pixels=b.pixels; |
} |
} |
BitmapFont(int w,int h) :width(w),height(h),bitmap(w*h,false){ |
BitmapFont(int w,int h) :width(w),height(h),bitmap(w*h,false){ |
} |
} |
assert(val>=0 && val<16); |
assert(val>=0 && val<16); |
for(int i=0;i<4;i++){ |
for(int i=0;i<4;i++){ |
bool pixel=false; |
bool pixel=false; |
if((val&(1<<(3-i)))!=0) pixel=true; |
if((val&(1<<(3-i)))!=0){ |
|
pixel=true; |
|
} |
bitmap.push_back(pixel); |
bitmap.push_back(pixel); |
} |
} |
} |
} |
|
for(int y=0;y<height;y++) |
|
for(int x=0;x<width;x++) |
|
if(get(x,y)) |
|
pixels.push_back(pair<int,int>(x,y)); |
} |
} |
bool get(int x, int y) const{ |
bool get(int x, int y) const{ |
if(x<0 || x>=width || y<0 || y>=height){ |
if(x<0 || x>=width || y<0 || y>=height){ |
} |
} |
return bitmap[y*width+x]; |
return bitmap[y*width+x]; |
} |
} |
|
int getIndex(const pixel &px) const{ |
|
vector<pixel>::const_iterator it=find(pixels.begin(),pixels.end(),px); |
|
if(it!=pixels.end()){ |
|
return it-pixels.begin(); |
|
} |
|
return -1; |
|
} |
}; |
}; |
#endif /* _BITMAP_FONT_H */ |
#endif /* _BITMAP_FONT_H */ |