Cleanup: style, use braces for editor/curve

This commit is contained in:
Campbell Barton 2019-03-26 21:15:47 +11:00
parent 14e013758d
commit fe7812f7c2
5 changed files with 734 additions and 330 deletions

File diff suppressed because it is too large Load Diff

View File

@ -148,7 +148,9 @@ Nurb *ED_curve_add_nurbs_primitive(bContext *C, Object *obedit, float mat[4][4],
bezt->vec[0][1] += -0.5f * grid;
bezt->vec[2][0] += -0.5f * grid;
bezt->vec[2][1] += 0.5f * grid;
for (a = 0; a < 3; a++) mul_m4_v3(mat, bezt->vec[a]);
for (a = 0; a < 3; a++) {
mul_m4_v3(mat, bezt->vec[a]);
}
bezt++;
bezt->h1 = bezt->h2 = HD_ALIGN;
@ -161,7 +163,9 @@ Nurb *ED_curve_add_nurbs_primitive(bContext *C, Object *obedit, float mat[4][4],
bezt->vec[1][1] = 0;
bezt->vec[2][0] = grid * 2;
bezt->vec[2][1] = 0;
for (a = 0; a < 3; a++) mul_m4_v3(mat, bezt->vec[a]);
for (a = 0; a < 3; a++) {
mul_m4_v3(mat, bezt->vec[a]);
}
BKE_nurb_handles_calc(nu);
}
@ -191,7 +195,9 @@ Nurb *ED_curve_add_nurbs_primitive(bContext *C, Object *obedit, float mat[4][4],
bp->vec[0] += 1.5f * grid;
bp = nu->bp;
for (a = 0; a < 4; a++, bp++) mul_m4_v3(mat, bp->vec);
for (a = 0; a < 4; a++, bp++) {
mul_m4_v3(mat, bp->vec);
}
if (cutype == CU_NURBS) {
nu->knotsu = NULL; /* nurbs_knot_calc_u allocates */
@ -225,7 +231,9 @@ Nurb *ED_curve_add_nurbs_primitive(bContext *C, Object *obedit, float mat[4][4],
bp->vec[0] += 2.0f * grid;
bp = nu->bp;
for (a = 0; a < 5; a++, bp++) mul_m4_v3(mat, bp->vec);
for (a = 0; a < 5; a++, bp++) {
mul_m4_v3(mat, bp->vec);
}
if (cutype == CU_NURBS) {
nu->knotsu = NULL; /* nurbs_knot_calc_u allocates */
@ -245,28 +253,36 @@ Nurb *ED_curve_add_nurbs_primitive(bContext *C, Object *obedit, float mat[4][4],
bezt->h1 = bezt->h2 = HD_AUTO;
bezt->f1 = bezt->f2 = bezt->f3 = SELECT;
bezt->vec[1][0] += -grid;
for (a = 0; a < 3; a++) mul_m4_v3(mat, bezt->vec[a]);
for (a = 0; a < 3; a++) {
mul_m4_v3(mat, bezt->vec[a]);
}
bezt->radius = bezt->weight = 1.0;
bezt++;
bezt->h1 = bezt->h2 = HD_AUTO;
bezt->f1 = bezt->f2 = bezt->f3 = SELECT;
bezt->vec[1][1] += grid;
for (a = 0; a < 3; a++) mul_m4_v3(mat, bezt->vec[a]);
for (a = 0; a < 3; a++) {
mul_m4_v3(mat, bezt->vec[a]);
}
bezt->radius = bezt->weight = 1.0;
bezt++;
bezt->h1 = bezt->h2 = HD_AUTO;
bezt->f1 = bezt->f2 = bezt->f3 = SELECT;
bezt->vec[1][0] += grid;
for (a = 0; a < 3; a++) mul_m4_v3(mat, bezt->vec[a]);
for (a = 0; a < 3; a++) {
mul_m4_v3(mat, bezt->vec[a]);
}
bezt->radius = bezt->weight = 1.0;
bezt++;
bezt->h1 = bezt->h2 = HD_AUTO;
bezt->f1 = bezt->f2 = bezt->f3 = SELECT;
bezt->vec[1][1] += -grid;
for (a = 0; a < 3; a++) mul_m4_v3(mat, bezt->vec[a]);
for (a = 0; a < 3; a++) {
mul_m4_v3(mat, bezt->vec[a]);
}
bezt->radius = bezt->weight = 1.0;
BKE_nurb_handles_calc(nu);
@ -289,8 +305,12 @@ Nurb *ED_curve_add_nurbs_primitive(bContext *C, Object *obedit, float mat[4][4],
bp->vec[0] += 0.25f * nurbcircle[a][0] * grid - 0.75f * grid;
bp->vec[2] += 0.25f * nurbcircle[a][1] * grid;
}
if (a & 1) bp->vec[3] = 0.25 * M_SQRT2;
else bp->vec[3] = 1.0;
if (a & 1) {
bp->vec[3] = 0.25 * M_SQRT2;
}
else {
bp->vec[3] = 1.0;
}
mul_m4_v3(mat, bp->vec);
bp->radius = bp->weight = 1.0;
@ -378,8 +398,12 @@ Nurb *ED_curve_add_nurbs_primitive(bContext *C, Object *obedit, float mat[4][4],
bp->f1 = SELECT;
bp->vec[0] += nurbcircle[a][0] * grid;
bp->vec[2] += nurbcircle[a][1] * grid;
if (a & 1) bp->vec[3] = 0.5 * M_SQRT2;
else bp->vec[3] = 1.0;
if (a & 1) {
bp->vec[3] = 0.5 * M_SQRT2;
}
else {
bp->vec[3] = 1.0;
}
mul_m4_v3(mat, bp->vec);
bp++;
}
@ -388,12 +412,15 @@ Nurb *ED_curve_add_nurbs_primitive(bContext *C, Object *obedit, float mat[4][4],
BLI_addtail(editnurb, nu); /* temporal for spin */
if (newob && (U.flag & USER_ADD_VIEWALIGNED) == 0)
if (newob && (U.flag & USER_ADD_VIEWALIGNED) == 0) {
ed_editnurb_spin(umat, NULL, obedit, tmp_vec, tmp_cent);
else if ((U.flag & USER_ADD_VIEWALIGNED))
}
else if ((U.flag & USER_ADD_VIEWALIGNED)) {
ed_editnurb_spin(viewmat, NULL, obedit, zvec, mat[3]);
else
}
else {
ed_editnurb_spin(umat, NULL, obedit, tmp_vec, mat[3]);
}
BKE_nurb_knot_calc_v(nu);
@ -420,12 +447,15 @@ Nurb *ED_curve_add_nurbs_primitive(bContext *C, Object *obedit, float mat[4][4],
BLI_addtail(editnurb, nu); /* temporal for spin */
/* same as above */
if (newob && (U.flag & USER_ADD_VIEWALIGNED) == 0)
if (newob && (U.flag & USER_ADD_VIEWALIGNED) == 0) {
ed_editnurb_spin(umat, NULL, obedit, tmp_vec, tmp_cent);
else if ((U.flag & USER_ADD_VIEWALIGNED))
}
else if ((U.flag & USER_ADD_VIEWALIGNED)) {
ed_editnurb_spin(viewmat, NULL, obedit, zvec, mat[3]);
else
}
else {
ed_editnurb_spin(umat, NULL, obedit, tmp_vec, mat[3]);
}
BLI_remlink(editnurb, nu);
@ -476,8 +506,9 @@ static int curvesurf_prim_add(bContext *C, wmOperator *op, int type, int isSurf)
WM_operator_view3d_unit_defaults(C, op);
if (!ED_object_add_generic_get_opts(C, op, 'Z', loc, rot, &enter_editmode, &local_view_bits, NULL))
if (!ED_object_add_generic_get_opts(C, op, 'Z', loc, rot, &enter_editmode, &local_view_bits, NULL)) {
return OPERATOR_CANCELLED;
}
if (!isSurf) { /* adding curve */
if (obedit == NULL || obedit->type != OB_CURVE) {
@ -490,8 +521,9 @@ static int curvesurf_prim_add(bContext *C, wmOperator *op, int type, int isSurf)
cu = (Curve *)obedit->data;
cu->flag |= CU_DEFORM_FILL;
if (type & CU_PRIM_PATH)
if (type & CU_PRIM_PATH) {
cu->flag |= CU_PATH | CU_3D;
}
}
else {
DEG_id_tag_update(&obedit->id, ID_RECALC_GEOMETRY);

View File

@ -96,18 +96,22 @@ bool select_bpoint(BPoint *bp, bool selstatus, short flag, bool hidden)
static bool swap_selection_beztriple(BezTriple *bezt)
{
if (bezt->f2 & SELECT)
if (bezt->f2 & SELECT) {
return select_beztriple(bezt, DESELECT, SELECT, VISIBLE);
else
}
else {
return select_beztriple(bezt, SELECT, SELECT, VISIBLE);
}
}
static bool swap_selection_bpoint(BPoint *bp)
{
if (bp->f1 & SELECT)
if (bp->f1 & SELECT) {
return select_bpoint(bp, DESELECT, SELECT, VISIBLE);
else
}
else {
return select_bpoint(bp, SELECT, SELECT, VISIBLE);
}
}
bool ED_curve_nurb_select_check(View3D *v3d, Nurb *nu)
@ -337,21 +341,29 @@ static void select_adjacent_cp(
int a;
bool lastsel = false;
if (next == 0) return;
if (next == 0) {
return;
}
for (nu = editnurb->first; nu; nu = nu->next) {
lastsel = false;
if (nu->type == CU_BEZIER) {
a = nu->pntsu;
bezt = nu->bezt;
if (next < 0) bezt = &nu->bezt[a - 1];
if (next < 0) {
bezt = &nu->bezt[a - 1];
}
while (a--) {
if (a - abs(next) < 0) break;
if (a - abs(next) < 0) {
break;
}
if ((lastsel == false) && (bezt->hide == 0) && ((bezt->f2 & SELECT) || (selstatus == DESELECT))) {
bezt += next;
if (!(bezt->f2 & SELECT) || (selstatus == DESELECT)) {
bool sel = select_beztriple(bezt, selstatus, SELECT, VISIBLE);
if (sel && !cont) lastsel = true;
if (sel && !cont) {
lastsel = true;
}
}
}
else {
@ -365,14 +377,20 @@ static void select_adjacent_cp(
else {
a = nu->pntsu * nu->pntsv;
bp = nu->bp;
if (next < 0) bp = &nu->bp[a - 1];
if (next < 0) {
bp = &nu->bp[a - 1];
}
while (a--) {
if (a - abs(next) < 0) break;
if (a - abs(next) < 0) {
break;
}
if ((lastsel == false) && (bp->hide == 0) && ((bp->f1 & SELECT) || (selstatus == DESELECT))) {
bp += next;
if (!(bp->f1 & SELECT) || (selstatus == DESELECT)) {
bool sel = select_bpoint(bp, selstatus, SELECT, VISIBLE);
if (sel && !cont) lastsel = true;
if (sel && !cont) {
lastsel = true;
}
}
}
else {
@ -402,7 +420,9 @@ static void selectend_nurb(Object *obedit, eEndPoint_Types selfirst, bool doswap
Curve *cu;
int a;
if (obedit == NULL) return;
if (obedit == NULL) {
return;
}
cu = (Curve *)obedit->data;
cu->actvert = CU_ACT_NONE;
@ -421,10 +441,16 @@ static void selectend_nurb(Object *obedit, eEndPoint_Types selfirst, bool doswap
while (a--) {
bool sel;
if (doswap) sel = swap_selection_beztriple(bezt);
else sel = select_beztriple(bezt, selstatus, SELECT, VISIBLE);
if (doswap) {
sel = swap_selection_beztriple(bezt);
}
else {
sel = select_beztriple(bezt, selstatus, SELECT, VISIBLE);
}
if (sel == true) break;
if (sel == true) {
break;
}
}
}
else {
@ -441,10 +467,16 @@ static void selectend_nurb(Object *obedit, eEndPoint_Types selfirst, bool doswap
while (a--) {
if (bp->hide == 0) {
bool sel;
if (doswap) sel = swap_selection_bpoint(bp);
else sel = select_bpoint(bp, selstatus, SELECT, VISIBLE);
if (doswap) {
sel = swap_selection_bpoint(bp);
}
else {
sel = select_bpoint(bp, selstatus, SELECT, VISIBLE);
}
if (sel == true) break;
if (sel == true) {
break;
}
}
}
}
@ -722,8 +754,9 @@ static int select_row_exec(bContext *C, wmOperator *UNUSED(op))
BPoint *bp = NULL;
int u = 0, v = 0, a, b;
if (!BKE_curve_nurb_vert_active_get(cu, &nu, (void *)&bp))
if (!BKE_curve_nurb_vert_active_get(cu, &nu, (void *)&bp)) {
return OPERATOR_CANCELLED;
}
if (last == bp) {
direction = 1 - direction;
@ -737,10 +770,14 @@ static int select_row_exec(bContext *C, wmOperator *UNUSED(op))
for (a = 0; a < nu->pntsv; a++) {
for (b = 0; b < nu->pntsu; b++, bp++) {
if (direction) {
if (a == v) select_bpoint(bp, SELECT, SELECT, VISIBLE);
if (a == v) {
select_bpoint(bp, SELECT, SELECT, VISIBLE);
}
}
else {
if (b == u) select_bpoint(bp, SELECT, SELECT, VISIBLE);
if (b == u) {
select_bpoint(bp, SELECT, SELECT, VISIBLE);
}
}
}
}
@ -859,29 +896,39 @@ static void curve_select_more(Object *obedit)
/* upper control point */
if (a % nu->pntsu != 0) {
tempbp = bp - 1;
if (!(tempbp->f1 & SELECT)) select_bpoint(tempbp, SELECT, SELECT, VISIBLE);
if (!(tempbp->f1 & SELECT)) {
select_bpoint(tempbp, SELECT, SELECT, VISIBLE);
}
}
/* left control point. select only if it is not selected already */
if (a - nu->pntsu > 0) {
sel = 0;
tempbp = bp + nu->pntsu;
if (!(tempbp->f1 & SELECT)) sel = select_bpoint(tempbp, SELECT, SELECT, VISIBLE);
if (!(tempbp->f1 & SELECT)) {
sel = select_bpoint(tempbp, SELECT, SELECT, VISIBLE);
}
/* make sure selected bpoint is discarded */
if (sel == 1) BLI_BITMAP_ENABLE(selbpoints, a - nu->pntsu);
if (sel == 1) {
BLI_BITMAP_ENABLE(selbpoints, a - nu->pntsu);
}
}
/* right control point */
if (a + nu->pntsu < nu->pntsu * nu->pntsv) {
tempbp = bp - nu->pntsu;
if (!(tempbp->f1 & SELECT)) select_bpoint(tempbp, SELECT, SELECT, VISIBLE);
if (!(tempbp->f1 & SELECT)) {
select_bpoint(tempbp, SELECT, SELECT, VISIBLE);
}
}
/* lower control point. skip next bp in case selection was made */
if (a % nu->pntsu != 1) {
sel = 0;
tempbp = bp + 1;
if (!(tempbp->f1 & SELECT)) sel = select_bpoint(tempbp, SELECT, SELECT, VISIBLE);
if (!(tempbp->f1 & SELECT)) {
sel = select_bpoint(tempbp, SELECT, SELECT, VISIBLE);
}
if (sel) {
bp++;
a--;
@ -962,7 +1009,9 @@ static void curve_select_less(Object *obedit)
}
else {
bp--;
if (BLI_BITMAP_TEST(selbpoints, a + 1) || ((bp->hide == 0) && (bp->f1 & SELECT))) sel++;
if (BLI_BITMAP_TEST(selbpoints, a + 1) || ((bp->hide == 0) && (bp->f1 & SELECT))) {
sel++;
}
bp++;
}
@ -971,7 +1020,9 @@ static void curve_select_less(Object *obedit)
}
else {
bp++;
if ((bp->hide == 0) && (bp->f1 & SELECT)) sel++;
if ((bp->hide == 0) && (bp->f1 & SELECT)) {
sel++;
}
bp--;
}
@ -980,7 +1031,9 @@ static void curve_select_less(Object *obedit)
}
else {
bp -= nu->pntsu;
if (BLI_BITMAP_TEST(selbpoints, a + nu->pntsu) || ((bp->hide == 0) && (bp->f1 & SELECT))) sel++;
if (BLI_BITMAP_TEST(selbpoints, a + nu->pntsu) || ((bp->hide == 0) && (bp->f1 & SELECT))) {
sel++;
}
bp += nu->pntsu;
}
@ -989,7 +1042,9 @@ static void curve_select_less(Object *obedit)
}
else {
bp += nu->pntsu;
if ((bp->hide == 0) && (bp->f1 & SELECT)) sel++;
if ((bp->hide == 0) && (bp->f1 & SELECT)) {
sel++;
}
bp -= nu->pntsu;
}
@ -1026,7 +1081,9 @@ static void curve_select_less(Object *obedit)
}
else {
bezt--;
if ((bezt->hide == 0) && (bezt->f2 & SELECT)) sel++;
if ((bezt->hide == 0) && (bezt->f2 & SELECT)) {
sel++;
}
bezt++;
}
@ -1035,7 +1092,9 @@ static void curve_select_less(Object *obedit)
}
else {
bezt++;
if ((bezt->hide == 0) && (bezt->f2 & SELECT)) sel++;
if ((bezt->hide == 0) && (bezt->f2 & SELECT)) {
sel++;
}
bezt--;
}
@ -1067,7 +1126,9 @@ static void curve_select_less(Object *obedit)
}
else {
bp--;
if ((bp->hide == 0) && (bp->f1 & SELECT)) sel++;
if ((bp->hide == 0) && (bp->f1 & SELECT)) {
sel++;
}
bp++;
}
@ -1076,7 +1137,9 @@ static void curve_select_less(Object *obedit)
}
else {
bp++;
if ((bp->hide == 0) && (bp->f1 & SELECT)) sel++;
if ((bp->hide == 0) && (bp->f1 & SELECT)) {
sel++;
}
bp--;
}
@ -1274,8 +1337,9 @@ static bool ed_curve_select_nth(Curve *cu, const struct CheckerIntervalParams *p
Nurb *nu = NULL;
void *vert = NULL;
if (!BKE_curve_nurb_vert_active_get(cu, &nu, &vert))
if (!BKE_curve_nurb_vert_active_get(cu, &nu, &vert)) {
return false;
}
if (nu->bezt) {
select_nth_bezt(nu, vert, params);

View File

@ -133,8 +133,9 @@ static void undocurve_from_editcurve(UndoCurve *ucu, Curve *cu, const short shap
}
if (ad) {
if (ad->action)
if (ad->action) {
copy_fcurves(&ucu->fcurves, &ad->action->curves);
}
copy_fcurves(&ucu->drivers, &ad->drivers);
}

View File

@ -79,139 +79,143 @@ static char findaccent(char char1, unsigned int code)
char new = 0;
if (char1 == 'a') {
if (code == '`') new = 224;
else if (code == 39) new = 225;
else if (code == '^') new = 226;
else if (code == '~') new = 227;
else if (code == '"') new = 228;
else if (code == 'o') new = 229;
else if (code == 'e') new = 230;
else if (code == '-') new = 170;
if (code == '`') { new = 224; }
else if (code == 39) { new = 225; }
else if (code == '^') { new = 226; }
else if (code == '~') { new = 227; }
else if (code == '"') { new = 228; }
else if (code == 'o') { new = 229; }
else if (code == 'e') { new = 230; }
else if (code == '-') { new = 170; }
}
else if (char1 == 'c') {
if (code == ',') new = 231;
else if (code == '|') new = 162;
else if (code == 'o') new = 169;
if (code == ',') { new = 231; }
else if (code == '|') { new = 162; }
else if (code == 'o') { new = 169; }
}
else if (char1 == 'e') {
if (code == '`') new = 232;
else if (code == 39) new = 233;
else if (code == '^') new = 234;
else if (code == '"') new = 235;
if (code == '`') { new = 232; }
else if (code == 39) { new = 233; }
else if (code == '^') { new = 234; }
else if (code == '"') { new = 235; }
}
else if (char1 == 'i') {
if (code == '`') new = 236;
else if (code == 39) new = 237;
else if (code == '^') new = 238;
else if (code == '"') new = 239;
if (code == '`') { new = 236; }
else if (code == 39) { new = 237; }
else if (code == '^') { new = 238; }
else if (code == '"') { new = 239; }
}
else if (char1 == 'n') {
if (code == '~') new = 241;
if (code == '~') { new = 241; }
}
else if (char1 == 'o') {
if (code == '`') new = 242;
else if (code == 39) new = 243;
else if (code == '^') new = 244;
else if (code == '~') new = 245;
else if (code == '"') new = 246;
else if (code == '/') new = 248;
else if (code == '-') new = 186;
else if (code == 'e') new = 143;
else if (code == 'c') new = 169;
else if (code == 'r') new = 174;
if (code == '`') { new = 242; }
else if (code == 39) { new = 243; }
else if (code == '^') { new = 244; }
else if (code == '~') { new = 245; }
else if (code == '"') { new = 246; }
else if (code == '/') { new = 248; }
else if (code == '-') { new = 186; }
else if (code == 'e') { new = 143; }
else if (code == 'c') { new = 169; }
else if (code == 'r') { new = 174; }
}
else if (char1 == 'r') {
if (code == 'o') new = 174;
if (code == 'o') { new = 174; }
}
else if (char1 == 's') {
if (code == 's') new = 167;
if (code == 's') { new = 167; }
}
else if (char1 == 't') {
if (code == 'm') new = 153;
if (code == 'm') { new = 153; }
}
else if (char1 == 'u') {
if (code == '`') new = 249;
else if (code == 39) new = 250;
else if (code == '^') new = 251;
else if (code == '"') new = 252;
if (code == '`') { new = 249; }
else if (code == 39) { new = 250; }
else if (code == '^') { new = 251; }
else if (code == '"') { new = 252; }
}
else if (char1 == 'y') {
if (code == 39) new = 253;
else if (code == '"') new = 255;
if (code == 39) { new = 253; }
else if (code == '"') { new = 255; }
}
else if (char1 == 'A') {
if (code == '`') new = 192;
else if (code == 39) new = 193;
else if (code == '^') new = 194;
else if (code == '~') new = 195;
else if (code == '"') new = 196;
else if (code == 'o') new = 197;
else if (code == 'e') new = 198;
if (code == '`') { new = 192; }
else if (code == 39) { new = 193; }
else if (code == '^') { new = 194; }
else if (code == '~') { new = 195; }
else if (code == '"') { new = 196; }
else if (code == 'o') { new = 197; }
else if (code == 'e') { new = 198; }
}
else if (char1 == 'C') {
if (code == ',') new = 199;
if (code == ',') { new = 199; }
}
else if (char1 == 'E') {
if (code == '`') new = 200;
else if (code == 39) new = 201;
else if (code == '^') new = 202;
else if (code == '"') new = 203;
if (code == '`') { new = 200; }
else if (code == 39) { new = 201; }
else if (code == '^') { new = 202; }
else if (code == '"') { new = 203; }
}
else if (char1 == 'I') {
if (code == '`') new = 204;
else if (code == 39) new = 205;
else if (code == '^') new = 206;
else if (code == '"') new = 207;
if (code == '`') { new = 204; }
else if (code == 39) { new = 205; }
else if (code == '^') { new = 206; }
else if (code == '"') { new = 207; }
}
else if (char1 == 'N') {
if (code == '~') new = 209;
if (code == '~') { new = 209; }
}
else if (char1 == 'O') {
if (code == '`') new = 210;
else if (code == 39) new = 211;
else if (code == '^') new = 212;
else if (code == '~') new = 213;
else if (code == '"') new = 214;
else if (code == '/') new = 216;
else if (code == 'e') new = 141;
if (code == '`') { new = 210; }
else if (code == 39) { new = 211; }
else if (code == '^') { new = 212; }
else if (code == '~') { new = 213; }
else if (code == '"') { new = 214; }
else if (code == '/') { new = 216; }
else if (code == 'e') { new = 141; }
}
else if (char1 == 'U') {
if (code == '`') new = 217;
else if (code == 39) new = 218;
else if (code == '^') new = 219;
else if (code == '"') new = 220;
if (code == '`') { new = 217; }
else if (code == 39) { new = 218; }
else if (code == '^') { new = 219; }
else if (code == '"') { new = 220; }
}
else if (char1 == 'Y') {
if (code == 39) new = 221;
if (code == 39) { new = 221; }
}
else if (char1 == '1') {
if (code == '4') new = 188;
if (code == '2') new = 189;
if (code == '4') { new = 188; }
if (code == '2') { new = 189; }
}
else if (char1 == '3') {
if (code == '4') new = 190;
if (code == '4') { new = 190; }
}
else if (char1 == ':') {
if (code == '-') new = 247;
if (code == '-') { new = 247; }
}
else if (char1 == '-') {
if (code == ':') new = 247;
if (code == '|') new = 135;
if (code == '+') new = 177;
if (code == ':') { new = 247; }
if (code == '|') { new = 135; }
if (code == '+') { new = 177; }
}
else if (char1 == '|') {
if (code == '-') new = 135;
if (code == '=') new = 136;
if (code == '-') { new = 135; }
if (code == '=') { new = 136; }
}
else if (char1 == '=') {
if (code == '|') new = 136;
if (code == '|') { new = 136; }
}
else if (char1 == '+') {
if (code == '-') new = 177;
if (code == '-') { new = 177; }
}
if (new) return new;
else return char1;
if (new) {
return new;
}
else {
return char1;
}
}
static int insert_into_textbuf(Object *obedit, uintptr_t c)
@ -222,8 +226,12 @@ static int insert_into_textbuf(Object *obedit, uintptr_t c)
if (ef->len < MAXTEXT - 1) {
int x;
for (x = ef->len; x > ef->pos; x--) ef->textbuf[x] = ef->textbuf[x - 1];
for (x = ef->len; x > ef->pos; x--) ef->textbufinfo[x] = ef->textbufinfo[x - 1];
for (x = ef->len; x > ef->pos; x--) {
ef->textbuf[x] = ef->textbuf[x - 1];
}
for (x = ef->len; x > ef->pos; x--) {
ef->textbufinfo[x] = ef->textbufinfo[x - 1];
}
ef->textbuf[ef->pos] = c;
ef->textbufinfo[ef->pos] = cu->curinfo;
ef->textbufinfo[ef->pos].kern = 0;
@ -235,8 +243,9 @@ static int insert_into_textbuf(Object *obedit, uintptr_t c)
return 1;
}
else
else {
return 0;
}
}
static void text_update_edited(bContext *C, Object *obedit, int mode)
@ -383,8 +392,9 @@ static int paste_from_file_exec(bContext *C, wmOperator *op)
static int paste_from_file_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
{
if (RNA_struct_property_is_set(op->ptr, "filepath"))
if (RNA_struct_property_is_set(op->ptr, "filepath")) {
return paste_from_file_exec(C, op);
}
WM_event_add_fileselect(C, op);
@ -450,8 +460,12 @@ static void txt_add_object(bContext *C, TextLine *firstline, int totline, const
nbytes += nbytes_line + 1;
}
if (cu->str) MEM_freeN(cu->str);
if (cu->strinfo) MEM_freeN(cu->strinfo);
if (cu->str) {
MEM_freeN(cu->str);
}
if (cu->strinfo) {
MEM_freeN(cu->strinfo);
}
cu->str = MEM_mallocN(nbytes + 4, "str");
cu->strinfo = MEM_callocN((nchars + 4) * sizeof(CharInfo), "strinfo");
@ -492,7 +506,9 @@ void ED_text_to_object(bContext *C, Text *text, const bool split_lines)
float offset[3];
int linenum = 0;
if (!text || !text->lines.first) return;
if (!text || !text->lines.first) {
return;
}
if (split_lines) {
for (line = text->lines.first; line; line = line->next) {
@ -507,8 +523,9 @@ void ED_text_to_object(bContext *C, Text *text, const bool split_lines)
offset[1] = -linenum;
offset[2] = 0;
if (rv3d)
if (rv3d) {
mul_mat3_m4_v3(rv3d->viewinv, offset);
}
txt_add_object(C, line, 1, offset);
@ -537,14 +554,20 @@ static int kill_selection(Object *obedit, int ins) /* 1 == new character */
direction = BKE_vfont_select_get(obedit, &selstart, &selend);
if (direction) {
int size;
if (ins) offset = 1;
if (ef->pos >= selstart) ef->pos = selstart + offset;
if (ins) {
offset = 1;
}
if (ef->pos >= selstart) {
ef->pos = selstart + offset;
}
if ((direction == -1) && ins) {
selstart++;
selend++;
}
getfrom = selend + offset;
if (ins == 0) getfrom++;
if (ins == 0) {
getfrom++;
}
size = (ef->len * sizeof(wchar_t)) - (selstart * sizeof(wchar_t)) + (offset * sizeof(wchar_t));
memmove(ef->textbuf + selstart, ef->textbuf + getfrom, size);
memmove(ef->textbufinfo + selstart, ef->textbufinfo + getfrom, ((ef->len - selstart) + offset) * sizeof(CharInfo));
@ -572,14 +595,17 @@ static int set_style(bContext *C, const int style, const bool clear)
EditFont *ef = cu->editfont;
int i, selstart, selend;
if (!BKE_vfont_select_get(obedit, &selstart, &selend))
if (!BKE_vfont_select_get(obedit, &selstart, &selend)) {
return OPERATOR_CANCELLED;
}
for (i = selstart; i <= selend; i++) {
if (clear)
if (clear) {
ef->textbufinfo[i].flag &= ~style;
else
}
else {
ef->textbufinfo[i].flag |= style;
}
}
DEG_id_tag_update(obedit->data, 0);
@ -623,8 +649,9 @@ static int toggle_style_exec(bContext *C, wmOperator *op)
Curve *cu = obedit->data;
int style, clear, selstart, selend;
if (!BKE_vfont_select_get(obedit, &selstart, &selend))
if (!BKE_vfont_select_get(obedit, &selstart, &selend)) {
return OPERATOR_CANCELLED;
}
style = RNA_enum_get(op->ptr, "style");
@ -748,8 +775,9 @@ static int cut_text_exec(bContext *C, wmOperator *UNUSED(op))
Object *obedit = CTX_data_edit_object(C);
int selstart, selend;
if (!BKE_vfont_select_get(obedit, &selstart, &selend))
if (!BKE_vfont_select_get(obedit, &selstart, &selend)) {
return OPERATOR_CANCELLED;
}
copy_selection(obedit);
kill_selection(obedit, 0);
@ -906,8 +934,12 @@ static int move_cursor(bContext *C, int type, const bool select)
switch (type) {
case LINE_BEGIN:
while (ef->pos > 0) {
if (ef->textbuf[ef->pos - 1] == '\n') break;
if (ef->textbufinfo[ef->pos - 1].flag & CU_CHINFO_WRAP) break;
if (ef->textbuf[ef->pos - 1] == '\n') {
break;
}
if (ef->textbufinfo[ef->pos - 1].flag & CU_CHINFO_WRAP) {
break;
}
ef->pos--;
}
cursmove = FO_CURS;
@ -915,9 +947,15 @@ static int move_cursor(bContext *C, int type, const bool select)
case LINE_END:
while (ef->pos < ef->len) {
if (ef->textbuf[ef->pos] == 0) break;
if (ef->textbuf[ef->pos] == '\n') break;
if (ef->textbufinfo[ef->pos].flag & CU_CHINFO_WRAP) break;
if (ef->textbuf[ef->pos] == 0) {
break;
}
if (ef->textbuf[ef->pos] == '\n') {
break;
}
if (ef->textbufinfo[ef->pos].flag & CU_CHINFO_WRAP) {
break;
}
ef->pos++;
}
cursmove = FO_CURS;
@ -969,12 +1007,13 @@ static int move_cursor(bContext *C, int type, const bool select)
break;
}
if (cursmove == -1)
if (cursmove == -1) {
return OPERATOR_CANCELLED;
}
if (ef->pos > ef->len) ef->pos = ef->len;
else if (ef->pos >= MAXTEXT) ef->pos = MAXTEXT;
else if (ef->pos < 0) ef->pos = 0;
if (ef->pos > ef->len) { ef->pos = ef->len; }
else if (ef->pos >= MAXTEXT) { ef->pos = MAXTEXT; }
else if (ef->pos < 0) { ef->pos = 0; }
/* apply vertical cursor motion to position immediately
* otherwise the selection will lag behind */
@ -990,8 +1029,9 @@ static int move_cursor(bContext *C, int type, const bool select)
}
}
if (select)
if (select) {
ef->selend = ef->pos;
}
text_update_edited(C, obedit, cursmove);
@ -1063,8 +1103,9 @@ static int change_spacing_exec(bContext *C, wmOperator *op)
kern += delta;
CLAMP(kern, -20, 20);
if (ef->textbufinfo[ef->pos - 1].kern == kern)
if (ef->textbufinfo[ef->pos - 1].kern == kern) {
return OPERATOR_CANCELLED;
}
ef->textbufinfo[ef->pos - 1].kern = kern;
@ -1100,15 +1141,17 @@ static int change_character_exec(bContext *C, wmOperator *op)
EditFont *ef = cu->editfont;
int character, delta = RNA_int_get(op->ptr, "delta");
if (ef->pos <= 0)
if (ef->pos <= 0) {
return OPERATOR_CANCELLED;
}
character = ef->textbuf[ef->pos - 1];
character += delta;
CLAMP(character, 0, 255);
if (character == ef->textbuf[ef->pos - 1])
if (character == ef->textbuf[ef->pos - 1]) {
return OPERATOR_CANCELLED;
}
ef->textbuf[ef->pos - 1] = character;
@ -1189,27 +1232,38 @@ static int delete_exec(bContext *C, wmOperator *op)
int range[2] = {0, 0};
bool has_select = false;
if (ef->len == 0)
if (ef->len == 0) {
return OPERATOR_CANCELLED;
}
if (BKE_vfont_select_get(obedit, &selstart, &selend)) {
if (type == DEL_NEXT_SEL) type = DEL_SELECTION;
else if (type == DEL_PREV_SEL) type = DEL_SELECTION;
if (type == DEL_NEXT_SEL) {
type = DEL_SELECTION;
}
else if (type == DEL_PREV_SEL) {
type = DEL_SELECTION;
}
has_select = true;
}
else {
if (type == DEL_NEXT_SEL) type = DEL_NEXT_CHAR;
else if (type == DEL_PREV_SEL) type = DEL_PREV_CHAR;
if (type == DEL_NEXT_SEL) {
type = DEL_NEXT_CHAR;
}
else if (type == DEL_PREV_SEL) {
type = DEL_PREV_CHAR;
}
}
switch (type) {
case DEL_SELECTION:
if (!kill_selection(obedit, 0))
if (!kill_selection(obedit, 0)) {
return OPERATOR_CANCELLED;
}
break;
case DEL_PREV_CHAR:
if (ef->pos <= 0)
if (ef->pos <= 0) {
return OPERATOR_CANCELLED;
}
range[0] = ef->pos - 1;
range[1] = ef->pos;
@ -1217,8 +1271,9 @@ static int delete_exec(bContext *C, wmOperator *op)
ef->pos--;
break;
case DEL_NEXT_CHAR:
if (ef->pos >= ef->len)
if (ef->pos >= ef->len) {
return OPERATOR_CANCELLED;
}
range[0] = ef->pos;
range[1] = ef->pos + 1;
@ -1306,8 +1361,9 @@ static int insert_text_exec(bContext *C, wmOperator *op)
wchar_t *inserted_text;
int a, len;
if (!RNA_struct_property_is_set(op->ptr, "text"))
if (!RNA_struct_property_is_set(op->ptr, "text")) {
return OPERATOR_CANCELLED;
}
inserted_utf8 = RNA_string_get_alloc(op->ptr, "text", NULL, 0);
len = BLI_strlen_utf8(inserted_utf8);
@ -1315,8 +1371,9 @@ static int insert_text_exec(bContext *C, wmOperator *op)
inserted_text = MEM_callocN(sizeof(wchar_t) * (len + 1), "FONT_insert_text");
BLI_strncpy_wchar_from_utf8(inserted_text, inserted_utf8, len + 1);
for (a = 0; a < len; a++)
for (a = 0; a < len; a++) {
insert_into_textbuf(obedit, inserted_text[a]);
}
MEM_freeN(inserted_text);
MEM_freeN(inserted_utf8);
@ -1338,26 +1395,31 @@ static int insert_text_invoke(bContext *C, wmOperator *op, const wmEvent *event)
int event_type = event->type, event_val = event->val;
wchar_t inserted_text[2] = {0};
if (RNA_struct_property_is_set(op->ptr, "text"))
if (RNA_struct_property_is_set(op->ptr, "text")) {
return insert_text_exec(C, op);
}
if (RNA_struct_property_is_set(op->ptr, "accent")) {
if (ef->len != 0 && ef->pos > 0)
if (ef->len != 0 && ef->pos > 0) {
accentcode = 1;
}
return OPERATOR_FINISHED;
}
/* tab should exit editmode, but we allow it to be typed using modifier keys */
if (event_type == TABKEY) {
if ((alt || ctrl || shift) == 0)
if ((alt || ctrl || shift) == 0) {
return OPERATOR_PASS_THROUGH;
else
}
else {
ascii = 9;
}
}
if (event_type == BACKSPACEKEY) {
if (alt && ef->len != 0 && ef->pos > 0)
if (alt && ef->len != 0 && ef->pos > 0) {
accentcode = 1;
}
return OPERATOR_PASS_THROUGH;
}
@ -1400,8 +1462,9 @@ static int insert_text_invoke(bContext *C, wmOperator *op, const wmEvent *event)
text_update_edited(C, obedit, FO_EDIT);
}
}
else
else {
return OPERATOR_PASS_THROUGH;
}
if (inserted_text[0]) {
/* store as utf8 in RNA string */
@ -1412,8 +1475,9 @@ static int insert_text_invoke(bContext *C, wmOperator *op, const wmEvent *event)
}
/* reset property? */
if (event_val == 0)
if (event_val == 0) {
accentcode = 0;
}
return OPERATOR_FINISHED;
}
@ -1447,7 +1511,9 @@ static int textbox_add_exec(bContext *C, wmOperator *UNUSED(op))
int i;
if (cu->totbox < 256) {
for (i = cu->totbox; i > cu->actbox; i--) cu->tb[i] = cu->tb[i - 1];
for (i = cu->totbox; i > cu->actbox; i--) {
cu->tb[i] = cu->tb[i - 1];
}
cu->tb[cu->actbox] = cu->tb[cu->actbox - 1];
cu->actbox++;
cu->totbox++;
@ -1490,10 +1556,13 @@ static int textbox_remove_exec(bContext *C, wmOperator *op)
if (cu->totbox > 1) {
for (i = index; i < cu->totbox; i++) cu->tb[i] = cu->tb[i + 1];
for (i = index; i < cu->totbox; i++) {
cu->tb[i] = cu->tb[i + 1];
}
cu->totbox--;
if (cu->actbox >= index)
if (cu->actbox >= index) {
cu->actbox--;
}
}
DEG_id_tag_update(obedit->data, 0);
@ -1544,7 +1613,9 @@ void ED_curve_editfont_make(Object *obedit)
memcpy(ef->textbufinfo, cu->strinfo, ef->len * sizeof(CharInfo));
if (ef->pos > ef->len) ef->pos = ef->len;
if (ef->pos > ef->len) {
ef->pos = ef->len;
}
cu->curinfo = ef->textbufinfo[ef->pos ? ef->pos - 1 : 0];
@ -1575,8 +1646,9 @@ void ED_curve_editfont_load(Object *obedit)
/* Copy the wchar to UTF-8 */
BLI_strncpy_wchar_as_utf8(cu->str, ef->textbuf, cu->len + 1);
if (cu->strinfo)
if (cu->strinfo) {
MEM_freeN(cu->strinfo);
}
cu->strinfo = MEM_callocN((cu->len_wchar + 4) * sizeof(CharInfo), "texteditinfo");
memcpy(cu->strinfo, ef->textbufinfo, cu->len_wchar * sizeof(CharInfo));
@ -1612,8 +1684,9 @@ static int set_case(bContext *C, int ccase)
len = (selend - selstart) + 1;
str = &ef->textbuf[selstart];
while (len) {
if (*str >= 'a' && *str <= 'z')
if (*str >= 'a' && *str <= 'z') {
*str -= 32;
}
len--;
str++;
}
@ -1727,12 +1800,15 @@ static int font_open_exec(bContext *C, wmOperator *op)
font = BKE_vfont_load(bmain, filepath);
if (!font) {
if (op->customdata) MEM_freeN(op->customdata);
if (op->customdata) {
MEM_freeN(op->customdata);
}
return OPERATOR_CANCELLED;
}
if (!op->customdata)
if (!op->customdata) {
font_ui_template_init(C, op);
}
/* hook into UI */
pprop = op->customdata;
@ -1772,8 +1848,9 @@ static int open_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event)
path = (vfont && !BKE_vfont_is_builtin(vfont)) ? vfont->name : U.fontdir;
if (RNA_struct_property_is_set(op->ptr, "filepath"))
if (RNA_struct_property_is_set(op->ptr, "filepath")) {
return font_open_exec(C, op);
}
RNA_string_set(op->ptr, "filepath", path);
WM_event_add_fileselect(C, op);