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 <waddlesplash@gmail.com>
This commit is contained in:
X512 2020-02-25 05:46:19 +09:00 committed by waddlesplash
parent 84195a491f
commit 371b3b2b42
2 changed files with 8 additions and 69 deletions

View File

@ -83,7 +83,6 @@ is_mappable_to_modifier(uint32 keyCode)
KeyboardLayoutView::KeyboardLayoutView(const char* name)
:
BView(name, B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE | B_FRAME_EVENTS),
fOffscreenBitmap(NULL),
fKeymap(NULL),
fEditable(true),
fModifiers(0),
@ -102,7 +101,6 @@ KeyboardLayoutView::KeyboardLayoutView(const char* name)
KeyboardLayoutView::~KeyboardLayoutView()
{
delete fOffscreenBitmap;
}
@ -110,7 +108,6 @@ void
KeyboardLayoutView::SetKeyboardLayout(KeyboardLayout* layout)
{
fLayout = layout;
_InitOffscreen();
_LayoutKeyboard();
Invalidate();
}
@ -159,7 +156,6 @@ KeyboardLayoutView::AttachedToWindow()
void
KeyboardLayoutView::FrameResized(float width, float height)
{
_InitOffscreen();
_LayoutKeyboard();
}
@ -502,32 +498,24 @@ void
KeyboardLayoutView::Draw(BRect updateRect)
{
if (fOldSize != BSize(Bounds().Width(), Bounds().Height())) {
_InitOffscreen();
_LayoutKeyboard();
}
BView* view;
if (fOffscreenBitmap != NULL) {
view = fOffscreenView;
view->LockLooper();
} else
view = this;
// Draw background
if (Parent())
view->SetLowColor(Parent()->ViewColor());
SetLowColor(Parent()->ViewColor());
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
for (int32 i = 0; i < fLayout->CountKeys(); i++) {
Key* key = fLayout->KeyAt(i);
_DrawKey(view, updateRect, key, _FrameFor(key),
_DrawKey(this, updateRect, key, _FrameFor(key),
_IsKeyPressed(key->code));
}
@ -536,16 +524,9 @@ KeyboardLayoutView::Draw(BRect updateRect)
for (int32 i = 0; i < fLayout->CountIndicators(); i++) {
Indicator* indicator = fLayout->IndicatorAt(i);
_DrawIndicator(view, updateRect, indicator, _FrameFor(indicator->frame),
_DrawIndicator(this, updateRect, indicator, _FrameFor(indicator->frame),
(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
KeyboardLayoutView::_LayoutKeyboard()
{
@ -734,9 +681,9 @@ KeyboardLayoutView::_LayoutKeyboard()
float factorY = Bounds().Height() / fLayout->Bounds().Height();
fFactor = min_c(factorX, factorY);
fOffset = BPoint((Bounds().Width() - fLayout->Bounds().Width()
* fFactor) / 2,
(Bounds().Height() - fLayout->Bounds().Height() * fFactor) / 2);
fOffset = BPoint(floorf((Bounds().Width() - fLayout->Bounds().Width()
* fFactor) / 2),
floorf((Bounds().Height() - fLayout->Bounds().Height() * fFactor) / 2));
if (fLayout->DefaultKeySize().width < 11)
fGap = 1;
@ -861,10 +808,6 @@ KeyboardLayoutView::_DrawKey(BView* view, BRect updateRect, const Key* key,
region.Exclude(bottomLeft);
view->ConstrainClippingRegion(&region);
// Fill in the rect with the background color
SetHighColor(background);
FillRect(rect);
// draw the button background
BRect bgRect = rect.InsetByCopy(2, 2);
be_control_look->DrawButtonBackground(view, bgRect, updateRect,

View File

@ -60,7 +60,6 @@ private:
kIndicator
};
void _InitOffscreen();
void _LayoutKeyboard();
void _DrawKeyButton(BView* view, BRect& rect,
BRect updateRect, rgb_color base,
@ -103,9 +102,6 @@ private:
uint32 newCode);
const char* _NameForModifier(uint32 modifier, bool pretty);
BBitmap* fOffscreenBitmap;
BView* fOffscreenView;
KeyboardLayout* fLayout;
Keymap* fKeymap;
BMessenger fTarget;