diff options
author | Tamito Kajiyama <rd6t-kjym@asahi-net.or.jp> | 2012-12-23 04:23:11 +0400 |
---|---|---|
committer | Tamito Kajiyama <rd6t-kjym@asahi-net.or.jp> | 2012-12-23 04:23:11 +0400 |
commit | 40449b1994301081f96d014df626a5375e020c76 (patch) | |
tree | 20220d8b071310fda8a0ab851c7a8f7bcc3ed8a2 /source/blender/editors | |
parent | fa0211df269a3398dd70467982f9e129c79e501b (diff) | |
parent | 3ca00cbf541d0283e91dc454866a5f24576271be (diff) |
Merged changes in the trunk up to revision 53280.
Diffstat (limited to 'source/blender/editors')
75 files changed, 1359 insertions, 863 deletions
diff --git a/source/blender/editors/animation/anim_filter.c b/source/blender/editors/animation/anim_filter.c index 23d35c80409..37fd05f75a5 100644 --- a/source/blender/editors/animation/anim_filter.c +++ b/source/blender/editors/animation/anim_filter.c @@ -293,7 +293,7 @@ static short nlaedit_get_context(bAnimContext *ac, SpaceNla *snla) short ANIM_animdata_context_getdata(bAnimContext *ac) { SpaceLink *sl = ac->sl; - short ok = 0; + short ok = FALSE; /* context depends on editor we are currently in */ if (sl) { @@ -322,10 +322,7 @@ short ANIM_animdata_context_getdata(bAnimContext *ac) } /* check if there's any valid data */ - if (ok && ac->data) - return 1; - else - return 0; + return (ok && ac->data); } /* Obtain current anim-data context from Blender Context info @@ -357,6 +354,7 @@ short ANIM_animdata_get_context(const bContext *C, bAnimContext *ac) ac->regiontype = (ar) ? ar->regiontype : 0; /* get data context info */ + // XXX: if the below fails, try to grab this info from context instead... (to allow for scripting) return ANIM_animdata_context_getdata(ac); } @@ -931,14 +929,14 @@ static short skip_fcurve_selected_data(bDopeSheet *ads, FCurve *fcu, ID *owner_i Editing *ed = BKE_sequencer_editing_get(scene, FALSE); Sequence *seq = NULL; char *seq_name; - + if (ed) { /* get strip name, and check if this strip is selected */ seq_name = BLI_str_quoted_substrN(fcu->rna_path, "sequences_all["); seq = BKE_sequence_get_by_name(ed->seqbasep, seq_name, FALSE); if (seq_name) MEM_freeN(seq_name); } - + /* can only add this F-Curve if it is selected */ if (ads->filterflag & ADS_FILTER_ONLYSEL) { if ((seq == NULL) || (seq->flag & SELECT) == 0) @@ -2214,7 +2212,7 @@ static size_t animdata_filter_dopesheet_scene(bAnimContext *ac, ListBase *anim_d if ((ntree) && !(ads->filterflag & ADS_FILTER_NONTREE)) { tmp_items += animdata_filter_ds_nodetree(ac, &tmp_data, ads, (ID *)sce, ntree, filter_mode); } - + #ifdef WITH_FREESTYLE /* line styles */ if ((ads->filterflag & ADS_FILTER_NOLINESTYLE) == 0) { diff --git a/source/blender/editors/animation/fmodifier_ui.c b/source/blender/editors/animation/fmodifier_ui.c index 79a4c9a769d..6bd774e084a 100644 --- a/source/blender/editors/animation/fmodifier_ui.c +++ b/source/blender/editors/animation/fmodifier_ui.c @@ -151,7 +151,7 @@ static void draw_modifier__generator(uiLayout *layout, ID *id, FModifier *fcm, s } else { /* basic size (just "x") */ - maxXWidth = 15; + maxXWidth = UI_GetStringWidth("x") + 10; } /* draw controls for each coefficient and a + sign at end of row */ @@ -231,16 +231,16 @@ static void draw_modifier__generator(uiLayout *layout, ID *id, FModifier *fcm, s uiDefButF(block, NUM, B_FMODIFIER_REDRAW, "", 0, 0, 100, 20, cp + 1, -UI_FLT_MAX, UI_FLT_MAX, 10, 3, TIP_("Second coefficient")); - /* closing bracket and '+' sign */ + /* closing bracket and multiplication sign */ if ( (i != (data->poly_order - 1)) || ((i == 0) && data->poly_order == 2) ) { - uiDefBut(block, LABEL, 1, ") +", 0, 0, 30, 20, NULL, 0.0, 0.0, 0, 0, ""); + uiDefBut(block, LABEL, 1, ") ×", 0, 0, 40, 20, NULL, 0.0, 0.0, 0, 0, ""); /* set up new row for the next pair of coefficients */ row = uiLayoutRow(layout, TRUE); block = uiLayoutGetBlock(row); } else - uiDefBut(block, LABEL, 1, ")", 0, 0, 20, 20, NULL, 0.0, 0.0, 0, 0, ""); + uiDefBut(block, LABEL, 1, ") ", 0, 0, 40, 20, NULL, 0.0, 0.0, 0, 0, ""); } } break; diff --git a/source/blender/editors/armature/editarmature.c b/source/blender/editors/armature/editarmature.c index ffe58be0139..ae405c0e113 100644 --- a/source/blender/editors/armature/editarmature.c +++ b/source/blender/editors/armature/editarmature.c @@ -2256,6 +2256,7 @@ void undo_push_armature(bContext *C, const char *name) /* *************** Adding stuff in editmode *************** */ /* default bone add, returns it selected, but without tail set */ +/* XXX should be used everywhere, now it mallocs bones still locally in functions */ EditBone *ED_armature_edit_bone_add(bArmature *arm, const char *name) { EditBone *bone = MEM_callocN(sizeof(EditBone), "eBone"); @@ -2265,7 +2266,7 @@ EditBone *ED_armature_edit_bone_add(bArmature *arm, const char *name) BLI_addtail(arm->edbo, bone); - bone->flag |= BONE_TIPSEL; + bone->flag |= BONE_TIPSEL | BONE_RELATIVE_PARENTING; bone->weight = 1.0f; bone->dist = 0.25f; bone->xwidth = 0.1f; @@ -3410,7 +3411,7 @@ static int armature_extrude_exec(bContext *C, wmOperator *op) copy_v3_v3(newbone->tail, newbone->head); newbone->parent = ebone; - newbone->flag = ebone->flag & BONE_TIPSEL; // copies it, in case mirrored bone + newbone->flag = ebone->flag & (BONE_TIPSEL | BONE_RELATIVE_PARENTING); // copies it, in case mirrored bone if (newbone->parent) newbone->flag |= BONE_CONNECTED; } @@ -3419,7 +3420,7 @@ static int armature_extrude_exec(bContext *C, wmOperator *op) copy_v3_v3(newbone->tail, ebone->head); newbone->parent = ebone->parent; - newbone->flag = BONE_TIPSEL; + newbone->flag = BONE_TIPSEL | BONE_RELATIVE_PARENTING; if (newbone->parent && (ebone->flag & BONE_CONNECTED)) { newbone->flag |= BONE_CONNECTED; diff --git a/source/blender/editors/armature/meshlaplacian.c b/source/blender/editors/armature/meshlaplacian.c index 5376c897c29..2848db18d59 100644 --- a/source/blender/editors/armature/meshlaplacian.c +++ b/source/blender/editors/armature/meshlaplacian.c @@ -666,8 +666,8 @@ void heat_bone_weighting(Object *ob, Mesh *me, float (*verts)[3], int numsource, *err_str = NULL; /* count triangles and create mask */ - if ((use_face_sel = ((me->editflag & ME_EDIT_PAINT_MASK) != 0)) || - (use_vert_sel = ((me->editflag & ME_EDIT_VERT_SEL) != 0))) + if ((use_face_sel = ((me->editflag & ME_EDIT_PAINT_FACE_SEL) != 0)) || + (use_vert_sel = ((me->editflag & ME_EDIT_PAINT_VERT_SEL) != 0))) { mask = MEM_callocN(sizeof(int) * me->totvert, "heat_bone_weighting mask"); diff --git a/source/blender/editors/armature/poselib.c b/source/blender/editors/armature/poselib.c index ae3d496b641..04815b9c33c 100644 --- a/source/blender/editors/armature/poselib.c +++ b/source/blender/editors/armature/poselib.c @@ -687,9 +687,6 @@ static int poselib_rename_exec(bContext *C, wmOperator *op) void POSELIB_OT_pose_rename(wmOperatorType *ot) { PropertyRNA *prop; - static EnumPropertyItem prop_poses_dummy_types[] = { - {0, NULL, 0, NULL, NULL} - }; /* identifiers */ ot->name = "PoseLib Rename Pose"; @@ -707,7 +704,7 @@ void POSELIB_OT_pose_rename(wmOperatorType *ot) /* properties */ /* NOTE: name not pose is the operator's "main" property, so that it will get activated in the popup for easy renaming */ ot->prop = RNA_def_string(ot->srna, "name", "RenamedPose", 64, "New Pose Name", "New name for pose"); - prop = RNA_def_enum(ot->srna, "pose", prop_poses_dummy_types, 0, "Pose", "The pose to rename"); + prop = RNA_def_enum(ot->srna, "pose", DummyRNA_NULL_items, 0, "Pose", "The pose to rename"); RNA_def_enum_funcs(prop, poselib_stored_pose_itemf); } diff --git a/source/blender/editors/armature/reeb.c b/source/blender/editors/armature/reeb.c index b1bf13db69b..1b5c550df11 100644 --- a/source/blender/editors/armature/reeb.c +++ b/source/blender/editors/armature/reeb.c @@ -634,7 +634,7 @@ static void mergeArcBuckets(ReebArc *aDst, ReebArc *aSrc, float start, float end if (aDst->bcount > 0 && aSrc->bcount > 0) { int indexDst = 0, indexSrc = 0; - start = MAX3(start, aDst->buckets[0].val, aSrc->buckets[0].val); + start = max_fff(start, aDst->buckets[0].val, aSrc->buckets[0].val); while (indexDst < aDst->bcount && aDst->buckets[indexDst].val < start) { indexDst++; diff --git a/source/blender/editors/curve/editcurve.c b/source/blender/editors/curve/editcurve.c index f4dccd01007..53e610401b7 100644 --- a/source/blender/editors/curve/editcurve.c +++ b/source/blender/editors/curve/editcurve.c @@ -1022,13 +1022,12 @@ static int curve_is_animated(Curve *cu) return ad && (ad->action || ad->drivers.first); } -static void fcurve_path_rename(AnimData *ad, char *orig_rna_path, char *rna_path, ListBase *orig_curves, ListBase *curves) +static void fcurve_path_rename(AnimData *adt, char *orig_rna_path, char *rna_path, ListBase *orig_curves, ListBase *curves) { FCurve *fcu, *nfcu, *nextfcu; int len = strlen(orig_rna_path); - fcu = orig_curves->first; - while (fcu) { + for (fcu = orig_curves->first; fcu; fcu = nextfcu) { nextfcu = fcu->next; if (!strncmp(fcu->rna_path, orig_rna_path, len)) { char *spath, *suffix = fcu->rna_path + len; @@ -1038,26 +1037,25 @@ static void fcurve_path_rename(AnimData *ad, char *orig_rna_path, char *rna_path BLI_addtail(curves, nfcu); if (fcu->grp) { - action_groups_remove_channel(ad->action, fcu); - action_groups_add_channel(ad->action, fcu->grp, nfcu); + action_groups_remove_channel(adt->action, fcu); + action_groups_add_channel(adt->action, fcu->grp, nfcu); } - else if (ad->action && &ad->action->curves == orig_curves) - BLI_remlink(&ad->action->curves, fcu); + else if ((adt->action) && (&adt->action->curves == orig_curves)) + BLI_remlink(&adt->action->curves, fcu); else - BLI_remlink(&ad->drivers, fcu); + BLI_remlink(&adt->drivers, fcu); free_fcurve(fcu); MEM_freeN(spath); } - fcu = nextfcu; } } -static void fcurve_remove(AnimData *ad, ListBase *orig_curves, FCurve *fcu) +static void fcurve_remove(AnimData *adt, ListBase *orig_curves, FCurve *fcu) { - if (orig_curves == &ad->drivers) BLI_remlink(&ad->drivers, fcu); - else action_groups_remove_channel(ad->action, fcu); + if (orig_curves == &adt->drivers) BLI_remlink(&adt->drivers, fcu); + else action_groups_remove_channel(adt->action, fcu); free_fcurve(fcu); } @@ -1073,7 +1071,7 @@ static void curve_rename_fcurves(Curve *cu, ListBase *orig_curves) ListBase curves = {NULL, NULL}; FCurve *fcu, *next; - while (nu) { + for (nu = editnurb->nurbs.first, nu_index = 0; nu != NULL; nu = nu->next, nu_index++) { if (nu->bezt) { BezTriple *bezt = nu->bezt; a = nu->pntsu; @@ -1126,8 +1124,6 @@ static void curve_rename_fcurves(Curve *cu, ListBase *orig_curves) pt_index++; } } - nu = nu->next; - nu_index++; } /* remove paths for removed control points @@ -1144,9 +1140,7 @@ static void curve_rename_fcurves(Curve *cu, ListBase *orig_curves) } } - nu_index = 0; - nu = editnurb->nurbs.first; - while (nu) { + for (nu = editnurb->nurbs.first, nu_index = 0; nu != NULL; nu = nu->next, nu_index++) { keyIndex = NULL; if (nu->pntsu) { if (nu->bezt) keyIndex = getCVKeyIndex(editnurb, &nu->bezt[0]); @@ -1158,9 +1152,6 @@ static void curve_rename_fcurves(Curve *cu, ListBase *orig_curves) BLI_snprintf(orig_rna_path, sizeof(orig_rna_path), "splines[%d]", keyIndex->nu_index); fcurve_path_rename(adt, orig_rna_path, rna_path, orig_curves, &curves); } - - nu_index++; - nu = nu->next; } /* the remainders in orig_curves can be copied back (like follow path) */ diff --git a/source/blender/editors/include/ED_view3d.h b/source/blender/editors/include/ED_view3d.h index 8ca7d5a023e..f7f58a4ee7a 100644 --- a/source/blender/editors/include/ED_view3d.h +++ b/source/blender/editors/include/ED_view3d.h @@ -114,10 +114,11 @@ typedef enum { V3D_PROJ_TEST_NOP = 0, V3D_PROJ_TEST_CLIP_BB = (1 << 0), V3D_PROJ_TEST_CLIP_WIN = (1 << 1), + V3D_PROJ_TEST_CLIP_NEAR = (1 << 2), } eV3DProjTest; -#define V3D_PROJ_TEST_CLIP_DEFAULT (V3D_PROJ_TEST_CLIP_BB | V3D_PROJ_TEST_CLIP_WIN) -#define V3D_PROJ_TEST_ALL (V3D_PROJ_TEST_CLIP_BB | V3D_PROJ_TEST_CLIP_WIN) +#define V3D_PROJ_TEST_CLIP_DEFAULT (V3D_PROJ_TEST_CLIP_BB | V3D_PROJ_TEST_CLIP_WIN | V3D_PROJ_TEST_CLIP_NEAR) +#define V3D_PROJ_TEST_ALL (V3D_PROJ_TEST_CLIP_BB | V3D_PROJ_TEST_CLIP_WIN | V3D_PROJ_TEST_CLIP_NEAR) /* view3d_iterators.c */ diff --git a/source/blender/editors/include/UI_resources.h b/source/blender/editors/include/UI_resources.h index bbc9ca3502d..b32bc1c2815 100644 --- a/source/blender/editors/include/UI_resources.h +++ b/source/blender/editors/include/UI_resources.h @@ -292,6 +292,9 @@ void UI_SetTheme(int spacetype, int regionid); // get current theme struct bTheme *UI_GetTheme(void); +// return shadow width outside menus and popups */ +int UI_ThemeMenuShadowWidth(void); + /* only for buttons in theme editor! */ const unsigned char *UI_ThemeGetColorPtr(struct bTheme *btheme, int spacetype, int colorid); diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c index 807f5279821..25f85883d9c 100644 --- a/source/blender/editors/interface/interface.c +++ b/source/blender/editors/interface/interface.c @@ -1291,7 +1291,7 @@ void ui_delete_linkline(uiLinkLine *line, uiBut *but) void ui_get_but_vectorf(uiBut *but, float vec[3]) { PropertyRNA *prop; - int a, tot; + int a; if (but->editvec) { copy_v3_v3(vec, but->editvec); @@ -1300,18 +1300,25 @@ void ui_get_but_vectorf(uiBut *but, float vec[3]) if (but->rnaprop) { prop = but->rnaprop; - vec[0] = vec[1] = vec[2] = 0.0f; + zero_v3(vec); if (RNA_property_type(prop) == PROP_FLOAT) { - tot = RNA_property_array_length(&but->rnapoin, prop); - tot = min_ii(tot, 3); - - for (a = 0; a < tot; a++) - vec[a] = RNA_property_float_get_index(&but->rnapoin, prop, a); + int tot = RNA_property_array_length(&but->rnapoin, prop); + BLI_assert(tot > 0); + if (tot == 3) { + RNA_property_float_get_array(&but->rnapoin, prop, vec); + } + else { + tot = min_ii(tot, 3); + for (a = 0; a < tot; a++) { + vec[a] = RNA_property_float_get_index(&but->rnapoin, prop, a); + } + } } } else if (but->pointype == UI_BUT_POIN_CHAR) { char *cp = (char *)but->poin; + vec[0] = ((float)cp[0]) / 255.0f; vec[1] = ((float)cp[1]) / 255.0f; vec[2] = ((float)cp[2]) / 255.0f; @@ -1322,8 +1329,8 @@ void ui_get_but_vectorf(uiBut *but, float vec[3]) } else { if (but->editvec == NULL) { - fprintf(stderr, "ui_get_but_vectorf: can't get color, should never happen\n"); - vec[0] = vec[1] = vec[2] = 0.0f; + fprintf(stderr, "%s: can't get color, should never happen\n", __func__); + zero_v3(vec); } } @@ -1349,10 +1356,15 @@ void ui_set_but_vectorf(uiBut *but, const float vec[3]) int a; tot = RNA_property_array_length(&but->rnapoin, prop); - tot = min_ii(tot, 3); - - for (a = 0; a < tot; a++) { - RNA_property_float_set_index(&but->rnapoin, prop, a, vec[a]); + BLI_assert(tot > 0); + if (tot == 3) { + RNA_property_float_set_array(&but->rnapoin, prop, vec); + } + else { + tot = min_ii(tot, 3); + for (a = 0; a < tot; a++) { + RNA_property_float_set_index(&but->rnapoin, prop, a, vec[a]); + } } } } diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c index 86fed3c2760..fed84092133 100644 --- a/source/blender/editors/interface/interface_handlers.c +++ b/source/blender/editors/interface/interface_handlers.c @@ -1208,30 +1208,37 @@ static void ui_but_copy_paste(bContext *C, uiBut *but, uiHandleButtonData *data, /* RGB triple */ else if (but->type == COLOR) { - float rgb[3]; + float rgba[4]; if (but->poin == NULL && but->rnapoin.data == NULL) { /* pass */ } else if (mode == 'c') { - - ui_get_but_vectorf(but, rgb); + if (RNA_property_array_length(&but->rnapoin, but->rnaprop) == 4) + rgba[3] = RNA_property_float_get_index(&but->rnapoin, but->rnaprop, 3); + else + rgba[3] = 1.0f; + + ui_get_but_vectorf(but, rgba); /* convert to linear color to do compatible copy between gamma and non-gamma */ if (but->rnaprop && RNA_property_subtype(but->rnaprop) == PROP_COLOR_GAMMA) - srgb_to_linearrgb_v3_v3(rgb, rgb); + srgb_to_linearrgb_v3_v3(rgba, rgba); - BLI_snprintf(buf, sizeof(buf), "[%f, %f, %f]", rgb[0], rgb[1], rgb[2]); + BLI_snprintf(buf, sizeof(buf), "[%f, %f, %f, %f]", rgba[0], rgba[1], rgba[2], rgba[3]); WM_clipboard_text_set(buf, 0); } else { - if (sscanf(buf, "[%f, %f, %f]", &rgb[0], &rgb[1], &rgb[2]) == 3) { + if (sscanf(buf, "[%f, %f, %f, %f]", &rgba[0], &rgba[1], &rgba[2], &rgba[3]) == 4) { /* assume linear colors in buffer */ if (but->rnaprop && RNA_property_subtype(but->rnaprop) == PROP_COLOR_GAMMA) - linearrgb_to_srgb_v3_v3(rgb, rgb); + linearrgb_to_srgb_v3_v3(rgba, rgba); button_activate_state(C, but, BUTTON_STATE_NUM_EDITING); - ui_set_but_vectorf(but, rgb); + ui_set_but_vectorf(but, rgba); + if (RNA_property_array_length(&but->rnapoin, but->rnaprop) == 4) + RNA_property_float_set_index(&but->rnapoin, but->rnaprop, 3, rgba[3]); + button_activate_state(C, but, BUTTON_STATE_EXIT); } } diff --git a/source/blender/editors/interface/interface_icons.c b/source/blender/editors/interface/interface_icons.c index 2dc77e96678..2928a5607c0 100644 --- a/source/blender/editors/interface/interface_icons.c +++ b/source/blender/editors/interface/interface_icons.c @@ -467,7 +467,10 @@ static void init_brush_icons(void) bbuf = IMB_ibImageFromMemory((unsigned char *)datatoc_ ##name## _png, \ datatoc_ ##name## _png_size, \ IB_rect, NULL, "<brush icon>"); \ - def_internal_icon(bbuf, icon_id, 0, 0, w, ICON_TYPE_BUFFER); \ + if (bbuf) { \ + IMB_premultiply_alpha(bbuf); \ + def_internal_icon(bbuf, icon_id, 0, 0, w, ICON_TYPE_BUFFER); \ + } \ IMB_freeImBuf(bbuf); \ } (void)0 /* end INIT_BRUSH_ICON */ @@ -537,10 +540,14 @@ static void init_internal_icons(void) if (b16buf == NULL) b16buf = IMB_ibImageFromMemory((unsigned char *)datatoc_blender_icons16_png, datatoc_blender_icons16_png_size, IB_rect, NULL, "<blender icons>"); + if (b16buf) + IMB_premultiply_alpha(b16buf); if (b32buf == NULL) b32buf = IMB_ibImageFromMemory((unsigned char *)datatoc_blender_icons32_png, datatoc_blender_icons32_png_size, IB_rect, NULL, "<blender icons>"); + if (b32buf) + IMB_premultiply_alpha(b32buf); if (b16buf && b32buf) { /* free existing texture if any */ @@ -940,8 +947,8 @@ static void icon_draw_texture(float x, float y, float w, float h, int ix, int iy { float x1, x2, y1, y2; - if (rgb) glColor4f(rgb[0], rgb[1], rgb[2], alpha); - else glColor4f(1.0f, 1.0f, 1.0f, alpha); + if (rgb) glColor4f(alpha*rgb[0], rgb[1], rgb[2], alpha); + else glColor4f(alpha, alpha, alpha, alpha); x1 = ix * icongltex.invw; x2 = (ix + ih) * icongltex.invw; @@ -951,6 +958,9 @@ static void icon_draw_texture(float x, float y, float w, float h, int ix, int iy glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, icongltex.id); + /* sharper downscaling, has no effect when scale matches with a mip level */ + glTexEnvf(GL_TEXTURE_FILTER_CONTROL, GL_TEXTURE_LOD_BIAS, -0.5f); + glBegin(GL_QUADS); glTexCoord2f(x1, y1); glVertex2f(x, y); @@ -965,6 +975,8 @@ static void icon_draw_texture(float x, float y, float w, float h, int ix, int iy glVertex2f(x, y + h); glEnd(); + glTexEnvf(GL_TEXTURE_FILTER_CONTROL, GL_TEXTURE_LOD_BIAS, 0.0f); + glBindTexture(GL_TEXTURE_2D, 0); glDisable(GL_TEXTURE_2D); } @@ -986,7 +998,7 @@ static void icon_draw_size(float x, float y, int icon_id, float aspect, float al Icon *icon = NULL; DrawInfo *di = NULL; IconImage *iimg; - float fdraw_size = draw_size; + const float fdraw_size = (float)draw_size; int w, h; icon = BKE_icon_get(icon_id); @@ -1017,8 +1029,11 @@ static void icon_draw_size(float x, float y, int icon_id, float aspect, float al di->data.vector.func((int)x, (int)y, ICON_DEFAULT_HEIGHT, ICON_DEFAULT_HEIGHT, 1.0f); } else if (di->type == ICON_TYPE_TEXTURE) { + /* texture image use premul alpha for correct scaling */ + glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); icon_draw_texture(x, y, (float)w, (float)h, di->data.texture.x, di->data.texture.y, di->data.texture.w, di->data.texture.h, alpha, rgb); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); } else if (di->type == ICON_TYPE_BUFFER) { /* it is a builtin icon */ @@ -1026,7 +1041,9 @@ static void icon_draw_size(float x, float y, int icon_id, float aspect, float al if (!iimg->rect) return; /* something has gone wrong! */ + glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); icon_draw_rect(x, y, w, h, aspect, iimg->w, iimg->h, iimg->rect, alpha, rgb, is_preview); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); } else if (di->type == ICON_TYPE_PREVIEW) { PreviewImage *pi = BKE_previewimg_get((ID *)icon->obj); diff --git a/source/blender/editors/interface/interface_panel.c b/source/blender/editors/interface/interface_panel.c index 5f7ed644894..5b6a609e4d2 100644 --- a/source/blender/editors/interface/interface_panel.c +++ b/source/blender/editors/interface/interface_panel.c @@ -133,8 +133,6 @@ static int panels_re_align(ScrArea *sa, ARegion *ar, Panel **r_pa) if (sbuts->re_align || sbuts->mainbo != sbuts->mainb) return 1; } - else if (ar->regiontype == RGN_TYPE_UI) - return 1; else if (sa->spacetype == SPACE_IMAGE && ar->regiontype == RGN_TYPE_PREVIEW) return 1; else if (sa->spacetype == SPACE_FILE && ar->regiontype == RGN_TYPE_CHANNELS) @@ -917,6 +915,7 @@ void uiEndPanels(const bContext *C, ARegion *ar, int *x, int *y) /* re-align, possibly with animation */ if (panels_re_align(sa, ar, &pa)) { + /* XXX code never gets here... PNL_ANIM_ALIGN flag is never set */ if (pa) panel_activate_state(C, pa, PANEL_STATE_ANIMATION); else @@ -1066,7 +1065,7 @@ static void ui_handle_panel_header(const bContext *C, uiBlock *block, int mx, in ED_region_tag_redraw(ar); } else { /* collapse */ - if(ctrl) + if (ctrl) panels_collapse_all(sa, ar, block->panel); if (block->panel->flag & PNL_CLOSED) { @@ -1150,7 +1149,7 @@ int ui_handler_panel_region(bContext *C, wmEvent *event) } /* XXX hardcoded key warning */ - if (inside && event->val == KM_PRESS) { + if ((inside || inside_header) && event->val == KM_PRESS) { if (event->type == AKEY && !ELEM4(KM_MOD_FIRST, event->ctrl, event->oskey, event->shift, event->alt)) { if (pa->flag & PNL_CLOSEDY) { @@ -1160,6 +1159,7 @@ int ui_handler_panel_region(bContext *C, wmEvent *event) else ui_handle_panel_header(C, block, mx, my, event->type, event->ctrl); + retval = WM_UI_HANDLER_BREAK; continue; } } diff --git a/source/blender/editors/interface/interface_regions.c b/source/blender/editors/interface/interface_regions.c index 60885f311ca..57c126c31c5 100644 --- a/source/blender/editors/interface/interface_regions.c +++ b/source/blender/editors/interface/interface_regions.c @@ -73,8 +73,6 @@ #include "interface_intern.h" #define B_NOP -1 -#define MENU_SHADOW_SIDE 8 -#define MENU_SHADOW_BOTTOM 10 #define MENU_TOP 8 /*********************** Menu Data Parsing ********************* */ @@ -693,16 +691,20 @@ ARegion *ui_tooltip_create(bContext *C, ARegion *butregion, uiBut *but) } /* widget rect, in region coords */ - data->bbox.xmin = MENU_SHADOW_SIDE; - data->bbox.xmax = BLI_rcti_size_x(&rect_i) + MENU_SHADOW_SIDE; - data->bbox.ymin = MENU_SHADOW_BOTTOM; - data->bbox.ymax = BLI_rcti_size_y(&rect_i) + MENU_SHADOW_BOTTOM; - - /* region bigger for shadow */ - ar->winrct.xmin = rect_i.xmin - MENU_SHADOW_SIDE; - ar->winrct.xmax = rect_i.xmax + MENU_SHADOW_SIDE; - ar->winrct.ymin = rect_i.ymin - MENU_SHADOW_BOTTOM; - ar->winrct.ymax = rect_i.ymax + MENU_TOP; + { + int width = UI_ThemeMenuShadowWidth(); + + data->bbox.xmin = width; + data->bbox.xmax = BLI_rcti_size_x(&rect_i) + width; + data->bbox.ymin = width; + data->bbox.ymax = BLI_rcti_size_y(&rect_i) + width; + + /* region bigger for shadow */ + ar->winrct.xmin = rect_i.xmin - width; + ar->winrct.xmax = rect_i.xmax + width; + ar->winrct.ymin = rect_i.ymin - width; + ar->winrct.ymax = rect_i.ymax + MENU_TOP; + } /* adds subwindow */ ED_region_init(C, ar); @@ -1140,16 +1142,17 @@ ARegion *ui_searchbox_create(bContext *C, ARegion *butregion, uiBut *but) /* compute position */ if (but->block->flag & UI_BLOCK_SEARCH_MENU) { + int width = UI_ThemeMenuShadowWidth(); /* this case is search menu inside other menu */ /* we copy region size */ ar->winrct = butregion->winrct; /* widget rect, in region coords */ - data->bbox.xmin = MENU_SHADOW_SIDE; - data->bbox.xmax = BLI_rcti_size_x(&ar->winrct) - MENU_SHADOW_SIDE; - data->bbox.ymin = MENU_SHADOW_BOTTOM; - data->bbox.ymax = BLI_rcti_size_y(&ar->winrct) - MENU_SHADOW_BOTTOM; + data->bbox.xmin = width; + data->bbox.xmax = BLI_rcti_size_x(&ar->winrct) - width; + data->bbox.ymin = width; + data->bbox.ymax = BLI_rcti_size_y(&ar->winrct) - width; /* check if button is lower half */ if (but->rect.ymax < BLI_rctf_cent_y(&but->block->rect)) { @@ -1161,6 +1164,8 @@ ARegion *ui_searchbox_create(bContext *C, ARegion *butregion, uiBut *but) } else { const int searchbox_width = uiSearchBoxWidth(); + const int shadow_width = UI_ThemeMenuShadowWidth(); + rect_fl.xmin = but->rect.xmin - 5; /* align text with button */ rect_fl.xmax = but->rect.xmax + 5; /* symmetrical */ rect_fl.ymax = but->rect.ymin; @@ -1212,15 +1217,15 @@ ARegion *ui_searchbox_create(bContext *C, ARegion *butregion, uiBut *but) } /* widget rect, in region coords */ - data->bbox.xmin = MENU_SHADOW_SIDE; - data->bbox.xmax = BLI_rcti_size_x(&rect_i) + MENU_SHADOW_SIDE; - data->bbox.ymin = MENU_SHADOW_BOTTOM; - data->bbox.ymax = BLI_rcti_size_y(&rect_i) + MENU_SHADOW_BOTTOM; + data->bbox.xmin = shadow_width; + data->bbox.xmax = BLI_rcti_size_x(&rect_i) + shadow_width; + data->bbox.ymin = shadow_width; + data->bbox.ymax = BLI_rcti_size_y(&rect_i) + shadow_width; /* region bigger for shadow */ - ar->winrct.xmin = rect_i.xmin - MENU_SHADOW_SIDE; - ar->winrct.xmax = rect_i.xmax + MENU_SHADOW_SIDE; - ar->winrct.ymin = rect_i.ymin - MENU_SHADOW_BOTTOM; + ar->winrct.xmin = rect_i.xmin - shadow_width; + ar->winrct.xmax = rect_i.xmax + shadow_width; + ar->winrct.ymin = rect_i.ymin - shadow_width; ar->winrct.ymax = rect_i.ymax; } @@ -1522,6 +1527,7 @@ static void ui_block_region_draw(const bContext *C, ARegion *ar) static void ui_popup_block_clip(wmWindow *window, uiBlock *block) { + int width = UI_ThemeMenuShadowWidth(); int winx, winy; if (block->flag & UI_BLOCK_NO_WIN_CLIP) { @@ -1532,13 +1538,13 @@ static void ui_popup_block_clip(wmWindow *window, uiBlock *block) winy = WM_window_pixels_y(window); // wm_window_get_size(window, &winx, &winy); - if (block->rect.xmin < MENU_SHADOW_SIDE) - block->rect.xmin = MENU_SHADOW_SIDE; - if (block->rect.xmax > winx - MENU_SHADOW_SIDE) - block->rect.xmax = winx - MENU_SHADOW_SIDE; + if (block->rect.xmin < width) + block->rect.xmin = width; + if (block->rect.xmax > winx - width) + block->rect.xmax = winx - width; - if (block->rect.ymin < MENU_SHADOW_BOTTOM) - block->rect.ymin = MENU_SHADOW_BOTTOM; + if (block->rect.ymin < width) + block->rect.ymin = width; if (block->rect.ymax > winy - MENU_TOP) block->rect.ymax = winy - MENU_TOP; } @@ -1590,6 +1596,7 @@ uiPopupBlockHandle *ui_popup_block_create(bContext *C, ARegion *butregion, uiBut uiBlock *block; uiPopupBlockHandle *handle; uiSafetyRct *saferct; + int width = UI_ThemeMenuShadowWidth(); /* create handle */ handle = MEM_callocN(sizeof(uiPopupBlockHandle), "uiPopupBlockHandle"); @@ -1658,9 +1665,9 @@ uiPopupBlockHandle *ui_popup_block_create(bContext *C, ARegion *butregion, uiBut /* the block and buttons were positioned in window space as in 2.4x, now * these menu blocks are regions so we bring it back to region space. * additionally we add some padding for the menu shadow or rounded menus */ - ar->winrct.xmin = block->rect.xmin - MENU_SHADOW_SIDE; - ar->winrct.xmax = block->rect.xmax + MENU_SHADOW_SIDE; - ar->winrct.ymin = block->rect.ymin - MENU_SHADOW_BOTTOM; + ar->winrct.xmin = block->rect.xmin - width; + ar->winrct.xmax = block->rect.xmax + width; + ar->winrct.ymin = block->rect.ymin - width; ar->winrct.ymax = block->rect.ymax + MENU_TOP; ui_block_translate(block, -ar->winrct.xmin, -ar->winrct.ymin); diff --git a/source/blender/editors/interface/interface_widgets.c b/source/blender/editors/interface/interface_widgets.c index e5b26148be5..4687647223a 100644 --- a/source/blender/editors/interface/interface_widgets.c +++ b/source/blender/editors/interface/interface_widgets.c @@ -261,7 +261,7 @@ static int round_box_shadow_edges(float (*vert)[2], const rcti *rect, float rad, if (2.0f * rad > BLI_rcti_size_y(rect)) rad = 0.5f * BLI_rcti_size_y(rect); - + minx = rect->xmin - step; miny = rect->ymin - step; maxx = rect->xmax + step; @@ -871,7 +871,7 @@ static void widget_draw_icon(uiBut *but, BIFIconID icon, float alpha, const rcti aspect = but->block->aspect / UI_DPI_FAC; height = ICON_DEFAULT_HEIGHT / aspect; - + /* calculate blend color */ if (ELEM4(but->type, TOG, ROW, TOGN, LISTROW)) { if (but->flag & UI_SELECT) {} @@ -915,6 +915,12 @@ static void widget_draw_icon(uiBut *but, BIFIconID icon, float alpha, const rcti ys = (rect->ymin + rect->ymax - height) / 2.0f; } + /* force positions to integers, for zoom levels near 1. draws icons crisp. */ + if (aspect > 0.95f && aspect < 1.05f) { + xs = (int)(xs + 0.1f); + ys = (int)(ys + 0.1f); + } + /* to indicate draggable */ if (but->dragpoin && (but->flag & UI_ACTIVE)) { float rgb[3] = {1.25f, 1.25f, 1.25f}; @@ -1793,13 +1799,19 @@ static void widget_state_menu_item(uiWidgetType *wt, int state) /* ************ menu backdrop ************************* */ /* outside of rect, rad to left/bottom/right */ -static void widget_softshadow(const rcti *rect, int roundboxalign, const float radin, const float radout) +static void widget_softshadow(const rcti *rect, int roundboxalign, const float radin) { + bTheme *btheme = UI_GetTheme(); uiWidgetBase wtb; rcti rect1 = *rect; - float alpha, alphastep; + float alphastep; int step, totvert; - float quad_strip[WIDGET_SIZE_MAX * 2][2]; + float quad_strip[WIDGET_SIZE_MAX * 2 + 2][2]; + const float radout = UI_ThemeMenuShadowWidth(); + + /* disabled shadow */ + if (radout == 0.0f) + return; /* prevent tooltips to not show round shadow */ if (radout > 0.2f * BLI_rcti_size_y(&rect1)) @@ -1810,24 +1822,22 @@ static void widget_softshadow(const rcti *rect, int roundboxalign, const float r /* inner part */ totvert = round_box_shadow_edges(wtb.inner_v, &rect1, radin, roundboxalign & (UI_CNR_BOTTOM_RIGHT | UI_CNR_BOTTOM_LEFT), 0.0f); - /* inverse linear shadow alpha */ - alpha = 0.15f; - if (U.pixelsize > 1.0f) - alphastep = 0.78f; - else - alphastep = 0.67f; + /* we draw a number of increasing size alpha quad strips */ + alphastep = 3.0f * btheme->tui.menu_shadow_fac / radout; glEnableClientState(GL_VERTEX_ARRAY); - for (step = 1; step <= radout; step++, alpha *= alphastep) { + for (step = 1; step <= (int)radout; step++) { + float expfac = sqrt(step / radout); + round_box_shadow_edges(wtb.outer_v, &rect1, radin, UI_CNR_ALL, (float)step); - glColor4f(0.0f, 0.0f, 0.0f, alpha); + glColor4f(0.0f, 0.0f, 0.0f, alphastep * (1.0f - expfac)); - widget_verts_to_quad_strip_open(&wtb, totvert, quad_strip); + widget_verts_to_quad_strip(&wtb, totvert, quad_strip); glVertexPointer(2, GL_FLOAT, 0, quad_strip); - glDrawArrays(GL_QUAD_STRIP, 0, totvert * 2); + glDrawArrays(GL_QUAD_STRIP, 0, totvert * 2 + 2); } glDisableClientState(GL_VERTEX_ARRAY); @@ -1855,7 +1865,7 @@ static void widget_menu_back(uiWidgetColors *wcol, rcti *rect, int flag, int dir } glEnable(GL_BLEND); - widget_softshadow(rect, roundboxalign, 0.25f * U.widget_unit, 0.4f * U.widget_unit); + widget_softshadow(rect, roundboxalign, 0.25f * U.widget_unit); round_box_edges(&wtb, roundboxalign, rect, 0.25f * U.widget_unit); wtb.emboss = 0; @@ -3403,7 +3413,7 @@ void ui_draw_search_back(uiStyle *UNUSED(style), uiBlock *block, rcti *rect) uiWidgetType *wt = widget_type(UI_WTYPE_BOX); glEnable(GL_BLEND); - widget_softshadow(rect, UI_CNR_ALL, 0.25f * U.widget_unit, 0.4f * U.widget_unit); + widget_softshadow(rect, UI_CNR_ALL, 0.25f * U.widget_unit); glDisable(GL_BLEND); wt->state(wt, 0); diff --git a/source/blender/editors/interface/resources.c b/source/blender/editors/interface/resources.c index 20d7277a94d..fd84c1fd4c4 100644 --- a/source/blender/editors/interface/resources.c +++ b/source/blender/editors/interface/resources.c @@ -683,6 +683,9 @@ void ui_theme_init_default(void) rgba_char_args_set(btheme->tui.yaxis, 0, 220, 0, 255); rgba_char_args_set(btheme->tui.zaxis, 0, 0, 220, 255); + btheme->tui.menu_shadow_fac = 0.5f; + btheme->tui.menu_shadow_width = 12; + /* Bone Color Sets */ ui_theme_init_boneColorSets(btheme); @@ -1269,6 +1272,12 @@ void UI_ThemeClearColor(int colorid) glClearColor(col[0], col[1], col[2], 0.0); } +int UI_ThemeMenuShadowWidth(void) +{ + bTheme *btheme = UI_GetTheme(); + return (int)(btheme->tui.menu_shadow_width * UI_DPI_FAC); +} + void UI_make_axis_color(const unsigned char src_col[3], unsigned char dst_col[3], const char axis) { unsigned char col[3]; @@ -2086,6 +2095,17 @@ void init_userdef_do_versions(void) } } + if (bmain->versionfile < 266) { + bTheme *btheme; + + for (btheme = U.themes.first; btheme; btheme = btheme->next) { + /* rna definition limits fac to 0.01 */ + if (btheme->tui.menu_shadow_fac == 0.0f) { + btheme->tui.menu_shadow_fac = 0.5f; + btheme->tui.menu_shadow_width = 12; + } + } + } if (U.pixelsize == 0.0f) U.pixelsize = 1.0f; diff --git a/source/blender/editors/interface/view2d.c b/source/blender/editors/interface/view2d.c index 306b328b431..190d90b3c36 100644 --- a/source/blender/editors/interface/view2d.c +++ b/source/blender/editors/interface/view2d.c @@ -1151,7 +1151,7 @@ View2DGrid *UI_view2d_grid_calc(Scene *scene, View2D *v2d, pixels = (float)BLI_rcti_size_x(&v2d->mask); if (pixels != 0.0f) { - grid->dx = (U.v2d_min_gridsize * U.pixelsize * space) / (seconddiv * pixels); + grid->dx = (U.v2d_min_gridsize * UI_DPI_FAC * space) / (seconddiv * pixels); step_to_grid(&grid->dx, &grid->powerx, xunits); grid->dx *= seconddiv; } @@ -1168,7 +1168,7 @@ View2DGrid *UI_view2d_grid_calc(Scene *scene, View2D *v2d, space = BLI_rctf_size_y(&v2d->cur); pixels = (float)winy; - grid->dy = U.v2d_min_gridsize * U.pixelsize * space / pixels; + grid->dy = U.v2d_min_gridsize * UI_DPI_FAC * space / pixels; step_to_grid(&grid->dy, &grid->powery, yunits); if (yclamp == V2D_GRID_CLAMP) { @@ -1213,7 +1213,7 @@ void UI_view2d_grid_draw(View2D *v2d, View2DGrid *grid, int flag) vec2[1] = v2d->cur.ymax; /* minor gridlines */ - step = (BLI_rcti_size_x(&v2d->mask) + 1) / (U.v2d_min_gridsize * U.pixelsize); + step = (BLI_rcti_size_x(&v2d->mask) + 1) / (U.v2d_min_gridsize * UI_DPI_FAC); UI_ThemeColor(TH_GRID); for (a = 0; a < step; a++) { @@ -1247,7 +1247,7 @@ void UI_view2d_grid_draw(View2D *v2d, View2DGrid *grid, int flag) vec1[0] = grid->startx; vec2[0] = v2d->cur.xmax; - step = (BLI_rcti_size_y(&v2d->mask) + 1) / (U.v2d_min_gridsize * U.pixelsize); + step = (BLI_rcti_size_y(&v2d->mask) + 1) / (U.v2d_min_gridsize * UI_DPI_FAC); UI_ThemeColor(TH_GRID); for (a = 0; a <= step; a++) { diff --git a/source/blender/editors/interface/view2d_ops.c b/source/blender/editors/interface/view2d_ops.c index 48a1f8bf0f3..006644bf366 100644 --- a/source/blender/editors/interface/view2d_ops.c +++ b/source/blender/editors/interface/view2d_ops.c @@ -1015,12 +1015,12 @@ static int view_zoomdrag_modal(bContext *C, wmOperator *op, wmEvent *event) /* x-axis transform */ dist = BLI_rcti_size_x(&v2d->mask) / 2.0f; - dx = 1.0f - (fabsf(vzd->lastx - dist) + 2.0f) / (fabsf(event->x - dist) + 2.0f); + dx = 1.0f - (fabsf(vzd->lastx - vzd->ar->winrct.xmin - dist) + 2.0f) / (fabsf(event->mval[0] - dist) + 2.0f); dx *= 0.5f * BLI_rctf_size_x(&v2d->cur); /* y-axis transform */ dist = BLI_rcti_size_y(&v2d->mask) / 2.0f; - dy = 1.0f - (fabsf(vzd->lasty - dist) + 2.0f) / (fabsf(event->y - dist) + 2.0f); + dy = 1.0f - (fabsf(vzd->lasty - vzd->ar->winrct.ymin - dist) + 2.0f) / (fabsf(event->mval[1] - dist) + 2.0f); dy *= 0.5f * BLI_rctf_size_y(&v2d->cur); } else { @@ -1034,18 +1034,7 @@ static int view_zoomdrag_modal(bContext *C, wmOperator *op, wmEvent *event) /* y-axis transform */ fac = 0.01f * (event->y - vzd->lasty); dy = fac * BLI_rctf_size_y(&v2d->cur); -#if 0 - /* continuous zoom shouldn't move that fast... */ - if (U.viewzoom == USER_ZOOM_CONT) { // XXX store this setting as RNA prop? - double time = PIL_check_seconds_timer(); - float time_step = (float)(time - vzd->timer_lastdraw); - - dx /= (0.1f / time_step); - dy /= (0.1f / time_step); - - vzd->timer_lastdraw = time; - } -#endif + } /* set transform amount, and add current deltas to stored total delta (for redo) */ diff --git a/source/blender/editors/mesh/editface.c b/source/blender/editors/mesh/editface.c index 05f2269c359..29139c5154f 100644 --- a/source/blender/editors/mesh/editface.c +++ b/source/blender/editors/mesh/editface.c @@ -27,12 +27,9 @@ * \ingroup edmesh */ -#include <math.h> -#include <string.h> #include "MEM_guardedalloc.h" -#include "BLI_utildefines.h" #include "BLI_blenlib.h" #include "BLI_math.h" #include "BLI_edgehash.h" @@ -41,9 +38,7 @@ #include "IMB_imbuf.h" #include "DNA_mesh_types.h" -#include "DNA_meshdata_types.h" #include "DNA_object_types.h" -#include "DNA_scene_types.h" #include "BKE_DerivedMesh.h" #include "BKE_global.h" @@ -61,7 +56,6 @@ #include "WM_types.h" /* own include */ -#include "mesh_intern.h" /* copy the face flags, most importantly selection from the mesh to the final derived mesh, * use in object mode when selecting faces (while painting) */ diff --git a/source/blender/editors/mesh/editmesh_add.c b/source/blender/editors/mesh/editmesh_add.c index adcec5699a9..a356f9fca7f 100644 --- a/source/blender/editors/mesh/editmesh_add.c +++ b/source/blender/editors/mesh/editmesh_add.c @@ -29,7 +29,6 @@ * \ingroup edmesh */ -#include "DNA_mesh_types.h" #include "DNA_object_types.h" #include "DNA_scene_types.h" @@ -39,7 +38,6 @@ #include "BLI_math.h" #include "BKE_context.h" -#include "BKE_depsgraph.h" #include "BKE_library.h" #include "BKE_tessmesh.h" diff --git a/source/blender/editors/mesh/editmesh_knife.c b/source/blender/editors/mesh/editmesh_knife.c index 31d5eed83dc..c8a1264fd10 100644 --- a/source/blender/editors/mesh/editmesh_knife.c +++ b/source/blender/editors/mesh/editmesh_knife.c @@ -38,14 +38,11 @@ #include "BLI_blenlib.h" #include "BLI_array.h" #include "BLI_math.h" -#include "BLI_rand.h" #include "BLI_smallhash.h" -#include "BLI_scanfill.h" #include "BLI_memarena.h" #include "BKE_DerivedMesh.h" #include "BKE_context.h" -#include "BKE_depsgraph.h" #include "BIF_gl.h" #include "BIF_glutil.h" /* for paint cursor */ @@ -59,7 +56,6 @@ #include "WM_types.h" #include "DNA_scene_types.h" -#include "DNA_mesh_types.h" #include "DNA_object_types.h" #include "BKE_tessmesh.h" #include "UI_resources.h" @@ -1150,7 +1146,7 @@ static float len_v3_tri_side_max(const float v1[3], const float v2[3], const flo const float s2 = len_squared_v3v3(v2, v3); const float s3 = len_squared_v3v3(v3, v1); - return sqrtf(MAX3(s1, s2, s3)); + return sqrtf(max_fff(s1, s2, s3)); } static BMEdgeHit *knife_edge_tri_isect(KnifeTool_OpData *kcd, BMBVHTree *bmtree, diff --git a/source/blender/editors/mesh/editmesh_loopcut.c b/source/blender/editors/mesh/editmesh_loopcut.c index 7721f878ce6..5f923dd65c6 100644 --- a/source/blender/editors/mesh/editmesh_loopcut.c +++ b/source/blender/editors/mesh/editmesh_loopcut.c @@ -28,46 +28,21 @@ * \ingroup edmesh */ -#include <float.h> -#ifdef _MSC_VER -# define _USE_MATH_DEFINES -#endif -#include <math.h> -#include <string.h> -#include <ctype.h> -#include <stdio.h> - -#include "DNA_ID.h" #include "DNA_object_types.h" -#include "DNA_mesh_types.h" -#include "DNA_screen_types.h" #include "DNA_scene_types.h" -#include "DNA_userdef_types.h" #include "MEM_guardedalloc.h" -#include "PIL_time.h" - #include "BLI_array.h" #include "BLI_blenlib.h" #include "BLI_math.h" -#include "BLI_dynstr.h" /*for WM_operator_pystring */ -#include "BLI_utildefines.h" -#include "BKE_blender.h" #include "BKE_context.h" -#include "BKE_depsgraph.h" -#include "BKE_mesh.h" #include "BKE_modifier.h" #include "BKE_report.h" -#include "BKE_scene.h" #include "BKE_tessmesh.h" -#include "BKE_depsgraph.h" #include "BIF_gl.h" -#include "BIF_glutil.h" /* for paint cursor */ - -#include "IMB_imbuf_types.h" #include "ED_screen.h" #include "ED_space_api.h" @@ -78,8 +53,6 @@ #include "RNA_access.h" #include "RNA_define.h" -#include "UI_interface.h" - #include "WM_api.h" #include "WM_types.h" @@ -187,7 +160,6 @@ static void edgering_sel(RingSelOpData *lcd, int previewlines, int select) BMWalker walker; float (*edges)[2][3] = NULL; BLI_array_declare(edges); - float co[2][3]; int i, tot = 0; memset(v, 0, sizeof(v)); @@ -245,16 +217,9 @@ static void edgering_sel(RingSelOpData *lcd, int previewlines, int select) BLI_array_grow_items(edges, previewlines); for (i = 1; i <= previewlines; i++) { - co[0][0] = (v[0][1]->co[0] - v[0][0]->co[0]) * (i / ((float)previewlines + 1)) + v[0][0]->co[0]; - co[0][1] = (v[0][1]->co[1] - v[0][0]->co[1]) * (i / ((float)previewlines + 1)) + v[0][0]->co[1]; - co[0][2] = (v[0][1]->co[2] - v[0][0]->co[2]) * (i / ((float)previewlines + 1)) + v[0][0]->co[2]; - - co[1][0] = (v[1][1]->co[0] - v[1][0]->co[0]) * (i / ((float)previewlines + 1)) + v[1][0]->co[0]; - co[1][1] = (v[1][1]->co[1] - v[1][0]->co[1]) * (i / ((float)previewlines + 1)) + v[1][0]->co[1]; - co[1][2] = (v[1][1]->co[2] - v[1][0]->co[2]) * (i / ((float)previewlines + 1)) + v[1][0]->co[2]; - - copy_v3_v3(edges[tot][0], co[0]); - copy_v3_v3(edges[tot][1], co[1]); + const float fac = (i / ((float)previewlines + 1)); + interp_v3_v3v3(edges[tot][0], v[0][0]->co, v[0][1]->co, fac); + interp_v3_v3v3(edges[tot][1], v[1][0]->co, v[1][1]->co, fac); tot++; } } @@ -274,19 +239,14 @@ static void edgering_sel(RingSelOpData *lcd, int previewlines, int select) BLI_array_grow_items(edges, previewlines); for (i = 1; i <= previewlines; i++) { - if (!v[0][0] || !v[0][1] || !v[1][0] || !v[1][1]) + const float fac = (i / ((float)previewlines + 1)); + + if (!v[0][0] || !v[0][1] || !v[1][0] || !v[1][1]) { continue; - - co[0][0] = (v[0][1]->co[0] - v[0][0]->co[0]) * (i / ((float)previewlines + 1)) + v[0][0]->co[0]; - co[0][1] = (v[0][1]->co[1] - v[0][0]->co[1]) * (i / ((float)previewlines + 1)) + v[0][0]->co[1]; - co[0][2] = (v[0][1]->co[2] - v[0][0]->co[2]) * (i / ((float)previewlines + 1)) + v[0][0]->co[2]; + } - co[1][0] = (v[1][1]->co[0] - v[1][0]->co[0]) * (i / ((float)previewlines + 1)) + v[1][0]->co[0]; - co[1][1] = (v[1][1]->co[1] - v[1][0]->co[1]) * (i / ((float)previewlines + 1)) + v[1][0]->co[1]; - co[1][2] = (v[1][1]->co[2] - v[1][0]->co[2]) * (i / ((float)previewlines + 1)) + v[1][0]->co[2]; - - copy_v3_v3(edges[tot][0], co[0]); - copy_v3_v3(edges[tot][1], co[1]); + interp_v3_v3v3(edges[tot][0], v[0][0]->co, v[0][1]->co, fac); + interp_v3_v3v3(edges[tot][1], v[1][0]->co, v[1][1]->co, fac); tot++; } } diff --git a/source/blender/editors/mesh/editmesh_rip.c b/source/blender/editors/mesh/editmesh_rip.c index 4909561f677..6cbf5e88cee 100644 --- a/source/blender/editors/mesh/editmesh_rip.c +++ b/source/blender/editors/mesh/editmesh_rip.c @@ -31,7 +31,6 @@ #include "MEM_guardedalloc.h" -#include "DNA_scene_types.h" #include "DNA_object_types.h" #include "RNA_define.h" @@ -41,11 +40,9 @@ #include "BLI_array.h" #include "BKE_context.h" -#include "BKE_object.h" #include "BKE_report.h" #include "BKE_tessmesh.h" -#include "WM_api.h" #include "WM_types.h" #include "ED_mesh.h" diff --git a/source/blender/editors/mesh/editmesh_select.c b/source/blender/editors/mesh/editmesh_select.c index a46edb19662..48dfe3bf667 100644 --- a/source/blender/editors/mesh/editmesh_select.c +++ b/source/blender/editors/mesh/editmesh_select.c @@ -40,7 +40,6 @@ #include "BKE_context.h" #include "BKE_displist.h" -#include "BKE_depsgraph.h" #include "BKE_report.h" #include "BKE_paint.h" #include "BKE_tessmesh.h" @@ -56,9 +55,7 @@ #include "ED_mesh.h" #include "ED_screen.h" -#include "ED_util.h" #include "ED_uvedit.h" -#include "ED_object.h" #include "ED_view3d.h" #include "BIF_gl.h" @@ -1148,11 +1145,11 @@ static void mouse_mesh_loop(bContext *C, int mval[2], short extend, short desele /* We can't be sure this has already been set... */ ED_view3d_init_mats_rv3d(vc.obedit, vc.rv3d); - if (ED_view3d_project_float_object(vc.ar, eed->v1->co, v1_co, V3D_PROJ_TEST_NOP) == V3D_PROJ_RET_OK) { + if (ED_view3d_project_float_object(vc.ar, eed->v1->co, v1_co, V3D_PROJ_TEST_CLIP_NEAR) == V3D_PROJ_RET_OK) { length_1 = len_squared_v2v2(mvalf, v1_co); } - if (ED_view3d_project_float_object(vc.ar, eed->v2->co, v2_co, V3D_PROJ_TEST_NOP) == V3D_PROJ_RET_OK) { + if (ED_view3d_project_float_object(vc.ar, eed->v2->co, v2_co, V3D_PROJ_TEST_CLIP_NEAR) == V3D_PROJ_RET_OK) { length_2 = len_squared_v2v2(mvalf, v2_co); } #if 0 @@ -1179,7 +1176,7 @@ static void mouse_mesh_loop(bContext *C, int mval[2], short extend, short desele float co[2], tdist; BM_face_calc_center_mean(f, cent); - if (ED_view3d_project_float_object(vc.ar, cent, co, V3D_PROJ_TEST_NOP) == V3D_PROJ_RET_OK) { + if (ED_view3d_project_float_object(vc.ar, cent, co, V3D_PROJ_TEST_CLIP_NEAR) == V3D_PROJ_RET_OK) { tdist = len_squared_v2v2(mvalf, co); if (tdist < best_dist) { /* printf("Best face: %p (%f)\n", f, tdist);*/ diff --git a/source/blender/editors/mesh/editmesh_tools.c b/source/blender/editors/mesh/editmesh_tools.c index c15c1d4a4de..41b263e8929 100644 --- a/source/blender/editors/mesh/editmesh_tools.c +++ b/source/blender/editors/mesh/editmesh_tools.c @@ -40,8 +40,8 @@ #include "RNA_define.h" #include "RNA_access.h" +#include "RNA_enum_types.h" -#include "BLI_array.h" #include "BLI_blenlib.h" #include "BLI_noise.h" #include "BLI_math.h" @@ -49,9 +49,7 @@ #include "BKE_material.h" #include "BKE_context.h" -#include "BKE_cdderivedmesh.h" #include "BKE_depsgraph.h" -#include "BKE_mesh.h" #include "BKE_object.h" #include "BKE_report.h" #include "BKE_texture.h" @@ -616,7 +614,7 @@ static int edbm_extrude_verts_exec(bContext *C, wmOperator *op) edbm_extrude_verts_indiv(em, op, BM_ELEM_SELECT, nor); - WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit); + EDBM_update_generic(em, TRUE, TRUE); return OPERATOR_FINISHED; } @@ -647,7 +645,7 @@ static int edbm_extrude_edges_exec(bContext *C, wmOperator *op) edbm_extrude_edges_indiv(em, op, BM_ELEM_SELECT, nor); - WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit); + EDBM_update_generic(em, TRUE, TRUE); return OPERATOR_FINISHED; } @@ -911,7 +909,7 @@ static int edbm_dupli_extrude_cursor_invoke(bContext *C, wmOperator *op, wmEvent BMOIter oiter; copy_v3_v3(min, curs); - view3d_get_view_aligned_coordinate(&vc, min, event->mval, 0); + view3d_get_view_aligned_coordinate(&vc, min, event->mval, FALSE); invert_m4_m4(vc.obedit->imat, vc.obedit->obmat); mul_m4_v3(vc.obedit->imat, min); // back in object space @@ -2531,7 +2529,6 @@ static void edbm_blend_from_shape_ui(bContext *C, wmOperator *op) void MESH_OT_blend_from_shape(wmOperatorType *ot) { PropertyRNA *prop; - static EnumPropertyItem shape_items[] = {{0, NULL, 0, NULL, NULL}}; /* identifiers */ ot->name = "Blend From Shape"; @@ -2548,7 +2545,7 @@ void MESH_OT_blend_from_shape(wmOperatorType *ot) ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* properties */ - prop = RNA_def_enum(ot->srna, "shape", shape_items, 0, "Shape", "Shape key to use for blending"); + prop = RNA_def_enum(ot->srna, "shape", DummyRNA_NULL_items, 0, "Shape", "Shape key to use for blending"); RNA_def_enum_funcs(prop, shape_itemf); RNA_def_float(ot->srna, "blend", 1.0f, -FLT_MAX, FLT_MAX, "Blend", "Blending factor", -2.0f, 2.0f); RNA_def_boolean(ot->srna, "add", 1, "Add", "Add rather than blend between shapes"); @@ -2931,7 +2928,7 @@ static int edbm_knife_cut_exec(bContext *C, wmOperator *op) screen_vert_coords = sco = MEM_mallocN(bm->totvert * sizeof(float) * 2, __func__); BM_ITER_MESH_INDEX (bv, &iter, bm, BM_VERTS_OF_MESH, i) { - if (ED_view3d_project_float_object(ar, bv->co, *sco, V3D_PROJ_TEST_NOP) != V3D_PROJ_RET_OK) { + if (ED_view3d_project_float_object(ar, bv->co, *sco, V3D_PROJ_TEST_CLIP_NEAR) != V3D_PROJ_RET_OK) { copy_v2_fl(*sco, FLT_MAX); /* set error value */ } BM_elem_index_set(bv, i); /* set_ok */ diff --git a/source/blender/editors/mesh/editmesh_utils.c b/source/blender/editors/mesh/editmesh_utils.c index b1094c75f27..e8132f5b82b 100644 --- a/source/blender/editors/mesh/editmesh_utils.c +++ b/source/blender/editors/mesh/editmesh_utils.c @@ -35,15 +35,12 @@ #include "DNA_object_types.h" #include "DNA_scene_types.h" -#include "BLI_blenlib.h" #include "BLI_math.h" #include "BKE_DerivedMesh.h" -#include "BKE_bmesh.h" #include "BKE_context.h" #include "BKE_depsgraph.h" #include "BKE_key.h" -#include "BKE_library.h" #include "BKE_mesh.h" #include "BKE_report.h" #include "BKE_tessmesh.h" @@ -56,7 +53,6 @@ #include "ED_mesh.h" #include "ED_util.h" -#include "bmesh.h" #include "mesh_intern.h" @@ -1302,15 +1298,15 @@ void EDBM_mesh_reveal(BMEditMesh *em) int sels[3] = {(em->selectmode & SCE_SELECT_VERTEX), (em->selectmode & SCE_SELECT_EDGE), (em->selectmode & SCE_SELECT_FACE), }; - - BMIter iter; - BMElem *ele; int i; /* Use tag flag to remember what was hidden before all is revealed. * BM_ELEM_HIDDEN --> BM_ELEM_TAG */ #pragma omp parallel for schedule(dynamic) if (em->bm->totvert + em->bm->totedge + em->bm->totface >= BM_OMP_LIMIT) for (i = 0; i < 3; i++) { + BMIter iter; + BMElem *ele; + BM_ITER_MESH (ele, &iter, em->bm, iter_types[i]) { BM_elem_flag_set(ele, BM_ELEM_TAG, BM_elem_flag_test(ele, BM_ELEM_HIDDEN)); } @@ -1321,6 +1317,9 @@ void EDBM_mesh_reveal(BMEditMesh *em) /* Select relevant just-revealed elements */ for (i = 0; i < 3; i++) { + BMIter iter; + BMElem *ele; + if (!sels[i]) { continue; } diff --git a/source/blender/editors/mesh/mesh_data.c b/source/blender/editors/mesh/mesh_data.c index e9906f852de..641d1be7a2e 100644 --- a/source/blender/editors/mesh/mesh_data.c +++ b/source/blender/editors/mesh/mesh_data.c @@ -28,35 +28,23 @@ * \ingroup edmesh */ - -#include <math.h> -#include <stdlib.h> -#include <string.h> - #include "MEM_guardedalloc.h" -#include "DNA_material_types.h" #include "DNA_mesh_types.h" #include "DNA_meshdata_types.h" #include "DNA_object_types.h" #include "DNA_scene_types.h" #include "DNA_view3d_types.h" -#include "BLI_utildefines.h" #include "BLI_path_util.h" #include "BLI_array.h" #include "BLI_math.h" -#include "BLI_edgehash.h" -#include "BLI_linklist.h" -#include "BLI_listbase.h" #include "BKE_context.h" #include "BKE_depsgraph.h" -#include "BKE_displist.h" #include "BKE_image.h" #include "BKE_library.h" #include "BKE_main.h" -#include "BKE_material.h" #include "BKE_mesh.h" #include "BKE_report.h" #include "BKE_tessmesh.h" @@ -72,10 +60,9 @@ #include "ED_uvedit.h" #include "ED_view3d.h" -#include "RE_render_ext.h" - #include "mesh_intern.h" + static CustomData *mesh_customdata_get_type(Mesh *me, const char htype, int *r_tot) { CustomData *data; diff --git a/source/blender/editors/mesh/mesh_navmesh.c b/source/blender/editors/mesh/mesh_navmesh.c index 21564d2d348..1a81cab8de7 100644 --- a/source/blender/editors/mesh/mesh_navmesh.c +++ b/source/blender/editors/mesh/mesh_navmesh.c @@ -26,31 +26,22 @@ * ***** END GPL LICENSE BLOCK ***** */ -#include <math.h> - #include "MEM_guardedalloc.h" #include "DNA_scene_types.h" #include "DNA_object_types.h" #include "DNA_mesh_types.h" -#include "DNA_meshdata_types.h" -#include "DNA_modifier_types.h" -#include "DNA_ID.h" #include "BLI_listbase.h" -#include "BLI_utildefines.h" #include "BLI_math_vector.h" #include "BLI_linklist.h" #include "BKE_library.h" #include "BKE_depsgraph.h" #include "BKE_context.h" -#include "BKE_main.h" #include "BKE_mesh.h" -#include "BKE_modifier.h" #include "BKE_scene.h" #include "BKE_DerivedMesh.h" -#include "BKE_cdderivedmesh.h" #include "BKE_report.h" #include "BKE_tessmesh.h" @@ -58,14 +49,13 @@ #include "ED_mesh.h" #include "ED_screen.h" -#include "RNA_access.h" - #include "WM_api.h" #include "WM_types.h" #include "mesh_intern.h" #include "recast-capi.h" + static void createVertsTrisData(bContext *C, LinkNode *obs, int *nverts_r, float **verts_r, int *ntris_r, int **tris_r) { MVert *mvert; diff --git a/source/blender/editors/mesh/mesh_ops.c b/source/blender/editors/mesh/mesh_ops.c index 12b68f0e419..372d6feec0c 100644 --- a/source/blender/editors/mesh/mesh_ops.c +++ b/source/blender/editors/mesh/mesh_ops.c @@ -29,17 +29,11 @@ */ -#include <stdlib.h> -#include <math.h> -#include "DNA_object_types.h" -#include "DNA_scene_types.h" #include "BLI_math.h" -#include "BLI_blenlib.h" -#include "BKE_context.h" #include "RNA_access.h" @@ -49,7 +43,6 @@ #include "ED_object.h" #include "ED_mesh.h" #include "ED_screen.h" -#include "ED_view3d.h" #include "mesh_intern.h" diff --git a/source/blender/editors/mesh/meshtools.c b/source/blender/editors/mesh/meshtools.c index c0b6327d740..773331d20f8 100644 --- a/source/blender/editors/mesh/meshtools.c +++ b/source/blender/editors/mesh/meshtools.c @@ -27,35 +27,22 @@ /** \file blender/editors/mesh/meshtools.c * \ingroup edmesh + * + * meshtools.c: no editmode (violated already :), mirror & join), + * tools operating on meshes */ - -/* - * meshtools.c: no editmode (violated already :), tools operating on meshes - */ - -#include <stddef.h> -#include <stdlib.h> -#include <math.h> -#include <float.h> - #include "MEM_guardedalloc.h" #include "DNA_mesh_types.h" -#include "DNA_view3d_types.h" #include "DNA_key_types.h" #include "DNA_material_types.h" -#include "DNA_meshdata_types.h" #include "DNA_modifier_types.h" #include "DNA_object_types.h" #include "DNA_scene_types.h" #include "BLI_math.h" #include "BLI_blenlib.h" -#include "BLI_utildefines.h" -#include "BLI_ghash.h" -#include "BLI_rand.h" /* for randome face sorting */ -#include "BLI_threads.h" #include "BKE_context.h" @@ -71,7 +58,6 @@ #include "BKE_tessmesh.h" #include "BKE_multires.h" -#include "BLO_sys_types.h" // for intptr_t support #include "ED_mesh.h" #include "ED_object.h" @@ -80,10 +66,6 @@ #include "WM_api.h" #include "WM_types.h" -/* own include */ -#include "mesh_intern.h" -#include "uvedit_intern.h" - /* * ********************** no editmode!!! *********** */ /*********************** JOIN ***************************/ @@ -1080,7 +1062,7 @@ static float *editmesh_get_mirror_uv(BMEditMesh *em, int axis, float *uv, float static unsigned int mirror_facehash(const void *ptr) { const MFace *mf = ptr; - int v0, v1; + unsigned int v0, v1; if (mf->v4) { v0 = MIN4(mf->v1, mf->v2, mf->v3, mf->v4); diff --git a/source/blender/editors/object/object_add.c b/source/blender/editors/object/object_add.c index b21b77e4e34..473119c90f3 100644 --- a/source/blender/editors/object/object_add.c +++ b/source/blender/editors/object/object_add.c @@ -802,10 +802,18 @@ void OBJECT_OT_lamp_add(wmOperatorType *ot) static int group_instance_add_exec(bContext *C, wmOperator *op) { - Group *group = BLI_findlink(&CTX_data_main(C)->group, RNA_enum_get(op->ptr, "group")); - + Group *group; unsigned int layer; float loc[3], rot[3]; + + if (RNA_struct_property_is_set(op->ptr, "name")) { + char name[MAX_ID_NAME - 2]; + + RNA_string_get(op->ptr, "name", name); + group = (Group *)BKE_libblock_find_name(ID_GR, name); + } + else + group = BLI_findlink(&CTX_data_main(C)->group, RNA_enum_get(op->ptr, "group")); if (!ED_object_add_generic_get_opts(C, op, loc, rot, NULL, &layer, NULL)) return OPERATOR_CANCELLED; @@ -847,6 +855,7 @@ void OBJECT_OT_group_instance_add(wmOperatorType *ot) ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* properties */ + RNA_def_string(ot->srna, "name", "Group", MAX_ID_NAME - 2, "Name", "Group name to add"); ot->prop = RNA_def_enum(ot->srna, "group", DummyRNA_NULL_items, 0, "Group", ""); RNA_def_enum_funcs(ot->prop, RNA_group_itemf); ED_object_add_generic_props(ot, FALSE); diff --git a/source/blender/editors/object/object_bake.c b/source/blender/editors/object/object_bake.c index 8b40379f88d..d3ebd1dae0a 100644 --- a/source/blender/editors/object/object_bake.c +++ b/source/blender/editors/object/object_bake.c @@ -100,6 +100,7 @@ typedef struct { float bias; int raytrace_structure; int octree_resolution; + int threads; } MultiresBakeJob; static int multiresbake_check(bContext *C, wmOperator *op) @@ -316,9 +317,10 @@ static int multiresbake_image_exec_locked(bContext *C, wmOperator *op) bkr.mode = scene->r.bake_mode; bkr.use_lores_mesh = scene->r.bake_flag & R_BAKE_LORES_MESH; bkr.bias = scene->r.bake_biasdist; - bkr.number_of_rays = scene->r.bake_rays_number; + bkr.number_of_rays = scene->r.bake_samples; bkr.raytrace_structure = scene->r.raytrace_structure; bkr.octree_resolution = scene->r.ocres; + bkr.threads = scene->r.mode & R_FIXED_THREADS ? scene->r.threads : 0; /* create low-resolution DM (to bake to) and hi-resolution DM (to bake from) */ bkr.hires_dm = multiresbake_create_hiresdm(scene, ob, &bkr.tot_lvl, &bkr.simple); @@ -353,9 +355,10 @@ static void init_multiresbake_job(bContext *C, MultiresBakeJob *bkj) bkj->use_lores_mesh = scene->r.bake_flag & R_BAKE_LORES_MESH; bkj->bake_clear = scene->r.bake_flag & R_BAKE_CLEAR; bkj->bias = scene->r.bake_biasdist; - bkj->number_of_rays = scene->r.bake_rays_number; + bkj->number_of_rays = scene->r.bake_samples; bkj->raytrace_structure = scene->r.raytrace_structure; bkj->octree_resolution = scene->r.ocres; + bkj->threads = scene->r.mode & R_FIXED_THREADS ? scene->r.threads : 0; CTX_DATA_BEGIN (C, Base *, base, selected_editable_bases) { @@ -422,6 +425,7 @@ static void multiresbake_startjob(void *bkv, short *stop, short *do_update, floa bkr.number_of_rays = bkj->number_of_rays; bkr.raytrace_structure = bkj->raytrace_structure; bkr.octree_resolution = bkj->octree_resolution; + bkr.threads = bkj->threads; RE_multires_bake_images(&bkr); diff --git a/source/blender/editors/object/object_edit.c b/source/blender/editors/object/object_edit.c index 12edb3e8edb..c9492d8f683 100644 --- a/source/blender/editors/object/object_edit.c +++ b/source/blender/editors/object/object_edit.c @@ -1676,10 +1676,6 @@ static EnumPropertyItem game_properties_copy_operations[] = { {0, NULL, 0, NULL, NULL} }; -static EnumPropertyItem gameprops_items[] = { - {0, NULL, 0, NULL, NULL} -}; - static EnumPropertyItem *gameprops_itemf(bContext *C, PointerRNA *UNUSED(ptr), PropertyRNA *UNUSED(prop), int *free) { Object *ob = ED_object_active_context(C); @@ -1689,7 +1685,7 @@ static EnumPropertyItem *gameprops_itemf(bContext *C, PointerRNA *UNUSED(ptr), P int a, totitem = 0; if (!ob) - return gameprops_items; + return DummyRNA_NULL_items; for (a = 1, prop = ob->prop.first; prop; prop = prop->next, a++) { tmp.value = a; @@ -1760,7 +1756,7 @@ void OBJECT_OT_game_property_copy(wmOperatorType *ot) ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; RNA_def_enum(ot->srna, "operation", game_properties_copy_operations, 3, "Operation", ""); - prop = RNA_def_enum(ot->srna, "property", gameprops_items, 0, "Property", "Properties to copy"); + prop = RNA_def_enum(ot->srna, "property", DummyRNA_NULL_items, 0, "Property", "Properties to copy"); RNA_def_property_flag(prop, PROP_SKIP_SAVE); RNA_def_enum_funcs(prop, gameprops_itemf); ot->prop = prop; diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c index f3e792def17..e7c619acb67 100644 --- a/source/blender/editors/object/object_vgroup.c +++ b/source/blender/editors/object/object_vgroup.c @@ -65,6 +65,7 @@ #include "RNA_access.h" #include "RNA_define.h" +#include "RNA_enum_types.h" #include "WM_api.h" #include "WM_types.h" @@ -87,7 +88,7 @@ static int vertex_group_use_vert_sel(Object *ob) if (ob->mode == OB_MODE_EDIT) { return TRUE; } - else if (ob->type == OB_MESH && ((Mesh *)ob->data)->editflag & ME_EDIT_VERT_SEL) { + else if (ob->type == OB_MESH && ((Mesh *)ob->data)->editflag & ME_EDIT_PAINT_VERT_SEL) { return TRUE; } else { @@ -1409,7 +1410,7 @@ static void vgroup_fix(Scene *scene, Object *ob, float distToBe, float strength, Mesh *me = ob->data; MVert *mvert = me->mvert; int *verts = NULL; - if (!(me->editflag & ME_EDIT_VERT_SEL)) + if (!(me->editflag & ME_EDIT_PAINT_VERT_SEL)) return; for (i = 0; i < me->totvert && mvert; i++, mvert++) { if (mvert->flag & SELECT) { @@ -2070,7 +2071,7 @@ void ED_vgroup_mirror(Object *ob, const short mirror_weights, const short flip_v /* object mode / weight paint */ MVert *mv, *mv_mirr; int vidx, vidx_mirr; - const int use_vert_sel = (me->editflag & ME_EDIT_VERT_SEL) != 0; + const int use_vert_sel = (me->editflag & ME_EDIT_PAINT_VERT_SEL) != 0; if (me->dvert == NULL) { goto cleanup; @@ -3369,10 +3370,6 @@ void OBJECT_OT_vertex_group_transfer_weight(wmOperatorType *ot) ot->prop = RNA_def_enum(ot->srna, "WT_replace_mode", WT_replace_mode_item, 1, "Replace", ""); } -static EnumPropertyItem vgroup_items[] = { - {0, NULL, 0, NULL, NULL} -}; - static int set_active_group_exec(bContext *C, wmOperator *op) { Object *ob = ED_object_context(C); @@ -3396,7 +3393,7 @@ static EnumPropertyItem *vgroup_itemf(bContext *C, PointerRNA *UNUSED(ptr), Prop int a, totitem = 0; if (!ob) - return vgroup_items; + return DummyRNA_NULL_items; for (a = 0, def = ob->defbase.first; def; def = def->next, a++) { tmp.value = a; @@ -3430,7 +3427,7 @@ void OBJECT_OT_vertex_group_set_active(wmOperatorType *ot) ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* properties */ - prop = RNA_def_enum(ot->srna, "group", vgroup_items, 0, "Group", "Vertex group to set as active"); + prop = RNA_def_enum(ot->srna, "group", DummyRNA_NULL_items, 0, "Group", "Vertex group to set as active"); RNA_def_enum_funcs(prop, vgroup_itemf); ot->prop = prop; } diff --git a/source/blender/editors/physics/particle_edit.c b/source/blender/editors/physics/particle_edit.c index 30508a793ae..9dbc0f9a10c 100644 --- a/source/blender/editors/physics/particle_edit.c +++ b/source/blender/editors/physics/particle_edit.c @@ -421,7 +421,7 @@ static int key_test_depth(PEData *data, const float co[3], const int screen_co[2 /* used to calculate here but all callers have the screen_co already, so pass as arg */ #if 0 if (ED_view3d_project_int_global(data->vc.ar, co, screen_co, - V3D_PROJ_TEST_CLIP_BB | V3D_PROJ_TEST_CLIP_WIN) != V3D_PROJ_RET_OK) + V3D_PROJ_TEST_CLIP_BB | V3D_PROJ_TEST_CLIP_WIN | V3D_PROJ_TEST_CLIP_NEAR) != V3D_PROJ_RET_OK) { return 0; } @@ -2812,7 +2812,7 @@ static void brush_cut(PEData *data, int pa_index) if (edit->points[pa_index].flag & PEP_HIDE) return; - if (ED_view3d_project_int_global(ar, key->co, screen_co, V3D_PROJ_TEST_NOP) != V3D_PROJ_RET_OK) + if (ED_view3d_project_int_global(ar, key->co, screen_co, V3D_PROJ_TEST_CLIP_NEAR) != V3D_PROJ_RET_OK) return; rad2= data->rad * data->rad; @@ -2837,7 +2837,7 @@ static void brush_cut(PEData *data, int pa_index) /* calculate path time closest to root that was inside the circle */ for (k=1, key++; k<=keys; k++, key++) { - if ((ED_view3d_project_int_global(ar, key->co, screen_co, V3D_PROJ_TEST_NOP) != V3D_PROJ_RET_OK) || + if ((ED_view3d_project_int_global(ar, key->co, screen_co, V3D_PROJ_TEST_CLIP_NEAR) != V3D_PROJ_RET_OK) || key_test_depth(data, key->co, screen_co) == 0) { x0 = (float)screen_co[0]; @@ -3476,11 +3476,16 @@ static int brush_edit_init(bContext *C, wmOperator *op) PTCacheEdit *edit= PE_get_current(scene, ob); ARegion *ar= CTX_wm_region(C); BrushEdit *bedit; - + float min[3], max[3]; + if (pset->brushtype < 0) return 0; - initgrabz(ar->regiondata, ob->obmat[3][0], ob->obmat[3][1], ob->obmat[3][2]); + /* set the 'distance factor' for grabbing (used in comb etc) */ + INIT_MINMAX(min, max); + PE_minmax(scene, min, max); + mid_v3_v3v3(min, min, max); + initgrabz(ar->regiondata, min[0], min[1], min[2]); bedit= MEM_callocN(sizeof(BrushEdit), "BrushEdit"); bedit->first= 1; diff --git a/source/blender/editors/physics/particle_object.c b/source/blender/editors/physics/particle_object.c index 221aad2161c..23069ab8a08 100644 --- a/source/blender/editors/physics/particle_object.c +++ b/source/blender/editors/physics/particle_object.c @@ -49,6 +49,7 @@ #include "BKE_main.h" #include "BKE_particle.h" #include "BKE_pointcache.h" +#include "BKE_report.h" #include "RNA_access.h" @@ -625,7 +626,7 @@ void PARTICLE_OT_disconnect_hair(wmOperatorType *ot) RNA_def_boolean(ot->srna, "all", 0, "All hair", "Disconnect all hair systems from the emitter mesh"); } -static void connect_hair(Scene *scene, Object *ob, ParticleSystem *psys) +static int connect_hair(Scene *scene, Object *ob, ParticleSystem *psys) { ParticleSystemModifierData *psmd = psys_get_modifier(ob, psys); ParticleData *pa; @@ -642,8 +643,8 @@ static void connect_hair(Scene *scene, Object *ob, ParticleSystem *psys) float hairmat[4][4], imat[4][4]; float v[4][3], vec[3]; - if (!psys || !psys->part || psys->part->type != PART_HAIR) - return; + if (!psys || !psys->part || psys->part->type != PART_HAIR || !psmd->dm) + return FALSE; edit= psys->edit; point= edit ? edit->points : NULL; @@ -724,6 +725,8 @@ static void connect_hair(Scene *scene, Object *ob, ParticleSystem *psys) psys->flag &= ~PSYS_GLOBAL_HAIR; PE_update_object(scene, ob, 0); + + return TRUE; } static int connect_hair_exec(bContext *C, wmOperator *op) @@ -733,18 +736,24 @@ static int connect_hair_exec(bContext *C, wmOperator *op) PointerRNA ptr = CTX_data_pointer_get_type(C, "particle_system", &RNA_ParticleSystem); ParticleSystem *psys= NULL; int all = RNA_boolean_get(op->ptr, "all"); + int any_connected = FALSE; if (!ob) return OPERATOR_CANCELLED; if (all) { for (psys=ob->particlesystem.first; psys; psys=psys->next) { - connect_hair(scene, ob, psys); + any_connected |= connect_hair(scene, ob, psys); } } else { psys = ptr.data; - connect_hair(scene, ob, psys); + any_connected |= connect_hair(scene, ob, psys); + } + + if (!any_connected) { + BKE_report(op->reports, RPT_ERROR, "Can't disconnect hair if particle system modifier is disabled"); + return OPERATOR_CANCELLED; } DAG_id_tag_update(&ob->id, OB_RECALC_DATA); diff --git a/source/blender/editors/physics/physics_fluid.c b/source/blender/editors/physics/physics_fluid.c index db2023b7364..c54ac485be6 100644 --- a/source/blender/editors/physics/physics_fluid.c +++ b/source/blender/editors/physics/physics_fluid.c @@ -127,7 +127,7 @@ static float get_fluid_size_m(Scene *scene, Object *domainob, FluidsimSettings * float longest_axis; BKE_object_dimensions_get(domainob, dim); - longest_axis = MAX3(dim[0], dim[1], dim[2]); + longest_axis = max_fff(dim[0], dim[1], dim[2]); return longest_axis * scene->unit.scale_length; } diff --git a/source/blender/editors/screen/area.c b/source/blender/editors/screen/area.c index cde94ec46ee..fbdec3dd8ad 100644 --- a/source/blender/editors/screen/area.c +++ b/source/blender/editors/screen/area.c @@ -876,7 +876,7 @@ static int rct_fits(rcti *rect, char dir, int size) /* ar should be overlapping */ /* function checks if some overlapping region was defined before - on same place */ -static void region_overlap_fix(ARegion *ar) +static void region_overlap_fix(ScrArea *sa, ARegion *ar) { ARegion *ar1 = ar->prev; @@ -890,18 +890,26 @@ static void region_overlap_fix(ARegion *ar) ar1 = ar1->prev; } - /* translate */ + /* translate or close */ if (ar1) { int align1 = ar1->alignment & ~RGN_SPLIT_PREV; if (align1 == RGN_ALIGN_LEFT) { - BLI_rcti_translate(&ar->winrct, ar1->winx, 0); + if (ar->winrct.xmax + ar1->winx > sa->winx - U.widget_unit) + ar->flag |= RGN_FLAG_TOO_SMALL; + else + BLI_rcti_translate(&ar->winrct, ar1->winx, 0); } else if (align1 == RGN_ALIGN_RIGHT) { - BLI_rcti_translate(&ar->winrct, -ar1->winx, 0); + if (ar->winrct.xmin - ar1->winx < U.widget_unit) + ar->flag |= RGN_FLAG_TOO_SMALL; + else + BLI_rcti_translate(&ar->winrct, -ar1->winx, 0); } } + + } /* overlapping regions only in the following restricted cases */ @@ -943,8 +951,9 @@ static void region_rect_recursive(wmWindow *win, ScrArea *sa, ARegion *ar, rcti if (ar->next == NULL && alignment != RGN_ALIGN_QSPLIT) alignment = RGN_ALIGN_NONE; - /* prefsize, for header we stick to exception */ - prefsizex = ar->sizex > 1 ? ar->sizex : UI_DPI_FAC * ar->type->prefsizex; + /* prefsize, for header we stick to exception (prevent dpi rounding error) */ + prefsizex = UI_DPI_FAC * (ar->sizex > 1 ? ar->sizex + 0.5f : ar->type->prefsizex); + if (ar->regiontype == RGN_TYPE_HEADER) { prefsizey = ED_area_headersize(); } @@ -952,7 +961,7 @@ static void region_rect_recursive(wmWindow *win, ScrArea *sa, ARegion *ar, rcti prefsizey = UI_UNIT_Y * 2 + (UI_UNIT_Y / 2); } else { - prefsizey = ar->sizey > 1 ? ar->sizey : UI_DPI_FAC * ar->type->prefsizey; + prefsizey = UI_DPI_FAC * (ar->sizey > 1 ? ar->sizey + 0.5f : ar->type->prefsizey); } @@ -1092,12 +1101,13 @@ static void region_rect_recursive(wmWindow *win, ScrArea *sa, ARegion *ar, rcti ar->winy = BLI_rcti_size_y(&ar->winrct) + 1; /* if region opened normally, we store this for hide/reveal usage */ - if (ar->winx > 1) ar->sizex = ar->winx; - if (ar->winy > 1) ar->sizey = ar->winy; + /* prevent rounding errors for UI_DPI_FAC mult and divide */ + if (ar->winx > 1) ar->sizex = (ar->winx + 0.5f) / UI_DPI_FAC; + if (ar->winy > 1) ar->sizey = (ar->winy + 0.5f) / UI_DPI_FAC; - /* exception for multiple aligned overlapping regions on same spot */ + /* exception for multiple overlapping regions on same spot */ if (ar->overlap) - region_overlap_fix(ar); + region_overlap_fix(sa, ar); /* set winrect for azones */ if (ar->flag & (RGN_FLAG_HIDDEN | RGN_FLAG_TOO_SMALL)) { diff --git a/source/blender/editors/screen/screen_edit.c b/source/blender/editors/screen/screen_edit.c index f71d63e5fef..cca713ec14a 100644 --- a/source/blender/editors/screen/screen_edit.c +++ b/source/blender/editors/screen/screen_edit.c @@ -672,29 +672,6 @@ static void screen_test_scale(bScreen *sc, int winsizex, int winsizey) CLAMP(sv->vec.y, 0, winsizey); } - - /* scale prefsizes of regions */ - for (sa = sc->areabase.first; sa; sa = sa->next) { - ARegion *ar; - - for (ar = sa->regionbase.first; ar; ar = ar->next) { - ar->sizex = (int)((float)ar->sizex * facx); - ar->sizey = (int)((float)ar->sizey * facy); - ar->winx = (int)((float)ar->winx * facx); - ar->winy = (int)((float)ar->winy * facy); - } - if (sa->spacedata.first) { - SpaceLink *sl = sa->spacedata.first; - for (sl = sl->next; sl; sl = sl->next) { - for (ar = sl->regionbase.first; ar; ar = ar->next) { - ar->sizex = (int)((float)ar->sizex * facx); - ar->sizey = (int)((float)ar->sizey * facy); - ar->winx = (int)((float)ar->winx * facx); - ar->winy = (int)((float)ar->winy * facy); - } - } - } - } } /* test for collapsed areas. This could happen in some blender version... */ @@ -1325,6 +1302,7 @@ void ED_screen_set_subwinactive(bContext *C, wmEvent *event) screen_cursor_set(win, event); } else { + /* notifier invokes freeing the buttons... causing a bit too much redraws */ if (oldswin != scr->subwinactive) { region_cursor_set(win, scr->subwinactive, TRUE); WM_event_add_notifier(C, NC_SCREEN | ND_SUBWINACTIVE, scr); diff --git a/source/blender/editors/screen/screen_ops.c b/source/blender/editors/screen/screen_ops.c index a26f5e87090..a22faea9eec 100644 --- a/source/blender/editors/screen/screen_ops.c +++ b/source/blender/editors/screen/screen_ops.c @@ -1759,7 +1759,7 @@ static int region_scale_get_maxsize(RegionMoveData *rmd) int maxsize = 0; if (rmd->edge == AE_LEFT_TO_TOPRIGHT || rmd->edge == AE_RIGHT_TO_TOPLEFT) { - return rmd->sa->winx - UI_UNIT_X; + return (int) ( (rmd->sa->winx / UI_DPI_FAC) - UI_UNIT_X); } if (rmd->ar->regiontype == RGN_TYPE_TOOL_PROPS) { @@ -1808,6 +1808,9 @@ static int region_scale_modal(bContext *C, wmOperator *op, wmEvent *event) delta = event->x - rmd->origx; if (rmd->edge == AE_LEFT_TO_TOPRIGHT) delta = -delta; + /* region sizes now get multiplied */ + delta /= UI_DPI_FAC; + rmd->ar->sizex = rmd->origval + delta; CLAMP(rmd->ar->sizex, 0, rmd->maxsize); @@ -1824,6 +1827,9 @@ static int region_scale_modal(bContext *C, wmOperator *op, wmEvent *event) delta = event->y - rmd->origy; if (rmd->edge == AE_BOTTOM_TO_TOPLEFT) delta = -delta; + /* region sizes now get multiplied */ + delta /= UI_DPI_FAC; + rmd->ar->sizey = rmd->origval + delta; CLAMP(rmd->ar->sizey, 0, rmd->maxsize); diff --git a/source/blender/editors/sculpt_paint/paint_image.c b/source/blender/editors/sculpt_paint/paint_image.c index b704414c321..8c9531e5554 100644 --- a/source/blender/editors/sculpt_paint/paint_image.c +++ b/source/blender/editors/sculpt_paint/paint_image.c @@ -3344,7 +3344,7 @@ static void project_paint_begin(ProjPaintState *ps) tpage = project_paint_face_image(ps, ps->dm_mtface, face_index); - if (tpage && ((((Mesh *)ps->ob->data)->editflag & ME_EDIT_PAINT_MASK) == 0 || mf->flag & ME_FACE_SEL)) { + if (tpage && ((((Mesh *)ps->ob->data)->editflag & ME_EDIT_PAINT_FACE_SEL) == 0 || mf->flag & ME_FACE_SEL)) { float *v1coSS, *v2coSS, *v3coSS, *v4coSS = NULL; @@ -5104,7 +5104,7 @@ static int texture_paint_init(bContext *C, wmOperator *op) } pop->s.ob = ob; - pop->s.do_facesel = (me->editflag & ME_EDIT_PAINT_MASK) != 0; + pop->s.do_facesel = (me->editflag & ME_EDIT_PAINT_FACE_SEL) != 0; /* for non prohect paint we need */ /* fill in derived mesh */ @@ -5705,7 +5705,7 @@ static int image_paint_sample_color_poll(bContext *C) if (obact && obact->mode & OB_MODE_TEXTURE_PAINT) { Mesh *me = BKE_mesh_from_object(obact); if (me) { - return !(me->editflag & ME_EDIT_PAINT_MASK); + return !(me->editflag & ME_EDIT_PAINT_FACE_SEL); } } } diff --git a/source/blender/editors/sculpt_paint/paint_intern.h b/source/blender/editors/sculpt_paint/paint_intern.h index 162e2fa15d6..cf55c93efe4 100644 --- a/source/blender/editors/sculpt_paint/paint_intern.h +++ b/source/blender/editors/sculpt_paint/paint_intern.h @@ -89,6 +89,12 @@ void PAINT_OT_weight_from_bones(struct wmOperatorType *ot); void PAINT_OT_weight_sample(struct wmOperatorType *ot); void PAINT_OT_weight_sample_group(struct wmOperatorType *ot); +enum { + WPAINT_GRADIENT_TYPE_LINEAR, + WPAINT_GRADIENT_TYPE_RADIAL +}; +void PAINT_OT_weight_gradient(struct wmOperatorType *ot); + void PAINT_OT_vertex_paint_toggle(struct wmOperatorType *ot); void PAINT_OT_vertex_paint(struct wmOperatorType *ot); diff --git a/source/blender/editors/sculpt_paint/paint_ops.c b/source/blender/editors/sculpt_paint/paint_ops.c index 40dcb92f087..10b9f26dbcd 100644 --- a/source/blender/editors/sculpt_paint/paint_ops.c +++ b/source/blender/editors/sculpt_paint/paint_ops.c @@ -475,6 +475,7 @@ void ED_operatortypes_paint(void) WM_operatortype_append(PAINT_OT_weight_paint); WM_operatortype_append(PAINT_OT_weight_set); WM_operatortype_append(PAINT_OT_weight_from_bones); + WM_operatortype_append(PAINT_OT_weight_gradient); WM_operatortype_append(PAINT_OT_weight_sample); WM_operatortype_append(PAINT_OT_weight_sample_group); @@ -710,6 +711,9 @@ void ED_keymap_paint(wmKeyConfig *keyconf) WM_keymap_verify_item(keymap, "PAINT_OT_weight_sample", LEFTMOUSE, KM_PRESS, KM_CTRL, 0); WM_keymap_verify_item(keymap, "PAINT_OT_weight_sample_group", LEFTMOUSE, KM_PRESS, KM_SHIFT, 0); + RNA_enum_set(WM_keymap_add_item(keymap, "PAINT_OT_weight_gradient", LEFTMOUSE, KM_PRESS, KM_ALT, 0)->ptr, "type", WPAINT_GRADIENT_TYPE_LINEAR); + RNA_enum_set(WM_keymap_add_item(keymap, "PAINT_OT_weight_gradient", LEFTMOUSE, KM_PRESS, KM_ALT | KM_CTRL, 0)->ptr, "type", WPAINT_GRADIENT_TYPE_RADIAL); + WM_keymap_add_item(keymap, "PAINT_OT_weight_set", KKEY, KM_PRESS, KM_SHIFT, 0); diff --git a/source/blender/editors/sculpt_paint/paint_vertex.c b/source/blender/editors/sculpt_paint/paint_vertex.c index 9bbf99ff3cf..359486a4a8d 100644 --- a/source/blender/editors/sculpt_paint/paint_vertex.c +++ b/source/blender/editors/sculpt_paint/paint_vertex.c @@ -224,7 +224,7 @@ static void do_shared_vertex_tesscol(Mesh *me) { /* if no mcol: do not do */ /* if tface: only the involved faces, otherwise all */ - const int use_face_sel = (me->editflag & ME_EDIT_PAINT_MASK); + const int use_face_sel = (me->editflag & ME_EDIT_PAINT_FACE_SEL); MFace *mface; int a; short *scolmain, *scol; @@ -284,7 +284,7 @@ static void do_shared_vertex_tesscol(Mesh *me) static void do_shared_vertexcol(Mesh *me, int do_tessface) { - const int use_face_sel = (me->editflag & ME_EDIT_PAINT_MASK); + const int use_face_sel = (me->editflag & ME_EDIT_PAINT_FACE_SEL); MPoly *mp; float (*scol)[4]; int i, j, has_shared = 0; @@ -402,12 +402,28 @@ static int wpaint_mirror_vgroup_ensure(Object *ob, const int vgroup_active) return -1; } -static void copy_vpaint_prev(VPaint *vp, unsigned int *lcol, int tot) +static void free_vpaint_prev(VPaint *vp) { if (vp->vpaint_prev) { MEM_freeN(vp->vpaint_prev); vp->vpaint_prev = NULL; + vp->tot = 0; } +} + +static void free_wpaint_prev(VPaint *vp) +{ + if (vp->wpaint_prev) { + MEM_freeN(vp->wpaint_prev); + vp->wpaint_prev = NULL; + vp->tot = 0; + } +} + +static void copy_vpaint_prev(VPaint *vp, unsigned int *lcol, int tot) +{ + free_vpaint_prev(vp); + vp->tot = tot; if (lcol == NULL || tot == 0) return; @@ -419,10 +435,7 @@ static void copy_vpaint_prev(VPaint *vp, unsigned int *lcol, int tot) static void copy_wpaint_prev(VPaint *wp, MDeformVert *dverts, int dcount) { - if (wp->wpaint_prev) { - free_dverts(wp->wpaint_prev, wp->tot); - wp->wpaint_prev = NULL; - } + free_wpaint_prev(wp); if (dverts && dcount) { @@ -432,7 +445,6 @@ static void copy_wpaint_prev(VPaint *wp, MDeformVert *dverts, int dcount) } } - void vpaint_fill(Object *ob, unsigned int paintcol) { Mesh *me; @@ -447,7 +459,7 @@ void vpaint_fill(Object *ob, unsigned int paintcol) if (!me->mloopcol) return; /* possible we can't make mcol's */ - selected = (me->editflag & ME_EDIT_PAINT_MASK); + selected = (me->editflag & ME_EDIT_PAINT_FACE_SEL); mp = me->mpoly; for (i = 0; i < me->totpoly; i++, mp++) { @@ -1018,7 +1030,7 @@ static int weight_sample_invoke(bContext *C, wmOperator *op, wmEvent *event) me = BKE_mesh_from_object(vc.obact); if (me && me->dvert && vc.v3d && vc.rv3d) { - const int use_vert_sel = (me->editflag & ME_EDIT_VERT_SEL) != 0; + const int use_vert_sel = (me->editflag & ME_EDIT_PAINT_VERT_SEL) != 0; int v_idx_best = -1; unsigned int index; @@ -1103,7 +1115,7 @@ static EnumPropertyItem *weight_paint_sample_enum_itemf(bContext *C, PointerRNA if (me && me->dvert && vc.v3d && vc.rv3d && vc.obact->defbase.first) { const int defbase_tot = BLI_countlist(&vc.obact->defbase); - const int use_vert_sel = (me->editflag & ME_EDIT_VERT_SEL) != 0; + const int use_vert_sel = (me->editflag & ME_EDIT_PAINT_VERT_SEL) != 0; int *groups = MEM_callocN(defbase_tot * sizeof(int), "groups"); int found = FALSE; unsigned int index; @@ -1993,6 +2005,13 @@ static int set_wpaint(bContext *C, wmOperator *UNUSED(op)) /* toggle */ else { mesh_octree_table(NULL, NULL, NULL, 'e'); mesh_mirrtopo_table(NULL, 'e'); + + if (me->editflag & ME_EDIT_PAINT_VERT_SEL) { + BKE_mesh_flush_select_from_verts(me); + } + else if (me->editflag & ME_EDIT_PAINT_FACE_SEL) { + BKE_mesh_flush_select_from_polys(me); + } } WM_event_add_notifier(C, NC_SCENE | ND_MODE, scene); @@ -2222,14 +2241,14 @@ static void wpaint_stroke_update_step(bContext *C, struct PaintStroke *stroke, P swap_m4m4(wpd->vc.rv3d->persmat, mat); - use_vert_sel = (me->editflag & ME_EDIT_VERT_SEL) != 0; + use_vert_sel = (me->editflag & ME_EDIT_PAINT_VERT_SEL) != 0; /* which faces are involved */ if (wp->flag & VP_AREA) { /* Ugly hack, to avoid drawing vertex index when getting the face index buffer - campbell */ - me->editflag &= ~ME_EDIT_VERT_SEL; + me->editflag &= ~ME_EDIT_PAINT_VERT_SEL; totindex = sample_backbuf_area(vc, indexar, me->totpoly, mval[0], mval[1], brush_size_pressure); - me->editflag |= use_vert_sel ? ME_EDIT_VERT_SEL : 0; + me->editflag |= use_vert_sel ? ME_EDIT_PAINT_VERT_SEL : 0; } else { indexar[0] = view3d_sample_backbuf(vc, mval[0], mval[1]); @@ -2237,7 +2256,7 @@ static void wpaint_stroke_update_step(bContext *C, struct PaintStroke *stroke, P else totindex = 0; } - if ((me->editflag & ME_EDIT_PAINT_MASK) && me->mpoly) { + if ((me->editflag & ME_EDIT_PAINT_FACE_SEL) && me->mpoly) { for (index = 0; index < totindex; index++) { if (indexar[index] && indexar[index] <= me->totpoly) { MPoly *mpoly = ((MPoly *)me->mpoly) + (indexar[index] - 1); @@ -2476,6 +2495,10 @@ static int set_vpaint(bContext *C, wmOperator *op) /* toggle */ if (ob->mode & OB_MODE_VERTEX_PAINT) { ob->mode &= ~OB_MODE_VERTEX_PAINT; + + if (me->editflag & ME_EDIT_PAINT_FACE_SEL) { + BKE_mesh_flush_select_from_polys(me); + } } else { ob->mode |= OB_MODE_VERTEX_PAINT; @@ -2770,7 +2793,7 @@ static void vpaint_stroke_update_step(bContext *C, struct PaintStroke *stroke, P else totindex = 0; } - if ((me->editflag & ME_EDIT_PAINT_MASK) && me->mpoly) { + if ((me->editflag & ME_EDIT_PAINT_FACE_SEL) && me->mpoly) { for (index = 0; index < totindex; index++) { if (indexar[index] && indexar[index] <= me->totpoly) { MPoly *mpoly = ((MPoly *)me->mpoly) + (indexar[index] - 1); @@ -2927,3 +2950,256 @@ void PAINT_OT_weight_from_bones(wmOperatorType *ot) /* properties */ ot->prop = RNA_def_enum(ot->srna, "type", type_items, 0, "Type", "Method to use for assigning weights"); } + +/* *** VGroups Gradient *** */ +typedef struct DMGradient_vertStore { + float sco[2]; + float weight_orig; + enum { + VGRAD_STORE_NOP = 0, + VGRAD_STORE_DW_EXIST = (1 << 0) + } flag; +} DMGradient_vertStore; + +typedef struct DMGradient_userData { + struct ARegion *ar; + Scene *scene; + Mesh *me; + Brush *brush; + const float *sco_start; /* [2] */ + const float *sco_end; /* [2] */ + float sco_line_div; /* store (1.0f / len_v2v2(sco_start, sco_end)) */ + int def_nr; + short is_init; + DMGradient_vertStore *vert_cache; + + /* options */ + short use_select; + short type; + float weightpaint; +} DMGradient_userData; + +static void gradientVert__mapFunc(void *userData, int index, const float co[3], + const float UNUSED(no_f[3]), const short UNUSED(no_s[3])) +{ + DMGradient_userData *grad_data = userData; + Mesh *me = grad_data->me; + + if (grad_data->use_select == FALSE || (me->mvert[index].flag & SELECT)) { + DMGradient_vertStore *vs = &grad_data->vert_cache[index]; + + /* run first pass only, could be split into its own mapFunc + * the screen coords of the verts need to be cached because + * updating the mesh may move them about (entering feedback loop) */ + if (grad_data->is_init) { + if (ED_view3d_project_float_global(grad_data->ar, + co, vs->sco, + V3D_PROJ_TEST_CLIP_BB | V3D_PROJ_TEST_CLIP_WIN | V3D_PROJ_TEST_CLIP_NEAR) == V3D_PROJ_RET_OK) + { + /* ok */ + MDeformVert *dv = &me->dvert[index]; + MDeformWeight *dw; + dw = defvert_find_index(dv, grad_data->def_nr); + if (dw) { + vs->weight_orig = dw->weight; + vs->flag = VGRAD_STORE_DW_EXIST; + } + else { + vs->weight_orig = 0.0f; + vs->flag = VGRAD_STORE_NOP; + } + } + else { + /* no go */ + copy_v2_fl(vs->sco, FLT_MAX); + } + } + /* end init */ + + if (vs->sco[0] != FLT_MAX) { + float alpha; + + if (grad_data->type == WPAINT_GRADIENT_TYPE_LINEAR) { + alpha = line_point_factor_v2(vs->sco, grad_data->sco_start, grad_data->sco_end); + } + else if (grad_data->type == WPAINT_GRADIENT_TYPE_RADIAL) { + alpha = len_v2v2(grad_data->sco_start, vs->sco) * grad_data->sco_line_div; + } + else { + BLI_assert(0); + } + /* no need to clamp 'alpha' yet */ + + /* adjust weight */ + alpha = BKE_brush_curve_strength_clamp(grad_data->brush, alpha, 1.0f); + + if (alpha != 0.0f) { + MDeformVert *dv = &me->dvert[index]; + MDeformWeight *dw = defvert_verify_index(dv, grad_data->def_nr); + // dw->weight = alpha; // testing + int tool = grad_data->brush->vertexpaint_tool; + float testw; + + /* init if we just added */ + testw = wpaint_blend_tool(tool, vs->weight_orig, grad_data->weightpaint, alpha * grad_data->brush->alpha); + CLAMP(testw, 0.0f, 1.0f); + dw->weight = testw; + } + else { + MDeformVert *dv = &me->dvert[index]; + if (vs->flag & VGRAD_STORE_DW_EXIST) { + /* normally we NULL check, but in this case we know it exists */ + MDeformWeight *dw = defvert_find_index(dv, grad_data->def_nr); + dw->weight = vs->weight_orig; + } + else { + /* wasn't originally existing, remove */ + MDeformWeight *dw = defvert_find_index(dv, grad_data->def_nr); + if (dw) { + defvert_remove_group(dv, dw); + } + } + } + } + } +} + +static int paint_weight_gradient_modal(bContext *C, wmOperator *op, wmEvent *event) +{ + int ret = WM_gesture_straightline_modal(C, op, event); + + if (ret & OPERATOR_RUNNING_MODAL) { + if (event->type == LEFTMOUSE && event->val == KM_RELEASE) { /* XXX, hardcoded */ + /* generally crap! redo! */ + WM_gesture_straightline_cancel(C, op); + ret &= ~OPERATOR_RUNNING_MODAL; + ret |= OPERATOR_FINISHED; + } + } + + if (ret & OPERATOR_CANCELLED) { + ToolSettings *ts = CTX_data_tool_settings(C); + VPaint *wp = ts->wpaint; + Object *ob = CTX_data_active_object(C); + Mesh *me = ob->data; + copy_dverts(me->dvert, wp->wpaint_prev, me->totvert); + free_wpaint_prev(wp); + + DAG_id_tag_update(&ob->id, OB_RECALC_DATA); + WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob); + } + else if (ret & OPERATOR_FINISHED) { + ToolSettings *ts = CTX_data_tool_settings(C); + VPaint *wp = ts->wpaint; + free_wpaint_prev(wp); + } + + return ret; +} + +static int paint_weight_gradient_exec(bContext *C, wmOperator *op) +{ + wmGesture *gesture = op->customdata; + struct ARegion *ar = CTX_wm_region(C); + Scene *scene = CTX_data_scene(C); + Object *ob = CTX_data_active_object(C); + Mesh *me = ob->data; + int x_start = RNA_int_get(op->ptr, "xstart"); + int y_start = RNA_int_get(op->ptr, "ystart"); + int x_end = RNA_int_get(op->ptr, "xend"); + int y_end = RNA_int_get(op->ptr, "yend"); + float sco_start[2] = {x_start, y_start}; + float sco_end[2] = {x_end, y_end}; + + DerivedMesh *dm = mesh_get_derived_final(scene, ob, scene->customdata_mask); + + DMGradient_userData data = {0}; + + if (gesture->userdata == NULL) { + VPaint *wp = scene->toolsettings->wpaint; + + gesture->userdata = MEM_mallocN(sizeof(DMGradient_vertStore) * me->totvert, __func__); + data.is_init = TRUE; + + copy_wpaint_prev(wp, me->dvert, me->totvert); + + /* on init only, convert face -> vert sel */ + if (me->editflag & ME_EDIT_PAINT_FACE_SEL) { + BKE_mesh_flush_select_from_polys(me); + } + + } + + data.ar = ar; + data.scene = scene; + data.me = ob->data; + data.sco_start = sco_start; + data.sco_end = sco_end; + data.sco_line_div = 1.0f / len_v2v2(sco_start, sco_end); + data.def_nr = ob->actdef - 1; + data.use_select = (me->editflag & (ME_EDIT_PAINT_FACE_SEL | ME_EDIT_PAINT_VERT_SEL)); + data.vert_cache = gesture->userdata; + data.type = RNA_enum_get(op->ptr, "type"); + + { + ToolSettings *ts = CTX_data_tool_settings(C); + VPaint *wp = ts->wpaint; + struct Brush *brush = paint_brush(&wp->paint); + data.brush = brush; + data.weightpaint = BKE_brush_weight_get(scene, brush); + } + + dm->foreachMappedVert(dm, gradientVert__mapFunc, &data); + + DAG_id_tag_update(&ob->id, OB_RECALC_DATA); + WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob); + + return OPERATOR_FINISHED; +} + +static int paint_weight_gradient_invoke(bContext *C, wmOperator *op, wmEvent *event) +{ + int ret = WM_gesture_straightline_invoke(C, op, event); + if (ret & OPERATOR_RUNNING_MODAL) { + struct ARegion *ar = CTX_wm_region(C); + if (ar->regiontype == RGN_TYPE_WINDOW) { + if (event->type == LEFTMOUSE && event->val == KM_PRESS) { /* TODO, hardcoded, extend WM_gesture_straightline_ */ + wmGesture *gesture = op->customdata; + gesture->mode = 1; + } + } + } + return ret; +} + +void PAINT_OT_weight_gradient(wmOperatorType *ot) +{ + /* defined in DNA_space_types.h */ + static EnumPropertyItem gradient_types[] = { + {WPAINT_GRADIENT_TYPE_LINEAR, "LINEAR", 0, "Linear", ""}, + {WPAINT_GRADIENT_TYPE_RADIAL, "RADIAL", 0, "Radial", ""}, + {0, NULL, 0, NULL, NULL} + }; + + PropertyRNA *prop; + + /* identifiers */ + ot->name = "Weight Gradient"; + ot->idname = "PAINT_OT_weight_gradient"; + ot->description = "Sample a line and show it in Scope panels"; + + /* api callbacks */ + ot->invoke = paint_weight_gradient_invoke; + ot->modal = paint_weight_gradient_modal; + ot->exec = paint_weight_gradient_exec; + ot->poll = weight_paint_poll; + ot->cancel = WM_gesture_straightline_cancel; + + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + + prop = RNA_def_enum(ot->srna, "type", gradient_types, 0, "Type", ""); + RNA_def_property_flag(prop, PROP_SKIP_SAVE); + + WM_operator_properties_gesture_straightline(ot, CURSOR_EDIT); +} diff --git a/source/blender/editors/space_clip/clip_intern.h b/source/blender/editors/space_clip/clip_intern.h index ac5cfbaed11..432032e9dbf 100644 --- a/source/blender/editors/space_clip/clip_intern.h +++ b/source/blender/editors/space_clip/clip_intern.h @@ -54,7 +54,7 @@ struct wmOperatorType; /* extra padding for lengths (to go under scrollers) */ #define EXTRA_SCROLL_PAD 100.0f -#define STRIP_HEIGHT_HALF (0.25 * UI_UNIT_Y) +#define STRIP_HEIGHT_HALF (0.25f * UI_UNIT_Y) /* internal exports only */ diff --git a/source/blender/editors/space_clip/tracking_select.c b/source/blender/editors/space_clip/tracking_select.c index b8e162bfb17..bec50130230 100644 --- a/source/blender/editors/space_clip/tracking_select.c +++ b/source/blender/editors/space_clip/tracking_select.c @@ -123,10 +123,10 @@ static int track_mouse_area(const bContext *C, float co[2], MovieTrackingTrack * BKE_tracking_marker_pattern_minmax(marker, pat_min, pat_max); - epsx = MIN4(pat_min[0] - marker->search_min[0], marker->search_max[0] - pat_max[0], - fabsf(pat_min[0]), fabsf(pat_max[0])) / 2; - epsy = MIN4(pat_min[1] - marker->search_min[1], marker->search_max[1] - pat_max[1], - fabsf(pat_min[1]), fabsf(pat_max[1])) / 2; + epsx = min_ffff(pat_min[0] - marker->search_min[0], marker->search_max[0] - pat_max[0], + fabsf(pat_min[0]), fabsf(pat_max[0])) / 2; + epsy = min_ffff(pat_min[1] - marker->search_min[1], marker->search_max[1] - pat_max[1], + fabsf(pat_min[1]), fabsf(pat_max[1])) / 2; epsx = max_ff(epsx, 2.0f / width); epsy = max_ff(epsy, 2.0f / height); @@ -166,7 +166,7 @@ static float dist_to_rect(float co[2], float pos[2], float min[2], float max[2]) d3 = dist_squared_to_line_segment_v2(p, v3, v4); d4 = dist_squared_to_line_segment_v2(p, v4, v1); - return sqrtf(MIN4(d1, d2, d3, d4)); + return sqrtf(min_ffff(d1, d2, d3, d4)); } static float dist_to_crns(float co[2], float pos[2], float crns[4][2]) @@ -181,7 +181,7 @@ static float dist_to_crns(float co[2], float pos[2], float crns[4][2]) d3 = dist_squared_to_line_segment_v2(p, v3, v4); d4 = dist_squared_to_line_segment_v2(p, v4, v1); - return sqrtf(MIN4(d1, d2, d3, d4)); + return sqrtf(min_ffff(d1, d2, d3, d4)); } static MovieTrackingTrack *find_nearest_track(SpaceClip *sc, ListBase *tracksbase, float co[2]) @@ -210,7 +210,7 @@ static MovieTrackingTrack *find_nearest_track(SpaceClip *sc, ListBase *tracksbas d3 = dist_to_rect(co, marker->pos, marker->search_min, marker->search_max); /* choose minimal distance. useful for cases of overlapped markers. */ - dist = MIN3(d1, d2, d3); + dist = min_fff(d1, d2, d3); if (track == NULL || dist < mindist) { track = cur; diff --git a/source/blender/editors/space_node/drawnode.c b/source/blender/editors/space_node/drawnode.c index f123bcdb94f..59dd66a0207 100644 --- a/source/blender/editors/space_node/drawnode.c +++ b/source/blender/editors/space_node/drawnode.c @@ -3416,10 +3416,10 @@ int node_link_bezier_points(View2D *v2d, SpaceNode *snode, bNodeLink *link, floa vec[2][0] = vec[3][0] - dist; vec[2][1] = vec[3][1]; } - if (v2d && MIN4(vec[0][0], vec[1][0], vec[2][0], vec[3][0]) > v2d->cur.xmax) { + if (v2d && min_ffff(vec[0][0], vec[1][0], vec[2][0], vec[3][0]) > v2d->cur.xmax) { /* clipped */ } - else if (v2d && MAX4(vec[0][0], vec[1][0], vec[2][0], vec[3][0]) < v2d->cur.xmin) { + else if (v2d && max_ffff(vec[0][0], vec[1][0], vec[2][0], vec[3][0]) < v2d->cur.xmin) { /* clipped */ } else { diff --git a/source/blender/editors/space_outliner/outliner_draw.c b/source/blender/editors/space_outliner/outliner_draw.c index 33217e042e5..6913ebc8a11 100644 --- a/source/blender/editors/space_outliner/outliner_draw.c +++ b/source/blender/editors/space_outliner/outliner_draw.c @@ -421,17 +421,17 @@ static void outliner_draw_restrictbuts(uiBlock *block, Scene *scene, ARegion *ar uiBlockSetEmboss(block, UI_EMBOSSN); bt = uiDefIconButR(block, ICONTOG, 0, ICON_RESTRICT_VIEW_OFF, - (int)ar->v2d.cur.xmax - OL_TOG_RESTRICT_VIEWX, (int)te->ys, UI_UNIT_X - 1, UI_UNIT_Y - 1, + (int)ar->v2d.cur.xmax - OL_TOG_RESTRICT_VIEWX, (int)te->ys, UI_UNIT_X, UI_UNIT_Y, &ptr, "hide", -1, 0, 0, -1, -1, NULL); uiButSetFunc(bt, restrictbutton_view_cb, scene, ob); bt = uiDefIconButR(block, ICONTOG, 0, ICON_RESTRICT_SELECT_OFF, - (int)ar->v2d.cur.xmax - OL_TOG_RESTRICT_SELECTX, (int)te->ys, UI_UNIT_X - 1, UI_UNIT_Y - 1, + (int)ar->v2d.cur.xmax - OL_TOG_RESTRICT_SELECTX, (int)te->ys, UI_UNIT_X, UI_UNIT_Y, &ptr, "hide_select", -1, 0, 0, -1, -1, NULL); uiButSetFunc(bt, restrictbutton_sel_cb, scene, ob); bt = uiDefIconButR(block, ICONTOG, 0, ICON_RESTRICT_RENDER_OFF, - (int)ar->v2d.cur.xmax - OL_TOG_RESTRICT_RENDERX, (int)te->ys, UI_UNIT_X - 1, UI_UNIT_Y - 1, + (int)ar->v2d.cur.xmax - OL_TOG_RESTRICT_RENDERX, (int)te->ys, UI_UNIT_X, UI_UNIT_Y, &ptr, "hide_render", -1, 0, 0, -1, -1, NULL); uiButSetFunc(bt, restrictbutton_rend_cb, scene, ob); @@ -445,15 +445,15 @@ static void outliner_draw_restrictbuts(uiBlock *block, Scene *scene, ARegion *ar uiBlockSetEmboss(block, UI_EMBOSSN); restrict_bool = group_restrict_flag(gr, OB_RESTRICT_VIEW); - bt = uiDefIconBut(block, ICONTOG, 0, restrict_bool ? ICON_RESTRICT_VIEW_ON : ICON_RESTRICT_VIEW_OFF, (int)ar->v2d.cur.xmax - OL_TOG_RESTRICT_VIEWX, (int)te->ys, UI_UNIT_X - 1, UI_UNIT_Y - 1, NULL, 0, 0, 0, 0, "Restrict/Allow visibility in the 3D View"); + bt = uiDefIconBut(block, ICONTOG, 0, restrict_bool ? ICON_RESTRICT_VIEW_ON : ICON_RESTRICT_VIEW_OFF, (int)ar->v2d.cur.xmax - OL_TOG_RESTRICT_VIEWX, (int)te->ys, UI_UNIT_X, UI_UNIT_Y, NULL, 0, 0, 0, 0, "Restrict/Allow visibility in the 3D View"); uiButSetFunc(bt, restrictbutton_gr_restrict_view, scene, gr); restrict_bool = group_restrict_flag(gr, OB_RESTRICT_SELECT); - bt = uiDefIconBut(block, ICONTOG, 0, restrict_bool ? ICON_RESTRICT_SELECT_ON : ICON_RESTRICT_SELECT_OFF, (int)ar->v2d.cur.xmax - OL_TOG_RESTRICT_SELECTX, (int)te->ys, UI_UNIT_X - 1, UI_UNIT_Y - 1, NULL, 0, 0, 0, 0, "Restrict/Allow selection in the 3D View"); + bt = uiDefIconBut(block, ICONTOG, 0, restrict_bool ? ICON_RESTRICT_SELECT_ON : ICON_RESTRICT_SELECT_OFF, (int)ar->v2d.cur.xmax - OL_TOG_RESTRICT_SELECTX, (int)te->ys, UI_UNIT_X, UI_UNIT_Y, NULL, 0, 0, 0, 0, "Restrict/Allow selection in the 3D View"); uiButSetFunc(bt, restrictbutton_gr_restrict_select, scene, gr); restrict_bool = group_restrict_flag(gr, OB_RESTRICT_RENDER); - bt = uiDefIconBut(block, ICONTOG, 0, restrict_bool ? ICON_RESTRICT_RENDER_ON : ICON_RESTRICT_RENDER_OFF, (int)ar->v2d.cur.xmax - OL_TOG_RESTRICT_RENDERX, (int)te->ys, UI_UNIT_X - 1, UI_UNIT_Y - 1, NULL, 0, 0, 0, 0, "Restrict/Allow renderability"); + bt = uiDefIconBut(block, ICONTOG, 0, restrict_bool ? ICON_RESTRICT_RENDER_ON : ICON_RESTRICT_RENDER_OFF, (int)ar->v2d.cur.xmax - OL_TOG_RESTRICT_RENDERX, (int)te->ys, UI_UNIT_X, UI_UNIT_Y, NULL, 0, 0, 0, 0, "Restrict/Allow renderability"); uiButSetFunc(bt, restrictbutton_gr_restrict_render, scene, gr); uiBlockSetEmboss(block, UI_EMBOSS); @@ -463,7 +463,7 @@ static void outliner_draw_restrictbuts(uiBlock *block, Scene *scene, ARegion *ar uiBlockSetEmboss(block, UI_EMBOSSN); bt = uiDefIconButBitI(block, ICONTOGN, SCE_LAY_DISABLE, 0, ICON_CHECKBOX_HLT - 1, - (int)ar->v2d.cur.xmax - OL_TOG_RESTRICT_VIEWX, (int)te->ys, UI_UNIT_X - 1, UI_UNIT_Y - 1, te->directdata, 0, 0, 0, 0, "Render this RenderLayer"); + (int)ar->v2d.cur.xmax - OL_TOG_RESTRICT_VIEWX, (int)te->ys, UI_UNIT_X, UI_UNIT_Y, te->directdata, 0, 0, 0, 0, "Render this RenderLayer"); uiButSetFunc(bt, restrictbutton_r_lay_cb, tselem->id, NULL); uiBlockSetEmboss(block, UI_EMBOSS); @@ -476,13 +476,13 @@ static void outliner_draw_restrictbuts(uiBlock *block, Scene *scene, ARegion *ar bt = uiDefIconButBitI(block, ICONTOG, passflag, 0, ICON_CHECKBOX_HLT - 1, - (int)ar->v2d.cur.xmax - OL_TOG_RESTRICT_VIEWX, (int)te->ys, UI_UNIT_X - 1, UI_UNIT_Y - 1, layflag, 0, 0, 0, 0, "Render this Pass"); + (int)ar->v2d.cur.xmax - OL_TOG_RESTRICT_VIEWX, (int)te->ys, UI_UNIT_X, UI_UNIT_Y, layflag, 0, 0, 0, 0, "Render this Pass"); uiButSetFunc(bt, restrictbutton_r_lay_cb, tselem->id, NULL); layflag++; /* is lay_xor */ if (ELEM8(passflag, SCE_PASS_SPEC, SCE_PASS_SHADOW, SCE_PASS_AO, SCE_PASS_REFLECT, SCE_PASS_REFRACT, SCE_PASS_INDIRECT, SCE_PASS_EMIT, SCE_PASS_ENVIRONMENT)) bt = uiDefIconButBitI(block, TOG, passflag, 0, (*layflag & passflag) ? ICON_DOT : ICON_BLANK1, - (int)ar->v2d.cur.xmax - OL_TOG_RESTRICT_SELECTX, (int)te->ys, UI_UNIT_X - 1, UI_UNIT_Y - 1, layflag, 0, 0, 0, 0, "Exclude this Pass from Combined"); + (int)ar->v2d.cur.xmax - OL_TOG_RESTRICT_SELECTX, (int)te->ys, UI_UNIT_X, UI_UNIT_Y, layflag, 0, 0, 0, 0, "Exclude this Pass from Combined"); uiButSetFunc(bt, restrictbutton_r_lay_cb, tselem->id, NULL); uiBlockSetEmboss(block, UI_EMBOSS); @@ -493,11 +493,11 @@ static void outliner_draw_restrictbuts(uiBlock *block, Scene *scene, ARegion *ar uiBlockSetEmboss(block, UI_EMBOSSN); bt = uiDefIconButBitI(block, ICONTOGN, eModifierMode_Realtime, 0, ICON_RESTRICT_VIEW_OFF, - (int)ar->v2d.cur.xmax - OL_TOG_RESTRICT_VIEWX, (int)te->ys, UI_UNIT_X - 1, UI_UNIT_Y - 1, &(md->mode), 0, 0, 0, 0, "Restrict/Allow visibility in the 3D View"); + (int)ar->v2d.cur.xmax - OL_TOG_RESTRICT_VIEWX, (int)te->ys, UI_UNIT_X, UI_UNIT_Y, &(md->mode), 0, 0, 0, 0, "Restrict/Allow visibility in the 3D View"); uiButSetFunc(bt, restrictbutton_modifier_cb, scene, ob); bt = uiDefIconButBitI(block, ICONTOGN, eModifierMode_Render, 0, ICON_RESTRICT_RENDER_OFF, - (int)ar->v2d.cur.xmax - OL_TOG_RESTRICT_RENDERX, (int)te->ys, UI_UNIT_X - 1, UI_UNIT_Y - 1, &(md->mode), 0, 0, 0, 0, "Restrict/Allow renderability"); + (int)ar->v2d.cur.xmax - OL_TOG_RESTRICT_RENDERX, (int)te->ys, UI_UNIT_X, UI_UNIT_Y, &(md->mode), 0, 0, 0, 0, "Restrict/Allow renderability"); uiButSetFunc(bt, restrictbutton_modifier_cb, scene, ob); } else if (tselem->type == TSE_POSE_CHANNEL) { @@ -506,11 +506,11 @@ static void outliner_draw_restrictbuts(uiBlock *block, Scene *scene, ARegion *ar uiBlockSetEmboss(block, UI_EMBOSSN); bt = uiDefIconButBitI(block, ICONTOG, BONE_HIDDEN_P, 0, ICON_RESTRICT_VIEW_OFF, - (int)ar->v2d.cur.xmax - OL_TOG_RESTRICT_VIEWX, (int)te->ys, UI_UNIT_X - 1, UI_UNIT_Y - 1, &(bone->flag), 0, 0, 0, 0, "Restrict/Allow visibility in the 3D View"); + (int)ar->v2d.cur.xmax - OL_TOG_RESTRICT_VIEWX, (int)te->ys, UI_UNIT_X, UI_UNIT_Y, &(bone->flag), 0, 0, 0, 0, "Restrict/Allow visibility in the 3D View"); uiButSetFunc(bt, restrictbutton_bone_cb, NULL, bone); bt = uiDefIconButBitI(block, ICONTOG, BONE_UNSELECTABLE, 0, ICON_RESTRICT_SELECT_OFF, - (int)ar->v2d.cur.xmax - OL_TOG_RESTRICT_SELECTX, (int)te->ys, UI_UNIT_X - 1, UI_UNIT_Y - 1, &(bone->flag), 0, 0, 0, 0, "Restrict/Allow selection in the 3D View"); + (int)ar->v2d.cur.xmax - OL_TOG_RESTRICT_SELECTX, (int)te->ys, UI_UNIT_X, UI_UNIT_Y, &(bone->flag), 0, 0, 0, 0, "Restrict/Allow selection in the 3D View"); uiButSetFunc(bt, restrictbutton_bone_cb, NULL, NULL); } else if (tselem->type == TSE_EBONE) { @@ -518,11 +518,11 @@ static void outliner_draw_restrictbuts(uiBlock *block, Scene *scene, ARegion *ar uiBlockSetEmboss(block, UI_EMBOSSN); bt = uiDefIconButBitI(block, ICONTOG, BONE_HIDDEN_A, 0, ICON_RESTRICT_VIEW_OFF, - (int)ar->v2d.cur.xmax - OL_TOG_RESTRICT_VIEWX, (int)te->ys, UI_UNIT_X - 1, UI_UNIT_Y - 1, &(ebone->flag), 0, 0, 0, 0, "Restrict/Allow visibility in the 3D View"); + (int)ar->v2d.cur.xmax - OL_TOG_RESTRICT_VIEWX, (int)te->ys, UI_UNIT_X, UI_UNIT_Y, &(ebone->flag), 0, 0, 0, 0, "Restrict/Allow visibility in the 3D View"); uiButSetFunc(bt, restrictbutton_ebone_cb, NULL, ebone); bt = uiDefIconButBitI(block, ICONTOG, BONE_UNSELECTABLE, 0, ICON_RESTRICT_SELECT_OFF, - (int)ar->v2d.cur.xmax - OL_TOG_RESTRICT_SELECTX, (int)te->ys, UI_UNIT_X - 1, UI_UNIT_Y - 1, &(ebone->flag), 0, 0, 0, 0, "Restrict/Allow selection in the 3D View"); + (int)ar->v2d.cur.xmax - OL_TOG_RESTRICT_SELECTX, (int)te->ys, UI_UNIT_X, UI_UNIT_Y, &(ebone->flag), 0, 0, 0, 0, "Restrict/Allow selection in the 3D View"); uiButSetFunc(bt, restrictbutton_ebone_cb, NULL, NULL); } } @@ -1227,12 +1227,12 @@ static void outliner_draw_iconrow(bContext *C, uiBlock *block, Scene *scene, Spa float ufac = UI_UNIT_X / 20.0f; uiSetRoundBox(UI_CNR_ALL); - glColor4ub(255, 255, 255, 128); + glColor4ub(255, 255, 255, 100); uiRoundBox((float) *offsx - 1.0f * ufac, (float)ys + 1.0f * ufac, - (float)*offsx + UI_UNIT_X - 1.0f * ufac, - (float)ys + UI_UNIT_Y - 1.0f * ufac, - (float)UI_UNIT_Y / 2.0f - 2.0f * ufac); + (float)*offsx + UI_UNIT_X - 2.0f * ufac, + (float)ys + UI_UNIT_Y - ufac, + (float)UI_UNIT_Y / 2.0f - ufac); glEnable(GL_BLEND); /* roundbox disables */ } @@ -1365,11 +1365,11 @@ static void outliner_draw_tree_element(bContext *C, uiBlock *block, Scene *scene /* active circle */ if (active) { uiSetRoundBox(UI_CNR_ALL); - uiRoundBox((float)startx + UI_UNIT_X - 1.0f * ufac, + uiRoundBox((float)startx + UI_UNIT_X, (float)*starty + 1.0f * ufac, - (float)startx + 2.0f * UI_UNIT_X - 1.0f * ufac, + (float)startx + 2.0f * UI_UNIT_X - 2.0f * ufac, (float)*starty + UI_UNIT_Y - 1.0f * ufac, - UI_UNIT_Y / 2.0f - 2.0f * ufac); + UI_UNIT_Y / 2.0f - 1.0f * ufac); glEnable(GL_BLEND); /* roundbox disables it */ te->flag |= TE_ACTIVE; // for lookup in display hierarchies @@ -1641,7 +1641,7 @@ static void outliner_draw_restrictcols(ARegion *ar) void draw_outliner(const bContext *C) { - Main *mainvar = CTX_data_main(C); + Main *mainvar = CTX_data_main(C); Scene *scene = CTX_data_scene(C); ARegion *ar = CTX_wm_region(C); View2D *v2d = &ar->v2d; diff --git a/source/blender/editors/space_outliner/outliner_edit.c b/source/blender/editors/space_outliner/outliner_edit.c index d11a8ed6369..a087ff65f63 100644 --- a/source/blender/editors/space_outliner/outliner_edit.c +++ b/source/blender/editors/space_outliner/outliner_edit.c @@ -183,8 +183,8 @@ void OUTLINER_OT_item_openclose(wmOperatorType *ot) static void do_item_rename(ARegion *ar, TreeElement *te, TreeStoreElem *tselem, ReportList *reports) { - /* can't rename rna datablocks entries */ - if (ELEM3(tselem->type, TSE_RNA_STRUCT, TSE_RNA_PROPERTY, TSE_RNA_ARRAY_ELEM)) { + /* can't rename rna datablocks entries or listbases */ + if (ELEM4(tselem->type, TSE_RNA_STRUCT, TSE_RNA_PROPERTY, TSE_RNA_ARRAY_ELEM, TSE_ID_BASE)) { /* do nothing */; } else if (ELEM10(tselem->type, TSE_ANIM_DATA, TSE_NLA, TSE_DEFGROUP_BASE, TSE_CONSTRAINT_BASE, TSE_MODIFIER_BASE, diff --git a/source/blender/editors/space_outliner/outliner_intern.h b/source/blender/editors/space_outliner/outliner_intern.h index 65de2a27568..f9fca378568 100644 --- a/source/blender/editors/space_outliner/outliner_intern.h +++ b/source/blender/editors/space_outliner/outliner_intern.h @@ -103,6 +103,7 @@ typedef struct TreeElement { #define TSE_NLA_TRACK 33 #define TSE_KEYMAP 34 #define TSE_KEYMAP_ITEM 35 +#define TSE_ID_BASE 36 /* button events */ #define OL_NAMEBUTTON 1 diff --git a/source/blender/editors/space_outliner/outliner_select.c b/source/blender/editors/space_outliner/outliner_select.c index 0b585e1272b..fa337ba7af1 100644 --- a/source/blender/editors/space_outliner/outliner_select.c +++ b/source/blender/editors/space_outliner/outliner_select.c @@ -336,7 +336,8 @@ static int tree_element_active_world(bContext *C, Scene *scene, SpaceOops *soops tep = te->parent; if (tep) { tselem = TREESTORE(tep); - sce = (Scene *)tselem->id; + if (tselem->type == 0) + sce = (Scene *)tselem->id; } if (set) { // make new scene active diff --git a/source/blender/editors/space_outliner/outliner_tools.c b/source/blender/editors/space_outliner/outliner_tools.c index 3b83279e09d..b2070cc2f1c 100644 --- a/source/blender/editors/space_outliner/outliner_tools.c +++ b/source/blender/editors/space_outliner/outliner_tools.c @@ -764,7 +764,7 @@ static EnumPropertyItem prop_id_op_types[] = { {OUTLINER_IDOP_LOCAL, "LOCAL", 0, "Make Local", ""}, {OUTLINER_IDOP_SINGLE, "SINGLE", 0, "Make Single User", ""}, {OUTLINER_IDOP_FAKE_ADD, "ADD_FAKE", 0, "Add Fake User", - "Ensure datablock gets saved even if it isn't in use (e.g. for motion and material libraries)"}, + "Ensure datablock gets saved even if it isn't in use (e.g. for motion and material libraries)"}, {OUTLINER_IDOP_FAKE_CLEAR, "CLEAR_FAKE", 0, "Clear Fake User", ""}, {OUTLINER_IDOP_RENAME, "RENAME", 0, "Rename", ""}, {OUTLINER_IDOP_SELECT_LINKED, "SELECT_LINKED", 0, "Select Linked", ""}, diff --git a/source/blender/editors/space_outliner/outliner_tree.c b/source/blender/editors/space_outliner/outliner_tree.c index e6910280da4..ddbc49bf995 100644 --- a/source/blender/editors/space_outliner/outliner_tree.c +++ b/source/blender/editors/space_outliner/outliner_tree.c @@ -66,8 +66,10 @@ #include "BKE_fcurve.h" #include "BKE_main.h" +#include "BKE_library.h" #include "BKE_modifier.h" #include "BKE_sequencer.h" +#include "BKE_idcode.h" #include "ED_armature.h" #include "ED_screen.h" @@ -593,6 +595,7 @@ static void outliner_add_object_contents(SpaceOops *soops, TreeElement *te, Tree outliner_add_element(soops, &te->subtree, ob->dup_group, te, 0, 0); } + // can be inlined if necessary static void outliner_add_id_contents(SpaceOops *soops, TreeElement *te, TreeStoreElem *tselem, ID *id) { @@ -785,6 +788,7 @@ static void outliner_add_id_contents(SpaceOops *soops, TreeElement *te, TreeStor } // TODO: this function needs to be split up! It's getting a bit too large... +// Note: "ID" is not always a real ID static TreeElement *outliner_add_element(SpaceOops *soops, ListBase *lb, void *idv, TreeElement *parent, short type, short index) { @@ -798,7 +802,9 @@ static TreeElement *outliner_add_element(SpaceOops *soops, ListBase *lb, void *i if (!id) id = ((PointerRNA *)idv)->data; } - if (id == NULL) return NULL; + /* One exception */ + if (type == TSE_ID_BASE); + else if (id == NULL) return NULL; te = MEM_callocN(sizeof(TreeElement), "tree elem"); /* add to the visual tree */ @@ -822,14 +828,20 @@ static TreeElement *outliner_add_element(SpaceOops *soops, ListBase *lb, void *i else if (type == TSE_ANIM_DATA) { /* pass */ } + else if (type == TSE_ID_BASE) { + /* pass */ + } else { te->name = id->name + 2; // default, can be overridden by Library or non-ID data te->idcode = GS(id->name); } if (type == 0) { + TreeStoreElem *tsepar = parent ? TREESTORE(parent) : NULL; + /* ID datablock */ - outliner_add_id_contents(soops, te, tselem, id); + if (tsepar==NULL || tsepar->type != TSE_ID_BASE) + outliner_add_id_contents(soops, te, tselem, id); } else if (type == TSE_ANIM_DATA) { IdAdtTemplate *iat = (IdAdtTemplate *)idv; @@ -1194,8 +1206,8 @@ typedef struct tTreeSort { short idcode; } tTreeSort; -/* alphabetical comparator */ -static int treesort_alpha(const void *v1, const void *v2) +/* alphabetical comparator, tryping to put objects first */ +static int treesort_alpha_ob(const void *v1, const void *v2) { const tTreeSort *x1 = v1, *x2 = v2; int comp; @@ -1216,6 +1228,20 @@ static int treesort_alpha(const void *v1, const void *v2) return 0; } +/* alphabetical comparator */ +static int treesort_alpha(const void *v1, const void *v2) +{ + const tTreeSort *x1 = v1, *x2 = v2; + int comp; + + comp = strcmp(x1->name, x2->name); + + if (comp > 0) return 1; + else if (comp < 0) return -1; + return 0; +} + + /* this is nice option for later? doesnt look too useful... */ #if 0 static int treesort_obtype_alpha(const void *v1, const void *v2) @@ -1254,8 +1280,8 @@ static void outliner_sort(SpaceOops *soops, ListBase *lb) if (te == NULL) return; tselem = TREESTORE(te); - /* sorting rules; only object lists or deformgroups */ - if ((tselem->type == TSE_DEFGROUP) || (tselem->type == 0 && te->idcode == ID_OB)) { + /* sorting rules; only object lists, ID lists, or deformgroups */ + if ( ELEM(tselem->type, TSE_DEFGROUP, TSE_ID_BASE) || (tselem->type == 0 && te->idcode == ID_OB)) { /* count first */ for (te = lb->first; te; te = te->next) totelem++; @@ -1270,15 +1296,27 @@ static void outliner_sort(SpaceOops *soops, ListBase *lb) tp->te = te; tp->name = te->name; tp->idcode = te->idcode; - if (tselem->type && tselem->type != TSE_DEFGROUP) tp->idcode = 0; // don't sort this + + if (tselem->type && tselem->type != TSE_DEFGROUP) + tp->idcode = 0; // don't sort this + if (tselem->type == TSE_ID_BASE) + tp->idcode = 1; // do sort this + tp->id = tselem->id; } - /* keep beginning of list */ - for (tp = tear, skip = 0; skip < totelem; skip++, tp++) - if (tp->idcode) break; - if (skip < totelem) - qsort(tear + skip, totelem - skip, sizeof(tTreeSort), treesort_alpha); + /* just sort alphabetically */ + if (tear->idcode == 1) { + qsort(tear, totelem, sizeof(tTreeSort), treesort_alpha); + } + else { + /* keep beginning of list */ + for (tp = tear, skip = 0; skip < totelem; skip++, tp++) + if (tp->idcode) break; + + if (skip < totelem) + qsort(tear + skip, totelem - skip, sizeof(tTreeSort), treesort_alpha_ob); + } lb->first = lb->last = NULL; tp = tear; @@ -1384,6 +1422,42 @@ static int outliner_filter_tree(SpaceOops *soops, ListBase *lb) return (lb->first != NULL); } +static void outliner_add_library_contents(Main *mainvar, SpaceOops *soops, TreeElement *te, Library *lib) +{ + TreeElement *ten; + ListBase *lbarray[MAX_LIBARRAY]; + int a, tot; + + tot = set_listbasepointers(mainvar, lbarray); + for (a = 0; a < tot; a++) { + if (lbarray[a]->first) { + ID *id = lbarray[a]->first; + + /* check if there's data in current lib */ + for (; id; id = id->next) + if (id->lib == lib) + break; + + if (id) { + + ten = outliner_add_element(soops, &te->subtree, (void *)lbarray[a], NULL, TSE_ID_BASE, 0); + ten->directdata = lbarray[a]; + + ten->name = (char *)BKE_idcode_to_name_plural(GS(id->name)); + if (ten->name == NULL) + ten->name = "UNKNOWN"; + + for (id = lbarray[a]->first; id; id = id->next) { + if (id->lib == lib) + outliner_add_element(soops, &ten->subtree, id, ten, 0, 0); + } + } + } + } + +} + + /* ======================================================= */ /* Main Tree Building API */ @@ -1418,17 +1492,31 @@ void outliner_build_tree(Main *mainvar, Scene *scene, SpaceOops *soops) if (soops->outlinevis == SO_LIBRARIES) { Library *lib; + /* current file first - mainvar provides tselem with unique pointer - not used */ + ten = outliner_add_element(soops, &soops->tree, mainvar, NULL, TSE_ID_BASE, 0); + ten->name = "Current File"; + + tselem = TREESTORE(ten); + if (!tselem->used) + tselem->flag &= ~TSE_CLOSED; + + outliner_add_library_contents(mainvar, soops, ten, NULL); + for (lib = mainvar->library.first; lib; lib = lib->id.next) { ten = outliner_add_element(soops, &soops->tree, lib, NULL, 0, 0); lib->id.newid = (ID *)ten; + + outliner_add_library_contents(mainvar, soops, ten, lib); + } /* make hierarchy */ ten = soops->tree.first; + ten= ten->next; /* first one is main */ while (ten) { TreeElement *nten = ten->next, *par; tselem = TREESTORE(ten); lib = (Library *)tselem->id; - if (lib->parent) { + if (lib && lib->parent) { BLI_remlink(&soops->tree, ten); par = (TreeElement *)lib->parent->id.newid; BLI_addtail(&par->subtree, ten); diff --git a/source/blender/editors/space_sequencer/sequencer_add.c b/source/blender/editors/space_sequencer/sequencer_add.c index 8155f9d645e..6219a9061f4 100644 --- a/source/blender/editors/space_sequencer/sequencer_add.c +++ b/source/blender/editors/space_sequencer/sequencer_add.c @@ -859,9 +859,9 @@ static int sequencer_add_effect_strip_exec(bContext *C, wmOperator *op) * the other strips. */ if (!RNA_struct_property_is_set(op->ptr, "channel")) { if (seq->seq1) { - int chan = MAX3(seq->seq1 ? seq->seq1->machine : 0, - seq->seq2 ? seq->seq2->machine : 0, - seq->seq3 ? seq->seq3->machine : 0); + int chan = max_iii(seq->seq1 ? seq->seq1->machine : 0, + seq->seq2 ? seq->seq2->machine : 0, + seq->seq3 ? seq->seq3->machine : 0); if (chan < MAXSEQ) seq->machine = chan; } diff --git a/source/blender/editors/space_text/CMakeLists.txt b/source/blender/editors/space_text/CMakeLists.txt index 9cc407f0604..6aaf4212779 100644 --- a/source/blender/editors/space_text/CMakeLists.txt +++ b/source/blender/editors/space_text/CMakeLists.txt @@ -37,10 +37,13 @@ set(INC_SYS set(SRC space_text.c text_draw.c + text_format.c + text_format_py.c text_header.c text_ops.c text_python.c + text_format.h text_intern.h ) diff --git a/source/blender/editors/space_text/space_text.c b/source/blender/editors/space_text/space_text.c index d74e32620af..9ac66ca1698 100644 --- a/source/blender/editors/space_text/space_text.c +++ b/source/blender/editors/space_text/space_text.c @@ -30,17 +30,12 @@ #include <string.h> -#include <stdio.h> #include "DNA_text_types.h" -#include "DNA_object_types.h" #include "MEM_guardedalloc.h" #include "BLI_blenlib.h" -#include "BLI_math.h" -#include "BLI_rand.h" -#include "BLI_utildefines.h" #include "BKE_context.h" #include "BKE_screen.h" @@ -61,7 +56,8 @@ #include "RNA_access.h" -#include "text_intern.h" // own include +#include "text_format.h" +#include "text_intern.h" /* own include */ /* ******************** default callbacks for text space ***************** */ @@ -556,5 +552,8 @@ void ED_spacetype_text(void) BLI_addhead(&st->regiontypes, art); BKE_spacetype_register(st); + + /* register formatters */ + ED_text_format_register_py(); } diff --git a/source/blender/editors/space_text/text_draw.c b/source/blender/editors/space_text/text_draw.c index 24f40dbbe2a..7d4c9e5af98 100644 --- a/source/blender/editors/space_text/text_draw.c +++ b/source/blender/editors/space_text/text_draw.c @@ -29,10 +29,6 @@ */ -#include <math.h> -#include <stdlib.h> -#include <string.h> -#include <sys/stat.h> #include "MEM_guardedalloc.h" @@ -40,12 +36,10 @@ #include "BLI_blenlib.h" #include "BLI_math.h" -#include "BLI_utildefines.h" #include "DNA_text_types.h" #include "DNA_space_types.h" #include "DNA_screen_types.h" -#include "DNA_userdef_types.h" #include "BKE_context.h" #include "BKE_suggestions.h" @@ -53,11 +47,12 @@ #include "BIF_gl.h" -#include "ED_datafiles.h" #include "UI_interface.h" #include "UI_resources.h" +#include "UI_view2d.h" #include "text_intern.h" +#include "text_format.h" /******************** text font drawing ******************/ // XXX, fixme @@ -105,350 +100,6 @@ static int text_font_draw_character_utf8(SpaceText *st, int x, int y, const char return st->cwidth; } -/****************** flatten string **********************/ - -static void flatten_string_append(FlattenString *fs, const char *c, int accum, int len) -{ - int i; - - if (fs->pos + len > fs->len) { - char *nbuf; int *naccum; - fs->len *= 2; - - nbuf = MEM_callocN(sizeof(*fs->buf) * fs->len, "fs->buf"); - naccum = MEM_callocN(sizeof(*fs->accum) * fs->len, "fs->accum"); - - memcpy(nbuf, fs->buf, fs->pos * sizeof(*fs->buf)); - memcpy(naccum, fs->accum, fs->pos * sizeof(*fs->accum)); - - if (fs->buf != fs->fixedbuf) { - MEM_freeN(fs->buf); - MEM_freeN(fs->accum); - } - - fs->buf = nbuf; - fs->accum = naccum; - } - - for (i = 0; i < len; i++) { - fs->buf[fs->pos + i] = c[i]; - fs->accum[fs->pos + i] = accum; - } - - fs->pos += len; -} - -int flatten_string(SpaceText *st, FlattenString *fs, const char *in) -{ - int r, i, total = 0; - - memset(fs, 0, sizeof(FlattenString)); - fs->buf = fs->fixedbuf; - fs->accum = fs->fixedaccum; - fs->len = sizeof(fs->fixedbuf); - - for (r = 0, i = 0; *in; r++) { - if (*in == '\t') { - i = st->tabnumber - (total % st->tabnumber); - total += i; - - while (i--) - flatten_string_append(fs, " ", r, 1); - - in++; - } - else { - size_t len = BLI_str_utf8_size_safe(in); - flatten_string_append(fs, in, r, len); - in += len; - total++; - } - } - - flatten_string_append(fs, "\0", r, 1); - - return total; -} - -void flatten_string_free(FlattenString *fs) -{ - if (fs->buf != fs->fixedbuf) - MEM_freeN(fs->buf); - if (fs->accum != fs->fixedaccum) - MEM_freeN(fs->accum); -} - -/* Checks the specified source string for a Python built-in function name. This - * name must start at the beginning of the source string and must be followed by - * a non-identifier (see text_check_identifier(char)) or null character. - * - * If a built-in function is found, the length of the matching name is returned. - * Otherwise, -1 is returned. - * - * See: - * http://docs.python.org/py3k/reference/lexical_analysis.html#keywords - */ - -static int find_builtinfunc(char *string) -{ - int a, i; - const char *builtinfuncs[] = { - /* "False", "None", "True", */ /* see find_bool() */ - "and", "as", "assert", "break", - "class", "continue", "def", "del", "elif", "else", "except", - "finally", "for", "from", "global", "if", "import", "in", - "is", "lambda", "nonlocal", "not", "or", "pass", "raise", - "return", "try", "while", "with", "yield", - }; - - for (a = 0; a < sizeof(builtinfuncs) / sizeof(builtinfuncs[0]); a++) { - i = 0; - while (1) { - /* If we hit the end of a keyword... (eg. "def") */ - if (builtinfuncs[a][i] == '\0') { - /* If we still have identifier chars in the source (eg. "definate") */ - if (text_check_identifier(string[i])) - i = -1; /* No match */ - break; /* Next keyword if no match, otherwise we're done */ - - /* If chars mismatch, move on to next keyword */ - } - else if (string[i] != builtinfuncs[a][i]) { - i = -1; - break; /* Break inner loop, start next keyword */ - } - i++; - } - if (i > 0) break; /* If we have a match, we're done */ - } - return i; -} - -/* Checks the specified source string for a Python special name. This name must - * start at the beginning of the source string and must be followed by a non- - * identifier (see text_check_identifier(char)) or null character. - * - * If a special name is found, the length of the matching name is returned. - * Otherwise, -1 is returned. */ - -static int find_specialvar(char *string) -{ - int i = 0; - /* Check for "def" */ - if (string[0] == 'd' && string[1] == 'e' && string[2] == 'f') - i = 3; - /* Check for "class" */ - else if (string[0] == 'c' && string[1] == 'l' && string[2] == 'a' && string[3] == 's' && string[4] == 's') - i = 5; - /* If next source char is an identifier (eg. 'i' in "definate") no match */ - if (i == 0 || text_check_identifier(string[i])) - return -1; - return i; -} - -static int find_decorator(char *string) -{ - if (string[0] == '@') { - int i = 1; - while (text_check_identifier(string[i])) { - i++; - } - return i; - } - return -1; -} - -static int find_bool(char *string) -{ - int i = 0; - /* Check for "False" */ - if (string[0] == 'F' && string[1] == 'a' && string[2] == 'l' && string[3] == 's' && string[4] == 'e') - i = 5; - /* Check for "True" */ - else if (string[0] == 'T' && string[1] == 'r' && string[2] == 'u' && string[3] == 'e') - i = 4; - /* Check for "None" */ - else if (string[0] == 'N' && string[1] == 'o' && string[2] == 'n' && string[3] == 'e') - i = 4; - /* If next source char is an identifier (eg. 'i' in "definate") no match */ - if (i == 0 || text_check_identifier(string[i])) - return -1; - return i; -} - -/* Ensures the format string for the given line is long enough, reallocating - * as needed. Allocation is done here, alone, to ensure consistency. */ -static int text_check_format_len(TextLine *line, unsigned int len) -{ - if (line->format) { - if (strlen(line->format) < len) { - MEM_freeN(line->format); - line->format = MEM_mallocN(len + 2, "SyntaxFormat"); - if (!line->format) return 0; - } - } - else { - line->format = MEM_mallocN(len + 2, "SyntaxFormat"); - if (!line->format) return 0; - } - - return 1; -} - -/* Formats the specified line. If do_next is set, the process will move on to - * the succeeding line if it is affected (eg. multiline strings). Format strings - * may contain any of the following characters: - * '_' Whitespace - * '#' Comment text - * '!' Punctuation and other symbols - * 'n' Numerals - * 'l' String letters - * 'v' Special variables (class, def) - * 'b' Built-in names (print, for, etc.) - * 'q' Other text (identifiers, etc.) - * It is terminated with a null-terminator '\0' followed by a continuation - * flag indicating whether the line is part of a multi-line string. */ - -static void txt_format_line(SpaceText *st, TextLine *line, int do_next) -{ - FlattenString fs; - char *str, *fmt, orig, cont, find, prev = ' '; - int len, i; - - /* Get continuation from previous line */ - if (line->prev && line->prev->format != NULL) { - fmt = line->prev->format; - cont = fmt[strlen(fmt) + 1]; /* Just after the null-terminator */ - } - else cont = 0; - - /* Get original continuation from this line */ - if (line->format != NULL) { - fmt = line->format; - orig = fmt[strlen(fmt) + 1]; /* Just after the null-terminator */ - } - else orig = 0xFF; - - len = flatten_string(st, &fs, line->line); - str = fs.buf; - if (!text_check_format_len(line, len)) { - flatten_string_free(&fs); - return; - } - fmt = line->format; - - while (*str) { - /* Handle escape sequences by skipping both \ and next char */ - if (*str == '\\') { - *fmt = prev; fmt++; str++; - if (*str == '\0') break; - *fmt = prev; fmt++; str += BLI_str_utf8_size_safe(str); - continue; - } - /* Handle continuations */ - else if (cont) { - /* Triple strings ("""...""" or '''...''') */ - if (cont & TXT_TRISTR) { - find = (cont & TXT_DBLQUOTSTR) ? '"' : '\''; - if (*str == find && *(str + 1) == find && *(str + 2) == find) { - *fmt = 'l'; fmt++; str++; - *fmt = 'l'; fmt++; str++; - cont = 0; - } - /* Handle other strings */ - } - else { - find = (cont & TXT_DBLQUOTSTR) ? '"' : '\''; - if (*str == find) cont = 0; - } - - *fmt = 'l'; - str += BLI_str_utf8_size_safe(str) - 1; - } - /* Not in a string... */ - else { - /* Deal with comments first */ - if (prev == '#' || *str == '#') { - *fmt = '#'; - str += BLI_str_utf8_size_safe(str) - 1; - } - else if (*str == '"' || *str == '\'') { - /* Strings */ - find = *str; - cont = (*str == '"') ? TXT_DBLQUOTSTR : TXT_SNGQUOTSTR; - if (*(str + 1) == find && *(str + 2) == find) { - *fmt = 'l'; fmt++; str++; - *fmt = 'l'; fmt++; str++; - cont |= TXT_TRISTR; - } - *fmt = 'l'; - } - /* Whitespace (all ws. has been converted to spaces) */ - else if (*str == ' ') - *fmt = '_'; - /* Numbers (digits not part of an identifier and periods followed by digits) */ - else if ((prev != 'q' && text_check_digit(*str)) || (*str == '.' && text_check_digit(*(str + 1)))) - *fmt = 'n'; - /* Booleans */ - else if (prev != 'q' && (i = find_bool(str)) != -1) - if (i > 0) { - while (i > 1) { - *fmt = 'n'; fmt++; str++; - i--; - } - *fmt = 'n'; - } - else { - str += BLI_str_utf8_size_safe(str) - 1; - *fmt = 'q'; - } - /* Punctuation */ - else if (text_check_delim(*str)) - *fmt = '!'; - /* Identifiers and other text (no previous ws. or delims. so text continues) */ - else if (prev == 'q') { - str += BLI_str_utf8_size_safe(str) - 1; - *fmt = 'q'; - } - /* Not ws, a digit, punct, or continuing text. Must be new, check for special words */ - else { - /* Special vars(v) or built-in keywords(b) */ - if ((i = find_specialvar(str)) != -1) - prev = 'v'; - else if ((i = find_builtinfunc(str)) != -1) - prev = 'b'; - else if ((i = find_decorator(str)) != -1) - prev = 'v'; /* could have a new color for this */ - if (i > 0) { - while (i > 1) { - *fmt = prev; fmt++; str++; - i--; - } - *fmt = prev; - } - else { - str += BLI_str_utf8_size_safe(str) - 1; - *fmt = 'q'; - } - } - } - prev = *fmt; - fmt++; - str++; - } - - /* Terminate and add continuation char */ - *fmt = '\0'; fmt++; - *fmt = cont; - - /* If continuation has changed and we're allowed, process the next line */ - if (cont != orig && do_next && line->next) { - txt_format_line(st, line->next, do_next); - } - - flatten_string_free(&fs); -} - #if 0 /* Formats every line of the current text */ static void txt_format_text(SpaceText *st) @@ -1085,12 +736,12 @@ static void calc_text_rcts(SpaceText *st, ARegion *ar, rcti *scroll, rcti *back) blank_lines = st->viewlines / 2; /* nicer code: use scroll rect for entire bar */ - back->xmin = ar->winx - 18; + back->xmin = ar->winx - (V2D_SCROLL_WIDTH + 1); back->xmax = ar->winx; back->ymin = 0; back->ymax = ar->winy; - scroll->xmin = ar->winx - 17; + scroll->xmin = ar->winx - V2D_SCROLL_WIDTH; scroll->xmax = ar->winx - 5; scroll->ymin = 4; scroll->ymax = 4 + pix_available; @@ -1394,7 +1045,7 @@ static void draw_cursor(SpaceText *st, ARegion *ar) UI_ThemeColor(TH_SHADE2); x = st->showlinenrs ? TXT_OFFSET + TEXTXLOC : TXT_OFFSET; - y = ar->winy - 2; + y = ar->winy; if (vcurl == vsell) { y -= vcurl * lheight; @@ -1469,7 +1120,7 @@ static void draw_cursor(SpaceText *st, ARegion *ar) /* Draw the cursor itself (we draw the sel. cursor as this is the leading edge) */ x = st->showlinenrs ? TXT_OFFSET + TEXTXLOC : TXT_OFFSET; x += vselc * st->cwidth; - y = ar->winy - 2 - vsell * lheight; + y = ar->winy - vsell * lheight; if (st->overwrite) { char ch = text->sell->line[text->selc]; @@ -1620,6 +1271,7 @@ static void draw_brackets(SpaceText *st, ARegion *ar) void draw_text_main(SpaceText *st, ARegion *ar) { Text *text = st->text; + TextFormatType *tft = ED_text_format_get(text); TextLine *tmp; rcti scroll, back; char linenr[12]; @@ -1651,7 +1303,7 @@ void draw_text_main(SpaceText *st, ARegion *ar) lineno = 0; for (i = 0; i < st->top && tmp; i++) { if (st->showsyntax && !tmp->format) - txt_format_line(st, tmp, 0); + tft->format_line(st, tmp, 0); if (st->wordwrap) { int lines = text_get_visible_lines_no(st, lineno); @@ -1700,7 +1352,7 @@ void draw_text_main(SpaceText *st, ARegion *ar) for (i = 0; y > 0 && i < st->viewlines && tmp; i++, tmp = tmp->next) { if (st->showsyntax && !tmp->format) - txt_format_line(st, tmp, 0); + tft->format_line(st, tmp, 0); if (st->showlinenrs && !wrap_skip) { /* draw line number */ diff --git a/source/blender/editors/space_text/text_format.c b/source/blender/editors/space_text/text_format.c new file mode 100644 index 00000000000..0b3856f4414 --- /dev/null +++ b/source/blender/editors/space_text/text_format.c @@ -0,0 +1,148 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): none yet. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file blender/editors/space_text/text_format.c + * \ingroup sptext + */ + +#include <string.h> + +#include "MEM_guardedalloc.h" + +#include "BLI_blenlib.h" + +#include "DNA_text_types.h" +#include "DNA_space_types.h" + +#include "text_format.h" + + +/****************** flatten string **********************/ + +static void flatten_string_append(FlattenString *fs, const char *c, int accum, int len) +{ + int i; + + if (fs->pos + len > fs->len) { + char *nbuf; int *naccum; + fs->len *= 2; + + nbuf = MEM_callocN(sizeof(*fs->buf) * fs->len, "fs->buf"); + naccum = MEM_callocN(sizeof(*fs->accum) * fs->len, "fs->accum"); + + memcpy(nbuf, fs->buf, fs->pos * sizeof(*fs->buf)); + memcpy(naccum, fs->accum, fs->pos * sizeof(*fs->accum)); + + if (fs->buf != fs->fixedbuf) { + MEM_freeN(fs->buf); + MEM_freeN(fs->accum); + } + + fs->buf = nbuf; + fs->accum = naccum; + } + + for (i = 0; i < len; i++) { + fs->buf[fs->pos + i] = c[i]; + fs->accum[fs->pos + i] = accum; + } + + fs->pos += len; +} + +int flatten_string(SpaceText *st, FlattenString *fs, const char *in) +{ + int r, i, total = 0; + + memset(fs, 0, sizeof(FlattenString)); + fs->buf = fs->fixedbuf; + fs->accum = fs->fixedaccum; + fs->len = sizeof(fs->fixedbuf); + + for (r = 0, i = 0; *in; r++) { + if (*in == '\t') { + i = st->tabnumber - (total % st->tabnumber); + total += i; + + while (i--) + flatten_string_append(fs, " ", r, 1); + + in++; + } + else { + size_t len = BLI_str_utf8_size_safe(in); + flatten_string_append(fs, in, r, len); + in += len; + total++; + } + } + + flatten_string_append(fs, "\0", r, 1); + + return total; +} + +void flatten_string_free(FlattenString *fs) +{ + if (fs->buf != fs->fixedbuf) + MEM_freeN(fs->buf); + if (fs->accum != fs->fixedaccum) + MEM_freeN(fs->accum); +} + +/* Ensures the format string for the given line is long enough, reallocating + * as needed. Allocation is done here, alone, to ensure consistency. */ +int text_check_format_len(TextLine *line, unsigned int len) +{ + if (line->format) { + if (strlen(line->format) < len) { + MEM_freeN(line->format); + line->format = MEM_mallocN(len + 2, "SyntaxFormat"); + if (!line->format) return 0; + } + } + else { + line->format = MEM_mallocN(len + 2, "SyntaxFormat"); + if (!line->format) return 0; + } + + return 1; +} + +/* *** Registration *** */ +static ListBase tft_lb = {NULL, NULL}; +void ED_text_format_register(TextFormatType *tft) +{ + BLI_addtail(&tft_lb, tft); +} + +TextFormatType *ED_text_format_get(Text *UNUSED(text)) +{ + /* NOTE: once more types are added we'll need to return some type based on 'text' + * for now this function is more of a placeholder */ + + return tft_lb.first; +} diff --git a/source/blender/editors/space_text/text_format.h b/source/blender/editors/space_text/text_format.h new file mode 100644 index 00000000000..7b5b326db6a --- /dev/null +++ b/source/blender/editors/space_text/text_format.h @@ -0,0 +1,77 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2009 Blender Foundation. + * All rights reserved. + * + * + * Contributor(s): Blender Foundation + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file blender/editors/space_text/text_format.h + * \ingroup sptext + */ + +#ifndef __TEXT_FORMAT_H__ +#define __TEXT_FORMAT_H__ + +/* *** Flatten String *** */ +typedef struct FlattenString { + char fixedbuf[256]; + int fixedaccum[256]; + + char *buf; + int *accum; + int pos, len; +} FlattenString; + +int flatten_string(struct SpaceText *st, FlattenString *fs, const char *in); +void flatten_string_free(FlattenString *fs); +int text_check_format_len(TextLine *line, unsigned int len); + + +/* *** Generalize Formatting *** */ +typedef struct TextFormatType { + struct TextFormatType *next, *prev; + + /* Formats the specified line. If do_next is set, the process will move on to + * the succeeding line if it is affected (eg. multiline strings). Format strings + * may contain any of the following characters: + * '_' Whitespace + * '#' Comment text + * '!' Punctuation and other symbols + * 'n' Numerals + * 'l' String letters + * 'v' Special variables (class, def) + * 'b' Built-in names (print, for, etc.) + * 'q' Other text (identifiers, etc.) + * It is terminated with a null-terminator '\0' followed by a continuation + * flag indicating whether the line is part of a multi-line string. */ + void (*format_line)(SpaceText *st, TextLine *line, int do_next); + + const char **ext; /* NULL terminated extensions */ +} TextFormatType; + +TextFormatType *ED_text_format_get(Text *text); +void ED_text_format_register(TextFormatType *tft); + +/* formatters */ +void ED_text_format_register_py(void); + +#endif /* __TEXT_FORMAT_H__ */ diff --git a/source/blender/editors/space_text/text_format_py.c b/source/blender/editors/space_text/text_format_py.c new file mode 100644 index 00000000000..2a0f483d80c --- /dev/null +++ b/source/blender/editors/space_text/text_format_py.c @@ -0,0 +1,296 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): none yet. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file blender/editors/space_text/text_format_py.c + * \ingroup sptext + */ + +#include <string.h> + +#include "BLI_blenlib.h" + +#include "DNA_text_types.h" +#include "DNA_space_types.h" + +#include "BKE_text.h" + +#include "text_format.h" + +/* *** Local Functions (for format_line) *** */ + + +/* Checks the specified source string for a Python built-in function name. This + * name must start at the beginning of the source string and must be followed by + * a non-identifier (see text_check_identifier(char)) or null character. + * + * If a built-in function is found, the length of the matching name is returned. + * Otherwise, -1 is returned. + * + * See: + * http://docs.python.org/py3k/reference/lexical_analysis.html#keywords + */ + +static int txtfmt_py_find_builtinfunc(char *string) +{ + int a, i; + const char *builtinfuncs[] = { + /* "False", "None", "True", */ /* see find_bool() */ + "and", "as", "assert", "break", + "class", "continue", "def", "del", "elif", "else", "except", + "finally", "for", "from", "global", "if", "import", "in", + "is", "lambda", "nonlocal", "not", "or", "pass", "raise", + "return", "try", "while", "with", "yield", + }; + + for (a = 0; a < sizeof(builtinfuncs) / sizeof(builtinfuncs[0]); a++) { + i = 0; + while (1) { + /* If we hit the end of a keyword... (eg. "def") */ + if (builtinfuncs[a][i] == '\0') { + /* If we still have identifier chars in the source (eg. "definate") */ + if (text_check_identifier(string[i])) + i = -1; /* No match */ + break; /* Next keyword if no match, otherwise we're done */ + + /* If chars mismatch, move on to next keyword */ + } + else if (string[i] != builtinfuncs[a][i]) { + i = -1; + break; /* Break inner loop, start next keyword */ + } + i++; + } + if (i > 0) break; /* If we have a match, we're done */ + } + return i; +} + +/* Checks the specified source string for a Python special name. This name must + * start at the beginning of the source string and must be followed by a non- + * identifier (see text_check_identifier(char)) or null character. + * + * If a special name is found, the length of the matching name is returned. + * Otherwise, -1 is returned. */ + +static int txtfmt_py_find_specialvar(char *string) +{ + int i = 0; + /* Check for "def" */ + if (string[0] == 'd' && string[1] == 'e' && string[2] == 'f') + i = 3; + /* Check for "class" */ + else if (string[0] == 'c' && string[1] == 'l' && string[2] == 'a' && string[3] == 's' && string[4] == 's') + i = 5; + /* If next source char is an identifier (eg. 'i' in "definate") no match */ + if (i == 0 || text_check_identifier(string[i])) + return -1; + return i; +} + +static int txtfmt_py_find_decorator(char *string) +{ + if (string[0] == '@') { + int i = 1; + while (text_check_identifier(string[i])) { + i++; + } + return i; + } + return -1; +} + +static int txtfmt_py_find_bool(char *string) +{ + int i = 0; + /* Check for "False" */ + if (string[0] == 'F' && string[1] == 'a' && string[2] == 'l' && string[3] == 's' && string[4] == 'e') + i = 5; + /* Check for "True" */ + else if (string[0] == 'T' && string[1] == 'r' && string[2] == 'u' && string[3] == 'e') + i = 4; + /* Check for "None" */ + else if (string[0] == 'N' && string[1] == 'o' && string[2] == 'n' && string[3] == 'e') + i = 4; + /* If next source char is an identifier (eg. 'i' in "definate") no match */ + if (i == 0 || text_check_identifier(string[i])) + return -1; + return i; +} + +static void txtfmt_py_format_line(SpaceText *st, TextLine *line, int do_next) +{ + FlattenString fs; + char *str, *fmt, orig, cont, find, prev = ' '; + int len, i; + + /* Get continuation from previous line */ + if (line->prev && line->prev->format != NULL) { + fmt = line->prev->format; + cont = fmt[strlen(fmt) + 1]; /* Just after the null-terminator */ + } + else { + cont = 0; + } + + /* Get original continuation from this line */ + if (line->format != NULL) { + fmt = line->format; + orig = fmt[strlen(fmt) + 1]; /* Just after the null-terminator */ + } + else { + orig = 0xFF; + } + + len = flatten_string(st, &fs, line->line); + str = fs.buf; + if (!text_check_format_len(line, len)) { + flatten_string_free(&fs); + return; + } + fmt = line->format; + + while (*str) { + /* Handle escape sequences by skipping both \ and next char */ + if (*str == '\\') { + *fmt = prev; fmt++; str++; + if (*str == '\0') break; + *fmt = prev; fmt++; str += BLI_str_utf8_size_safe(str); + continue; + } + /* Handle continuations */ + else if (cont) { + /* Triple strings ("""...""" or '''...''') */ + if (cont & TXT_TRISTR) { + find = (cont & TXT_DBLQUOTSTR) ? '"' : '\''; + if (*str == find && *(str + 1) == find && *(str + 2) == find) { + *fmt = 'l'; fmt++; str++; + *fmt = 'l'; fmt++; str++; + cont = 0; + } + /* Handle other strings */ + } + else { + find = (cont & TXT_DBLQUOTSTR) ? '"' : '\''; + if (*str == find) cont = 0; + } + + *fmt = 'l'; + str += BLI_str_utf8_size_safe(str) - 1; + } + /* Not in a string... */ + else { + /* Deal with comments first */ + if (prev == '#' || *str == '#') { + *fmt = '#'; + str += BLI_str_utf8_size_safe(str) - 1; + } + else if (*str == '"' || *str == '\'') { + /* Strings */ + find = *str; + cont = (*str == '"') ? TXT_DBLQUOTSTR : TXT_SNGQUOTSTR; + if (*(str + 1) == find && *(str + 2) == find) { + *fmt = 'l'; fmt++; str++; + *fmt = 'l'; fmt++; str++; + cont |= TXT_TRISTR; + } + *fmt = 'l'; + } + /* Whitespace (all ws. has been converted to spaces) */ + else if (*str == ' ') + *fmt = '_'; + /* Numbers (digits not part of an identifier and periods followed by digits) */ + else if ((prev != 'q' && text_check_digit(*str)) || (*str == '.' && text_check_digit(*(str + 1)))) + *fmt = 'n'; + /* Booleans */ + else if (prev != 'q' && (i = txtfmt_py_find_bool(str)) != -1) + if (i > 0) { + while (i > 1) { + *fmt = 'n'; fmt++; str++; + i--; + } + *fmt = 'n'; + } + else { + str += BLI_str_utf8_size_safe(str) - 1; + *fmt = 'q'; + } + /* Punctuation */ + else if (text_check_delim(*str)) + *fmt = '!'; + /* Identifiers and other text (no previous ws. or delims. so text continues) */ + else if (prev == 'q') { + str += BLI_str_utf8_size_safe(str) - 1; + *fmt = 'q'; + } + /* Not ws, a digit, punct, or continuing text. Must be new, check for special words */ + else { + /* Special vars(v) or built-in keywords(b) */ + if ((i = txtfmt_py_find_specialvar(str)) != -1) + prev = 'v'; + else if ((i = txtfmt_py_find_builtinfunc(str)) != -1) + prev = 'b'; + else if ((i = txtfmt_py_find_decorator(str)) != -1) + prev = 'v'; /* could have a new color for this */ + if (i > 0) { + while (i > 1) { + *fmt = prev; fmt++; str++; + i--; + } + *fmt = prev; + } + else { + str += BLI_str_utf8_size_safe(str) - 1; + *fmt = 'q'; + } + } + } + prev = *fmt; + fmt++; + str++; + } + + /* Terminate and add continuation char */ + *fmt = '\0'; fmt++; + *fmt = cont; + + /* If continuation has changed and we're allowed, process the next line */ + if (cont != orig && do_next && line->next) { + txtfmt_py_format_line(st, line->next, do_next); + } + + flatten_string_free(&fs); +} + +void ED_text_format_register_py(void) +{ + static TextFormatType tft = {0}; + static const char *ext[] = {"py", NULL}; + + tft.format_line = txtfmt_py_format_line; + tft.ext = ext; + + ED_text_format_register(&tft); +} diff --git a/source/blender/editors/space_text/text_header.c b/source/blender/editors/space_text/text_header.c index 7dc3ec1ac60..52253b2d5d2 100644 --- a/source/blender/editors/space_text/text_header.c +++ b/source/blender/editors/space_text/text_header.c @@ -29,20 +29,11 @@ */ -#include <stdlib.h> -#include <string.h> -#include <stdio.h> /* file time checking */ -#include <ctype.h> -#include <sys/types.h> -#include <sys/stat.h> #ifndef _WIN32 -# include <unistd.h> #else -# include <io.h> -# include "BLI_winstuff.h" #endif #include "DNA_windowmanager_types.h" @@ -50,7 +41,6 @@ #include "MEM_guardedalloc.h" #include "BLI_blenlib.h" -#include "BLI_utildefines.h" #include "BKE_context.h" #include "BKE_screen.h" diff --git a/source/blender/editors/space_text/text_intern.h b/source/blender/editors/space_text/text_intern.h index 6d3b184f6cf..c7f9512737f 100644 --- a/source/blender/editors/space_text/text_intern.h +++ b/source/blender/editors/space_text/text_intern.h @@ -68,18 +68,6 @@ void text_update_cursor_moved(struct bContext *C); #define TOOL_SUGG_LIST 0x01 #define TOOL_DOCUMENT 0x02 -typedef struct FlattenString { - char fixedbuf[256]; - int fixedaccum[256]; - - char *buf; - int *accum; - int pos, len; -} FlattenString; - -int flatten_string(struct SpaceText *st, FlattenString *fs, const char *in); -void flatten_string_free(FlattenString *fs); - int wrap_width(struct SpaceText *st, struct ARegion *ar); void wrap_offset(struct SpaceText *st, struct ARegion *ar, struct TextLine *linein, int cursin, int *offl, int *offc); void wrap_offset_in_line(struct SpaceText *st, struct ARegion *ar, struct TextLine *linep, int cursin, int *offl, int *offc); diff --git a/source/blender/editors/space_text/text_ops.c b/source/blender/editors/space_text/text_ops.c index 71044579df4..01041c0e385 100644 --- a/source/blender/editors/space_text/text_ops.c +++ b/source/blender/editors/space_text/text_ops.c @@ -30,19 +30,14 @@ */ -#include <stdlib.h> #include <string.h> -#include <ctype.h> /* ispunct */ -#include <sys/stat.h> #include <errno.h> #include "MEM_guardedalloc.h" #include "DNA_text_types.h" -#include "DNA_userdef_types.h" #include "BLI_blenlib.h" -#include "BLI_utildefines.h" #include "BLF_translation.h" @@ -72,6 +67,7 @@ #endif #include "text_intern.h" +#include "text_format.h" /************************ poll ***************************/ diff --git a/source/blender/editors/space_text/text_python.c b/source/blender/editors/space_text/text_python.c index a06144b8260..1201302dad0 100644 --- a/source/blender/editors/space_text/text_python.c +++ b/source/blender/editors/space_text/text_python.c @@ -28,22 +28,17 @@ * \ingroup sptext */ - #include <ctype.h> -#include <stdio.h> -#include <stdlib.h> #include "DNA_screen_types.h" #include "DNA_space_types.h" #include "DNA_text_types.h" #include "DNA_userdef_types.h" -#include "BKE_blender.h" #include "BKE_suggestions.h" #include "BKE_text.h" #include "BLI_blenlib.h" -#include "BLI_utildefines.h" #include "WM_types.h" diff --git a/source/blender/editors/space_view3d/drawobject.c b/source/blender/editors/space_view3d/drawobject.c index 1f071e5f20e..3722e6797f8 100644 --- a/source/blender/editors/space_view3d/drawobject.c +++ b/source/blender/editors/space_view3d/drawobject.c @@ -759,7 +759,7 @@ void view3d_cached_text_draw_end(View3D *v3d, ARegion *ar, int depth_write, floa (vos->flag & V3D_CACHE_TEXT_GLOBALSPACE) ? rv3d->persmat : rv3d->persmatob, (vos->flag & V3D_CACHE_TEXT_LOCALCLIP) != 0, vos->vec, vos->sco, - V3D_PROJ_TEST_CLIP_BB | V3D_PROJ_TEST_CLIP_WIN) == V3D_PROJ_RET_OK) + V3D_PROJ_TEST_CLIP_BB | V3D_PROJ_TEST_CLIP_WIN | V3D_PROJ_TEST_CLIP_NEAR) == V3D_PROJ_RET_OK) { tot++; } @@ -1290,6 +1290,13 @@ static void drawlamp(Scene *scene, View3D *v3d, RegionView3D *rv3d, Base *base, glVertex3fv(vvec_clip); glEnd(); } + /* Else, draw spot direction (using distance as end limit, same as for Area lamp). */ + else { + glBegin(GL_LINE_STRIP); + glVertex3f(0.0, 0.0, -circrad); + glVertex3f(0.0, 0.0, -la->dist); + glEnd(); + } } else if (ELEM(la->type, LA_HEMI, LA_SUN)) { @@ -7167,7 +7174,7 @@ static void bbs_mesh_solid(Scene *scene, Object *ob) glColor3ub(0, 0, 0); - if ((me->editflag & ME_EDIT_PAINT_MASK)) + if ((me->editflag & ME_EDIT_PAINT_FACE_SEL)) dm->drawMappedFaces(dm, bbs_mesh_solid_hide__setDrawOpts, GPU_enable_material, NULL, me, 0); else dm->drawMappedFaces(dm, bbs_mesh_solid__setDrawOpts, GPU_enable_material, NULL, me, 0); @@ -7221,7 +7228,7 @@ void draw_object_backbufsel(Scene *scene, View3D *v3d, RegionView3D *rv3d, Objec } else { Mesh *me = ob->data; - if ((me->editflag & ME_EDIT_VERT_SEL) && + if ((me->editflag & ME_EDIT_PAINT_VERT_SEL) && /* currently vertex select only supports weight paint */ (ob->mode & OB_MODE_WEIGHT_PAINT)) { diff --git a/source/blender/editors/space_view3d/drawvolume.c b/source/blender/editors/space_view3d/drawvolume.c index 70690e2dce7..29daee3e11b 100644 --- a/source/blender/editors/space_view3d/drawvolume.c +++ b/source/blender/editors/space_view3d/drawvolume.c @@ -449,8 +449,8 @@ void draw_smoke_volume(SmokeDomainSettings *sds, Object *ob, * inserting previously found vertex into the plane equation */ /* d0 = (viewnormal[0]*cv[i][0] + viewnormal[1]*cv[i][1] + viewnormal[2]*cv[i][2]); */ /* UNUSED */ - ds = (ABS(viewnormal[0]) * size[0] + ABS(viewnormal[1]) * size[1] + ABS(viewnormal[2]) * size[2]); - dd = MAX3(sds->global_size[0], sds->global_size[1], sds->global_size[2]) / 128.f; + ds = (fabsf(viewnormal[0]) * size[0] + fabsf(viewnormal[1]) * size[1] + fabsf(viewnormal[2]) * size[2]); + dd = max_fff(sds->global_size[0], sds->global_size[1], sds->global_size[2]) / 128.f; n = 0; good_index = i; @@ -570,7 +570,7 @@ void draw_smoke_velocity(SmokeDomainSettings *domain, Object *ob) float min[3]; float *cell_size = domain->cell_size; - float step_size = ((float)MAX3(base_res[0], base_res[1], base_res[2])) / 16.f; + float step_size = ((float)max_iii(base_res[0], base_res[1], base_res[2])) / 16.f; float vf = domain->scale / 16.f * 2.f; /* velocity factor */ glLineWidth(1.0f); @@ -624,7 +624,7 @@ void draw_smoke_heat(SmokeDomainSettings *domain, Object *ob) float min[3]; float *cell_size = domain->cell_size; - float step_size = ((float)MAX3(base_res[0], base_res[1], base_res[2])) / 16.f; + float step_size = ((float)max_iii(base_res[0], base_res[1], base_res[2])) / 16.f; float vf = domain->scale / 16.f * 2.f; /* velocity factor */ /* set first position so that it doesn't jump when domain moves */ diff --git a/source/blender/editors/space_view3d/space_view3d.c b/source/blender/editors/space_view3d/space_view3d.c index 61649e105ee..4ade47fbdc7 100644 --- a/source/blender/editors/space_view3d/space_view3d.c +++ b/source/blender/editors/space_view3d/space_view3d.c @@ -466,6 +466,16 @@ static int view3d_ob_drop_poll(bContext *UNUSED(C), wmDrag *drag, wmEvent *UNUSE return 0; } +static int view3d_group_drop_poll(bContext *UNUSED(C), wmDrag *drag, wmEvent *UNUSED(event)) +{ + if (drag->type == WM_DRAG_ID) { + ID *id = (ID *)drag->poin; + if (GS(id->name) == ID_GR) + return 1; + } + return 0; +} + static int view3d_mat_drop_poll(bContext *UNUSED(C), wmDrag *drag, wmEvent *UNUSED(event)) { if (drag->type == WM_DRAG_ID) { @@ -520,6 +530,14 @@ static void view3d_ob_drop_copy(wmDrag *drag, wmDropBox *drop) RNA_string_set(drop->ptr, "name", id->name + 2); } +static void view3d_group_drop_copy(wmDrag *drag, wmDropBox *drop) +{ + ID *id = (ID *)drag->poin; + + drop->opcontext = WM_OP_EXEC_DEFAULT; + RNA_string_set(drop->ptr, "name", id->name + 2); +} + static void view3d_id_drop_copy(wmDrag *drag, wmDropBox *drop) { ID *id = (ID *)drag->poin; @@ -547,6 +565,7 @@ static void view3d_dropboxes(void) WM_dropbox_add(lb, "OBJECT_OT_drop_named_material", view3d_mat_drop_poll, view3d_id_drop_copy); WM_dropbox_add(lb, "MESH_OT_drop_named_image", view3d_ima_ob_drop_poll, view3d_id_path_drop_copy); WM_dropbox_add(lb, "VIEW3D_OT_background_image_add", view3d_ima_bg_drop_poll, view3d_id_path_drop_copy); + WM_dropbox_add(lb, "OBJECT_OT_group_instance_add", view3d_group_drop_poll, view3d_group_drop_copy); } diff --git a/source/blender/editors/space_view3d/view3d_edit.c b/source/blender/editors/space_view3d/view3d_edit.c index a1f0bf69497..78c3f4e4f4a 100644 --- a/source/blender/editors/space_view3d/view3d_edit.c +++ b/source/blender/editors/space_view3d/view3d_edit.c @@ -1551,7 +1551,8 @@ static int viewmove_invoke(bContext *C, wmOperator *op, wmEvent *event) vod = op->customdata; if (event->type == MOUSEPAN) { - viewmove_apply(vod, event->prevx, event->prevy); + /* invert it, trackpad scroll follows same principle as 2d windows this way */ + viewmove_apply(vod, 2 * event->x - event->prevx, 2 * event->y - event->prevy); ED_view3d_depth_tag_update(vod->rv3d); viewops_data_free(C, op); @@ -2232,7 +2233,7 @@ static void view3d_from_minmax(bContext *C, View3D *v3d, ARegion *ar, float new_dist; sub_v3_v3v3(afm, max, min); - size = MAX3(afm[0], afm[1], afm[2]); + size = max_fff(afm[0], afm[1], afm[2]); if (ok_dist) { /* fix up zoom distance if needed */ diff --git a/source/blender/editors/space_view3d/view3d_fly.c b/source/blender/editors/space_view3d/view3d_fly.c index cddfae53f6f..f8c9497a686 100644 --- a/source/blender/editors/space_view3d/view3d_fly.c +++ b/source/blender/editors/space_view3d/view3d_fly.c @@ -1041,8 +1041,8 @@ static int flyApply_ndof(bContext *C, FlyInfo *fly) const int flag = U.ndof_flag; #if 0 - int shouldRotate = (flag & NDOF_SHOULD_ROTATE) && (fly->pan_view == FALSE), - shouldTranslate = (flag & (NDOF_SHOULD_PAN | NDOF_SHOULD_ZOOM)); + int shouldRotate = (flag & NDOF_SHOULD_ROTATE) && (fly->pan_view == FALSE); + int shouldTranslate = (flag & (NDOF_SHOULD_PAN | NDOF_SHOULD_ZOOM)); #endif int shouldRotate = (fly->pan_view == FALSE); diff --git a/source/blender/editors/space_view3d/view3d_project.c b/source/blender/editors/space_view3d/view3d_project.c index 34b983f83df..d4bdf6c3177 100644 --- a/source/blender/editors/space_view3d/view3d_project.c +++ b/source/blender/editors/space_view3d/view3d_project.c @@ -116,7 +116,7 @@ static eV3DProjStatus ed_view3d_project__internal(ARegion *ar, float perspmat[4][4], const int is_local, /* normally hidden */ const float co[3], float r_co[2], const eV3DProjTest flag) { - float fx, fy, vec4[4]; + float vec4[4]; /* check for bad flags */ BLI_assert((flag & V3D_PROJ_TEST_ALL) == flag); @@ -134,13 +134,19 @@ static eV3DProjStatus ed_view3d_project__internal(ARegion *ar, vec4[3] = 1.0; mul_m4_v4(perspmat, vec4); - if (vec4[3] > (float)BL_NEAR_CLIP) { - fx = ((float)ar->winx / 2.0f) * (1.0f + vec4[0] / vec4[3]); - if (((flag & V3D_PROJ_TEST_CLIP_WIN) == 0) || (fx > 0 && fx < ar->winx)) { - fy = ((float)ar->winy / 2.0f) * (1.0f + vec4[1] / vec4[3]); + if (((flag & V3D_PROJ_TEST_CLIP_NEAR) == 0) || (vec4[3] > (float)BL_NEAR_CLIP)) { + const float scalar = (vec4[3] != 0.0f) ? (1.0f / vec4[3]): 0.0f; + const float fx = ((float)ar->winx / 2.0f) * (1.0f + (vec4[0] * scalar)); + if (((flag & V3D_PROJ_TEST_CLIP_WIN) == 0) || (fx > 0.0f && fx < (float)ar->winx)) { + const float fy = ((float)ar->winy / 2.0f) * (1.0f + (vec4[1] * scalar)); if (((flag & V3D_PROJ_TEST_CLIP_WIN) == 0) || (fy > 0.0f && fy < (float)ar->winy)) { - r_co[0] = (short)floor(fx); - r_co[1] = (short)floor(fy); + r_co[0] = floorf(fx); + r_co[1] = floorf(fy); + + /* check if the point is behind the view, we need to flip in this case */ + if (UNLIKELY((flag & V3D_PROJ_TEST_CLIP_NEAR) == 0) && (vec4[3] < 0.0f)) { + negate_v2(r_co); + } } else { return V3D_PROJ_RET_CLIP_WIN; @@ -166,8 +172,8 @@ eV3DProjStatus ED_view3d_project_short_ex(ARegion *ar, float perspmat[4][4], con if ((tvec[0] > -32700.0f && tvec[0] < 32700.0f) && (tvec[1] > -32700.0f && tvec[1] < 32700.0f)) { - r_co[0] = (short)floor(tvec[0]); - r_co[1] = (short)floor(tvec[1]); + r_co[0] = (short)floorf(tvec[0]); + r_co[1] = (short)floorf(tvec[1]); } else { ret = V3D_PROJ_RET_OVERFLOW; @@ -185,8 +191,8 @@ eV3DProjStatus ED_view3d_project_int_ex(ARegion *ar, float perspmat[4][4], const if ((tvec[0] > -2140000000.0f && tvec[0] < 2140000000.0f) && (tvec[1] > -2140000000.0f && tvec[1] < 2140000000.0f)) { - r_co[0] = (int)floor(tvec[0]); - r_co[1] = (int)floor(tvec[1]); + r_co[0] = (int)floorf(tvec[0]); + r_co[1] = (int)floorf(tvec[1]); } else { ret = V3D_PROJ_RET_OVERFLOW; diff --git a/source/blender/editors/space_view3d/view3d_select.c b/source/blender/editors/space_view3d/view3d_select.c index cffa53b5dfb..d37042fa2ec 100644 --- a/source/blender/editors/space_view3d/view3d_select.c +++ b/source/blender/editors/space_view3d/view3d_select.c @@ -541,11 +541,11 @@ static void do_lasso_select_mesh(ViewContext *vc, const int mcords[][2], short m if (ts->selectmode & SCE_SELECT_EDGE) { /* Does both bbsel and non-bbsel versions (need screen cos for both) */ data.pass = 0; - mesh_foreachScreenEdge(vc, do_lasso_select_mesh__doSelectEdge, &data, V3D_PROJ_TEST_NOP); + mesh_foreachScreenEdge(vc, do_lasso_select_mesh__doSelectEdge, &data, V3D_PROJ_TEST_CLIP_NEAR); if (data.is_done == 0) { data.pass = 1; - mesh_foreachScreenEdge(vc, do_lasso_select_mesh__doSelectEdge, &data, V3D_PROJ_TEST_NOP); + mesh_foreachScreenEdge(vc, do_lasso_select_mesh__doSelectEdge, &data, V3D_PROJ_TEST_CLIP_NEAR); } } @@ -1448,7 +1448,7 @@ static int mouse_select(bContext *C, const int mval[2], short extend, short dese if (BASE_SELECTABLE(v3d, base)) { float screen_co[2]; if (ED_view3d_project_float_global(ar, base->object->obmat[3], screen_co, - V3D_PROJ_TEST_CLIP_BB | V3D_PROJ_TEST_CLIP_WIN) == V3D_PROJ_RET_OK) + V3D_PROJ_TEST_CLIP_BB | V3D_PROJ_TEST_CLIP_WIN | V3D_PROJ_TEST_CLIP_NEAR) == V3D_PROJ_RET_OK) { float dist_temp = len_manhattan_v2v2(mval_fl, screen_co); if (base == BASACT) dist_temp += 10.0f; @@ -1803,11 +1803,11 @@ static int do_mesh_box_select(ViewContext *vc, rcti *rect, int select, int exten /* Does both bbsel and non-bbsel versions (need screen cos for both) */ data.pass = 0; - mesh_foreachScreenEdge(vc, do_mesh_box_select__doSelectEdge, &data, V3D_PROJ_TEST_NOP); + mesh_foreachScreenEdge(vc, do_mesh_box_select__doSelectEdge, &data, V3D_PROJ_TEST_CLIP_NEAR); if (data.is_done == 0) { data.pass = 1; - mesh_foreachScreenEdge(vc, do_mesh_box_select__doSelectEdge, &data, V3D_PROJ_TEST_NOP); + mesh_foreachScreenEdge(vc, do_mesh_box_select__doSelectEdge, &data, V3D_PROJ_TEST_CLIP_NEAR); } } @@ -2333,7 +2333,7 @@ static void mesh_circle_select(ViewContext *vc, int select, const int mval[2], f edbm_backbuf_check_and_select_edges(vc->em, select == LEFTMOUSE); } else { - mesh_foreachScreenEdge(vc, mesh_circle_doSelectEdge, &data, V3D_PROJ_TEST_NOP); + mesh_foreachScreenEdge(vc, mesh_circle_doSelectEdge, &data, V3D_PROJ_TEST_CLIP_NEAR); } } @@ -2670,7 +2670,7 @@ static int object_circle_select(ViewContext *vc, int select, const int mval[2], if (BASE_SELECTABLE(vc->v3d, base) && ((base->flag & SELECT) != select_flag)) { float screen_co[2]; if (ED_view3d_project_float_global(vc->ar, base->object->obmat[3], screen_co, - V3D_PROJ_TEST_CLIP_BB | V3D_PROJ_TEST_CLIP_WIN) == V3D_PROJ_RET_OK) + V3D_PROJ_TEST_CLIP_BB | V3D_PROJ_TEST_CLIP_WIN | V3D_PROJ_TEST_CLIP_NEAR) == V3D_PROJ_RET_OK) { if (len_squared_v2v2(mval_fl, screen_co) <= radius_squared) { ED_base_object_select(base, select); diff --git a/source/blender/editors/space_view3d/view3d_view.c b/source/blender/editors/space_view3d/view3d_view.c index 56ce9bda607..41d092ce2b1 100644 --- a/source/blender/editors/space_view3d/view3d_view.c +++ b/source/blender/editors/space_view3d/view3d_view.c @@ -1070,11 +1070,9 @@ static int view3d_localview_init(Main *bmain, Scene *scene, ScrArea *sa, ReportL } } } - - box[0] = (max[0] - min[0]); - box[1] = (max[1] - min[1]); - box[2] = (max[2] - min[2]); - size = MAX3(box[0], box[1], box[2]); + + sub_v3_v3v3(box, max, min); + size = max_fff(box[0], box[1], box[2]); /* do not zoom closer than the near clipping plane */ size = max_ff(size, v3d->near * 1.5f); diff --git a/source/blender/editors/transform/transform.c b/source/blender/editors/transform/transform.c index 65b29cf6475..b2ee17b8a8b 100644 --- a/source/blender/editors/transform/transform.c +++ b/source/blender/editors/transform/transform.c @@ -352,6 +352,7 @@ void projectFloatView(TransInfo *t, const float vec[3], float adr[2]) case SPACE_VIEW3D: { if (t->ar->regiontype == RGN_TYPE_WINDOW) { + /* allow points behind the view [#33643] */ if (ED_view3d_project_float_global(t->ar, vec, adr, V3D_PROJ_TEST_NOP) != V3D_PROJ_RET_OK) { /* XXX, 2.64 and prior did this, weak! */ adr[0] = t->ar->winx / 2.0f; @@ -4885,6 +4886,7 @@ static void calcNonProportionalEdgeSlide(TransInfo *t, SlideData *sld, const flo sv->edge_len = len_v3v3(sv->upvec, sv->downvec); mul_v3_m4v3(v_proj, t->obedit->obmat, sv->v->co); + /* allow points behind the view [#33643] */ if (ED_view3d_project_float_global(t->ar, v_proj, v_proj, V3D_PROJ_TEST_NOP) == V3D_PROJ_RET_OK) { dist = len_squared_v2v2(mval, v_proj); if (dist < min_dist) { diff --git a/source/blender/editors/transform/transform_generics.c b/source/blender/editors/transform/transform_generics.c index 6d7ddd4e0ed..8f1d6a7b46e 100644 --- a/source/blender/editors/transform/transform_generics.c +++ b/source/blender/editors/transform/transform_generics.c @@ -1529,13 +1529,6 @@ void calculateCenterMedian(TransInfo *t) total++; } } - else { - /* - * All the selected elements are at the head of the array - * which means we can stop when it finds unselected data - */ - break; - } } if (i) mul_v3_fl(partial, 1.0f / total); @@ -1555,13 +1548,6 @@ void calculateCenterBound(TransInfo *t) if (!(t->data[i].flag & TD_NOCENTER)) minmax_v3v3_v3(min, max, t->data[i].center); } - else { - /* - * All the selected elements are at the head of the array - * which means we can stop when it finds unselected data - */ - break; - } } else { copy_v3_v3(max, t->data[i].center); diff --git a/source/blender/editors/uvedit/uvedit_parametrizer.c b/source/blender/editors/uvedit/uvedit_parametrizer.c index 8703234122a..5d3a5983030 100644 --- a/source/blender/editors/uvedit/uvedit_parametrizer.c +++ b/source/blender/editors/uvedit/uvedit_parametrizer.c @@ -3109,7 +3109,7 @@ static PBool p_chart_lscm_solve(PHandle *handle, PChart *chart) sina2 = sin(a2); sina3 = sin(a3); - sinmax = MAX3(sina1, sina2, sina3); + sinmax = max_fff(sina1, sina2, sina3); /* shift vertices to find most stable order */ if (sina3 != sinmax) { |