style cleanup: mask, whitespace edits, also use len_squared_v2 for comparisons.

This commit is contained in:
Campbell Barton
2012-05-13 21:36:42 +00:00
parent 2a3fddf5b3
commit ee9d9f4737
10 changed files with 213 additions and 195 deletions

View File

@@ -32,8 +32,8 @@
#include "raskter.h"
// from BLI_utildefines.h
#define MIN2(x,y) ( (x)<(y) ? (x) : (y) )
#define MAX2(x,y) ( (x)>(y) ? (x) : (y) )
#define MIN2(x, y) ( (x) < (y) ? (x) : (y) )
#define MAX2(x, y) ( (x) > (y) ? (x) : (y) )
struct e_status {
@@ -64,7 +64,7 @@ static struct r_buffer_stats rb;
* just the poly. Since the DEM code could end up being coupled with this, we'll keep it separate
* for now.
*/
static void preprocess_all_edges(struct poly_vert * verts, int num_verts, struct e_status * open_edge) {
static void preprocess_all_edges(struct poly_vert *verts, int num_verts, struct e_status *open_edge) {
int i;
int xbeg;
int ybeg;
@@ -82,21 +82,22 @@ static void preprocess_all_edges(struct poly_vert * verts, int num_verts, struct
v = verts;
all_edges = NULL;
// loop all verts
for(i = 0; i < num_verts; i++) {
for (i = 0; i < num_verts; i++) {
// determine beginnings and endings of edges, linking last vertex to first vertex
xbeg = v[i].x;
ybeg = v[i].y;
if(i) {
if (i) {
// we're not at the last vert, so end of the edge is the previous vertex
xend = v[i-1].x;
yend = v[i-1].y;
} else {
xend = v[i - 1].x;
yend = v[i - 1].y;
}
else {
// we're at the first vertex, so the "end" of this edge is the last vertex
xend = v[num_verts-1].x;
yend = v[num_verts-1].y;
xend = v[num_verts - 1].x;
yend = v[num_verts - 1].y;
}
// make sure our edges are facing the correct direction
if(ybeg > yend) {
if (ybeg > yend) {
// flip the Xs
temp_pos = xbeg;
xbeg = xend;
@@ -110,16 +111,17 @@ static void preprocess_all_edges(struct poly_vert * verts, int num_verts, struct
// calculate y delta
dy = yend - ybeg;
// dont draw horizontal lines directly, they are scanned as part of the edges they connect, so skip em. :)
if(dy) {
if (dy) {
// create the edge and determine it's slope (for incremental line drawing)
e_new = open_edge++;
// calculate x delta
dx = xend - xbeg;
if(dx > 0){
if (dx > 0) {
e_new->xdir = 1;
xdist = dx;
}else{
}
else {
e_new->xdir = -1;
xdist = -dx;
}
@@ -130,23 +132,25 @@ static void preprocess_all_edges(struct poly_vert * verts, int num_verts, struct
e_new->drift_dec = dy;
// calculate deltas for incremental drawing
if(dx >= 0) {
if (dx >= 0) {
e_new->drift = 0;
} else {
}
else {
e_new->drift = -dy + 1;
}
if(dy >= xdist) {
if (dy >= xdist) {
e_new->drift_inc = xdist;
e_new->xshift = 0;
} else {
}
else {
e_new->drift_inc = xdist % dy;
e_new->xshift = (xdist / dy) * e_new->xdir;
}
next_edge_ref = &all_edges;
// link in all the edges, in sorted order
for(;;) {
for (;; ) {
next_edge = *next_edge_ref;
if(!next_edge || (next_edge->ybeg > ybeg) || ((next_edge->ybeg == ybeg) && (next_edge->x >= xbeg))) {
if (!next_edge || (next_edge->ybeg > ybeg) || ((next_edge->ybeg == ybeg) && (next_edge->x >= xbeg))) {
e_new->e_next = next_edge;
*next_edge_ref = e_new;
break;
@@ -162,156 +166,158 @@ static void preprocess_all_edges(struct poly_vert * verts, int num_verts, struct
* for speed, but waiting on final design choices for curve-data before eliminating data the DEM code will need
* if it ends up being coupled with this function.
*/
int rast_scan_fill(struct poly_vert * verts, int num_verts) {
int x_curr; // current pixel position in X
int y_curr; // current scan line being drawn
int yp; // y-pixel's position in frame buffer
int swixd = 0; // whether or not edges switched position in X
float *cpxl; // pixel pointers...
int rast_scan_fill(struct poly_vert *verts, int num_verts) {
int x_curr; // current pixel position in X
int y_curr; // current scan line being drawn
int yp; // y-pixel's position in frame buffer
int swixd = 0; // whether or not edges switched position in X
float *cpxl; // pixel pointers...
float *mpxl;
float *spxl;
struct e_status *e_curr; // edge pointers...
struct e_status *e_curr; // edge pointers...
struct e_status *e_temp;
struct e_status *edgbuf;
struct e_status **edgec;
/*
If the number of verts specified to render as a polygon is less than 3,
return immediately. Obviously we cant render a poly with sides < 3. The
return for this we set to 1, simply so it can be distinguished from the
next place we could return, which is a failure to allocate memory.
If the number of verts specified to render as a polygon is less than 3,
return immediately. Obviously we cant render a poly with sides < 3. The
return for this we set to 1, simply so it can be distinguished from the
next place we could return, which is a failure to allocate memory.
*/
if(num_verts < 3) {
if (num_verts < 3) {
return(1);
}
/*
Try to allocate an edge buffer in memory. needs to be the size of the edge tracking data
multiplied by the number of edges, which is always equal to the number of verts in
a 2D polygon. Here we return 0 to indicate a memory allocation failure, as opposed to a 1 for
the preceeding error, which was a rasterization request on a 2D poly with less than
3 sides.
Try to allocate an edge buffer in memory. needs to be the size of the edge tracking data
multiplied by the number of edges, which is always equal to the number of verts in
a 2D polygon. Here we return 0 to indicate a memory allocation failure, as opposed to a 1 for
the preceeding error, which was a rasterization request on a 2D poly with less than
3 sides.
*/
if((edgbuf = (struct e_status *)(malloc(sizeof(struct e_status) * num_verts))) == NULL) {
if ((edgbuf = (struct e_status *)(malloc(sizeof(struct e_status) * num_verts))) == NULL) {
return(0);
}
/*
Do some preprocessing on all edges. This constructs a table structure in memory of all
the edge properties and can "flip" some edges so sorting works correctly.
Do some preprocessing on all edges. This constructs a table structure in memory of all
the edge properties and can "flip" some edges so sorting works correctly.
*/
preprocess_all_edges(verts, num_verts, edgbuf);
/*
Set the pointer for tracking the edges currently in processing to NULL to make sure
we don't get some crazy value after initialization.
Set the pointer for tracking the edges currently in processing to NULL to make sure
we don't get some crazy value after initialization.
*/
possible_edges = NULL;
/*
Loop through all scan lines to be drawn. Since we sorted by Y values during
preprocess_all_edges(), we can already exact values for the lowest and
highest Y values we could possibly need by induction. The preprocessing sorted
out edges by Y position, we can cycle the current edge being processed once
it runs out of Y pixels. When we have no more edges, meaning the current edge
is NULL after setting the "current" edge to be the previous current edge's
"next" edge in the Y sorted edge connection chain, we can stop looping Y values,
since we can't possibly have more scan lines if we ran out of edges. :)
Loop through all scan lines to be drawn. Since we sorted by Y values during
preprocess_all_edges(), we can already exact values for the lowest and
highest Y values we could possibly need by induction. The preprocessing sorted
out edges by Y position, we can cycle the current edge being processed once
it runs out of Y pixels. When we have no more edges, meaning the current edge
is NULL after setting the "current" edge to be the previous current edge's
"next" edge in the Y sorted edge connection chain, we can stop looping Y values,
since we can't possibly have more scan lines if we ran out of edges. :)
TODO: This clips Y to the frame buffer, which should be done in the preprocessor, but for now is done here.
Will get changed once DEM code gets in.
TODO: This clips Y to the frame buffer, which should be done in the preprocessor, but for now is done here.
Will get changed once DEM code gets in.
*/
for(y_curr = MAX2(all_edges->ybeg,0); (all_edges || possible_edges) && (y_curr < rb.sizey); y_curr++) {
for (y_curr = MAX2(all_edges->ybeg, 0); (all_edges || possible_edges) && (y_curr < rb.sizey); y_curr++) {
/*
Link any edges that start on the current scan line into the list of
edges currently needed to draw at least this, if not several, scan lines.
Link any edges that start on the current scan line into the list of
edges currently needed to draw at least this, if not several, scan lines.
*/
/*
Set the current edge to the beginning of the list of edges to be rasterized
into this scan line.
Set the current edge to the beginning of the list of edges to be rasterized
into this scan line.
We could have lots of edge here, so iterate over all the edges needed. The
preprocess_all_edges() function sorted edges by X within each chunk of Y sorting
so we safely cycle edges to thier own "next" edges in order.
We could have lots of edge here, so iterate over all the edges needed. The
preprocess_all_edges() function sorted edges by X within each chunk of Y sorting
so we safely cycle edges to thier own "next" edges in order.
At each iteration, make sure we still have a non-NULL edge.
At each iteration, make sure we still have a non-NULL edge.
*/
for(edgec = &possible_edges; all_edges && (all_edges->ybeg == y_curr);) {
for (edgec = &possible_edges; all_edges && (all_edges->ybeg == y_curr); ) {
x_curr = all_edges->x; // Set current X position.
for(;;) { // Start looping edges. Will break when edges run out.
for (;; ) { // Start looping edges. Will break when edges run out.
e_curr = *edgec; // Set up a current edge pointer.
if(!e_curr || (e_curr->x >= x_curr)) { // If we have an no edge, or we need to skip some X-span,
if (!e_curr || (e_curr->x >= x_curr)) { // If we have an no edge, or we need to skip some X-span,
e_temp = all_edges->e_next; // set a temp "next" edge to test.
*edgec = all_edges; // Add this edge to the list to be scanned.
all_edges->e_next = e_curr; // Set up the next edge.
edgec = &all_edges->e_next; // Set our list to the next edge's location in memory.
all_edges = e_temp; // Skip the NULL or bad X edge, set pointer to next edge.
break; // Stop looping edges (since we ran out or hit empty X span.
} else {
}
else {
edgec = &e_curr->e_next; // Set the pointer to the edge list the "next" edge.
}
}
}
/*
Determine the current scan line's offset in the pixel buffer based on its Y position.
Basically we just multiply the current scan line's Y value by the number of pixels in each line.
Determine the current scan line's offset in the pixel buffer based on its Y position.
Basically we just multiply the current scan line's Y value by the number of pixels in each line.
*/
yp = y_curr * rb.sizex;
/*
Set a "scan line pointer" in memory. The location of the buffer plus the row offset.
Set a "scan line pointer" in memory. The location of the buffer plus the row offset.
*/
spxl = rb.buf + (yp);
/*
Set up the current edge to the first (in X) edge. The edges which could possibly be in this
list were determined in the preceeding edge loop above. They were already sorted in X by the
initial processing function.
Set up the current edge to the first (in X) edge. The edges which could possibly be in this
list were determined in the preceeding edge loop above. They were already sorted in X by the
initial processing function.
At each iteration, test for a NULL edge. Since we'll keep cycling edge's to their own "next" edge
we will eventually hit a NULL when the list runs out.
At each iteration, test for a NULL edge. Since we'll keep cycling edge's to their own "next" edge
we will eventually hit a NULL when the list runs out.
*/
for(e_curr = possible_edges; e_curr; e_curr = e_curr->e_next) {
for (e_curr = possible_edges; e_curr; e_curr = e_curr->e_next) {
/*
Calculate a span of pixels to fill on the current scan line.
Calculate a span of pixels to fill on the current scan line.
Set the current pixel pointer by adding the X offset to the scan line's start offset.
Cycle the current edge the next edge.
Set the max X value to draw to be one less than the next edge's first pixel. This way we are
sure not to ever get into a situation where we have overdraw. (drawing the same pixel more than
one time because it's on a vertex connecting two edges)
Set the current pixel pointer by adding the X offset to the scan line's start offset.
Cycle the current edge the next edge.
Set the max X value to draw to be one less than the next edge's first pixel. This way we are
sure not to ever get into a situation where we have overdraw. (drawing the same pixel more than
one time because it's on a vertex connecting two edges)
Then blast through all the pixels in the span, advancing the pointer and setting the color to white.
Then blast through all the pixels in the span, advancing the pointer and setting the color to white.
TODO: Here we clip to the scan line, this is not efficient, and should be done in the preprocessor,
but for now it is done here until the DEM code comes in.
*/
TODO: Here we clip to the scan line, this is not efficient, and should be done in the preprocessor,
but for now it is done here until the DEM code comes in.
*/
// set up xmin and xmax bounds on this scan line
cpxl = spxl + MAX2(e_curr->x,0);
cpxl = spxl + MAX2(e_curr->x, 0);
e_curr = e_curr->e_next;
mpxl = spxl + MIN2(e_curr->x,rb.sizex) - 1;
mpxl = spxl + MIN2(e_curr->x, rb.sizex) - 1;
// draw the pixels.
for(; cpxl <= mpxl; *cpxl++ = 1.0f);
for (; cpxl <= mpxl; *cpxl++ = 1.0f) ;
}
/*
Loop through all edges of polygon that could be hit by this scan line,
and figure out their x-intersections with the next scan line.
Loop through all edges of polygon that could be hit by this scan line,
and figure out their x-intersections with the next scan line.
Either A.) we wont have any more edges to test, or B.) we just add on the
slope delta computed in preprocessing step. Since this draws non-antialiased
polygons, we dont have fractional positions, so we only move in x-direction
when needed to get all the way to the next pixel over...
Either A.) we wont have any more edges to test, or B.) we just add on the
slope delta computed in preprocessing step. Since this draws non-antialiased
polygons, we dont have fractional positions, so we only move in x-direction
when needed to get all the way to the next pixel over...
*/
for(edgec = &possible_edges; (e_curr = *edgec);) {
if(!(--(e_curr->num))) {
for (edgec = &possible_edges; (e_curr = *edgec); ) {
if (!(--(e_curr->num))) {
*edgec = e_curr->e_next;
} else {
}
else {
e_curr->x += e_curr->xshift;
if((e_curr->drift += e_curr->drift_inc) > 0) {
if ((e_curr->drift += e_curr->drift_inc) > 0) {
e_curr->x += e_curr->xdir;
e_curr->drift -= e_curr->drift_dec;
}
@@ -319,17 +325,17 @@ int rast_scan_fill(struct poly_vert * verts, int num_verts) {
}
}
/*
It's possible that some edges may have crossed during the last step, so we'll be sure
that we ALWAYS intersect scan lines in order by shuffling if needed to make all edges
sorted by x-intersection coordinate. We'll always scan through at least once to see if
edges crossed, and if so, we set the 'swixd' flag. If 'swixd' gets set on the initial
pass, then we know we need to sort by x, so then cycle through edges again and perform
the sort.-
It's possible that some edges may have crossed during the last step, so we'll be sure
that we ALWAYS intersect scan lines in order by shuffling if needed to make all edges
sorted by x-intersection coordinate. We'll always scan through at least once to see if
edges crossed, and if so, we set the 'swixd' flag. If 'swixd' gets set on the initial
pass, then we know we need to sort by x, so then cycle through edges again and perform
the sort.-
*/
if(possible_edges) {
for(edgec = &possible_edges; (e_curr = *edgec)->e_next; edgec = &(*edgec)->e_next) {
if (possible_edges) {
for (edgec = &possible_edges; (e_curr = *edgec)->e_next; edgec = &(*edgec)->e_next) {
// if the current edge hits scan line at greater X than the next edge, we need to exchange the edges
if(e_curr->x > e_curr->e_next->x) {
if (e_curr->x > e_curr->e_next->x) {
*edgec = e_curr->e_next;
// exchange the pointers
e_temp = e_curr->e_next->e_next;
@@ -340,12 +346,12 @@ int rast_scan_fill(struct poly_vert * verts, int num_verts) {
}
}
// if we did have a switch, look for more (there will more if there was one)
for(;;) {
for (;; ) {
// reset exchange flag so it's only set if we encounter another one
swixd = 0;
for(edgec = &possible_edges; (e_curr = *edgec)->e_next; edgec = &(*edgec)->e_next) {
for (edgec = &possible_edges; (e_curr = *edgec)->e_next; edgec = &(*edgec)->e_next) {
// again, if current edge hits scan line at higher X than next edge, exchange the edges and set flag
if(e_curr->x > e_curr->e_next->x) {
if (e_curr->x > e_curr->e_next->x) {
*edgec = e_curr->e_next;
// exchange the pointers
e_temp = e_curr->e_next->e_next;
@@ -356,7 +362,7 @@ int rast_scan_fill(struct poly_vert * verts, int num_verts) {
}
}
// if we had no exchanges, we're done reshuffling the pointers
if(!swixd) {
if (!swixd) {
break;
}
}
@@ -367,7 +373,7 @@ int rast_scan_fill(struct poly_vert * verts, int num_verts) {
return 1;
}
int PLX_raskterize(float * verts, int num, float * buf, int buf_x, int buf_y) {
int PLX_raskterize(float *verts, int num, float *buf, int buf_x, int buf_y) {
int i; // i: Loop counter.
struct poly_vert *ply; // ply: Pointer to a list of integer buffer-space vertex coordinates.
@@ -378,7 +384,7 @@ int PLX_raskterize(float * verts, int num, float * buf, int buf_x, int buf_y) {
* In the event of a failure to allocate the memory, return 0, so this error can
* be distinguished as a memory allocation error.
*/
if((ply = (struct poly_vert *)(malloc(sizeof(struct poly_vert) * num))) == NULL) {
if ((ply = (struct poly_vert *)(malloc(sizeof(struct poly_vert) * num))) == NULL) {
return(0);
}
@@ -390,9 +396,9 @@ int PLX_raskterize(float * verts, int num, float * buf, int buf_x, int buf_y) {
* It's worth noting that this function ONLY outputs fully white pixels in a mask. Every pixel
* drawn will be 1.0f in value, there is no anti-aliasing.
*/
for(i = 0; i < num; i++) { // Loop over all verts.
ply[i].x = (verts[i<<1] * buf_x) + 0.5f; // Range expand normalized X to integer buffer-space X.
ply[i].y = (verts[(i<<1)+1] * buf_y) + 0.5f; // Range expand normalized Y to integer buffer-space Y.
for (i = 0; i < num; i++) { // Loop over all verts.
ply[i].x = (verts[i << 1] * buf_x) + 0.5f; // Range expand normalized X to integer buffer-space X.
ply[i].y = (verts[(i << 1) + 1] * buf_y) + 0.5f; // Range expand normalized Y to integer buffer-space Y.
}
rb.buf = buf; // Set the output buffer pointer.

View File

@@ -28,27 +28,27 @@
* \ingroup RASKTER
*/
struct poly_vert{
struct poly_vert {
int x;
int y;
};
struct scan_line{
struct scan_line {
int xstart;
int xend;
};
struct scan_line_batch{
struct scan_line_batch {
int num;
int ystart;
struct scan_line * slines;
struct scan_line *slines;
};
#ifdef __cplusplus
extern "C" {
#endif
int PLX_raskterize(float * verts, int num, float * buf, int buf_x, int buf_y);
int PLX_raskterize(float *verts, int num, float *buf, int buf_x, int buf_y);
#ifdef __cplusplus
}

View File

@@ -83,12 +83,12 @@ void BKE_mask_evaluate_all_masks(struct Main *bmain, float ctime);
void BKE_mask_update_scene(struct Main *bmain, struct Scene *scene);
void BKE_mask_parent_init(struct MaskParent *parent);
#define MASKPOINT_ISSEL(p) ( ((p)->bezt.f1 | (p)->bezt.f2 | (p)->bezt.f2) & SELECT )
#define MASKPOINT_ISSEL(p) ( ((p)->bezt.f1 | (p)->bezt.f2 | (p)->bezt.f2) & SELECT)
#define MASKPOINT_SEL(p) { (p)->bezt.f1 |= SELECT; (p)->bezt.f2 |= SELECT; (p)->bezt.f3 |= SELECT; } (void)0
#define MASKPOINT_DESEL(p) { (p)->bezt.f1 &= ~SELECT; (p)->bezt.f2 &= ~SELECT; (p)->bezt.f3 &= ~SELECT; } (void)0
#define MASKPOINT_INVSEL(p) { (p)->bezt.f1 ^= SELECT; (p)->bezt.f2 ^= SELECT; (p)->bezt.f3 ^= SELECT; } (void)0
#define MASKPOINT_CV_ISSEL(p) ( (p)->bezt.f2 & SELECT )
#define MASKPOINT_CV_ISSEL(p) ( (p)->bezt.f2 & SELECT)
#define MASKPOINT_HANDLE_ONLY_ISSEL(p) ( (((p)->bezt.f1 | (p)->bezt.f2) & SELECT) && (((p)->bezt.f2 & SELECT) == 0) )
#define MASKPOINT_HANDLE_ISSEL(p) ( (((p)->bezt.f1 | (p)->bezt.f2) & SELECT) )

View File

@@ -79,7 +79,7 @@ static IDType idtypes[] = {
{ ID_WO, "World", "worlds", IDTYPE_FLAGS_ISLINKABLE},
{ ID_WM, "WindowManager", "window_managers", 0},
{ ID_MC, "MovieClip", "movieclips", IDTYPE_FLAGS_ISLINKABLE},
{ ID_MSK, "Mask", "masks", IDTYPE_FLAGS_ISLINKABLE},
{ ID_MSK, "Mask", "masks", IDTYPE_FLAGS_ISLINKABLE},
};
static int nidtypes = sizeof(idtypes) / sizeof(idtypes[0]);

View File

@@ -573,7 +573,7 @@ int set_listbasepointers(Main *main, ListBase **lb)
lb[a++] = &(main->library);
lb[a++] = &(main->wm);
lb[a++] = &(main->movieclip);
lb[a++]= &(main->mask);
lb[a++] = &(main->mask);
lb[a] = NULL;

View File

@@ -169,7 +169,7 @@ int ED_operator_editmball(struct bContext *C);
int ED_operator_uvedit(struct bContext *C);
int ED_operator_uvmap(struct bContext *C);
int ED_operator_posemode(struct bContext *C);
int ED_operator_mask(struct bContext *C);
int ED_operator_mask(struct bContext *C);
/* default keymaps, bitflags */

View File

@@ -95,7 +95,7 @@ enum {
#define CTX_BMESH 64
#define CTX_NDOF 128
#define CTX_MOVIECLIP 256
#define CTX_MASK 512
#define CTX_MASK 512
/* Standalone call to get the transformation center corresponding to the current situation
* returns 1 if successful, 0 otherwise (usually means there's no selection)

View File

@@ -38,7 +38,7 @@
#include "BKE_mask.h"
#include "DNA_mask_types.h"
#include "DNA_object_types.h" /* SELECT */
#include "DNA_object_types.h" /* SELECT */
#include "ED_mask.h"
@@ -47,7 +47,7 @@
#include "UI_resources.h"
#include "mask_intern.h" // own include
#include "mask_intern.h" /* own include */
typedef struct PixelSpaceContext {
int width, height;
@@ -102,11 +102,13 @@ static void draw_spline_points(MaskShape *shape, MaskSpline *spline, PixelSpaceC
glColor3f(1.0f, 1.0f, 1.0f);
else
glColor3f(1.0f, 1.0f, 0.0f);
} else
}
else {
glColor3f(0.5f, 0.5f, 0.0f);
}
glBegin(GL_POINTS);
glVertex2fv(fp);
glVertex2fv(fp);
glEnd();
fp += 2;
@@ -119,7 +121,7 @@ static void draw_spline_points(MaskShape *shape, MaskSpline *spline, PixelSpaceC
MaskSplinePoint *point = &spline->points[i];
BezTriple *bezt = &point->bezt;
float vert[2], handle[2];
int has_handle = BKE_mask_point_has_handle(point);;
int has_handle = BKE_mask_point_has_handle(point);
copy_v2_v2(vert, bezt->vec[1]);
BKE_mask_point_handle(point, pixelspace->aspx, pixelspace->aspy, handle);
@@ -129,8 +131,8 @@ static void draw_spline_points(MaskShape *shape, MaskSpline *spline, PixelSpaceC
set_spline_color(shape, spline);
glBegin(GL_LINES);
glVertex3fv(vert);
glVertex3fv(handle);
glVertex3fv(vert);
glVertex3fv(handle);
glEnd();
}
@@ -140,11 +142,12 @@ static void draw_spline_points(MaskShape *shape, MaskSpline *spline, PixelSpaceC
glColor3f(1.0f, 1.0f, 1.0f);
else
glColor3f(1.0f, 1.0f, 0.0f);
} else
}
else
glColor3f(0.5f, 0.5f, 0.0f);
glBegin(GL_POINTS);
glVertex3fv(vert);
glVertex3fv(vert);
glEnd();
/* draw handle points */
@@ -154,11 +157,13 @@ static void draw_spline_points(MaskShape *shape, MaskSpline *spline, PixelSpaceC
glColor3f(1.0f, 1.0f, 1.0f);
else
glColor3f(1.0f, 1.0f, 0.0f);
} else
}
else {
glColor3f(0.5f, 0.5f, 0.0f);
}
glBegin(GL_POINTS);
glVertex3fv(handle);
glVertex3fv(handle);
glEnd();
}
}
@@ -176,7 +181,8 @@ static void draw_spline_curve_lines(float *points, int tot_point, int closed)
else
glBegin(GL_LINE_STRIP);
for (i = 0; i < tot_point; i++, fp+=2) {
/* MASK_TODO - vertex arrays */
for (i = 0; i < tot_point; i++, fp += 2) {
glVertex3fv(fp);
}
glEnd();
@@ -210,7 +216,7 @@ static void draw_spline_curve(MaskShape *shape, MaskSpline *spline, PixelSpaceCo
return;
feather_points = BKE_mask_spline_feather_differentiated_points(spline, pixelspace->aspx, pixelspace->aspy,
&tot_feather_point);
&tot_feather_point);
/* draw feather */
if (spline->flag & SELECT)

View File

@@ -47,7 +47,7 @@
#include "RNA_access.h"
#include "mask_intern.h" // own include
#include "mask_intern.h" /* own include */
/********************** generic poll functions *********************/
@@ -204,13 +204,13 @@ void ED_operatormacros_mask(void)
wmOperatorType *ot;
wmOperatorTypeMacro *otmacro;
ot= WM_operatortype_append_macro("MASK_OT_add_vertex_slide", "Add Vertex and Slide", "Add new vertex and slide it", OPTYPE_UNDO|OPTYPE_REGISTER);
ot = WM_operatortype_append_macro("MASK_OT_add_vertex_slide", "Add Vertex and Slide", "Add new vertex and slide it", OPTYPE_UNDO | OPTYPE_REGISTER);
ot->description = "Add new vertex and slide it";
WM_operatortype_macro_define(ot, "MASK_OT_add_vertex");
otmacro = WM_operatortype_macro_define(ot, "TRANSFORM_OT_translate");
RNA_boolean_set(otmacro->ptr, "release_confirm", TRUE);
ot= WM_operatortype_append_macro("MASK_OT_add_feather_vertex_slide", "Add Feather Vertex and Slide", "Add new vertex to feater and slide it", OPTYPE_UNDO|OPTYPE_REGISTER);
ot = WM_operatortype_append_macro("MASK_OT_add_feather_vertex_slide", "Add Feather Vertex and Slide", "Add new vertex to feater and slide it", OPTYPE_UNDO | OPTYPE_REGISTER);
ot->description = "Add new feather vertex and slide it";
WM_operatortype_macro_define(ot, "MASK_OT_add_feather_vertex");
otmacro = WM_operatortype_macro_define(ot, "MASK_OT_slide_point");

View File

@@ -41,7 +41,7 @@
#include "BKE_mask.h"
#include "DNA_mask_types.h"
#include "DNA_object_types.h" /* SELECT */
#include "DNA_object_types.h" /* SELECT */
#include "WM_api.h"
#include "WM_types.h"
@@ -53,7 +53,7 @@
#include "RNA_access.h"
#include "RNA_define.h"
#include "mask_intern.h" // own include
#include "mask_intern.h" /* own include */
/******************** utility functions *********************/
@@ -88,8 +88,11 @@ static void spline_point_select(MaskSplinePoint *point, int action)
}
}
static float projection_on_spline(MaskSpline *spline, MaskSplinePoint *point, float aspx, float aspy, float start_u, float co[2])
static float projection_on_spline(MaskSpline *spline, MaskSplinePoint *point, float aspx, float aspy, float start_u, const float co[2])
{
const float proj_eps = 1e-3;
const float proj_eps_squared = proj_eps * proj_eps;
const int N = 1000;
float u = -1.0f, du = 1.0f / N, u1 = start_u, u2 = start_u;
float ang = -1.0f;
@@ -104,7 +107,7 @@ static float projection_on_spline(MaskSpline *spline, MaskSplinePoint *point, fl
BKE_mask_point_normal(spline, point, aspx, aspy, u1, n1);
sub_v2_v2v2(v1, co, co1);
if (len_v2(v1) > 1e-3) {
if (len_squared_v2(v1) > proj_eps_squared) {
ang1 = angle_v2v2(v1, n1);
if (ang1 > M_PI / 2.0f)
ang1 = M_PI - ang1;
@@ -125,7 +128,7 @@ static float projection_on_spline(MaskSpline *spline, MaskSplinePoint *point, fl
BKE_mask_point_normal(spline, point, aspx, aspy, u2, n2);
sub_v2_v2v2(v2, co, co2);
if (len_v2(v2) > 1e-3) {
if (len_squared_v2(v2) > proj_eps_squared) {
ang2 = angle_v2v2(v2, n2);
if (ang2 > M_PI / 2.0f)
ang2 = M_PI - ang2;
@@ -441,7 +444,7 @@ static int find_nearest_diff_point(bContext *C, Mask *mask, float normal_co[2],
if (feather) {
feather_points = BKE_mask_point_segment_feather_diff(spline, cur_point,
aspx, aspy, &tot_feather_point);
aspx, aspy, &tot_feather_point);
points = feather_points;
tot_point = tot_feather_point;
@@ -563,7 +566,7 @@ static int mask_new_exec(bContext *C, wmOperator *op)
{
SpaceClip *sc = CTX_wm_space_clip(C);
Mask *mask;
char name[MAX_ID_NAME-2];
char name[MAX_ID_NAME - 2];
RNA_string_get(op->ptr, "name", name);
@@ -583,14 +586,14 @@ void MASK_OT_new(wmOperatorType *ot)
ot->idname = "MASK_OT_new";
/* flags */
ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
/* api callbacks */
ot->exec = mask_new_exec;
ot->poll = ED_operator_mask;
/* properties */
RNA_def_string(ot->srna, "name", "", MAX_ID_NAME-2, "Name", "Name of new mask");
RNA_def_string(ot->srna, "name", "", MAX_ID_NAME - 2, "Name", "Name of new mask");
}
/******************** create new shape *********************/
@@ -598,14 +601,14 @@ void MASK_OT_new(wmOperatorType *ot)
static int shape_new_exec(bContext *C, wmOperator *op)
{
Mask *mask = CTX_data_edit_mask(C);
char name[MAX_ID_NAME-2];
char name[MAX_ID_NAME - 2];
RNA_string_get(op->ptr, "name", name);
BKE_mask_shape_new(mask, name);
mask->shapenr = mask->tot_shape - 1;
WM_event_add_notifier(C, NC_MASK|NA_EDITED, mask);
WM_event_add_notifier(C, NC_MASK | NA_EDITED, mask);
return OPERATOR_FINISHED;
}
@@ -622,10 +625,10 @@ void MASK_OT_shape_new(wmOperatorType *ot)
ot->poll = ED_maskediting_poll;
/* flags */
ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
/* properties */
RNA_def_string(ot->srna, "name", "", MAX_ID_NAME-2, "Name", "Name of new shape");
RNA_def_string(ot->srna, "name", "", MAX_ID_NAME - 2, "Name", "Name of new shape");
}
/******************** remove shape *********************/
@@ -638,7 +641,7 @@ static int shape_remove_exec(bContext *C, wmOperator *UNUSED(op))
if (shape) {
BKE_mask_shape_remove(mask, shape);
WM_event_add_notifier(C, NC_MASK|NA_EDITED, mask);
WM_event_add_notifier(C, NC_MASK | NA_EDITED, mask);
}
return OPERATOR_FINISHED;
@@ -656,15 +659,15 @@ void MASK_OT_shape_remove(wmOperatorType *ot)
ot->poll = ED_maskediting_poll;
/* flags */
ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
}
/******************** slide *********************/
#define SLIDE_ACTION_NONE 0
#define SLIDE_ACTION_POINT 1
#define SLIDE_ACTION_HANDLE 2
#define SLIDE_ACTION_FEATHER 3
#define SLIDE_ACTION_NONE 0
#define SLIDE_ACTION_POINT 1
#define SLIDE_ACTION_HANDLE 2
#define SLIDE_ACTION_FEATHER 3
typedef struct SlidePointData {
int action;
@@ -798,7 +801,7 @@ static int slide_point_invoke(bContext *C, wmOperator *op, wmEvent *event)
slidedata->shape->act_spline = slidedata->spline;
slidedata->shape->act_point = slidedata->point;
WM_event_add_notifier(C, NC_MASK|ND_SELECT, mask);
WM_event_add_notifier(C, NC_MASK | ND_SELECT, mask);
return OPERATOR_RUNNING_MODAL;
}
@@ -831,18 +834,18 @@ static int slide_point_modal(bContext *C, wmOperator *op, wmEvent *event)
BezTriple *bezt = &data->point->bezt;
float co[2], dco[2];
switch(event->type) {
switch (event->type) {
case LEFTCTRLKEY:
case RIGHTCTRLKEY:
case LEFTSHIFTKEY:
case RIGHTSHIFTKEY:
if (ELEM(event->type, LEFTCTRLKEY, RIGHTCTRLKEY))
data->curvature_only = event->val==KM_PRESS;
data->curvature_only = event->val == KM_PRESS;
if (ELEM(event->type, LEFTSHIFTKEY, RIGHTSHIFTKEY))
data->accurate = event->val==KM_PRESS;
data->accurate = event->val == KM_PRESS;
/* no break! update CV position */
/* no break! update CV position */
case MOUSEMOVE:
ED_mask_mouse_pos(C, event, co);
@@ -909,16 +912,16 @@ static int slide_point_modal(bContext *C, wmOperator *op, wmEvent *event)
*weight = 0;
}
WM_event_add_notifier(C, NC_MASK|NA_EDITED, data->mask);
WM_event_add_notifier(C, NC_MASK | NA_EDITED, data->mask);
DAG_id_tag_update(&data->mask->id, 0);
break;
case LEFTMOUSE:
if(event->val==KM_RELEASE) {
if (event->val == KM_RELEASE) {
free_slide_point_data(op->customdata);
WM_event_add_notifier(C, NC_MASK|NA_EDITED, data->mask);
WM_event_add_notifier(C, NC_MASK | NA_EDITED, data->mask);
DAG_id_tag_update(&data->mask->id, 0);
return OPERATOR_FINISHED;
@@ -931,7 +934,7 @@ static int slide_point_modal(bContext *C, wmOperator *op, wmEvent *event)
free_slide_point_data(op->customdata);
WM_event_add_notifier(C, NC_MASK|NA_EDITED, data->mask);
WM_event_add_notifier(C, NC_MASK | NA_EDITED, data->mask);
DAG_id_tag_update(&data->mask->id, 0);
return OPERATOR_CANCELLED;
@@ -953,7 +956,7 @@ void MASK_OT_slide_point(wmOperatorType *ot)
ot->poll = ED_maskediting_mask_poll;
/* flags */
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
RNA_def_boolean(ot->srna, "slide_feather", 0, "Slide Feather", "First try to slide slide feather instead of vertex");
}
@@ -968,7 +971,7 @@ static int select_all_exec(bContext *C, wmOperator *op)
toggle_selection_all(mask, action);
mask_flush_selection(mask);
WM_event_add_notifier(C, NC_MASK|ND_SELECT, mask);
WM_event_add_notifier(C, NC_MASK | ND_SELECT, mask);
return OPERATOR_FINISHED;
}
@@ -985,7 +988,7 @@ void MASK_OT_select_all(wmOperatorType *ot)
ot->poll = ED_maskediting_mask_poll;
/* flags */
ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
/* properties */
WM_operator_properties_select_all(ot);
@@ -1024,7 +1027,7 @@ static int select_exec(bContext *C, wmOperator *op)
mask_flush_selection(mask);
WM_event_add_notifier(C, NC_MASK|ND_SELECT, mask);
WM_event_add_notifier(C, NC_MASK | ND_SELECT, mask);
}
else {
MaskSplinePointUW *uw;
@@ -1040,7 +1043,7 @@ static int select_exec(bContext *C, wmOperator *op)
mask_flush_selection(mask);
WM_event_add_notifier(C, NC_MASK|ND_SELECT, mask);
WM_event_add_notifier(C, NC_MASK | ND_SELECT, mask);
}
}
@@ -1075,9 +1078,9 @@ void MASK_OT_select(wmOperatorType *ot)
/* properties */
RNA_def_boolean(ot->srna, "extend", 0,
"Extend", "Extend selection rather than clearing the existing selection");
"Extend", "Extend selection rather than clearing the existing selection");
RNA_def_float_vector(ot->srna, "location", 2, NULL, -FLT_MIN, FLT_MAX,
"Location", "Location of vertex in normalized space", -1.0f, 1.0f);
"Location", "Location of vertex in normalized space", -1.0f, 1.0f);
}
/******************** add vertex *********************/
@@ -1125,7 +1128,8 @@ static void setup_vertex_point(bContext *C, Mask *mask, MaskSpline *spline, Mask
sub_v2_v2(bezt->vec[0], vec);
add_v2_v2(bezt->vec[2], vec);
} else {
}
else {
/* next points are aligning in the direction of previous/next point */
MaskSplinePoint *point;
float v1[2], v2[2], vec[2];
@@ -1134,7 +1138,8 @@ static void setup_vertex_point(bContext *C, Mask *mask, MaskSpline *spline, Mask
if (new_point == spline->points) {
point = new_point + 1;
dir = -1.0f;
} else
}
else
point = new_point - 1;
if (spline->tot_point < 3) {
@@ -1210,7 +1215,7 @@ static int add_vertex_subdivide(bContext *C, Mask *mask, float co[2])
shape->act_point = new_point;
WM_event_add_notifier(C, NC_MASK|NA_EDITED, mask);
WM_event_add_notifier(C, NC_MASK | NA_EDITED, mask);
return TRUE;
}
@@ -1312,7 +1317,7 @@ static int add_vertex_extrude(bContext *C, Mask *mask, float co[2])
shape->act_point = new_point;
setup_vertex_point(C, mask, spline, new_point, co, NULL);
WM_event_add_notifier(C, NC_MASK|NA_EDITED, mask);
WM_event_add_notifier(C, NC_MASK | NA_EDITED, mask);
return TRUE;
}
@@ -1356,11 +1361,11 @@ void MASK_OT_add_vertex(wmOperatorType *ot)
ot->poll = ED_maskediting_mask_poll;
/* flags */
ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
/* properties */
RNA_def_float_vector(ot->srna, "location", 2, NULL, -FLT_MIN, FLT_MAX,
"Location", "Location of vertex in normalized space", -1.0f, 1.0f);
"Location", "Location of vertex in normalized space", -1.0f, 1.0f);
}
/******************** add feather vertex *********************/
@@ -1385,7 +1390,7 @@ static int add_feather_vertex_exec(bContext *C, wmOperator *op)
BKE_mask_point_add_uw(point, u, w);
WM_event_add_notifier(C, NC_MASK|NA_EDITED, mask);
WM_event_add_notifier(C, NC_MASK | NA_EDITED, mask);
return OPERATOR_FINISHED;
}
@@ -1417,11 +1422,11 @@ void MASK_OT_add_feather_vertex(wmOperatorType *ot)
ot->poll = ED_maskediting_mask_poll;
/* flags */
ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
/* properties */
RNA_def_float_vector(ot->srna, "location", 2, NULL, -FLT_MIN, FLT_MAX,
"Location", "Location of vertex in normalized space", -1.0f, 1.0f);
"Location", "Location of vertex in normalized space", -1.0f, 1.0f);
}
/******************** toggle cyclic *********************/
@@ -1444,7 +1449,7 @@ static int cyclic_toggle_exec(bContext *C, wmOperator *UNUSED(op))
shape = shape->next;
}
WM_event_add_notifier(C, NC_MASK|NA_EDITED, mask);
WM_event_add_notifier(C, NC_MASK | NA_EDITED, mask);
return OPERATOR_FINISHED;
}
@@ -1461,7 +1466,7 @@ void MASK_OT_cyclic_toggle(wmOperatorType *ot)
ot->poll = ED_maskediting_mask_poll;
/* flags */
ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
}
/******************** delete *********************/
@@ -1536,7 +1541,7 @@ static int delete_exec(bContext *C, wmOperator *UNUSED(op))
MaskSplinePoint *new_points;
int j;
new_points = MEM_callocN(count*sizeof(MaskSplinePoint), "deleteMaskPoints");
new_points = MEM_callocN(count * sizeof(MaskSplinePoint), "deleteMaskPoints");
for (i = 0, j = 0; i < spline->tot_point; i++) {
MaskSplinePoint *point = &spline->points[i];
@@ -1571,7 +1576,7 @@ static int delete_exec(bContext *C, wmOperator *UNUSED(op))
shape = shape->next;
}
WM_event_add_notifier(C, NC_MASK|NA_EDITED, mask);
WM_event_add_notifier(C, NC_MASK | NA_EDITED, mask);
return OPERATOR_FINISHED;
}
@@ -1589,7 +1594,7 @@ void MASK_OT_delete(wmOperatorType *ot)
ot->poll = ED_maskediting_mask_poll;
/* flags */
ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
}
/******************** set handle type *********************/
@@ -1621,7 +1626,7 @@ static int set_handle_type_exec(bContext *C, wmOperator *op)
shape = shape->next;
}
WM_event_add_notifier(C, NC_MASK|ND_DATA, mask);
WM_event_add_notifier(C, NC_MASK | ND_DATA, mask);
DAG_id_tag_update(&mask->id, 0);
return OPERATOR_FINISHED;
@@ -1629,11 +1634,12 @@ static int set_handle_type_exec(bContext *C, wmOperator *op)
void MASK_OT_handle_type_set(wmOperatorType *ot)
{
static EnumPropertyItem editcurve_handle_type_items[]= {
static EnumPropertyItem editcurve_handle_type_items[] = {
{HD_AUTO, "AUTO", 0, "Auto", ""},
{HD_VECT, "VECTOR", 0, "Vector", ""},
{HD_ALIGN, "ALIGNED", 0, "Aligned", ""},
{0, NULL, 0, NULL, NULL}};
{0, NULL, 0, NULL, NULL}
};
/* identifiers */
ot->name = "Set Handle Type";
@@ -1646,7 +1652,7 @@ void MASK_OT_handle_type_set(wmOperatorType *ot)
ot->poll = ED_maskediting_mask_poll;
/* flags */
ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
/* properties */
ot->prop = RNA_def_enum(ot->srna, "type", editcurve_handle_type_items, 1, "Type", "Spline type");