Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/icons.c
| Show All 29 Lines | |||||
| * \ingroup bke | * \ingroup bke | ||||
| */ | */ | ||||
| #include <math.h> | #include <math.h> | ||||
| #include <stdlib.h> | #include <stdlib.h> | ||||
| #include <string.h> | #include <string.h> | ||||
| #include "CLG_log.h" | |||||
| #include "MEM_guardedalloc.h" | #include "MEM_guardedalloc.h" | ||||
| #include "DNA_brush_types.h" | #include "DNA_brush_types.h" | ||||
| #include "DNA_collection_types.h" | #include "DNA_collection_types.h" | ||||
| #include "DNA_gpencil_types.h" | #include "DNA_gpencil_types.h" | ||||
| #include "DNA_lamp_types.h" | #include "DNA_lamp_types.h" | ||||
| #include "DNA_material_types.h" | #include "DNA_material_types.h" | ||||
| #include "DNA_object_types.h" | #include "DNA_object_types.h" | ||||
| Show All 26 Lines | |||||
| * Previews & ID's have their own functions to remove icons. | * Previews & ID's have their own functions to remove icons. | ||||
| */ | */ | ||||
| enum { | enum { | ||||
| ICON_FLAG_MANAGED = (1 << 0), | ICON_FLAG_MANAGED = (1 << 0), | ||||
| }; | }; | ||||
| /* GLOBALS */ | /* GLOBALS */ | ||||
| static CLG_LogRef LOG = {"bke.icons"}; | |||||
| static GHash *gIcons = NULL; | static GHash *gIcons = NULL; | ||||
| static int gNextIconId = 1; | static int gNextIconId = 1; | ||||
| static int gFirstIconId = 1; | static int gFirstIconId = 1; | ||||
| static GHash *gCachedPreviews = NULL; | static GHash *gCachedPreviews = NULL; | ||||
| ▲ Show 20 Lines • Show All 495 Lines • ▼ Show 20 Lines | int BKE_icon_id_ensure(struct ID *id) | ||||
| } | } | ||||
| if (id->icon_id) | if (id->icon_id) | ||||
| return id->icon_id; | return id->icon_id; | ||||
| id->icon_id = get_next_free_id(); | id->icon_id = get_next_free_id(); | ||||
| if (!id->icon_id) { | if (!id->icon_id) { | ||||
| printf("%s: Internal error - not enough IDs\n", __func__); | CLOG_ERROR(&LOG, "not enough IDs"); | ||||
| return 0; | return 0; | ||||
| } | } | ||||
| /* Ensure we synchronize ID icon_id with its previewimage if it has one. */ | /* Ensure we synchronize ID icon_id with its previewimage if it has one. */ | ||||
| PreviewImage **p_prv = BKE_previewimg_id_get_p(id); | PreviewImage **p_prv = BKE_previewimg_id_get_p(id); | ||||
| if (p_prv && *p_prv) { | if (p_prv && *p_prv) { | ||||
| BLI_assert(ELEM((*p_prv)->icon_id, 0, id->icon_id)); | BLI_assert(ELEM((*p_prv)->icon_id, 0, id->icon_id)); | ||||
| (*p_prv)->icon_id = id->icon_id; | (*p_prv)->icon_id = id->icon_id; | ||||
| Show All 28 Lines | int BKE_icon_gplayer_color_ensure(bGPDlayer *gpl) | ||||
| } | } | ||||
| if (gpl->runtime.icon_id) | if (gpl->runtime.icon_id) | ||||
| return gpl->runtime.icon_id; | return gpl->runtime.icon_id; | ||||
| gpl->runtime.icon_id = get_next_free_id(); | gpl->runtime.icon_id = get_next_free_id(); | ||||
| if (!gpl->runtime.icon_id) { | if (!gpl->runtime.icon_id) { | ||||
| printf("%s: Internal error - not enough IDs\n", __func__); | CLOG_ERROR(&LOG, "not enough IDs"); | ||||
| return 0; | return 0; | ||||
| } | } | ||||
| return icon_gplayer_color_ensure_create_icon(gpl); | return icon_gplayer_color_ensure_create_icon(gpl); | ||||
| } | } | ||||
| /** | /** | ||||
| * Return icon id of given preview, or create new icon if not found. | * Return icon id of given preview, or create new icon if not found. | ||||
| Show All 15 Lines | int BKE_icon_preview_ensure(ID *id, PreviewImage *preview) | ||||
| if (id && id->icon_id) { | if (id && id->icon_id) { | ||||
| preview->icon_id = id->icon_id; | preview->icon_id = id->icon_id; | ||||
| return preview->icon_id; | return preview->icon_id; | ||||
| } | } | ||||
| preview->icon_id = get_next_free_id(); | preview->icon_id = get_next_free_id(); | ||||
| if (!preview->icon_id) { | if (!preview->icon_id) { | ||||
| printf("%s: Internal error - not enough IDs\n", __func__); | CLOG_ERROR(&LOG, "not enough IDs"); | ||||
| return 0; | return 0; | ||||
| } | } | ||||
| /* Ensure we synchronize ID icon_id with its previewimage if available, and generate suitable 'ID' icon. */ | /* Ensure we synchronize ID icon_id with its previewimage if available, and generate suitable 'ID' icon. */ | ||||
| if (id) { | if (id) { | ||||
| id->icon_id = preview->icon_id; | id->icon_id = preview->icon_id; | ||||
| return icon_id_ensure_create_icon(id); | return icon_id_ensure_create_icon(id); | ||||
| } | } | ||||
| Icon *icon = icon_create(preview->icon_id, ICON_DATA_PREVIEW, preview); | Icon *icon = icon_create(preview->icon_id, ICON_DATA_PREVIEW, preview); | ||||
| icon->flag = ICON_FLAG_MANAGED; | icon->flag = ICON_FLAG_MANAGED; | ||||
| return preview->icon_id; | return preview->icon_id; | ||||
| } | } | ||||
| Icon *BKE_icon_get(const int icon_id) | Icon *BKE_icon_get(const int icon_id) | ||||
| { | { | ||||
| BLI_assert(BLI_thread_is_main()); | BLI_assert(BLI_thread_is_main()); | ||||
| Icon *icon = NULL; | Icon *icon = NULL; | ||||
| icon = BLI_ghash_lookup(gIcons, POINTER_FROM_INT(icon_id)); | icon = BLI_ghash_lookup(gIcons, POINTER_FROM_INT(icon_id)); | ||||
| if (!icon) { | if (!icon) { | ||||
| printf("%s: Internal error, no icon for icon ID: %d\n", __func__, icon_id); | CLOG_ERROR(&LOG, "no icon for icon ID: %d", icon_id); | ||||
| return NULL; | return NULL; | ||||
| } | } | ||||
| return icon; | return icon; | ||||
| } | } | ||||
| void BKE_icon_set(const int icon_id, struct Icon *icon) | void BKE_icon_set(const int icon_id, struct Icon *icon) | ||||
| { | { | ||||
| BLI_assert(BLI_thread_is_main()); | BLI_assert(BLI_thread_is_main()); | ||||
| void **val_p; | void **val_p; | ||||
| if (BLI_ghash_ensure_p(gIcons, POINTER_FROM_INT(icon_id), &val_p)) { | if (BLI_ghash_ensure_p(gIcons, POINTER_FROM_INT(icon_id), &val_p)) { | ||||
| printf("%s: Internal error, icon already set: %d\n", __func__, icon_id); | CLOG_ERROR(&LOG, "icon already set: %d", icon_id); | ||||
| return; | return; | ||||
| } | } | ||||
| *val_p = icon; | *val_p = icon; | ||||
| } | } | ||||
| static void icon_add_to_deferred_delete_queue(int icon_id) | static void icon_add_to_deferred_delete_queue(int icon_id) | ||||
| { | { | ||||
| ▲ Show 20 Lines • Show All 149 Lines • Show Last 20 Lines | |||||