Double buffering support (as it's in the original version). Needs some testing to see if it's cheaper/better than direct drawing.

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@9988 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stefano Ceccherini
2004-11-17 11:02:16 +00:00
parent d288a106d4
commit 970c2591f5
+32 -25
View File
@@ -3670,18 +3670,22 @@ void
BTextView::DrawLines(int32 startLine, int32 endLine, int32 startOffset, BTextView::DrawLines(int32 startLine, int32 endLine, int32 startOffset,
bool erase) bool erase)
{ {
// TODO: Draw on the "fOffscreen" BBitmap, then draw it on the view
// clip the text // clip the text
BRect clipRect = Bounds() & fTextRect; BRect clipRect = Bounds() & fTextRect;
clipRect.InsetBy(-1, -1); clipRect.InsetBy(-1, -1);
BRegion newClip;
newClip.Set(clipRect); BView *view = this;
ConstrainClippingRegion(&newClip); if (fOffscreen && fOffscreen->Lock()) {
view = fOffscreen->ChildAt(0);
} else {
BRegion newClip;
newClip.Set(clipRect);
ConstrainClippingRegion(&newClip);
}
// set the low color to the view color so that // set the low color to the view color so that
// drawing to a non-white background will work // drawing to a non-white background will work
SetLowColor(ViewColor()); view->SetLowColor(view->ViewColor());
long maxLine = fLines->NumLines() - 1; long maxLine = fLines->NumLines() - 1;
startLine = (startLine < 0) ? 0 : startLine; startLine = (startLine < 0) ? 0 : startLine;
@@ -3711,7 +3715,7 @@ BTextView::DrawLines(int32 startLine, int32 endLine, int32 startOffset,
eraseRect.top = line->origin + fTextRect.top; eraseRect.top = line->origin + fTextRect.top;
eraseRect.bottom = (line + 1)->origin + fTextRect.top; eraseRect.bottom = (line + 1)->origin + fTextRect.top;
FillRect(eraseRect, B_SOLID_LOW); view->FillRect(eraseRect, B_SOLID_LOW);
eraseRect = clipRect; eraseRect = clipRect;
} }
@@ -3731,13 +3735,13 @@ BTextView::DrawLines(int32 startLine, int32 endLine, int32 startOffset,
startLeft += fTextRect.left; startLeft += fTextRect.left;
} }
MovePenTo(startLeft, line->origin + line->ascent + fTextRect.top); view->MovePenTo(startLeft, line->origin + line->ascent + fTextRect.top);
if (erase && i >= startEraseLine) { if (erase && i >= startEraseLine) {
eraseRect.top = line->origin + fTextRect.top; eraseRect.top = line->origin + fTextRect.top;
eraseRect.bottom = (line + 1)->origin + fTextRect.top; eraseRect.bottom = (line + 1)->origin + fTextRect.top;
FillRect(eraseRect, B_SOLID_LOW); view->FillRect(eraseRect, B_SOLID_LOW);
} }
// do we have any text to draw? // do we have any text to draw?
@@ -3751,8 +3755,8 @@ BTextView::DrawLines(int32 startLine, int32 endLine, int32 startOffset,
int32 numChars; int32 numChars;
// iterate through each style on this line // iterate through each style on this line
while ((numChars = fStyles->Iterate(offset, length, fInline, &font, &color)) != 0) { while ((numChars = fStyles->Iterate(offset, length, fInline, &font, &color)) != 0) {
SetFont(font); view->SetFont(font);
SetHighColor(*color); view->SetHighColor(*color);
tabChars = numChars; tabChars = numChars;
do { do {
@@ -3778,10 +3782,9 @@ BTextView::DrawLines(int32 startLine, int32 endLine, int32 startOffset,
BRect rect(PointAt(inlineOffset), rightBottom); BRect rect(PointAt(inlineOffset), rightBottom);
// Highlight in blue the inputted text // Highlight in blue the inputted text
PushState(); view->PushState();
SetLowColor(kBlueInputColor); view->SetLowColor(kBlueInputColor);
FillRect(rect, B_SOLID_LOW); view->FillRect(rect, B_SOLID_LOW);
PopState();
// Highlight in red the selected part // Highlight in red the selected part
if (fInline->SelectionLength() > 0) { if (fInline->SelectionLength() > 0) {
@@ -3790,15 +3793,14 @@ BTextView::DrawLines(int32 startLine, int32 endLine, int32 startOffset,
rightBottom.y += height; rightBottom.y += height;
rect.SetLeftTop(PointAt(inlineOffset + fInline->SelectionOffset())); rect.SetLeftTop(PointAt(inlineOffset + fInline->SelectionOffset()));
rect.SetRightBottom(rightBottom); rect.SetRightBottom(rightBottom);
PushState(); view->SetLowColor(kRedInputColor);
SetLowColor(kRedInputColor); view->FillRect(rect, B_SOLID_LOW);
FillRect(rect, B_SOLID_LOW); }
PopState(); view->PopState();
}
} }
} }
DrawString(fText->GetString(offset, tabChars), tabChars); view->DrawString(fText->GetString(offset, tabChars), tabChars);
if (foundTab) { if (foundTab) {
float penPos = PenLocation().x - fTextRect.left; float penPos = PenLocation().x - fTextRect.left;
@@ -3806,7 +3808,7 @@ BTextView::DrawLines(int32 startLine, int32 endLine, int32 startOffset,
if (numTabs > 1) if (numTabs > 1)
tabWidth += ((numTabs - 1) * fTabWidth); tabWidth += ((numTabs - 1) * fTabWidth);
MovePenBy(tabWidth, 0.0); view->MovePenBy(tabWidth, 0.0);
tabChars += numTabs; tabChars += numTabs;
} }
@@ -3822,7 +3824,13 @@ BTextView::DrawLines(int32 startLine, int32 endLine, int32 startOffset,
line++; line++;
} }
ConstrainClippingRegion(NULL); if (view == this)
ConstrainClippingRegion(NULL);
else {
view->Sync();
fOffscreen->Unlock();
DrawBitmap(fOffscreen, B_ORIGIN);
}
} }
@@ -4108,7 +4116,6 @@ BTextView::NewOffscreen(float padding)
if (fOffscreen != NULL) if (fOffscreen != NULL)
DeleteOffscreen(); DeleteOffscreen();
// TODO: Is this correct ?
BRect bitmapRect(0, 0, fTextRect.Width() + padding, fTextRect.Height()); BRect bitmapRect(0, 0, fTextRect.Width() + padding, fTextRect.Height());
fOffscreen = new BBitmap(bitmapRect, fColorSpace, true, false); fOffscreen = new BBitmap(bitmapRect, fColorSpace, true, false);
if (fOffscreen != NULL && fOffscreen->Lock()) { if (fOffscreen != NULL && fOffscreen->Lock()) {