Code clean up and refactoring.

Removed HaikuTTF from the project.

--HG--
branch : dev
This commit is contained in:
Martí­n Lucas Golini
2017-03-17 23:17:21 -03:00
parent 0a71104127
commit c0975dd80d
26 changed files with 30 additions and 1333 deletions

View File

@@ -449,7 +449,7 @@ void TileMap::update() {
mLightManager->update();
for ( Uint32 i = 0; i < mLayerCount; i++ )
mLayers[i]->update( Engine::instance()->getElapsed() );
mLayers[i]->update( mWindow->getElapsed() );
if ( mUpdateCb.IsSet() )
mUpdateCb();

View File

@@ -363,7 +363,7 @@ void ParticleSystem::draw() {
}
void ParticleSystem::update() {
update( Engine::instance()->getElapsed() );
update( Engine::instance()->getCurrentWindow()->getElapsed() );
}
void ParticleSystem::update( const System::Time& time ) {

View File

@@ -482,7 +482,7 @@ bool Sprite::addSubFrame(const Uint32& TexId, const unsigned int& NumFrame, cons
}
void Sprite::update() {
update( Engine::instance()->getElapsed() );
update( Engine::instance()->getCurrentWindow()->getElapsed() );
}
void Sprite::update( const Time& ElapsedTime ) {

View File

@@ -1,9 +0,0 @@
#ifndef HAIKUTTF_HPP
#define HAIKUTTF_HPP
#include "hkbase.hpp"
#include "hkglyph.hpp"
#include "hkfont.hpp"
#include "hkfontmanager.hpp"
#endif

View File

@@ -1,94 +0,0 @@
#ifndef HAIKUTTF_HKBASE_HPP
#define HAIKUTTF_HKBASE_HPP
namespace HaikuTTF {
typedef signed char s8;
typedef unsigned char u8;
typedef signed short s16;
typedef unsigned short u16;
typedef signed int s32;
typedef unsigned int u32;
}
#define HK_PLATFORM_WIN (1)
#define HK_PLATFORM_LINUX (2)
#define HK_PLATFORM_MACOSX (3)
#define HK_PLATFORM_BSD (4)
#define HK_PLATFORM_SOLARIS (5)
#define HK_PLATFORM_HAIKU (6)
#if defined( __WIN32__ ) || defined( _WIN32 ) || defined( _WIN64 )
#define HK_PLATFORM HK_PLATFORM_WIN
#elif defined( __APPLE_CC__ ) || defined ( __APPLE__ )
#define HK_PLATFORM HK_PLATFORM_MACOSX
#elif defined ( linux ) || defined( __linux__ )
#define HK_PLATFORM HK_PLATFORM_LINUX
#elif defined( __FreeBSD__ ) || defined(__OpenBSD__) || defined( __NetBSD__ ) || defined( __DragonFly__ )
#define HK_PLATFORM HK_PLATFORM_BSD
#elif defined( __SVR4 )
#define HK_PLATFORM HK_PLATFORM_SOLARIS
#elif defined( __HAIKU__ ) || defined( __BEOS__ )
#define HK_PLATFORM HK_PLATFORM_HAIKU
#endif
#if defined ( linux ) || defined( __linux__ ) || defined( __FreeBSD__ ) || defined(__OpenBSD__) || defined( __NetBSD__ ) || defined( __DragonFly__ ) || defined( __SVR4 ) || defined( __APPLE_CC__ ) || defined ( __APPLE__ ) || defined( __HAIKU__ ) || defined( __BEOS__ ) || defined( __emscripten__ ) || defined( EMSCRIPTEN )
#define HK_PLATFORM_POSIX
#endif
#define NUM_GRAYS 256
#define FT_FLOOR(X) ( ( X & -64 ) / 64 )
#define FT_CEIL(X) ( ( ( X + 63) & -64 ) / 64 )
#define CACHED_METRICS 0x10
#define CACHED_BITMAP 0x01
#define CACHED_PIXMAP 0x02
#define HK_TTF_STYLE_NORMAL (0x00)
#define HK_TTF_STYLE_BOLD (0x01)
#define HK_TTF_STYLE_ITALIC (0x02)
#define HK_TTF_STYLE_UNDERLINE (0x04)
#define HK_TTF_STYLE_STRIKETHROUGH (0x08)
#define HK_TTF_HINTING_NORMAL (0)
#define HK_TTF_HINTING_LIGHT (1)
#define HK_TTF_HINTING_MONO (2)
#define HK_TTF_HINTING_NONE (3)
#define HK_TTF_HANDLE_STYLE_BOLD(font) ( ( (font)->style() & HK_TTF_STYLE_BOLD ) && !( (font)->faceStyle() & HK_TTF_STYLE_BOLD ) )
#define HK_TTF_HANDLE_STYLE_ITALIC(font) ( ( (font)->style() & HK_TTF_STYLE_ITALIC ) && !( (font)->faceStyle() & HK_TTF_STYLE_ITALIC ) )
#define HK_TTF_HANDLE_STYLE_UNDERLINE(font) ( (font)->style() & HK_TTF_STYLE_UNDERLINE )
#define HK_TTF_HANDLE_STYLE_STRIKETHROUGH(font) ( (font)->style() & HK_TTF_STYLE_STRIKETHROUGH )
#define HK_TTF_STYLE_NO_GLYPH_CHANGE ( HK_TTF_STYLE_UNDERLINE | HK_TTF_STYLE_STRIKETHROUGH )
#ifndef hkNew
#define hkNew( classType, constructor ) new classType constructor
#endif
#ifndef hkNewArray
#define hkNewArray( classType, amount ) new classType [ amount ]
#endif
#ifndef hkMalloc
#define hkMalloc( amount ) malloc( amount )
#endif
#ifndef hkDelete
#define hkDelete( data ) delete data;
#endif
#ifndef hkDeleteArray
#define hkDeleteArray( data ) delete [] data;
#endif
#ifndef hkFree
#define hkFree( data ) free(data);
#endif
#define hkARRAY_SIZE(__array) ( sizeof(__array) / sizeof(__array[0]) )
#define hkSAFE_DELETE(p) { if(p) { hkDelete (p); (p)=NULL; } }
#define hkSAFE_FREE(p) { if(p) { hkFree (p); (p)=NULL; } }
#define hkSAFE_DELETE_ARRAY(p) { if(p) { hkDeleteArray(p); (p)=NULL; } }
#endif

View File

@@ -1,521 +0,0 @@
#include "hkfont.hpp"
#include "hkfontmanager.hpp"
#include <cmath>
namespace HaikuTTF {
hkFont::hkFont( hkFontManager * FontManager, unsigned int CacheSize ) :
mFm( FontManager ),
mCache(NULL),
mFace(NULL),
mHeight(0),
mAscent(0),
mDescent(0),
mLineSkip(0),
mFaceStyle(0),
mKerning(0),
mGlyphOverhang(0),
mGlyphItalics(0),
mUnderlineOffset(0),
mUnderlineHeight(0),
mCurrent(NULL),
mFontSizeFamily(0),
mStyle(0),
mOutline(0),
mHinting(0)
{
mCacheSize = CacheSize;
mCache = hkNewArray( hkGlyph, mCacheSize );
}
hkFont::~hkFont() {
cacheFlush();
if ( NULL != mFace ) {
FT_Done_Face( mFace );
mFace = NULL;
}
hkSAFE_DELETE_ARRAY( mCache );
}
void hkFont::outline( int outline ) {
mOutline = outline;
cacheFlush();
}
void hkFont::hinting( int hinting ) {
if ( hinting == HK_TTF_HINTING_LIGHT )
mHinting = FT_LOAD_TARGET_LIGHT;
else if ( hinting == HK_TTF_HINTING_MONO )
mHinting= FT_LOAD_TARGET_MONO;
else if ( hinting == HK_TTF_HINTING_NONE )
mHinting = FT_LOAD_NO_HINTING;
else
mHinting = 0;
cacheFlush();
}
void hkFont::style( int style ) {
int prev_style = mFaceStyle;
mStyle = style | mFaceStyle;
if ( ( mStyle | HK_TTF_STYLE_NO_GLYPH_CHANGE ) != ( prev_style | HK_TTF_STYLE_NO_GLYPH_CHANGE ) )
cacheFlush();
}
int hkFont::underlineTopRow() {
return mAscent - mUnderlineOffset - 1;
}
int hkFont::strikeThroughTopRow() {
return mHeight / 2;
}
void hkFont::cacheFlush() {
for( int i = 0; i < (int)mCacheSize; ++i ) {
if( mCache[i].cached() )
mCache[i].flush();
}
if( mScratch.cached() )
mScratch.flush();
}
FT_Error hkFont::findGlyph(u32 ch, int want ) {
int retval = 0;
if( ch < mCacheSize ) {
mCurrent = &mCache[ch];
} else {
if ( mScratch.cached() != ch )
mScratch.flush();
mCurrent = &mScratch;
}
if ( ( mCurrent->stored() & want) != want )
retval = loadGlyph( ch, mCurrent, want );
return retval;
}
FT_Error hkFont::loadGlyph(u32 ch, hkGlyph * cached, int want ) {
FT_Face face;
FT_Error error;
FT_GlyphSlot glyph;
FT_Glyph_Metrics* metrics;
FT_Outline* outline;
if ( NULL == mFace )
return FT_Err_Invalid_Handle;
face = mFace;
mFm->mutexLock();
if ( !cached->index() )
cached->index( FT_Get_Char_Index( face, ch ) );
error = FT_Load_Glyph( face, cached->index(), FT_LOAD_DEFAULT | mHinting );
if( error )
return error;
glyph = face->glyph;
metrics = &glyph->metrics;
outline = &glyph->outline;
if ( ( want & CACHED_METRICS ) && !( cached->stored() & CACHED_METRICS ) ) {
if ( FT_IS_SCALABLE( face ) ) {
cached->minX( FT_FLOOR( metrics->horiBearingX ) );
cached->maxX( cached->minX() + FT_CEIL( metrics->width ) );
cached->maxY( FT_FLOOR( metrics->horiBearingY ) );
cached->minY( cached->maxY() - FT_CEIL( metrics->height ) );
cached->offsetY( mAscent - cached->maxY() );
cached->advance( FT_CEIL( metrics->horiAdvance ) );
} else {
cached->minX( FT_FLOOR( metrics->horiBearingX ) );
cached->maxX( cached->minX() + FT_CEIL( metrics->horiAdvance ) );
cached->maxY( FT_FLOOR( metrics->horiBearingY ) );
cached->minY( cached->maxY() - FT_CEIL( face->available_sizes[ mFontSizeFamily ].height ) );
cached->offsetY( 0 );
cached->advance( FT_CEIL( metrics->horiAdvance ) );
}
if( HK_TTF_HANDLE_STYLE_BOLD(this) )
cached->maxX( cached->maxX() + mGlyphOverhang );
if( HK_TTF_HANDLE_STYLE_ITALIC(this) )
cached->maxX( cached->maxX() + (int)ceil( mGlyphItalics ) );
cached->stored( cached->stored() | CACHED_METRICS );
}
if ( ( want & CACHED_PIXMAP ) && !( cached->stored() & CACHED_PIXMAP) ) {
int mono = ( want & CACHED_BITMAP );
int i;
FT_Bitmap* src;
FT_Bitmap* dst;
FT_Glyph bitmap_glyph = NULL;
if( HK_TTF_HANDLE_STYLE_ITALIC(this) ) {
FT_Matrix shear;
shear.xx = 1 << 16;
shear.xy = (int) ( mGlyphItalics * ( 1 << 16 ) ) / mHeight;
shear.yx = 0;
shear.yy = 1 << 16;
FT_Outline_Transform( outline, &shear );
}
if( ( mOutline > 0 ) && glyph->format != FT_GLYPH_FORMAT_BITMAP ) {
FT_Stroker stroker;
FT_Get_Glyph( glyph, &bitmap_glyph );
error = FT_Stroker_New( mFm->getLibrary(), &stroker );
if( error )
return error;
FT_Stroker_Set( stroker, mOutline * 64, FT_STROKER_LINECAP_ROUND, FT_STROKER_LINEJOIN_ROUND, 0 );
FT_Glyph_Stroke( &bitmap_glyph, stroker, 1 );
FT_Stroker_Done( stroker );
error = FT_Glyph_To_Bitmap( &bitmap_glyph, mono ? ft_render_mode_mono : ft_render_mode_normal, 0, 1 );
if( error ) {
FT_Done_Glyph( bitmap_glyph );
return error;
}
src = &((FT_BitmapGlyph)bitmap_glyph)->bitmap;
} else {
error = FT_Render_Glyph( glyph, mono ? ft_render_mode_mono : ft_render_mode_normal );
if( error )
return error;
src = &glyph->bitmap;
}
dst = cached->pixmap();
memcpy( dst, src, sizeof( *dst ) );
if( HK_TTF_HANDLE_STYLE_BOLD(this) ) {
int bump = mGlyphOverhang;
dst->pitch += bump;
dst->width += bump;
}
if( HK_TTF_HANDLE_STYLE_ITALIC(this) ) {
int bump = (int)ceil( mGlyphItalics );
dst->pitch += bump;
dst->width += bump;
}
if (dst->rows != 0) {
dst->buffer = (unsigned char*)hkMalloc( dst->pitch * dst->rows );
if( !dst->buffer ) {
return FT_Err_Out_Of_Memory;
}
memset( dst->buffer, 0, dst->pitch * dst->rows );
for( i = 0; i < src->rows; i++ ) {
int soffset = i * src->pitch;
int doffset = i * dst->pitch;
memcpy( dst->buffer+doffset, src->buffer+soffset, src->pitch );
}
}
if ( HK_TTF_HANDLE_STYLE_BOLD(this) ) {
int row;
int col;
int offset;
int pixel;
u8* pixmap;
for( row = dst->rows - 1; row >= 0; --row ) {
pixmap = (u8*) dst->buffer + row * dst->pitch;
for( offset=1; offset <= mGlyphOverhang; ++offset ) {
for( col = dst->width - 1; col > 0; --col ) {
pixel = (pixmap[col] + pixmap[col-1]);
if( pixel > NUM_GRAYS - 1 ) {
pixel = NUM_GRAYS - 1;
}
pixmap[col] = (u8) pixel;
}
}
}
}
cached->stored( cached->stored() | CACHED_PIXMAP );
if( bitmap_glyph ) {
FT_Done_Glyph( bitmap_glyph );
}
}
mFm->mutexUnlock();
cached->cached( ch );
return 0;
}
unsigned char * hkFont::renderGlyph(u32 ch, u32 fg ) {
unsigned char * textbuf = NULL;
int row;
FT_Error error;
hkGlyph *glyph;
FT_Bitmap * bitmap;
error = findGlyph( ch, CACHED_METRICS | CACHED_PIXMAP );
if ( error )
return(NULL);
glyph = mCurrent;
bitmap = glyph->pixmap();
textbuf = hkNewArray( unsigned char, bitmap->width * bitmap->rows * 4 );
if ( NULL == textbuf )
return NULL;
u32 * buffu32 = reinterpret_cast<u32*> ( &textbuf[0] );
memset( buffu32, fg, bitmap->width * bitmap->rows * 4 );
const u8* pixels = bitmap->buffer;
u32 index;
for ( int y = 0; y < bitmap->rows; y++ ) {
for ( int x = 0; x < bitmap->width; x++ ) {
index = (x + y * bitmap->width) * 4 + 3;
textbuf[ index ] = pixels[ x ];
}
pixels += bitmap->pitch;
}
if( HK_TTF_HANDLE_STYLE_UNDERLINE(this) ) {
row = underlineTopRow();
drawLine( textbuf, row, fg, bitmap );
}
if( HK_TTF_HANDLE_STYLE_STRIKETHROUGH(this) ) {
row = strikeThroughTopRow();
drawLine( textbuf, row, fg, bitmap );
}
return textbuf;
}
int hkFont::getGlyphMetrics(u32 ch, int* minx, int* maxx, int* miny, int* maxy, int* advance ) {
FT_Error error;
error = findGlyph( ch, CACHED_METRICS );
if ( error )
return -1;
if ( NULL != minx )
*minx = mCurrent->minX() - mOutline;
if ( NULL !=maxx ) {
*maxx = mCurrent->maxX() + mOutline;
if( HK_TTF_HANDLE_STYLE_BOLD(this) )
*maxx += mGlyphOverhang;
}
if ( NULL !=miny )
*miny = mCurrent->minY() - mOutline;
if ( NULL !=maxy )
*maxy = mCurrent->maxY() + mOutline;
if ( NULL != advance ) {
*advance = mCurrent->advance() + mOutline;
if( HK_TTF_HANDLE_STYLE_BOLD(this) )
*advance += mGlyphOverhang;
}
return 0;
}
void hkFont::initLineMectrics( const unsigned char * textbuf, const int row, u8 **pdst, int *pheight, FT_Bitmap * bitmap ) {
u8 *dst;
int height;
dst = (u8 *)textbuf;
if( row > 0 )
dst += row * bitmap->pitch;
height = mUnderlineHeight;
if( mOutline > 0 )
height += mOutline * 2;
*pdst = dst;
*pheight = height;
}
void hkFont::drawLine( const unsigned char * textbuf, const int row, const u32 color, FT_Bitmap * bitmap ) {
int line;
u32 * dst_check = (u32*)textbuf + bitmap->pitch / 4 * bitmap->rows;
u8 * dst8; /* destination, byte version */
u32 * dst;
int height;
int col;
u32 pixel = color | 0xFF000000;
initLineMectrics( textbuf, row, &dst8, &height, bitmap );
dst = (u32 *) dst8;
for ( line = height; line > 0 && dst < dst_check; --line ) {
for ( col = 0; col < bitmap->width; ++col )
dst[col] = pixel;
dst += bitmap->pitch / 4;
}
}
void hkFont::face( FT_Face face ) {
mFace = face;
}
FT_Face hkFont::face() {
return mFace;
}
void hkFont::height( int height ) {
mHeight = height;
}
int hkFont::height() {
return mHeight + mOutline;
}
void hkFont::ascent( int ascent ) {
mAscent = ascent;
}
int hkFont::ascent() {
return mAscent;
}
void hkFont::descent( int descent ) {
mDescent = descent;
}
int hkFont::descent() {
return mDescent;
}
void hkFont::lineSkip( int lineskip ) {
mLineSkip = lineskip;
}
int hkFont::lineSkip() {
return mLineSkip;
}
void hkFont::faceStyle( int facestyle ) {
mFaceStyle = facestyle;
}
int hkFont::faceStyle() {
return mFaceStyle;
}
void hkFont::kerning( int kerning ) {
mKerning = kerning;
}
int hkFont::kerning() {
return mKerning;
}
void hkFont::glyphOverhang( int glyphoverhang ) {
mGlyphOverhang = glyphoverhang;
}
int hkFont::glyphOverhang() {
return mGlyphOverhang;
}
void hkFont::glyphItalics( float glyphitalics ) {
mGlyphItalics = glyphitalics;
}
float hkFont::glyphItalics() {
return mGlyphItalics;
}
void hkFont::underlineOffset( int underlineoffset ) {
mUnderlineOffset = underlineoffset;
}
int hkFont::underlineOffset() {
return mUnderlineOffset;
}
void hkFont::underlineHeight( int underlineheight ) {
mUnderlineHeight = underlineheight;
}
int hkFont::underlineHeight() {
return mUnderlineHeight;
}
void hkFont::current( hkGlyph * current ) {
mCurrent = current;
}
hkGlyph * hkFont::current() {
return mCurrent;
}
void hkFont::scratch( hkGlyph scratch ) {
mScratch = scratch;
}
hkGlyph hkFont::scratch() {
return mScratch;
}
void hkFont::fontSizeFamily( int fontsizefamily ) {
mFontSizeFamily = fontsizefamily;
}
int hkFont::fontSizeFamily() {
return mFontSizeFamily;
}
int hkFont::outline() const {
return mOutline;
}
int hkFont::hinting() const {
return mHinting;
}
int hkFont::style() {
return mStyle;
}
}

View File

@@ -1,113 +0,0 @@
#ifndef HAIKUTTF_HKFONT_HPP
#define HAIKUTTF_HKFONT_HPP
#include "hkbase.hpp"
#include "hkglyph.hpp"
namespace HaikuTTF {
class hkFontManager;
class hkFont {
public:
hkFont( hkFontManager * FontManager, unsigned int CacheSize = 256 );
~hkFont();
void face( FT_Face face );
FT_Face face();
void height( int height );
int height();
void ascent( int ascent );
int ascent();
void descent( int descent );
int descent();
void lineSkip( int lineskip );
int lineSkip();
void faceStyle( int facestyle );
int faceStyle();
void kerning( int kerning );
int kerning();
void glyphOverhang( int glyphoverhang );
int glyphOverhang();
void glyphItalics( float glyphitalics );
float glyphItalics();
void underlineOffset( int underlineoffset );
int underlineOffset();
void underlineHeight( int underlineheight );
int underlineHeight();
void current( hkGlyph * current );
hkGlyph * current();
void scratch( hkGlyph scratch );
hkGlyph scratch();
void fontSizeFamily( int fontsizefamily );
int fontSizeFamily();
void outline( int outline );
int outline() const;
void hinting( int hinting );
int hinting() const;
void style( int style );
int style();
FT_Error findGlyph( u32 ch, int want );
FT_Error loadGlyph( u32 ch, hkGlyph * cached, int want );
unsigned char * renderGlyph( u32 ch, u32 fg = 0x00000000 );
int getGlyphMetrics( u32 ch, int* minx, int* maxx, int* miny, int* maxy, int* advance );
void cacheFlush();
protected:
friend class hkFontManager;
hkFontManager * mFm;
hkGlyph * mCache;
unsigned int mCacheSize;
FT_Face mFace;
int mHeight;
int mAscent;
int mDescent;
int mLineSkip;
int mFaceStyle;
int mKerning;
int mGlyphOverhang;
float mGlyphItalics;
int mUnderlineOffset;
int mUnderlineHeight;
hkGlyph * mCurrent;
hkGlyph mScratch;
int mFontSizeFamily;
int mStyle;
int mOutline;
int mHinting;
int underlineTopRow();
int strikeThroughTopRow();
void drawLine( const unsigned char * textbuf, const int row, const u32 color, FT_Bitmap * bitmap );
void initLineMectrics( const unsigned char * textbuf, const int row, u8 **pdst, int *pheight, FT_Bitmap * bitmap );
};
}
#endif

View File

@@ -1,189 +0,0 @@
#include "hkfontmanager.hpp"
namespace HaikuTTF {
hkFontManager * hkFontManager::mSingleton = NULL;
hkFontManager * hkFontManager::exists() {
return mSingleton;
}
hkFontManager * hkFontManager::instance() {
if ( mSingleton == NULL ) {
mSingleton = hkNew( hkFontManager, () );
}
return mSingleton;
}
void hkFontManager::destroySingleton() {
hkSAFE_DELETE( mSingleton );
}
hkFontManager::hkFontManager() :
mLibrary(NULL),
mInitialized(0)
{
init();
}
hkFontManager::~hkFontManager() {
destroy();
}
int hkFontManager::init() {
int status = 0;
if ( !mInitialized ) {
FT_Error error = FT_Init_FreeType( &mLibrary );
if ( error )
status = -1;
}
if ( status == 0 )
++mInitialized;
return status;
}
void hkFontManager::destroy() {
if ( mInitialized ) {
if ( --mInitialized == 0 ) {
FT_Done_FreeType( mLibrary );
}
}
}
int hkFontManager::wasInit() {
return mInitialized;
}
void hkFontManager::closeFont( hkFont * Font ) {
hkSAFE_DELETE( Font );
}
hkFont * hkFontManager::openFromMemory( const u8* data, unsigned long size, int ptsize, long index, unsigned int glyphCacheSize ) {
if ( init() != 0 )
return NULL;
FT_Face face = NULL;
mutexLock();
if ( FT_New_Memory_Face( mLibrary, reinterpret_cast<const FT_Byte*>(data), static_cast<FT_Long>(size), index, &face ) != 0 )
return NULL;
if ( FT_Select_Charmap( face, FT_ENCODING_UNICODE ) != 0 )
return NULL;
mutexUnlock();
hkFont * Font = hkNew( hkFont, ( this, glyphCacheSize ) );
Font->face( face );
return fontPrepare( Font, ptsize );
}
hkFont * hkFontManager::openFromFile( const char* filename, int ptsize, long index, unsigned int glyphCacheSize ) {
if ( init() != 0 )
return NULL;
FT_Face face;
mutexLock();
if ( FT_New_Face( mLibrary, filename, index, &face ) != 0 )
return NULL;
if ( FT_Select_Charmap(face, FT_ENCODING_UNICODE) != 0 )
return NULL;
mutexUnlock();
hkFont * Font = hkNew( hkFont, ( this, glyphCacheSize ) );
Font->face( face );
return fontPrepare( Font, ptsize );
}
hkFont * hkFontManager::fontPrepare( hkFont * font, int ptsize ) {
FT_Error error;
FT_Face face;
FT_Fixed scale;
face = font->face();
if ( FT_IS_SCALABLE( face ) ) {
mutexLock();
error = FT_Set_Char_Size( font->face(), 0, ptsize * 64, 0, 0 );
if( error ) {
closeFont( font );
mutexUnlock();
return NULL;
}
mutexUnlock();
scale = face->size->metrics.y_scale;
font->ascent( FT_CEIL( FT_MulFix( face->ascender, scale) ) );
font->descent( FT_CEIL( FT_MulFix( face->descender, scale ) ) );
font->height( font->ascent() - font->descent() + 1 );
font->lineSkip( FT_CEIL( FT_MulFix( face->height, scale ) ) );
font->underlineOffset( FT_FLOOR( FT_MulFix( face->underline_position, scale ) ) );
font->underlineHeight( FT_FLOOR( FT_MulFix( face->underline_thickness, scale ) ) );
} else {
if ( ptsize >= face->num_fixed_sizes )
ptsize = face->num_fixed_sizes - 1;
font->fontSizeFamily( ptsize );
error = FT_Set_Pixel_Sizes( face, face->available_sizes[ptsize].height, face->available_sizes[ptsize].width );
font->ascent( face->available_sizes[ptsize].height );
font->descent( 0 );
font->height( face->available_sizes[ptsize].height );
font->lineSkip( FT_CEIL( font->ascent() ) );
font->underlineOffset( FT_FLOOR( face->underline_position ) );
font->underlineHeight( FT_FLOOR( face->underline_thickness ) );
}
if ( font->underlineHeight() < 1 )
font->underlineHeight( 1 );
font->faceStyle( HK_TTF_STYLE_NORMAL );
if ( face->style_flags & FT_STYLE_FLAG_BOLD )
font->faceStyle( font->faceStyle() | HK_TTF_STYLE_BOLD );
if ( face->style_flags & FT_STYLE_FLAG_ITALIC )
font->faceStyle( font->faceStyle() | HK_TTF_STYLE_ITALIC );
font->style( font->faceStyle() );
font->outline( 0 );
font->kerning( 1 );
font->glyphOverhang( face->size->metrics.y_ppem / 10 );
font->glyphItalics( 0.207f );
font->glyphItalics( font->glyphItalics() * font->height() );
return font;
}
void hkFontManager::mutexLock() {
lock();
}
void hkFontManager::mutexUnlock() {
unlock();
}
FT_Library hkFontManager::getLibrary() const {
return mLibrary;
}
}

View File

@@ -1,52 +0,0 @@
#ifndef HAIKUTTF_HKFONTMANAGER_HPP
#define HAIKUTTF_HKFONTMANAGER_HPP
#include "hkbase.hpp"
#include "hkglyph.hpp"
#include "hkfont.hpp"
#include "hkmutex.hpp"
namespace HaikuTTF {
class hkFontManager : private hkMutex {
static hkFontManager * mSingleton;
public:
static hkFontManager * exists();
static hkFontManager * instance();
static void destroySingleton();
hkFontManager();
~hkFontManager();
int init();
void destroy();
int wasInit();
void closeFont( hkFont * Font );
hkFont * openFromMemory( const u8* data, unsigned long size, int ptsize, long index = 0, unsigned int glyphCacheSize = 256 );
hkFont * openFromFile( const char* filename, int ptsize, long index = 0, unsigned int glyphCacheSize = 256 );
FT_Library getLibrary() const;
protected:
friend class hkFont;
FT_Library mLibrary;
int mInitialized;
hkFont * fontPrepare( hkFont * font, int ptsize );
void mutexLock();
void mutexUnlock();
};
}
#endif

View File

@@ -1,111 +0,0 @@
#include "hkglyph.hpp"
namespace HaikuTTF {
hkGlyph::hkGlyph() :
mStored(0),
mIndex(0),
mMinX(0),
mMaxX(0),
mMinY(0),
mMaxY(0),
mOffsetY(0),
mAdvance(0),
mCached(0)
{
memset( &mPixmap, 0, sizeof(mPixmap) );
}
hkGlyph::~hkGlyph() {
flush();
}
void hkGlyph::flush() {
mStored = 0;
mIndex = 0;
mCached = 0;
hkSAFE_FREE( mPixmap.buffer );
}
int hkGlyph::stored() const {
return mStored;
}
void hkGlyph::stored( int stored ) {
mStored = stored;
}
FT_UInt hkGlyph::index() const {
return mIndex;
}
void hkGlyph::index( FT_UInt index ) {
mIndex = index;
}
FT_Bitmap * hkGlyph::pixmap() {
return &mPixmap;
}
void hkGlyph::pixmap( const FT_Bitmap& pixmap ) {
mPixmap = pixmap;
}
int hkGlyph::minX() const {
return mMinX;
}
void hkGlyph::minX( int minx ) {
mMinX = minx;
}
int hkGlyph::minY() const {
return mMinY;
}
void hkGlyph::minY( int miny ) {
mMinY = miny;
}
int hkGlyph::maxX() const {
return mMaxX;
}
void hkGlyph::maxX( int maxx ) {
mMaxX = maxx;
}
int hkGlyph::maxY() const {
return mMaxY;
}
void hkGlyph::maxY( int maxy ) {
mMaxY = maxy;
}
int hkGlyph::offsetY() const {
return mOffsetY;
}
void hkGlyph::offsetY( int offsety ) {
mOffsetY = offsety;
}
int hkGlyph::advance() const {
return mAdvance;
}
void hkGlyph::advance( int advance ) {
mAdvance = advance;
}
u16 hkGlyph::cached() const {
return mCached;
}
void hkGlyph::cached( u16 cached ) {
mCached = cached;
}
}

View File

@@ -1,67 +0,0 @@
#ifndef HAIKUTTF_HKGLYPH_HPP
#define HAIKUTTF_HKGLYPH_HPP
#include "hkbase.hpp"
#include <ft2build.h>
#include FT_FREETYPE_H
#include FT_OUTLINE_H
#include FT_STROKER_H
#include FT_GLYPH_H
#include FT_TRUETYPE_IDS_H
namespace HaikuTTF {
class hkGlyph {
public:
hkGlyph();
~hkGlyph();
int stored() const;
void stored( int stored );
FT_UInt index() const;
void index( FT_UInt index );
FT_Bitmap * pixmap();
void pixmap( const FT_Bitmap& pixmap );
int minX() const;
void minX( int minx );
int minY() const;
void minY( int miny );
int maxX() const;
void maxX( int maxx );
int maxY() const;
void maxY( int maxy );
int offsetY() const;
void offsetY( int offsety );
int advance() const;
void advance( int advance );
u16 cached() const;
void cached( u16 cached );
void flush();
protected:
int mStored;
FT_UInt mIndex;
FT_Bitmap mPixmap;
int mMinX;
int mMaxX;
int mMinY;
int mMaxY;
int mOffsetY;
int mAdvance;
u16 mCached;
};
}
#endif

View File

@@ -1,82 +0,0 @@
#include "hkmutex.hpp"
namespace HaikuTTF {
#if HK_PLATFORM == HK_PLATFORM_WIN
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
#ifndef NOMINMAX
#define NOMINMAX
#endif
#include <windows.h>
class hkMutexImpl {
public:
hkMutexImpl() {
InitializeCriticalSection(&mMutex);
}
~hkMutexImpl() {
DeleteCriticalSection(&mMutex);
}
void Lock() {
EnterCriticalSection(&mMutex);
}
void Unlock() {
LeaveCriticalSection(&mMutex);
}
protected:
CRITICAL_SECTION mMutex;
};
#elif defined( HK_PLATFORM_POSIX )
#include <pthread.h>
class hkMutexImpl {
public:
hkMutexImpl() {
pthread_mutex_init(&mMutex, NULL);
}
~hkMutexImpl() {
pthread_mutex_destroy(&mMutex);
}
void Lock() {
pthread_mutex_lock(&mMutex);
}
void Unlock() {
pthread_mutex_unlock(&mMutex);
}
protected:
pthread_mutex_t mMutex;
};
#endif
hkMutex::hkMutex() :
mImpl( hkNew( hkMutexImpl, () ) )
{
}
hkMutex::~hkMutex() {
hkSAFE_DELETE( mImpl )
}
void hkMutex::lock() {
mImpl->Lock();
}
void hkMutex::unlock() {
mImpl->Unlock();
}
}

View File

@@ -1,24 +0,0 @@
#ifndef HAIKUTTF_HKMUTEX_HPP
#define HAIKUTTF_HKMUTEX_HPP
#include "hkbase.hpp"
namespace HaikuTTF {
class hkMutexImpl;
class hkMutex {
public:
hkMutex();
~hkMutex();
void lock();
void unlock();
protected:
hkMutexImpl * mImpl;
};
}
#endif

View File

@@ -64,7 +64,7 @@ void Space::step( const cpFloat& dt ) {
void Space::update() {
#ifdef PHYSICS_RENDERER_ENABLED
step( Window::Engine::instance()->getElapsed().asSeconds() );
step( Window::Engine::instance()->getCurrentWindow()->getElapsed().asSeconds() );
#else
Step( 1 / 60 );
#endif

View File

@@ -58,7 +58,7 @@ void UIManager::init( Uint32 Flags, EE::Window::Window * window ) {
mControl = UIWindow::New();
mControl->setFlags( UI_REPORT_SIZE_CHANGE_TO_CHILDS );
mControl->setStyleConfig( windowStyleConfig );
mControl->setSize( (Float)Engine::instance()->getWidth() / PixelDensity::getPixelDensity(), (Float)Engine::instance()->getHeight() / PixelDensity::getPixelDensity() );
mControl->setSize( (Float)mWindow->getWidth() / PixelDensity::getPixelDensity(), (Float)mWindow->getHeight() / PixelDensity::getPixelDensity() );
mControl->setVisible( true );
mControl->setEnabled( true );
mControl->getContainer()->setEnabled( false );

View File

@@ -10,7 +10,6 @@
#include <eepp/graphics/vertexbuffermanager.hpp>
#include <eepp/ui/uimanager.hpp>
#include <eepp/audio/audiolistener.hpp>
#include <eepp/helper/haikuttf/hkfontmanager.hpp>
#include <eepp/physics/physicsmanager.hpp>
#include <eepp/network/ssl/sslsocket.hpp>
#include <eepp/window/backend.hpp>
@@ -69,8 +68,6 @@ Engine::~Engine() {
Log::destroySingleton();
HaikuTTF::hkFontManager::destroySingleton();
#ifdef EE_SSL_SUPPORT
Network::SSL::SSLSocket::end();
#endif
@@ -215,24 +212,6 @@ bool Engine::isRunning() const {
return NULL != mWindow;
}
Time Engine::getElapsed() const {
eeASSERT( isRunning() );
return mWindow->getElapsed();
}
const Uint32& Engine::getWidth() const {
eeASSERT( isRunning() );
return mWindow->getWidth();
}
const Uint32& Engine::getHeight() const {
eeASSERT( isRunning() );
return mWindow->getHeight();
}
Uint32 Engine::getDefaultBackend() const {
#if DEFAULT_BACKEND == BACKEND_SDL2
return WindowBackend::SDL2;

View File

@@ -157,7 +157,7 @@ void Input::processEvent( InputEvent * Event ) {
Finger->y = (Uint16)( Event->finger.y * (Float)mWindow->getHeight() );
Finger->pressure = Event->finger.pressure;
Finger->down = false;
Finger->was_down = true;
Finger->wasDown = true;
Finger->xdelta = Event->finger.dx;
Finger->ydelta = Event->finger.dy;
@@ -222,7 +222,7 @@ InputFinger * Input::getFingerId( const Int64 &fingerId ) {
void Input::resetFingerWasDown() {
for ( Uint32 i = 0; i < EE_MAX_FINGERS; i++ ) {
mFingers[i].was_down = false;
mFingers[i].wasDown = false;
}
}
@@ -429,7 +429,7 @@ std::list<InputFinger *> Input::getFingersWasDown() {
std::list<InputFinger *> fDown;
for ( Uint32 i = 0; i < EE_MAX_FINGERS; i++ ) {
if ( mFingers[i].was_down ) {
if ( mFingers[i].wasDown ) {
fDown.push_back( &mFingers[i] );
}
}

View File

@@ -11,9 +11,9 @@ InputFinger::InputFinger() :
ydelta(0),
last_x(0),
last_y(0),
last_pressure(0),
lastPressure(0),
down(false),
was_down(false)
wasDown(false)
{
}
@@ -21,8 +21,8 @@ bool InputFinger::isDown() {
return down;
}
bool InputFinger::wasDown() {
return was_down;
bool InputFinger::getWasDown() {
return wasDown;
}
Vector2i InputFinger::getPos() {
@@ -32,7 +32,7 @@ Vector2i InputFinger::getPos() {
void InputFinger::writeLast() {
last_x = x;
last_y = y;
last_pressure = pressure;
lastPressure = pressure;
}
}}

View File

@@ -13,13 +13,13 @@ JoystickManager::JoystickManager() :
}
JoystickManager::~JoystickManager() {
for ( Uint32 i = 0; i < count(); i++ )
for ( Uint32 i = 0; i < getCount(); i++ )
eeSAFE_DELETE( mJoysticks[i] );
close();
}
Uint32 JoystickManager::count() {
Uint32 JoystickManager::getCount() {
return mCount;
}

View File

@@ -137,7 +137,7 @@ EE_MAIN_FUNC int main (int argc, char * argv [])
P.setFillMode( DRAW_LINE );
// Set the sprites position to the screen center
Vector2i ScreenCenter( Engine::instance()->getWidth() / 2, Engine::instance()->getHeight() / 2 );
Vector2i ScreenCenter( Engine::instance()->getCurrentWindow()->getWidth() / 2, Engine::instance()->getCurrentWindow()->getHeight() / 2 );
Planet.setPosition( ScreenCenter.x - Planet.getAABB().getSize().getWidth() / 2, ScreenCenter.y - Planet.getAABB().getSize().getHeight() / 2 );

View File

@@ -508,7 +508,6 @@ void EETest::createUI() {
void EETest::createNewUI() {
std::vector<String> str = getTestStringArr();
/*
UIRadioButton * ctrl = UIRadioButton::New();
ctrl->setPosition( 50, 100 )->setSize( 200, 32 );
ctrl->setBackgroundFillEnabled( true )->setColor( 0x33333333 );
@@ -522,7 +521,7 @@ void EETest::createNewUI() {
cbox->setBorderEnabled( true )->setColor( 0x66666666 );
cbox->setText( "Happy CheckBox :)" );
cbox->setFontColor( 0x000000FF );
/*
UIImage * gfx = UIImage::New();
gfx->setPosition( 50, 140 )->setSize( 16, 16 );
gfx->setBackgroundFillEnabled( true )->setColor( 0x33333333 );
@@ -641,7 +640,7 @@ void EETest::createNewUI() {
TabWidget->add( "Tab 2", UIWidget::New()->setThemeControl( "winback" ), mTheme->getIconByName( "go-up" ) );
TabWidget->add( "Tab 3", UIWidget::New()->setThemeControl( "winback" ), mTheme->getIconByName( "add" ) );
/**/
*/
/*
UIWindow * win = UIWindow::New();
win->setSize( 500, 500 );
@@ -689,7 +688,7 @@ void EETest::createNewUI() {
drop->getListBox()->addListBoxItems( { "Car", "Bus", "Plane", "Submarine" } );
drop->getListBox()->setSelected(0);
win->show();
/**/
*/
/*
UIWindow * win2 = UIWindow::New();
@@ -709,7 +708,7 @@ void EETest::createNewUI() {
->setLayoutPositionRule( LEFT_OF, ofBut )->setParent( rlay );
win2->show();
/**/
UIManager::instance()->loadLayoutFromString(
"<window layout_width='300dp' layout_height='300dp' winflags='default|maximize'>"
@@ -730,7 +729,7 @@ void EETest::createNewUI() {
" </LinearLayout>"
"</window>"
);
*/
}
void EETest::createMapEditor() {
@@ -1593,8 +1592,8 @@ void EETest::input() {
nmX = eemax<Float>( nmX, 0 );
nmY = eemax<Float>( nmY, 0 );
nmX = eemin( nmX, (Float)EE->getWidth() );
nmY = eemin( nmY, (Float)EE->getHeight() );
nmX = eemin( nmX, (Float)EE->getCurrentWindow()->getWidth() );
nmY = eemin( nmY, (Float)EE->getCurrentWindow()->getHeight() );
KM->injectMousePos( (Int32)nmX, (Int32)nmY );