2023-08-16 00:20:26 +10:00
|
|
|
/* SPDX-FileCopyrightText: 2006-2007 Blender Authors
|
2023-05-31 16:19:06 +02:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
2005-12-21 22:21:43 +00:00
|
|
|
|
2012-02-17 18:59:41 +00:00
|
|
|
#pragma once
|
2005-12-21 22:21:43 +00:00
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
|
* \ingroup bke
|
2012-12-03 13:01:07 +00:00
|
|
|
*
|
2012-03-03 20:19:11 +00:00
|
|
|
* Resizable Icons for Blender
|
2020-12-14 13:21:58 +01:00
|
|
|
*
|
|
|
|
|
* There is some thread safety for this API but it is rather weak. Registering or unregistering
|
|
|
|
|
* icons is thread safe, changing data of icons from multiple threads is not. Practically this
|
|
|
|
|
* should be fine since only the main thread modifies icons. Should that change, more locks or a
|
|
|
|
|
* different design need to be introduced.
|
2012-03-03 20:19:11 +00:00
|
|
|
*/
|
2005-12-21 22:21:43 +00:00
|
|
|
|
2020-12-14 13:21:58 +01:00
|
|
|
#include "BLI_compiler_attrs.h"
|
2023-08-03 16:54:39 +02:00
|
|
|
#include "BLI_sys_types.h"
|
2020-12-14 13:21:58 +01:00
|
|
|
|
2012-05-12 20:39:39 +00:00
|
|
|
typedef void (*DrawInfoFreeFP)(void *drawinfo);
|
2005-12-21 22:21:43 +00:00
|
|
|
|
2018-04-20 15:15:10 +02:00
|
|
|
enum {
|
|
|
|
|
/** ID preview: obj is #ID. */
|
|
|
|
|
ICON_DATA_ID = 0,
|
2020-12-14 13:21:58 +01:00
|
|
|
/** Arbitrary Image buffer: obj is #ImBuf */
|
|
|
|
|
ICON_DATA_IMBUF,
|
2018-04-20 15:15:10 +02:00
|
|
|
/** Preview: obj is #PreviewImage */
|
|
|
|
|
ICON_DATA_PREVIEW,
|
|
|
|
|
/** 2D triangles: obj is #Icon_Geom */
|
|
|
|
|
ICON_DATA_GEOM,
|
2023-04-16 20:41:22 +10:00
|
|
|
/** Studio-light. */
|
2018-05-11 16:55:14 +02:00
|
|
|
ICON_DATA_STUDIOLIGHT,
|
2018-07-31 10:22:19 +02:00
|
|
|
/** GPencil Layer color preview (annotations): obj is #bGPDlayer */
|
|
|
|
|
ICON_DATA_GPLAYER,
|
2018-04-20 15:15:10 +02:00
|
|
|
};
|
|
|
|
|
|
2020-12-14 13:21:58 +01:00
|
|
|
/**
|
|
|
|
|
* \note See comment at the top regarding thread safety.
|
|
|
|
|
*/
|
2012-05-12 20:39:39 +00:00
|
|
|
struct Icon {
|
2005-12-21 22:21:43 +00:00
|
|
|
void *drawinfo;
|
2018-04-20 15:15:10 +02:00
|
|
|
/**
|
|
|
|
|
* Data defined by #obj_type
|
|
|
|
|
* \note for #ICON_DATA_GEOM the memory is owned by the icon,
|
|
|
|
|
* could be made into a flag if we want that to be optional.
|
|
|
|
|
*/
|
2005-12-21 22:21:43 +00:00
|
|
|
void *obj;
|
2018-04-20 15:15:10 +02:00
|
|
|
char obj_type;
|
|
|
|
|
/** Internal use only. */
|
|
|
|
|
char flag;
|
2018-04-19 12:52:32 +02:00
|
|
|
/** #ID_Type or 0 when not used for ID preview. */
|
|
|
|
|
short id_type;
|
2005-12-21 22:21:43 +00:00
|
|
|
DrawInfoFreeFP drawinfo_free;
|
|
|
|
|
};
|
|
|
|
|
|
2018-04-20 15:15:10 +02:00
|
|
|
/** Used for #ICON_DATA_GEOM, assigned to #Icon.obj. */
|
|
|
|
|
struct Icon_Geom {
|
|
|
|
|
int icon_id;
|
|
|
|
|
int coords_len;
|
2018-04-23 20:16:32 +02:00
|
|
|
int coords_range[2];
|
2020-02-03 17:47:04 +01:00
|
|
|
unsigned char (*coords)[2];
|
|
|
|
|
unsigned char (*colors)[4];
|
2018-04-23 20:16:32 +02:00
|
|
|
/* when not NULL, the memory of coords and colors is a sub-region of this pointer. */
|
|
|
|
|
const void *mem;
|
2018-04-20 15:15:10 +02:00
|
|
|
};
|
|
|
|
|
|
2005-12-21 22:21:43 +00:00
|
|
|
typedef struct Icon Icon;
|
|
|
|
|
|
2019-01-28 21:08:24 +11:00
|
|
|
struct ID;
|
2018-04-21 21:10:09 +02:00
|
|
|
struct ImBuf;
|
2007-09-02 17:25:03 +00:00
|
|
|
struct PreviewImage;
|
2018-05-11 16:55:14 +02:00
|
|
|
struct StudioLight;
|
2018-07-31 10:22:19 +02:00
|
|
|
struct bGPDlayer;
|
2007-09-02 17:25:03 +00:00
|
|
|
|
2005-12-21 22:21:43 +00:00
|
|
|
void BKE_icons_init(int first_dyn_id);
|
|
|
|
|
|
2021-12-07 17:19:15 +11:00
|
|
|
/**
|
|
|
|
|
* Return icon id for library object or create new icon if not found.
|
|
|
|
|
*/
|
2015-05-11 16:29:12 +02:00
|
|
|
int BKE_icon_id_ensure(struct ID *id);
|
|
|
|
|
|
2021-12-07 17:19:15 +11:00
|
|
|
/**
|
|
|
|
|
* Return icon id for Grease Pencil layer (color preview) or create new icon if not found.
|
|
|
|
|
*/
|
2018-07-31 10:22:19 +02:00
|
|
|
int BKE_icon_gplayer_color_ensure(struct bGPDlayer *gpl);
|
|
|
|
|
|
2021-12-07 17:19:15 +11:00
|
|
|
/**
|
|
|
|
|
* Return icon id of given preview, or create new icon if not found.
|
|
|
|
|
*/
|
2016-07-12 17:49:30 +02:00
|
|
|
int BKE_icon_preview_ensure(struct ID *id, struct PreviewImage *preview);
|
2005-12-21 22:21:43 +00:00
|
|
|
|
2021-12-07 17:19:15 +11:00
|
|
|
/**
|
|
|
|
|
* Create an icon as owner or \a ibuf. The icon-ID is not stored in \a ibuf,
|
|
|
|
|
* it needs to be stored separately.
|
|
|
|
|
* \note Transforms ownership of \a ibuf to the newly created icon.
|
|
|
|
|
*/
|
2020-12-14 13:21:58 +01:00
|
|
|
int BKE_icon_imbuf_create(struct ImBuf *ibuf) ATTR_WARN_UNUSED_RESULT;
|
|
|
|
|
struct ImBuf *BKE_icon_imbuf_get_buffer(int icon_id) ATTR_WARN_UNUSED_RESULT;
|
|
|
|
|
|
2021-12-07 17:19:15 +11:00
|
|
|
/**
|
|
|
|
|
* Retrieve icon for id.
|
|
|
|
|
*/
|
2022-01-07 11:38:08 +11:00
|
|
|
struct Icon *BKE_icon_get(int icon_id);
|
2005-12-21 22:21:43 +00:00
|
|
|
|
2021-12-07 17:19:15 +11:00
|
|
|
/**
|
|
|
|
|
* Set icon for id if not already defined.
|
|
|
|
|
* Used for inserting the internal icons.
|
|
|
|
|
*/
|
2022-01-07 11:38:08 +11:00
|
|
|
void BKE_icon_set(int icon_id, struct Icon *icon);
|
2005-12-21 22:21:43 +00:00
|
|
|
|
2021-12-07 17:19:15 +11:00
|
|
|
/**
|
|
|
|
|
* Remove icon and free data if library object becomes invalid.
|
|
|
|
|
*/
|
2015-05-11 16:29:12 +02:00
|
|
|
void BKE_icon_id_delete(struct ID *id);
|
|
|
|
|
|
2021-12-07 17:19:15 +11:00
|
|
|
/**
|
|
|
|
|
* Remove icon and free data.
|
|
|
|
|
*/
|
2022-01-07 11:38:08 +11:00
|
|
|
bool BKE_icon_delete(int icon_id);
|
|
|
|
|
bool BKE_icon_delete_unmanaged(int icon_id);
|
2005-12-21 22:21:43 +00:00
|
|
|
|
2021-12-07 17:19:15 +11:00
|
|
|
/**
|
|
|
|
|
* Report changes - icon needs to be recalculated.
|
|
|
|
|
*/
|
2022-01-07 11:38:08 +11:00
|
|
|
void BKE_icon_changed(int icon_id);
|
2005-12-21 22:21:43 +00:00
|
|
|
|
2021-12-07 17:19:15 +11:00
|
|
|
/**
|
|
|
|
|
* Free all icons.
|
|
|
|
|
*/
|
2010-12-03 12:30:59 +00:00
|
|
|
void BKE_icons_free(void);
|
2005-12-21 22:21:43 +00:00
|
|
|
|
2021-12-07 17:19:15 +11:00
|
|
|
/**
|
|
|
|
|
* Free all icons marked for deferred deletion.
|
|
|
|
|
*/
|
2018-04-13 13:52:37 +02:00
|
|
|
void BKE_icons_deferred_free(void);
|
|
|
|
|
|
2018-04-23 20:16:32 +02:00
|
|
|
int BKE_icon_geom_ensure(struct Icon_Geom *geom);
|
2020-12-14 13:21:58 +01:00
|
|
|
struct Icon_Geom *BKE_icon_geom_from_memory(uchar *data, size_t data_len);
|
2018-04-23 20:16:32 +02:00
|
|
|
struct Icon_Geom *BKE_icon_geom_from_file(const char *filename);
|
|
|
|
|
|
2018-04-21 21:10:09 +02:00
|
|
|
struct ImBuf *BKE_icon_geom_rasterize(const struct Icon_Geom *geom,
|
2022-01-07 11:38:08 +11:00
|
|
|
unsigned int size_x,
|
|
|
|
|
unsigned int size_y);
|
2020-02-03 17:47:04 +01:00
|
|
|
void BKE_icon_geom_invert_lightness(struct Icon_Geom *geom);
|
2018-04-21 21:10:09 +02:00
|
|
|
|
2018-05-25 08:06:36 +02:00
|
|
|
int BKE_icon_ensure_studio_light(struct StudioLight *sl, int id_type);
|
2018-05-11 16:55:14 +02:00
|
|
|
|
2015-05-11 16:29:12 +02:00
|
|
|
#define ICON_RENDER_DEFAULT_HEIGHT 32
|