FontDemo: remove flickering workarounds
Part of #15623. Change-Id: Iddd1bff519fac8f5387ba1eeec22cc2314112271 Reviewed-on: https://review.haiku-os.org/c/haiku/+/2276 Reviewed-by: waddlesplash <[email protected]>
This commit is contained in:
@@ -29,8 +29,6 @@
|
|||||||
|
|
||||||
FontDemoView::FontDemoView(BRect rect)
|
FontDemoView::FontDemoView(BRect rect)
|
||||||
: BView(rect, "FontDemoView", B_FOLLOW_ALL, B_WILL_DRAW | B_FRAME_EVENTS),
|
: BView(rect, "FontDemoView", B_FOLLOW_ALL, B_WILL_DRAW | B_FRAME_EVENTS),
|
||||||
fBitmap(NULL),
|
|
||||||
fBufferView(NULL),
|
|
||||||
fFontSize(50.0),
|
fFontSize(50.0),
|
||||||
fSpacing(0.0),
|
fSpacing(0.0),
|
||||||
fOutLineLevel(0),
|
fOutLineLevel(0),
|
||||||
@@ -39,22 +37,16 @@ FontDemoView::FontDemoView(BRect rect)
|
|||||||
fDrawShapes(false),
|
fDrawShapes(false),
|
||||||
fShapes(NULL)
|
fShapes(NULL)
|
||||||
{
|
{
|
||||||
SetViewColor(B_TRANSPARENT_COLOR);
|
|
||||||
BString setStr = B_TRANSLATE("Haiku, Inc.");
|
BString setStr = B_TRANSLATE("Haiku, Inc.");
|
||||||
SetString(setStr);
|
SetString(setStr);
|
||||||
SetFontSize(fFontSize);
|
SetFontSize(fFontSize);
|
||||||
SetAntialiasing(true);
|
SetAntialiasing(true);
|
||||||
|
|
||||||
_NewBitmap(Bounds());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
FontDemoView::~FontDemoView()
|
FontDemoView::~FontDemoView()
|
||||||
{
|
{
|
||||||
free(fShapes);
|
free(fShapes);
|
||||||
|
|
||||||
fBitmap->Lock();
|
|
||||||
delete fBitmap;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -71,33 +63,15 @@ FontDemoView::FrameResized(float width, float height)
|
|||||||
void
|
void
|
||||||
FontDemoView::Draw(BRect updateRect)
|
FontDemoView::Draw(BRect updateRect)
|
||||||
{
|
{
|
||||||
|
SetDrawingMode(B_OP_COPY);
|
||||||
|
|
||||||
BRect rect = Bounds();
|
BRect rect = Bounds();
|
||||||
fBufferView = _GetView(rect);
|
SetHighColor(255, 255, 255);
|
||||||
_DrawView(fBufferView);
|
|
||||||
|
|
||||||
fBufferView->Sync();
|
|
||||||
DrawBitmap(fBitmap, rect);
|
|
||||||
fBitmap->Unlock();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
FontDemoView::_DrawView(BView* view)
|
|
||||||
{
|
|
||||||
if (!view)
|
|
||||||
return;
|
|
||||||
|
|
||||||
view->SetDrawingMode(B_OP_COPY);
|
|
||||||
|
|
||||||
|
|
||||||
BRect rect = view->Bounds();
|
|
||||||
view->SetHighColor(255, 255, 255);
|
|
||||||
view->FillRect(rect);
|
|
||||||
|
|
||||||
if (!fString)
|
if (!fString)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
view->SetFont(&fFont, B_FONT_ALL);
|
SetFont(&fFont, B_FONT_ALL);
|
||||||
|
|
||||||
const size_t size = fString.CountChars();
|
const size_t size = fString.CountChars();
|
||||||
BStackOrHeapArray<BRect, 64> boundBoxes(size);
|
BStackOrHeapArray<BRect, 64> boundBoxes(size);
|
||||||
@@ -136,7 +110,7 @@ FontDemoView::_DrawView(BView* view)
|
|||||||
// region area instead of the whole view.
|
// region area instead of the whole view.
|
||||||
|
|
||||||
fBoxRegion.MakeEmpty();
|
fBoxRegion.MakeEmpty();
|
||||||
|
|
||||||
for (size_t i = 0; i < size; i++) {
|
for (size_t i = 0; i < size; i++) {
|
||||||
xCoordArray[i] = 0.0f;
|
xCoordArray[i] = 0.0f;
|
||||||
yCoordArray[i] = 0.0f;
|
yCoordArray[i] = 0.0f;
|
||||||
@@ -150,28 +124,28 @@ FontDemoView::_DrawView(BView* view)
|
|||||||
boundBoxes[i].OffsetBy(xCoordArray[i], yCoordArray[i]);
|
boundBoxes[i].OffsetBy(xCoordArray[i], yCoordArray[i]);
|
||||||
|
|
||||||
if (OutLineLevel()) {
|
if (OutLineLevel()) {
|
||||||
view->MovePenTo(xCoordArray[i], yCoordArray[i]);
|
MovePenTo(xCoordArray[i], yCoordArray[i]);
|
||||||
view->SetHighColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
SetHighColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
||||||
view->FillShape(fShapes[i]);
|
FillShape(fShapes[i]);
|
||||||
view->SetPenSize(OutLineLevel());
|
SetPenSize(OutLineLevel());
|
||||||
view->SetHighColor(0, 0, 0);
|
SetHighColor(0, 0, 0);
|
||||||
view->StrokeShape(fShapes[i]);
|
StrokeShape(fShapes[i]);
|
||||||
} else {
|
} else {
|
||||||
view->SetHighColor(0, 0, 0);
|
SetHighColor(0, 0, 0);
|
||||||
view->SetDrawingMode(fDrawingMode);
|
SetDrawingMode(fDrawingMode);
|
||||||
int32 charLength;
|
int32 charLength;
|
||||||
const char* charAt = fString.CharAt(i, &charLength);
|
const char* charAt = fString.CharAt(i, &charLength);
|
||||||
view->DrawString(charAt, charLength,
|
DrawString(charAt, charLength,
|
||||||
BPoint(xCoordArray[i], yCoordArray[i]));
|
BPoint(xCoordArray[i], yCoordArray[i]));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (BoundingBoxes() && !OutLineLevel()) {
|
if (BoundingBoxes() && !OutLineLevel()) {
|
||||||
if (i % 2)
|
if (i % 2)
|
||||||
view->SetHighColor(0, 255, 0);
|
SetHighColor(0, 255, 0);
|
||||||
else
|
else
|
||||||
view->SetHighColor(255, 0, 0);
|
SetHighColor(255, 0, 0);
|
||||||
view->SetDrawingMode(B_OP_COPY);
|
SetDrawingMode(B_OP_COPY);
|
||||||
view->StrokeRect(boundBoxes[i]);
|
StrokeRect(boundBoxes[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// add the bounding to the region.
|
// add the bounding to the region.
|
||||||
@@ -430,31 +404,3 @@ FontDemoView::_AddShapes(BString string)
|
|||||||
fShapes[i] = new BShape();
|
fShapes[i] = new BShape();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
BView*
|
|
||||||
FontDemoView::_GetView(BRect rect)
|
|
||||||
{
|
|
||||||
if (!fBitmap || fBitmap->Bounds() != rect)
|
|
||||||
_NewBitmap(rect);
|
|
||||||
|
|
||||||
fBitmap->Lock();
|
|
||||||
return fBitmap->ChildAt(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
FontDemoView::_NewBitmap(BRect rect)
|
|
||||||
{
|
|
||||||
delete fBitmap;
|
|
||||||
fBitmap = new BBitmap(rect, B_RGB16, true);
|
|
||||||
|
|
||||||
if (fBitmap->Lock()) {
|
|
||||||
BView* view = new BView(rect, "", B_FOLLOW_NONE, B_WILL_DRAW);
|
|
||||||
fBitmap->AddChild(view);
|
|
||||||
fBitmap->Unlock();
|
|
||||||
} else {
|
|
||||||
delete fBitmap;
|
|
||||||
fBitmap = NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -51,13 +51,6 @@ class FontDemoView : public BView {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
void _AddShapes(BString string);
|
void _AddShapes(BString string);
|
||||||
void _DrawView(BView* view);
|
|
||||||
|
|
||||||
BView* _GetView(BRect rect);
|
|
||||||
void _NewBitmap(BRect rect);
|
|
||||||
|
|
||||||
BBitmap* fBitmap;
|
|
||||||
BView* fBufferView;
|
|
||||||
|
|
||||||
BString fString;
|
BString fString;
|
||||||
float fFontSize;
|
float fFontSize;
|
||||||
|
|||||||
Reference in New Issue
Block a user