예제 #1
0
파일: jlocator.cpp 프로젝트: skopp/rush
void JLocator::OnDrag( JDragEvent& e )
{
    if (e.GetType() == deDragStart)
    {
        e.SetDragObject( this );
        e.Consume();
    }
    else if (e.GetType() == deDrag && e.GetDragObject() == this)
    {
        m_Pos.x = e.GetCurPos().x;
        m_Pos.y = e.GetCurPos().y;
        e.Consume();
    }
} // JLocator::OnDrag
예제 #2
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