Example #1
0
Control* Window::MouseMoveEvent(int x, int y)
{
	Control* control = Control::MouseMoveEvent(x, y);
	if (control == this && IsDraggable() && IsPressed() /* same as IsActive() */)
	{
		SetX(x - GetDragX());
		SetY(y - GetDragY());
	}
	return control;
}
Example #2
0
Control* Window::MouseButtonDownEvent(int x, int y, uchar button)
{
	Control* control = Control::MouseButtonDownEvent(x, y, button);
	if (control == this && IsDraggable() && 
		xaih::IsPointInRectangle(x, y, GetAbsX(), GetAbsY(), GetWidth(), GetHeight()))
	{
		SetDragX(x - GetAbsX() + GetAlignmentX());
		SetDragY(y - GetAbsY() + GetAlignmentY());	
	}
	return control;
}
Example #3
0
void JObjectTree::OnDrag( JDragEvent& e )
{
    Vec2 mPos = e.GetCurPos();
    if (e.Key() == mkMiddle)
    {
        if (e.GetType() == deDragStart && IsDraggable())
        {
            if (PickNode( mPos.x, mPos.y ) != NULL)
            {
                e.SetDragObject( this );
                SetDragged();
            }
        }
        if (e.GetType() == deDrag && e.GetDragObject() == this)
        {
            m_RootPos += e.GetDelta();
        }
    }
    else if (e.Key() == mkRight)
    {
        if (e.GetType() == deDragStart)
        {
            Frame ext;
            JObject* pNode = PickNode( mPos.x, mPos.y, &ext );
            if (pNode)
            {
                e.SetSource( this );
                m_pDraggedNode = pNode;
                m_DragShift = Vec2( mPos.x - ext.x, mPos.y - ext.y );
                m_bClone = (GetKeyState( VK_CONTROL ) < 0);
            }
            e.Consume();
        }
        if (e.GetType() == deDrag && e.GetSource() == this)
        {
            //  check whether node can be dropped onto hovered one
            Frame ext;
            JObject* pNode = PickNode( e.GetCurPos().x, e.GetCurPos().y, &ext );
            bool bAsChild = (mPos.x > ext.center().x);
            m_bCanDrop = CanDropNode( m_pDraggedNode, pNode, bAsChild, m_bClone );
            if (m_bCanDrop)
            {
                if (bAsChild)
                {
                    ext.x += ext.w - 10;
                    ext.w = 10;
                    m_InsExt = ext;
                }
                else
                {
                    ext.y += ext.h;
                    ext.w -= 10;
                    ext.h = 4;
                    m_InsExt = ext;
                }
            }
            e.Consume();
        }
        if (e.GetType() == deDrop && e.GetSource() == this && m_pDraggedNode)
        {
            //  find node we are going to drop onto
            Frame ext;
            JObject* pNode = PickNode( e.GetCurPos().x, e.GetCurPos().y, &ext );
            bool bAsChild = (mPos.x > ext.center().x);
            if (CanDropNode( m_pDraggedNode, pNode, bAsChild, m_bClone ))
            {
                DropNode( m_pDraggedNode, pNode, bAsChild, m_bClone );
            }
            m_pDraggedNode = NULL;
            e.Consume();
        }
    }
} // JObjectTree::OnDrag