Esempio n. 1
0
void TextField::OnClicked(void* arg) {
    assert(this == arg);
    if (!IsKeyboardFocused()) {
        UIManager::GetInstance().SetFocusUI(mSelfPtr.lock());
    }
    auto injector = InputManager::GetInstance().GetInputInjector();
    long x, y;
    injector->GetMousePos(x, y);
    Vec2I cursorPos(x, y);
    const auto& finalPos = GetFinalPos();
    cursorPos = cursorPos - finalPos;
    cursorPos.x -= mTextGap.x;
    cursorPos.x += mCursorOffset;

    auto font = Renderer::GetInstance().GetFontWithHeight(mTextSize);
    if (font)
    {
        float length = 0.f;
        if (cursorPos.x >= (int)mTextWidth) {
            UIManager::GetInstance().GetTextManipulator()->SetCursorPos(mTextw.size());
        }
        else {
            for (int i = 0; i < (int)mTextw.size(); i++)
            {
                float halfLength = font->GetTextWidth((const char*)&mTextw[i], 2) *.5f;
                length += halfLength;
                if (cursorPos.x < length)
                {
                    UIManager::GetInstance().GetTextManipulator()->SetCursorPos(i);
                    break;
                }
                length += halfLength;
            }
        }
    }
    injector->Invalidate(InputDevice::Mouse);

}
void CXTPMarkupVisual::Render(CXTPMarkupDrawingContext* drawingContext)
{
	CRect rcClipBox = drawingContext->GetClipBox();
	rcClipBox.OffsetRect(-m_ptVisualOffset);

	RECT rcIntersect;
	if (!::IntersectRect(&rcIntersect, GetBoundRect(), &rcClipBox))
	{
		RenderClipped(drawingContext);
		return;
	}

	CRect rcLayoutClip(0, 0, 0, 0);
	BOOL bClipLayout = FALSE;

	if (GetLayoutClip(rcLayoutClip))
	{
		if (rcLayoutClip.IsRectEmpty())
		{
			RenderClipped(drawingContext);
			return;
		}

		rcClipBox.IntersectRect(rcClipBox, rcLayoutClip);

		if (!::IntersectRect(&rcIntersect, GetBoundRect(), &rcClipBox))
		{
			RenderClipped(drawingContext);
			return;
		}

		bClipLayout = TRUE;
	}

	drawingContext->OffsetViewport(m_ptVisualOffset);

	HRGN hrgnClip = 0;

	if (bClipLayout)
	{
		hrgnClip = drawingContext->SaveClipRegion();

		drawingContext->IntersectClipRect(rcLayoutClip);
	}

	OnRender(drawingContext);

	int nVisualCount = GetVisualChildrenCount();
	for (int i = 0; i < nVisualCount; i++)
	{
		GetVisualChild(i)->Render(drawingContext);
	}

	if (IsKeyboardFocused())
	{
		OnRenderFocusVisual(drawingContext);

	}

	if (hrgnClip != NULL)
	{
		drawingContext->RestoreClipRegion(hrgnClip);
	}

	drawingContext->OffsetViewport(-m_ptVisualOffset);
}
Esempio n. 3
0
bool TextField::OnInputFromHandler(IInputInjectorPtr injector)
{
    if (!mEnable)
        return false;

    bool mouseIn = __super::OnInputFromHandler(injector);

    if (!mVisibility.IsVisible() || !GetFocus(false))
        return mouseIn;

    if (injector->IsValid(InputDevice::Keyboard)) {
        auto ch = injector->GetChar();
        if (ch == VK_TAB)	{
            if (IsKeyboardFocused())
            {
                auto listbox = IsInListBox();
                if (listbox)
                {
                    injector->PopChar();
                    if (injector->IsKeyDown(VK_SHIFT)) {
                        listbox->IterateItem(false, true);
                    }
                    else {
                        listbox->IterateItem(true, true);
                    }
                }
                else {
                    OnEvent(UIEvents::EVENT_ENTER);
                }
            }
        }
        else if (ch == VK_RETURN)
        {
            bool succ = false;
            if (OnEvent(UIEvents::EVENT_ENTER))
            {
                succ = true;
            }
            else
            {
                auto listbox = IsInListBox();
                if (listbox)
                {
                    auto eventHandler = dynamic_cast<EventHandler*>(listbox.get());
                    if (eventHandler)
                    {
                        if (eventHandler->OnEvent(UIEvents::EVENT_ENTER)) {
                            succ = true;
                        }
                    }
                }
            }
            if (succ) {
                injector->PopChar();
                injector->Invalidate(InputDevice::Keyboard);
                TriggerRedraw();

            }
        }
        else if (ch == VK_ESCAPE) {
            auto prop = IsInPropertyList();
            if (prop) {
                prop->MoveFocusToKeyItem();
                injector->PopChar();
                injector->Invalidate(InputDevice::Keyboard);
            }
        }
        else {
            UIManager::GetInstance().GetTextManipulator()->ConsumeInput(injector, mouseIn);
        }
    }

    return mouseIn;
}