static DrawInfo *def_internal_icon(ImBuf *bbuf, int icon_id, int xofs, int yofs, int size, int type) { Icon *new_icon = NULL; IconImage *iimg = NULL; DrawInfo *di; new_icon = MEM_callocN(sizeof(Icon), "texicon"); new_icon->obj = NULL; /* icon is not for library object */ new_icon->type = 0; di = MEM_callocN(sizeof(DrawInfo), "drawinfo"); di->type = type; if (type == ICON_TYPE_TEXTURE) { di->data.texture.x = xofs; di->data.texture.y = yofs; di->data.texture.w = size; di->data.texture.h = size; } else if (type == ICON_TYPE_BUFFER) { iimg = MEM_callocN(sizeof(IconImage), "icon_img"); iimg->w = size; iimg->h = size; /* icon buffers can get initialized runtime now, via datatoc */ if (bbuf) { int y, imgsize; iimg->rect = MEM_mallocN(size * size * sizeof(unsigned int), "icon_rect"); /* Here we store the rect in the icon - same as before */ if (size == bbuf->x && size == bbuf->y && xofs == 0 && yofs == 0) memcpy(iimg->rect, bbuf->rect, size * size * sizeof(int)); else { /* this code assumes square images */ imgsize = bbuf->x; for (y = 0; y < size; y++) { memcpy(&iimg->rect[y * size], &bbuf->rect[(y + yofs) * imgsize + xofs], size * sizeof(int)); } } } di->data.buffer.image = iimg; } new_icon->drawinfo_free = UI_icons_free_drawinfo; new_icon->drawinfo = di; BKE_icon_set(icon_id, new_icon); return di; }
static void def_internal_vicon(int icon_id, VectorDrawFunc drawFunc) { Icon *new_icon = NULL; DrawInfo *di; new_icon = MEM_callocN(sizeof(Icon), "texicon"); new_icon->obj = NULL; /* icon is not for library object */ new_icon->type = 0; di = MEM_callocN(sizeof(DrawInfo), "drawinfo"); di->type = ICON_TYPE_VECTOR; di->data.vector.func = drawFunc; new_icon->drawinfo_free = NULL; new_icon->drawinfo = di; BKE_icon_set(icon_id, new_icon); }
static void def_internal_icon(ImBuf *bbuf, int icon_id, int xofs, int yofs, int size, int type) { Icon *new_icon = NULL; IconImage *iimg = NULL; DrawInfo *di; int y = 0; int imgsize = 0; new_icon = MEM_callocN(sizeof(Icon), "texicon"); new_icon->obj = NULL; /* icon is not for library object */ new_icon->type = 0; di = MEM_callocN(sizeof(DrawInfo), "drawinfo"); di->type= type; if(type == ICON_TYPE_TEXTURE) { di->data.texture.x= xofs; di->data.texture.y= yofs; di->data.texture.w= size; di->data.texture.h= size; } else if(type == ICON_TYPE_BUFFER) { iimg = MEM_mallocN(sizeof(IconImage), "icon_img"); iimg->rect = MEM_mallocN(size*size*sizeof(unsigned int), "icon_rect"); iimg->w = size; iimg->h = size; /* Here we store the rect in the icon - same as before */ imgsize = bbuf->x; for (y=0; y<size; y++) { memcpy(&iimg->rect[y*size], &bbuf->rect[(y+yofs)*imgsize+xofs], size*sizeof(int)); } di->data.buffer.image = iimg; } new_icon->drawinfo_free = UI_icons_free_drawinfo; new_icon->drawinfo = di; BKE_icon_set(icon_id, new_icon); }