Blender  V2.93
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_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, const float mouse_in[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, 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 *op)
 
static void stroke_done (bContext *C, wmOperator *op)
 
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)
 
int paint_stroke_exec (bContext *C, wmOperator *op)
 
void paint_stroke_cancel (bContext *C, wmOperator *op)
 
ViewContextpaint_stroke_view_context (PaintStroke *stroke)
 
void * paint_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_poll (bContext *C)
 

Macro Definition Documentation

◆ PAINT_STROKE_MODAL_CANCEL

#define PAINT_STROKE_MODAL_CANCEL   1

Definition at line 1116 of file paint_stroke.c.

Typedef Documentation

◆ PaintSample

typedef struct PaintSample PaintSample

◆ PaintStroke

typedef struct PaintStroke PaintStroke

Function Documentation

◆ paint_brush_stroke_add_step()

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

◆ 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

Definition at line 292 of file paint_stroke.c.

References UnifiedPaintSettings::anchored_initial_mouse, UnifiedPaintSettings::anchored_size, atan2f, BKE_brush_randomize_texture_coords(), BKE_brush_size_get(), BKE_brush_use_size_pressure(), BKE_image_pool_acquire_ibuf(), BKE_image_pool_release_ibuf(), BLI_rng_get_float(), BLI_rng_new(), BRUSH_ANCHORED, MTex::brush_angle_mode, BRUSH_CURVE, BRUSH_EDGE_TO_EDGE, PaintStroke::brush_init, MTex::brush_map_mode, UnifiedPaintSettings::brush_rotation, UnifiedPaintSettings::brush_rotation_sec, C, PaintStroke::cached_size_pressure, UnifiedPaintSettings::colorspace, copy_v2_v2(), CTX_data_scene(), UnifiedPaintSettings::do_linear_conversion, UnifiedPaintSettings::draw_anchored, ELEM, Brush::flag, float(), PaintStroke::get_location, Tex::ima, PaintStroke::initial_mouse, UnifiedPaintSettings::initial_pixel_radius, Tex::iuser, UnifiedPaintSettings::last_rake, M_PI, Brush::mask_mtex, UnifiedPaintSettings::mask_tex_mouse, Brush::mtex, MTEX_ANGLE_RANDOM, MTEX_MAP_MODE_AREA, MTEX_MAP_MODE_RANDOM, MTEX_MAP_MODE_VIEW, NULL, paint_calculate_rake_rotation(), paint_supports_dynamic_size(), paint_supports_dynamic_tex_coords(), paint_tool_require_location(), PIL_check_seconds_timer_i(), UnifiedPaintSettings::pixel_radius, POINTER_AS_INT, PaintStroke::rake_started, MTex::random_angle, ImBuf::rect_colorspace, ImBuf::rect_float, PaintStroke::rng, scene, UnifiedPaintSettings::size_pressure_value, sqrtf, UnifiedPaintSettings::stroke_active, PaintStroke::stroke_distance, MTex::tex, TEX_IMAGE, UnifiedPaintSettings::tex_mouse, Tex::type, UINT_MAX, PaintStroke::ups, zero_v3(), and PaintStroke::zoom_2d.

Referenced by paint_brush_stroke_add_step().

◆ 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_poll()

bool paint_poll ( bContext C)

◆ 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,
const float  final_mouse[2],
float  final_pressure 
)
static

◆ paint_space_stroke_enabled()

bool paint_space_stroke_enabled ( Brush br,
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 
)

◆ 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)

Definition at line 1652 of file paint_stroke.c.

References PaintStroke::stroke_distance.

Referenced by paint_stroke_update_step().

◆ paint_stroke_exec()

int paint_stroke_exec ( bContext C,
wmOperator op 
)

◆ paint_stroke_flipped()

bool paint_stroke_flipped ( struct PaintStroke stroke)

Definition at line 1642 of file paint_stroke.c.

References PaintStroke::pen_flip.

Referenced by paint_stroke_done().

◆ paint_stroke_free()

void paint_stroke_free ( bContext C,
wmOperator op 
)

◆ 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)

Definition at line 1647 of file paint_stroke.c.

References BRUSH_STROKE_INVERT, and PaintStroke::stroke_mode.

Referenced by paint_stroke_done().

◆ 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 
)

Definition at line 1407 of file paint_stroke.c.

References wmEvent::alt, 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(), wmOperator::customdata, wmEvent::customdata, ELEM, PaintStroke::event_type, EVT_MODAL_MAP, EVT_RETKEY, EVT_SPACEKEY, Brush::flag, Paint::flags, INBETWEEN_MOUSEMOVE, 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, PaintSample::mouse, MOUSEMOVE, 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, UnifiedPaintSettings::overlap_factor, paint_brush_stroke_add_step(), paint_calculate_rake_rotation(), paint_draw_line_cursor(), paint_draw_smooth_cursor(), paint_poll(), 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)

◆ 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 
)

◆ paint_stroke_overlapped_curve()

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

Definition at line 725 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 503 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 1632 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 ( Brush br,
ePaintMode  mode 
)

◆ paint_supports_dynamic_tex_coords()

bool paint_supports_dynamic_tex_coords ( Brush br,
ePaintMode  mode 
)

Definition at line 1098 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_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 
)
static