From 0a364788c1f9007163b7d799d4758555af29b3be Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sat, 20 Sep 2008 13:21:10 +0000 Subject: simple changes for bez point selection. use as a flag incase other flags are stored in bezt->f1,2,3 --- source/blender/blenkernel/intern/curve.c | 22 +++++------ source/blender/include/blendef.h | 4 ++ source/blender/src/drawipo.c | 2 +- source/blender/src/editcurve.c | 10 ++--- source/blender/src/editipo.c | 41 +++++++------------- source/blender/src/editipo_mods.c | 65 +++++++++++++------------------- source/blender/src/retopo.c | 6 +-- 7 files changed, 65 insertions(+), 85 deletions(-) diff --git a/source/blender/blenkernel/intern/curve.c b/source/blender/blenkernel/intern/curve.c index 396bdda9c10..c5ad9e58a4c 100644 --- a/source/blender/blenkernel/intern/curve.c +++ b/source/blender/blenkernel/intern/curve.c @@ -1519,7 +1519,7 @@ void makeBevelList(Object *ob) bevp->y= bp->vec[1]; bevp->z= bp->vec[2]; bevp->alfa= bp->alfa; - bevp->f1= 1; + bevp->f1= SELECT; bevp++; bp++; } @@ -1579,11 +1579,11 @@ void makeBevelList(Object *ob) /* indicate with handlecodes double points */ if(prevbezt->h1==prevbezt->h2) { - if(prevbezt->h1==0 || prevbezt->h1==HD_VECT) bevp->f1= 1; + if(prevbezt->h1==0 || prevbezt->h1==HD_VECT) bevp->f1= SELECT; } else { - if(prevbezt->h1==0 || prevbezt->h1==HD_VECT) bevp->f1= 1; - else if(prevbezt->h2==0 || prevbezt->h2==HD_VECT) bevp->f1= 1; + if(prevbezt->h1==0 || prevbezt->h1==HD_VECT) bevp->f1= SELECT; + else if(prevbezt->h2==0 || prevbezt->h2==HD_VECT) bevp->f1= SELECT; } v1= data; @@ -2385,9 +2385,9 @@ void sethandlesNurb(short code) bezt= nu->bezt; a= nu->pntsu; while(a--) { - if(bezt->f1 || bezt->f3) { - if(bezt->f1) bezt->h1= code; - if(bezt->f3) bezt->h2= code; + if((bezt->f1 & SELECT) || (bezt->f3 & SELECT)) { + if(bezt->f1 & SELECT) bezt->h1= code; + if(bezt->f3 & SELECT) bezt->h2= code; if(bezt->h1!=bezt->h2) { if ELEM(bezt->h1, HD_ALIGN, HD_AUTO) bezt->h1= HD_FREE; if ELEM(bezt->h2, HD_ALIGN, HD_AUTO) bezt->h2= HD_FREE; @@ -2415,8 +2415,8 @@ void sethandlesNurb(short code) bezt= nu->bezt; a= nu->pntsu; while(a--) { - if(bezt->f1 && bezt->h1) ok= 1; - if(bezt->f3 && bezt->h2) ok= 1; + if((bezt->f1 & SELECT) && bezt->h1) ok= 1; + if((bezt->f3 & SELECT) && bezt->h2) ok= 1; if(ok) break; bezt++; } @@ -2432,8 +2432,8 @@ void sethandlesNurb(short code) bezt= nu->bezt; a= nu->pntsu; while(a--) { - if(bezt->f1) bezt->h1= ok; - if(bezt->f3 ) bezt->h2= ok; + if(bezt->f1 & SELECT) bezt->h1= ok; + if(bezt->f3 & SELECT) bezt->h2= ok; bezt++; } diff --git a/source/blender/include/blendef.h b/source/blender/include/blendef.h index 7fd607f6feb..5a883dc9e21 100644 --- a/source/blender/include/blendef.h +++ b/source/blender/include/blendef.h @@ -128,6 +128,10 @@ /* for curve objects in editmode that can have hidden handles - may use for IPO's later */ #define BEZSELECTED_HIDDENHANDLES(bezt) ((G.f & G_HIDDENHANDLES) ? (bezt)->f2 & SELECT : BEZSELECTED(bezt)) +#define BEZ_SEL(bezt) { (bezt)->f1 |= SELECT; (bezt)->f2 |= SELECT; (bezt)->f3 |= SELECT; } +#define BEZ_DESEL(bezt) { (bezt)->f1 &= ~SELECT; (bezt)->f2 &= ~SELECT; (bezt)->f3 &= ~SELECT; } +#define BEZ_INVSEL(bezt) { (bezt)->f1 ^= SELECT; (bezt)->f2 ^= SELECT; (bezt)->f3 ^= SELECT; } + /* psfont */ #define FNT_PDRAW 1 #define FNT_HAEBERLI 2 diff --git a/source/blender/src/drawipo.c b/source/blender/src/drawipo.c index ec6a0f0d75b..1454c0d4f09 100644 --- a/source/blender/src/drawipo.c +++ b/source/blender/src/drawipo.c @@ -1315,7 +1315,7 @@ static void draw_ipohandles(int sel) glVertex2fv(fp+3); glVertex2fv(fp+6); glEnd(); } - else if( (bezt->f1 & 1)==sel) { + else if( (bezt->f1 & SELECT)==sel) { fp= bezt->vec[0]; cpack(col[bezt->h1]); diff --git a/source/blender/src/editcurve.c b/source/blender/src/editcurve.c index 261bb26b0c4..f15ffcdcb58 100644 --- a/source/blender/src/editcurve.c +++ b/source/blender/src/editcurve.c @@ -262,7 +262,7 @@ static void printweightsNurb__doPrint(void *userData, Nurb *nurb, BPoint *bp, Be { char str[30]; - if (bp && (bp->f1&1)) { + if (bp && (bp->f1 & SELECT)) { sprintf(str,"%2.2f", bp->vec[3]); cpack(0x737373); @@ -2916,12 +2916,12 @@ void addvert_Nurb(int mode) if((nu->type & 7)==CU_BEZIER) { /* which bezpoint? */ if(bezt== nu->bezt) { /* first */ - bezt->f1= bezt->f2= bezt->f3= 0; + BEZ_DESEL(bezt); newbezt = (BezTriple*)MEM_callocN((nu->pntsu+1) * sizeof(BezTriple), "addvert_Nurb"); memcpy(newbezt+1, bezt, nu->pntsu*sizeof(BezTriple)); *newbezt= *bezt; - newbezt->f1= newbezt->f2= newbezt->f3= SELECT; + BEZ_SEL(newbezt); if(newbezt->h1 >= 0) newbezt->h2= newbezt->h1; else newbezt->h2= newbezt->h1= HD_ALIGN; /* does this ever happen? */ VECCOPY(temp, bezt->vec[1]); @@ -2930,7 +2930,7 @@ void addvert_Nurb(int mode) bezt= newbezt+1; } else if(bezt== (nu->bezt+nu->pntsu-1)) { /* last */ - bezt->f1= bezt->f2= bezt->f3= 0; + BEZ_DESEL(bezt); newbezt = (BezTriple*)MEM_callocN((nu->pntsu+1) * sizeof(BezTriple), "addvert_Nurb"); memcpy(newbezt, nu->bezt, nu->pntsu*sizeof(BezTriple)); @@ -2939,7 +2939,7 @@ void addvert_Nurb(int mode) MEM_freeN(nu->bezt); nu->bezt= newbezt; newbezt+= nu->pntsu; - newbezt->f1= newbezt->f2= newbezt->f3= SELECT; + BEZ_SEL(newbezt); if(newbezt->h1 >= 0) newbezt->h2= newbezt->h1; else newbezt->h2= newbezt->h1= HD_ALIGN; /* does this ever happen? */ bezt= nu->bezt+nu->pntsu-1; diff --git a/source/blender/src/editipo.c b/source/blender/src/editipo.c index ecb9e845104..45641fc80ca 100644 --- a/source/blender/src/editipo.c +++ b/source/blender/src/editipo.c @@ -1318,14 +1318,10 @@ void update_editipo_flags(void) for(a=0; atotipo; a++) { if(ik->data[a]) { if(ik->flag & 1) { - ik->data[a]->f1 |= SELECT; - ik->data[a]->f2 |= SELECT; - ik->data[a]->f3 |= SELECT; + BEZ_SEL(ik->data[a]); } else { - ik->data[a]->f1 &= ~SELECT; - ik->data[a]->f2 &= ~SELECT; - ik->data[a]->f3 &= ~SELECT; + BEZ_DESEL(ik->data[a]); } } } @@ -1423,7 +1419,7 @@ static short findnearest_ipovert(IpoCurve **icu, BezTriple **bezt) if(ei->disptype!=IPO_DISPBITS && ei->icu->ipo==IPO_BEZ) { /* middle points get an advantage */ temp= -3+abs(mval[0]- sco[0][0])+ abs(mval[1]- sco[0][1]); - if( bezt1->f1 & 1) temp+=5; + if( bezt1->f1 & SELECT) temp+=5; if(tempf1= bezt->f2= bezt->f3= 0; + BEZ_DESEL(bezt); } else { - bezt->f1= bezt->f2= bezt->f3= SELECT; + BEZ_SEL(bezt); } } else if(hand==0) { - if(bezt->f1 & SELECT) bezt->f1= 0; + if(bezt->f1 & SELECT) bezt->f1 &= ~SELECT; else bezt->f1= SELECT; } else { - if(bezt->f3 & SELECT) bezt->f3= 0; + if(bezt->f3 & SELECT) bezt->f3 &= ~SELECT; else bezt->f3= SELECT; } } @@ -1535,7 +1531,7 @@ void mouse_select_ipo(void) if(bezt) { if(hand==1) { - bezt->f1|= SELECT; bezt->f2|= SELECT; bezt->f3|= SELECT; + BEZ_SEL(bezt); } else if(hand==0) bezt->f1 |= SELECT; else bezt->f3 |= SELECT; @@ -2261,7 +2257,7 @@ void add_duplicate_editipo(void) while(b--) { *beztn= *bezt; if(bezt->f2 & SELECT) { - beztn->f1= beztn->f2= beztn->f3= 0; + BEZ_DESEL(beztn); beztn++; *beztn= *bezt; } @@ -3474,14 +3470,10 @@ void make_ipokey(void) if(ik->data[a]) { bezt= ik->data[a]; if(sel) { - bezt->f1 |= SELECT; - bezt->f2 |= SELECT; - bezt->f3 |= SELECT; + BEZ_SEL(bezt); } else { - bezt->f1 &= ~SELECT; - bezt->f2 &= ~SELECT; - bezt->f3 &= ~SELECT; + BEZ_DESEL(bezt); } } } @@ -4645,7 +4637,7 @@ void duplicate_ipo_keys(Ipo *ipo) for (icu=ipo->curve.first; icu; icu=icu->next){ for (i=0; itotvert; i++){ /* If a key is selected */ - if (icu->bezt[i].f2 & 1){ + if (icu->bezt[i].f2 & SELECT){ /* Expand the list */ newbezt = MEM_callocN(sizeof(BezTriple) * (icu->totvert+1), "beztriple"); memcpy (newbezt, icu->bezt, sizeof(BezTriple) * (i+1)); @@ -4655,15 +4647,10 @@ void duplicate_ipo_keys(Ipo *ipo) MEM_freeN (icu->bezt); icu->bezt=newbezt; /* Unselect the current key*/ - icu->bezt[i].f1 &= ~ 1; - icu->bezt[i].f2 &= ~ 1; - icu->bezt[i].f3 &= ~ 1; + BEZ_DESEL(&icu->bezt[i]); i++; /* Select the copied key */ - icu->bezt[i].f1 |= 1; - icu->bezt[i].f2 |= 1; - icu->bezt[i].f3 |= 1; - + BEZ_SEL(&icu->bezt[i]); } } } diff --git a/source/blender/src/editipo_mods.c b/source/blender/src/editipo_mods.c index 24bb111c8d1..94a373d5841 100644 --- a/source/blender/src/editipo_mods.c +++ b/source/blender/src/editipo_mods.c @@ -136,10 +136,10 @@ void swap_selectall_editipo(void) b= ei->icu->totvert; while(b--) { if(totipo_vertsel) { - bezt->f1= bezt->f2= bezt->f3= 0; + BEZ_DESEL(bezt); } else { - bezt->f1= bezt->f2= bezt->f3= SELECT; + BEZ_SEL(bezt); } bezt++; } @@ -228,7 +228,7 @@ void deselectall_editipo(void) bezt= ei->icu->bezt; b= ei->icu->totvert; while(b--) { - bezt->f1= bezt->f2= bezt->f3= 0; + BEZ_SEL(bezt); bezt++; } } @@ -374,18 +374,14 @@ static int selected_bezier_loop(int (*looptest)(EditIpo *), int select_bezier_add(BezTriple *bezt) { /* Select the bezier triple */ - bezt->f1 |= SELECT; - bezt->f2 |= SELECT; - bezt->f3 |= SELECT; + BEZ_SEL(bezt); return 0; } int select_bezier_subtract(BezTriple *bezt) { /* Deselect the bezier triple */ - bezt->f1 &= ~SELECT; - bezt->f2 &= ~SELECT; - bezt->f3 &= ~SELECT; + BEZ_DESEL(bezt); return 0; } @@ -412,9 +408,9 @@ static int set_bezier_auto(BezTriple *bezt) /* is a handle selected? If so * set it to type auto */ - if(bezt->f1 || bezt->f3) { - if(bezt->f1) bezt->h1= 1; /* the secret code for auto */ - if(bezt->f3) bezt->h2= 1; + if((bezt->f1 & SELECT) || (bezt->f3 & SELECT)) { + if(bezt->f1 & SELECT) bezt->h1= 1; /* the secret code for auto */ + if(bezt->f3 & SELECT) bezt->h2= 1; /* if the handles are not of the same type, set them * to type free @@ -435,9 +431,9 @@ static int set_bezier_vector(BezTriple *bezt) /* is a handle selected? If so * set it to type vector */ - if(bezt->f1 || bezt->f3) { - if(bezt->f1) bezt->h1= 2; /* the code for vector */ - if(bezt->f3) bezt->h2= 2; + if((bezt->f1 & SELECT) || (bezt->f3 & SELECT)) { + if(bezt->f1 & SELECT) bezt->h1= 2; /* the code for vector */ + if(bezt->f3 & SELECT) bezt->h2= 2; /* if the handles are not of the same type, set them * to type free @@ -455,8 +451,8 @@ static int bezier_isfree(BezTriple *bezt) /* queries whether the handle should be set * to type 'free' (I think) */ - if(bezt->f1 && bezt->h1) return 1; - if(bezt->f3 && bezt->h2) return 1; + if((bezt->f1 & SELECT) && bezt->h1) return 1; + if((bezt->f3 & SELECT) && bezt->h2) return 1; return 0; } @@ -464,8 +460,8 @@ static int set_bezier_free(BezTriple *bezt) { /* Sets selected bezier handles to type 'free' */ - if(bezt->f1) bezt->h1= HD_FREE; - if(bezt->f3) bezt->h2= HD_FREE; + if(bezt->f1 & SELECT) bezt->h1= HD_FREE; + if(bezt->f3 & SELECT) bezt->h2= HD_FREE; return 0; } @@ -473,8 +469,8 @@ static int set_bezier_align(BezTriple *bezt) { /* Sets selected bezier handles to type 'align' */ - if(bezt->f1) bezt->h1= HD_ALIGN; - if(bezt->f3) bezt->h2= HD_ALIGN; + if(bezt->f1 & SELECT) bezt->h1= HD_ALIGN; + if(bezt->f3 & SELECT) bezt->h2= HD_ALIGN; return 0; } @@ -1032,6 +1028,7 @@ void borderselect_ipo(void) select_proj_ipo(&rectf, val); } else { + int selflag= (val==LEFTMOUSE) ? SELECT : 0; ei= G.sipo->editipo; for(a=0; atotipo; a++, ei++) { @@ -1040,14 +1037,12 @@ void borderselect_ipo(void) b= ei->icu->totvert; bezt= ei->icu->bezt; while(b--) { - int bit= (val==LEFTMOUSE); - if(BLI_in_rctf(&rectf, bezt->vec[0][0], bezt->vec[0][1])) - bezt->f1 = (bezt->f1&~SELECT) | bit; + bezt->f1 = selflag ? (bezt->f1 | SELECT) : (bezt->f1 & ~SELECT); if(BLI_in_rctf(&rectf, bezt->vec[1][0], bezt->vec[1][1])) - bezt->f2 = (bezt->f2&~SELECT) | bit; + bezt->f2 = selflag ? (bezt->f2 | SELECT) : (bezt->f2 & ~SELECT); if(BLI_in_rctf(&rectf, bezt->vec[2][0], bezt->vec[2][1])) - bezt->f3 = (bezt->f3&~SELECT) | bit; + bezt->f3 = selflag ? (bezt->f3 | SELECT) : (bezt->f3 & ~SELECT); bezt++; } @@ -1211,19 +1206,13 @@ void set_ipo_key_selection(Ipo *ipo, int sel) for (icu=ipo->curve.first; icu; icu=icu->next){ for (i=0; itotvert; i++){ if (sel == 2) { - icu->bezt[i].f1^=1; - icu->bezt[i].f2^=1; - icu->bezt[i].f3^=1; + BEZ_INVSEL(&icu->bezt[i]); } else if (sel == 1){ - icu->bezt[i].f1|=1; - icu->bezt[i].f2|=1; - icu->bezt[i].f3|=1; + BEZ_SEL(&icu->bezt[i]); } else{ - icu->bezt[i].f1&=~1; - icu->bezt[i].f2&=~1; - icu->bezt[i].f3&=~1; + BEZ_DESEL(&icu->bezt[i]); } } } @@ -1240,10 +1229,10 @@ int fullselect_ipo_keys(Ipo *ipo) for (icu=ipo->curve.first; icu; icu=icu->next) { for (i=0; itotvert; i++){ - if (icu->bezt[i].f2 & 1){ + if (icu->bezt[i].f2 & SELECT){ tvtot+=3; - icu->bezt[i].f1 |= 1; - icu->bezt[i].f3 |= 1; + icu->bezt[i].f1 |= SELECT; + icu->bezt[i].f3 |= SELECT; } } } diff --git a/source/blender/src/retopo.c b/source/blender/src/retopo.c index 60be622e3ad..47eee872a8a 100644 --- a/source/blender/src/retopo.c +++ b/source/blender/src/retopo.c @@ -826,11 +826,11 @@ void retopo_do_all() } else if(nu->type & CU_BEZIER) { for(i=0; ipntsu; ++i) { - if(nu->bezt[i].f1 & 1) + if(nu->bezt[i].f1 & SELECT) retopo_do_vert(G.vd, nu->bezt[i].vec[0]); - if(nu->bezt[i].f2 & 1) + if(nu->bezt[i].f2 & SELECT) retopo_do_vert(G.vd, nu->bezt[i].vec[1]); - if(nu->bezt[i].f3 & 1) + if(nu->bezt[i].f3 & SELECT) retopo_do_vert(G.vd, nu->bezt[i].vec[2]); } } -- cgit v1.2.3