Page Menu
Home
Phabricator (Chris)
Search
Configure Global Search
Log In
Files
F127071
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
43 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/util/bitmap.cpp b/util/bitmap.cpp
index 70b1efad..9af5f3f2 100644
--- a/util/bitmap.cpp
+++ b/util/bitmap.cpp
@@ -1,734 +1,736 @@
#include <allegro.h>
#include "bitmap.h"
#include "font.h"
#include <stdarg.h>
#include <vector>
#include <string>
#include <iostream>
// #include <fblend.h>
#ifdef WINDOWS
#include <winalleg.h>
#endif
using namespace std;
#ifndef debug
#define debug cout<<"File: "<<__FILE__<<" Line: "<<__LINE__<<endl;
#endif
const int Bitmap::MaskColor = MASK_COLOR_16;
const int Bitmap::MODE_TRANS = 0;
const int Bitmap::MODE_SOLID = 1;
Bitmap * Bitmap::Screen;
Bitmap::Bitmap():
error( false ){
setBitmap( create_bitmap( 10, 10 ) );
if ( ! getBitmap() ){
error = true;
cerr << "Could not create bitmap!" << endl;
} else {
clear();
own = new int;
*own = 1;
}
}
Bitmap::Bitmap( int x, int y ):
error( false ){
if ( x < 1 ){
x = 1;
}
if ( y < 1 ){
y = 1;
}
setBitmap( create_bitmap( x, y ) );
if ( ! getBitmap() ){
error = true;
cerr << "Could not create bitmap!" << endl;
} else {
clear();
own = new int;
*own = 1;
}
}
/* If a BITMAP is given to us, we didnt make it so we dont own it */
Bitmap::Bitmap( BITMAP * who, bool deep_copy ):
error( false ){
if ( deep_copy ){
BITMAP * his = who;
setBitmap( create_bitmap( his->w, his->h ) );
::blit( his, getBitmap(), 0, 0, 0, 0, his->w, his->h );
own = new int;
*own = 1;
} else {
setBitmap( who );
own = NULL;
}
}
Bitmap::Bitmap( const char * load_file ):
error( false ){
internalLoadFile( load_file );
/*
my_bitmap = load_bitmap( load_file, NULL );
if ( !my_bitmap ){
my_bitmap = create_bitmap( 100, 100 );
clear( my_bitmap );
cout<<"Could not load "<<load_file<<endl;
error = true;
}
own = true;
*/
}
Bitmap::Bitmap( const string & load_file ):
error( false ){
internalLoadFile( load_file.c_str() );
}
Bitmap::Bitmap( const char * load_file, int sx, int sy ):
error( false ){
path = load_file;
BITMAP * temp = load_bitmap( load_file, NULL );
// my_bitmap = load_bitmap( load_file, NULL );
setBitmap( create_bitmap( sx, sy ) );
// clear( my_bitmap );
clear();
if ( !temp ){
cout<<"Could not load "<<load_file<<endl;
error = true;
} else {
stretch_blit( temp, getBitmap(), 0, 0, temp->w, temp->h, 0, 0, getBitmap()->w, getBitmap()->h );
destroy_bitmap( temp );
}
// own = true;
own = new int;
*own = 1;
}
Bitmap::Bitmap( const char * load_file, int sx, int sy, double accuracy ):
error( false ){
path = load_file;
BITMAP * temp = load_bitmap( load_file, NULL );
own = new int;
*own = 1;
if ( !temp ){
cout<<"Could not load "<<load_file<<endl;
setBitmap( create_bitmap( sx, sy ) );
// clear( my_bitmap );
clear();
error = true;
} else {
if ( temp->w > sx || temp->h > sy ){
double bx = temp->w / sx;
double by = temp->h / sy;
double use;
use = bx > by ? bx : by;
int fx = (int)(sx / use);
int fy = (int)(sy / use);
setBitmap( create_bitmap( fx, fy ) );
stretch_blit( temp, getBitmap(), 0, 0, temp->w, temp->h, 0, 0, getBitmap()->w, getBitmap()->h );
destroy_bitmap( temp );
} else setBitmap( temp );
}
// own = true;
}
Bitmap::Bitmap( const Bitmap & copy, int sx, int sy ):
error( false ){
path = copy.getPath();
BITMAP * temp = copy.getBitmap();
setBitmap( create_bitmap( sx, sy ) );
// clear( my_bitmap );
clear();
stretch_blit( temp, getBitmap(), 0, 0, temp->w, temp->h, 0, 0, getBitmap()->w, getBitmap()->h );
// own = true;
// own = copy.own;
own = new int;
*own = 1;
}
Bitmap::Bitmap( const Bitmap & copy, int sx, int sy, double accuracy ):
error( false ){
path = copy.getPath();
BITMAP * temp = copy.getBitmap();
own = new int;
*own = 1;
if ( temp->w > sx || temp->h > sy ){
double bx = (double)temp->w / (double)sx;
double by = (double)temp->h / (double)sy;
double use;
use = bx > by ? bx : by;
int fx = (int)(temp->w / use);
int fy = (int)(temp->h / use);
setBitmap( create_bitmap( fx, fy ) );
if ( ! getBitmap() ){
allegro_message("Could not create bitmap\n");
// own = false;
// own = copy.own;
// *own++;
error = true;
return;
}
stretch_blit( temp, getBitmap(), 0, 0, temp->w, temp->h, 0, 0, getBitmap()->w, getBitmap()->h );
// destroy_bitmap( temp );
} else {
setBitmap( create_bitmap( temp->w, temp->h ) );
blit( temp, getBitmap(), 0, 0, 0, 0, temp->w, temp->h );
// own = new int
// own = true;
}
}
Bitmap::Bitmap( const Bitmap & copy, bool deep_copy ):
error( false ){
path = copy.getPath();
if ( deep_copy ){
BITMAP * his = copy.getBitmap();
setBitmap( create_bitmap( his->w, his->h ) );
::blit( his, getBitmap(), 0, 0, 0, 0, his->w, his->h );
own = new int;
*own = 1;
} else {
setBitmap( copy.getBitmap() );
// own = false;
own = copy.own;
if ( own ){
*own = *own + 1;
}
}
/*
BITMAP * his = copy.getBitmap();
my_bitmap = create_bitmap( his->w, his->h );
::blit( his, my_bitmap, 0, 0, 0, 0, his->w, his->h );
own = true;
*/
}
Bitmap::Bitmap( const Bitmap & copy, int x, int y, int width, int height ):
error( false ){
path = copy.getPath();
BITMAP * his = copy.getBitmap();
if ( x < 0 )
x = 0;
if ( y < 0 )
y = 0;
if ( width > his->w )
width = his->w;
if ( height > his->h )
height = his->h;
setBitmap( create_sub_bitmap( his, x, y, width, height ) );
if ( ! getBitmap() ){
cout<<"Could not create sub-bitmap"<<endl;
setBitmap( create_bitmap( 10, 10 ) );
// clear( my_bitmap );
clear();
}
// own = true;
own = new int;
*own = 1;
}
void Bitmap::load( const string & str ){
releaseInternalBitmap();
internalLoadFile( str.c_str() );
}
void Bitmap::internalLoadFile( const char * load_file ){
path = load_file;
setBitmap( load_bitmap( load_file, NULL ) );
if ( ! getBitmap() ){
cout<<"Could not load "<<load_file<<". Using default"<<endl;
setBitmap( create_bitmap( 10, 10 ) );
if ( ! getBitmap() ){
cout<<"Out of memory or Allegro not initialized"<<endl;
error = true;
return;
}
// clear( my_bitmap );
clear();
// cout<<"Could not load "<<load_file<<endl;
error = true;
}
// own = true;
own = new int;
*own = 1;
}
void Bitmap::save( const string & str ){
save_bitmap( str.c_str(), getBitmap(), NULL );
}
/* decrement bitmap reference counter and free memory if counter hits 0 */
void Bitmap::releaseInternalBitmap(){
if ( own ){
(*own)--;
if ( *own == 0 ){
delete own;
destroy_bitmap( getBitmap() );
own = NULL;
}
}
}
const int Bitmap::getWidth() const{
return getBitmap()->w;
}
const int Bitmap::getHeight() const{
return getBitmap()->h;
}
int Bitmap::getRed( int x ){
return ::getr( x );
}
int Bitmap::getBlue( int x ){
return ::getg( x );
}
int Bitmap::getGreen( int x ){
return ::getb( x );
}
/* resize the internal bitmap. not guaranteed to destroy the internal bitmap */
void Bitmap::resize( const int width, const int height ){
/* if internal bitmap is already the proper size, do nothing */
if ( getWidth() == width && getHeight() == height ){
return;
}
releaseInternalBitmap();
own = new int;
setBitmap( create_bitmap( width, height ) );
*own = 1;
}
/*
const string & Bitmap::getPath() const{
return path;
}
*/
void Bitmap::debugSelf() const{
cout<<"Bitmap: "<<endl;
cout<<"Self = "<< getBitmap() <<endl;
cout<<"Own = "<< own <<" : "<< *own <<endl;
cout<<"Path = "<<path<<endl;
}
Bitmap & Bitmap::operator=( const Bitmap & copy ){
/*
if ( own ){
(*own)--;
if ( *own == 0 ){
destroy_bitmap( getBitmap() );
delete own;
}
}
*/
releaseInternalBitmap();
path = copy.getPath();
setBitmap( copy.getBitmap() );
// own = false;
own = copy.own;
if ( own )
*own++;
return *this;
}
Bitmap::~Bitmap(){
/*
if ( own ){
(*own)--;
if ( *own == 0 ){
destroy_bitmap( getBitmap() );
delete own;
} else {
// cout<<"Not destroying bitmap "<<this<<endl;
}
}
*/
releaseInternalBitmap();
}
void Bitmap::detach(){
/*
if ( own ){
(*own)--;
if ( *own == 0 ){
destroy_bitmap( getBitmap() );
delete own;
}
}
*/
releaseInternalBitmap();
}
/*
BITMAP * Bitmap::getBitmap() const{
return my_bitmap;
}
*/
bool Bitmap::getError(){
return error;
}
/*
int Bitmap::getWidth(){
return my_bitmap->w;
}
int Bitmap::getHeight(){
return my_bitmap->h;
}
*/
void Bitmap::acquire(){
acquire_bitmap( getBitmap() );
}
void Bitmap::release(){
release_bitmap( getBitmap() );
}
void Bitmap::circleFill( int x, int y, int radius, int color ) const{
::circlefill( getBitmap(), x, y, radius, color );
}
void Bitmap::circle( int x, int y, int radius, int color ) const{
::circle( getBitmap(), x, y, radius, color );
}
void Bitmap::line( const int x1, const int y1, const int x2, const int y2, const int color ) const{
::line( getBitmap(), x1, y1, x2, y2, color );
}
void Bitmap::transBlender( int r, int g, int b, int a ){
set_trans_blender( r, g, b, a );
}
void Bitmap::multiplyBlender( int r, int g, int b, int a ){
set_multiply_blender( r, g, b, a );
}
void Bitmap::drawingMode( int mode ){
// drawing_mode( DRAW_MODE_TRANS, NULL, 0, 0 );
switch( mode ){
case MODE_TRANS : {
drawing_mode( DRAW_MODE_TRANS, NULL, 0, 0 );
break;
}
case MODE_SOLID : {
drawing_mode( DRAW_MODE_SOLID, NULL, 0, 0 );
break;
}
}
}
/*
const int Bitmap::getWidth() const{
return getBitmap()->w;
}
const int Bitmap::getHeight() const{
return getBitmap()->h;
}
*/
const int Bitmap::getPixel( const int x, const int y ) const{
if ( x >= 0 && x < getBitmap()->w && y >= 0 && y < getBitmap()->h )
return _getpixel16( getBitmap(), x, y );
return -1;
}
void Bitmap::readLine( vector< int > & vec, int y ){
if ( y >= 0 && y < getBitmap()->h ){
for ( int q = 0; q < getBitmap()->w; q++ ){
// int col = my_bitmap->line[ y ][ q ];
int col = _getpixel16( getBitmap(), q, y );
vec.push_back( col );
}
}
}
int Bitmap::setGfxModeText(){
return ::set_gfx_mode( GFX_TEXT, 0, 0, 0, 0 );
}
int Bitmap::setGfxModeFullscreen( int x, int y ){
return ::set_gfx_mode( GFX_AUTODETECT_FULLSCREEN, x, y, 0, 0 );
}
int Bitmap::setGfxModeWindowed( int x, int y ){
return ::set_gfx_mode( GFX_AUTODETECT_WINDOWED, x, y, 0, 0 );
}
int Bitmap::makeColor( int r, int g, int b ){
return ::makecol16( r, g, b );
}
void Bitmap::hsvToRGB( float h, float s, float v, int * r, int * g, int * b ){
::hsv_to_rgb( h, s, v, r, g, b );
}
int Bitmap::addColor( int color1, int color2 ){
return makeColor( getr( color1 ) + getr( color2 ),
getg( color1 ) + getg( color2 ),
getb( color1 ) + getb( color2 ) );
}
void Bitmap::putPixel( int x, int y, int col ) const{
if ( x >= 0 && x < getBitmap()->w && y >= 0 && y < getBitmap()->h )
_putpixel16( getBitmap(), x, y, col );
}
+/*
void Bitmap::printf( int x, int y, int color, FONT * f, const char * str, ... ) const{
char buf[512];
va_list ap;
va_start(ap, str);
uvszprintf(buf, sizeof(buf), str, ap);
va_end(ap);
textout_ex( getBitmap(), f, buf, x, y, color, -1);
}
void Bitmap::printf( int x, int y, int color, const Font * const f, const char * str, ... ) const{
char buf[512];
va_list ap;
va_start(ap, str);
uvszprintf(buf, sizeof(buf), str, ap);
va_end(ap);
textout_ex( getBitmap(), f->getInternalFont(), buf, x, y, color, -1);
}
void Bitmap::printf( int x, int y, int color, const Font * const f, const string & str ) const{
printf( x, y, color, f, str.c_str() );
}
void Bitmap::printf( int x, int y, int color, const Font & f, const string & str ) const{
printf( x, y, color, &f, str );
}
void Bitmap::printfNormal( int x, int y, int color, const char * str, ... ) const{
char buf[512];
va_list ap;
va_start(ap, str);
uvszprintf(buf, sizeof(buf), str, ap);
va_end(ap);
textout_ex( getBitmap(), font, buf, x, y, color, -1);
}
void Bitmap::printfNormal( int x, int y, int color, const string & str ) const{
printfNormal( x, y, color, "%s", str.c_str() );
}
+*/
void Bitmap::triangle( int x1, int y1, int x2, int y2, int x3, int y3, int color ) const{
::triangle( getBitmap(), x1, y1, x2, y2, x3, y3, color );
}
void Bitmap::ellipse( int x, int y, int rx, int ry, int color ) const {
::ellipse( getBitmap(), x, y, rx, ry, color );
}
void Bitmap::ellipseFill( int x, int y, int rx, int ry, int color ) const {
::ellipsefill( getBitmap(), x, y, rx, ry, color );
}
void Bitmap::rectangle( int x1, int y1, int x2, int y2, int color ) const{
::rect( getBitmap(), x1, y1, x2, y2, color );
}
void Bitmap::rectangleFill( int x1, int y1, int x2, int y2, int color ) const{
::rectfill( getBitmap(), x1, y1, x2, y2, color );
}
/*
int Bitmap::getPixel( int x, int y ){
if ( x >= 0 && x < my_bitmap->w && y >= 0 && y <= my_bitmap->h )
return _getpixel16( my_bitmap, x, y );
return -1;
}
*/
/*
int Bitmap::makeColor( int r, int g, int b ){
return makecol16( r, g, b );
}
*/
void Bitmap::hLine( const int x1, const int y, const int x2, const int color ) const{
::hline( getBitmap(), x1, y, x2, color );
}
void Bitmap::horizontalLine( const int x1, const int y, const int x2, const int color ) const{
this->hLine( x1, y, x2, color );
}
void Bitmap::vLine( const int y1, const int x, const int y2, const int color ) const{
::vline( getBitmap(), x, y1, y2, color );
}
void Bitmap::polygon( const int * verts, const int nverts, const int color ) const{
::polygon( getBitmap(), nverts, verts, color );
}
/*
void Bitmap::clear(){
this->fill( 0 );
}
*/
void Bitmap::fill( int color ) const{
::clear_to_color( getBitmap(), color );
}
void Bitmap::draw( const int x, const int y, const Bitmap & where ) const{
::draw_sprite( where.getBitmap(), getBitmap(), x, y );
}
void Bitmap::drawHFlip( const int x, const int y, const Bitmap & where ){
::draw_sprite_h_flip( where.getBitmap(), getBitmap(), x, y );
}
void Bitmap::drawLit( const int x, const int y, const int level, const Bitmap & where ) const{
::draw_lit_sprite( where.getBitmap(), getBitmap(), x, y, level );
}
void Bitmap::drawTrans( const int x, const int y, const Bitmap & where ) const{
::draw_trans_sprite( where.getBitmap(), getBitmap(), x, y );
}
void Bitmap::drawRotate( const int x, const int y, const int angle, const Bitmap & where ){
::fixed fang = itofix( (360 - angle) % 360 * 256 / 360 );
::rotate_sprite( where.getBitmap(), getBitmap(), x, y, fang );
}
void Bitmap::drawStretched( const int x, const int y, const int new_width, const int new_height, const Bitmap & who ){
BITMAP * bmp = who.getBitmap();
::masked_stretch_blit( getBitmap(), bmp, 0, 0, getBitmap()->w, getBitmap()->h, x,y, new_height, new_width );
}
void Bitmap::drawMask( const int _x, const int _y, const Bitmap & where ){
int mask = Bitmap::MaskColor;
for ( int x = 0; x < getWidth(); x++ ){
for ( int y = 0; y < getHeight(); y++ ){
if ( getPixel( x,y ) == mask ){
where.putPixel( x+_x, y+_y, mask );
}
}
}
}
void Bitmap::StretchBy2( const Bitmap & where ){
BITMAP * bmp = where.getBitmap();
if ( where.getWidth() == getWidth() && where.getHeight() == getHeight() ){
::blit( getBitmap(), bmp, 0, 0, 0, 0, getBitmap()->w, getBitmap()->h );
return;
}
if ( where.getWidth() != getWidth()*2 ||
where.getHeight() != getHeight()*2 ){
cout<<"Wrong dimensions"<<endl;
cout<<"My: "<< getWidth() << " " << getHeight() << endl;
cout<<"Him: "<<where.getWidth()<< " " << where.getHeight()<<endl;
return;
}
// debug
::stretch_blit( getBitmap(), bmp, 0, 0, getBitmap()->w, getBitmap()->h, 0, 0, bmp->w, bmp->h );
// fblend_2x_stretch( my_bitmap, bmp, 0, 0, 0, 0, my_bitmap->w, my_bitmap->h);
// scale2x_allegro( my_bitmap, bmp, 2 );
// debug
}
void Bitmap::StretchBy4( const Bitmap & where ){
BITMAP * bmp = where.getBitmap();
if ( where.getWidth() != getWidth()*4 ||
where.getHeight() != getHeight()*4 ){
cout<<"Wrong dimensions"<<endl;
cout<<"My: "<< getWidth() << " " << getHeight() << endl;
cout<<"Him: "<<where.getWidth()<< " " << where.getHeight()<<endl;
cout<<"Scaled: "<<getWidth()*4<<" "<< getHeight()*4<<endl;
return;
}
// fblend_2x_stretch( my_bitmap, bmp, 0, 0, 0, 0, my_bitmap->w, my_bitmap->h);
// scale4x_allegro( my_bitmap, bmp, 2 );
::stretch_blit( getBitmap(), bmp, 0, 0, getBitmap()->w, getBitmap()->h, 0, 0, bmp->w, bmp->h );
}
void Bitmap::Stretch( const Bitmap & where ){
BITMAP * bmp = where.getBitmap();
::stretch_blit( getBitmap(), bmp, 0, 0, getBitmap()->w, getBitmap()->h, 0, 0, bmp->w, bmp->h );
}
void Bitmap::Blit( const string & xpath ){
Bitmap duh( xpath );
duh.Blit( *this );
}
void Bitmap::Blit( const int x, const int y, const Bitmap & where ){
BITMAP * bmp = where.getBitmap();
/*
acquire_bitmap( bmp );
acquire_bitmap( my_bitmap );
*/
::blit( getBitmap(), bmp, 0, 0, x, y, getBitmap()->w, getBitmap()->h );
/*
release_bitmap( my_bitmap );
release_bitmap( bmp );
*/
}
void Bitmap::Blit( const int mx, const int my, const int wx, const int wy, const Bitmap & where ){
BITMAP * bmp = where.getBitmap();
::blit( getBitmap(), bmp, mx, my, wx, wy, getBitmap()->w, getBitmap()->h );
}
void Bitmap::Blit( const int mx, const int my, const int width, const int height, const int wx, const int wy, Bitmap & where ){
BITMAP * bmp = where.getBitmap();
::blit( getBitmap(), bmp, mx, my, wx, wy, width, height );
}
void Bitmap::Blit( const Bitmap & where ){
this->Blit( 0, 0, where );
}
void Bitmap::BlitToScreen(){
this->Blit( *Bitmap::Screen );
}
diff --git a/util/bitmap.h b/util/bitmap.h
index 68fe3477..473cec4d 100644
--- a/util/bitmap.h
+++ b/util/bitmap.h
@@ -1,202 +1,205 @@
#ifndef _bitmap_h_
#define _bitmap_h_
#include <string>
#include <vector>
#include <iostream>
/*
#ifdef WINDOWS
#include <winalleg.h>
#endif
*/
struct BITMAP;
struct FONT;
class Font;
using namespace std;
class Bitmap{
public:
static Bitmap * Screen;
/* default constructor makes 10x10 bitmap */
Bitmap();
Bitmap( int x, int y );
Bitmap( const char * load_file );
Bitmap( const string & load_file );
Bitmap( const char * load_file, int sx, int sy );
Bitmap( const char * load_file, int sx, int sy, double accuracy );
Bitmap( BITMAP * who, bool deep_copy = false );
Bitmap( const Bitmap & copy, bool deep_copy = false );
Bitmap( const Bitmap & copy, int sx, int sy );
Bitmap( const Bitmap & copy, int sx, int sy, double accuracy );
Bitmap( const Bitmap & copy, int x, int y, int width, int height );
virtual ~Bitmap();
virtual void save( const string & str );
Bitmap & operator=( const Bitmap & );
virtual void load( const string & str );
const int getWidth() const;
const int getHeight() const;
/*
inline const int getWidth() const{
return getBitmap()->w;
}
inline const int getHeight() const{
return getBitmap()->h;
}
*/
/*
inline const int getWidth() const{
return my_bitmap->w;
}
inline const int getHeight() const{
return my_bitmap->h;
}
*/
void detach();
static void transBlender( int r, int g, int b, int a );
static void multiplyBlender( int r, int g, int b, int a );
static void drawingMode( int type );
void acquire();
void release();
void resize( const int width, const int height );
void debugSelf() const;
+ /*
void printf( int x, int y, int color, FONT * f, const char * str, ... ) const;
void printf( int x, int y, int color, const Font * const f, const char * str, ... ) const;
void printf( int x, int y, int color, const Font * const f, const string & str ) const;
void printf( int x, int y, int color, const Font & f, const string & str ) const;
void printfNormal( int x, int y, int color, const char * str, ... ) const;
void printfNormal( int x, int y, int color, const string & str ) const;
+ */
+
void triangle( int x1, int y1, int x2, int y2, int x3, int y3, int color ) const;
void ellipse( int x, int y, int rx, int ry, int color ) const;
void ellipseFill( int x, int y, int rx, int ry, int color ) const;
void rectangle( int x1, int y1, int x2, int y2, int color ) const;
void rectangleFill( int x1, int y1, int x2, int y2, int color ) const;
void circleFill( int x, int y, int radius, int color ) const;
void circle( int x, int y, int radius, int color ) const;
void line( const int x1, const int y1, const int x2, const int y2, const int color ) const;
void horizontalLine( const int x1, const int y, const int x2, const int color ) const;
void hLine( const int x1, const int y, const int x2, const int color ) const;
void vLine( const int y1, const int x, const int y2, const int color ) const;
void polygon( const int * verts, const int nverts, const int color ) const;
void draw( const int x, const int y, const Bitmap & where ) const;
void drawLit( const int x, const int y, const int level, const Bitmap & where ) const;
void drawHFlip( const int x, const int y, const Bitmap & where );
void drawTrans( const int x, const int y, const Bitmap & where ) const;
void drawMask( const int x, const int y, const Bitmap & where );
void drawStretched( const int x, const int y, const int new_width, const int new_height, const Bitmap & who );
void drawRotate( const int x, const int y, const int angle, const Bitmap & where );
void Stretch( const Bitmap & where );
void StretchBy2( const Bitmap & where );
void StretchBy4( const Bitmap & where );
void Blit( const string & xpath );
void Blit( const Bitmap & where );
void Blit( const int x, const int y, const Bitmap & where );
void Blit( const int mx, const int my, const int wx, const int wy, const Bitmap & where );
void Blit( const int mx, const int my, const int width, const int height, const int wx, const int wy, Bitmap & where );
void BlitToScreen();
void fill( int color ) const;
inline void clear() const{
this->fill( 0 );
}
bool getError();
inline BITMAP * getBitmap() const{
return _my_bitmap;
}
void readLine( vector< int > & vec, int y );
const int getPixel( const int x, const int y ) const;
void putPixel( int x, int y, int col ) const;
/*
inline int getPixel( int x, int y ) const{
if ( x >= 0 && x < my_bitmap->w && y >= 0 && y <= my_bitmap->h )
return _getpixel16( my_bitmap, x, y );
return -1;
}
inline void putPixel( int x, int y, int col ) const{
if ( x >= 0 && x < my_bitmap->w && y >= 0 && y <= my_bitmap->h )
_putpixel16( my_bitmap, x, y, col );
}
*/
inline const string & getPath() const{
return path;
}
static int setGfxModeText();
static int setGfxModeFullscreen( int x, int y );
static int setGfxModeWindowed( int x, int y );
static int makeColor( int r, int g, int b );
static void hsvToRGB( float h, float s, float v, int * r, int * g, int * b );
static int getRed( int x );
static int getBlue( int x );
static int getGreen( int x );
/* Add two colors together
*/
static int addColor( int color1, int color2 );
/*
inline static int makeColor( int r, int g, int b ){
return makecol16( r, g, b );
}
*/
// static const int MaskColor = MASK_COLOR_16;
static const int MaskColor;
static const int MODE_TRANS;
static const int MODE_SOLID;
protected:
void releaseInternalBitmap();
inline void setBitmap( BITMAP * bitmap ){
if ( bitmap == NULL ){
cout << "*FATAL* Setting null bitmap" << endl;
}
_my_bitmap = bitmap;
}
void internalLoadFile( const char * load_file );
BITMAP * _my_bitmap;
int * own;
// bool own;
bool error;
string path;
};
#endif
diff --git a/util/font.cpp b/util/font.cpp
index 6466563b..bb3a19f7 100644
--- a/util/font.cpp
+++ b/util/font.cpp
@@ -1,27 +1,104 @@
#include <allegro.h>
#include "font.h"
#include "init.h"
+#include "factory/font_factory.h"
-Font::Font( FONT * f ):
-my_font( f ){
+Font::Font(){
+}
+
+Font::~Font(){
+}
+
+AllegroFont::AllegroFont( const FONT * const font ):
+font( font ){
}
-Font::Font( const Font & f ):
-my_font( f.getInternalFont() ){
+AllegroFont::AllegroFont( const AllegroFont & copy ):
+font( copy.getInternalFont() ){
+}
+
+AllegroFont::~AllegroFont(){
}
-const int Font::textLength( const char * text ) const{
+const int AllegroFont::textLength( const char * text ) const{
return text_length( getInternalFont(), text );
}
-const int Font::getHeight() const{
+const int AllegroFont::getHeight() const {
return text_height( getInternalFont() );
}
-const Font getFont( int index ){
- return Font( (FONT *) Global::all_fonts[ index ].dat );
+void AllegroFont::setSize( const int x, const int y ){
+}
+
+const int AllegroFont::getSizeX() const {
+ return 0;
+}
+
+const int AllegroFont::getSizeY() const {
+ return 0;
+}
+
+void AllegroFont::printf( int x, int y, int color, const Bitmap & work, const string & str, ... ) const {
+ char buf[512];
+ va_list ap;
+
+ va_start(ap, str);
+ uvszprintf(buf, sizeof(buf), str.c_str(), ap);
+ va_end(ap);
+
+ textout_ex( work.getBitmap(), getInternalFont(), buf, x, y, color, -1 );
+}
+
+const Font & Font::getDefaultFont(){
+ // return getFont( "tmp/comic.ttf" );
+ return getFont( "bios", 16, 16 );
+}
+
+const Font & Font::getFont( const string & name, const int x, const int y ){
+ return *FontFactory::getFont( name, x, y );
+}
+
+FreeTypeFont::FreeTypeFont( const string & str ):
+sizeX( 16 ),
+sizeY( 16 ){
+ this->font = new ftalleg::freetype( str, getSizeX(), getSizeY() );
+}
+
+const int FreeTypeFont::getHeight() const{
+ return this->font->getHeight();
+}
+
+const int FreeTypeFont::textLength( const char * text ) const {
+ return this->font->getLength( string( text ) );
+}
+
+void FreeTypeFont::printf( int x, int y, int color, const Bitmap & work, const string & str, ... ) const {
+ char buf[512];
+ va_list ap;
+
+ va_start(ap, str);
+ uvszprintf(buf, sizeof(buf), str.c_str(), ap);
+ va_end(ap);
+
+ this->font->render( x, y, color, work.getBitmap(), ftalleg::freetype::ftLeft, string( buf ) );
+}
+
+void FreeTypeFont::setSize( const int x, const int y ){
+ this->sizeX = x;
+ this->sizeY = y;
+ this->font->setSize( this->sizeX, this->sizeY );
+}
+
+const int FreeTypeFont::getSizeX() const {
+ return this->sizeX;
+}
+
+const int FreeTypeFont::getSizeY() const {
+ return this->sizeY;
}
-const Font getDefaultFont(){
- return Font( font );
+FreeTypeFont::~FreeTypeFont(){
+ // cout << "Delete font " << this->font << endl;
+ delete this->font;
}
diff --git a/util/font.h b/util/font.h
index 59f1584c..9e4048d8 100644
--- a/util/font.h
+++ b/util/font.h
@@ -1,26 +1,80 @@
#ifndef _paintown_font_h
#define _paintown_font_h
struct FONT;
+#include <string>
+#include <vector>
+#include "ftalleg.h"
+#include "bitmap.h"
+
+using namespace std;
+
+/* handle allegro fonts and true type fonts */
class Font{
public:
- Font( FONT * f );
- Font( const Font & f );
+ Font();
+ virtual ~Font();
- inline FONT * getInternalFont() const{
- return my_font;
- }
+ virtual void setSize( const int x, const int y ) = 0;
+ virtual const int getSizeX() const = 0;
+ virtual const int getSizeY() const = 0;
+
+ virtual const int textLength( const char * text ) const = 0;
+
+ virtual const int getHeight() const = 0;
+
+ virtual void printf( int x, int y, int color, const Bitmap & work, const string & str, ... ) const = 0;
+
+ static const Font & getDefaultFont();
+ static const Font & getFont( const string & name, const int x = 32, const int y = 32 );
+
+ /* store all the freetype fonts forever */
+ static vector< ftalleg::freetype * > cacheFreeType;
+};
+
+class AllegroFont: public Font {
+public:
+ AllegroFont( const FONT * const font );
+ AllegroFont( const AllegroFont & copy );
+ virtual ~AllegroFont();
+
+ virtual const int getHeight() const;
+ virtual const int textLength( const char * text ) const;
+
+ virtual void printf( int x, int y, int color, const Bitmap & work, const string & str, ... ) const;
- const int textLength( const char * text ) const;
+ virtual void setSize( const int x, const int y );
+ virtual const int getSizeX() const;
+ virtual const int getSizeY() const;
- const int getHeight() const;
+private:
+ inline const FONT * const getInternalFont() const{
+ return font;
+ }
-protected:
- FONT * my_font;
+ const FONT * const font;
};
-const Font getFont( int index );
-const Font getDefaultFont();
+class FreeTypeFont: public Font {
+public:
+ FreeTypeFont( const string & filename );
+ FreeTypeFont( const FreeTypeFont & copy );
+ virtual ~FreeTypeFont();
+
+ virtual const int getHeight() const;
+ virtual const int textLength( const char * text ) const;
+
+ virtual void printf( int x, int y, int color, const Bitmap & work, const string & str, ... ) const;
+
+ virtual void setSize( const int x, const int y );
+ virtual const int getSizeX() const;
+ virtual const int getSizeY() const;
+
+private:
+ ftalleg::freetype * font;
+ int sizeX;
+ int sizeY;
+};
#endif
diff --git a/util/ftalleg.cpp b/util/ftalleg.cpp
new file mode 100644
index 00000000..1e97ce65
--- /dev/null
+++ b/util/ftalleg.cpp
@@ -0,0 +1,420 @@
+/*
+--------------
+About
+--------------
+A Freetype wrapper for use with allegro
+Feel free to do whatever you like with this, by all means enjoy!
+Just add it to your project
+
+--------------
+Linking
+--------------
+on linux:
+g++ `freetype-config --cflags` ftalleg.cpp myfiles.cpp `freetype-config --libs` `allegro-config --libs`
+
+on windows (you may need to include the freetype dir location, ie -Ic:/mingw/include):
+g++ ftalleg.cpp myfiles.cpp -lfreetype -lalleg
+
+--------------
+Disclaimer
+--------------
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
+INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE,
+TITLE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE
+SOFTWARE BE LIABLE FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+*/
+
+#ifndef FT_FONT_CPP
+#define FT_FONT_CPP
+
+#include "ftalleg.h"
+#include <allegro.h>
+#include <iostream>
+#include <sstream>
+#include <cassert>
+
+namespace ftalleg{
+
+ static int fixColor(const unsigned char *c,short grays){
+ // Safety checks
+ assert(c != 0);
+ assert(grays != 1);
+
+ // invariant: c can be dereferenced safely
+ // invariant: (grays - 1) != 0, thus it can be used as divisor.
+
+ int red = *c * 255 / (grays - 1);
+ int green = *c * 255 / (grays - 1);
+ int blue = *c * 255 / (grays - 1);
+ //alpha = *c * 255 / (grays - 1);
+ return makecol(red,green,blue);
+ }
+ // Static count of instances of fonts to track library
+ static int instances=0;
+ static FT_Library ftLibrary = 0;
+
+ character::character() {
+ }
+
+ character::~character() {
+ //if(line)delete [] line;
+ }
+
+ fontSize::fontSize() {
+ width = height = italics = 0;
+ }
+
+ fontSize::~fontSize() {
+ }
+
+ bool fontSize::operator<(const fontSize &fs) const {
+ return (width<fs.width || height<fs.height || italics<fs.italics);
+ }
+
+ int fontSize::createKey(){
+ return ((width+10) * (height+20) * (italics+250));
+ }
+
+ //! Constructor
+ freetype::freetype( const std::string & str, const int x, const int y ){
+ //Load library
+ if(!ftLibrary){
+ FT_Init_FreeType(&ftLibrary);
+ instances++;
+ }
+ faceLoaded = kerning = false;
+ currentIndex=0;
+ currentFilename="";
+ faceName="";
+ currentChar = new character;
+ systemName="";
+ internalFix = false;
+
+ this->load( str, 0, x, y );
+ }
+
+ //! Destructor
+ freetype::~freetype(){
+
+ //if(face!=NULL)FT_Done_Face(face);
+
+ if ( instances>0 ){
+ instances--;
+ }
+ if ( instances==0 ){
+ FT_Done_FreeType(ftLibrary);
+ }
+
+ if ( currentChar ){
+ delete currentChar;
+ }
+ }
+
+ // Extract glyph
+ character freetype::extractGlyph(signed long unicode){
+ int w, h, ew;
+ character tempChar;
+
+ // Translate it according to the given italics
+ double italics = (double)(size.italics)*GLYPH_PI/180;
+
+ FT_Matrix matrix;
+ matrix.xx = 0x10000L;
+ matrix.xy = (FT_Fixed)( sin( italics ) * (GLYPH_SQRT2*0x10000L) );
+ matrix.yx = 0;
+ matrix.yy = 0x10000L;
+ FT_Set_Transform( face, &matrix, 0 );
+
+ FT_Load_Char(face, unicode, FT_LOAD_TARGET_NORMAL | FT_LOAD_RENDER | FT_LOAD_FORCE_AUTOHINT);
+
+ w = face->glyph->bitmap.width;
+ h = face->glyph->bitmap.rows;
+ ew = 0;
+ if (!w)ew = 1;
+ if (!h)h = 1;
+
+ tempChar.width = (w + ew);
+ tempChar.height = h;
+
+ tempChar.rows = face->glyph->bitmap.rows;
+ tempChar.grays = face->glyph->bitmap.num_grays;
+ tempChar.pitch = face->glyph->bitmap.pitch;
+ tempChar.line = new unsigned char[tempChar.rows * tempChar.pitch];
+ memcpy(tempChar.line,face->glyph->bitmap.buffer,tempChar.rows * tempChar.pitch);
+
+ tempChar.left = face->glyph->bitmap_left;
+ tempChar.top = face->glyph->bitmap_top;
+ tempChar.right = face->glyph->advance.x >> 6;
+ tempChar.unicode = unicode;
+
+ tempChar.length = (w + ew)+face->glyph->advance.x >> 6;
+
+ return tempChar;
+ }
+
+ // Create single index
+ void freetype::createIndex(){
+ std::map<int, std::map<signed long, character> >::iterator p;
+ p = fontTable.find(size.createKey());
+ if ( p == fontTable.end() ){
+ FT_Set_Pixel_Sizes(face, size.width, size.height);
+
+ FT_UInt g;
+
+ FT_ULong unicode = FT_Get_First_Char(face, &g);
+ std::map<signed long, character>tempMap;
+ while ( g ){
+ tempMap.insert(std::make_pair(unicode,extractGlyph(unicode)));
+ unicode = FT_Get_Next_Char(face, unicode, &g);
+ }
+
+ fontTable.insert(std::make_pair(size.createKey(),tempMap));
+ }
+ }
+
+ // Render a character from the lookup table
+ void freetype::drawCharacter(signed long unicode, int &x1, int &y1, BITMAP *bitmap, const int &color){
+
+ std::map<int, std::map<signed long, character> >::iterator ft;
+ ft = fontTable.find(size.createKey());
+ if ( ft!=fontTable.end() ){
+ std::map<signed long, character>::iterator p;
+ p = (ft->second).find(unicode);
+ if(p!=(ft->second).end())
+ {
+ character tempChar = p->second;
+
+ unsigned char *line = tempChar.line;
+ for (int y = 0; y < tempChar.rows; y++)
+ {
+ unsigned char *buffer = line;
+ for (int x = 0; x < tempChar.width; x++)
+ {
+ int col = fixColor(buffer++,tempChar.grays);
+
+ if((getr(col)< 50) || (getg(col)< 50) || (getb(col)< 50))continue;
+ int red = getr(col) * getr(color) / 255;
+ int green = getg(col) * getg(color) / 255;
+ int blue = getb(col) * getb(color) / 255;
+
+ //col.alpha= col.alpha * color.alpha / 255;
+ putpixel(bitmap,x1+tempChar.left+x,y1 - tempChar.top+y + size.height,makecol(red,blue,green));
+ }
+ line += tempChar.pitch;
+ }
+ x1+=tempChar.right;
+ }
+ }
+ }
+
+ //! Load font from memory
+ bool freetype::load(const unsigned char *memoryFont, unsigned int length, int index, unsigned int width, unsigned int height)
+ {
+ if(!FT_New_Memory_Face(ftLibrary,memoryFont, length,index,&face))
+ {
+ currentFilename = "memoryFont";
+ currentIndex = index;
+ faceLoaded = true;
+ size.italics = 0;
+ setSize(width, height);
+ if(FT_HAS_GLYPH_NAMES(face))
+ {
+ char buff[1024];
+ if(!FT_Get_Glyph_Name(face,currentIndex,buff,sizeof(buff)))
+ {
+ faceName = currentFilename;
+ }
+ else faceName = std::string(buff);
+ }
+ else
+ {
+ faceName = currentFilename;
+ }
+ if(FT_HAS_KERNING(face))kerning=true;
+ else kerning = false;
+ }
+ else
+ {
+ faceLoaded=false;
+ std::cout << "Load system font failed\n";
+ }
+
+ return faceLoaded;
+ }
+
+ //! Load font from file
+ bool freetype::load(const std::string & filename, int index, unsigned int width, unsigned int height)
+ {
+ if(!FT_New_Face(ftLibrary,filename.c_str(),index,&face))
+ {
+ currentFilename = filename;
+ currentIndex = index;
+ faceLoaded = true;
+ size.italics = 0;
+ setSize(width, height);
+ if(FT_HAS_GLYPH_NAMES(face))
+ {
+ char buff[1024];
+ if(!FT_Get_Glyph_Name(face,currentIndex,buff,sizeof(buff)))
+ {
+ faceName = currentFilename;
+ }
+ else faceName = std::string(buff);
+ }
+ else
+ {
+ faceName = currentFilename;
+ }
+ if(FT_HAS_KERNING(face))kerning=true;
+ else kerning = false;
+ }
+ else
+ {
+ faceLoaded=false;
+ }
+
+ return faceLoaded;
+ }
+
+ //! Get text length
+ int freetype::getLength(const std::string & text)
+ {
+ int length=0;
+ std::map<int, std::map<signed long, character> >::iterator ft;
+ ft = fontTable.find(size.createKey());
+ if(ft!=fontTable.end())
+ {
+ for(unsigned int i = 0; i<text.length();++i)
+ {
+ std::map<signed long, character>::iterator p;
+ p = (ft->second).find(text[i]);
+ if(p!=(ft->second).end())
+ {
+ if(p!=fontTable[size.createKey()].end())
+ {
+ length+=(p->second).length;
+ }
+ }
+ }
+ }
+ return length;
+ }
+
+ //! Render font to a bitmap
+ void freetype::render(int x, int y, const int & color, BITMAP *bmp, ftAlign alignment, const std::string & text, ...)
+ {
+ if(faceLoaded)
+ {
+ int rend_x=0;
+ int rend_y=0;
+ std::ostringstream str;
+
+ // Get extra arguments
+ va_list ap;
+ va_start(ap,text);
+ for(unsigned int i = 0; i<text.length();++i)
+ {
+ if(text[i]=='%')
+ {
+ if(text[i+1]=='s')
+ {
+ str << va_arg(ap,char *);
+ ++i;
+ }
+ else if(text[i+1]=='d'||text[i+1]=='i')
+ {
+ str << va_arg(ap,signed int);
+ ++i;
+ }
+ else if(text[i+1]=='c')
+ {
+ str << (char)va_arg(ap,int);
+ ++i;
+ }
+ else str << text[i];
+ }
+ else
+ {
+ str << text[i];
+ }
+ }
+ va_end(ap);
+
+ std::string fixedText(str.str());
+ switch(alignment)
+ {
+ case ftLeft:
+ rend_x=x;
+ rend_y=y;
+ break;
+ case ftCenter:
+ rend_x = x - getLength(fixedText)/2;
+ rend_y=y;
+ break;
+ case ftRight:
+ rend_x = x - getLength(fixedText);
+ rend_y=y;
+ break;
+ default:
+ rend_x=x;
+ rend_y=y;
+ break;
+ }
+ int previous = 0;
+ int next = 0;
+ for(unsigned int i = 0; i<fixedText.length();++i)
+ {
+ if(kerning && previous && next)
+ {
+ next = FT_Get_Char_Index( face, fixedText[i] );
+ FT_Vector delta;
+ FT_Get_Kerning( face, previous, next, FT_KERNING_DEFAULT, &delta );
+ rend_x += delta.x >> 6;
+ previous = next;
+ }
+ drawCharacter(fixedText[i],rend_x, rend_y, bmp, color);
+ }
+ }
+ }
+
+ //! Set size
+ void freetype::setSize(int w, int h)
+ {
+ if(internalFix)return;
+ if(w<=0 || h<=0)return;
+ size.width=w;
+ size.height=h;
+ createIndex();
+ }
+
+ //! Set italics
+ void freetype::setItalics(int i)
+ {
+ if(internalFix)return;
+ if(i<-45)i=(-45);
+ else if(i>45)i=45;
+ size.italics = i;
+ createIndex();
+ }
+
+ //! Get Width
+ int freetype::getWidth()
+ {
+ return size.width;
+ }
+
+ //! Get Height
+ int freetype::getHeight()
+ {
+ return size.height;
+ }
+
+ //! Get Italics
+ int freetype::getItalics()
+ {
+ return size.italics;
+ }
+}
+
+#endif /* FONT_BASE_CPP */
diff --git a/util/ftalleg.h b/util/ftalleg.h
new file mode 100644
index 00000000..6f671cb4
--- /dev/null
+++ b/util/ftalleg.h
@@ -0,0 +1,206 @@
+/*
+--------------
+About
+--------------
+A Freetype wrapper for use with allegro
+Feel free to do whatever you like with this, by all means enjoy!
+Just add it to your project
+
+--------------
+Linking
+--------------
+on linux:
+g++ `freetype-config --cflags` ftalleg.cpp myfiles.cpp `freetype-config --libs` `allegro-config --libs`
+
+on windows (you may need to include the freetype dir location, ie -Ic:/mingw/include):
+g++ ftalleg.cpp myfiles.cpp -lfreetype -lalleg
+
+--------------
+Disclaimer
+--------------
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
+INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE,
+TITLE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE
+SOFTWARE BE LIABLE FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+*/
+
+#ifndef FT_FONT_H
+#define FT_FONT_H
+
+// #include <allegro.h>
+#include <map>
+#include <string>
+#include <math.h>
+#include <ft2build.h>
+#include FT_FREETYPE_H
+
+#define GLYPH_PI 3.14159265358979323846
+#define GLYPH_SQRT2 1.41421356237309504880
+
+class BITMAP;
+namespace ftalleg
+{
+ //! Internal class for freetype to use
+ /*!
+ * This holds necessary information regarding a character \n
+ * from Freetype.
+ */
+ class character
+ {
+ public:
+ //! Constructor
+ character();
+
+ //! Destructor
+ ~character();
+
+ //! Unicode representation of character
+ signed long unicode;
+
+ //! Width of character
+ int width;
+
+ //! Height of character
+ int height;
+
+ //! Space on the left of a character (assists on positioning the character)
+ int left;
+
+ //! Space on top of the character (assists on positioning the character)
+ int top;
+
+ //! Space on the right of a character (assists on positioning the character)
+ int right;
+
+ //! Pitch of a character (assists on positioning the character)
+ int pitch;
+
+ //! Amount of shades of grays the FT_Bitmap holds
+ int grays;
+
+ //! Entire rows of the FT_Bitmap
+ int rows;
+
+ //! Entire length of the character with spacing and all
+ int length;
+
+ //! FT_Bitmap raw data
+ unsigned char *line;
+ };
+
+ //! Internal class for freetype to use
+ /*!
+ * Properties used for indexing a given font according to its size and matrix \n
+ */
+ class fontSize
+ {
+ public:
+ fontSize();
+ ~fontSize();
+ FT_UInt width;
+ FT_UInt height;
+ int italics;
+ int angle;
+
+ bool operator<(const fontSize &fs) const;
+
+ int createKey();
+ };
+
+ //! Freetype based font system
+ /*!
+ * Allows us to use freetype in allegro
+ */
+ class freetype
+ {
+ private:
+ //! Filename
+ std::string currentFilename;
+
+ //! Is the face loaded
+ bool faceLoaded;
+
+ //! Does the face have kerning
+ bool kerning;
+
+ //! Current index default 0
+ int currentIndex;
+
+ //! for internal use disregard
+ bool internalFix;
+
+ //! Font size
+ fontSize size;
+
+ //! Current Set system name
+ std::string systemName;
+
+ //! Face
+ FT_Face face;
+
+ //! Face Name
+ std::string faceName;
+
+ //! Current character
+ character *currentChar;
+
+ //! Lookup Table by size
+ std::map<int, std::map<signed long, character> >fontTable;
+
+ //! Extract glyph
+ character extractGlyph(signed long unicode);
+
+ //! Create single index
+ void createIndex();
+
+ //! Render a character from the lookup table (utilizing the workBitmap)
+ void drawCharacter(signed long unicode, int &x1, int &y1, BITMAP *bitmap, const int & color);
+
+ public:
+ //! Constructor
+ freetype::freetype( const std::string & str, const int x, const int y );
+
+ //! Destructor
+ ~freetype();
+
+ //! Enum list of alignments
+ enum ftAlign
+ {
+ ftLeft = 0,
+ ftCenter = 1,
+ ftRight = 2
+ };
+
+ //! Load font from memory
+ bool load(const unsigned char *memoryFont, unsigned int length, int index, unsigned int width, unsigned int height);
+
+ //! Load font from file
+ bool load(const std::string & filename, int index, unsigned int width, unsigned int height);
+
+ //! Get text length
+ int getLength(const std::string & text);
+
+ //! Render font to a bitmap
+ void render(int x, int y, const int & color, BITMAP *bmp, ftAlign alignment, const std::string & text, ...);
+
+ //! Set size
+ void setSize(int w, int h);
+
+ //! Set italics
+ void setItalics(int i);
+
+ //! Get Width
+ int getWidth();
+
+ //! Get Height
+ int getHeight();
+
+ //! Get Italics
+ int getItalics();
+ };
+
+}
+
+
+#endif /* FT_FONT_H */
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Thu, Jun 11, 2:18 PM (3 w, 4 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
69427
Default Alt Text
(43 KB)
Attached To
Mode
R75 R-Tech1
Attached
Detach File
Event Timeline