diff --git a/src/apps/debugger/user_interface/gui/team_window/SourceView.cpp b/src/apps/debugger/user_interface/gui/team_window/SourceView.cpp index ea0015fcca..88d8ddc1b1 100644 --- a/src/apps/debugger/user_interface/gui/team_window/SourceView.cpp +++ b/src/apps/debugger/user_interface/gui/team_window/SourceView.cpp @@ -78,7 +78,7 @@ static rgb_color kSyntaxColors[] = { {0x44, 0x8a, 0, 255}, // SYNTAX_HIGHLIGHT_OPERATOR {0, 0, 0, 255}, // SYNTAX_HIGHLIGHT_TYPE {0x85, 0x19, 0x19, 255}, // SYNTAX_HIGHLIGHT_NUMERIC_LITERAL - {0x85, 0x19, 0x19, 255}, // SYNTAX_HIGHLIGHT_STRING_LITERAL + {0x3f, 0x48, 0x84, 255}, // SYNTAX_HIGHLIGHT_STRING_LITERAL {0xa1, 0x64, 0xe, 255}, // SYNTAX_HIGHLIGHT_COMMENT }; @@ -330,9 +330,11 @@ private: }; float _MaxLineWidth(); - void _FormatLine(const char* line, - BString& formattedLine, - int32* columns, int32 columnCount); + void _DrawLineSyntaxSection(const char* line, + int32 length, int32& _column, + BPoint& _offset); + inline void _DrawLineSegment(const char* line, + int32 length, BPoint& _offset); inline int32 _NextTabStop(int32 column) const; float _FormattedPosition(int32 line, int32 offset) const; @@ -1179,8 +1181,6 @@ SourceView::TextView::Draw(BRect updateRect) SetLowColor(ui_color(B_DOCUMENT_BACKGROUND_COLOR)); y = i * fFontInfo->lineHeight; - BString lineString; - _FormatLine(fSourceCode->LineAt(i), lineString, columns, syntaxCount); FillRect(BRect(0.0, y, kLeftTextMargin, y + fFontInfo->lineHeight), B_SOLID_LOW); @@ -1208,27 +1208,29 @@ SourceView::TextView::Draw(BRect updateRect) FillRect(BRect(kLeftTextMargin, y, Bounds().right, y + fFontInfo->lineHeight - 1), B_SOLID_LOW); - syntax_highlight_type currentHighlight = SYNTAX_HIGHLIGHT_NONE; - int32 currentColumn = 0; - SetHighColor(kSyntaxColors[currentHighlight]); - BPoint linePoint(kLeftTextMargin, y + fFontInfo->fontHeight.ascent); - for (int32 j = 0; j < syntaxCount; j++) { - int32 length = columns[j] - currentColumn; - if (length != 0) { - DrawString(lineString.String() + currentColumn, length, - linePoint); - currentColumn += length; - linePoint.x += fCharacterWidth * length; + syntax_highlight_type currentHighlight = SYNTAX_HIGHLIGHT_NONE; + SetHighColor(kSyntaxColors[currentHighlight]); + const char* lineData = fSourceCode->LineAt(i); + int32 lineLength = fSourceCode->LineLengthAt(i); + BPoint linePoint(kLeftTextMargin, y + fFontInfo->fontHeight.ascent); + int32 lineOffset = 0; + int32 currentColumn = 0; + for (int32 j = 0; j < syntaxCount; j++) { + int32 length = columns[j] - lineOffset; + if (length != 0) { + _DrawLineSyntaxSection(lineData + lineOffset, length, + currentColumn, linePoint); + lineOffset += length; } currentHighlight = types[j]; SetHighColor(kSyntaxColors[currentHighlight]); } // draw remainder, if any. - if (currentColumn < lineString.Length()) { - DrawString(lineString.String() + currentColumn, lineString.Length() - - currentColumn, linePoint); + if (lineOffset < lineLength) { + _DrawLineSyntaxSection(lineData + lineOffset, + lineLength - lineOffset, currentColumn, linePoint); } } @@ -1532,33 +1534,40 @@ SourceView::TextView::_MaxLineWidth() void -SourceView::TextView::_FormatLine(const char* line, BString& formattedLine, - int32* columns, int32 columnCount) +SourceView::TextView::_DrawLineSyntaxSection(const char* line, int32 length, + int32& _column, BPoint& _offset) { - int32 column = 0; - int32 columnAdjustments[columnCount]; - memset(columnAdjustments, 0, sizeof(columnAdjustments)); - for (int32 i = 0; line[i] != '\0'; i++) { - // TODO: That's probably not very efficient! + int32 start = 0; + int32 currentLength = 0; + for (int32 i = 0; i < length; i++) { if (line[i] == '\t') { - int32 nextTabStop = _NextTabStop(column); - int32 diff = nextTabStop - column; - for (; column < nextTabStop; column++) - formattedLine << ' '; - for (int32 j = 0; j < columnCount; j++) { - // syntax highlights need to be offset according - // to our tabstop adjustments as well. - if (columns[j] >= i && diff > 0) - columnAdjustments[j] += (diff - 1); - } - } else { - formattedLine << line[i]; - column++; - } + currentLength = i - start; + if (currentLength != 0) + _DrawLineSegment(line + start, currentLength, _offset); + + // set new starting offset to the position after this tab + start = i + 1; + int32 nextTabStop = _NextTabStop(_column); + int32 diff = nextTabStop - _column; + _column = nextTabStop; + _offset.x += diff * fCharacterWidth; + } else + _column++; } - for (int32 i = 0; i < columnCount; i++) - columns[i] += columnAdjustments[i]; + // draw last segment + currentLength = length - start; + if (currentLength > 0) + _DrawLineSegment(line + start, currentLength, _offset); +} + + +void +SourceView::TextView::_DrawLineSegment(const char* line, int32 length, + BPoint& _offset) +{ + DrawString(line, length, _offset); + _offset.x += fCharacterWidth * length; }