2011-02-23 10:52:22 +00:00
|
|
|
/*
|
2011-10-10 09:38:02 +00:00
|
|
|
* ***** BEGIN GPL LICENSE BLOCK *****
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
|
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
*
|
|
|
|
|
* The Original Code is Copyright (C) 2006-2007 Blender Foundation.
|
|
|
|
|
* All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
* The Original Code is: all of this file.
|
|
|
|
|
*
|
|
|
|
|
* Contributor(s): none yet.
|
|
|
|
|
*
|
|
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
|
|
|
|
*
|
|
|
|
|
*/
|
2005-12-21 22:21:43 +00:00
|
|
|
|
2011-02-27 20:40:57 +00:00
|
|
|
/** \file blender/blenkernel/intern/icons.c
|
|
|
|
|
* \ingroup bke
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
2005-12-21 22:21:43 +00:00
|
|
|
#include <math.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
|
2007-09-02 17:25:03 +00:00
|
|
|
#include "DNA_lamp_types.h"
|
|
|
|
|
#include "DNA_material_types.h"
|
|
|
|
|
#include "DNA_texture_types.h"
|
|
|
|
|
#include "DNA_world_types.h"
|
2010-07-14 14:11:03 +00:00
|
|
|
#include "DNA_brush_types.h"
|
2005-12-21 22:21:43 +00:00
|
|
|
|
2011-01-07 18:36:47 +00:00
|
|
|
#include "BLI_utildefines.h"
|
2005-12-21 22:21:43 +00:00
|
|
|
#include "BLI_ghash.h"
|
2015-05-11 16:29:12 +02:00
|
|
|
#include "BLI_string.h"
|
2005-12-21 22:21:43 +00:00
|
|
|
|
|
|
|
|
#include "BKE_icons.h"
|
2010-02-11 16:54:25 +00:00
|
|
|
#include "BKE_global.h" /* only for G.background test */
|
2005-12-21 22:21:43 +00:00
|
|
|
|
2013-05-28 19:35:26 +00:00
|
|
|
#include "BLI_sys_types.h" // for intptr_t support
|
2008-08-17 17:11:00 +00:00
|
|
|
|
2013-01-22 11:18:41 +00:00
|
|
|
#include "GPU_extensions.h"
|
|
|
|
|
|
2015-05-11 16:29:12 +02:00
|
|
|
#include "IMB_imbuf.h"
|
|
|
|
|
#include "IMB_imbuf_types.h"
|
|
|
|
|
#include "IMB_thumbs.h"
|
|
|
|
|
|
2005-12-21 22:21:43 +00:00
|
|
|
/* GLOBALS */
|
|
|
|
|
|
2012-05-13 22:05:51 +00:00
|
|
|
static GHash *gIcons = NULL;
|
2005-12-21 22:21:43 +00:00
|
|
|
|
|
|
|
|
static int gNextIconId = 1;
|
|
|
|
|
|
|
|
|
|
static int gFirstIconId = 1;
|
|
|
|
|
|
2015-05-11 16:29:12 +02:00
|
|
|
static GHash *gCachedPreviews = NULL;
|
2005-12-21 22:21:43 +00:00
|
|
|
|
|
|
|
|
static void icon_free(void *val)
|
|
|
|
|
{
|
2012-05-13 22:05:51 +00:00
|
|
|
Icon *icon = val;
|
2005-12-21 22:21:43 +00:00
|
|
|
|
2012-03-06 18:40:15 +00:00
|
|
|
if (icon) {
|
2012-09-16 04:58:18 +00:00
|
|
|
if (icon->drawinfo_free) {
|
2005-12-21 22:21:43 +00:00
|
|
|
icon->drawinfo_free(icon->drawinfo);
|
|
|
|
|
}
|
|
|
|
|
else if (icon->drawinfo) {
|
|
|
|
|
MEM_freeN(icon->drawinfo);
|
|
|
|
|
}
|
|
|
|
|
MEM_freeN(icon);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* create an id for a new icon and make sure that ids from deleted icons get reused
|
2012-03-03 20:19:11 +00:00
|
|
|
* after the integer number range is used up */
|
2010-12-03 12:30:59 +00:00
|
|
|
static int get_next_free_id(void)
|
2005-12-21 22:21:43 +00:00
|
|
|
{
|
|
|
|
|
int startId = gFirstIconId;
|
|
|
|
|
|
|
|
|
|
/* if we haven't used up the int number range, we just return the next int */
|
2012-05-13 22:05:51 +00:00
|
|
|
if (gNextIconId >= gFirstIconId)
|
2005-12-21 22:21:43 +00:00
|
|
|
return gNextIconId++;
|
|
|
|
|
|
|
|
|
|
/* now we try to find the smallest icon id not stored in the gIcons hash */
|
2012-05-13 22:05:51 +00:00
|
|
|
while (BLI_ghash_lookup(gIcons, SET_INT_IN_POINTER(startId)) && startId >= gFirstIconId)
|
2005-12-21 22:21:43 +00:00
|
|
|
startId++;
|
|
|
|
|
|
2012-03-18 07:38:51 +00:00
|
|
|
/* if we found a suitable one that isn't used yet, return it */
|
2012-05-13 22:05:51 +00:00
|
|
|
if (startId >= gFirstIconId)
|
2005-12-21 22:21:43 +00:00
|
|
|
return startId;
|
|
|
|
|
|
|
|
|
|
/* fail */
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BKE_icons_init(int first_dyn_id)
|
|
|
|
|
{
|
|
|
|
|
gNextIconId = first_dyn_id;
|
|
|
|
|
gFirstIconId = first_dyn_id;
|
|
|
|
|
|
|
|
|
|
if (!gIcons)
|
2015-05-11 16:29:12 +02:00
|
|
|
gIcons = BLI_ghash_int_new(__func__);
|
|
|
|
|
|
|
|
|
|
if (!gCachedPreviews) {
|
|
|
|
|
gCachedPreviews = BLI_ghash_str_new(__func__);
|
|
|
|
|
}
|
2005-12-21 22:21:43 +00:00
|
|
|
}
|
|
|
|
|
|
2011-02-13 10:52:18 +00:00
|
|
|
void BKE_icons_free(void)
|
2005-12-21 22:21:43 +00:00
|
|
|
{
|
2015-05-11 16:29:12 +02:00
|
|
|
if (gIcons) {
|
2011-02-13 10:52:18 +00:00
|
|
|
BLI_ghash_free(gIcons, NULL, icon_free);
|
2015-05-11 16:29:12 +02:00
|
|
|
gIcons = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (gCachedPreviews) {
|
|
|
|
|
BLI_ghash_free(gCachedPreviews, MEM_freeN, BKE_previewimg_freefunc);
|
|
|
|
|
gCachedPreviews = NULL;
|
|
|
|
|
}
|
2005-12-21 22:21:43 +00:00
|
|
|
}
|
|
|
|
|
|
2015-05-11 16:29:12 +02:00
|
|
|
static PreviewImage *previewimg_create_ex(size_t deferred_data_size)
|
2007-09-02 17:25:03 +00:00
|
|
|
{
|
2012-05-13 22:05:51 +00:00
|
|
|
PreviewImage *prv_img = NULL;
|
2007-09-02 17:25:03 +00:00
|
|
|
int i;
|
|
|
|
|
|
2015-05-11 16:29:12 +02:00
|
|
|
prv_img = MEM_mallocN(sizeof(PreviewImage) + deferred_data_size, "img_prv");
|
|
|
|
|
memset(prv_img, 0, sizeof(*prv_img)); /* leave deferred data dirty */
|
|
|
|
|
|
|
|
|
|
if (deferred_data_size) {
|
|
|
|
|
prv_img->use_deferred = true;
|
|
|
|
|
}
|
2007-09-02 17:25:03 +00:00
|
|
|
|
2012-05-13 22:05:51 +00:00
|
|
|
for (i = 0; i < NUM_ICON_SIZES; ++i) {
|
2015-05-11 16:29:12 +02:00
|
|
|
prv_img->flag[i] |= PRV_CHANGED;
|
2010-07-14 14:11:03 +00:00
|
|
|
prv_img->changed_timestamp[i] = 0;
|
2007-09-02 17:25:03 +00:00
|
|
|
}
|
|
|
|
|
return prv_img;
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-11 16:29:12 +02:00
|
|
|
PreviewImage *BKE_previewimg_create(void)
|
|
|
|
|
{
|
|
|
|
|
return previewimg_create_ex(0);
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-18 19:42:30 +00:00
|
|
|
void BKE_previewimg_freefunc(void *link)
|
2007-09-02 17:25:03 +00:00
|
|
|
{
|
2011-05-18 19:42:30 +00:00
|
|
|
PreviewImage *prv = (PreviewImage *)link;
|
|
|
|
|
if (prv) {
|
2007-09-02 17:25:03 +00:00
|
|
|
int i;
|
2011-05-18 19:42:30 +00:00
|
|
|
|
2012-05-13 22:05:51 +00:00
|
|
|
for (i = 0; i < NUM_ICON_SIZES; ++i) {
|
2011-05-18 19:42:30 +00:00
|
|
|
if (prv->rect[i]) {
|
|
|
|
|
MEM_freeN(prv->rect[i]);
|
2007-09-02 17:25:03 +00:00
|
|
|
}
|
2013-01-22 11:18:41 +00:00
|
|
|
if (prv->gputexture[i])
|
|
|
|
|
GPU_texture_free(prv->gputexture[i]);
|
2007-09-02 17:25:03 +00:00
|
|
|
}
|
2013-01-22 11:18:41 +00:00
|
|
|
|
2011-05-18 19:42:30 +00:00
|
|
|
MEM_freeN(prv);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BKE_previewimg_free(PreviewImage **prv)
|
|
|
|
|
{
|
2012-03-24 06:18:31 +00:00
|
|
|
if (prv && (*prv)) {
|
2011-05-18 19:42:30 +00:00
|
|
|
BKE_previewimg_freefunc(*prv);
|
2007-09-02 17:25:03 +00:00
|
|
|
*prv = NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-11 16:29:12 +02:00
|
|
|
void BKE_previewimg_clear_single(struct PreviewImage *prv, enum eIconSizes size)
|
|
|
|
|
{
|
|
|
|
|
MEM_SAFE_FREE(prv->rect[size]);
|
|
|
|
|
if (prv->gputexture[size]) {
|
|
|
|
|
GPU_texture_free(prv->gputexture[size]);
|
|
|
|
|
}
|
|
|
|
|
prv->h[size] = prv->w[size] = 0;
|
|
|
|
|
prv->flag[size] |= PRV_CHANGED;
|
2015-05-11 17:12:31 +02:00
|
|
|
prv->flag[size] &= ~PRV_USER_EDITED;
|
2015-05-11 16:29:12 +02:00
|
|
|
prv->changed_timestamp[size] = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BKE_previewimg_clear(struct PreviewImage *prv)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
for (i = 0; i < NUM_ICON_SIZES; ++i) {
|
|
|
|
|
BKE_previewimg_clear_single(prv, i);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-13 22:05:51 +00:00
|
|
|
PreviewImage *BKE_previewimg_copy(PreviewImage *prv)
|
2007-09-02 17:25:03 +00:00
|
|
|
{
|
2012-05-13 22:05:51 +00:00
|
|
|
PreviewImage *prv_img = NULL;
|
2007-09-02 17:25:03 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
if (prv) {
|
|
|
|
|
prv_img = MEM_dupallocN(prv);
|
2012-05-13 22:05:51 +00:00
|
|
|
for (i = 0; i < NUM_ICON_SIZES; ++i) {
|
2007-09-02 17:25:03 +00:00
|
|
|
if (prv->rect[i]) {
|
|
|
|
|
prv_img->rect[i] = MEM_dupallocN(prv->rect[i]);
|
2012-03-24 06:18:31 +00:00
|
|
|
}
|
2013-01-22 11:18:41 +00:00
|
|
|
prv_img->gputexture[i] = NULL;
|
2007-09-02 17:25:03 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return prv_img;
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-11 16:29:12 +02:00
|
|
|
PreviewImage **BKE_previewimg_id_get_p(ID *id)
|
2007-09-02 17:25:03 +00:00
|
|
|
{
|
2015-05-11 16:29:12 +02:00
|
|
|
switch (GS(id->name)) {
|
2015-08-02 13:54:06 +10:00
|
|
|
#define ID_PRV_CASE(id_code, id_struct) case id_code: { return &((id_struct *)id)->preview; } ((void)0)
|
2015-05-11 16:29:12 +02:00
|
|
|
ID_PRV_CASE(ID_MA, Material);
|
|
|
|
|
ID_PRV_CASE(ID_TE, Tex);
|
|
|
|
|
ID_PRV_CASE(ID_WO, World);
|
|
|
|
|
ID_PRV_CASE(ID_LA, Lamp);
|
|
|
|
|
ID_PRV_CASE(ID_IM, Image);
|
|
|
|
|
ID_PRV_CASE(ID_BR, Brush);
|
|
|
|
|
#undef ID_PRV_CASE
|
2012-03-24 06:18:31 +00:00
|
|
|
}
|
2015-05-11 16:29:12 +02:00
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BKE_previewimg_id_free(ID *id)
|
|
|
|
|
{
|
|
|
|
|
PreviewImage **prv_p = BKE_previewimg_id_get_p(id);
|
|
|
|
|
if (prv_p) {
|
|
|
|
|
BKE_previewimg_free(prv_p);
|
2012-03-24 06:18:31 +00:00
|
|
|
}
|
2015-05-11 16:29:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PreviewImage *BKE_previewimg_id_ensure(ID *id)
|
|
|
|
|
{
|
|
|
|
|
PreviewImage **prv_p = BKE_previewimg_id_get_p(id);
|
|
|
|
|
|
|
|
|
|
if (prv_p) {
|
|
|
|
|
if (*prv_p == NULL) {
|
|
|
|
|
*prv_p = BKE_previewimg_create();
|
|
|
|
|
}
|
|
|
|
|
return *prv_p;
|
2007-09-02 17:25:03 +00:00
|
|
|
}
|
2015-05-11 16:29:12 +02:00
|
|
|
|
|
|
|
|
return NULL;
|
2007-09-02 17:25:03 +00:00
|
|
|
}
|
|
|
|
|
|
2015-05-11 16:29:12 +02:00
|
|
|
PreviewImage *BKE_previewimg_cached_get(const char *name)
|
2007-09-02 17:25:03 +00:00
|
|
|
{
|
2015-05-11 16:29:12 +02:00
|
|
|
return BLI_ghash_lookup(gCachedPreviews, name);
|
|
|
|
|
}
|
2007-09-02 17:25:03 +00:00
|
|
|
|
2015-05-11 16:29:12 +02:00
|
|
|
/**
|
|
|
|
|
* Generate an empty PreviewImage, if not yet existing.
|
|
|
|
|
*/
|
|
|
|
|
PreviewImage *BKE_previewimg_cached_ensure(const char *name)
|
|
|
|
|
{
|
|
|
|
|
PreviewImage *prv = NULL;
|
|
|
|
|
void **prv_p;
|
|
|
|
|
|
|
|
|
|
if (!BLI_ghash_ensure_p_ex(gCachedPreviews, name, &prv_p, (GHashKeyCopyFP)BLI_strdup)) {
|
|
|
|
|
*prv_p = BKE_previewimg_create();
|
2012-03-24 06:18:31 +00:00
|
|
|
}
|
2015-05-11 16:29:12 +02:00
|
|
|
prv = *prv_p;
|
|
|
|
|
BLI_assert(prv);
|
|
|
|
|
|
|
|
|
|
return prv;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Generate a PreviewImage from given file path, using thumbnails management, if not yet existing.
|
|
|
|
|
*/
|
|
|
|
|
PreviewImage *BKE_previewimg_cached_thumbnail_read(
|
|
|
|
|
const char *name, const char *path, const int source, bool force_update)
|
|
|
|
|
{
|
|
|
|
|
PreviewImage *prv = NULL;
|
|
|
|
|
void **prv_p;
|
|
|
|
|
|
|
|
|
|
prv_p = BLI_ghash_lookup_p(gCachedPreviews, name);
|
|
|
|
|
|
|
|
|
|
if (prv_p) {
|
|
|
|
|
prv = *prv_p;
|
|
|
|
|
BLI_assert(prv);
|
2012-03-24 06:18:31 +00:00
|
|
|
}
|
2015-05-11 16:29:12 +02:00
|
|
|
|
|
|
|
|
if (prv && force_update) {
|
|
|
|
|
const char *prv_deferred_data = PRV_DEFERRED_DATA(prv);
|
|
|
|
|
if (((int)prv_deferred_data[0] == source) && STREQ(&prv_deferred_data[1], path)) {
|
|
|
|
|
/* If same path, no need to re-allocate preview, just clear it up. */
|
|
|
|
|
BKE_previewimg_clear(prv);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
BKE_previewimg_free(&prv);
|
|
|
|
|
}
|
2012-03-24 06:18:31 +00:00
|
|
|
}
|
2015-05-11 16:29:12 +02:00
|
|
|
|
|
|
|
|
if (!prv) {
|
|
|
|
|
/* We pack needed data for lazy loading (source type, in a single char, and path). */
|
|
|
|
|
const size_t deferred_data_size = strlen(path) + 2;
|
|
|
|
|
char *deferred_data;
|
|
|
|
|
|
|
|
|
|
prv = previewimg_create_ex(deferred_data_size);
|
|
|
|
|
deferred_data = PRV_DEFERRED_DATA(prv);
|
|
|
|
|
deferred_data[0] = source;
|
|
|
|
|
memcpy(&deferred_data[1], path, deferred_data_size - 1);
|
|
|
|
|
|
|
|
|
|
force_update = true;
|
2012-03-24 06:18:31 +00:00
|
|
|
}
|
2015-05-11 16:29:12 +02:00
|
|
|
|
|
|
|
|
if (force_update) {
|
|
|
|
|
if (prv_p) {
|
|
|
|
|
*prv_p = prv;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
BLI_ghash_insert(gCachedPreviews, BLI_strdup(name), prv);
|
|
|
|
|
}
|
2012-03-24 06:18:31 +00:00
|
|
|
}
|
2015-05-11 16:29:12 +02:00
|
|
|
|
|
|
|
|
return prv;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BKE_previewimg_cached_release(const char *name)
|
|
|
|
|
{
|
|
|
|
|
PreviewImage *prv = BLI_ghash_popkey(gCachedPreviews, name, MEM_freeN);
|
|
|
|
|
|
|
|
|
|
if (prv) {
|
|
|
|
|
if (prv->icon_id) {
|
|
|
|
|
BKE_icon_delete(prv->icon_id);
|
|
|
|
|
}
|
|
|
|
|
BKE_previewimg_freefunc(prv);
|
2010-07-14 14:11:03 +00:00
|
|
|
}
|
2015-05-11 16:29:12 +02:00
|
|
|
}
|
2007-09-02 17:25:03 +00:00
|
|
|
|
2015-05-11 16:29:12 +02:00
|
|
|
/** Handle deferred (lazy) loading/generation of preview image, if needed.
|
|
|
|
|
* For now, only used with file thumbnails. */
|
|
|
|
|
void BKE_previewimg_ensure(PreviewImage *prv, const int size)
|
|
|
|
|
{
|
|
|
|
|
if (prv->use_deferred) {
|
|
|
|
|
const bool do_icon = ((size == ICON_SIZE_ICON) && !prv->rect[ICON_SIZE_ICON]);
|
|
|
|
|
const bool do_preview = ((size == ICON_SIZE_PREVIEW) && !prv->rect[ICON_SIZE_PREVIEW]);
|
|
|
|
|
|
|
|
|
|
if (do_icon || do_preview) {
|
|
|
|
|
ImBuf *thumb;
|
|
|
|
|
char *prv_deferred_data = PRV_DEFERRED_DATA(prv);
|
|
|
|
|
int source = prv_deferred_data[0];
|
|
|
|
|
char *path = &prv_deferred_data[1];
|
|
|
|
|
int icon_w, icon_h;
|
|
|
|
|
|
|
|
|
|
thumb = IMB_thumb_manage(path, THB_LARGE, source);
|
|
|
|
|
|
|
|
|
|
if (thumb) {
|
|
|
|
|
/* PreviewImage assumes premultiplied alhpa... */
|
|
|
|
|
IMB_premultiply_alpha(thumb);
|
|
|
|
|
|
|
|
|
|
if (do_preview) {
|
|
|
|
|
prv->w[ICON_SIZE_PREVIEW] = thumb->x;
|
|
|
|
|
prv->h[ICON_SIZE_PREVIEW] = thumb->y;
|
|
|
|
|
prv->rect[ICON_SIZE_PREVIEW] = MEM_dupallocN(thumb->rect);
|
|
|
|
|
prv->flag[ICON_SIZE_PREVIEW] &= ~(PRV_CHANGED | PRV_USER_EDITED);
|
|
|
|
|
}
|
|
|
|
|
if (do_icon) {
|
|
|
|
|
if (thumb->x > thumb->y) {
|
|
|
|
|
icon_w = ICON_RENDER_DEFAULT_HEIGHT;
|
|
|
|
|
icon_h = (thumb->y * icon_w) / thumb->x + 1;
|
|
|
|
|
}
|
|
|
|
|
else if (thumb->x < thumb->y) {
|
|
|
|
|
icon_h = ICON_RENDER_DEFAULT_HEIGHT;
|
|
|
|
|
icon_w = (thumb->x * icon_h) / thumb->y + 1;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
icon_w = icon_h = ICON_RENDER_DEFAULT_HEIGHT;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
IMB_scaleImBuf(thumb, icon_w, icon_h);
|
|
|
|
|
prv->w[ICON_SIZE_ICON] = icon_w;
|
|
|
|
|
prv->h[ICON_SIZE_ICON] = icon_h;
|
|
|
|
|
prv->rect[ICON_SIZE_ICON] = MEM_dupallocN(thumb->rect);
|
|
|
|
|
prv->flag[ICON_SIZE_ICON] &= ~(PRV_CHANGED | PRV_USER_EDITED);
|
|
|
|
|
}
|
|
|
|
|
IMB_freeImBuf(thumb);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2007-09-02 17:25:03 +00:00
|
|
|
}
|
2005-12-21 22:21:43 +00:00
|
|
|
|
|
|
|
|
void BKE_icon_changed(int id)
|
|
|
|
|
{
|
2012-05-13 22:05:51 +00:00
|
|
|
Icon *icon = NULL;
|
2005-12-21 22:21:43 +00:00
|
|
|
|
2010-02-11 16:54:25 +00:00
|
|
|
if (!id || G.background) return;
|
2005-12-21 22:21:43 +00:00
|
|
|
|
2008-02-18 10:49:46 +00:00
|
|
|
icon = BLI_ghash_lookup(gIcons, SET_INT_IN_POINTER(id));
|
2005-12-21 22:21:43 +00:00
|
|
|
|
2012-03-06 18:40:15 +00:00
|
|
|
if (icon) {
|
2015-05-11 16:29:12 +02:00
|
|
|
PreviewImage *prv = BKE_previewimg_id_ensure((ID *)icon->obj);
|
2007-09-02 17:25:03 +00:00
|
|
|
|
|
|
|
|
/* all previews changed */
|
|
|
|
|
if (prv) {
|
|
|
|
|
int i;
|
2012-05-13 22:05:51 +00:00
|
|
|
for (i = 0; i < NUM_ICON_SIZES; ++i) {
|
2015-05-11 16:29:12 +02:00
|
|
|
prv->flag[i] |= PRV_CHANGED;
|
2010-07-14 14:11:03 +00:00
|
|
|
prv->changed_timestamp[i]++;
|
2007-09-02 17:25:03 +00:00
|
|
|
}
|
|
|
|
|
}
|
2012-09-16 04:58:18 +00:00
|
|
|
}
|
2005-12-21 22:21:43 +00:00
|
|
|
}
|
|
|
|
|
|
2015-05-11 16:29:12 +02:00
|
|
|
int BKE_icon_id_ensure(struct ID *id)
|
2005-12-21 22:21:43 +00:00
|
|
|
{
|
2012-05-13 22:05:51 +00:00
|
|
|
Icon *new_icon = NULL;
|
2005-12-21 22:21:43 +00:00
|
|
|
|
2010-02-11 16:54:25 +00:00
|
|
|
if (!id || G.background)
|
2005-12-21 22:21:43 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
if (id->icon_id)
|
|
|
|
|
return id->icon_id;
|
|
|
|
|
|
|
|
|
|
id->icon_id = get_next_free_id();
|
|
|
|
|
|
2012-02-27 10:35:39 +00:00
|
|
|
if (!id->icon_id) {
|
2015-05-11 16:29:12 +02:00
|
|
|
printf("%s: Internal error - not enough IDs\n", __func__);
|
2005-12-21 22:21:43 +00:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-11 16:29:12 +02:00
|
|
|
new_icon = MEM_mallocN(sizeof(Icon), __func__);
|
2005-12-21 22:21:43 +00:00
|
|
|
|
|
|
|
|
new_icon->obj = id;
|
|
|
|
|
new_icon->type = GS(id->name);
|
|
|
|
|
|
|
|
|
|
/* next two lines make sure image gets created */
|
2011-02-13 10:52:18 +00:00
|
|
|
new_icon->drawinfo = NULL;
|
|
|
|
|
new_icon->drawinfo_free = NULL;
|
2005-12-21 22:21:43 +00:00
|
|
|
|
2008-02-18 10:49:46 +00:00
|
|
|
BLI_ghash_insert(gIcons, SET_INT_IN_POINTER(id->icon_id), new_icon);
|
2005-12-21 22:21:43 +00:00
|
|
|
|
|
|
|
|
return id->icon_id;
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-11 16:29:12 +02:00
|
|
|
/**
|
|
|
|
|
* Return icon id of given preview, or create new icon if not found.
|
|
|
|
|
*/
|
|
|
|
|
int BKE_icon_preview_ensure(PreviewImage *preview)
|
|
|
|
|
{
|
|
|
|
|
Icon *new_icon = NULL;
|
|
|
|
|
|
|
|
|
|
if (!preview || G.background)
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
if (preview->icon_id)
|
|
|
|
|
return preview->icon_id;
|
|
|
|
|
|
|
|
|
|
preview->icon_id = get_next_free_id();
|
|
|
|
|
|
|
|
|
|
if (!preview->icon_id) {
|
|
|
|
|
printf("%s: Internal error - not enough IDs\n", __func__);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
new_icon = MEM_mallocN(sizeof(Icon), __func__);
|
|
|
|
|
|
|
|
|
|
new_icon->obj = preview;
|
|
|
|
|
new_icon->type = 0; /* Special, tags as non-ID icon/preview. */
|
|
|
|
|
|
|
|
|
|
/* next two lines make sure image gets created */
|
|
|
|
|
new_icon->drawinfo = NULL;
|
|
|
|
|
new_icon->drawinfo_free = NULL;
|
|
|
|
|
|
|
|
|
|
BLI_ghash_insert(gIcons, SET_INT_IN_POINTER(preview->icon_id), new_icon);
|
|
|
|
|
|
|
|
|
|
return preview->icon_id;
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-13 22:05:51 +00:00
|
|
|
Icon *BKE_icon_get(int icon_id)
|
2005-12-21 22:21:43 +00:00
|
|
|
{
|
2012-05-13 22:05:51 +00:00
|
|
|
Icon *icon = NULL;
|
2005-12-21 22:21:43 +00:00
|
|
|
|
2008-02-18 10:49:46 +00:00
|
|
|
icon = BLI_ghash_lookup(gIcons, SET_INT_IN_POINTER(icon_id));
|
2005-12-21 22:21:43 +00:00
|
|
|
|
|
|
|
|
if (!icon) {
|
2015-05-11 16:29:12 +02:00
|
|
|
printf("%s: Internal error, no icon for icon ID: %d\n", __func__, icon_id);
|
2011-02-13 10:52:18 +00:00
|
|
|
return NULL;
|
2005-12-21 22:21:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return icon;
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-13 22:05:51 +00:00
|
|
|
void BKE_icon_set(int icon_id, struct Icon *icon)
|
2005-12-21 22:21:43 +00:00
|
|
|
{
|
2015-04-06 20:03:49 +10:00
|
|
|
void **val_p;
|
2005-12-21 22:21:43 +00:00
|
|
|
|
2015-04-06 20:03:49 +10:00
|
|
|
if (BLI_ghash_ensure_p(gIcons, SET_INT_IN_POINTER(icon_id), &val_p)) {
|
2015-05-11 16:29:12 +02:00
|
|
|
printf("%s: Internal error, icon already set: %d\n", __func__, icon_id);
|
2005-12-21 22:21:43 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-06 20:03:49 +10:00
|
|
|
*val_p = icon;
|
2005-12-21 22:21:43 +00:00
|
|
|
}
|
|
|
|
|
|
2015-05-11 16:29:12 +02:00
|
|
|
void BKE_icon_id_delete(struct ID *id)
|
2005-12-21 22:21:43 +00:00
|
|
|
{
|
2012-05-13 22:05:51 +00:00
|
|
|
if (!id->icon_id) return; /* no icon defined for library object */
|
2005-12-21 22:21:43 +00:00
|
|
|
|
2011-02-13 10:52:18 +00:00
|
|
|
BLI_ghash_remove(gIcons, SET_INT_IN_POINTER(id->icon_id), NULL, icon_free);
|
2005-12-21 22:21:43 +00:00
|
|
|
id->icon_id = 0;
|
|
|
|
|
}
|
2015-05-11 16:29:12 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Remove icon and free data.
|
|
|
|
|
*/
|
|
|
|
|
void BKE_icon_delete(int icon_id)
|
|
|
|
|
{
|
|
|
|
|
Icon *icon;
|
|
|
|
|
|
|
|
|
|
if (!icon_id) return; /* no icon defined for library object */
|
|
|
|
|
|
|
|
|
|
icon = BLI_ghash_popkey(gIcons, SET_INT_IN_POINTER(icon_id), NULL);
|
|
|
|
|
|
|
|
|
|
if (icon) {
|
|
|
|
|
if (icon->type) {
|
|
|
|
|
((ID *)(icon->obj))->icon_id = 0;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
((PreviewImage *)(icon->obj))->icon_id = 0;
|
|
|
|
|
}
|
|
|
|
|
icon_free(icon);
|
|
|
|
|
}
|
|
|
|
|
}
|