Example with Open Interface (OI)
The example below illustrates the integration of Views with Open Interface:
#include <OI/oi.H>
#include <ilviews/view.h>
// ------------------------------------------------------------
// Augments the OI_box translations so that Views Views receives
// events
// ------------------------------------------------------------
static void
callViews(OI_box*, XEvent* xevent, char**, unsigned int*)
{
IlvEventLoop::getEventLoop()->dispatchEvent(xevent);
}
static OI_actions_rec Views_actions[]= {{"CallViews",callViews}};
static char* Views_translations[] = " \
<BtnDown>: CallViews() \n \
<BtnUp>: CallViews() \n \
<KeyDown>: CallViews() \n \
<KeyUp>: CallViews() \n \
<PtrMoved>: CallViews() \n \
<BtnMotion>: CallViews() \n \
<Enter>: CallViews() \n \
<Leave>: CallViews() \n \
<Expose>: CallViews() \n \
<GrExp>: CallViews() \n \
<Configure>: CallViews() \n";
// ------------------------------------------------------------
static void
IlvAugmentTranslations(OI_box* box)
{
OI_translation_table* translations =
OI_parse_translation_table(Views_translations);
if (translations) box->augment_translations(translations);
}
static IlvDisplay* ilv_display = 0;
// ------------------------------------------------------------
// Creates a Views Views IlvDisplay from the X Display created by
// OI
// ------------------------------------------------------------
static void
Init(OI_box* box)
{
OI_add_actions(Views_actions, OI_count(Views_actions));
ilv_display = new IlvDisplay(box->display(), "Views");
}
// -------------------------------------------------------------
IlvDisplay*
IlvOIGetDisplay(OI_box* box)
{
if (!ilv_display) Init(box);
return ilv_display;
}
// ------------------------------------------------------------
// Creates a Views Views IlvView object from the OI_box
// ------------------------------------------------------------
IlvView*
IlvOICreateView(OI_box* box)
{
IlvAugmentTranslations(box);
return new IlvView(IlvOIGetDisplay(box), (IlvAny)box->X_window());
}
// -------------------------------------------------------------
// Create a grapher and some basic objects into it
// ------------------------------------------------------------
static void
IlvCreateGrapher(IlvView* view)
{
IlvGrapher* grapher = new IlvGrapher(view->getDisplay());
grapher->addView(view);
IlvGraphic* node1 =
new IlvLabel(view->getDisplay(), IlvPoint(10, 20), "node1");
IlvGraphic* node2 =
new IlvLabel(view->getDisplay(), IlvPoint(50, 50), "node2");
grapher->addNode(node1);
grapher->addNode(node2);
grapher->addLink(new IlvLinkImage(view->getDisplay(),
IlvTrue, node1, node2));
}
// -------------------------------------------------------------
// Main procedure
// ------------------------------------------------------------
main(int argc, char* argv[])
{
OI_connection* conn = OI_init(&argc, argv, "Views");
if (conn) {
OI_app_window* wp = oi_create_app_window("main", 1, 1, "ViewsOI");
OI_box* box = oi_create_box("box", 100, 100);
IlvDisplay* display = IlvOIGetDisplay(box);
IlvView* view = IlvOICreateView(box);
IlvCreateGrapher(view);
OI_begin_interaction();
OI_fini();
}
}