void cbInitDrag( const Msg_p& _pMsg, const Object_p& pObject ) { Widget_p pWidget = Widget::cast(pObject); FlexHook_p pHook = FlexHook::cast(pWidget->hook()); dragStartPos = pHook->floatOfs(); printf( "DRAG START!\n" ); }
void cbDragWidget( const Msg_p& _pMsg, const Object_p& pObject ) { Widget_p pWidget = Widget::cast(pObject); if( _pMsg->type() != WG_MSG_MOUSE_DRAG || !pWidget->parent() ) return; const MouseDragMsg_p pMsg = MouseDragMsg::cast(_pMsg); Coord dragDistance = pMsg->draggedTotal(); Coord ofs = dragStartPos + dragDistance; // printf( "AccDistance: %d, %d\n", dragDistance.x, dragDistance.y ); printf( "ofs: %d, %d start: %d %d distance: %d, %d\n", ofs.x, ofs.y, dragStartPos.x, dragStartPos.y, dragDistance.x, dragDistance.y ); FlexHook_p pHook = FlexHook::cast(pWidget->hook()); pHook->setOfs(dragStartPos+dragDistance); }
void cbMoveResize( const Msg_p& _pMsg, const Object_p& _pWidget ) { static Coord posAtPress[MouseButton_Max]; auto pWidget = Widget::cast(_pWidget); FlexHook_p pHook = FlexHook::cast(pWidget->hook()); switch( _pMsg->type() ) { case MsgType::MousePress: { auto pMsg = MousePressMsg::cast(_pMsg); posAtPress[(int)pMsg->button()] = pWidget->pos(); } break; case MsgType::MouseDrag: { auto pMsg = MouseDragMsg::cast(_pMsg); if( pMsg->button() == MouseButton::Right ) { pHook->setSize( pHook->size() + pMsg->draggedNow().toSize() ); } else if( pMsg->button() == MouseButton::Middle ) { pHook->setOfs( posAtPress[(int)MouseButton::Middle] + pMsg->draggedTotal() ); } } break; case MsgType::MouseRelease: break; default: break; } }