THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 16/02/2010 at 01:00, xxxxxxxx wrote:
Draw() is not automatically displaying the highlighting. You have to do the highlight drawing yourself within Draw(). DrawViews() is just triggering the viewport redraw by internally calling Draw(). You are using DrawViews() wrong. Also as I said you should store the polygon ID within a member variable of the tool class.
Have a look at eh code below. I store the polygon ID in the polygonid variable and call DrawViews() to trigger a redraw. In Draw() I read out the variable then to draw the highlight polygon. I use the BaseDraw drawing functions for this. The highlight variable is used to prevent highlighting during viewport navigation.
class LiquidToolData : public ToolData
{
public:
LiquidToolData() { polygonid = 0; highlight = FALSE; }
virtual Bool GetCursorInfo(BaseDocument *doc, BaseContainer &data, BaseDraw *bd, Real x, Real y, BaseContainer &bc);
virtual LONG Draw(BaseDocument *doc, BaseContainer &data, BaseDraw *bd, BaseDrawHelp *bh, BaseThread *bt, LONG flags);
private:
LONG polygonid;
Bool highlight;
};
Bool LiquidToolData::GetCursorInfo(BaseDocument *doc, BaseContainer &data, BaseDraw *bd, Real x, Real y, BaseContainer &bc)
{
LONG left, top, right, bottom, width, height;
bd->GetFrame(&left, &top, &right, &bottom);
width = right - left + 1;
height = bottom - top + 1;
LONG mode = doc->GetMode();
BaseObject *op = doc->GetActiveObject();
if (!op || op->GetType() != Opolygon) return TRUE;
AutoAlloc<ViewportSelect> vs;
if (!vs || !vs->Init(width,height,bd,op,mode,TRUE,0)) return FALSE;
if (mode == Mpolygons)
{
highlight = TRUE;
ViewportPixel *vpp = NULL;
LONG mx = x;
LONG my = y;
vpp = vs->GetNearestPolygon(op, mx, my, MAXLONGl, FALSE, NULL, 0);
if (vpp)
{
polygonid = vpp->i;
DrawViews(DA_ONLY_ACTIVE_VIEW|DA_NO_THREAD|DA_NO_ANIMATION, bd);
}
}
return TRUE;
}
LONG LiquidToolData::Draw(BaseDocument *doc, BaseContainer &data, BaseDraw *bd, BaseDrawHelp *bh, BaseThread *bt, LONG flags)
{
if (!(flags & DRAWFLAGS_HIGHLIGHT))
return FALSE;
if (doc->GetMode() != Mpolygons)
return TRUE;
if (!highlight)
return TRUE;
BaseObject *op = doc->GetActiveObject();
if (op && op->GetType() == Opolygon)
{
const CPolygon *polys = ToPoly(op)->GetPolygonR();
const Vector *points = ToPoly(op)->GetPointR();
Vector *p = bNew Vector[4];
p[0] = points[polys[polygonid].a];
p[1] = points[polys[polygonid].b];
p[2] = points[polys[polygonid].c];
p[3] = points[polys[polygonid].d];
Vector *f = bNew Vector[4];
f[0] = 1.0;
f[1] = 1.0;
f[2] = 1.0;
f[3] = 1.0;
bd->SetMatrix_Matrix(NULL, op->GetMg(), 3);
bd->PolygonNew(p,f,TRUE);
bd->LineZOffset(0);
bDelete(p);
bDelete(f);
}
highlight = FALSE;
return TRUE;
}
cheers,
Matthias