Blender V5.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
8
9#include <cstring>
10
11#include "MEM_guardedalloc.h"
12
13#include "DNA_brush_types.h"
14#include "DNA_userdef_types.h"
15
16#include "BKE_paint.hh"
17#include "BKE_undo_system.hh"
18
19#include "ED_paint.hh"
20#include "ED_undo.hh"
21
22#include "WM_api.hh"
23
24#include "paint_intern.hh"
25
26#ifndef NDEBUG
27# include "BLI_array_utils_c.hh" /* #BLI_array_is_zeroed */
28#endif
29
30namespace blender {
31
32/* -------------------------------------------------------------------- */
35
36namespace {
37
38struct UndoCurve {
39 PaintCurvePoint *points; /* points of curve */
40 int tot_points;
41 int add_index;
42};
43
44} // namespace
45
46static void undocurve_from_paintcurve(UndoCurve *uc, const PaintCurve *pc)
47{
49 uc->points = MEM_dupalloc(pc->points);
50 uc->tot_points = pc->tot_points;
51 uc->add_index = pc->add_index;
52}
53
54static void undocurve_to_paintcurve(const UndoCurve *uc, PaintCurve *pc)
55{
56 MEM_SAFE_DELETE(pc->points);
57 pc->points = MEM_dupalloc(uc->points);
58 pc->tot_points = uc->tot_points;
59 pc->add_index = uc->add_index;
60}
61
62static void undocurve_free_data(UndoCurve *uc)
63{
64 MEM_SAFE_DELETE(uc->points);
65}
66
68
69/* -------------------------------------------------------------------- */
72
75
76 UndoRefID_PaintCurve pc_ref;
77
78 UndoCurve data;
79};
80
82{
83 if (C == nullptr || !paint_curve_poll(C)) {
84 return false;
85 }
88 return (brush && brush->paint_curve);
89}
90
92{
93 /* XXX, use to set the undo type only. */
94 UNUSED_VARS(C, us_p);
95}
96
97static bool paintcurve_undosys_step_encode(bContext *C, Main * /*bmain*/, UndoStep *us_p)
98{
99 /* FIXME Double check this, it should not be needed here at all? undo system is supposed to
100 * ensure that. */
101 if (!paint_curve_poll(C)) {
102 return false;
103 }
104
107 PaintCurve *pc = paint ? (brush ? brush->paint_curve : nullptr) : nullptr;
108 if (pc == nullptr) {
109 return false;
110 }
111
112 PaintCurveUndoStep *us = reinterpret_cast<PaintCurveUndoStep *>(us_p);
113 BLI_assert(us->step.data_size == 0);
114
115 us->pc_ref.ptr = pc;
117
118 return true;
119}
120
122 Main * /*bmain*/,
123 UndoStep *us_p,
124 const eUndoStepDir /*dir*/,
125 bool /*is_final*/)
126{
127 PaintCurveUndoStep *us = reinterpret_cast<PaintCurveUndoStep *>(us_p);
128 undocurve_to_paintcurve(&us->data, us->pc_ref.ptr);
129}
130
132{
133 PaintCurveUndoStep *us = reinterpret_cast<PaintCurveUndoStep *>(us_p);
135}
136
138 UndoTypeForEachIDRefFn foreach_ID_ref_fn,
139 void *user_data)
140{
141 PaintCurveUndoStep *us = reinterpret_cast<PaintCurveUndoStep *>(us_p);
142 foreach_ID_ref_fn(user_data, (reinterpret_cast<UndoRefID *>(&us->pc_ref)));
143}
144
160
162
163/* -------------------------------------------------------------------- */
166
167void ED_paintcurve_undo_push_begin(const char *name)
168{
169 UndoStack *ustack = ED_undo_stack_get();
170 bContext *C = nullptr; /* special case, we never read from this. */
172}
173
181
183
184} // namespace blender
#define BKE_undosys_stack_limit_steps_and_memory_defaults(ustack)
Generic array manipulation API.
#define BLI_array_is_zeroed(arr, arr_len)
Read Blender memory allocation and freeing.
#define C
Definition RandGen.cpp:29
#define UNUSED_VARS(...)
BMesh Iterators.
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
static void undocurve_from_paintcurve(UndoCurve *uc, const PaintCurve *pc)
void ED_paintcurve_undosys_type(UndoType *ut)
UndoStack * ED_undo_stack_get()
Definition ed_undo.cc:690
static void undocurve_to_paintcurve(const UndoCurve *uc, PaintCurve *pc)
const UndoType * BKE_UNDOSYS_TYPE_PAINTCURVE
void ED_paintcurve_undo_push_begin(const char *name)
static void paintcurve_undosys_step_encode_init(bContext *C, UndoStep *us_p)
bool paint_curve_poll(bContext *C)
static bool paintcurve_undosys_poll(bContext *C)
static void paintcurve_undosys_step_decode(bContext *, Main *, UndoStep *us_p, const eUndoStepDir, bool)
static bool paintcurve_undosys_step_encode(bContext *C, Main *, UndoStep *us_p)
void ED_paintcurve_undo_push_end(bContext *C)
void WM_file_tag_modified()
Definition wm_files.cc:188
static void paintcurve_undosys_step_free(UndoStep *us_p)
Paint * BKE_paint_get_active_from_context(const bContext *C)
Brush * BKE_paint_brush(Paint *paint)
void(*)(void *user_data, UndoRefID *id_ref) UndoTypeForEachIDRefFn
static void undocurve_free_data(UndoCurve *uc)
static void paintcurve_undosys_foreach_ID_ref(UndoStep *us_p, UndoTypeForEachIDRefFn foreach_ID_ref_fn, void *user_data)
eUndoPushReturn BKE_undosys_step_push(UndoStack *ustack, bContext *C, const char *name, UndoEncodeHints hints)
UndoStep * BKE_undosys_step_push_init_with_type(UndoStack *ustack, bContext *C, const char *name, const UndoType *ut)
UndoRefID_PaintCurve pc_ref
PaintCurvePoint * points
bool(*) poll(bContext *C)
void(*) step_free(UndoStep *us)
void(*) step_decode(bContext *C, Main *bmain, UndoStep *us, eUndoStepDir dir, bool is_final)
void(*) step_foreach_ID_ref(UndoStep *us, UndoTypeForEachIDRefFn foreach_ID_ref_fn, void *user_data)
bool(*) step_encode(bContext *C, Main *bmain, UndoStep *us)
const char * identifier
void(*) step_encode_init(bContext *C, UndoStep *us)