|
@@ -15,21 +15,12 @@
|
|
|
|
|
|
using namespace Framework;
|
|
|
|
|
|
-template<typename T, typename... U>
|
|
|
-size_t getAddress( std::function<T( U... )> f )
|
|
|
-{
|
|
|
- typedef T( fnType )( U... );
|
|
|
- fnType **fnPointer = f.template target<fnType *>();
|
|
|
- if( !fnPointer )
|
|
|
- return 0;
|
|
|
- return (size_t)*fnPointer;
|
|
|
-}
|
|
|
|
|
|
bool TextFeld::TextStyle::operator==( const TextStyle &rhs )
|
|
|
{
|
|
|
return fontSize == rhs.fontSize && fontColor == rhs.fontColor &&
|
|
|
selectedColor == rhs.selectedColor && selectedBackcroundColor == rhs.selectedBackcroundColor &&
|
|
|
- underlined == rhs.underlined && selected == rhs.selected && getAddress( onClick ) == getAddress( rhs.onClick ) && rendererIndex == rhs.rendererIndex;
|
|
|
+ underlined == rhs.underlined && selected == rhs.selected && interactParam == rhs.interactParam && rendererIndex == rhs.rendererIndex;
|
|
|
}
|
|
|
|
|
|
|
|
@@ -47,7 +38,7 @@ TextFeld::TextStyleManager::TextStyleManager()
|
|
|
current.selectedColor = 0xFFFFFFFF;
|
|
|
current.selectedBackcroundColor = 0xFF0000FF;
|
|
|
current.underlined = 0;
|
|
|
- current.onClick = 0;
|
|
|
+ current.interactParam = 0;
|
|
|
current.rendererIndex = 0;
|
|
|
textStyle.add( current );
|
|
|
}
|
|
@@ -210,6 +201,16 @@ bool TextFeld::TextStyleManager::nextStyle()
|
|
|
return text && index < text->getLength();
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+bool TextFeld::TextStyleManager::stepTo( int index )
|
|
|
+{
|
|
|
+ this->index = index;
|
|
|
+ current = getTextStyle( index );
|
|
|
+ return text && index < text->getLength();
|
|
|
+}
|
|
|
+
|
|
|
|
|
|
void TextFeld::TextStyleManager::resetIteration()
|
|
|
{
|
|
@@ -263,6 +264,7 @@ TextFeld::TextFeld()
|
|
|
tickVal( 0 ),
|
|
|
mausKlick( 0 )
|
|
|
{
|
|
|
+ charEvent = 0;
|
|
|
horizontalScrollBar = new HScrollBar();
|
|
|
vertikalScrollBar = new VScrollBar();
|
|
|
this->setMausEreignis( _ret1ME );
|
|
@@ -336,6 +338,13 @@ int TextFeld::getTextWidth() const
|
|
|
return maxBr;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+void TextFeld::setCharEvent( std::function< void( int, int, MausEreignis me ) > charEvent )
|
|
|
+{
|
|
|
+ this->charEvent = charEvent;
|
|
|
+}
|
|
|
+
|
|
|
void TextFeld::setText( Text * txt )
|
|
|
{
|
|
|
lockZeichnung();
|
|
@@ -387,6 +396,7 @@ void TextFeld::setText( const char *txt )
|
|
|
|
|
|
|
|
|
|
|
|
+
|
|
|
void TextFeld::setFormattedText( const char *txt )
|
|
|
{
|
|
|
lockZeichnung();
|
|
@@ -401,7 +411,7 @@ void TextFeld::setFormattedText( const char *txt )
|
|
|
current.selectedColor = 0xFFFFFFFF;
|
|
|
current.selectedBackcroundColor = 0xFF0000FF;
|
|
|
current.underlined = 0;
|
|
|
- current.onClick = 0;
|
|
|
+ current.interactParam = 0;
|
|
|
current.rendererIndex = 0;
|
|
|
tm->textStyle.add( current );
|
|
|
Text result = "";
|
|
@@ -454,6 +464,13 @@ void TextFeld::setFormattedText( const char *txt )
|
|
|
current.underlined = 0;
|
|
|
tm->textStyle.add( current );
|
|
|
break;
|
|
|
+ case 8:
|
|
|
+ current.interactParam = 0;
|
|
|
+ current.interactParam |= (unsigned char)txt[ ++i ] << 24;
|
|
|
+ current.interactParam |= (unsigned char)txt[ ++i ] << 16;
|
|
|
+ current.interactParam |= (unsigned char)txt[ ++i ] << 8;
|
|
|
+ current.interactParam |= (unsigned char)txt[ ++i ];
|
|
|
+ tm->textStyle.add( current );
|
|
|
default:
|
|
|
result.append( txt[ i ] );
|
|
|
}
|
|
@@ -470,6 +487,120 @@ void TextFeld::setFormattedText( const char *txt )
|
|
|
unlockZeichnung();
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+void TextFeld::addLineBreaks()
|
|
|
+{
|
|
|
+ if( !tm->text )
|
|
|
+ return;
|
|
|
+ int lastPos = -1;
|
|
|
+ int lastPos2 = -1;
|
|
|
+ int x = 0;
|
|
|
+ const char *txt = tm->text->getText();
|
|
|
+ Text result = "";
|
|
|
+ int len = tm->text->getLength();
|
|
|
+ lockZeichnung();
|
|
|
+ tm->resetIteration();
|
|
|
+ TextStyle last = tm->currentStyle();
|
|
|
+ for( int i = 0; i < len; ++i )
|
|
|
+ {
|
|
|
+ if( txt[ i ] == ' ' )
|
|
|
+ {
|
|
|
+ lastPos = i;
|
|
|
+ lastPos2 = result.getLength();
|
|
|
+ x += tm->zCurrentRenderer()->getTextBreite( " " );
|
|
|
+ result += " ";
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if( txt[ i ] == '\t' )
|
|
|
+ {
|
|
|
+ lastPos = i;
|
|
|
+ lastPos2 = result.getLength();
|
|
|
+ x += tm->zCurrentRenderer()->getTextBreite( "\t" );
|
|
|
+ result += "\t";
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if( txt[ i ] == '\n' )
|
|
|
+ {
|
|
|
+ x = 0;
|
|
|
+ lastPos = -1;
|
|
|
+ lastPos2 = -1;
|
|
|
+ result += "\n";
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ char buff[ 2 ] = { txt[ i ], 0 };
|
|
|
+ x += tm->zCurrentRenderer()->getTextBreite( buff );
|
|
|
+ result += buff;
|
|
|
+ if( x > getBreite() && lastPos > -1 )
|
|
|
+ {
|
|
|
+ result.remove( lastPos2, result.getLength() );
|
|
|
+ result += "\n";
|
|
|
+ x = 0;
|
|
|
+ i = lastPos;
|
|
|
+ lastPos = -1;
|
|
|
+ lastPos2 = -1;
|
|
|
+ tm->stepTo( lastPos );
|
|
|
+ last = tm->currentStyle();
|
|
|
+ }
|
|
|
+ tm->nextStyle();
|
|
|
+ if( last.fontSize != tm->current.fontSize )
|
|
|
+ {
|
|
|
+ char tmp[ 3 ] = { 2, (char)tm->current.fontSize, 0 };
|
|
|
+ result += tmp;
|
|
|
+ last.fontSize = tm->current.fontSize;
|
|
|
+ }
|
|
|
+ if( last.fontColor != tm->current.fontColor )
|
|
|
+ {
|
|
|
+ char tmp[ 6 ] = { 3, (char)((tm->current.fontColor >> 24) & 0xFF),
|
|
|
+ (char)( ( tm->current.fontColor >> 16 ) & 0xFF ),
|
|
|
+ (char)( ( tm->current.fontColor >> 8 ) & 0xFF ),
|
|
|
+ (char)( tm->current.fontColor & 0xFF ), 0 };
|
|
|
+ result += tmp;
|
|
|
+ last.fontColor = tm->current.fontColor;
|
|
|
+ }
|
|
|
+ if( last.selectedColor != tm->current.selectedColor )
|
|
|
+ {
|
|
|
+ char tmp[ 6 ] = { 4, (char)( ( tm->current.selectedColor >> 24 ) & 0xFF ),
|
|
|
+ (char)( ( tm->current.selectedColor >> 16 ) & 0xFF ),
|
|
|
+ (char)( ( tm->current.selectedColor >> 8 ) & 0xFF ),
|
|
|
+ (char)( tm->current.selectedColor & 0xFF ), 0 };
|
|
|
+ result += tmp;
|
|
|
+ last.selectedColor = tm->current.selectedColor;
|
|
|
+ }
|
|
|
+ if( last.selectedBackcroundColor != tm->current.selectedBackcroundColor )
|
|
|
+ {
|
|
|
+ char tmp[ 6 ] = { 5, (char)( ( tm->current.selectedBackcroundColor >> 24 ) & 0xFF ),
|
|
|
+ (char)( ( tm->current.selectedBackcroundColor >> 16 ) & 0xFF ),
|
|
|
+ (char)( ( tm->current.selectedBackcroundColor >> 8 ) & 0xFF ),
|
|
|
+ (char)( tm->current.selectedBackcroundColor & 0xFF ), 0 };
|
|
|
+ result += tmp;
|
|
|
+ last.selectedBackcroundColor = tm->current.selectedBackcroundColor;
|
|
|
+ }
|
|
|
+ if( last.underlined != tm->current.underlined )
|
|
|
+ {
|
|
|
+ char tmp[ 2 ] = { tm->current.underlined ? 1 : 7, 0 };
|
|
|
+ result += tmp;
|
|
|
+ last.underlined = tm->current.underlined;
|
|
|
+ }
|
|
|
+ if( last.interactParam != tm->current.interactParam )
|
|
|
+ {
|
|
|
+ char tmp[ 6 ] = { 8, (char)( ( tm->current.interactParam >> 24 ) & 0xFF ),
|
|
|
+ (char)( ( tm->current.interactParam >> 16 ) & 0xFF ),
|
|
|
+ (char)( ( tm->current.interactParam >> 8 ) & 0xFF ),
|
|
|
+ (char)( tm->current.interactParam & 0xFF ), 0 };
|
|
|
+ result += tmp;
|
|
|
+ last.interactParam = tm->current.interactParam;
|
|
|
+ }
|
|
|
+ if( last.rendererIndex != tm->current.rendererIndex )
|
|
|
+ {
|
|
|
+ char tmp[ 3 ] = { 6, (char)tm->current.rendererIndex, 0 };
|
|
|
+ result += tmp;
|
|
|
+ last.rendererIndex = tm->current.rendererIndex;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ unlockZeichnung();
|
|
|
+ setFormattedText( result );
|
|
|
+}
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
@@ -1036,8 +1167,8 @@ void TextFeld::doMausEreignis( MausEreignis & me )
|
|
|
if( mausChar >= 0 )
|
|
|
{
|
|
|
TextStyle s = tm->getTextStyle( mausChar );
|
|
|
- if( s.onClick )
|
|
|
- s.onClick( 0, this, me );
|
|
|
+ if( charEvent )
|
|
|
+ charEvent( mausChar, s.interactParam, me );
|
|
|
}
|
|
|
if( me.mx < gr.x - rbr - 15 )
|
|
|
{
|