Browse Source

Neue Methode zum setzen der farbe von neuen textfeldzeilen hinzugefügt

Kolja Strohm 5 years ago
parent
commit
9a97333c07
2 changed files with 39 additions and 1 deletions
  1. 35 1
      TextFeld.cpp
  2. 4 0
      TextFeld.h

+ 35 - 1
TextFeld.cpp

@@ -382,7 +382,8 @@ void TextFeld::addZeile( const char *zeile ) // f
     if( tm->text )
     {
         Text *txt = new Text( zeile );
-        txt->append( "\n" );
+        if( zeile[ txt->getLength() - 1 ] != '\n' )
+            txt->append( "\n" );
         TextRenderer *r = tm->renderer->z( 0 );
         if( tm->textStyle.get( tm->textStyle.getEintragAnzahl() - 1 ).rendererIndex < tm->renderer->getEintragAnzahl() )
             r = tm->renderer->z( tm->textStyle.get( tm->textStyle.getEintragAnzahl() - 1 ).rendererIndex );
@@ -405,6 +406,39 @@ void TextFeld::addZeile( const char *zeile ) // f
     }
 }
 
+// Fügt eine Zeile an den Text an
+//  zeile: Die neue Zeile
+//  color: Die Farbe der Zeile
+void TextFeld::addZeile( const char *zeile, int color )
+{
+    if( tm->text )
+    {
+        Text *txt = new Text( zeile );
+        if( zeile[ txt->getLength() - 1 ] != '\n' )
+            txt->append( "\n" );
+        TextRenderer * r = tm->renderer->z( 0 );
+        if( tm->textStyle.get( tm->textStyle.getEintragAnzahl() - 1 ).rendererIndex < tm->renderer->getEintragAnzahl() )
+            r = tm->renderer->z( tm->textStyle.get( tm->textStyle.getEintragAnzahl() - 1 ).rendererIndex );
+        if( r )
+        {
+            bool vs = vertikalScrollBar && hatStyle( Style::VScroll );
+            int rbr = ( rahmen && hatStyle( Style::Rahmen ) ) ? rahmen->getRBreite() : 0;
+            r->setSchriftSize( tm->textStyle.get( tm->textStyle.getEintragAnzahl() - 1 ).fontSize );
+            r->textFormatieren( txt, gr.x - ( (int)vs * 15 ) - rbr * 2 );
+        }
+        lockZeichnung();
+        tm->text->append( txt->getText() );
+        setSchriftFarbe( tm->text->getLength() - txt->getLength(), tm->text->getLength(), color );
+        unlockZeichnung();
+        txt->release();
+        if( hatStyle( Style::VScroll ) )
+            updateVScroll();
+        if( hatStyle( Style::HScroll ) )
+            updateHScroll();
+        rend = 1;
+    }
+}
+
 // Deselectiert alle textabschnitte
 void TextFeld::deselectAuswahl()
 {

+ 4 - 0
TextFeld.h

@@ -127,6 +127,10 @@ namespace Framework
         // Fügt eine Zeile an den Text an
         //  zeile: Die neue Zeile
         __declspec( dllexport ) void addZeile( const char *zeile );
+        // Fügt eine Zeile an den Text an
+        //  zeile: Die neue Zeile
+        //  color: Die Farbe der Zeile
+        __declspec( dllexport ) void addZeile( const char *zeile, int color );
         // Deselectiert alle textabschnitte
         __declspec( dllexport ) void deselectAuswahl();
         // Setzt den ausgewählten textabschnitt fest