|
@@ -14,10 +14,8 @@ using namespace Framework;
|
|
|
// Konstruktor
|
|
|
Buchstabe::Buchstabe()
|
|
|
: size( 0, 0 ),
|
|
|
- pos( 0, 0 ),
|
|
|
alpha( 0 ),
|
|
|
schriftSize( 0 ),
|
|
|
- drawSg( 0 ),
|
|
|
ref( 1 )
|
|
|
{}
|
|
|
|
|
@@ -53,25 +51,14 @@ void Buchstabe::setPixel( int i, unsigned char alpha )
|
|
|
this->alpha[ i ] = alpha;
|
|
|
}
|
|
|
|
|
|
-void Buchstabe::setPosition( Punkt &pos ) // setzt die Buchstabenposition
|
|
|
-{
|
|
|
- this->pos = pos;
|
|
|
-}
|
|
|
-
|
|
|
-void Buchstabe::setPosition( int x, int y )
|
|
|
-{
|
|
|
- pos.x = x;
|
|
|
- pos.y = y;
|
|
|
-}
|
|
|
-
|
|
|
void Buchstabe::setSchriftSize( int sg ) // setzt die Schriftgröße des Buchstaben
|
|
|
{
|
|
|
schriftSize = sg;
|
|
|
}
|
|
|
|
|
|
-void Buchstabe::setDrawSchriftSize( int dsg ) // setzt die Zeichengröße des Buchstaben
|
|
|
+int Buchstabe::getSchriftSize() const
|
|
|
{
|
|
|
- drawSg = dsg;
|
|
|
+ return schriftSize;
|
|
|
}
|
|
|
|
|
|
// constant
|
|
@@ -82,15 +69,10 @@ const Punkt &Buchstabe::getSize() const // gibt die Buchstabenbildgr
|
|
|
|
|
|
int Buchstabe::getBreite() const // Buchstabenbreite
|
|
|
{
|
|
|
- return (int)( ( (double)size.x / (double)schriftSize ) * (double)drawSg + 0.5 );
|
|
|
+ return size.x;
|
|
|
}
|
|
|
|
|
|
int Buchstabe::getHeight() const // Buchstabenhöhe
|
|
|
-{
|
|
|
- return (int)( ( (double)size.y / (double)schriftSize ) *(double)drawSg + 0.5 );
|
|
|
-}
|
|
|
-
|
|
|
-int Buchstabe::getNormHeight() const // Buchstabenhöhe
|
|
|
{
|
|
|
return size.y;
|
|
|
}
|
|
@@ -100,97 +82,6 @@ unsigned char *Buchstabe::getBuff() const // gibt den Alphabuffer zur
|
|
|
return alpha;
|
|
|
}
|
|
|
|
|
|
-void Buchstabe::render( Bild &zRObj, int f ) const // Zeichnet nach zRObj
|
|
|
-{
|
|
|
- if( alpha )
|
|
|
- {
|
|
|
- const Punkt &zRObjGr = zRObj.getDrawGr();
|
|
|
- const Punkt &zRObjPos = zRObj.getDrawPos();
|
|
|
- const Punkt &zRObjOff = zRObj.getDrawOff();
|
|
|
- int xp = pos.x + zRObjOff.x, yp = pos.y + zRObjOff.y;
|
|
|
- int xs = xp < zRObjPos.x ? ( zRObjPos.x - xp ) : 0, ys = yp < zRObjPos.y ? ( zRObjPos.y - yp ) : 0;
|
|
|
- int b = size.x, h = size.y;
|
|
|
- unsigned char a2 = (unsigned char)( 255 - ( f >> 24 ) );
|
|
|
- f &= 0x00FFFFFF;
|
|
|
- if( schriftSize == drawSg )
|
|
|
- {
|
|
|
- if( xp >= zRObjGr.x || yp >= zRObjGr.y || xp + b < zRObjPos.x || yp + h < zRObjPos.y )
|
|
|
- return;
|
|
|
- b = ( xp + b ) > zRObjGr.x ? ( zRObjGr.x - xp ) : b;
|
|
|
- h = ( yp + h ) > zRObjGr.y ? ( zRObjGr.y - yp ) : h;
|
|
|
- if( !a2 )
|
|
|
- {
|
|
|
- int xx, ygr = ( ys - 1 ) * size.x, ygr2 = ( yp + ys - 1 ) * zRObj.getBreite();
|
|
|
- for( int yy = ys; yy < h; ++yy )
|
|
|
- {
|
|
|
- ygr += size.x;
|
|
|
- ygr2 += zRObj.getBreite();
|
|
|
- for( xx = xs; xx < b; ++xx )
|
|
|
- zRObj.alphaPixel( xp + xx + ygr2, f | ( alpha[ xx + ygr ] << 24 ) );
|
|
|
- }
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- int a;
|
|
|
- int xx, ygr = ( ys - 1 ) * size.x, ygr2 = ( yp + ys - 1 ) * zRObj.getBreite();
|
|
|
- for( int yy = ys; yy < h; ++yy )
|
|
|
- {
|
|
|
- ygr += size.x;
|
|
|
- ygr2 += zRObj.getBreite();
|
|
|
- for( xx = xs; xx < b; ++xx )
|
|
|
- {
|
|
|
- a = alpha[ xx + ygr ] - a2;
|
|
|
- if( a > 0 )
|
|
|
- zRObj.alphaPixel( xp + xx + ygr2, f | ( a << 24 ) );
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- double xoff = (double)schriftSize / (double)drawSg,
|
|
|
- yoff = (double)schriftSize / (double)drawSg;
|
|
|
- double x = xs * xoff, y = ys * yoff;
|
|
|
- int maxX = getBreite(), maxY = getHeight();
|
|
|
- maxX = ( xp + maxX ) >= zRObjGr.x ? ( zRObjGr.x - xp ) : maxX;
|
|
|
- maxY = ( yp + maxY ) >= zRObjGr.y ? ( zRObjGr.y - yp ) : maxY;
|
|
|
- if( !a2 )
|
|
|
- {
|
|
|
- int dx, ygr, ygr2;
|
|
|
- for( int dy = ys; dy < maxY; ++dy )
|
|
|
- {
|
|
|
- ygr2 = ( yp + dy ) * zRObj.getBreite();
|
|
|
- ygr = (int)y * b;
|
|
|
- for( dx = xs; dx < maxX; ++dx )
|
|
|
- {
|
|
|
- zRObj.alphaPixel( xp + dx + ygr2, f | ( alpha[ (int)x + ygr ] << 24 ) );
|
|
|
- x += xoff;
|
|
|
- }
|
|
|
- x = xs;
|
|
|
- y += yoff;
|
|
|
- }
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- int a, dx, ygr, ygr2;
|
|
|
- for( int dy = ys; dy < maxY; ++dy )
|
|
|
- {
|
|
|
- ygr2 = ( yp + dy ) * zRObj.getBreite();
|
|
|
- ygr = (int)y * b;
|
|
|
- for( dx = xs; dx < maxX; ++dx )
|
|
|
- {
|
|
|
- a = alpha[ (int)x + ygr ] - a2;
|
|
|
- zRObj.alphaPixel( xp + dx + ygr2, f | ( a << 24 ) );
|
|
|
- x += xoff;
|
|
|
- }
|
|
|
- x = xs;
|
|
|
- y += yoff;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
// Reference Counting
|
|
|
Buchstabe *Buchstabe::getThis()
|
|
|
{
|
|
@@ -206,15 +97,12 @@ Buchstabe *Buchstabe::release()
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
// Inhalt der Alphabet Klasse aus Schrift.h
|
|
|
// Konstruktor
|
|
|
Alphabet::Alphabet()
|
|
|
: zeichen( new Buchstabe*[ 256 ] ),
|
|
|
schriftSize( 12 ),
|
|
|
- drawSchriftSize( 12 ),
|
|
|
- pos( 0, 0 ),
|
|
|
- zeilenHeight( 0 ),
|
|
|
- zeilenAbstand( 5 ),
|
|
|
ref( 1 )
|
|
|
{
|
|
|
for( int i = 0; i < 256; ++i )
|
|
@@ -242,7 +130,6 @@ void Alphabet::NeuAlphabet() // Initialisierung
|
|
|
}
|
|
|
for( int i = 0; i < 256; ++i )
|
|
|
zeichen[ i ] = 0;
|
|
|
- zeilenHeight = 0;
|
|
|
}
|
|
|
|
|
|
void Alphabet::setBuchstabe( unsigned char i, Buchstabe *buchstabe ) // setzt einen Buchstaben
|
|
@@ -253,13 +140,6 @@ void Alphabet::setBuchstabe( unsigned char i, Buchstabe *buchstabe ) // setzt ei
|
|
|
if( zeichen[ i ] )
|
|
|
{
|
|
|
zeichen[ i ]->setSchriftSize( schriftSize );
|
|
|
- zeichen[ i ]->setDrawSchriftSize( drawSchriftSize );
|
|
|
- }
|
|
|
- zeilenHeight = 0;
|
|
|
- for( int i = 0; i < 256; ++i )
|
|
|
- {
|
|
|
- if( zeichen[ i ] != 0 )
|
|
|
- zeilenHeight = maxInt( zeichen[ i ]->getHeight(), zeilenHeight );
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -273,32 +153,6 @@ void Alphabet::setSchriftSize( int gr ) // setzt die Schriftgr
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-void Alphabet::setDrawSchriftSize( int gr ) // setzt die Zeichengröße
|
|
|
-{
|
|
|
- drawSchriftSize = gr;
|
|
|
- for( int i = 0; i < 256; ++i )
|
|
|
- {
|
|
|
- if( zeichen[ i ] )
|
|
|
- zeichen[ i ]->setDrawSchriftSize( gr );
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-void Alphabet::setZeilenAbstand( int za ) // setzt die Zeilenhöhe( Zeilenabstand )
|
|
|
-{
|
|
|
- zeilenAbstand = za;
|
|
|
-}
|
|
|
-
|
|
|
-void Alphabet::setDrawPosition( Punkt &pos ) // setzt die Draw Position
|
|
|
-{
|
|
|
- this->pos = pos;
|
|
|
-}
|
|
|
-
|
|
|
-void Alphabet::setDrawPosition( int x, int y )
|
|
|
-{
|
|
|
- pos.x = x;
|
|
|
- pos.y = y;
|
|
|
-}
|
|
|
-
|
|
|
// constant
|
|
|
Buchstabe *Alphabet::getBuchstabe( unsigned char i ) const // gibt einen Buchstaben zurück
|
|
|
{
|
|
@@ -322,399 +176,218 @@ int Alphabet::getSchriftSize() const // gibt die Schriftgr
|
|
|
return schriftSize;
|
|
|
}
|
|
|
|
|
|
-int Alphabet::getDrawSchriftSize() const // gibt die Zeichengröße zurück
|
|
|
+// Reference Counting
|
|
|
+Alphabet *Alphabet::getThis()
|
|
|
{
|
|
|
- return drawSchriftSize;
|
|
|
+ ++ref;
|
|
|
+ return this;
|
|
|
}
|
|
|
|
|
|
-int Alphabet::getZeilenAbstand() const // gibt den Zeilenabstand zurück
|
|
|
+Alphabet *Alphabet::release()
|
|
|
{
|
|
|
- return zeilenAbstand;
|
|
|
+ --ref;
|
|
|
+ if( ref == 0 )
|
|
|
+ delete this;
|
|
|
+ return 0;
|
|
|
}
|
|
|
|
|
|
-int Alphabet::getZeilenHeight() const // gibt die Höhe des höchsten Zeichens zurück
|
|
|
-{
|
|
|
- return (int)( (double)zeilenHeight / schriftSize * drawSchriftSize + 0.5 );
|
|
|
-}
|
|
|
+// Inhalt der AlphabetArray Klasse aus Schrift.h
|
|
|
+// Konstruktor
|
|
|
+AlphabetArray::AlphabetArray()
|
|
|
+ : next( 0 ),
|
|
|
+ This( 0 )
|
|
|
+{}
|
|
|
|
|
|
-const Punkt &Alphabet::getPosition() const // gibt die DrawPosition zurück
|
|
|
+// Destruktor
|
|
|
+AlphabetArray::~AlphabetArray()
|
|
|
{
|
|
|
- return pos;
|
|
|
+ if( This )
|
|
|
+ This->release();
|
|
|
+ delete next;
|
|
|
}
|
|
|
|
|
|
-int Alphabet::getTextBreite( Text *zTxt ) const // gibt die Breite des Textes zurück
|
|
|
+// nicht constant
|
|
|
+bool AlphabetArray::addAlphabet( Alphabet *alphabet ) // Fügt ein Alphabet hinzu
|
|
|
{
|
|
|
- int ret = 0;
|
|
|
- int len = zTxt->getLength();
|
|
|
- char *buff = zTxt->getText();
|
|
|
- unsigned char c = 0;
|
|
|
- int tmp = 0;
|
|
|
- for( int i = 0; i < len; ++i )
|
|
|
+ if( This )
|
|
|
{
|
|
|
- c = (unsigned char)buff[ i ];
|
|
|
- if( buff[ i ] == '\n' )
|
|
|
- {
|
|
|
- if( tmp > ret )
|
|
|
- ret = tmp;
|
|
|
- tmp = 0;
|
|
|
- }
|
|
|
- else if( buff[ i ] == '\r' )
|
|
|
+ if( This->getSchriftSize() == alphabet->getSchriftSize() )
|
|
|
{
|
|
|
- i += 10;
|
|
|
- continue;
|
|
|
+ alphabet->release();
|
|
|
+ return false;
|
|
|
}
|
|
|
- else if( buff[ i ] == '\t' )
|
|
|
- tmp += drawSchriftSize;
|
|
|
- else if( buff[ i ] == ' ' )
|
|
|
- tmp += drawSchriftSize / 2;
|
|
|
- else if( zeichen[ c ] )
|
|
|
- tmp += zeichen[ c ]->getBreite();
|
|
|
}
|
|
|
- if( tmp > ret )
|
|
|
- ret = tmp;
|
|
|
- return ret;
|
|
|
+ else
|
|
|
+ {
|
|
|
+ This = alphabet;
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ if( !next )
|
|
|
+ next = new AlphabetArray();
|
|
|
+ return next->addAlphabet( alphabet );
|
|
|
}
|
|
|
|
|
|
-int Alphabet::getTextHeight( Text *zTxt ) const // gibt die Höhe des Textes zurück
|
|
|
+bool AlphabetArray::removeAlphabet( int sg ) // entfernt ein Alphabet
|
|
|
{
|
|
|
- int hi = getZeilenHeight();
|
|
|
- return hi + ( ( hi + zeilenAbstand ) * zTxt->anzahlVon( '\n' ) );
|
|
|
+ if( This )
|
|
|
+ {
|
|
|
+ if( This->getSchriftSize() == sg )
|
|
|
+ This = This->release();
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+ if( !next )
|
|
|
+ return 0;
|
|
|
+ if( next->removeAlphabet( sg ) )
|
|
|
+ {
|
|
|
+ AlphabetArray *tmp = next->getNext();
|
|
|
+ next->setNext0();
|
|
|
+ delete next;
|
|
|
+ next = tmp;
|
|
|
+ }
|
|
|
+ return 0;
|
|
|
}
|
|
|
|
|
|
-int Alphabet::textPos( Text *zText, int mausX, int mausY ) const // gibt den Buchstaben zurück, auf den die Maus zeigt
|
|
|
+void AlphabetArray::setNext0() // setzt den next Zeiger zu 0
|
|
|
{
|
|
|
- char *buffer = zText->getText();
|
|
|
- int len = zText->getLength();
|
|
|
- int tx = 0;
|
|
|
- int ty = 0;
|
|
|
- int sh = getZeilenHeight();
|
|
|
- if( mausX < 0 || mausY < 0 )
|
|
|
- return -1;
|
|
|
- for( int i = 0; i < len; ++i )
|
|
|
+ next = 0;
|
|
|
+}
|
|
|
+
|
|
|
+// constant
|
|
|
+Alphabet *AlphabetArray::getAlphabet( unsigned char sg ) const // gibt getThis von einem Alphabet zurück
|
|
|
+{
|
|
|
+ if( !This )
|
|
|
+ return 0;
|
|
|
+ if( This->getSchriftSize() == sg )
|
|
|
+ return This->getThis();
|
|
|
+ if( next )
|
|
|
+ return next->getAlphabet( sg );
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+
|
|
|
+Alphabet *AlphabetArray::zAlphabet( unsigned char sg ) const // gibt ein Alphabet zurück
|
|
|
+{
|
|
|
+ if( !This )
|
|
|
+ return 0;
|
|
|
+ if( This->getSchriftSize() == sg )
|
|
|
+ return This;
|
|
|
+ if( next )
|
|
|
+ return next->zAlphabet( sg );
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+
|
|
|
+Alphabet *AlphabetArray::getAlphabetI( int index, int count ) const
|
|
|
+{
|
|
|
+ if( count == index )
|
|
|
+ return This->getThis();
|
|
|
+ if( next )
|
|
|
+ return next->getAlphabetI( index, count + 1 );
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+
|
|
|
+Alphabet *AlphabetArray::zAlphabetI( int index, int count ) const
|
|
|
+{
|
|
|
+ if( count == index )
|
|
|
+ return This;
|
|
|
+ if( next )
|
|
|
+ return next->zAlphabetI( index, count + 1 );
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+
|
|
|
+AlphabetArray *AlphabetArray::getNext() const // gibt das nächste Alphabet zurück
|
|
|
+{
|
|
|
+ return next;
|
|
|
+}
|
|
|
+
|
|
|
+// Inhalt der Schrift Klasse aus Schrift.h
|
|
|
+// Konstruktor
|
|
|
+Schrift::Schrift()
|
|
|
+ : alphabetAnzahl( 0 ),
|
|
|
+ alphabet( new AlphabetArray() ),
|
|
|
+ ref( 1 )
|
|
|
+{}
|
|
|
+
|
|
|
+// Destruktor
|
|
|
+Schrift::~Schrift()
|
|
|
+{
|
|
|
+ delete alphabet;
|
|
|
+}
|
|
|
+
|
|
|
+bool Schrift::addAlphabet( Alphabet *alphabet ) // Fügt der Schrift ein Alphabet hinzu
|
|
|
+{
|
|
|
+ if( this->alphabet->addAlphabet( alphabet ) )
|
|
|
{
|
|
|
- if( buffer[ i ] == '\n' )
|
|
|
- {
|
|
|
- ty += sh + zeilenAbstand;
|
|
|
- tx = 0;
|
|
|
- if( mausY < ty )
|
|
|
- return i;
|
|
|
- }
|
|
|
- if( buffer[ i ] == '\t' )
|
|
|
- tx += drawSchriftSize;
|
|
|
- if( buffer[ i ] == ' ' )
|
|
|
- tx += drawSchriftSize / 2;
|
|
|
- if( zeichen[ (unsigned char)buffer[ i ] ] )
|
|
|
- tx += zeichen[ (unsigned char)buffer[ i ] ]->getBreite();
|
|
|
- int txpl = 0;
|
|
|
- if( zeichen[ (unsigned char)buffer[ i + 1 ] ] )
|
|
|
- txpl = zeichen[ (unsigned char)buffer[ i + 1 ] ]->getBreite() / 2;
|
|
|
- if( mausX < tx - txpl && mausY < ty + sh + zeilenAbstand )
|
|
|
- return i;
|
|
|
+ ++alphabetAnzahl;
|
|
|
+ return true;
|
|
|
}
|
|
|
- if( mausY < ty + sh + zeilenAbstand )
|
|
|
- return len;
|
|
|
- return -1;
|
|
|
+ return false;
|
|
|
}
|
|
|
|
|
|
-void Alphabet::textFormatieren( Text *zText, int maxBreite, int schriftSize ) // fügt zeilenumbrüche ein
|
|
|
+void Schrift::removeAlphabet( int sg ) // Entfernt ein Alphabet
|
|
|
{
|
|
|
- int sg = drawSchriftSize;
|
|
|
- setDrawSchriftSize( schriftSize );
|
|
|
- int lastPos = -1;
|
|
|
- int len = zText->getLength();
|
|
|
- char *txt = zText->getText();
|
|
|
- int x = 0;
|
|
|
- Text result = zText->getText();
|
|
|
- for( int i = 0; i < len; ++i )
|
|
|
+ if( alphabet->removeAlphabet( sg ) )
|
|
|
+ --alphabetAnzahl;
|
|
|
+}
|
|
|
+
|
|
|
+// constant
|
|
|
+Alphabet *Schrift::getAlphabet( int sg ) const
|
|
|
+{
|
|
|
+ Alphabet *drawAlphabet = alphabet->zAlphabet( (unsigned char)sg );
|
|
|
+ if( !drawAlphabet )
|
|
|
{
|
|
|
- char c = txt[ i ];
|
|
|
- if( c == ' ' )
|
|
|
- {
|
|
|
- lastPos = i;
|
|
|
- x += schriftSize / 2;
|
|
|
- continue;
|
|
|
- }
|
|
|
- if( c == '\t' )
|
|
|
- {
|
|
|
- lastPos = i;
|
|
|
- x += schriftSize;
|
|
|
- continue;
|
|
|
- }
|
|
|
- if( c == '\n' )
|
|
|
- {
|
|
|
- x = 0;
|
|
|
- lastPos = -1;
|
|
|
- continue;
|
|
|
- }
|
|
|
- if( c == '\r' && len - i >= 11 )
|
|
|
- {
|
|
|
- i += 10;
|
|
|
- continue;
|
|
|
- }
|
|
|
- Buchstabe *b = getBuchstabe( (unsigned)c );
|
|
|
- if( b )
|
|
|
+ for( int i = 0; i < 256; ++i )
|
|
|
{
|
|
|
- x += b->getBreite();
|
|
|
- if( x > maxBreite && lastPos > -1 )
|
|
|
- {
|
|
|
- result.ersetzen( lastPos, lastPos + 1, "\n" );
|
|
|
- x = 0;
|
|
|
- i = lastPos;
|
|
|
- lastPos = -1;
|
|
|
- }
|
|
|
- b = b->release();
|
|
|
+ drawAlphabet = alphabet->zAlphabet( (unsigned char)( sg - i ) );
|
|
|
+ if( drawAlphabet )
|
|
|
+ break;
|
|
|
+ drawAlphabet = alphabet->zAlphabet( (unsigned char)( sg + i ) );
|
|
|
+ if( drawAlphabet )
|
|
|
+ break;
|
|
|
}
|
|
|
}
|
|
|
- zText->setText( result );
|
|
|
- setDrawSchriftSize( sg );
|
|
|
+ return drawAlphabet->getThis();
|
|
|
}
|
|
|
|
|
|
-void Alphabet::render( Text *zTxt, Bild &rendezRObj, std::function< int( int, int, int ) > f ) const // Zeichnet txt nach rendezRObj
|
|
|
+Alphabet *Schrift::zAlphabet( int sg ) const
|
|
|
{
|
|
|
- int zRObjBr = rendezRObj.getBreite();
|
|
|
- int zRObjHi = rendezRObj.getHeight();
|
|
|
- int xp = pos.x;
|
|
|
- int yp = pos.y;
|
|
|
- int zh = getZeilenHeight();
|
|
|
- if( yp + ( zh + zeilenAbstand ) * zTxt->anzahlVon( '\n' ) + zh < 0 || xp >= zRObjBr || yp >= zRObjHi )
|
|
|
- return;
|
|
|
- char *text = zTxt->getText();
|
|
|
- int len = zTxt->getLength();
|
|
|
- for( int i = 0; i < len; ++i )
|
|
|
+ Alphabet *drawAlphabet = alphabet->zAlphabet( (unsigned char)sg );
|
|
|
+ if( !drawAlphabet )
|
|
|
{
|
|
|
- unsigned char c = text[ i ];
|
|
|
- if( c == ' ' )
|
|
|
- {
|
|
|
- xp += drawSchriftSize / 2;
|
|
|
- continue;
|
|
|
- }
|
|
|
- if( c == '\t' )
|
|
|
- {
|
|
|
- xp += drawSchriftSize;
|
|
|
- continue;
|
|
|
- }
|
|
|
- if( c == '\n' )
|
|
|
- {
|
|
|
- yp += zh + zeilenAbstand;
|
|
|
- xp = pos.x;
|
|
|
- continue;
|
|
|
- }
|
|
|
- if( zeichen[ c ] )
|
|
|
+ for( int i = 0; i < 256; ++i )
|
|
|
{
|
|
|
- if( xp >= zRObjBr )
|
|
|
- continue;
|
|
|
- if( rendezRObj.isAreaDrawable( xp, yp, zeichen[ c ]->getBreite(), zeichen[ c ]->getHeight() ) )
|
|
|
- {
|
|
|
- zeichen[ c ]->setPosition( xp, yp );
|
|
|
- zeichen[ c ]->render( rendezRObj, f( xp, yp, i ) );
|
|
|
- }
|
|
|
- xp += zeichen[ c ]->getBreite();
|
|
|
+ drawAlphabet = alphabet->zAlphabet( (unsigned char)( sg - i ) );
|
|
|
+ if( drawAlphabet )
|
|
|
+ break;
|
|
|
+ drawAlphabet = alphabet->zAlphabet( (unsigned char)( sg + i ) );
|
|
|
+ if( drawAlphabet )
|
|
|
+ break;
|
|
|
}
|
|
|
}
|
|
|
+ return drawAlphabet;
|
|
|
}
|
|
|
|
|
|
-void Alphabet::render( Text *zTxt, Bild &rendezRObj, int f ) const // Zeichnet txt nach rendezRObj
|
|
|
+Alphabet *Schrift::getAlphabetI( int index ) const
|
|
|
{
|
|
|
- int zRObjBr = rendezRObj.getBreite();
|
|
|
- int zRObjHi = rendezRObj.getHeight();
|
|
|
- int xp = pos.x;
|
|
|
- int yp = pos.y;
|
|
|
- int zh = getZeilenHeight();
|
|
|
- if( yp + ( zh + zeilenAbstand ) * zTxt->anzahlVon( '\n' ) + zh < 0 || xp >= zRObjBr || yp >= zRObjHi )
|
|
|
- return;
|
|
|
- char *text = zTxt->getText();
|
|
|
- int len = zTxt->getLength();
|
|
|
- for( int i = 0; i < len; ++i )
|
|
|
- {
|
|
|
- unsigned char c = text[ i ];
|
|
|
- if( c == ' ' )
|
|
|
- {
|
|
|
- xp += drawSchriftSize / 2;
|
|
|
- continue;
|
|
|
- }
|
|
|
- if( c == '\t' )
|
|
|
- {
|
|
|
- xp += drawSchriftSize;
|
|
|
- continue;
|
|
|
- }
|
|
|
- if( c == '\n' )
|
|
|
- {
|
|
|
- yp += zh + zeilenAbstand;
|
|
|
- xp = pos.x;
|
|
|
- continue;
|
|
|
- }
|
|
|
- if( c == '\r' && len - i >= 11 )
|
|
|
- {
|
|
|
- i += 3;
|
|
|
- Text *hex1 = zTxt->getTeilText( i, i + 6 );
|
|
|
- Text *hex2 = zTxt->getTeilText( i + 6, i + 8 );
|
|
|
- f = ( TextZuInt( hex1->getText(), 16 ) << 8 ) |
|
|
|
- ( TextZuInt( hex2->getText(), 16 ) );
|
|
|
- hex1->release();
|
|
|
- hex2->release();
|
|
|
- i += 7;
|
|
|
- continue;
|
|
|
- }
|
|
|
- if( zeichen[ c ] )
|
|
|
- {
|
|
|
- if( xp >= zRObjBr )
|
|
|
- continue;
|
|
|
- if( rendezRObj.isAreaDrawable( xp, yp, zeichen[ c ]->getBreite(), zeichen[ c ]->getHeight() ) )
|
|
|
- {
|
|
|
- zeichen[ c ]->setPosition( xp, yp );
|
|
|
- zeichen[ c ]->render( rendezRObj, f );
|
|
|
- }
|
|
|
- xp += zeichen[ c ]->getBreite();
|
|
|
- }
|
|
|
- }
|
|
|
+ return alphabet->getAlphabetI( index, 0 );
|
|
|
}
|
|
|
|
|
|
-void Alphabet::render( Text *zTxt, Bild &rendezRObj, int cpos, int cf, int fbeg, int ff, std::function< int( int, int, int ) > f ) const
|
|
|
+Alphabet *Schrift::zAlphabetI( int index ) const
|
|
|
{
|
|
|
- int zRObjBr = rendezRObj.getBreite();
|
|
|
- int zRObjHi = rendezRObj.getHeight();
|
|
|
- int xp = pos.x;
|
|
|
- int yp = pos.y;
|
|
|
- int zh = getZeilenHeight();
|
|
|
- if( yp + ( zh + zeilenAbstand ) * zTxt->anzahlVon( '\n' ) + zh < 0 || xp >= zRObjBr || yp >= zRObjHi )
|
|
|
- return;
|
|
|
- char *text = zTxt->getText();
|
|
|
- int len = zTxt->getLength();
|
|
|
- bool faerb = 0;
|
|
|
- for( int i = 0; i < len; ++i )
|
|
|
- {
|
|
|
- unsigned char c = text[ i ];
|
|
|
- if( i == fbeg )
|
|
|
- faerb = !faerb;
|
|
|
- if( i == cpos )
|
|
|
- {
|
|
|
- rendezRObj.drawLinieVAlpha( xp, yp, zh, cf );
|
|
|
- faerb = !faerb;
|
|
|
- }
|
|
|
- if( c == ' ' )
|
|
|
- {
|
|
|
- if( faerb )
|
|
|
- rendezRObj.alphaRegion( xp, yp, drawSchriftSize / 2, zh, ff );
|
|
|
- xp += drawSchriftSize / 2;
|
|
|
- continue;
|
|
|
- }
|
|
|
- if( c == '\t' )
|
|
|
- {
|
|
|
- if( faerb )
|
|
|
- rendezRObj.alphaRegion( xp, yp, drawSchriftSize, zh, ff );
|
|
|
- xp += drawSchriftSize;
|
|
|
- continue;
|
|
|
- }
|
|
|
- if( c == '\n' )
|
|
|
- {
|
|
|
- yp += zh + zeilenAbstand;
|
|
|
- xp = pos.x;
|
|
|
- continue;
|
|
|
- }
|
|
|
- if( zeichen[ c ] )
|
|
|
- {
|
|
|
- if( xp >= zRObjBr )
|
|
|
- continue;
|
|
|
- if( rendezRObj.isAreaDrawable( xp, yp, zeichen[ c ]->getBreite(), zeichen[ c ]->getHeight() ) )
|
|
|
- {
|
|
|
- if( faerb )
|
|
|
- {
|
|
|
- int br = zeichen[ c ]->getBreite();
|
|
|
- rendezRObj.alphaRegion( xp, yp, br, zh, ff );
|
|
|
- }
|
|
|
- zeichen[ c ]->setPosition( xp, yp );
|
|
|
- zeichen[ c ]->render( rendezRObj, f( xp, yp, i ) );
|
|
|
- }
|
|
|
- xp += zeichen[ c ]->getBreite();
|
|
|
- }
|
|
|
- }
|
|
|
- if( len == cpos )
|
|
|
- rendezRObj.drawLinieVAlpha( xp, yp, zh, cf );
|
|
|
+ return alphabet->zAlphabetI( index, 0 );
|
|
|
}
|
|
|
|
|
|
-void Alphabet::render( Text *zTxt, Bild &rendezRObj, int cpos, int cf, int fbeg, int ff, int f ) const
|
|
|
+unsigned char Schrift::getAlphabetAnzahl() const // gibt die anzahl von in der Schrift enthaltenen Alphabeten zurück
|
|
|
{
|
|
|
- int zRObjBr = rendezRObj.getBreite();
|
|
|
- int zRObjHi = rendezRObj.getHeight();
|
|
|
- int xp = pos.x;
|
|
|
- int yp = pos.y;
|
|
|
- int zh = getZeilenHeight();
|
|
|
- if( yp + ( zh + zeilenAbstand ) * zTxt->anzahlVon( '\n' ) + zh < 0 || xp >= zRObjBr || yp >= zRObjHi )
|
|
|
- return;
|
|
|
- char *text = zTxt->getText();
|
|
|
- int len = zTxt->getLength();
|
|
|
- bool faerb = 0;
|
|
|
- for( int i = 0; i < len; ++i )
|
|
|
- {
|
|
|
- unsigned char c = text[ i ];
|
|
|
- if( i == fbeg )
|
|
|
- faerb = !faerb;
|
|
|
- if( i == cpos )
|
|
|
- {
|
|
|
- rendezRObj.drawLinieVAlpha( xp, yp, zh, cf );
|
|
|
- faerb = !faerb;
|
|
|
- }
|
|
|
- if( c == ' ' )
|
|
|
- {
|
|
|
- if( faerb )
|
|
|
- rendezRObj.alphaRegion( xp, yp, drawSchriftSize / 2, zh, ff );
|
|
|
- xp += drawSchriftSize / 2;
|
|
|
- continue;
|
|
|
- }
|
|
|
- if( c == '\t' )
|
|
|
- {
|
|
|
- if( faerb )
|
|
|
- rendezRObj.alphaRegion( xp, yp, drawSchriftSize, zh, ff );
|
|
|
- xp += drawSchriftSize;
|
|
|
- continue;
|
|
|
- }
|
|
|
- if( c == '\n' )
|
|
|
- {
|
|
|
- yp += zh + zeilenAbstand;
|
|
|
- xp = pos.x;
|
|
|
- continue;
|
|
|
- }
|
|
|
- if( c == '\r' && len - i >= 11 )
|
|
|
- {
|
|
|
- i += 3;
|
|
|
- Text *hex1 = zTxt->getTeilText( i, i + 6 );
|
|
|
- Text *hex2 = zTxt->getTeilText( i + 6, i + 8 );
|
|
|
- f = ( TextZuInt( hex1->getText(), 16 ) << 8 ) |
|
|
|
- ( TextZuInt( hex2->getText(), 16 ) );
|
|
|
- hex1->release();
|
|
|
- hex2->release();
|
|
|
- i += 7;
|
|
|
- continue;
|
|
|
- }
|
|
|
- if( zeichen[ c ] )
|
|
|
- {
|
|
|
- if( xp >= zRObjBr )
|
|
|
- continue;
|
|
|
- if( rendezRObj.isAreaDrawable( xp, yp, zeichen[ c ]->getBreite(), zeichen[ c ]->getHeight() ) )
|
|
|
- {
|
|
|
- if( faerb )
|
|
|
- {
|
|
|
- int br = zeichen[ c ]->getBreite();
|
|
|
- rendezRObj.alphaRegion( xp, yp, br, zh, ff );
|
|
|
- }
|
|
|
- zeichen[ c ]->setPosition( xp, yp );
|
|
|
- zeichen[ c ]->render( rendezRObj, f );
|
|
|
- }
|
|
|
- xp += zeichen[ c ]->getBreite();
|
|
|
- }
|
|
|
- }
|
|
|
- if( len == cpos )
|
|
|
- rendezRObj.drawLinieVAlpha( xp, yp, zh, cf );
|
|
|
+ return alphabetAnzahl;
|
|
|
}
|
|
|
|
|
|
// Reference Counting
|
|
|
-Alphabet *Alphabet::getThis()
|
|
|
+Schrift *Schrift::getThis()
|
|
|
{
|
|
|
++ref;
|
|
|
return this;
|
|
|
}
|
|
|
|
|
|
-Alphabet *Alphabet::release()
|
|
|
+Schrift *Schrift::release()
|
|
|
{
|
|
|
--ref;
|
|
|
if( ref == 0 )
|
|
@@ -722,450 +395,457 @@ Alphabet *Alphabet::release()
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
-// Inhalt der AlphabetArray Klasse aus Schrift.h
|
|
|
-// Konstruktor
|
|
|
-AlphabetArray::AlphabetArray()
|
|
|
- : next( 0 ),
|
|
|
- This( 0 )
|
|
|
-{}
|
|
|
-
|
|
|
-// Destruktor
|
|
|
-AlphabetArray::~AlphabetArray()
|
|
|
-{
|
|
|
- if( This )
|
|
|
- This->release();
|
|
|
- delete next;
|
|
|
-}
|
|
|
-
|
|
|
-// nicht constant
|
|
|
-bool AlphabetArray::addAlphabet( Alphabet *alphabet ) // Fügt ein Alphabet hinzu
|
|
|
-{
|
|
|
- if( This )
|
|
|
- {
|
|
|
- if( This->getSchriftSize() == alphabet->getSchriftSize() )
|
|
|
- {
|
|
|
- alphabet->release();
|
|
|
- return false;
|
|
|
- }
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- This = alphabet;
|
|
|
- return true;
|
|
|
- }
|
|
|
- if( !next )
|
|
|
- next = new AlphabetArray();
|
|
|
- return next->addAlphabet( alphabet );
|
|
|
-}
|
|
|
-
|
|
|
-bool AlphabetArray::removeAlphabet( int sg ) // entfernt ein Alphabet
|
|
|
-{
|
|
|
- if( This )
|
|
|
- {
|
|
|
- if( This->getSchriftSize() == sg )
|
|
|
- This = This->release();
|
|
|
- return 1;
|
|
|
- }
|
|
|
- if( !next )
|
|
|
- return 0;
|
|
|
- if( next->removeAlphabet( sg ) )
|
|
|
- {
|
|
|
- AlphabetArray *tmp = next->getNext();
|
|
|
- next->setNext0();
|
|
|
- delete next;
|
|
|
- next = tmp;
|
|
|
- }
|
|
|
- return 0;
|
|
|
-}
|
|
|
-
|
|
|
-void AlphabetArray::setDrawSchriftSize( int sg ) // Setzt die Draw Schriftgröße aller Alphabete
|
|
|
-{
|
|
|
- if( This )
|
|
|
- This->setDrawSchriftSize( sg );
|
|
|
- if( next )
|
|
|
- next->setDrawSchriftSize( sg );
|
|
|
-}
|
|
|
|
|
|
-void AlphabetArray::setZeilenAbstand( int za ) // setzt den Zeilenabstant aller Alphabete
|
|
|
-{
|
|
|
- if( This )
|
|
|
- This->setZeilenAbstand( za );
|
|
|
- if( next )
|
|
|
- next->setZeilenAbstand( za );
|
|
|
-}
|
|
|
+TextRenderer::TextRenderer()
|
|
|
+ : TextRenderer( 0 )
|
|
|
+{}
|
|
|
|
|
|
-void AlphabetArray::setNext0() // setzt den next Zeiger zu 0
|
|
|
+TextRenderer::TextRenderer( Schrift *schrift )
|
|
|
{
|
|
|
- next = 0;
|
|
|
+ s = schrift;
|
|
|
+ schriftSize = 12;
|
|
|
+ zeilenAbstand = 5;
|
|
|
+ zeichenAbstand = 0;
|
|
|
+ ref = 1;
|
|
|
}
|
|
|
|
|
|
-// constant
|
|
|
-Alphabet *AlphabetArray::getAlphabet( unsigned char sg ) const // gibt getThis von einem Alphabet zurück
|
|
|
+TextRenderer::~TextRenderer()
|
|
|
{
|
|
|
- if( !This )
|
|
|
- return 0;
|
|
|
- if( This->getSchriftSize() == sg )
|
|
|
- return This->getThis();
|
|
|
- if( next )
|
|
|
- return next->getAlphabet( sg );
|
|
|
- return 0;
|
|
|
+ s->release();
|
|
|
}
|
|
|
|
|
|
-Alphabet *AlphabetArray::zAlphabet( unsigned char sg ) const // gibt ein Alphabet zurück
|
|
|
-{
|
|
|
- if( !This )
|
|
|
- return 0;
|
|
|
- if( This->getSchriftSize() == sg )
|
|
|
- return This;
|
|
|
- if( next )
|
|
|
- return next->zAlphabet( sg );
|
|
|
- return 0;
|
|
|
-}
|
|
|
|
|
|
-Alphabet *AlphabetArray::getAlphabetI( int index, int count ) const
|
|
|
+void TextRenderer::setSchriftZ( Schrift *schrift )
|
|
|
{
|
|
|
- if( count == index )
|
|
|
- return This->getThis();
|
|
|
- if( next )
|
|
|
- return next->getAlphabetI( index, count + 1 );
|
|
|
- return 0;
|
|
|
+ if( s )
|
|
|
+ s->release();
|
|
|
+ s = schrift;
|
|
|
}
|
|
|
|
|
|
-Alphabet *AlphabetArray::zAlphabetI( int index, int count ) const
|
|
|
+Schrift *TextRenderer::getSchrift()
|
|
|
{
|
|
|
- if( count == index )
|
|
|
- return This;
|
|
|
- if( next )
|
|
|
- return next->zAlphabetI( index, count + 1 );
|
|
|
+ if( s )
|
|
|
+ return s->getThis();
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
-AlphabetArray *AlphabetArray::getNext() const // gibt das nächste Alphabet zurück
|
|
|
+Schrift *TextRenderer::zSchrift()
|
|
|
{
|
|
|
- return next;
|
|
|
+ return s;
|
|
|
}
|
|
|
|
|
|
-// Inhalt der Schrift Klasse aus Schrift.h
|
|
|
-// Konstruktor
|
|
|
-Schrift::Schrift()
|
|
|
- : alphabetAnzahl( 0 ),
|
|
|
- alphabet( new AlphabetArray() ),
|
|
|
- schriftSize( 12 ),
|
|
|
- zeilenAbstand( 5 ),
|
|
|
- drawPos( 0, 0 ),
|
|
|
- ref( 1 )
|
|
|
+// Setzt die Schriftgröße, in der gezeichnet werden soll. Die Schrift wählt automatisch das passende Alphabet zum Zeichnen
|
|
|
+// sg: Die Schriftgröße
|
|
|
+void TextRenderer::setSchriftSize( int sg )
|
|
|
{
|
|
|
-}
|
|
|
-
|
|
|
-// Destruktor
|
|
|
-Schrift::~Schrift()
|
|
|
-{
|
|
|
- delete alphabet;
|
|
|
-}
|
|
|
-
|
|
|
-// nicht constant
|
|
|
-void Schrift::lock() // lockt die Schrift
|
|
|
-{
|
|
|
- cs.lock();
|
|
|
-}
|
|
|
-
|
|
|
-void Schrift::unlock() // unlockt die Schrift
|
|
|
-{
|
|
|
- cs.unlock();
|
|
|
-}
|
|
|
-
|
|
|
-bool Schrift::addAlphabet( Alphabet *alphabet ) // Fügt der Schrift ein Alphabet hinzu
|
|
|
-{
|
|
|
- lock();
|
|
|
- if( this->alphabet->addAlphabet( alphabet ) )
|
|
|
- {
|
|
|
- ++alphabetAnzahl;
|
|
|
- alphabet->setDrawSchriftSize( schriftSize );
|
|
|
- unlock();
|
|
|
- return true;
|
|
|
- }
|
|
|
- unlock();
|
|
|
- return false;
|
|
|
-}
|
|
|
-
|
|
|
-void Schrift::removeAlphabet( int sg ) // Entfernt ein Alphabet
|
|
|
-{
|
|
|
- lock();
|
|
|
- if( alphabet->removeAlphabet( sg ) )
|
|
|
- --alphabetAnzahl;
|
|
|
- unlock();
|
|
|
-}
|
|
|
-
|
|
|
-void Schrift::setDrawPosition( int x, int y ) // setzt die Zeichenposition
|
|
|
-{
|
|
|
- lock();
|
|
|
- drawPos.x = x;
|
|
|
- drawPos.y = y;
|
|
|
- unlock();
|
|
|
-}
|
|
|
-
|
|
|
-void Schrift::setDrawPosition( Punkt &pos )
|
|
|
-{
|
|
|
- lock();
|
|
|
- drawPos = pos;
|
|
|
- unlock();
|
|
|
-}
|
|
|
-
|
|
|
-void Schrift::setSchriftSize( int sg ) // setzt die Schriftgröße
|
|
|
-{
|
|
|
- lock();
|
|
|
schriftSize = sg;
|
|
|
- alphabet->setDrawSchriftSize( sg );
|
|
|
- unlock();
|
|
|
}
|
|
|
|
|
|
-void Schrift::setZeilenAbstand( int za ) // setzt den Zeilenabstand
|
|
|
+// Setzt den Zeilenabstand, der zum zeichnen verwendet werden soll
|
|
|
+// za: Der Zeilenabstand zum unteren Ende der darüber liegenden zeile in Pixeln
|
|
|
+void TextRenderer::setZeilenAbstand( int za )
|
|
|
{
|
|
|
- lock();
|
|
|
zeilenAbstand = za;
|
|
|
- alphabet->setZeilenAbstand( za );
|
|
|
- unlock();
|
|
|
}
|
|
|
|
|
|
-void Schrift::textFormatieren( Text *zText, int maxBreite, int schriftSize ) // fügt zeilenumbrüche ein
|
|
|
+// Setzt den Zeichenabstand, der zum zeichnen verwendet werden soll
|
|
|
+// za: Der Zeichenabstand zum unteren Ende der darüber liegenden zeile in Pixeln
|
|
|
+void TextRenderer::setZeichenAbstand( int za )
|
|
|
{
|
|
|
- lock();
|
|
|
- Alphabet *drawAlphabet = alphabet->zAlphabet( (unsigned char)schriftSize );
|
|
|
- if( !drawAlphabet )
|
|
|
- {
|
|
|
- for( int i = 0; i < 256; ++i )
|
|
|
- {
|
|
|
- drawAlphabet = alphabet->zAlphabet( (unsigned char)( schriftSize - i ) );
|
|
|
- if( drawAlphabet )
|
|
|
- break;
|
|
|
- drawAlphabet = alphabet->zAlphabet( (unsigned char)( schriftSize + i ) );
|
|
|
- if( drawAlphabet )
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- if( drawAlphabet )
|
|
|
- drawAlphabet->textFormatieren( zText, maxBreite, schriftSize );
|
|
|
- unlock();
|
|
|
+ zeichenAbstand = za;
|
|
|
}
|
|
|
|
|
|
-void Schrift::renderText( Text *zTxt, Bild &zRObj, std::function< int( int, int, int ) > f ) // zeichnet txt nach zRObj
|
|
|
+// Fügt Zeilenumbrüche in den Text ein, so dass er bei einer vorgegebenen Breite follständig angezeigt wird
|
|
|
+// zText: Der text, in den die Zeilenumbrüche eingefügt werden sollen
|
|
|
+// maxBreite: Die Breite in Pixeln auf der der Text follständig angezeigt werden soll
|
|
|
+void TextRenderer::textFormatieren( Text *zTxt, int maxBreite )
|
|
|
{
|
|
|
- lock();
|
|
|
- Alphabet *drawAlphabet = alphabet->zAlphabet( (unsigned char)schriftSize );
|
|
|
- if( !drawAlphabet )
|
|
|
+ int lastPos = -1;
|
|
|
+ int x = 0;
|
|
|
+ const char *txt = zTxt->getText();
|
|
|
+ Text result = txt;
|
|
|
+ int len = zTxt->getLength();
|
|
|
+ for( int i = 0; txt[ i ]; ++i )
|
|
|
{
|
|
|
- for( int i = 0; i < 256; ++i )
|
|
|
+ if( txt[ i ] == ' ' )
|
|
|
{
|
|
|
- drawAlphabet = alphabet->zAlphabet( (unsigned char)( schriftSize - i ) );
|
|
|
- if( drawAlphabet )
|
|
|
- break;
|
|
|
- drawAlphabet = alphabet->zAlphabet( (unsigned char)( schriftSize + i ) );
|
|
|
- if( drawAlphabet )
|
|
|
- break;
|
|
|
+ lastPos = i;
|
|
|
+ x += schriftSize / 2 + zeichenAbstand;
|
|
|
+ continue;
|
|
|
}
|
|
|
- }
|
|
|
- if( drawAlphabet )
|
|
|
- {
|
|
|
- drawAlphabet->setDrawPosition( drawPos.x, drawPos.y );
|
|
|
- drawAlphabet->render( zTxt, zRObj, f );
|
|
|
- }
|
|
|
- unlock();
|
|
|
-}
|
|
|
-
|
|
|
-void Schrift::renderText( Text *zTxt, Bild &zRObj, int f ) // zeichnet txt nach zRObj
|
|
|
-{
|
|
|
- lock();
|
|
|
- Alphabet *drawAlphabet = alphabet->zAlphabet( (unsigned char)schriftSize );
|
|
|
- if( !drawAlphabet )
|
|
|
- {
|
|
|
- for( int i = 0; i < 256; ++i )
|
|
|
+ if( txt[ i ] == '\t' )
|
|
|
{
|
|
|
- drawAlphabet = alphabet->zAlphabet( (unsigned char)( schriftSize - i ) );
|
|
|
- if( drawAlphabet )
|
|
|
- break;
|
|
|
- drawAlphabet = alphabet->zAlphabet( (unsigned char)( schriftSize + i ) );
|
|
|
- if( drawAlphabet )
|
|
|
- break;
|
|
|
+ lastPos = i;
|
|
|
+ x += schriftSize + zeichenAbstand;
|
|
|
+ continue;
|
|
|
}
|
|
|
- }
|
|
|
- if( drawAlphabet )
|
|
|
- {
|
|
|
- drawAlphabet->setDrawPosition( drawPos.x, drawPos.y );
|
|
|
- drawAlphabet->render( zTxt, zRObj, f );
|
|
|
- }
|
|
|
- unlock();
|
|
|
-}
|
|
|
-
|
|
|
-void Schrift::renderText( Text *zTxt, Bild &zRObj, int cpos, int cf, int fbeg, int ff, std::function< int( int, int, int ) > f )
|
|
|
-{
|
|
|
- lock();
|
|
|
- Alphabet *drawAlphabet = alphabet->zAlphabet( (unsigned char)schriftSize );
|
|
|
- if( !drawAlphabet )
|
|
|
- {
|
|
|
- for( int i = 0; i < 256; ++i )
|
|
|
+ if( txt[ i ] == '\n' )
|
|
|
{
|
|
|
- drawAlphabet = alphabet->zAlphabet( (unsigned char)( schriftSize - i ) );
|
|
|
- if( drawAlphabet )
|
|
|
- break;
|
|
|
- drawAlphabet = alphabet->zAlphabet( (unsigned char)( schriftSize + i ) );
|
|
|
- if( drawAlphabet )
|
|
|
- break;
|
|
|
+ x = 0;
|
|
|
+ lastPos = -1;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if( txt[ i ] == '\r' && len - i >= 11 )
|
|
|
+ {
|
|
|
+ i += 10;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ x += getCharWidth( txt[ i ] ) + zeichenAbstand;
|
|
|
+ if( x > maxBreite && lastPos > -1 )
|
|
|
+ {
|
|
|
+ result.ersetzen( lastPos, lastPos + 1, "\n" );
|
|
|
+ x = 0;
|
|
|
+ i = lastPos;
|
|
|
+ lastPos = -1;
|
|
|
}
|
|
|
}
|
|
|
- if( drawAlphabet )
|
|
|
- {
|
|
|
- drawAlphabet->setDrawPosition( drawPos.x, drawPos.y );
|
|
|
- drawAlphabet->render( zTxt, zRObj, cpos, cf, fbeg, ff, f );
|
|
|
- }
|
|
|
- unlock();
|
|
|
-}
|
|
|
-
|
|
|
-void Schrift::renderText( Text *zTxt, Bild &zRObj, int cpos, int cf, int fbeg, int ff, int f )
|
|
|
-{
|
|
|
- lock();
|
|
|
- Alphabet *drawAlphabet = alphabet->zAlphabet( (unsigned char)schriftSize );
|
|
|
- if( !drawAlphabet )
|
|
|
+ zTxt->setText( result );
|
|
|
+}
|
|
|
+
|
|
|
+// Zeichnet einen Bestimmten Text mit Cursor und einfärbung auf ein Bild
|
|
|
+// Nutze (setPosition) und (setDrawSchriftGröße) um die Position und die Größe zu verändern
|
|
|
+// x: x position des ersten zeichens
|
|
|
+// y: y position des ersten zeichens
|
|
|
+// txt: Der Text, der gezeichnet werden soll
|
|
|
+// zRObj: Das Bild, auf das gezeichnet werden soll
|
|
|
+// cpos: Die position des Cursors im Text
|
|
|
+// cf: Die Farbe des Cursors
|
|
|
+// fbeg: Die Position des Zeichens im Text, wo die Einfärbung beginnen soll. Der Text wird von dort bis zur Cursorposition eingefärbt
|
|
|
+// ff: Die Hintergrund Farbe des eingefärbten Textes
|
|
|
+// f: Eine Funktion die für jeden Buchstaben aufgerufen wird und seine Farbe zurückgibt
|
|
|
+void TextRenderer::renderText( int x, int y, const char *txt, Bild &zRObj, std::function< int( int, int, int ) > f, int cpos, int cf, int fbeg, int ff )
|
|
|
+{
|
|
|
+ if( !s )
|
|
|
+ return;
|
|
|
+ int zRObjBr = zRObj.getBreite();
|
|
|
+ int zRObjHi = zRObj.getHeight();
|
|
|
+ int beginX = x;
|
|
|
+ int zh = getZeilenHeight();
|
|
|
+ if( y + ( zh + zeilenAbstand ) * Text( txt ).anzahlVon( '\n' ) + zh < 0 || x >= zRObjBr || y >= zRObjHi )
|
|
|
+ return;
|
|
|
+ bool faerb = 0;
|
|
|
+ for( int i = 0; txt[ i ]; ++i )
|
|
|
{
|
|
|
- for( int i = 0; i < 256; ++i )
|
|
|
+ if( i == fbeg )
|
|
|
+ faerb = !faerb;
|
|
|
+ if( i == cpos )
|
|
|
{
|
|
|
- drawAlphabet = alphabet->zAlphabet( (unsigned char)( schriftSize - i ) );
|
|
|
- if( drawAlphabet )
|
|
|
- break;
|
|
|
- drawAlphabet = alphabet->zAlphabet( (unsigned char)( schriftSize + i ) );
|
|
|
- if( drawAlphabet )
|
|
|
- break;
|
|
|
+ zRObj.drawLinieVAlpha( x, y, zh, cf );
|
|
|
+ faerb = !faerb;
|
|
|
}
|
|
|
+ if( txt[ i ] == ' ' )
|
|
|
+ {
|
|
|
+ if( faerb )
|
|
|
+ zRObj.alphaRegion( x, y, schriftSize / 2 + zeichenAbstand, zh, ff );
|
|
|
+ x += schriftSize / 2 + zeichenAbstand;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if( txt[ i ] == '\t' )
|
|
|
+ {
|
|
|
+ if( faerb )
|
|
|
+ zRObj.alphaRegion( x, y, schriftSize + zeichenAbstand, zh, ff );
|
|
|
+ x += schriftSize + zeichenAbstand;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if( txt[ i ] == '\n' )
|
|
|
+ {
|
|
|
+ y += zh + zeilenAbstand;
|
|
|
+ x = beginX;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if( txt[ i ] == '\r' && textLength( txt ) - i >= 11 )
|
|
|
+ {
|
|
|
+ i += 3;
|
|
|
+ Text *hex1 = Text( txt ).getTeilText( i, i + 6 );
|
|
|
+ Text *hex2 = Text( txt ).getTeilText( i + 6, i + 8 );
|
|
|
+ int nf = ( TextZuInt( hex1->getText(), 16 ) << 8 ) |
|
|
|
+ ( TextZuInt( hex2->getText(), 16 ) );
|
|
|
+ f = [ nf ]( int a, int b, int c )
|
|
|
+ {
|
|
|
+ return nf;
|
|
|
+ };
|
|
|
+ hex1->release();
|
|
|
+ hex2->release();
|
|
|
+ i += 7;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ renderChar( x, y, txt[ i ], zRObj, faerb, ff, f( x, y, i ) );
|
|
|
}
|
|
|
- if( drawAlphabet )
|
|
|
+ if( textLength( txt ) == cpos )
|
|
|
+ zRObj.drawLinieVAlpha( x, y, zh, cf );
|
|
|
+}
|
|
|
+
|
|
|
+// Zeichnet einen Bestimmten Text mit Cursor und einfärbung auf ein Bild
|
|
|
+// Nutze (setPosition) und (setDrawSchriftGröße) um die Position und die Größe zu verändern
|
|
|
+// x: x position des ersten zeichens
|
|
|
+// y: y position des ersten zeichens
|
|
|
+// txt: Der Text, der gezeichnet werden soll
|
|
|
+// zRObj: Das Bild, auf das gezeichnet werden soll
|
|
|
+// cpos: Die position des Cursors im Text
|
|
|
+// cf: Die Farbe des Cursors
|
|
|
+// fbeg: Die Position des Zeichens im Text, wo die Einfärbung beginnen soll. Der Text wird von dort bis zur Cursorposition eingefärbt
|
|
|
+// ff: Die Hintergrund Farbe des eingefärbten Textes
|
|
|
+// f: Die Farbe, in der der Text gezeichnet werden soll
|
|
|
+void TextRenderer::renderText( int x, int y, const char *txt, Bild &zRObj, int f, int cpos, int cf, int fbeg, int ff )
|
|
|
+{
|
|
|
+ return renderText( x, y, txt, zRObj, [ f ]( int a, int b, int c ) { return f; }, cpos, cf, fbeg, ff );
|
|
|
+}
|
|
|
+
|
|
|
+// Zeichnet einen Bestimmten Buchstaben mit einfärbung auf ein Bild
|
|
|
+// Nutze (setPosition) und (setDrawSchriftGröße) um die Position und die Größe zu verändern
|
|
|
+// x: x position des ersten zeichens
|
|
|
+// y: y position des ersten zeichens
|
|
|
+// txt: Der Text, der gezeichnet werden soll
|
|
|
+// zRObj: Das Bild, auf das gezeichnet werden soll
|
|
|
+// selected: 1, falls das zeichen eingefärbt sein soll
|
|
|
+// ff: Die Hintergrund Farbe des eingefärbten Textes
|
|
|
+// f: Die Farbe, in der der Text gezeichnet werden soll
|
|
|
+void TextRenderer::renderChar( int &x, int y, char c, Bild &zRObj, bool selected, int ff, int f )
|
|
|
+{
|
|
|
+ if( !s )
|
|
|
+ return;
|
|
|
+ Alphabet *a = s->zAlphabet( schriftSize );
|
|
|
+ Buchstabe *b = a->zBuchstabe( c );
|
|
|
+ if( b )
|
|
|
{
|
|
|
- drawAlphabet->setDrawPosition( drawPos.x, drawPos.y );
|
|
|
- drawAlphabet->render( zTxt, zRObj, cpos, cf, fbeg, ff, f );
|
|
|
+ if( x >= zRObj.getBreite() )
|
|
|
+ return;
|
|
|
+ if( zRObj.isAreaDrawable( x, y, getCharWidth( c ), getCharHeight( c ) ) )
|
|
|
+ {
|
|
|
+ if( selected )
|
|
|
+ {
|
|
|
+ int br = getCharWidth( c ) + zeichenAbstand;
|
|
|
+ zRObj.alphaRegion( x, y, br, getZeilenHeight(), ff );
|
|
|
+ }
|
|
|
+ if( b->getBuff() )
|
|
|
+ {
|
|
|
+ const Punkt &zRObjGr = zRObj.getDrawGr();
|
|
|
+ const Punkt &zRObjPos = zRObj.getDrawPos();
|
|
|
+ const Punkt &zRObjOff = zRObj.getDrawOff();
|
|
|
+ int xp = x + zRObjOff.x, yp = y + zRObjOff.y;
|
|
|
+ int xs = xp < zRObjPos.x ? ( zRObjPos.x - xp ) : 0, ys = yp < zRObjPos.y ? ( zRObjPos.y - yp ) : 0;
|
|
|
+ int br = b->getBreite(), h = b->getHeight();
|
|
|
+ unsigned char a2 = (unsigned char)( 255 - ( f >> 24 ) );
|
|
|
+ f &= 0x00FFFFFF;
|
|
|
+ if( schriftSize == b->getSchriftSize() )
|
|
|
+ {
|
|
|
+ if( xp >= zRObjGr.x || yp >= zRObjGr.y || xp + br < zRObjPos.x || yp + h < zRObjPos.y )
|
|
|
+ return;
|
|
|
+ br = ( xp + br ) > zRObjGr.x ? ( zRObjGr.x - xp ) : br;
|
|
|
+ h = ( yp + h ) > zRObjGr.y ? ( zRObjGr.y - yp ) : h;
|
|
|
+ if( !a2 )
|
|
|
+ {
|
|
|
+ int xx, ygr = ( ys - 1 ) * b->getBreite(), ygr2 = ( yp + ys - 1 ) * zRObj.getBreite();
|
|
|
+ for( int yy = ys; yy < h; ++yy )
|
|
|
+ {
|
|
|
+ ygr += b->getBreite();
|
|
|
+ ygr2 += zRObj.getBreite();
|
|
|
+ for( xx = xs; xx < br; ++xx )
|
|
|
+ zRObj.alphaPixel( xp + xx + ygr2, f | ( b->getBuff()[ xx + ygr ] << 24 ) );
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ int a;
|
|
|
+ int xx, ygr = ( ys - 1 ) * b->getBreite(), ygr2 = ( yp + ys - 1 ) * zRObj.getBreite();
|
|
|
+ for( int yy = ys; yy < h; ++yy )
|
|
|
+ {
|
|
|
+ ygr += b->getBreite();
|
|
|
+ ygr2 += zRObj.getBreite();
|
|
|
+ for( xx = xs; xx < br; ++xx )
|
|
|
+ {
|
|
|
+ a = b->getBuff()[ xx + ygr ] - a2;
|
|
|
+ if( a > 0 )
|
|
|
+ zRObj.alphaPixel( xp + xx + ygr2, f | ( a << 24 ) );
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ double xoff = (double)b->getSchriftSize() / (double)schriftSize,
|
|
|
+ yoff = (double)b->getSchriftSize() / (double)schriftSize;
|
|
|
+ double x = xs * xoff, y = ys * yoff;
|
|
|
+ int maxX = getCharWidth( c ), maxY = getCharHeight( c );
|
|
|
+ maxX = ( xp + maxX ) >= zRObjGr.x ? ( zRObjGr.x - xp ) : maxX;
|
|
|
+ maxY = ( yp + maxY ) >= zRObjGr.y ? ( zRObjGr.y - yp ) : maxY;
|
|
|
+ if( !a2 )
|
|
|
+ {
|
|
|
+ int dx, ygr, ygr2;
|
|
|
+ for( int dy = ys; dy < maxY; ++dy )
|
|
|
+ {
|
|
|
+ ygr2 = ( yp + dy ) * zRObj.getBreite();
|
|
|
+ ygr = (int)y * br;
|
|
|
+ for( dx = xs; dx < maxX; ++dx )
|
|
|
+ {
|
|
|
+ zRObj.alphaPixel( xp + dx + ygr2, f | ( b->getBuff()[ (int)x + ygr ] << 24 ) );
|
|
|
+ x += xoff;
|
|
|
+ }
|
|
|
+ x = xs;
|
|
|
+ y += yoff;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ int a, dx, ygr, ygr2;
|
|
|
+ for( int dy = ys; dy < maxY; ++dy )
|
|
|
+ {
|
|
|
+ ygr2 = ( yp + dy ) * zRObj.getBreite();
|
|
|
+ ygr = (int)y * br;
|
|
|
+ for( dx = xs; dx < maxX; ++dx )
|
|
|
+ {
|
|
|
+ a = b->getBuff()[ (int)x + ygr ] - a2;
|
|
|
+ zRObj.alphaPixel( xp + dx + ygr2, f | ( a << 24 ) );
|
|
|
+ x += xoff;
|
|
|
+ }
|
|
|
+ x = xs;
|
|
|
+ y += yoff;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ x += getCharWidth( c ) + zeichenAbstand;
|
|
|
}
|
|
|
- unlock();
|
|
|
}
|
|
|
|
|
|
-// constant
|
|
|
-Alphabet *Schrift::getAlphabet( int sg ) const // gibt einen Alphaberarray zurück
|
|
|
+// Gibt die Schriftgröße zurück, die zum Zeichnen verwendet wird
|
|
|
+int TextRenderer::getSchriftSize() const
|
|
|
{
|
|
|
- return alphabet->getAlphabet( (unsigned char)sg );
|
|
|
+ return schriftSize;
|
|
|
}
|
|
|
|
|
|
-Alphabet *Schrift::zAlphabet( int sg ) const
|
|
|
+// Gibt den Abstand in Pixeln zum unteren Ende der darüber ligenden Zeile zurück
|
|
|
+int TextRenderer::getZeilenabstand() const
|
|
|
{
|
|
|
- return alphabet->zAlphabet( (unsigned char)sg );
|
|
|
+ return zeilenAbstand;
|
|
|
}
|
|
|
|
|
|
-Alphabet *Schrift::getAlphabetI( int index ) const
|
|
|
+// Ermittelt, wie viele Pixel benötigt werden, um einen Bestimmten Text vollständig darzustellen
|
|
|
+// txt: Der Text, von dem die Breite in Pixeln ermitelt werden soll
|
|
|
+int TextRenderer::getTextBreite( const char *txt ) const
|
|
|
{
|
|
|
- return alphabet->getAlphabetI( index, 0 );
|
|
|
+ int ret = 0;
|
|
|
+ int tmp = 0;
|
|
|
+ for( int i = 0; txt[ i ]; ++i )
|
|
|
+ {
|
|
|
+ if( txt[ i ] == '\n' )
|
|
|
+ {
|
|
|
+ if( tmp > ret )
|
|
|
+ ret = tmp;
|
|
|
+ tmp = 0;
|
|
|
+ }
|
|
|
+ else if( txt[ i ] == '\r' )
|
|
|
+ {
|
|
|
+ i += 10;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ else if( txt[ i ] == '\t' )
|
|
|
+ tmp += schriftSize + zeichenAbstand;
|
|
|
+ else if( txt[ i ] == ' ' )
|
|
|
+ tmp += schriftSize / 2 + zeichenAbstand;
|
|
|
+ else
|
|
|
+ tmp += getCharWidth( txt[ i ] ) + zeichenAbstand;
|
|
|
+ }
|
|
|
+ if( tmp > ret )
|
|
|
+ ret = tmp;
|
|
|
+ return ret;
|
|
|
}
|
|
|
|
|
|
-Alphabet *Schrift::zAlphabetI( int index ) const
|
|
|
+// Ermittelt, wie viele Pixel benötigt werden, um einen Bestimmten Text vollständig darzustellen
|
|
|
+// txt: Der Text, von dem die Höhe in Pixeln ermitelt werden soll
|
|
|
+int TextRenderer::getTextHeight( const char *txt ) const
|
|
|
{
|
|
|
- return alphabet->zAlphabetI( index, 0 );
|
|
|
+ int hi = getZeilenHeight();
|
|
|
+ return hi + ( ( hi + zeilenAbstand ) * Text( txt ).anzahlVon( '\n' ) );
|
|
|
}
|
|
|
|
|
|
-unsigned char Schrift::getAlphabetAnzahl() const // gibt die anzahl von in der Schrift enthaltenen Alphabeten zurück
|
|
|
+// Ermittelt, wie viele Pixel benötigt werden, um einen Bestimmten Buchstaben vollständig darzustellen
|
|
|
+// c: Der Buchstabe, von dem die Breite in Pixeln ermitelt werden soll
|
|
|
+int TextRenderer::getCharWidth( const char c ) const
|
|
|
{
|
|
|
- return alphabetAnzahl;
|
|
|
+ if( !s )
|
|
|
+ return 0;
|
|
|
+ Alphabet *a = s->zAlphabet( schriftSize );
|
|
|
+ Buchstabe *b = a->zBuchstabe( c );
|
|
|
+ if( b )
|
|
|
+ return (int)( ( (double)b->getBreite() / (double)b->getSchriftSize() ) * (double)schriftSize + 0.5 );
|
|
|
+ return 0;
|
|
|
}
|
|
|
|
|
|
-int Schrift::getSchriftSize() const // gibt die Schriftgröße zurück
|
|
|
+// Ermittelt, wie viele Pixel benötigt werden, um einen Bestimmten Text vollständig darzustellen
|
|
|
+// c: Der Buchstabe, von dem die Höhe in Pixeln ermitelt werden soll
|
|
|
+int TextRenderer::getCharHeight( const char c ) const
|
|
|
{
|
|
|
- return schriftSize;
|
|
|
+ if( !s )
|
|
|
+ return 0;
|
|
|
+ Alphabet *a = s->zAlphabet( schriftSize );
|
|
|
+ Buchstabe *b = a->zBuchstabe( c );
|
|
|
+ if( b )
|
|
|
+ return (int)( ( (double)b->getHeight() / (double)b->getSchriftSize() ) * (double)schriftSize + 0.5 );
|
|
|
+ return 0;
|
|
|
}
|
|
|
|
|
|
-int Schrift::getZeilenabstand() const // gibt den Zeilenabstand zurück
|
|
|
+// Gibt den Abstand in Pixeln zum unteren Ende der darüber ligenden Zeile zurück
|
|
|
+int TextRenderer::getZeilenAbstand() const
|
|
|
{
|
|
|
return zeilenAbstand;
|
|
|
}
|
|
|
|
|
|
-int Schrift::getDrawX() const // gibt die Zeichenposition zurück
|
|
|
-{
|
|
|
- return drawPos.x;
|
|
|
-}
|
|
|
-
|
|
|
-int Schrift::getDrawY() const
|
|
|
+// Gibt die skallierte Höhe zurück, die eine gezeichnete Zeile in Pixeln benötigt
|
|
|
+int TextRenderer::getZeilenHeight() const
|
|
|
{
|
|
|
- return drawPos.y;
|
|
|
-}
|
|
|
-
|
|
|
-const Punkt &Schrift::getDrawPosition() const
|
|
|
-{
|
|
|
- return drawPos;
|
|
|
-}
|
|
|
-
|
|
|
-int Schrift::getTextBreite( Text *zTxt ) const // gibt die Breite des Textes zurück
|
|
|
-{
|
|
|
- Alphabet *drawAlphabet = alphabet->zAlphabet( (unsigned char)schriftSize );
|
|
|
- if( !drawAlphabet )
|
|
|
+ int zh = 0;
|
|
|
+ for( int i = 0; i < 256; ++i )
|
|
|
{
|
|
|
- for( int i = 0; i < 256; ++i )
|
|
|
- {
|
|
|
- drawAlphabet = alphabet->zAlphabet( (unsigned char)( schriftSize - i ) );
|
|
|
- if( drawAlphabet )
|
|
|
- break;
|
|
|
- drawAlphabet = alphabet->zAlphabet( (unsigned char)( schriftSize + i ) );
|
|
|
- if( drawAlphabet )
|
|
|
- break;
|
|
|
- }
|
|
|
+ zh = maxInt( getCharHeight( (char)i ), zh );
|
|
|
}
|
|
|
- if( !drawAlphabet )
|
|
|
- return 0;
|
|
|
- return drawAlphabet->getTextBreite( zTxt );
|
|
|
+ return zh;
|
|
|
}
|
|
|
|
|
|
-int Schrift::getTextHeight( Text *zTxt ) const // gibt die Höhe des Textes zurück
|
|
|
+// Ermittelt das Zeichen im Text, auf das die Maus zeigt
|
|
|
+// txt: Der Text, auf den die Maus Zeigt
|
|
|
+// mausX: Die X Position der Maus in Pixeln Relativ zur Position des ersten Zeichens
|
|
|
+// mausY: Die Y Position der Maus in Pixeln Relativ zur Position des ersten Zeichens
|
|
|
+int TextRenderer::textPos( const char *txt, int mausX, int mausY ) const
|
|
|
{
|
|
|
- Alphabet *drawAlphabet = alphabet->zAlphabet( (unsigned char)schriftSize );
|
|
|
- if( !drawAlphabet )
|
|
|
- {
|
|
|
- for( int i = 0; i < 256; ++i )
|
|
|
- {
|
|
|
- drawAlphabet = alphabet->zAlphabet( (unsigned char)( schriftSize - i ) );
|
|
|
- if( drawAlphabet )
|
|
|
- break;
|
|
|
- drawAlphabet = alphabet->zAlphabet( (unsigned char)( schriftSize + i ) );
|
|
|
- if( drawAlphabet )
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- if( !drawAlphabet )
|
|
|
- return 0;
|
|
|
- return drawAlphabet->getTextHeight( zTxt );
|
|
|
-}
|
|
|
-
|
|
|
-int Schrift::textPos( Text *zTxt, int mausX, int mausY ) const // gibt den Buchstaben zurück, auf den die Maus zeigt
|
|
|
-{
|
|
|
- Alphabet *drawAlphabet = alphabet->zAlphabet( (unsigned char)schriftSize );
|
|
|
- if( !drawAlphabet )
|
|
|
+ int tx = 0;
|
|
|
+ int ty = 0;
|
|
|
+ int sh = getZeilenHeight();
|
|
|
+ if( mausX < 0 || mausY < 0 )
|
|
|
+ return -1;
|
|
|
+ for( int i = 0; i < txt[ i ]; ++i )
|
|
|
{
|
|
|
- for( int i = 0; i < 256; ++i )
|
|
|
+ if( txt[ i ] == '\n' )
|
|
|
{
|
|
|
- drawAlphabet = alphabet->zAlphabet( (unsigned char)( schriftSize - i ) );
|
|
|
- if( drawAlphabet )
|
|
|
- break;
|
|
|
- drawAlphabet = alphabet->zAlphabet( (unsigned char)( schriftSize + i ) );
|
|
|
- if( drawAlphabet )
|
|
|
- break;
|
|
|
+ ty += sh + zeilenAbstand;
|
|
|
+ tx = 0;
|
|
|
+ if( mausY < ty )
|
|
|
+ return i;
|
|
|
}
|
|
|
+ if( txt[ i ] == '\t' )
|
|
|
+ tx += schriftSize + zeichenAbstand;
|
|
|
+ if( txt[ i ] == ' ' )
|
|
|
+ tx += schriftSize / 2 + zeichenAbstand;
|
|
|
+ tx += getCharWidth( txt[ i ] );
|
|
|
+ int txpl = getCharWidth( txt[ i + 1 ] ) / 2;
|
|
|
+ if( mausX < tx - txpl && mausY < ty + sh + zeilenAbstand )
|
|
|
+ return i;
|
|
|
}
|
|
|
- if( !drawAlphabet )
|
|
|
- return 0;
|
|
|
- return drawAlphabet->textPos( zTxt, mausX, mausY );
|
|
|
+ if( mausY < ty + sh + zeilenAbstand )
|
|
|
+ return textLength( txt );
|
|
|
+ return -1;
|
|
|
}
|
|
|
|
|
|
-// Reference Counting
|
|
|
-Schrift *Schrift::getThis()
|
|
|
+TextRenderer *TextRenderer::getThis()
|
|
|
{
|
|
|
- ++ref;
|
|
|
+ ref++;
|
|
|
return this;
|
|
|
}
|
|
|
|
|
|
-Schrift *Schrift::release()
|
|
|
+TextRenderer *TextRenderer::release()
|
|
|
{
|
|
|
- --ref;
|
|
|
- if( ref == 0 )
|
|
|
+ if( !--ref )
|
|
|
delete this;
|
|
|
return 0;
|
|
|
}
|