示例#1
0
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());
	else
		view->SetLowColor(ui_color(B_PANEL_BACKGROUND_COLOR));

	view->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),
			_IsKeyPressed(key->code));
	}

	// Draw LED indicators

	for (int32 i = 0; i < fLayout->CountIndicators(); i++) {
		Indicator* indicator = fLayout->IndicatorAt(i);

		_DrawIndicator(view, updateRect, indicator, _FrameFor(indicator->frame),
			(fModifiers & indicator->modifier) != 0);
	}

	if (fOffscreenBitmap != NULL) {
		view->Sync();
		view->UnlockLooper();

		DrawBitmapAsync(fOffscreenBitmap, BPoint(0, 0));
	}
}
void
CharacterView::ScrollToCharacter(uint32 c)
{
	if (IsCharacterVisible(c))
		return;

	BRect frame = _FrameFor(c);
	BView::ScrollTo(0.0f, frame.top);
}
bool
CharacterView::IsCharacterVisible(uint32 c) const
{
	return Bounds().Contains(_FrameFor(c));
}
示例#4
0
void
KeyboardLayoutView::_InvalidateKey(const Key* key)
{
	if (key != NULL)
		Invalidate(_FrameFor(key));
}
示例#5
0
void
KeyboardLayoutView::MouseMoved(BPoint point, uint32 transit,
                               const BMessage* dragMessage)
{
    if (fKeymap == NULL)
        return;

    // prevent dragging for tertiary mouse button
    if ((fButtons & B_TERTIARY_MOUSE_BUTTON) != 0)
        return;

    if (dragMessage != NULL) {
        if (fEditable) {
            _InvalidateKey(fDropTarget);
            fDropPoint = point;

            _EvaluateDropTarget(point);
        }

        return;
    }

    int32 buttons;
    if (Window()->CurrentMessage() == NULL
            || Window()->CurrentMessage()->FindInt32("buttons", &buttons) != B_OK
            || buttons == 0)
        return;

    if (fDragKey == NULL && (fabs(point.x - fClickPoint.x) > 4
                             || fabs(point.y - fClickPoint.y) > 4)) {
        // start dragging
        Key* key = _KeyAt(fClickPoint);
        if (key == NULL)
            return;

        BRect frame = _FrameFor(key);
        BPoint offset = fClickPoint - frame.LeftTop();
        frame.OffsetTo(B_ORIGIN);

        BRect rect = frame;
        rect.right--;
        rect.bottom--;
        BBitmap* bitmap = new BBitmap(rect, B_RGBA32, true);
        bitmap->Lock();

        BView* view = new BView(rect, "drag", B_FOLLOW_NONE, 0);
        bitmap->AddChild(view);

        view->SetHighColor(0, 0, 0, 0);
        view->FillRect(view->Bounds());
        view->SetDrawingMode(B_OP_ALPHA);
        view->SetHighColor(0, 0, 0, 128);
        // set the level of transparency by value
        view->SetBlendingMode(B_CONSTANT_ALPHA, B_ALPHA_COMPOSITE);
        _DrawKey(view, frame, key, frame, false);

        view->Sync();
        bitmap->Unlock();

        BMessage drag(B_MIME_DATA);
        drag.AddInt32("key", key->code);

        char* string;
        int32 numBytes;
        fKeymap->GetChars(key->code, fModifiers, fDeadKey, &string,
                          &numBytes);
        if (string != NULL) {
            drag.AddData("text/plain", B_MIME_DATA, string, numBytes);
            delete[] string;
        }

        DragMessage(&drag, bitmap, B_OP_ALPHA, offset);
        fDragKey = key;
        fDragModifiers = fModifiers;

        fKeyState[key->code / 8] &= ~(1 << (7 - (key->code & 7)));
        _InvalidateKey(key);
    }
}