Vector2 LandscapeEditorDrawSystem::TranslatePoint(const Vector2& point, const Rect& fromRect, const Rect& toRect)
{
	DVASSERT(fromRect.dx != 0.f && fromRect.dy != 0.f);

	Vector2 origRectSize = fromRect.GetSize();
	Vector2 destRectSize = toRect.GetSize();

	Vector2 scale(destRectSize.x / origRectSize.x,
				  destRectSize.y / origRectSize.y);

	Vector2 relPos = point - fromRect.GetPosition();
	Vector2 newRelPos(relPos.x * scale.x,
					  relPos.y * scale.y);

	Vector2 newPos = newRelPos + toRect.GetPosition();

	return newPos;
}
Rect LandscapeTestData::TranslateRect(const Rect &rect, const Rect& destPlane) const
{
	DVASSERT(landscapeRect.dx != 0 && landscapeRect.dy !=0);
	
	Vector2 origPlaneSize = landscapeRect.GetSize();
	Vector2 destPlaneSize = destPlane.GetSize();

	Vector2 scale(destPlaneSize.x / origPlaneSize.x,
				   destPlaneSize.y / origPlaneSize.y);

	Vector2 relPos = rect.GetPosition() - landscapeRect.GetPosition();

	Vector2 newRelPos(relPos.x * scale.x,
					  relPos.y * scale.y);

	Vector2 newPos = newRelPos + destPlane.GetPosition();

	Vector2 newSize(rect.GetSize().x * scale.x,
					rect.GetSize().y * scale.y);

	return Rect(newPos, newSize);
}
Vector2 HierarchyTreeControlNode::GetParentDelta(bool skipControl/* = false*/) const
{
	Vector2 parentDelta(0, 0);
	
	if (!skipControl && uiObject)
	{
		Rect rect = uiObject->GetRect();
		parentDelta = rect.GetPosition();
	}
	
	const HierarchyTreeControlNode* parentControl = dynamic_cast<const HierarchyTreeControlNode* >(parent);
	if (parentControl)
		parentDelta += parentControl->GetParentDelta();
	return parentDelta;
}
Example #4
0
void UIJoypad::Input(UIEvent *currentInput)
{
	if((TOUCH_INVALID_ID == mainTouch) && currentInput->phase == UIEvent::PHASE_BEGAN)
	{
		mainTouch = currentInput->tid;
	}
	
	if(mainTouch != currentInput->tid)
	{
		return;
	}
	
	if(currentInput->phase == UIEvent::PHASE_ENDED)
	{
		currentPos.x = 0;
		currentPos.y = 0;
        mainTouch = TOUCH_INVALID_ID;
	}
	else 
	{
		Rect r = GetGeometricData().GetUnrotatedRect();//GetRect(true);
		currentPos = currentInput->point - r.GetPosition();
		
		currentPos -= Vector2(r.dx * 0.5f, r.dy * 0.5f);

		if(currentPos.x < deadAreaSize &&  currentPos.x > -deadAreaSize && currentPos.y < deadAreaSize &&  currentPos.y > -deadAreaSize)
		{
			currentPos.x = 0;
			currentPos.y = 0;
		}
        currentPos.x = Max(currentPos.x, -size.x/2);
        currentPos.x = Min(currentPos.x, size.x/2);
        currentPos.y = Max(currentPos.y, -size.y/2);
        currentPos.y = Min(currentPos.y, size.y/2);
	}
	if (stick)
	{
		stick->relativePosition.x = size.x/2 + currentPos.x;
		stick->relativePosition.y = size.y/2 + currentPos.y;
	}

	needRecalcAnalog = true;
	needRecalcDigital = true;
	currentInput->SetInputHandledType(UIEvent::INPUT_HANDLED_HARD); // Drag is handled - see please DF-2508.
}
Example #5
0
void DeviceInfoTest::LoadResources()
{
    UITestTemplate::LoadResources();
    Font *font = FTFont::Create("~res:/Fonts/korinna.ttf");
    DVASSERT(font);
	font->SetSize(20);
	
    Rect textRect = GetRect();
    textRect.SetPosition(textRect.GetPosition() + Vector2(1.0f, 31.0f));
    textRect.SetSize(textRect.GetSize() - Vector2(1.0f, 31.0f));

	deviceInfoText = new UIStaticText(textRect);
    deviceInfoText->SetMultiline(true);
    deviceInfoText->SetTextAlign(ALIGN_LEFT | ALIGN_TOP);
    deviceInfoText->SetFont(font);
    deviceInfoText->SetTextColor(Color::White);
    deviceInfoText->SetDebugDraw(true);

    AddControl(deviceInfoText);
}
Vector2 HierarchyTreeControlNode::GetParentDelta(bool skipControl/* = false*/) const
{
    Vector2 parentDelta(0, 0);

    if (!skipControl && uiObject)
    {
        Rect rect = uiObject->GetRect();
        parentDelta = rect.GetPosition();
        // For UIScrollView we should consider scrollcontainer delta also
        UIScrollView* scrollView = dynamic_cast<UIScrollView* >(uiObject);
        if (scrollView)
        {
            parentDelta += scrollView->GetPadding();
        }
    }

    const HierarchyTreeControlNode* parentControl = dynamic_cast<const HierarchyTreeControlNode* >(parent);
    if (parentControl)
        parentDelta += parentControl->GetParentDelta();
    return parentDelta;
}
void HierarchyTreeControlNode::SetParent(HierarchyTreeNode* node, HierarchyTreeNode* insertAfter)
{
    if (this == insertAfter)
        return;

    if (parent)
        parent->RemoveTreeNode(this, false, false);

    HierarchyTreeControlNode* newParentControl = dynamic_cast<HierarchyTreeControlNode* >(node);
    HierarchyTreeScreenNode* newParentScreen = dynamic_cast<HierarchyTreeScreenNode* >(node);
    DVASSERT(newParentControl || newParentScreen);
    if (!newParentControl && !newParentScreen)
        return;

    UIControl* afterControl = NULL;
    HierarchyTreeControlNode* insertAfterControl = dynamic_cast<HierarchyTreeControlNode* >(insertAfter);
    if (insertAfterControl)
        afterControl = insertAfterControl->GetUIObject();

    UIControl* newParentUI = NULL;
    if (newParentControl)
        newParentUI = newParentControl->GetUIObject();
    else if (newParentScreen)
        newParentUI = newParentScreen->GetScreen();

    node->AddTreeNode(this, insertAfter);
    if (newParentUI && uiObject)
    {
        Rect controlAbsoluteRect = uiObject->GetRect(true);
        Rect parentAbsoluteRect = newParentUI->GetRect(true);

        if (insertAfter != node)
        {
            newParentUI->InsertChildAbove(uiObject, afterControl);
        }
        else
        {
            UIControl* belowControl = NULL;
            const List<UIControl*> & controls = newParentUI->GetChildren();
            if (controls.size())
            {
                belowControl = *controls.begin();
            }
            newParentUI->InsertChildBelow(uiObject, belowControl);
        }

        // Recalculate the relative coords of the moved object to don't change its position.
        Vector2 newControlOffset = controlAbsoluteRect.GetPosition() - parentAbsoluteRect.GetPosition();
        uiObject->SetRect(Rect(newControlOffset, uiObject->GetRect().GetSize()));

        // Fix
        // DF-2395 - Recalculate scrollContainer content each time we add controls to it
        UIScrollViewContainer *container = dynamic_cast<UIScrollViewContainer*>(newParentUI);
        if (container)
        {
            UIScrollView *scroll =  dynamic_cast<UIScrollView*>(container->GetParent());
            if (scroll)
            {
                scroll->RecalculateContentSize();
            }
        }
    }

    parent = node;
}