@xeron
I extended bitmap.image instead of button.gadget but the solution still works great for me.
Here are some C++ snippets to get you going...
struct InstanceData {
BitMap* bitmap;
uint32 width;
uint32 height;
};
IClass* iclass =
IIntuition->MakeClass(0, 0, BitMapClass, sizeof(InstanceData), 0);
iclass->cl_Dispatcher.h_Entry = reinterpret_cast<HOOKFUNC>(dispatcher);
iclass->cl_Dispatcher.h_SubEntry = 0;
iclass->cl_Dispatcher.h_Data = 0;
uint32 dispatcher(IClass* iclass, Object* obj, Msg msg)
{
uint32 retval = 0;
switch ( msg->MethodID ) {
case OM_NEW:
{
retval = IIntuition->IDoSuperMethodA(iclass, obj, msg);
InstanceData* data =
static_cast<InstanceData*>(INST_DATA(iclass, retval));
opSet* op = reinterpret_cast<opSet*>(msg);
data->bitmap = reinterpret_cast<BitMap*>(
IUtility->GetTagData(BITMAP_BitMap, 0, op->ops_AttrList));
data->width =
IUtility->GetTagData(BITMAP_Width, 1, op->ops_AttrList);
data->height =
IUtility->GetTagData(BITMAP_Height, 1, op->ops_AttrList);
break;
}
case IM_DRAW:
{
impDraw* imp = reinterpret_cast<impDraw*>(msg);
InstanceData* data =
static_cast<InstanceData*>(INST_DATA(iclass, obj));
Image* image = reinterpret_cast<Image*>(obj);
int32 dx = image->LeftEdge + imp->imp_Offset.X;
int32 dy = image->TopEdge + imp->imp_Offset.Y;
uint32 iwidth = image->Width;
uint32 iheight = image->Height;
if ( iwidth > data->width ) {
dx += (iwidth - data->width) / 2;
}
if ( iheight > data->height ) {
dy += (iheight - data->height) / 2;
}
uint32 bgpen = 0;
(void)IIntuition->GetAttr(IA_BGPen, obj, &bgpen);
IGraphics->SetAPen(imp->imp_RPort, bgpen);
IGraphics->RectFill(imp->imp_RPort, dx, dy,
dx + data->width - 1, dy + data->height - 1);
(void)IGraphics->BltBitMapTags(
BLITA_Source, data->bitmap,
BLITA_UseSrcAlpha, TRUE,
BLITA_Dest, imp->imp_RPort,
BLITA_DestType, BLITT_RASTPORT,
BLITA_DestX, dx,
BLITA_DestY, dy,
BLITA_Width, data->width,
BLITA_Height, data->height,
TAG_END);
break;
}
default:
{
retval = IIntuition->IDoSuperMethodA(iclass, obj, msg);
break;
}
};
return retval;
}