// this is an attempt to clarify the lifespan of a widget vcell *world_create() { vcell *world = vcell_quickcreate("world",0,0, 320,200); void world_mouse(vcell *self) { // interact // the coordinates supplied should be in easily digestable chunks // if the UI was designed for a specific pixel size (common) then // that size will be given, ie a mouse at the top left may be 00, and at the bottom right (320,200) // this was the designed size and all rendering is expected at this size // even if 320,200 is being stretched all the way upto 800,480 or even displayed as a thumbnail } void world_paint(vcell *self,painteventargs *args) { // i may make the graphics view enter the function pre-initialized, since it may have been used earlier to // find out the mouse was inside or to render its parent. //vgraph *graph = args->graph; // instead at this point I have direct construction // tile will be replaced by cell soon vgraph *graph = vgraph_new(); vgraph_setrendertarget(graph, canvas.image); vgraph_setviewscale( graph, self->x,self->y, self->w,self->h ); vgraph_setbackcolor( graph, mkYUV(255,128,100) ); vgraph_setpencolor( graph, mkYUV(255,128,100) ); vgraph_setpenthick( graph, 4 ); vgraph_setfont( graph, vfont_newfromlibrary("arial",18,0) ); vgraph_drawclear( graph, ); vgraph_drawpoint( graph, self->x,self->y ); vgraph_drawline( graph, self->x,self->y, 100,500 ); vgraph_drawbox( graph, self->x,self->y, self->w,self->h ); vgraph_drawrect( graph, self->x,self->y, self->w/2,self->h ); vgraph_drawcircle( graph, self->x,self->y, 50 ); vgraph_drawellipse( graph, self->x,self->y, 50 ,40 ); vgraph_drawtext( graph, self->x,self->y, "hello world" ); vgraph_release( graph); } // link handlers now world->handler_paint = world_paint; world->handler_mouse = world_mouse; return world; } int main() { // initialize application // open display // run program vcell_easyrun( world_create() ); // hold breath for reference counting to work... // cleanup }