Blender V5.0
gpencil_legacy.cc File Reference
#include <cmath>
#include <cstddef>
#include <cstdlib>
#include <cstring>
#include <optional>
#include "CLG_log.h"
#include "MEM_guardedalloc.h"
#include "BLI_listbase.h"
#include "BLI_math_matrix.h"
#include "BLI_math_vector.h"
#include "BLI_string_utf8.h"
#include "BLI_string_utils.hh"
#include "BLT_translation.hh"
#include "DNA_scene_types.h"
#include "DNA_brush_types.h"
#include "DNA_gpencil_legacy_types.h"
#include "DNA_material_types.h"
#include "DNA_meshdata_types.h"
#include "DNA_userdef_types.h"
#include "BKE_action.hh"
#include "BKE_anim_data.hh"
#include "BKE_brush.hh"
#include "BKE_collection.hh"
#include "BKE_colortools.hh"
#include "BKE_deform.hh"
#include "BKE_gpencil_legacy.h"
#include "BKE_icons.h"
#include "BKE_idtype.hh"
#include "BKE_image.hh"
#include "BKE_lib_id.hh"
#include "BKE_lib_query.hh"
#include "BKE_main.hh"
#include "BKE_material.hh"
#include "BKE_paint.hh"
#include "DEG_depsgraph.hh"
#include "BLI_math_color.h"
#include "BLO_read_write.hh"
#include "IMB_colormanagement.hh"

Go to the source code of this file.

Macros

#define DNA_DEPRECATED_ALLOW

Functions

static void greasepencil_copy_data (Main *, std::optional< Library * >, ID *id_dst, const ID *id_src, const int)
static void greasepencil_free_data (ID *id)
static void greasepencil_foreach_id (ID *id, LibraryForeachIDData *data)
static void greasepencil_blend_write (BlendWriter *writer, ID *id, const void *id_address)
void BKE_gpencil_blend_read_data (BlendDataReader *reader, bGPdata *gpd)
static void greasepencil_blend_read_data (BlendDataReader *reader, ID *id)
void BKE_gpencil_free_point_weights (MDeformVert *dvert)
void BKE_gpencil_free_stroke_weights (bGPDstroke *gps)
void BKE_gpencil_free_stroke_editcurve (bGPDstroke *gps)
void BKE_gpencil_free_stroke (bGPDstroke *gps)
bool BKE_gpencil_free_strokes (bGPDframe *gpf)
void BKE_gpencil_free_frames (bGPDlayer *gpl)
void BKE_gpencil_free_layer_masks (bGPDlayer *gpl)
void BKE_gpencil_free_layers (ListBase *list)
void BKE_gpencil_free_legacy_palette_data (ListBase *list)
void BKE_gpencil_free_data (bGPdata *gpd, bool)
void BKE_gpencil_tag (bGPdata *gpd)
bGPDframeBKE_gpencil_frame_addnew (bGPDlayer *gpl, int cframe)
bGPDframeBKE_gpencil_frame_addcopy (bGPDlayer *gpl, int cframe)
bGPDlayerBKE_gpencil_layer_addnew (bGPdata *gpd, const char *name, const bool setactive, const bool add_to_header)
bGPdataBKE_gpencil_data_addnew (Main *bmain, const char name[])
void BKE_gpencil_stroke_weights_duplicate (bGPDstroke *gps_src, bGPDstroke *gps_dst)
bGPDstrokeBKE_gpencil_stroke_duplicate (bGPDstroke *gps_src, const bool dup_points, const bool)
bGPDframeBKE_gpencil_frame_duplicate (const bGPDframe *gpf_src, const bool dup_strokes)
bGPDlayerBKE_gpencil_layer_duplicate (const bGPDlayer *gpl_src, const bool dup_frames, const bool dup_strokes)
bGPdataBKE_gpencil_data_duplicate (Main *bmain, const bGPdata *gpd_src, bool internal_copy)
bool BKE_gpencil_layer_is_editable (const bGPDlayer *gpl)
bGPDframeBKE_gpencil_layer_frame_find (bGPDlayer *gpl, int cframe)
bGPDframeBKE_gpencil_layer_frame_get (bGPDlayer *gpl, int cframe, eGP_GetFrame_Mode addnew)
bool BKE_gpencil_layer_frame_delete (bGPDlayer *gpl, bGPDframe *gpf)
bGPDlayerBKE_gpencil_layer_named_get (bGPdata *gpd, const char *name)
static int gpencil_cb_cmp_frame (void *thunk, const void *a, const void *b)
void BKE_gpencil_layer_frames_sort (bGPDlayer *gpl, bool *r_has_duplicate_frames)
bGPDlayerBKE_gpencil_layer_active_get (bGPdata *gpd)
void BKE_gpencil_layer_active_set (bGPdata *gpd, bGPDlayer *active)
void BKE_gpencil_layer_delete (bGPdata *gpd, bGPDlayer *gpl)
void BKE_gpencil_brush_material_set (Brush *brush, Material *ma)
void BKE_gpencil_palette_ensure (Main *bmain, Scene *scene)

Variables

static CLG_LogRef LOG = {"geom.gpencil"}
IDTypeInfo IDType_ID_GD_LEGACY

Macro Definition Documentation

◆ DNA_DEPRECATED_ALLOW

#define DNA_DEPRECATED_ALLOW

Definition at line 28 of file gpencil_legacy.cc.

Function Documentation

◆ BKE_gpencil_blend_read_data()

◆ BKE_gpencil_brush_material_set()

void BKE_gpencil_brush_material_set ( struct Brush * brush,
struct Material * material )

Set grease pencil brush material.

Parameters
brushBrush
materialMaterial

Definition at line 1146 of file gpencil_legacy.cc.

References BKE_brush_tag_unsaved_changes(), BLI_assert, Brush::gpencil_settings, Material::id, id_us_min(), id_us_plus(), and BrushGpencilSettings::material.

◆ BKE_gpencil_data_addnew()

◆ BKE_gpencil_data_duplicate()

bGPdata * BKE_gpencil_data_duplicate ( Main * bmain,
const bGPdata * gpd_src,
bool internal_copy )

◆ BKE_gpencil_frame_addcopy()

bGPDframe * BKE_gpencil_frame_addcopy ( struct bGPDlayer * gpl,
int cframe )

Add a copy of the active gp-frame to the given layer.

Parameters
gplGrease pencil layer
cframeFrame number
Returns
Pointer to new frame

Definition at line 510 of file gpencil_legacy.cc.

References bGPDlayer::actframe, BKE_gpencil_frame_addnew(), BKE_gpencil_frame_duplicate(), BKE_gpencil_free_strokes(), BLI_addtail(), BLI_insertlinkbefore(), bGPDframe::framenum, bGPDlayer::frames, LISTBASE_FOREACH, and MEM_freeN().

Referenced by BKE_gpencil_layer_frame_get().

◆ BKE_gpencil_frame_addnew()

bGPDframe * BKE_gpencil_frame_addnew ( struct bGPDlayer * gpl,
int cframe )

Add a new gp-frame to the given layer.

Parameters
gplGrease pencil layer
cframeFrame number
Returns
Pointer to new frame

Definition at line 457 of file gpencil_legacy.cc.

References BLI_addtail(), BLI_assert, BLI_insertlinkbefore(), CLOG_ERROR, ListBase::first, bGPDframe::framenum, bGPDlayer::frames, LOG, MEM_callocN(), MEM_freeN(), bGPDframe::next, and state.

Referenced by BKE_gpencil_frame_addcopy(), and BKE_gpencil_layer_frame_get().

◆ BKE_gpencil_frame_duplicate()

bGPDframe * BKE_gpencil_frame_duplicate ( const bGPDframe * gpf_src,
const bool dup_strokes )

◆ BKE_gpencil_free_data()

void BKE_gpencil_free_data ( struct bGPdata * gpd,
bool free_all )

◆ BKE_gpencil_free_frames()

void BKE_gpencil_free_frames ( struct bGPDlayer * gpl)

◆ BKE_gpencil_free_layer_masks()

void BKE_gpencil_free_layer_masks ( bGPDlayer * gpl)

◆ BKE_gpencil_free_layers()

void BKE_gpencil_free_layers ( struct ListBase * list)

Free all of the gp-layers for a viewport (list should be &gpd->layers or so).

Definition at line 405 of file gpencil_legacy.cc.

References BKE_gpencil_free_frames(), BKE_gpencil_free_layer_masks(), BLI_freelinkN(), ListBase::first, and bGPDlayer::next.

Referenced by BKE_gpencil_free_data(), and ED_gpencil_anim_copybuf_free().

◆ BKE_gpencil_free_legacy_palette_data()

void BKE_gpencil_free_legacy_palette_data ( struct ListBase * list)

Free all of the palettes & colors (list should be &gpd->palettes or so).

Definition at line 428 of file gpencil_legacy.cc.

References BLI_freelistN(), BLI_listbase_clear(), LISTBASE_FOREACH_MUTABLE, and MEM_freeN().

Referenced by BKE_gpencil_free_data().

◆ BKE_gpencil_free_point_weights()

void BKE_gpencil_free_point_weights ( MDeformVert * dvert)

Definition at line 300 of file gpencil_legacy.cc.

References MDeformVert::dw, and MEM_SAFE_FREE.

Referenced by BKE_gpencil_free_stroke_weights().

◆ BKE_gpencil_free_stroke()

◆ BKE_gpencil_free_stroke_editcurve()

void BKE_gpencil_free_stroke_editcurve ( bGPDstroke * gps)

Definition at line 324 of file gpencil_legacy.cc.

References bGPDcurve::curve_points, bGPDstroke::editcurve, and MEM_freeN().

Referenced by BKE_gpencil_free_stroke().

◆ BKE_gpencil_free_stroke_weights()

void BKE_gpencil_free_stroke_weights ( bGPDstroke * gps)

◆ BKE_gpencil_free_strokes()

bool BKE_gpencil_free_strokes ( struct bGPDframe * gpf)

◆ BKE_gpencil_layer_active_get()

bGPDlayer * BKE_gpencil_layer_active_get ( struct bGPdata * gpd)

◆ BKE_gpencil_layer_active_set()

void BKE_gpencil_layer_active_set ( struct bGPdata * gpd,
struct bGPDlayer * active )

◆ BKE_gpencil_layer_addnew()

◆ BKE_gpencil_layer_delete()

void BKE_gpencil_layer_delete ( struct bGPdata * gpd,
struct bGPDlayer * gpl )

Delete grease pencil layer.

Parameters
gpdGrease pencil data-block
gplGrease pencil layer

Definition at line 1127 of file gpencil_legacy.cc.

References BKE_gpencil_free_frames(), BKE_gpencil_free_layer_masks(), BKE_icon_delete(), BLI_freelinkN(), ELEM, bGPDlayer_Runtime::icon_id, bGPdata::layers, and bGPDlayer::runtime.

Referenced by animchannels_delete_exec(), and gpencil_layer_remove_exec().

◆ BKE_gpencil_layer_duplicate()

bGPDlayer * BKE_gpencil_layer_duplicate ( const bGPDlayer * gpl_src,
const bool dup_frames,
const bool dup_strokes )

◆ BKE_gpencil_layer_frame_delete()

bool BKE_gpencil_layer_frame_delete ( struct bGPDlayer * gpl,
struct bGPDframe * gpf )

Delete the given frame from a layer.

Parameters
gplGrease pencil layer
gpfGrease pencil frame
Returns
True if delete was done

Definition at line 1030 of file gpencil_legacy.cc.

References bGPDlayer::actframe, BKE_gpencil_free_strokes(), BLI_freelinkN(), ELEM, bGPDlayer::frames, and bGPDframe::prev.

Referenced by ED_gpencil_anim_copybuf_paste(), ED_gpencil_layer_frames_delete(), gpencil_actframe_delete_exec(), and blender::ed::transform::posttrans_gpd_clean().

◆ BKE_gpencil_layer_frame_find()

bGPDframe * BKE_gpencil_layer_frame_find ( struct bGPDlayer * gpl,
int cframe )

Look up the gp-frame on the requested frame number, but don't add a new one.

Parameters
gplGrease pencil layer
cframeFrame number
Returns
Pointer to frame

Definition at line 853 of file gpencil_legacy.cc.

References bGPDlayer::frames, and LISTBASE_FOREACH_BACKWARD.

Referenced by ED_gpencil_select_frame().

◆ BKE_gpencil_layer_frame_get()

bGPDframe * BKE_gpencil_layer_frame_get ( struct bGPDlayer * gpl,
int cframe,
eGP_GetFrame_Mode addnew )

Get the appropriate gp-frame from a given layer

  • this sets the layer's actframe var (if allowed to)
  • extension beyond range (if first gp-frame is after all frame in interest and cannot add)
Parameters
gplGrease pencil layer
cframeFrame number
addnewAdd option
Returns
Pointer to new frame

Definition at line 867 of file gpencil_legacy.cc.

References abs, bGPDlayer::actframe, BKE_gpencil_frame_addcopy(), BKE_gpencil_frame_addnew(), CLOG_STR_ERROR, ListBase::first, bGPDframe::flag, bGPDlayer::flag, bGPDframe::framenum, bGPDlayer::frames, GP_FRAME_PAINT, GP_GETFRAME_ADD_COPY, GP_LAYER_FRAMELOCK, ListBase::last, LOG, bGPDframe::next, and bGPDframe::prev.

Referenced by annotation_draw_data_layers(), annotation_paint_initstroke(), ED_gpencil_anim_copybuf_paste(), gpencil_actframe_delete_exec(), insert_gpencil_key(), view3d_ruler_from_gpencil(), and view3d_ruler_to_gpencil().

◆ BKE_gpencil_layer_frames_sort()

void BKE_gpencil_layer_frames_sort ( struct bGPDlayer * gpl,
bool * r_has_duplicate_frames )

Sort grease pencil frames.

Parameters
gplGrease pencil layer
r_has_duplicate_framesDuplicated frames flag

Definition at line 1082 of file gpencil_legacy.cc.

References BLI_listbase_sort_r(), bGPDlayer::frames, and gpencil_cb_cmp_frame().

Referenced by ANIM_animdata_update(), and blender::ed::transform::posttrans_gpd_clean().

◆ BKE_gpencil_layer_is_editable()

bool BKE_gpencil_layer_is_editable ( const bGPDlayer * gpl)

Definition at line 837 of file gpencil_legacy.cc.

References bGPDlayer::flag, GP_LAYER_HIDE, and GP_LAYER_LOCKED.

◆ BKE_gpencil_layer_named_get()

bGPDlayer * BKE_gpencil_layer_named_get ( struct bGPdata * gpd,
const char * name )

Get layer by name

Parameters
gpdGrease pencil data-block
nameLayer name
Returns
Pointer to layer

Definition at line 1053 of file gpencil_legacy.cc.

References BLI_findstring(), bGPdata::layers, name, and offsetof.

◆ BKE_gpencil_palette_ensure()

◆ BKE_gpencil_stroke_duplicate()

bGPDstroke * BKE_gpencil_stroke_duplicate ( struct bGPDstroke * gps_src,
bool dup_points,
bool dup_curve )

Make a copy of a given grease-pencil stroke.

Parameters
gps_srcSource grease pencil strokes.
dup_pointsDuplicate points data.
dup_curveDuplicate curve data.
Returns
Pointer to new stroke.

Definition at line 710 of file gpencil_legacy.cc.

References BKE_gpencil_stroke_weights_duplicate(), bGPDstroke::dvert, bGPDstroke::editcurve, MEM_dupallocN(), bGPDstroke::next, bGPDstroke::points, bGPDstroke::prev, and bGPDstroke::triangles.

Referenced by annotation_stroke_newfrombuffer(), BKE_gpencil_frame_duplicate(), BKE_gpencil_stroke_delete_tagged_points(), ED_gpencil_anim_copybuf_paste(), and gpencil_stroke_join_islands().

◆ BKE_gpencil_stroke_weights_duplicate()

void BKE_gpencil_stroke_weights_duplicate ( struct bGPDstroke * gps_src,
struct bGPDstroke * gps_dst )

Make a copy of a given gpencil weights.

Parameters
gps_srcSource grease pencil stroke
gps_dstDestination grease pencil stroke

Definition at line 700 of file gpencil_legacy.cc.

References BKE_defvert_array_copy(), BLI_assert, bGPDstroke::dvert, and bGPDstroke::totpoints.

Referenced by BKE_gpencil_stroke_duplicate().

◆ BKE_gpencil_tag()

void BKE_gpencil_tag ( struct bGPdata * gpd)

Tag data-block for depsgraph update. Wrapper to avoid include Depsgraph tag functions in other modules.

Parameters
gpdGrease pencil data-block.

Definition at line 449 of file gpencil_legacy.cc.

References DEG_id_tag_update(), bGPdata::id, ID_RECALC_GEOMETRY, and ID_RECALC_TRANSFORM.

Referenced by insert_gpencil_key().

◆ gpencil_cb_cmp_frame()

int gpencil_cb_cmp_frame ( void * thunk,
const void * a,
const void * b )
static

Definition at line 1061 of file gpencil_legacy.cc.

References b, bGPDframe::flag, bGPDframe::framenum, and GP_FRAME_SELECT.

Referenced by BKE_gpencil_layer_frames_sort().

◆ greasepencil_blend_read_data()

void greasepencil_blend_read_data ( BlendDataReader * reader,
ID * id )
static

Definition at line 260 of file gpencil_legacy.cc.

References BKE_gpencil_blend_read_data().

◆ greasepencil_blend_write()

◆ greasepencil_copy_data()

◆ greasepencil_foreach_id()

void greasepencil_foreach_id ( ID * id,
LibraryForeachIDData * data )
static

◆ greasepencil_free_data()

void greasepencil_free_data ( ID * id)
static

Definition at line 119 of file gpencil_legacy.cc.

References BKE_gpencil_free_data().

Variable Documentation

◆ IDType_ID_GD_LEGACY

IDTypeInfo IDType_ID_GD_LEGACY
Initial value:
= {
bGPdata::id_type,
sizeof(bGPdata),
"Annotation",
N_("annotations"),
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
}
@ IDTYPE_FLAGS_APPEND_IS_REUSABLE
Definition BKE_idtype.hh:47
#define BLT_I18NCONTEXT_ID_GPENCIL
#define FILTER_ID_GD_LEGACY
Definition DNA_ID.h:1202
#define FILTER_ID_MA
Definition DNA_ID.h:1208
@ INDEX_ID_GD_LEGACY
Definition DNA_ID.h:1290
static void greasepencil_copy_data(Main *, std::optional< Library * >, ID *id_dst, const ID *id_src, const int)
static void greasepencil_blend_write(BlendWriter *writer, ID *id, const void *id_address)
static void greasepencil_free_data(ID *id)
static void greasepencil_foreach_id(ID *id, LibraryForeachIDData *data)
static void greasepencil_blend_read_data(BlendDataReader *reader, ID *id)
#define N_(msgid)

Definition at line 266 of file gpencil_legacy.cc.

◆ LOG

CLG_LogRef LOG = {"geom.gpencil"}
static

Definition at line 62 of file gpencil_legacy.cc.