Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoshua Leung <aligorith@gmail.com>2016-03-27 16:33:14 +0300
committerJoshua Leung <aligorith@gmail.com>2016-03-27 17:21:28 +0300
commit00cfbeef11c62364e343df27d00fd363f625f2ad (patch)
tree9e8e3537c90da68f5a2147925369da096a75fd21 /source/blender/editors
parentbfbbc8ec4001243ad5e9954665ddf9621329319f (diff)
Code Cleanup - Style tweaks
Diffstat (limited to 'source/blender/editors')
-rw-r--r--source/blender/editors/gpencil/gpencil_intern.h32
-rw-r--r--source/blender/editors/gpencil/gpencil_paint.c31
-rw-r--r--source/blender/editors/gpencil/gpencil_utils.c64
3 files changed, 62 insertions, 65 deletions
diff --git a/source/blender/editors/gpencil/gpencil_intern.h b/source/blender/editors/gpencil/gpencil_intern.h
index 5dd491c66d3..d6d9d7cb347 100644
--- a/source/blender/editors/gpencil/gpencil_intern.h
+++ b/source/blender/editors/gpencil/gpencil_intern.h
@@ -126,6 +126,23 @@ extern ListBase gp_strokes_copypastebuf;
void gp_stroke_delete_tagged_points(bGPDframe *gpf, bGPDstroke *gps, bGPDstroke *next_stroke, int tag_flags);
+
+/**
+ * Apply smooth to stroke
+ *
+ * \param gps Stroke to smooth
+ * \param i Point index
+ * \param inf Smooth factor
+*/
+bool gp_smooth_stroke(bGPDstroke *gps, int i, float inf);
+
+/**
+ * Subdivide a stroke
+ * \param gps Stroke data
+ * \param new_totpoints Total number of points
+*/
+void gp_subdivide_stroke(bGPDstroke *gps, const int new_totpoints);
+
/* Layers Enums -------------------------------------- */
struct EnumPropertyItem *ED_gpencil_layers_enum_itemf(struct bContext *C, struct PointerRNA *ptr, struct PropertyRNA *prop, bool *r_free);
@@ -208,21 +225,6 @@ void gpencil_undo_init(struct bGPdata *gpd);
void gpencil_undo_push(struct bGPdata *gpd);
void gpencil_undo_finish(void);
-/**
-* Apply smooth to stroke
-*
-* gps Stroke to smooth
-* i Point index
-* inf Smooth factor
-*/
-bool gp_smooth_stroke(bGPDstroke *gps, int i, float inf);
-
-/* subdivide a stroke
-* gps Stroke data
-* new_totpoints Total number of points
-*/
-void gp_subdivide_stroke(bGPDstroke *gps, const int new_totpoints);
-
/******************************************************* */
/* FILTERED ACTION DATA - TYPES ---> XXX DEPRECEATED OLD ANIM SYSTEM CODE! */
diff --git a/source/blender/editors/gpencil/gpencil_paint.c b/source/blender/editors/gpencil/gpencil_paint.c
index 3784d11908f..6f4d65fc09e 100644
--- a/source/blender/editors/gpencil/gpencil_paint.c
+++ b/source/blender/editors/gpencil/gpencil_paint.c
@@ -568,10 +568,10 @@ static void gp_stroke_simplify(tGPsdata *p)
static void gp_stroke_newfrombuffer(tGPsdata *p)
{
bGPdata *gpd = p->gpd;
+ bGPDlayer *gpl = p->gpl;
bGPDstroke *gps;
bGPDspoint *pt;
tGPspoint *ptc;
- bGPDlayer *layer = gpencil_layer_getactive(p->gpd);
int i, totelem;
/* since strokes are so fine, when using their depth we need a margin otherwise they might get missed */
@@ -612,14 +612,13 @@ static void gp_stroke_newfrombuffer(tGPsdata *p)
gps->inittime = p->inittime;
/* allocate enough memory for a continuous array for storage points */
- int sublevel = layer->sublevel;
+ int sublevel = gpl->sublevel;
int new_totpoints = gps->totpoints;
- for (i = 0; i < sublevel; ++i)
- {
- // Avoid error if subdivide is too big (assume totpoints is right)
- if (new_totpoints + (new_totpoints - 1) > GP_STROKE_BUFFER_MAX)
- {
- sublevel = i; // reduce sublevel
+ for (i = 0; i < sublevel; i++) {
+ /* Avoid error if subdivide is too big (assume totpoints is right) */
+ if (new_totpoints + (new_totpoints - 1) > GP_STROKE_BUFFER_MAX) {
+ /* Reduce sublevel to avoid too-dense strokes */
+ sublevel = i;
break;
}
new_totpoints += new_totpoints - 1;
@@ -745,21 +744,17 @@ static void gp_stroke_newfrombuffer(tGPsdata *p)
}
/* subdivide the stroke */
- if (sublevel > 0)
- {
+ if (sublevel > 0) {
int sub = gps->totpoints;
- for (i = 0; i < sublevel; ++i)
- {
+ for (i = 0; i < sublevel; i++) {
sub += sub - 1;
gp_subdivide_stroke(gps, sub);
}
}
- /* smooth stroke */
- if (layer->smooth_drawfac > 0.0f) // only if something to do
- {
- for (i = 0; i < gps->totpoints; i++)
- {
- gp_smooth_stroke(gps, i, layer->smooth_drawfac);
+ /* smooth stroke - only if there's somethign to do */
+ if (gpl->smooth_drawfac > 0.0f) {
+ for (i = 0; i < gps->totpoints; i++) {
+ gp_smooth_stroke(gps, i, gpl->smooth_drawfac);
}
}
diff --git a/source/blender/editors/gpencil/gpencil_utils.c b/source/blender/editors/gpencil/gpencil_utils.c
index 8e56cf8199e..c2ffd5ea82d 100644
--- a/source/blender/editors/gpencil/gpencil_utils.c
+++ b/source/blender/editors/gpencil/gpencil_utils.c
@@ -533,28 +533,29 @@ bool gp_point_xy_to_3d(GP_SpaceConversion *gsc, Scene *scene, const float screen
}
}
-/* Apply smooth to stroke point
-* gps Stroke to smooth
-* i Point index
-* inf Smooth factor
+/**
+ * Apply smooth to stroke point
+ * \param gps Stroke to smooth
+ * \param i Point index
+ * \param inf Smooth factor
*/
bool gp_smooth_stroke(bGPDstroke *gps, int i, float inf)
{
bGPDspoint *pt = &gps->points[i];
- float sco[3] = { 0.0f };
-
+ float sco[3] = {0.0f};
+
/* Do nothing if not enough points to smooth out */
if (gps->totpoints <= 2) {
return false;
}
-
+
/* Only affect endpoints by a fraction of the normal strength,
* to prevent the stroke from shrinking too much
*/
if ((i == 0) || (i == gps->totpoints - 1)) {
inf *= 0.1f;
}
-
+
/* Compute smoothed coordinate by taking the ones nearby */
/* XXX: This is potentially slow, and suffers from accumulation error as earlier points are handled before later ones */
{
@@ -562,10 +563,10 @@ bool gp_smooth_stroke(bGPDstroke *gps, int i, float inf)
const int steps = 2;
const float average_fac = 1.0f / (float)(steps * 2 + 1);
int step;
-
+
/* add the point itself */
madd_v3_v3fl(sco, &pt->x, average_fac);
-
+
/* n-steps before/after current point */
// XXX: review how the endpoints are treated by this algorithm
// XXX: falloff measures should also introduce some weighting variations, so that further-out points get less weight
@@ -573,62 +574,61 @@ bool gp_smooth_stroke(bGPDstroke *gps, int i, float inf)
bGPDspoint *pt1, *pt2;
int before = i - step;
int after = i + step;
-
+
CLAMP_MIN(before, 0);
CLAMP_MAX(after, gps->totpoints - 1);
-
+
pt1 = &gps->points[before];
pt2 = &gps->points[after];
-
+
/* add both these points to the average-sum (s += p[i]/n) */
madd_v3_v3fl(sco, &pt1->x, average_fac);
madd_v3_v3fl(sco, &pt2->x, average_fac);
-
+
}
}
-
+
/* Based on influence factor, blend between original and optimal smoothed coordinate */
interp_v3_v3v3(&pt->x, &pt->x, sco, inf);
-
+
return true;
}
-/* subdivide a stroke
-* gps Stroke data
-* new_totpoints Total number of points
-*/
+/**
+ * Subdivide a stroke
+ * \param gps Stroke data
+ * \param new_totpoints Total number of points
+ */
void gp_subdivide_stroke(bGPDstroke *gps, const int new_totpoints)
{
int i;
- // Subdivide stroke adding a point half way existing points
+ /* Subdivide stroke adding a point half way existing points */
bGPDspoint *pt_a;
bGPDspoint *pt_b;
bGPDspoint *pt_n;
-
+
/* Move points to insert subdivision */
int y = 1;
- for (i = gps->totpoints - 1; i > 0; --i)
- {
+ for (i = gps->totpoints - 1; i > 0; i--) {
pt_n = &gps->points[i];
gps->points[new_totpoints - y] = *pt_n;
y = y + 2;
}
+
/* Create interpolated points */
- for (i = 0; i < new_totpoints - 1; ++i)
- {
+ for (i = 0; i < new_totpoints - 1; i++) {
pt_a = &gps->points[i];
pt_n = &gps->points[i + 1];
pt_b = &gps->points[i + 2];
- // Interpolate all values
+ /* Interpolate all values */
interp_v3_v3v3(&pt_n->x, &pt_a->x, &pt_b->x, 0.5f);
pt_n->pressure = interpf(pt_a->pressure, pt_b->pressure, 0.5f);
pt_n->time = interpf(pt_a->time, pt_b->time, 0.5f);
-
- ++i; // add to loop to jump next pair
+
+ i++; /* add to loop to jump next pair */
}
-
- gps->totpoints = new_totpoints; // Increase number of points
-
+
+ gps->totpoints = new_totpoints; /* Increase number of points */
}
/* ******************************************************** */