On 21/02/2013 at 13:17, xxxxxxxx wrote:
Here are the Handle methods that I use in one of my plugins. Not that the UNFURL_UNFURL_AMOUNT goes from 0.0 to 1.0 (0% to 100%).
// ObjectData.Draw
//*---------------------------------------------------------------------------*
DRAWRESULT UnfurlObj::Draw(BaseObject* op, DRAWPASS drawpass, BaseDraw* bd, BaseDrawHelp* bh)
//*---------------------------------------------------------------------------*
{
if (!(op && bd && bh)) return DRAWRESULT_DRAWN;
if (drawpass == DRAWPASS_HANDLES)
{
LONG hitid = op->GetHighlightHandle(bd);
HandleInfo info;
bd->SetPen(GetViewColor(VIEWCOLOR_ACTIVEPOINT));
bd->SetMatrix_Matrix(op, bh->GetMg());
GetHandle(op, 0L, info);
if (hitid == 0L) bd->SetPen(GetViewColor(VIEWCOLOR_SELECTION_PREVIEW));
else bd->SetPen(GetViewColor(VIEWCOLOR_ACTIVEPOINT));
bd->DrawHandle(info.position, DRAWHANDLE_BIG, 0L);
GetHandle(op, 1L, info);
bd->SetPen(GetViewColor(VIEWCOLOR_ACTIVEPOINT));
bd->DrawLine(info.position, Vector(0.0), 0L);
bd->SetMatrix_Matrix(NULL, Matrix());
if (hit == 0L) bd->SetPen(GetViewColor(VIEWCOLOR_SELECTION_PREVIEW));
else bd->SetPen(GetViewColor(VIEWCOLOR_ACTIVEPOINT));
bd->DrawHandle(GetHandle(op, 0L),DRAWHANDLE_BIG,0L);
// Line from center to Handle
bd->SetPen(GetViewColor(VIEWCOLOR_ACTIVEPOINT));
bd->DrawLine(GetHandle(op, 1L),m.off,0L);
}
return SUPER::Draw(op, drawpass, bd, bh);
}
// ObjectData.GetHandle
//*---------------------------------------------------------------------------*
void UnfurlObj::GetHandle(BaseObject* op, LONG i, HandleInfo& info)
//*---------------------------------------------------------------------------*
{
BaseContainer* data = op->GetDataInstance();
if (!data) return;
info.position.x = data->GetReal(UNFURL_UNFURL_AMOUNT)*125.0;
info.direction.x = 1.0;
info.type = HANDLECONSTRAINTTYPE_LINEAR;
}
// ObjectData.DetectHandle
//*---------------------------------------------------------------------------*
LONG UnfurlObj::DetectHandle(BaseObject* op, BaseDraw* bd, LONG x, LONG y, QUALIFIER qualifier)
//*---------------------------------------------------------------------------*
{
HandleInfo info;
GetHandle(op, 0L, info);
return (bd->PointInRange(info.position*op->GetMg(),x,y))?0L:NOTOK;
}
// ObjectData.MoveHandle
//*---------------------------------------------------------------------------*
Bool UnfurlObj::MoveHandle(BaseObject* op, BaseObject* undo, const Vector& mouse_pos, LONG hit_id, QUALIFIER qualifier, BaseDraw* bd)
//*---------------------------------------------------------------------------*
{
BaseContainer* dst = op->GetDataInstance();
if (!dst) return TRUE;
HandleInfo info;
Real val = mouse_pos.x;
GetHandle(op, hit_id, info);
if (bd)
{
Matrix mg = op->GetUpMg() * undo->GetMl();
Vector pos = bd->ProjectPointOnLine(info.position * mg, info.direction ^ mg, mouse_pos.x, mouse_pos.y);
val = (pos * !mg) * info.direction;
}
if (hit_id != 0L) return TRUE;
dst->SetReal(UNFURL_UNFURL_AMOUNT,FCut01(val*0.008));
return TRUE;
}