Moderator
Posts: 2362 from 2003/2/24
Well doing the same here (MUI+cairo) and it's really no magic:
Code:
static ULONG mSetup(struct IClass *cl,Object *obj,Msg msg)
{
struct Data *data = (struct Data*)INST_DATA(cl,obj);
data->renderbuffer = new RenderBuffer(_screen(obj)->Width,_screen(obj)->Height);
return DoSuperMethodA(cl,obj,msg);
}
DISPATCHER(DisplayClass)
{
switch (msg->MethodID)
{
................
case MUIM_Setup : return(mSetup (cl,obj,(Msg)msg));
................
}
return(DoSuperMethodA(cl,obj,msg));
}
DISPATCHER_END
Were "RenderBuffer" is a class that encapsultes cairo_surfcae_t, cairo_t and a few other things.
So now you have a valid cairo-instance before your object is drawn 1st time.
A few things to add to my unfinished example:
- I allocate based on the screensize as my MUI-object hasn't a size limit
- I don't do any errorchecking (still to come)
- I don't free the RenderBuffer in MUIM_Cleanup which will be triggered everytime the window gets iconified or is move to another screen. Instead I loose a freaking bunch of MBs everytime that happens
So don't copy this vanilla, just use it as a starting point.
Edit:
Yeah, using MUIM_Show and MUIM_Hide instead might also be a good idea
[ Edited by Kronos 04.11.2011 - 14:34 ]