Blender  V3.3
Classes | Macros | Typedefs | Functions
paint_stroke.c File Reference
#include "MEM_guardedalloc.h"
#include "BLI_listbase.h"
#include "BLI_math.h"
#include "BLI_rand.h"
#include "BLI_utildefines.h"
#include "PIL_time.h"
#include "DNA_brush_types.h"
#include "DNA_curve_types.h"
#include "DNA_object_types.h"
#include "DNA_scene_types.h"
#include "RNA_access.h"
#include "BKE_brush.h"
#include "BKE_colortools.h"
#include "BKE_context.h"
#include "BKE_curve.h"
#include "BKE_image.h"
#include "BKE_paint.h"
#include "WM_api.h"
#include "WM_types.h"
#include "GPU_immediate.h"
#include "GPU_state.h"
#include "ED_screen.h"
#include "ED_view3d.h"
#include "IMB_imbuf_types.h"
#include "paint_intern.h"
#include "sculpt_intern.h"
#include <float.h>
#include <math.h>

Go to the source code of this file.

Classes

struct  PaintSample
 
struct  PaintStroke
 

Macros

#define PAINT_STROKE_MODAL_CANCEL   1
 

Typedefs

typedef struct PaintSample PaintSample
 
typedef struct PaintStroke PaintStroke
 

Functions

static void paint_draw_smooth_cursor (bContext *C, int x, int y, void *customdata)
 
static void paint_draw_line_cursor (bContext *C, int x, int y, void *customdata)
 
static bool paint_tool_require_location (Brush *brush, ePaintMode mode)
 
static bool paint_stroke_use_scene_spacing (Brush *brush, ePaintMode mode)
 
static bool paint_tool_raycast_original (Brush *brush, ePaintMode UNUSED(mode))
 
static bool paint_tool_require_inbetween_mouse_events (Brush *brush, ePaintMode mode)
 
static bool paint_brush_update (bContext *C, Brush *brush, ePaintMode mode, struct PaintStroke *stroke, const float mouse_init[2], float mouse[2], float pressure, float r_location[3], bool *r_location_is_set)
 
static bool paint_stroke_use_dash (Brush *brush)
 
static bool paint_stroke_use_jitter (ePaintMode mode, Brush *brush, bool invert)
 
static void paint_brush_stroke_add_step (bContext *C, wmOperator *op, PaintStroke *stroke, const float mval[2], float pressure)
 
static bool paint_smooth_stroke (PaintStroke *stroke, const PaintSample *sample, ePaintMode mode, float r_mouse[2], float *r_pressure)
 
static float paint_space_stroke_spacing (bContext *C, const Scene *scene, PaintStroke *stroke, float size_pressure, float spacing_pressure)
 
static float paint_stroke_overlapped_curve (Brush *br, float x, float spacing)
 
static float paint_stroke_integrate_overlap (Brush *br, float factor)
 
static float paint_space_stroke_spacing_variable (bContext *C, const Scene *scene, PaintStroke *stroke, float pressure, float dpressure, float length)
 
static int paint_space_stroke (bContext *C, wmOperator *op, PaintStroke *stroke, const float final_mouse[2], float final_pressure)
 
PaintStrokepaint_stroke_new (bContext *C, wmOperator *op, StrokeGetLocation get_location, StrokeTestStart test_start, StrokeUpdateStep update_step, StrokeRedraw redraw, StrokeDone done, int event_type)
 
void paint_stroke_free (bContext *C, wmOperator *UNUSED(op), PaintStroke *stroke)
 
static void stroke_done (bContext *C, wmOperator *op, PaintStroke *stroke)
 
static bool curves_sculpt_brush_uses_spacing (const eBrushCurvesSculptTool tool)
 
bool paint_space_stroke_enabled (Brush *br, ePaintMode mode)
 
static bool sculpt_is_grab_tool (Brush *br)
 
bool paint_supports_dynamic_size (Brush *br, ePaintMode mode)
 
bool paint_supports_smooth_stroke (Brush *br, ePaintMode mode)
 
bool paint_supports_texture (ePaintMode mode)
 
bool paint_supports_dynamic_tex_coords (Brush *br, ePaintMode mode)
 
struct wmKeyMappaint_stroke_modal_keymap (struct wmKeyConfig *keyconf)
 
static void paint_stroke_add_sample (const Paint *paint, PaintStroke *stroke, float x, float y, float pressure)
 
static void paint_stroke_sample_average (const PaintStroke *stroke, PaintSample *average)
 
static void paint_line_strokes_spacing (bContext *C, wmOperator *op, PaintStroke *stroke, float spacing, float *length_residue, const float old_pos[2], const float new_pos[2])
 
static void paint_stroke_line_end (bContext *C, wmOperator *op, PaintStroke *stroke, const float mouse[2])
 
static bool paint_stroke_curve_end (bContext *C, wmOperator *op, PaintStroke *stroke)
 
static void paint_stroke_line_constrain (PaintStroke *stroke, float mouse[2])
 
int paint_stroke_modal (bContext *C, wmOperator *op, const wmEvent *event, PaintStroke **stroke_p)
 
int paint_stroke_exec (bContext *C, wmOperator *op, PaintStroke *stroke)
 
void paint_stroke_cancel (bContext *C, wmOperator *op, PaintStroke *stroke)
 
ViewContextpaint_stroke_view_context (PaintStroke *stroke)
 
voidpaint_stroke_mode_data (struct PaintStroke *stroke)
 
bool paint_stroke_flipped (struct PaintStroke *stroke)
 
bool paint_stroke_inverted (struct PaintStroke *stroke)
 
float paint_stroke_distance_get (struct PaintStroke *stroke)
 
void paint_stroke_set_mode_data (PaintStroke *stroke, void *mode_data)
 
bool PAINT_brush_tool_poll (bContext *C)
 

Macro Definition Documentation

◆ PAINT_STROKE_MODAL_CANCEL

#define PAINT_STROKE_MODAL_CANCEL   1

Definition at line 1129 of file paint_stroke.c.

Typedef Documentation

◆ PaintSample

typedef struct PaintSample PaintSample

◆ PaintStroke

typedef struct PaintStroke PaintStroke

Function Documentation

◆ curves_sculpt_brush_uses_spacing()

static bool curves_sculpt_brush_uses_spacing ( const eBrushCurvesSculptTool  tool)
static

Definition at line 1016 of file paint_stroke.c.

References CURVES_SCULPT_TOOL_ADD, CURVES_SCULPT_TOOL_DENSITY, and ELEM.

Referenced by paint_space_stroke_enabled().

◆ paint_brush_stroke_add_step()

static void paint_brush_stroke_add_step ( bContext C,
wmOperator op,
PaintStroke stroke,
const float  mval[2],
float  pressure 
)
static

◆ PAINT_brush_tool_poll()

bool PAINT_brush_tool_poll ( bContext C)

◆ paint_brush_update()

static bool paint_brush_update ( bContext C,
Brush brush,
ePaintMode  mode,
struct PaintStroke stroke,
const float  mouse_init[2],
float  mouse[2],
float  pressure,
float  r_location[3],
bool r_location_is_set 
)
static

◆ paint_draw_line_cursor()

static void paint_draw_line_cursor ( bContext C,
int  x,
int  y,
void customdata 
)
static

◆ paint_draw_smooth_cursor()

static void paint_draw_smooth_cursor ( bContext C,
int  x,
int  y,
void customdata 
)
static

◆ paint_line_strokes_spacing()

static void paint_line_strokes_spacing ( bContext C,
wmOperator op,
PaintStroke stroke,
float  spacing,
float length_residue,
const float  old_pos[2],
const float  new_pos[2] 
)
static

◆ paint_smooth_stroke()

static bool paint_smooth_stroke ( PaintStroke stroke,
const PaintSample sample,
ePaintMode  mode,
float  r_mouse[2],
float r_pressure 
)
static

◆ paint_space_stroke()

static int paint_space_stroke ( bContext C,
wmOperator op,
PaintStroke stroke,
const float  final_mouse[2],
float  final_pressure 
)
static

◆ paint_space_stroke_enabled()

bool paint_space_stroke_enabled ( struct Brush br,
enum ePaintMode  mode 
)

◆ paint_space_stroke_spacing()

static float paint_space_stroke_spacing ( bContext C,
const Scene scene,
PaintStroke stroke,
float  size_pressure,
float  spacing_pressure 
)
static

◆ paint_space_stroke_spacing_variable()

static float paint_space_stroke_spacing_variable ( bContext C,
const Scene scene,
PaintStroke stroke,
float  pressure,
float  dpressure,
float  length 
)
static

◆ paint_stroke_add_sample()

static void paint_stroke_add_sample ( const Paint paint,
PaintStroke stroke,
float  x,
float  y,
float  pressure 
)
static

◆ paint_stroke_cancel()

void paint_stroke_cancel ( bContext C,
wmOperator op,
PaintStroke stroke 
)

◆ paint_stroke_curve_end()

static bool paint_stroke_curve_end ( bContext C,
wmOperator op,
PaintStroke stroke 
)
static

◆ paint_stroke_distance_get()

float paint_stroke_distance_get ( struct PaintStroke stroke)

◆ paint_stroke_exec()

int paint_stroke_exec ( bContext C,
wmOperator op,
PaintStroke stroke 
)

◆ paint_stroke_flipped()

bool paint_stroke_flipped ( struct PaintStroke stroke)

Definition at line 1656 of file paint_stroke.c.

References PaintStroke::pen_flip.

◆ paint_stroke_free()

void paint_stroke_free ( bContext C,
wmOperator UNUSEDop,
PaintStroke stroke 
)

◆ paint_stroke_integrate_overlap()

static float paint_stroke_integrate_overlap ( Brush br,
float  factor 
)
static

◆ paint_stroke_inverted()

bool paint_stroke_inverted ( struct PaintStroke stroke)

◆ paint_stroke_line_constrain()

static void paint_stroke_line_constrain ( PaintStroke stroke,
float  mouse[2] 
)
static

◆ paint_stroke_line_end()

static void paint_stroke_line_end ( bContext C,
wmOperator op,
PaintStroke stroke,
const float  mouse[2] 
)
static

◆ paint_stroke_modal()

int paint_stroke_modal ( bContext C,
wmOperator op,
const wmEvent event,
PaintStroke **  stroke_p 
)

Definition at line 1421 of file paint_stroke.c.

References BKE_paint_brush(), BKE_paint_get_active_from_context(), BKE_paintmode_get_active_from_context(), BLI_assert, PaintStroke::brush, BRUSH_AIRBRUSH, BRUSH_ANCHORED, MTex::brush_angle_mode, BRUSH_DRAG_DOT, BRUSH_LINE, BRUSH_SMOOTH_STROKE, C, wmOperatorType::cancel, PaintStroke::constrain_line, copy_v2_fl2(), copy_v2_v2(), CTX_wm_manager(), CTX_wm_region(), CTX_wm_window(), wmEvent::customdata, ELEM, PaintStroke::event_type, EVT_MODAL_MAP, EVT_RETKEY, EVT_SPACEKEY, Brush::flag, Paint::flags, INBETWEEN_MOUSEMOVE, ISMOUSE_MOTION, KM_ALT, KM_RELEASE, PaintStroke::last_mouse_position, PaintStroke::last_pressure, UnifiedPaintSettings::last_rake, PaintStroke::last_tablet_event_pressure, PaintStroke::last_world_space_position, len_v2(), Brush::mask_mtex, wmEvent::modifier, PaintSample::mouse, Brush::mtex, MTEX_ANGLE_RAKE, mul_m4_v3(), wmEvent::mval, NDOF_MOTION, NULL, ViewContext::obact, Object::obmat, OPERATOR_CANCELLED, OPERATOR_FINISHED, OPERATOR_PASS_THROUGH, OPERATOR_RUNNING_MODAL, PaintStroke::original, UnifiedPaintSettings::overlap_factor, paint_brush_stroke_add_step(), PAINT_brush_tool_poll(), paint_calculate_rake_rotation(), paint_draw_line_cursor(), paint_draw_smooth_cursor(), PAINT_SHOW_BRUSH, paint_smooth_stroke(), paint_space_stroke(), paint_space_stroke_enabled(), paint_stroke_add_sample(), paint_stroke_cancel(), paint_stroke_curve_end(), paint_stroke_integrate_overlap(), paint_stroke_line_constrain(), paint_stroke_line_end(), PAINT_STROKE_MODAL_CANCEL, paint_stroke_sample_average(), paint_stroke_use_scene_spacing(), paint_supports_smooth_stroke(), paint_tool_require_inbetween_mouse_events(), PaintStroke::pen_flip, PaintSample::pressure, Brush::rate, PaintStroke::redraw, RGN_TYPE_ANY, SCULPT_stroke_get_location(), SPACE_TYPE_ANY, PaintStroke::stroke_cursor, PaintStroke::stroke_distance, stroke_done(), PaintStroke::stroke_init, PaintStroke::stroke_over_mesh, PaintStroke::stroke_started, sub_v2_v2v2(), PaintStroke::test_start, PaintStroke::timer, TIMER, wmOperator::type, wmEvent::type, PaintStroke::ups, wmEvent::val, PaintStroke::vc, WM_event_add_timer(), WM_event_is_tablet(), WM_event_tablet_data(), WM_paint_cursor_activate(), WM_paint_cursor_tag_redraw(), PaintStroke::x_tilt, and PaintStroke::y_tilt.

◆ paint_stroke_modal_keymap()

struct wmKeyMap* paint_stroke_modal_keymap ( struct wmKeyConfig keyconf)

Called in paint_ops.c, on each regeneration of key-maps.

Definition at line 1131 of file paint_stroke.c.

References wmKeyMap::modal_items, EnumPropertyItem::name, PAINT_STROKE_MODAL_CANCEL, WM_modalkeymap_ensure(), and WM_modalkeymap_find().

Referenced by ED_keymap_paint().

◆ paint_stroke_mode_data()

void* paint_stroke_mode_data ( struct PaintStroke stroke)

◆ paint_stroke_new()

PaintStroke* paint_stroke_new ( bContext C,
wmOperator op,
StrokeGetLocation  get_location,
StrokeTestStart  test_start,
StrokeUpdateStep  update_step,
StrokeRedraw  redraw,
StrokeDone  done,
int  event_type 
)

Definition at line 874 of file paint_stroke.c.

References UnifiedPaintSettings::average_stroke_accum, UnifiedPaintSettings::average_stroke_counter, BKE_brush_size_get(), BKE_curvemapping_init(), BKE_image_pool_acquire_ibuf(), BKE_image_pool_release_ibuf(), BKE_paint_brush(), BKE_paint_get_active_from_context(), BKE_paint_set_overlay_override(), BKE_paintmode_get_active_from_context(), PaintStroke::brush, BRUSH_CURVE, BRUSH_STROKE_INVERT, BRUSH_STROKE_NORMAL, C, Paint::cavity_curve, UnifiedPaintSettings::colorspace, CTX_data_ensure_evaluated_depsgraph(), CTX_data_scene(), CTX_data_tool_settings(), CTX_wm_region_view3d(), Brush::curve, depsgraph, UnifiedPaintSettings::do_linear_conversion, PaintStroke::done, ED_view3d_viewcontext_init(), PaintStroke::event_type, Brush::flag, Paint::flags, get_imapaint_zoom(), PaintStroke::get_location, Tex::ima, Tex::iuser, max_ff(), MEM_callocN, Brush::mtex, mul_v3_fl(), NULL, PaintStroke::original, UnifiedPaintSettings::overlap_factor, Brush::overlay_flags, paint_tool_raycast_original(), PAINT_USE_CAVITY_MASK, wmOperator::ptr, ImBuf::rect_colorspace, ImBuf::rect_float, PaintStroke::redraw, RegionView3D::rflag, RNA_enum_get(), RNA_enum_set(), RV3D_PAINTING, UnifiedPaintSettings::start_pixel_radius, UnifiedPaintSettings::stroke_active, PaintStroke::stroke_mode, PaintStroke::test_start, MTex::tex, TEX_IMAGE, Tex::type, ToolSettings::unified_paint_settings, PaintStroke::update_step, PaintStroke::ups, PaintStroke::vc, and PaintStroke::zoom_2d.

Referenced by blender::ed::sculpt_paint::image::ops::paint::paint_exec(), blender::ed::sculpt_paint::image::ops::paint::paint_invoke(), sculpt_brush_stroke_exec(), sculpt_brush_stroke_invoke(), blender::ed::sculpt_paint::sculpt_curves_stroke_invoke(), vpaint_exec(), vpaint_invoke(), wpaint_exec(), and wpaint_invoke().

◆ paint_stroke_overlapped_curve()

static float paint_stroke_overlapped_curve ( Brush br,
float  x,
float  spacing 
)
static

Definition at line 708 of file paint_stroke.c.

References BKE_brush_curve_strength(), fabsf, sum(), and x.

Referenced by paint_stroke_integrate_overlap().

◆ paint_stroke_sample_average()

static void paint_stroke_sample_average ( const PaintStroke stroke,
PaintSample average 
)
static

◆ paint_stroke_set_mode_data()

void paint_stroke_set_mode_data ( PaintStroke stroke,
void mode_data 
)

◆ paint_stroke_use_dash()

static bool paint_stroke_use_dash ( Brush brush)
static

Definition at line 481 of file paint_stroke.c.

References BRUSH_CURVE, BRUSH_LINE, BRUSH_SPACE, and Brush::flag.

Referenced by paint_brush_stroke_add_step().

◆ paint_stroke_use_jitter()

static bool paint_stroke_use_jitter ( ePaintMode  mode,
Brush brush,
bool  invert 
)
static

◆ paint_stroke_use_scene_spacing()

static bool paint_stroke_use_scene_spacing ( Brush brush,
ePaintMode  mode 
)
static

◆ paint_stroke_view_context()

ViewContext* paint_stroke_view_context ( PaintStroke stroke)

Definition at line 1646 of file paint_stroke.c.

References PaintStroke::vc.

Referenced by sculpt_update_cache_invariants(), and vwpaint_update_cache_invariants().

◆ paint_supports_dynamic_size()

bool paint_supports_dynamic_size ( struct Brush br,
enum ePaintMode  mode 
)

◆ paint_supports_dynamic_tex_coords()

bool paint_supports_dynamic_tex_coords ( struct Brush br,
enum ePaintMode  mode 
)

Return true if the brush size can change during paint (normally used for pressure).

Definition at line 1111 of file paint_stroke.c.

References BRUSH_ANCHORED, Brush::flag, PAINT_MODE_SCULPT, and sculpt_is_grab_tool().

Referenced by paint_brush_update().

◆ paint_supports_smooth_stroke()

bool paint_supports_smooth_stroke ( Brush br,
ePaintMode  mode 
)

◆ paint_supports_texture()

bool paint_supports_texture ( ePaintMode  mode)

◆ paint_tool_raycast_original()

static bool paint_tool_raycast_original ( Brush brush,
ePaintMode   UNUSEDmode 
)
static

Definition at line 250 of file paint_stroke.c.

References BRUSH_ANCHORED, and Brush::flag.

Referenced by paint_stroke_new().

◆ paint_tool_require_inbetween_mouse_events()

static bool paint_tool_require_inbetween_mouse_events ( Brush brush,
ePaintMode  mode 
)
static

◆ paint_tool_require_location()

static bool paint_tool_require_location ( Brush brush,
ePaintMode  mode 
)
static

◆ sculpt_is_grab_tool()

static bool sculpt_is_grab_tool ( Brush br)
static

◆ stroke_done()

static void stroke_done ( bContext C,
wmOperator op,
PaintStroke stroke 
)
static