2018-03-27 07:05:07 +02:00
|
|
|
/*
|
|
|
|
* ***** BEGIN GPL LICENSE BLOCK *****
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** \file blender/editors/sculpt_paint/paint_curve_undo.c
|
|
|
|
* \ingroup edsculpt
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
|
|
|
#include "DNA_brush_types.h"
|
|
|
|
#include "DNA_space_types.h"
|
|
|
|
|
|
|
|
#include "BLI_string.h"
|
2018-03-19 14:17:59 +01:00
|
|
|
#include "BLI_array_utils.h"
|
2018-03-27 07:05:07 +02:00
|
|
|
|
|
|
|
#include "BKE_context.h"
|
|
|
|
#include "BKE_paint.h"
|
2018-03-19 14:17:59 +01:00
|
|
|
#include "BKE_global.h"
|
|
|
|
#include "BKE_main.h"
|
|
|
|
#include "BKE_undo_system.h"
|
2018-03-27 07:05:07 +02:00
|
|
|
|
|
|
|
#include "ED_paint.h"
|
|
|
|
|
|
|
|
#include "WM_api.h"
|
|
|
|
#include "WM_types.h"
|
|
|
|
|
|
|
|
#include "paint_intern.h"
|
|
|
|
|
2018-03-19 14:17:59 +01:00
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
/** \name Undo Conversion
|
|
|
|
* \{ */
|
2018-03-27 07:05:07 +02:00
|
|
|
|
2018-03-19 14:17:59 +01:00
|
|
|
typedef struct UndoCurve {
|
2018-03-27 07:05:07 +02:00
|
|
|
PaintCurvePoint *points; /* points of curve */
|
|
|
|
int tot_points;
|
2018-03-19 14:17:59 +01:00
|
|
|
int add_index;
|
2018-03-27 07:05:07 +02:00
|
|
|
} UndoCurve;
|
|
|
|
|
2018-03-19 14:17:59 +01:00
|
|
|
static void undocurve_from_paintcurve(UndoCurve *uc, const PaintCurve *pc)
|
2018-03-27 07:05:07 +02:00
|
|
|
{
|
2018-03-19 14:17:59 +01:00
|
|
|
BLI_assert(BLI_array_is_zeroed(uc, 1));
|
|
|
|
uc->points = MEM_dupallocN(pc->points);
|
|
|
|
uc->tot_points = pc->tot_points;
|
|
|
|
uc->add_index = pc->add_index;
|
|
|
|
}
|
2018-03-27 07:05:07 +02:00
|
|
|
|
2018-03-19 14:17:59 +01:00
|
|
|
static void undocurve_to_paintcurve(const UndoCurve *uc, PaintCurve *pc)
|
|
|
|
{
|
|
|
|
MEM_SAFE_FREE(pc->points);
|
|
|
|
pc->points = MEM_dupallocN(uc->points);
|
|
|
|
pc->tot_points = uc->tot_points;
|
|
|
|
pc->add_index = uc->add_index;
|
|
|
|
}
|
2018-03-27 07:05:07 +02:00
|
|
|
|
2018-03-19 14:17:59 +01:00
|
|
|
static void undocurve_free_data(UndoCurve *uc)
|
|
|
|
{
|
|
|
|
MEM_SAFE_FREE(uc->points);
|
|
|
|
}
|
2018-03-27 07:05:07 +02:00
|
|
|
|
2018-03-19 14:17:59 +01:00
|
|
|
/** \} */
|
2018-03-27 07:05:07 +02:00
|
|
|
|
2018-03-19 14:17:59 +01:00
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
/** \name Implements ED Undo System
|
|
|
|
* \{ */
|
2018-03-27 07:05:07 +02:00
|
|
|
|
2018-03-19 14:17:59 +01:00
|
|
|
typedef struct PaintCurveUndoStep {
|
|
|
|
UndoStep step;
|
|
|
|
PaintCurve *pc;
|
|
|
|
UndoCurve data;
|
|
|
|
} PaintCurveUndoStep;
|
|
|
|
|
|
|
|
static bool paintcurve_undosys_poll(bContext *C)
|
2018-03-27 07:05:07 +02:00
|
|
|
{
|
2018-03-19 14:17:59 +01:00
|
|
|
Paint *p = BKE_paint_get_active_from_context(C);
|
|
|
|
return (p->brush && p->brush->paint_curve);
|
|
|
|
}
|
2018-03-27 07:05:07 +02:00
|
|
|
|
2018-03-19 14:17:59 +01:00
|
|
|
static void paintcurve_undosys_step_encode_init(struct bContext *C, UndoStep *us_p)
|
|
|
|
{
|
|
|
|
/* XXX, use to set the undo type only. */
|
|
|
|
UNUSED_VARS(C, us_p);
|
2018-03-27 07:05:07 +02:00
|
|
|
}
|
|
|
|
|
2018-03-19 14:17:59 +01:00
|
|
|
static bool paintcurve_undosys_step_encode(struct bContext *C, UndoStep *us_p)
|
2018-03-27 07:05:07 +02:00
|
|
|
{
|
2018-03-19 14:17:59 +01:00
|
|
|
Paint *p = BKE_paint_get_active_from_context(C);
|
|
|
|
PaintCurve *pc = p ? (p->brush ? p->brush->paint_curve : NULL) : NULL;
|
|
|
|
if (pc == NULL) {
|
|
|
|
return false;
|
2018-03-27 07:05:07 +02:00
|
|
|
}
|
|
|
|
|
2018-03-19 14:17:59 +01:00
|
|
|
PaintCurveUndoStep *us = (PaintCurveUndoStep *)us_p;
|
|
|
|
BLI_assert(us->step.data_size == 0);
|
2018-03-27 07:05:07 +02:00
|
|
|
|
2018-03-19 14:17:59 +01:00
|
|
|
us->pc = pc;
|
|
|
|
undocurve_from_paintcurve(&us->data, pc);
|
2018-03-27 07:05:07 +02:00
|
|
|
|
2018-03-19 14:17:59 +01:00
|
|
|
return true;
|
|
|
|
}
|
2018-03-27 07:05:07 +02:00
|
|
|
|
2018-03-19 14:17:59 +01:00
|
|
|
static void paintcurve_undosys_step_decode(struct bContext *UNUSED(C), UndoStep *us_p, int UNUSED(dir))
|
|
|
|
{
|
|
|
|
PaintCurveUndoStep *us = (PaintCurveUndoStep *)us_p;
|
|
|
|
undocurve_to_paintcurve(&us->data, us->pc);
|
|
|
|
}
|
2018-03-27 07:05:07 +02:00
|
|
|
|
2018-03-19 14:17:59 +01:00
|
|
|
static void paintcurve_undosys_step_free(UndoStep *us_p)
|
|
|
|
{
|
|
|
|
PaintCurveUndoStep *us = (PaintCurveUndoStep *)us_p;
|
|
|
|
undocurve_free_data(&us->data);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Export for ED_undo_sys. */
|
|
|
|
void ED_paintcurve_undosys_type(UndoType *ut)
|
|
|
|
{
|
|
|
|
ut->name = "Paint Curve";
|
|
|
|
/* don't poll for now */
|
|
|
|
ut->poll = paintcurve_undosys_poll;
|
|
|
|
ut->step_encode_init = paintcurve_undosys_step_encode_init;
|
|
|
|
ut->step_encode = paintcurve_undosys_step_encode;
|
|
|
|
ut->step_decode = paintcurve_undosys_step_decode;
|
|
|
|
ut->step_free = paintcurve_undosys_step_free;
|
|
|
|
|
|
|
|
ut->mode = BKE_UNDOTYPE_MODE_STORE;
|
|
|
|
ut->use_context = false;
|
|
|
|
|
|
|
|
ut->step_size = sizeof(PaintCurveUndoStep);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** \} */
|
2018-03-27 07:05:07 +02:00
|
|
|
|
|
|
|
|
2018-03-19 14:17:59 +01:00
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
/** \name Utilities
|
|
|
|
* \{ */
|
|
|
|
|
|
|
|
void ED_paintcurve_undo_push_begin(const char *name)
|
|
|
|
{
|
|
|
|
bContext *C = NULL; /* special case, we never read from this. */
|
|
|
|
wmWindowManager *wm = G.main->wm.first;
|
|
|
|
BKE_undosys_step_push_init_with_type(wm->undo_stack, C, name, BKE_UNDOSYS_TYPE_PAINTCURVE);
|
2018-03-27 07:05:07 +02:00
|
|
|
}
|
2018-03-19 14:17:59 +01:00
|
|
|
|
|
|
|
void ED_paintcurve_undo_push_end(void)
|
|
|
|
{
|
|
|
|
wmWindowManager *wm = G.main->wm.first; /* XXX, avoids adding extra arg. */
|
|
|
|
BKE_undosys_step_push(wm->undo_stack, NULL, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** \} */
|