2023-08-15 16:20:26 +02:00
|
|
|
/* SPDX-FileCopyrightText: 2019 Blender Authors
|
2023-05-31 16:19:06 +02:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
2019-11-20 22:12:32 +01:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
/** \file
|
|
|
|
* \ingroup bke
|
|
|
|
*/
|
|
|
|
|
2020-09-04 17:56:56 +02:00
|
|
|
#include "DNA_curveprofile_types.h"
|
|
|
|
|
2020-03-02 15:07:49 +01:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2020-06-23 17:02:49 +02:00
|
|
|
struct BlendDataReader;
|
2020-09-30 03:51:13 +02:00
|
|
|
struct BlendWriter;
|
2019-11-20 22:12:32 +01:00
|
|
|
struct CurveProfile;
|
|
|
|
struct CurveProfilePoint;
|
|
|
|
|
2021-12-07 07:19:15 +01:00
|
|
|
/**
|
|
|
|
* Sets the default settings and clip range for the profile widget.
|
|
|
|
* Does not generate either table.
|
|
|
|
*/
|
2019-11-20 22:12:32 +01:00
|
|
|
void BKE_curveprofile_set_defaults(struct CurveProfile *profile);
|
|
|
|
|
2021-12-07 07:19:15 +01:00
|
|
|
/**
|
|
|
|
* Returns a pointer to a newly allocated curve profile, using the given preset.
|
|
|
|
*/
|
2020-09-04 17:56:56 +02:00
|
|
|
struct CurveProfile *BKE_curveprofile_add(eCurveProfilePresets preset);
|
2019-11-20 22:12:32 +01:00
|
|
|
|
|
|
|
void BKE_curveprofile_free_data(struct CurveProfile *profile);
|
|
|
|
|
|
|
|
void BKE_curveprofile_free(struct CurveProfile *profile);
|
|
|
|
|
|
|
|
void BKE_curveprofile_copy_data(struct CurveProfile *target, const struct CurveProfile *profile);
|
|
|
|
|
|
|
|
struct CurveProfile *BKE_curveprofile_copy(const struct CurveProfile *profile);
|
|
|
|
|
2021-12-07 07:19:15 +01:00
|
|
|
/**
|
|
|
|
* Move a point's handle, accounting for the alignment of handles with the #HD_ALIGN type.
|
|
|
|
*
|
|
|
|
* \param handle_1: Whether to move the 1st or 2nd control point.
|
|
|
|
* \param delta: The *relative* change in the handle's position.
|
|
|
|
* \note Requires #BKE_curveprofile_update call after.
|
|
|
|
* \return Whether the handle moved from its start position.
|
|
|
|
*/
|
2020-06-24 17:50:01 +02:00
|
|
|
bool BKE_curveprofile_move_handle(struct CurveProfilePoint *point,
|
2022-01-07 01:38:08 +01:00
|
|
|
bool handle_1,
|
|
|
|
bool snap,
|
2020-06-24 17:50:01 +02:00
|
|
|
const float delta[2]);
|
|
|
|
|
2021-12-07 07:19:15 +01:00
|
|
|
/**
|
|
|
|
* Moves a control point, accounting for clipping and snapping, and moving free handles.
|
|
|
|
*
|
|
|
|
* \param snap: Whether to snap the point to the grid
|
|
|
|
* \param delta: The *relative* change of the point's location.
|
|
|
|
* \return Whether the point moved from its start position.
|
|
|
|
* \note Requires #BKE_curveprofile_update call after.
|
|
|
|
*/
|
2020-06-24 17:50:01 +02:00
|
|
|
bool BKE_curveprofile_move_point(struct CurveProfile *profile,
|
|
|
|
struct CurveProfilePoint *point,
|
2022-01-07 01:38:08 +01:00
|
|
|
bool snap,
|
2020-06-24 17:50:01 +02:00
|
|
|
const float delta[2]);
|
|
|
|
|
2021-12-07 07:19:15 +01:00
|
|
|
/**
|
|
|
|
* Removes a specific point from the path of control points.
|
|
|
|
* \note Requires #BKE_curveprofile_update call after.
|
|
|
|
*/
|
2019-11-20 22:12:32 +01:00
|
|
|
bool BKE_curveprofile_remove_point(struct CurveProfile *profile, struct CurveProfilePoint *point);
|
|
|
|
|
2021-12-07 07:19:15 +01:00
|
|
|
/**
|
|
|
|
* Removes every point in the widget with the supplied flag set, except for the first and last.
|
|
|
|
*
|
|
|
|
* \param flag: #CurveProfilePoint.flag.
|
|
|
|
*
|
|
|
|
* \note Requires #BKE_curveprofile_update call after.
|
|
|
|
*/
|
2022-01-07 01:38:08 +01:00
|
|
|
void BKE_curveprofile_remove_by_flag(struct CurveProfile *profile, short flag);
|
2019-11-20 22:12:32 +01:00
|
|
|
|
2021-12-07 07:19:15 +01:00
|
|
|
/**
|
|
|
|
* Adds a new point at the specified location. The choice for which points to place the new vertex
|
|
|
|
* between is made by checking which control point line segment is closest to the new point and
|
|
|
|
* placing the new vertex in between that segment's points.
|
|
|
|
*
|
|
|
|
* \note Requires #BKE_curveprofile_update call after.
|
|
|
|
*/
|
2019-11-20 22:12:32 +01:00
|
|
|
struct CurveProfilePoint *BKE_curveprofile_insert(struct CurveProfile *profile, float x, float y);
|
|
|
|
|
2021-12-07 07:19:15 +01:00
|
|
|
/**
|
|
|
|
* Sets the handle type of the selected control points.
|
|
|
|
* \param type_1, type_2: Handle type for the first handle. HD_VECT, HD_AUTO, HD_FREE, or HD_ALIGN.
|
|
|
|
* \note Requires #BKE_curveprofile_update call after.
|
|
|
|
*/
|
2019-11-20 22:12:32 +01:00
|
|
|
void BKE_curveprofile_selected_handle_set(struct CurveProfile *profile, int type_1, int type_2);
|
|
|
|
|
2021-12-07 07:19:15 +01:00
|
|
|
/**
|
|
|
|
* Flips the profile across the diagonal so that its orientation is reversed.
|
|
|
|
*
|
|
|
|
* \note Requires #BKE_curveprofile_update call after.
|
|
|
|
*/
|
2019-11-20 22:12:32 +01:00
|
|
|
void BKE_curveprofile_reverse(struct CurveProfile *profile);
|
|
|
|
|
2021-12-07 07:19:15 +01:00
|
|
|
/**
|
|
|
|
* Reset the view to the clipping rectangle.
|
|
|
|
*/
|
2021-03-18 22:25:36 +01:00
|
|
|
void BKE_curveprofile_reset_view(struct CurveProfile *profile);
|
|
|
|
|
2021-12-07 07:19:15 +01:00
|
|
|
/**
|
|
|
|
* Resets the profile to the current preset.
|
|
|
|
*
|
|
|
|
* \note Requires #BKE_curveprofile_update call after.
|
|
|
|
*/
|
2019-11-20 22:12:32 +01:00
|
|
|
void BKE_curveprofile_reset(struct CurveProfile *profile);
|
|
|
|
|
2021-10-04 01:54:52 +02:00
|
|
|
int BKE_curveprofile_table_size(const struct CurveProfile *profile);
|
|
|
|
|
2021-12-07 07:19:15 +01:00
|
|
|
/**
|
|
|
|
* Refreshes the higher resolution table sampled from the input points. A call to this or
|
|
|
|
* #BKE_curveprofile_update is needed before evaluation functions that use the table.
|
|
|
|
* Also sets the number of segments used for the display preview of the locations
|
|
|
|
* of the sampled points.
|
|
|
|
*/
|
2020-08-01 05:02:21 +02:00
|
|
|
void BKE_curveprofile_init(struct CurveProfile *profile, short segments_len);
|
2019-11-20 22:12:32 +01:00
|
|
|
|
|
|
|
/* Called for a complete update of the widget after modifications */
|
2020-06-24 17:50:01 +02:00
|
|
|
enum {
|
|
|
|
PROF_UPDATE_NONE = 0,
|
|
|
|
PROF_UPDATE_REMOVE_DOUBLES = (1 << 0),
|
|
|
|
PROF_UPDATE_CLIP = (1 << 1),
|
|
|
|
};
|
2021-12-07 07:19:15 +01:00
|
|
|
/**
|
|
|
|
* Should be called after the widget is changed. Does profile and remove double checks and more
|
|
|
|
* importantly, recreates the display / evaluation and segments tables.
|
|
|
|
* \param update_flags: Bit-field with fields defined in header file.
|
|
|
|
* Controls removing doubles and clipping.
|
|
|
|
*/
|
2022-01-07 01:38:08 +01:00
|
|
|
void BKE_curveprofile_update(struct CurveProfile *profile, int update_flags);
|
2019-11-20 22:12:32 +01:00
|
|
|
|
2021-12-07 07:19:15 +01:00
|
|
|
/**
|
|
|
|
* Does a single evaluation along the profile's path.
|
|
|
|
* Travels down (length_portion * path) length and returns the position at that point.
|
|
|
|
* Where length portion is the fraction of the total path length where we want the location.
|
|
|
|
*
|
|
|
|
* \param length_portion: The portion (0 to 1) of the path's full length to sample at.
|
|
|
|
* \note Requires #BKE_curveprofile_init or #BKE_curveprofile_update call before to fill table.
|
|
|
|
*/
|
2019-11-20 22:12:32 +01:00
|
|
|
void BKE_curveprofile_evaluate_length_portion(const struct CurveProfile *profile,
|
|
|
|
float length_portion,
|
|
|
|
float *x_out,
|
|
|
|
float *y_out);
|
2020-03-02 15:07:49 +01:00
|
|
|
|
2020-06-23 17:02:49 +02:00
|
|
|
void BKE_curveprofile_blend_write(struct BlendWriter *writer, const struct CurveProfile *profile);
|
2021-12-07 07:19:15 +01:00
|
|
|
/**
|
|
|
|
* Expects that the curve profile itself has been read already.
|
|
|
|
*/
|
2020-06-23 17:02:49 +02:00
|
|
|
void BKE_curveprofile_blend_read(struct BlendDataReader *reader, struct CurveProfile *profile);
|
|
|
|
|
2020-03-02 15:07:49 +01:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|