Blender V4.3
gpencil_utils.cc File Reference
#include <algorithm>
#include <cmath>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include "MEM_guardedalloc.h"
#include "BLI_blenlib.h"
#include "BLI_ghash.h"
#include "BLI_hash.h"
#include "BLI_lasso_2d.hh"
#include "BLI_math_color.h"
#include "BLI_math_matrix.h"
#include "BLI_math_vector.hh"
#include "BLI_time.h"
#include "BLI_utildefines.h"
#include "BLT_translation.hh"
#include "DNA_brush_types.h"
#include "DNA_gpencil_legacy_types.h"
#include "DNA_material_types.h"
#include "DNA_meshdata_types.h"
#include "DNA_object_types.h"
#include "DNA_scene_types.h"
#include "DNA_screen_types.h"
#include "DNA_space_types.h"
#include "DNA_view3d_types.h"
#include "BKE_action.hh"
#include "BKE_brush.hh"
#include "BKE_collection.hh"
#include "BKE_colortools.hh"
#include "BKE_context.hh"
#include "BKE_deform.hh"
#include "BKE_gpencil_curve_legacy.h"
#include "BKE_gpencil_geom_legacy.h"
#include "BKE_gpencil_legacy.h"
#include "BKE_main.hh"
#include "BKE_material.h"
#include "BKE_object.hh"
#include "BKE_paint.hh"
#include "BKE_preview_image.hh"
#include "BKE_tracking.h"
#include "WM_api.hh"
#include "WM_toolsystem.hh"
#include "WM_types.hh"
#include "RNA_access.hh"
#include "RNA_define.hh"
#include "RNA_enum_types.hh"
#include "RNA_prototypes.hh"
#include "UI_resources.hh"
#include "UI_view2d.hh"
#include "ED_clip.hh"
#include "ED_gpencil_legacy.hh"
#include "ED_object.hh"
#include "ED_select_utils.hh"
#include "ED_transform_snap_object_context.hh"
#include "ED_view3d.hh"
#include "GPU_immediate.hh"
#include "GPU_immediate_util.hh"
#include "GPU_state.hh"
#include "DEG_depsgraph.hh"
#include "DEG_depsgraph_query.hh"
#include "gpencil_intern.hh"

Go to the source code of this file.

Functions

bGPdata ** ED_gpencil_data_get_pointers_direct (ScrArea *area, Object *ob, PointerRNA *r_ptr)
 
bGPdata ** ED_annotation_data_get_pointers_direct (ID *screen_id, ScrArea *area, Scene *scene, PointerRNA *r_ptr)
 
bGPdata ** ED_gpencil_data_get_pointers (const bContext *C, PointerRNA *r_ptr)
 
bGPdata ** ED_annotation_data_get_pointers (const bContext *C, PointerRNA *r_ptr)
 
bGPdataED_annotation_data_get_active_direct (ID *screen_id, ScrArea *area, Scene *scene)
 
bGPdataED_gpencil_data_get_active (const bContext *C)
 
bGPdataED_annotation_data_get_active (const bContext *C)
 
bool ED_gpencil_data_owner_is_annotation (PointerRNA *owner_ptr)
 
bool gpencil_stroke_inside_circle (const float mval[2], int rad, int x0, int y0, int x1, int y1)
 
bool ED_gpencil_stroke_can_use_direct (const ScrArea *area, const bGPDstroke *gps)
 
bool ED_gpencil_stroke_can_use (const bContext *C, const bGPDstroke *gps)
 
bool ED_gpencil_stroke_material_editable (Object *ob, const bGPDlayer *gpl, const bGPDstroke *gps)
 
void gpencil_point_to_xy (const GP_SpaceConversion *gsc, const bGPDstroke *gps, const bGPDspoint *pt, int *r_x, int *r_y)
 
void ED_gpencil_drawing_reference_get (const Scene *scene, const Object *ob, char align_flag, float r_vec[3])
 
static void gpencil_stroke_convertcoords (ARegion *region, const tGPspoint *point2D, const float origin[3], float out[3])
 
void ED_gpencil_tpoint_to_point (ARegion *region, float origin[3], const tGPspoint *tpt, bGPDspoint *pt)
 
tGPspointED_gpencil_sbuffer_ensure (tGPspoint *buffer_array, int *buffer_size, int *buffer_used, const bool clear)
 

Function Documentation

◆ ED_annotation_data_get_active()

bGPdata * ED_annotation_data_get_active ( const bContext * C)

Get the active Grease Pencil data-block

Note
This is the original (#G.main) copy of the data-block, stored in files. Do not use for reading evaluated copies of GP Objects data.

Definition at line 247 of file gpencil_utils.cc.

References ED_annotation_data_get_pointers().

Referenced by annotation_actframe_delete_poll(), ED_annotation_draw_2dimage(), ED_annotation_draw_view2d(), gpencil_actframe_delete_exec(), gpencil_active_layer_annotation_poll(), gpencil_layer_move_exec(), and gpencil_layer_remove_exec().

◆ ED_annotation_data_get_active_direct()

bGPdata * ED_annotation_data_get_active_direct ( ID * screen_id,
ScrArea * area,
Scene * scene )

Get the active Grease Pencil data-block, when context is not available.

Definition at line 232 of file gpencil_utils.cc.

References ED_annotation_data_get_pointers_direct().

Referenced by screen_ctx_active_annotation_layer(), and screen_ctx_annotation_data().

◆ ED_annotation_data_get_pointers()

◆ ED_annotation_data_get_pointers_direct()

bGPdata ** ED_annotation_data_get_pointers_direct ( ID * screen_id,
ScrArea * area,
Scene * scene,
PointerRNA * r_ptr )

◆ ED_gpencil_data_get_active()

bGPdata * ED_gpencil_data_get_active ( const bContext * C)

◆ ED_gpencil_data_get_pointers()

bGPdata ** ED_gpencil_data_get_pointers ( const bContext * C,
PointerRNA * r_ptr )

Get pointer to active Grease Pencil data-block, and an RNA-pointer to trace back to whatever owns it.

Definition at line 214 of file gpencil_utils.cc.

References CTX_data_active_object(), CTX_wm_area(), and ED_gpencil_data_get_pointers_direct().

Referenced by ED_undo_gpencil_step().

◆ ED_gpencil_data_get_pointers_direct()

bGPdata ** ED_gpencil_data_get_pointers_direct ( ScrArea * area,
Object * ob,
PointerRNA * r_ptr )

Context independent (i.e. each required part is passed in instead).

Get pointer to active Grease Pencil data-block, and an RNA-pointer to trace back to whatever owns it, when context info is not available.

Definition at line 87 of file gpencil_utils.cc.

References Object::data, Object::id, OB_GPENCIL_LEGACY, RNA_id_pointer_create(), SPACE_INFO, SPACE_PROPERTIES, SPACE_TOPBAR, SPACE_VIEW3D, and Object::type.

Referenced by ED_gpencil_data_get_pointers().

◆ ED_gpencil_data_owner_is_annotation()

bool ED_gpencil_data_owner_is_annotation ( PointerRNA * owner_ptr)

Utility to check whether the r_ptr output of ED_gpencil_data_get_pointers() is for annotation usage.

Definition at line 255 of file gpencil_utils.cc.

References PointerRNA::type.

Referenced by annotation_session_initdata().

◆ ED_gpencil_drawing_reference_get()

void ED_gpencil_drawing_reference_get ( const Scene * scene,
const Object * ob,
char align_flag,
float r_vec[3] )

Get drawing reference point for conversion or projection of the stroke

Parameters
r_vecReference point found

Definition at line 374 of file gpencil_utils.cc.

References add_v3_v3(), BKE_gpencil_layer_active_get(), copy_v3_v3(), Object::data, GP_PROJECT_CURSOR, GP_PROJECT_VIEWSPACE, bGPDlayer::layer_mat, OB_GPENCIL_LEGACY, and Object::type.

◆ ED_gpencil_sbuffer_ensure()

tGPspoint * ED_gpencil_sbuffer_ensure ( tGPspoint * buffer_array,
int * buffer_size,
int * buffer_used,
bool clear )

Ensure the tGPspoint buffer (while drawing stroke) size is enough to save all points of the stroke.

Definition at line 453 of file gpencil_utils.cc.

References clear(), GP_STROKE_BUFFER_CHUNK, MEM_callocN, and MEM_recallocN.

Referenced by annotation_session_validatebuffer(), and annotation_stroke_addpoint().

◆ ED_gpencil_stroke_can_use()

bool ED_gpencil_stroke_can_use ( const bContext * C,
const bGPDstroke * gps )

Check whether given stroke can be edited in the current context

Definition at line 306 of file gpencil_utils.cc.

References CTX_wm_area(), and ED_gpencil_stroke_can_use_direct().

Referenced by createTransGPencil_curves(), and createTransGPencil_strokes().

◆ ED_gpencil_stroke_can_use_direct()

bool ED_gpencil_stroke_can_use_direct ( const ScrArea * area,
const bGPDstroke * gps )

Check whether given stroke can be edited given the supplied context. TODO: do we need additional flags for screen-space vs data-space?.

Definition at line 282 of file gpencil_utils.cc.

References ELEM, bGPDstroke::flag, GP_STROKE_2DIMAGE, GP_STROKE_2DSPACE, GP_STROKE_3DSPACE, SPACE_IMAGE, SPACE_PROPERTIES, and SPACE_VIEW3D.

Referenced by annotation_stroke_doeraser(), and ED_gpencil_stroke_can_use().

◆ ED_gpencil_stroke_material_editable()

bool ED_gpencil_stroke_material_editable ( Object * ob,
const bGPDlayer * gpl,
const bGPDstroke * gps )

◆ ED_gpencil_tpoint_to_point()

◆ gpencil_point_to_xy()

void gpencil_point_to_xy ( const GP_SpaceConversion * gsc,
const bGPDstroke * gps,
const bGPDspoint * pt,
int * r_x,
int * r_y )

Convert a Grease Pencil coordinate (i.e. can be 2D or 3D) to screen-space (2D)

Parameters
[out]r_xThe screen-space x-coordinate of the point
[out]r_yThe screen-space y-coordinate of the point
Warning
This assumes that the caller has already checked whether the stroke in question can be drawn.

Definition at line 332 of file gpencil_utils.cc.

References GP_SpaceConversion::area, BLI_assert, BLI_rctf_size_x(), BLI_rctf_size_y(), ED_view3d_project_int_global(), bGPDstroke::flag, GP_STROKE_2DSPACE, GP_STROKE_3DSPACE, int, GP_SpaceConversion::mat, mul_m4_v3(), GP_SpaceConversion::region, SPACE_VIEW3D, ScrArea::spacetype, GP_SpaceConversion::subrect, UI_view2d_view_to_region_clip(), GP_SpaceConversion::v2d, V2D_IS_CLIPPED, V3D_PROJ_RET_OK, V3D_PROJ_TEST_NOP, bGPDspoint::x, rctf::xmin, bGPDspoint::y, and rctf::ymin.

Referenced by annotation_stroke_eraser_dostroke().

◆ gpencil_stroke_convertcoords()

static void gpencil_stroke_convertcoords ( ARegion * region,
const tGPspoint * point2D,
const float origin[3],
float out[3] )
static

◆ gpencil_stroke_inside_circle()

bool gpencil_stroke_inside_circle ( const float mval[2],
int rad,
int x0,
int y0,
int x1,
int y1 )

Check whether a given stroke segment is inside a circular brush

Parameters
mvalThe current screen-space coordinates (midpoint) of the brush
radThe radius of the brush
x0,y0The screen-space x and y coordinates of the start of the stroke segment
x1,y1The screen-space x and y coordinates of the end of the stroke segment

Definition at line 265 of file gpencil_utils.cc.

References edge_inside_circle(), and float.

Referenced by annotation_stroke_eraser_dostroke().