1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * Copyright (C) 2019 Blender Foundation.
17  * All rights reserved.
18  */
19 
20 /** \file
21  * \ingroup DNA
22  */
23 
24 #pragma once
25 
26 #include "DNA_vec_types.h"
27 
28 /** Number of points in high resolution table is dynamic up to a maximum. */
29 #define PROF_TABLE_MAX 512
30 /** Number of table points per control point. */
31 #define PROF_RESOL 16
32 /** Dynamic size of widget's high resolution table. Input should be profile->totpoint. */
33 #define PROF_TABLE_LEN(n_pts) min_ii(PROF_TABLE_MAX, (((n_pts - 1)) * PROF_RESOL) + 1)
34 
35 /**
36  * Each control point that makes up the profile.
37  * \note The flags use the same enum as Bezier curves, but they aren't guaranteed
38  * to have identical functionality, and all types aren't implemented.
39  */
40 typedef struct CurveProfilePoint {
41   /** Location of the point, keep together. */
42   float x, y;
43   /** Flag selection state and others. */
44   short flag;
45   /** Flags for both handle's type (eBezTriple_Handle auto, vect, free, and aligned supported). */
46   char h1, h2;
47   /** Handle locations, keep together.
48    * \note For now the two handle types are set to the same type in RNA. */
49   float h1_loc[2];
50   float h2_loc[2];
51   char _pad[4];
52   /** Runtime pointer to the point's profile for updating the curve with no direct reference. */
53   struct CurveProfile *profile;
54 } CurveProfilePoint;
55 
56 /** #CurveProfilePoint.flag */
57 enum {
58   PROF_SELECT = (1 << 0),
59   PROF_H1_SELECT = (1 << 1),
60   PROF_H2_SELECT = (1 << 2),
61 };
62 
63 /** Defines a profile. */
64 typedef struct CurveProfile {
65   /** Number of user-added points that define the profile. */
66   short path_len;
67   /** Number of sampled points. */
68   short segments_len;
69   /** Preset to use when reset. */
70   int preset;
71   /** Sequence of points defining the shape of the curve.  */
72   CurveProfilePoint *path;
73   /** Display and evaluation table at higher resolution for curves. */
74   CurveProfilePoint *table;
75   /** The positions of the sampled points. Used to display a preview of where they will be. */
76   CurveProfilePoint *segments;
77   /** Flag for mode states, sampling options, etc... */
78   int flag;
79   /** Used for keeping track how many times the widget is changed. */
80   int changed_timestamp;
81   /** Widget's current view, and clipping rect (is default rect too). */
82   rctf view_rect, clip_rect;
83 } CurveProfile;
84 
85 /** #CurveProfile.flag */
86 enum {
87   PROF_USE_CLIP = (1 << 0), /* Keep control points inside bounding rectangle. */
88   /* PROF_SYMMETRY_MODE = (1 << 1),         Unused for now. */
89   PROF_SAMPLE_STRAIGHT_EDGES = (1 << 2), /* Sample extra points on straight edges. */
90   PROF_SAMPLE_EVEN_LENGTHS = (1 << 3),   /* Put segments evenly spaced along the path. */
91   PROF_DIRTY_PRESET = (1 << 4),          /* Marks when the dynamic preset has been changed. */
92 };
93 
94 typedef enum eCurveProfilePresets {
95   PROF_PRESET_LINE = 0,     /* Default simple line between end points. */
96   PROF_PRESET_SUPPORTS = 1, /* Support loops for a regular curved profile. */
97   PROF_PRESET_CORNICE = 2,  /* Molding type example. */
98   PROF_PRESET_CROWN = 3,    /* Second molding example. */
99   PROF_PRESET_STEPS = 4,    /* Dynamic number of steps defined by segments_len. */
100 } eCurveProfilePresets;
101