Keymap: remove flickering workarounds, small fixes

Part of #15623.

Change-Id: I44d62a39efeaa25ecdc3b8a9aa27ca9fef33e5b9
Reviewed-on: https://review.haiku-os.org/c/haiku/+/2279
Reviewed-by: waddlesplash <[email protected]>
This commit is contained in:
X512
2020-02-25 04:44:29 +00:00
committed by waddlesplash
parent 84195a491f
commit 371b3b2b42
2 changed files with 8 additions and 69 deletions
+8 -65
View File
@@ -83,7 +83,6 @@ is_mappable_to_modifier(uint32 keyCode)
KeyboardLayoutView::KeyboardLayoutView(const char* name) KeyboardLayoutView::KeyboardLayoutView(const char* name)
: :
BView(name, B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE | B_FRAME_EVENTS), BView(name, B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE | B_FRAME_EVENTS),
fOffscreenBitmap(NULL),
fKeymap(NULL), fKeymap(NULL),
fEditable(true), fEditable(true),
fModifiers(0), fModifiers(0),
@@ -102,7 +101,6 @@ KeyboardLayoutView::KeyboardLayoutView(const char* name)
KeyboardLayoutView::~KeyboardLayoutView() KeyboardLayoutView::~KeyboardLayoutView()
{ {
delete fOffscreenBitmap;
} }
@@ -110,7 +108,6 @@ void
KeyboardLayoutView::SetKeyboardLayout(KeyboardLayout* layout) KeyboardLayoutView::SetKeyboardLayout(KeyboardLayout* layout)
{ {
fLayout = layout; fLayout = layout;
_InitOffscreen();
_LayoutKeyboard(); _LayoutKeyboard();
Invalidate(); Invalidate();
} }
@@ -159,7 +156,6 @@ KeyboardLayoutView::AttachedToWindow()
void void
KeyboardLayoutView::FrameResized(float width, float height) KeyboardLayoutView::FrameResized(float width, float height)
{ {
_InitOffscreen();
_LayoutKeyboard(); _LayoutKeyboard();
} }
@@ -502,32 +498,24 @@ void
KeyboardLayoutView::Draw(BRect updateRect) KeyboardLayoutView::Draw(BRect updateRect)
{ {
if (fOldSize != BSize(Bounds().Width(), Bounds().Height())) { if (fOldSize != BSize(Bounds().Width(), Bounds().Height())) {
_InitOffscreen();
_LayoutKeyboard(); _LayoutKeyboard();
} }
BView* view;
if (fOffscreenBitmap != NULL) {
view = fOffscreenView;
view->LockLooper();
} else
view = this;
// Draw background // Draw background
if (Parent()) if (Parent())
view->SetLowColor(Parent()->ViewColor()); SetLowColor(Parent()->ViewColor());
else else
view->SetLowColor(ui_color(B_PANEL_BACKGROUND_COLOR)); SetLowColor(ui_color(B_PANEL_BACKGROUND_COLOR));
view->FillRect(updateRect, B_SOLID_LOW); FillRect(updateRect, B_SOLID_LOW);
// Draw keys // Draw keys
for (int32 i = 0; i < fLayout->CountKeys(); i++) { for (int32 i = 0; i < fLayout->CountKeys(); i++) {
Key* key = fLayout->KeyAt(i); Key* key = fLayout->KeyAt(i);
_DrawKey(view, updateRect, key, _FrameFor(key), _DrawKey(this, updateRect, key, _FrameFor(key),
_IsKeyPressed(key->code)); _IsKeyPressed(key->code));
} }
@@ -536,16 +524,9 @@ KeyboardLayoutView::Draw(BRect updateRect)
for (int32 i = 0; i < fLayout->CountIndicators(); i++) { for (int32 i = 0; i < fLayout->CountIndicators(); i++) {
Indicator* indicator = fLayout->IndicatorAt(i); Indicator* indicator = fLayout->IndicatorAt(i);
_DrawIndicator(view, updateRect, indicator, _FrameFor(indicator->frame), _DrawIndicator(this, updateRect, indicator, _FrameFor(indicator->frame),
(fModifiers & indicator->modifier) != 0); (fModifiers & indicator->modifier) != 0);
} }
if (fOffscreenBitmap != NULL) {
view->Sync();
view->UnlockLooper();
DrawBitmapAsync(fOffscreenBitmap, BPoint(0, 0));
}
} }
@@ -693,40 +674,6 @@ KeyboardLayoutView::MessageReceived(BMessage* message)
} }
void
KeyboardLayoutView::_InitOffscreen()
{
delete fOffscreenBitmap;
fOffscreenView = NULL;
fOffscreenBitmap = new(std::nothrow) BBitmap(Bounds(),
B_BITMAP_ACCEPTS_VIEWS, B_RGB32);
if (fOffscreenBitmap != NULL && fOffscreenBitmap->IsValid()) {
fOffscreenBitmap->Lock();
fOffscreenView = new(std::nothrow) BView(Bounds(), "offscreen view",
0, 0);
if (fOffscreenView != NULL) {
if (Parent() != NULL) {
fOffscreenView->SetViewColor(Parent()->ViewColor());
} else {
fOffscreenView->SetViewColor(
ui_color(B_PANEL_BACKGROUND_COLOR));
}
fOffscreenView->SetLowColor(fOffscreenView->ViewColor());
fOffscreenBitmap->AddChild(fOffscreenView);
}
fOffscreenBitmap->Unlock();
}
if (fOffscreenView == NULL) {
// something went wrong
delete fOffscreenBitmap;
fOffscreenBitmap = NULL;
}
}
void void
KeyboardLayoutView::_LayoutKeyboard() KeyboardLayoutView::_LayoutKeyboard()
{ {
@@ -734,9 +681,9 @@ KeyboardLayoutView::_LayoutKeyboard()
float factorY = Bounds().Height() / fLayout->Bounds().Height(); float factorY = Bounds().Height() / fLayout->Bounds().Height();
fFactor = min_c(factorX, factorY); fFactor = min_c(factorX, factorY);
fOffset = BPoint((Bounds().Width() - fLayout->Bounds().Width() fOffset = BPoint(floorf((Bounds().Width() - fLayout->Bounds().Width()
* fFactor) / 2, * fFactor) / 2),
(Bounds().Height() - fLayout->Bounds().Height() * fFactor) / 2); floorf((Bounds().Height() - fLayout->Bounds().Height() * fFactor) / 2));
if (fLayout->DefaultKeySize().width < 11) if (fLayout->DefaultKeySize().width < 11)
fGap = 1; fGap = 1;
@@ -861,10 +808,6 @@ KeyboardLayoutView::_DrawKey(BView* view, BRect updateRect, const Key* key,
region.Exclude(bottomLeft); region.Exclude(bottomLeft);
view->ConstrainClippingRegion(&region); view->ConstrainClippingRegion(&region);
// Fill in the rect with the background color
SetHighColor(background);
FillRect(rect);
// draw the button background // draw the button background
BRect bgRect = rect.InsetByCopy(2, 2); BRect bgRect = rect.InsetByCopy(2, 2);
be_control_look->DrawButtonBackground(view, bgRect, updateRect, be_control_look->DrawButtonBackground(view, bgRect, updateRect,
@@ -60,7 +60,6 @@ private:
kIndicator kIndicator
}; };
void _InitOffscreen();
void _LayoutKeyboard(); void _LayoutKeyboard();
void _DrawKeyButton(BView* view, BRect& rect, void _DrawKeyButton(BView* view, BRect& rect,
BRect updateRect, rgb_color base, BRect updateRect, rgb_color base,
@@ -103,9 +102,6 @@ private:
uint32 newCode); uint32 newCode);
const char* _NameForModifier(uint32 modifier, bool pretty); const char* _NameForModifier(uint32 modifier, bool pretty);
BBitmap* fOffscreenBitmap;
BView* fOffscreenView;
KeyboardLayout* fLayout; KeyboardLayout* fLayout;
Keymap* fKeymap; Keymap* fKeymap;
BMessenger fTarget; BMessenger fTarget;