Blender V4.3
paint_curve_undo.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
9#include <cstring>
10
11#include "MEM_guardedalloc.h"
12
13#include "DNA_brush_types.h"
14
15#include "BKE_paint.hh"
16#include "BKE_undo_system.hh"
17
18#include "ED_paint.hh"
19#include "ED_undo.hh"
20
21#include "WM_api.hh"
22
23#include "paint_intern.hh"
24
25#ifndef NDEBUG
26# include "BLI_array_utils.h" /* #BLI_array_is_zeroed */
27#endif
28
29/* -------------------------------------------------------------------- */
33struct UndoCurve {
34 PaintCurvePoint *points; /* points of curve */
37};
38
40{
42 uc->points = static_cast<PaintCurvePoint *>(MEM_dupallocN(pc->points));
43 uc->tot_points = pc->tot_points;
44 uc->add_index = pc->add_index;
45}
46
47static void undocurve_to_paintcurve(const UndoCurve *uc, PaintCurve *pc)
48{
50 pc->points = static_cast<PaintCurvePoint *>(MEM_dupallocN(uc->points));
51 pc->tot_points = uc->tot_points;
52 pc->add_index = uc->add_index;
53}
54
56{
58}
59
62/* -------------------------------------------------------------------- */
68
69 UndoRefID_PaintCurve pc_ref;
70
72};
73
75{
76 if (C == nullptr || !paint_curve_poll(C)) {
77 return false;
78 }
80 Brush *brush = BKE_paint_brush(paint);
81 return (brush && brush->paint_curve);
82}
83
85{
86 /* XXX, use to set the undo type only. */
87 UNUSED_VARS(C, us_p);
88}
89
90static bool paintcurve_undosys_step_encode(bContext *C, Main * /*bmain*/, UndoStep *us_p)
91{
92 /* FIXME Double check this, it should not be needed here at all? undo system is supposed to
93 * ensure that. */
94 if (!paint_curve_poll(C)) {
95 return false;
96 }
97
99 Brush *brush = BKE_paint_brush(paint);
100 PaintCurve *pc = paint ? (brush ? brush->paint_curve : nullptr) : nullptr;
101 if (pc == nullptr) {
102 return false;
103 }
104
106 BLI_assert(us->step.data_size == 0);
107
108 us->pc_ref.ptr = pc;
110
111 return true;
112}
113
115 Main * /*bmain*/,
116 UndoStep *us_p,
117 const eUndoStepDir /*dir*/,
118 bool /*is_final*/)
119{
121 undocurve_to_paintcurve(&us->data, us->pc_ref.ptr);
122}
123
129
131 UndoTypeForEachIDRefFn foreach_ID_ref_fn,
132 void *user_data)
133{
135 foreach_ID_ref_fn(user_data, ((UndoRefID *)&us->pc_ref));
136}
137
153
156/* -------------------------------------------------------------------- */
160void ED_paintcurve_undo_push_begin(const char *name)
161{
162 UndoStack *ustack = ED_undo_stack_get();
163 bContext *C = nullptr; /* special case, we never read from this. */
165}
166
174
Paint * BKE_paint_get_active_from_context(const bContext *C)
Definition paint.cc:477
Brush * BKE_paint_brush(Paint *paint)
Definition paint.cc:649
void(*)(void *user_data, UndoRefID *id_ref) UndoTypeForEachIDRefFn
eUndoPushReturn BKE_undosys_step_push(UndoStack *ustack, bContext *C, const char *name)
eUndoStepDir
UndoStep * BKE_undosys_step_push_init_with_type(UndoStack *ustack, bContext *C, const char *name, const UndoType *ut)
#define BKE_undosys_stack_limit_steps_and_memory_defaults(ustack)
const UndoType * BKE_UNDOSYS_TYPE_PAINTCURVE
Generic array manipulation API.
#define BLI_array_is_zeroed(arr, arr_len)
#define BLI_assert(a)
Definition BLI_assert.h:50
#define UNUSED_VARS(...)
UndoStack * ED_undo_stack_get()
Definition ed_undo.cc:455
Read Guarded memory(de)allocation.
#define MEM_SAFE_FREE(v)
void *(* MEM_dupallocN)(const void *vmemh)
Definition mallocn.cc:39
bool paint_curve_poll(bContext *C)
static bool paintcurve_undosys_poll(bContext *C)
void ED_paintcurve_undosys_type(UndoType *ut)
static void paintcurve_undosys_foreach_ID_ref(UndoStep *us_p, UndoTypeForEachIDRefFn foreach_ID_ref_fn, void *user_data)
static void undocurve_from_paintcurve(UndoCurve *uc, const PaintCurve *pc)
static void paintcurve_undosys_step_free(UndoStep *us_p)
static void paintcurve_undosys_step_encode_init(bContext *C, UndoStep *us_p)
static void undocurve_to_paintcurve(const UndoCurve *uc, PaintCurve *pc)
void ED_paintcurve_undo_push_begin(const char *name)
static bool paintcurve_undosys_step_encode(bContext *C, Main *, UndoStep *us_p)
static void undocurve_free_data(UndoCurve *uc)
void ED_paintcurve_undo_push_end(bContext *C)
static void paintcurve_undosys_step_decode(bContext *, Main *, UndoStep *us_p, const eUndoStepDir, bool)
struct PaintCurve * paint_curve
UndoRefID_PaintCurve pc_ref
PaintCurvePoint * points
PaintCurvePoint * points
size_t data_size
void(* step_encode_init)(bContext *C, UndoStep *us)
void(* step_foreach_ID_ref)(UndoStep *us, UndoTypeForEachIDRefFn foreach_ID_ref_fn, void *user_data)
const char * name
void(* step_free)(UndoStep *us)
bool(* poll)(struct bContext *C)
void(* step_decode)(bContext *C, Main *bmain, UndoStep *us, eUndoStepDir dir, bool is_final)
bool(* step_encode)(bContext *C, Main *bmain, UndoStep *us)
void WM_file_tag_modified()
Definition wm_files.cc:171