Author: matt
Date: 2010-04-30 14:55:58 -0700 (Fri, 30 Apr 2010)
New Revision: 7572
Log:
Added a simplified (but fast) line drawing function which handles styles, but 
no tabs. I am skipping the text expansion alltogether.

Modified:
   branches/branch-1.3-STR2158-matt/FL/Fl_Text_Display.H
   branches/branch-1.3-STR2158-matt/src/Fl_Text_Display.cxx
   branches/branch-1.3-STR2158-matt/test/editor.cxx

Modified: branches/branch-1.3-STR2158-matt/FL/Fl_Text_Display.H
===================================================================
--- branches/branch-1.3-STR2158-matt/FL/Fl_Text_Display.H       2010-04-30 
21:09:44 UTC (rev 7571)
+++ branches/branch-1.3-STR2158-matt/FL/Fl_Text_Display.H       2010-04-30 
21:55:58 UTC (rev 7572)
@@ -147,8 +147,7 @@
                         Unfinished_Style_Cb unfinishedHighlightCB,
                         void *cbArg);
 
-    int position_style(int lineStartPos, int lineLen, int lineIndex,
-                       int dispIndex) const;
+    int position_style(int lineStartPos, int lineLen, int lineIndex) const;
     /** \todo FIXME : get set methods pointing on shortcut_ 
      have no effects as shortcut_ is unused in this class and derived! */
     int shortcut() const {return shortcut_;}

Modified: branches/branch-1.3-STR2158-matt/src/Fl_Text_Display.cxx
===================================================================
--- branches/branch-1.3-STR2158-matt/src/Fl_Text_Display.cxx    2010-04-30 
21:09:44 UTC (rev 7571)
+++ branches/branch-1.3-STR2158-matt/src/Fl_Text_Display.cxx    2010-04-30 
21:55:58 UTC (rev 7572)
@@ -732,8 +732,7 @@
   {
     charLen = Fl_Text_Buffer::expand_character( lineStr+charIndex, outIndex, 
expandedChar,
               mBuffer->tab_distance());
-    charStyle = position_style( lineStartPos, lineLen, charIndex,
-                                outIndex );
+    charStyle = position_style( lineStartPos, lineLen, charIndex);
     xStep += string_width( expandedChar, charLen, charStyle );
     outIndex += charLen;
   }
@@ -1452,10 +1451,38 @@
 
   dispIndexOffset = 0;
 
-  // FIXME: quick out to avoid insane calculations of line width
+  
+  
+  
+  // FIXME: simplified line drawing - quite OK so far, but no line wrapping or 
tab expansion
   X = text_area.x - mHorizOffset;
   startX = X;
-  draw_string( 0, startX, Y, text_area.x+text_area.w, lineStr, lineLen );
+  startIndex = 0;
+  if (!lineStr) {
+    // just clear the background
+    style = position_style(lineStartPos, lineLen, -1);
+    draw_string( style|BG_ONLY_MASK, text_area.x, Y, text_area.x+text_area.w, 
lineStr, lineLen );
+  }
+  style = position_style(lineStartPos, lineLen, i);
+  for (i=0; i<lineLen; ) {
+    int len = fl_utf8len(lineStr[i]);
+    charStyle = position_style(lineStartPos, lineLen, i);
+    if (charStyle!=style) {
+      int w = string_width( lineStr+startIndex, i-startIndex, style );
+      draw_string( style, startX, Y, startX+w, lineStr+startIndex, 
i-startIndex );
+      style = charStyle;
+      startX += w;
+      startIndex = i;
+    }
+    i += len;
+  }
+  int w = string_width( lineStr+startIndex, i-startIndex, style );
+  draw_string( style, startX, Y, startX+w, lineStr+startIndex, i-startIndex );
+  
+  // clear the rest of the line
+  startX += w;
+  style = position_style(lineStartPos, lineLen, i);
+  draw_string( style|BG_ONLY_MASK, startX, Y, text_area.x+text_area.w, 
lineStr, lineLen );
   return;
   
   
@@ -1470,8 +1497,7 @@
     charLen = charIndex >= lineLen ? 1 :
               Fl_Text_Buffer::expand_character( lineStr+charIndex, outIndex,
                                                 expandedChar, 
buf->tab_distance());
-    style = position_style( lineStartPos, lineLen, charIndex,
-                            outIndex + dispIndexOffset );
+    style = position_style( lineStartPos, lineLen, charIndex);
     charWidth = charIndex >= lineLen ? stdCharWidth :
                 string_width( expandedChar, charLen, style );
     if ( X + charWidth >= leftClip && charIndex >= leftCharIndex ) {
@@ -1501,12 +1527,10 @@
     charLen = charIndex >= lineLen ? 1 :
               Fl_Text_Buffer::expand_character( lineStr+charIndex, outIndex, 
expandedChar,
                                                 buf->tab_distance());
-    charStyle = position_style( lineStartPos, lineLen, charIndex,
-                                outIndex + dispIndexOffset );
+    charStyle = position_style( lineStartPos, lineLen, charIndex);
     for ( i = 0; i < charLen; i++ ) { // FIXME: this rips apart the utf-8 
sequneces
       if ( i != 0 && charIndex < lineLen && lineStr[ charIndex ] == '\t' )
-        charStyle = position_style( lineStartPos, lineLen,
-                                    charIndex, outIndex + dispIndexOffset );
+        charStyle = position_style( lineStartPos, lineLen, charIndex);
       if ( charStyle != style ) {
         draw_string( style|BG_ONLY_MASK, sX, Y, X, outStr, outPtr - outStr );
         outPtr = outStr;
@@ -1543,12 +1567,10 @@
     charLen = charIndex >= lineLen ? 1 :
               Fl_Text_Buffer::expand_character( lineStr+charIndex, outIndex, 
expandedChar,
                                                 buf->tab_distance());
-    charStyle = position_style( lineStartPos, lineLen, charIndex,
-                                outIndex + dispIndexOffset );
+    charStyle = position_style( lineStartPos, lineLen, charIndex );
     for ( i = 0; i < charLen; i++ ) { // FIXME: this rips apart the utf-8 
sequneces
       if ( i != 0 && charIndex < lineLen && lineStr[ charIndex ] == '\t' )
-        charStyle = position_style( lineStartPos, lineLen,
-                                    charIndex, outIndex + dispIndexOffset );
+        charStyle = position_style( lineStartPos, lineLen, charIndex );
       if ( charStyle != style ) {
         draw_string( style|TEXT_ONLY_MASK, startX, Y, X, outStr, outPtr - 
outStr );
         outPtr = outStr;
@@ -1802,8 +1824,8 @@
    Note that style is a somewhat incorrect name, drawing method would
    be more appropriate.
 */
-int Fl_Text_Display::position_style( int lineStartPos,
-                                     int lineLen, int lineIndex, int dispIndex 
) const {
+int Fl_Text_Display::position_style( int lineStartPos, int lineLen, int 
lineIndex) const 
+{
   Fl_Text_Buffer * buf = mBuffer;
   Fl_Text_Buffer *styleBuf = mStyleBuffer;
   int pos, style = 0;
@@ -1900,7 +1922,7 @@
   {
     charLen = Fl_Text_Buffer::expand_character( lineStr+charIndex, outIndex, 
expandedChar,
               mBuffer->tab_distance());
-    charStyle = position_style( lineStart, lineLen, charIndex, outIndex );
+    charStyle = position_style( lineStart, lineLen, charIndex );
     charWidth = string_width( expandedChar, charLen, charStyle );
     if ( X < xStep + ( posType == CURSOR_POS ? charWidth / 2 : charWidth ) ) {
       free((char *)lineStr);

Modified: branches/branch-1.3-STR2158-matt/test/editor.cxx
===================================================================
--- branches/branch-1.3-STR2158-matt/test/editor.cxx    2010-04-30 21:09:44 UTC 
(rev 7571)
+++ branches/branch-1.3-STR2158-matt/test/editor.cxx    2010-04-30 21:55:58 UTC 
(rev 7572)
@@ -792,7 +792,6 @@
 int main(int argc, char **argv) {
   textbuf = new Fl_Text_Buffer;
   textbuf->text(
-#if 0
                 "void saveas_cb() {\n"
                 "  Fl_Native_File_Chooser fnfc;\n"
                 "  fnfc.title(\"Save File As?\");\n"
@@ -800,7 +799,6 @@
                 "  if ( fnfc.show() ) return;\n"
                 "  save_file(fnfc.filename());\n"
                 "}\n\n"
-#else                
                 "Falsches Üben von Xylophonmusik quält jeden größeren Zwerg\n"
                 "(= Wrongful practicing of xylophone music tortures every 
larger dwarf)\n"
                 "\n"
@@ -827,8 +825,7 @@
                 "いろはにほへと ちりぬるを わかよ\n"
                 "たれそ つねならむ うゐのおくやま\n"
                 "けふこえて あさきゆめみし ゑひも\n"
-                "せす\n"
-#endif
+                "せす\n\n"
                 "Even colours and sweet perfume / Will eventually fade /\n"
                 "Even our world / Is not eternal /\n"
                 "The deep mountains of vanity / Cross them today /\n"

_______________________________________________
fltk-commit mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-commit

Reply via email to