Example: Maintaining a Scale Displayed With No Transformation

This part presents an example of subtyping an IlvManagerViewHook. At first there is a map and a circular scale used as a compass card. Then, because of hooks, the manager translates and zooms the view without affecting the compass card. The afterDraw and transformerChanged member functions are redefined to redraw the scale to its original dimensions and location.

static void ILVCALLBACK

Quit(IlvView* view, IlAny)

{

delete view->getDisplay();

IlvExit(0);

}

 

char* labels[] = {“N”, “O”, “S”, “E”, ““};

 

class ExHook

: public IlvManagerViewHook

{

public :

ExHook(IlvManager* m, IlvView* v, const IlvRect* psize=0)

: IlvManagerViewHook(m, v)

{

_cirscale = new IlvCircularScale(m->getDisplay(),

IlvRect(30, 30, 100, 100),

“%.4f”,

0, 100, 90., 360.);

_cirscale->setLabels(5, (const char* const*)labels);

}

virtual void afterDraw(IlvPort*,

const IlvTransformer* = 0,

const IlvRegion* = 0,

const IlvRegion* = 0);

virtual void transformerChanged(const IlvTransformer*,

const IlvTransformer*);

protected :

IlvRect _size;

IlvCircularScale* _cirscale;

};

void ExHook::afterDraw(IlvPort* dst,

const IlvTransformer*,

const IlvRegion*,

const IlvRegion* clip)

{

if (getManager()->isInvalidating())

getManager()->reDrawViews();

_cirscale->draw(dst, 0, 0 /*clip*/);

if (dst->isABitmap())

_cirscale->draw(getView(), 0, 0);

}

void ExHook::transformerChanged(const IlvTransformer* current,

const IlvTransformer* old)

{

IlvRect bbox;

_cirscale->boundingBox(bbox);

if (old) old->inverse(bbox);

if (current) current->apply(bbox);

if (!getManager()->isInvalidating())

{

getManager()->initReDraws();

getManager()->invalidateRegion(getView(), bbox);

}

}

 

static void

SetDoubleBuffering(IlvManager* m,

IlvView* v,

IlvEvent&,

IlAny)

{

m->setDoubleBuffering(v, !m->isDoubleBuffering(v));

}

 

int

main(int argc, char* argv[])

{

IlvDisplay* display = new IlvDisplay(“Example”, ““, argc, argv);

if (!display || display->isBad())

{

IlvFatalError(“Can’t open display”);

IlvExit(-1);

}

 

IlvView* view = new IlvView(display, “ExMan”, “Manager”,

IlvRect(0, 0, 400, 400));

view->setDestroyCallback(Quit);

IlvManager* manager = new IlvManager(display);

manager->addView(view);

manager->addAccelerator(SetDoubleBuffering, IlvKeyUp, ‘b’);

 

// Description of a map

manager->read(“../hook.ilv”);

 

// Instantiation of the hook class

ExHook* pHook = new ExHook(manager, view);

 

// Connect the hook to the manager view

manager->installViewHook(pHook);

manager->setInteractor(new IlvSelectInteractor(manager, view));

 

IlvMainLoop();

}