2 * ***** BEGIN GPL LICENSE BLOCK *****
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software Foundation,
16 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * The Original Code is Copyright (C) 2006-2007 Blender Foundation.
19 * All rights reserved.
21 * The Original Code is: all of this file.
23 * Contributor(s): none yet.
25 * ***** END GPL LICENSE BLOCK *****
28 #ifndef __BKE_ICONS_H__
29 #define __BKE_ICONS_H__
34 * Resizable Icons for Blender
37 typedef void (*DrawInfoFreeFP)(void *drawinfo);
40 /** ID preview: obj is #ID. */
42 /** Preview: obj is #PreviewImage */
44 /** 2D triangles: obj is #Icon_Geom */
47 ICON_DATA_STUDIOLIGHT,
48 /** GPencil Layer color preview (annotations): obj is #bGPDlayer */
55 * Data defined by #obj_type
56 * \note for #ICON_DATA_GEOM the memory is owned by the icon,
57 * could be made into a flag if we want that to be optional.
61 /** Internal use only. */
63 /** #ID_Type or 0 when not used for ID preview. */
65 DrawInfoFreeFP drawinfo_free;
68 /** Used for #ICON_DATA_GEOM, assigned to #Icon.obj. */
73 const unsigned char (*coords)[2];
74 const unsigned char (*colors)[4];
75 /* when not NULL, the memory of coords and colors is a sub-region of this pointer. */
79 typedef struct Icon Icon;
89 void BKE_icons_init(int first_dyn_id);
91 /* return icon id for library object or create new icon if not found */
92 int BKE_icon_id_ensure(struct ID *id);
94 /* return icon id for Grease Pencil layer (color preview) or create new icon if not found */
95 int BKE_icon_gplayer_color_ensure(struct bGPDlayer *gpl);
97 int BKE_icon_preview_ensure(struct ID *id, struct PreviewImage *preview);
99 /* retrieve icon for id */
100 struct Icon *BKE_icon_get(const int icon_id);
102 /* set icon for id if not already defined */
103 /* used for inserting the internal icons */
104 void BKE_icon_set(const int icon_id, struct Icon *icon);
106 /* remove icon and free data if library object becomes invalid */
107 void BKE_icon_id_delete(struct ID *id);
109 bool BKE_icon_delete(const int icon_id);
110 bool BKE_icon_delete_unmanaged(const int icon_id);
112 /* report changes - icon needs to be recalculated */
113 void BKE_icon_changed(const int icon_id);
116 void BKE_icons_free(void);
118 /* free all icons marked for deferred deletion */
119 void BKE_icons_deferred_free(void);
121 /* free the preview image for use in list */
122 void BKE_previewimg_freefunc(void *link);
124 /* free the preview image */
125 void BKE_previewimg_free(struct PreviewImage **prv);
127 /* clear the preview image or icon, but does not free it */
128 void BKE_previewimg_clear(struct PreviewImage *prv);
130 /* clear the preview image or icon at a specific size */
131 void BKE_previewimg_clear_single(struct PreviewImage *prv, enum eIconSizes size);
133 /* get the preview from any pointer */
134 struct PreviewImage **BKE_previewimg_id_get_p(const struct ID *id);
136 /* free the preview image belonging to the id */
137 void BKE_previewimg_id_free(struct ID *id);
139 /* create a new preview image */
140 struct PreviewImage *BKE_previewimg_create(void);
142 /* create a copy of the preview image */
143 struct PreviewImage *BKE_previewimg_copy(const struct PreviewImage *prv);
145 void BKE_previewimg_id_copy(struct ID *new_id, const struct ID *old_id);
147 /* retrieve existing or create new preview image */
148 struct PreviewImage *BKE_previewimg_id_ensure(struct ID *id);
150 void BKE_previewimg_ensure(struct PreviewImage *prv, const int size);
152 struct PreviewImage *BKE_previewimg_cached_get(const char *name);
154 struct PreviewImage *BKE_previewimg_cached_ensure(const char *name);
156 struct PreviewImage *BKE_previewimg_cached_thumbnail_read(
157 const char *name, const char *path, const int source, bool force_update);
159 void BKE_previewimg_cached_release(const char *name);
160 void BKE_previewimg_cached_release_pointer(struct PreviewImage *prv);
162 int BKE_icon_geom_ensure(struct Icon_Geom *geom);
163 struct Icon_Geom *BKE_icon_geom_from_memory(const uchar *data, size_t data_len);
164 struct Icon_Geom *BKE_icon_geom_from_file(const char *filename);
166 struct ImBuf *BKE_icon_geom_rasterize(
167 const struct Icon_Geom *geom,
168 const unsigned int size_x, const unsigned int size_y);
170 int BKE_icon_ensure_studio_light(struct StudioLight *sl, int id_type);
172 #define ICON_RENDER_DEFAULT_HEIGHT 32
174 #endif /* __BKE_ICONS_H__ */