A canvas client
class draw_clt : public canvas { [2]
public:
void plug(widgets::canvas* x) { draw = x; }
int operator()() {
hush::event* e = hush->event(_event->type());
cerr << "Getting event " << e->type() << endl;
e->x(_event->x()+10);
e->y(_event->y()+10);
//hush::event::_duplicate(e); // CORBA 2.0
e->_duplicate();
hush::event* res = draw->dispatch(e);
return canvas::operator()();
}
draw_clt(const widget* w, char* path ) : canvas(w,path) {
configure("-background white");
geometry(200,100);
self()->bind(this);
dragging = 0;
}
draw_clt(char* path ) : canvas(path) {
configure("-background white");
geometry(200,100);
self()->bind(this);
dragging = 0;
}
void press( event& ) { dragging = 1; }
void motion( event& e) {
if (dragging) {
self()->circle(e.x(),e.y(),2,"-fill black");
draw->circle(e.x(),e.y(),3,"-fill yellow");
}
}
void release( event& ) { dragging = 0; }
protected:
int dragging;
widgets::canvas* draw;
};
slide: A (remote) canvas client
This fragmemt shows the implementation of
a canvas which is simultaneously the client side of a remote canvas.
The method plug allows for declaring the remote canvas,
which is accessed via the instance variable draw in
both the operator method and
the motion method (whent dragging).
In the operator() an event is created which is dispatched to
the remote canvas.
Note that this is possible since a canvas is a handler.
In the motion method, a large yellow dot is drawn
on the remote canvas, whereas the local canvas draws a black dot.
Combined, the actions on the remote canvas result in
drawing parallel yellow and black dots.
The server
A canvas server
class draw_srv : public canvas {
public:
draw_srv( const widget* w, char* path ) : canvas(w,path) { (a)
geometry(200,100);
self()->bind(this);
dragging = 0;
}
void press( event& ) { dragging = 1; }
void motion( event& e) {
if (dragging) circle(e.x(),e.y(),10,"-fill black");
}
void release( event& ) { dragging = 0; }
protected:
int dragging;
};
slide: A canvas server
The canvas implementation on the server side straightforwardly
implements a hush canvas.
It is embedded in a CORBA server when an object reference
is given to it via the distributed object table.
Moving items
This example is similar to the [Canvas] example, but shows some additional features, such as how to
manipulate a list of items.
Moving items
list<hush::item>* rlist = new list<hush::item>;
item* it = draw->circle(40,40,10,"-fill yellow");
hush::item* rit = new item_srv(it);
rlist->insert(rit);
it = draw->circle(30,30,10,"-fill red");
rit = new item_srv(it);
rlist->insert(rit);
hush::container* rx = new list_srv<hush::item>(rlist);
list<hush::item>::declare("items",rx); // store server
iter<hush::item>* riter = rlist->walk();
iter<hush::item>::declare("riter",riter);
slide: Moving items
The fragment above illustrates the creation of a list
of items.
In addition it shows how to obtain an iterator and
how the iterator may be declared to make it accessible
via the distributed object table.
[]
introduction,
legacy,
interfaces,
examples,
conclusions,
references,
appendix