diff options
author | Campbell Barton <ideasman42@gmail.com> | 2019-04-17 07:17:24 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2019-04-17 07:21:24 +0300 |
commit | e12c08e8d170b7ca40f204a5b0423c23a9fbc2c1 (patch) | |
tree | 8cf3453d12edb177a218ef8009357518ec6cab6a /source/blender/editors/util | |
parent | b3dabc200a4b0399ec6b81f2ff2730d07b44fcaa (diff) |
ClangFormat: apply to source, most of intern
Apply clang format as proposed in T53211.
For details on usage and instructions for migrating branches
without conflicts, see:
https://wiki.blender.org/wiki/Tools/ClangFormat
Diffstat (limited to 'source/blender/editors/util')
-rw-r--r-- | source/blender/editors/util/CMakeLists.txt | 158 | ||||
-rw-r--r-- | source/blender/editors/util/ed_transverts.c | 876 | ||||
-rw-r--r-- | source/blender/editors/util/ed_util.c | 620 | ||||
-rw-r--r-- | source/blender/editors/util/gizmo_utils.c | 44 | ||||
-rw-r--r-- | source/blender/editors/util/numinput.c | 919 | ||||
-rw-r--r-- | source/blender/editors/util/select_utils.c | 157 |
6 files changed, 1402 insertions, 1372 deletions
diff --git a/source/blender/editors/util/CMakeLists.txt b/source/blender/editors/util/CMakeLists.txt index 728dacc1649..a1893d8e6f1 100644 --- a/source/blender/editors/util/CMakeLists.txt +++ b/source/blender/editors/util/CMakeLists.txt @@ -16,87 +16,87 @@ # ***** END GPL LICENSE BLOCK ***** set(INC - ../include - ../../blenkernel - ../../blenlib - ../../blentranslation - ../../bmesh - ../../depsgraph - ../../imbuf - ../../gpu - ../../makesdna - ../../makesrna - ../../windowmanager - ../../../../intern/guardedalloc - ../../../../intern/clog - ../../../../intern/glew-mx + ../include + ../../blenkernel + ../../blenlib + ../../blentranslation + ../../bmesh + ../../depsgraph + ../../imbuf + ../../gpu + ../../makesdna + ../../makesrna + ../../windowmanager + ../../../../intern/guardedalloc + ../../../../intern/clog + ../../../../intern/glew-mx ) set(INC_SYS - ${GLEW_INCLUDE_PATH} + ${GLEW_INCLUDE_PATH} ) set(SRC - ed_transverts.c - ed_util.c - gizmo_utils.c - numinput.c - select_utils.c + ed_transverts.c + ed_util.c + gizmo_utils.c + numinput.c + select_utils.c - # general includes - ../include/BIF_gl.h - ../include/BIF_glutil.h - ../include/ED_anim_api.h - ../include/ED_armature.h - ../include/ED_buttons.h - ../include/ED_clip.h - ../include/ED_curve.h - ../include/ED_datafiles.h - ../include/ED_fileselect.h - ../include/ED_gizmo_library.h - ../include/ED_gizmo_utils.h - ../include/ED_gpencil.h - ../include/ED_image.h - ../include/ED_info.h - ../include/ED_keyframes_draw.h - ../include/ED_keyframes_edit.h - ../include/ED_keyframing.h - ../include/ED_lattice.h - ../include/ED_logic.h - ../include/ED_markers.h - ../include/ED_mask.h - ../include/ED_mball.h - ../include/ED_mesh.h - ../include/ED_node.h - ../include/ED_numinput.h - ../include/ED_object.h - ../include/ED_outliner.h - ../include/ED_paint.h - ../include/ED_particle.h - ../include/ED_physics.h - ../include/ED_render.h - ../include/ED_scene.h - ../include/ED_screen.h - ../include/ED_screen_types.h - ../include/ED_sculpt.h - ../include/ED_select_utils.h - ../include/ED_sequencer.h - ../include/ED_sound.h - ../include/ED_space_api.h - ../include/ED_text.h - ../include/ED_transform.h - ../include/ED_transform_snap_object_context.h - ../include/ED_transverts.h - ../include/ED_types.h - ../include/ED_undo.h - ../include/ED_util.h - ../include/ED_uvedit.h - ../include/ED_view3d.h - ../include/UI_icons.h - ../include/UI_interface.h - ../include/UI_interface_icons.h - ../include/UI_resources.h - ../include/UI_view2d.h + # general includes + ../include/BIF_gl.h + ../include/BIF_glutil.h + ../include/ED_anim_api.h + ../include/ED_armature.h + ../include/ED_buttons.h + ../include/ED_clip.h + ../include/ED_curve.h + ../include/ED_datafiles.h + ../include/ED_fileselect.h + ../include/ED_gizmo_library.h + ../include/ED_gizmo_utils.h + ../include/ED_gpencil.h + ../include/ED_image.h + ../include/ED_info.h + ../include/ED_keyframes_draw.h + ../include/ED_keyframes_edit.h + ../include/ED_keyframing.h + ../include/ED_lattice.h + ../include/ED_logic.h + ../include/ED_markers.h + ../include/ED_mask.h + ../include/ED_mball.h + ../include/ED_mesh.h + ../include/ED_node.h + ../include/ED_numinput.h + ../include/ED_object.h + ../include/ED_outliner.h + ../include/ED_paint.h + ../include/ED_particle.h + ../include/ED_physics.h + ../include/ED_render.h + ../include/ED_scene.h + ../include/ED_screen.h + ../include/ED_screen_types.h + ../include/ED_sculpt.h + ../include/ED_select_utils.h + ../include/ED_sequencer.h + ../include/ED_sound.h + ../include/ED_space_api.h + ../include/ED_text.h + ../include/ED_transform.h + ../include/ED_transform_snap_object_context.h + ../include/ED_transverts.h + ../include/ED_types.h + ../include/ED_undo.h + ../include/ED_util.h + ../include/ED_uvedit.h + ../include/ED_view3d.h + ../include/UI_icons.h + ../include/UI_interface.h + ../include/UI_interface_icons.h + ../include/UI_resources.h + ../include/UI_view2d.h ) set(LIB @@ -105,14 +105,14 @@ set(LIB add_definitions(${GL_DEFINITIONS}) if(WITH_INTERNATIONAL) - add_definitions(-DWITH_INTERNATIONAL) + add_definitions(-DWITH_INTERNATIONAL) endif() if(WITH_PYTHON) - add_definitions(-DWITH_PYTHON) - list(APPEND INC - ../../python - ) + add_definitions(-DWITH_PYTHON) + list(APPEND INC + ../../python + ) endif() blender_add_lib(bf_editor_util "${SRC}" "${INC}" "${INC_SYS}" "${LIB}") diff --git a/source/blender/editors/util/ed_transverts.c b/source/blender/editors/util/ed_transverts.c index ccd35983551..4cc74bec7d9 100644 --- a/source/blender/editors/util/ed_transverts.c +++ b/source/blender/editors/util/ed_transverts.c @@ -45,462 +45,468 @@ #include "ED_armature.h" -#include "ED_transverts.h" /* own include */ - +#include "ED_transverts.h" /* own include */ /* copied from editobject.c, now uses (almost) proper depgraph */ void ED_transverts_update_obedit(TransVertStore *tvs, Object *obedit) { - const int mode = tvs->mode; - BLI_assert(ED_transverts_check_obedit(obedit) == true); - - DEG_id_tag_update(obedit->data, 0); - - if (obedit->type == OB_MESH) { - BMEditMesh *em = BKE_editmesh_from_object(obedit); - BM_mesh_normals_update(em->bm); - } - else if (ELEM(obedit->type, OB_CURVE, OB_SURF)) { - Curve *cu = obedit->data; - ListBase *nurbs = BKE_curve_editNurbs_get(cu); - Nurb *nu = nurbs->first; - - while (nu) { - /* keep handles' vectors unchanged */ - if (nu->bezt && (mode & TM_SKIP_HANDLES)) { - int a = nu->pntsu; - TransVert *tv = tvs->transverts; - BezTriple *bezt = nu->bezt; - - while (a--) { - if (bezt->hide == 0) { - bool skip_handle = false; - if (bezt->f2 & SELECT) - skip_handle = (mode & TM_SKIP_HANDLES) != 0; - - if ((bezt->f1 & SELECT) && !skip_handle) { - BLI_assert(tv->loc == bezt->vec[0]); - tv++; - } - - if (bezt->f2 & SELECT) { - float v[3]; - - if (((bezt->f1 & SELECT) && !skip_handle) == 0) { - sub_v3_v3v3(v, tv->loc, tv->oldloc); - add_v3_v3(bezt->vec[0], v); - } - - if (((bezt->f3 & SELECT) && !skip_handle) == 0) { - sub_v3_v3v3(v, tv->loc, tv->oldloc); - add_v3_v3(bezt->vec[2], v); - } - - BLI_assert(tv->loc == bezt->vec[1]); - tv++; - } - - if ((bezt->f3 & SELECT) && !skip_handle) { - BLI_assert(tv->loc == bezt->vec[2]); - tv++; - } - } - - bezt++; - } - } - - BKE_nurb_test_2d(nu); - BKE_nurb_handles_test(nu, true); /* test for bezier too */ - nu = nu->next; - } - } - else if (obedit->type == OB_ARMATURE) { - bArmature *arm = obedit->data; - EditBone *ebo; - TransVert *tv = tvs->transverts; - int a = 0; - - /* Ensure all bone tails are correctly adjusted */ - for (ebo = arm->edbo->first; ebo; ebo = ebo->next) { - /* adjust tip if both ends selected */ - if ((ebo->flag & BONE_ROOTSEL) && (ebo->flag & BONE_TIPSEL)) { - if (tv) { - float diffvec[3]; - - sub_v3_v3v3(diffvec, tv->loc, tv->oldloc); - add_v3_v3(ebo->tail, diffvec); - - a++; - if (a < tvs->transverts_tot) tv++; - } - } - } - - /* Ensure all bones are correctly adjusted */ - for (ebo = arm->edbo->first; ebo; ebo = ebo->next) { - if ((ebo->flag & BONE_CONNECTED) && ebo->parent) { - /* If this bone has a parent tip that has been moved */ - if (ebo->parent->flag & BONE_TIPSEL) { - copy_v3_v3(ebo->head, ebo->parent->tail); - } - /* If this bone has a parent tip that has NOT been moved */ - else { - copy_v3_v3(ebo->parent->tail, ebo->head); - } - } - } - if (arm->flag & ARM_MIRROR_EDIT) - ED_armature_edit_transform_mirror_update(obedit); - } - else if (obedit->type == OB_LATTICE) { - Lattice *lt = obedit->data; - - if (lt->editlatt->latt->flag & LT_OUTSIDE) - outside_lattice(lt->editlatt->latt); - } + const int mode = tvs->mode; + BLI_assert(ED_transverts_check_obedit(obedit) == true); + + DEG_id_tag_update(obedit->data, 0); + + if (obedit->type == OB_MESH) { + BMEditMesh *em = BKE_editmesh_from_object(obedit); + BM_mesh_normals_update(em->bm); + } + else if (ELEM(obedit->type, OB_CURVE, OB_SURF)) { + Curve *cu = obedit->data; + ListBase *nurbs = BKE_curve_editNurbs_get(cu); + Nurb *nu = nurbs->first; + + while (nu) { + /* keep handles' vectors unchanged */ + if (nu->bezt && (mode & TM_SKIP_HANDLES)) { + int a = nu->pntsu; + TransVert *tv = tvs->transverts; + BezTriple *bezt = nu->bezt; + + while (a--) { + if (bezt->hide == 0) { + bool skip_handle = false; + if (bezt->f2 & SELECT) + skip_handle = (mode & TM_SKIP_HANDLES) != 0; + + if ((bezt->f1 & SELECT) && !skip_handle) { + BLI_assert(tv->loc == bezt->vec[0]); + tv++; + } + + if (bezt->f2 & SELECT) { + float v[3]; + + if (((bezt->f1 & SELECT) && !skip_handle) == 0) { + sub_v3_v3v3(v, tv->loc, tv->oldloc); + add_v3_v3(bezt->vec[0], v); + } + + if (((bezt->f3 & SELECT) && !skip_handle) == 0) { + sub_v3_v3v3(v, tv->loc, tv->oldloc); + add_v3_v3(bezt->vec[2], v); + } + + BLI_assert(tv->loc == bezt->vec[1]); + tv++; + } + + if ((bezt->f3 & SELECT) && !skip_handle) { + BLI_assert(tv->loc == bezt->vec[2]); + tv++; + } + } + + bezt++; + } + } + + BKE_nurb_test_2d(nu); + BKE_nurb_handles_test(nu, true); /* test for bezier too */ + nu = nu->next; + } + } + else if (obedit->type == OB_ARMATURE) { + bArmature *arm = obedit->data; + EditBone *ebo; + TransVert *tv = tvs->transverts; + int a = 0; + + /* Ensure all bone tails are correctly adjusted */ + for (ebo = arm->edbo->first; ebo; ebo = ebo->next) { + /* adjust tip if both ends selected */ + if ((ebo->flag & BONE_ROOTSEL) && (ebo->flag & BONE_TIPSEL)) { + if (tv) { + float diffvec[3]; + + sub_v3_v3v3(diffvec, tv->loc, tv->oldloc); + add_v3_v3(ebo->tail, diffvec); + + a++; + if (a < tvs->transverts_tot) + tv++; + } + } + } + + /* Ensure all bones are correctly adjusted */ + for (ebo = arm->edbo->first; ebo; ebo = ebo->next) { + if ((ebo->flag & BONE_CONNECTED) && ebo->parent) { + /* If this bone has a parent tip that has been moved */ + if (ebo->parent->flag & BONE_TIPSEL) { + copy_v3_v3(ebo->head, ebo->parent->tail); + } + /* If this bone has a parent tip that has NOT been moved */ + else { + copy_v3_v3(ebo->parent->tail, ebo->head); + } + } + } + if (arm->flag & ARM_MIRROR_EDIT) + ED_armature_edit_transform_mirror_update(obedit); + } + else if (obedit->type == OB_LATTICE) { + Lattice *lt = obedit->data; + + if (lt->editlatt->latt->flag & LT_OUTSIDE) + outside_lattice(lt->editlatt->latt); + } } -static void set_mapped_co(void *vuserdata, int index, const float co[3], - const float UNUSED(no[3]), const short UNUSED(no_s[3])) +static void set_mapped_co(void *vuserdata, + int index, + const float co[3], + const float UNUSED(no[3]), + const short UNUSED(no_s[3])) { - void **userdata = vuserdata; - BMEditMesh *em = userdata[0]; - TransVert *tv = userdata[1]; - BMVert *eve = BM_vert_at_index(em->bm, index); - - if (BM_elem_index_get(eve) != TM_INDEX_SKIP) { - tv = &tv[BM_elem_index_get(eve)]; - - /* be clever, get the closest vertex to the original, - * behaves most logically when the mirror modifier is used for eg [#33051]*/ - if ((tv->flag & TX_VERT_USE_MAPLOC) == 0) { - /* first time */ - copy_v3_v3(tv->maploc, co); - tv->flag |= TX_VERT_USE_MAPLOC; - } - else { - /* find best location to use */ - if (len_squared_v3v3(eve->co, co) < len_squared_v3v3(eve->co, tv->maploc)) { - copy_v3_v3(tv->maploc, co); - } - } - } + void **userdata = vuserdata; + BMEditMesh *em = userdata[0]; + TransVert *tv = userdata[1]; + BMVert *eve = BM_vert_at_index(em->bm, index); + + if (BM_elem_index_get(eve) != TM_INDEX_SKIP) { + tv = &tv[BM_elem_index_get(eve)]; + + /* be clever, get the closest vertex to the original, + * behaves most logically when the mirror modifier is used for eg [#33051]*/ + if ((tv->flag & TX_VERT_USE_MAPLOC) == 0) { + /* first time */ + copy_v3_v3(tv->maploc, co); + tv->flag |= TX_VERT_USE_MAPLOC; + } + else { + /* find best location to use */ + if (len_squared_v3v3(eve->co, co) < len_squared_v3v3(eve->co, tv->maploc)) { + copy_v3_v3(tv->maploc, co); + } + } + } } bool ED_transverts_check_obedit(Object *obedit) { - return (ELEM(obedit->type, OB_ARMATURE, OB_LATTICE, OB_MESH, OB_SURF, OB_CURVE, OB_MBALL)); + return (ELEM(obedit->type, OB_ARMATURE, OB_LATTICE, OB_MESH, OB_SURF, OB_CURVE, OB_MBALL)); } void ED_transverts_create_from_obedit(TransVertStore *tvs, Object *obedit, const int mode) { - Nurb *nu; - BezTriple *bezt; - BPoint *bp; - TransVert *tv = NULL; - MetaElem *ml; - BMVert *eve; - EditBone *ebo; - int a; - - tvs->transverts_tot = 0; - - if (obedit->type == OB_MESH) { - BMEditMesh *em = BKE_editmesh_from_object(obedit); - BMesh *bm = em->bm; - BMIter iter; - void *userdata[2] = {em, NULL}; - /*int proptrans = 0; */ /*UNUSED*/ - - /* abuses vertex index all over, set, just set dirty here, - * perhaps this could use its own array instead? - campbell */ - - /* transform now requires awareness for select mode, so we tag the f1 flags in verts */ - tvs->transverts_tot = 0; - if (em->selectmode & SCE_SELECT_VERTEX) { - BM_ITER_MESH (eve, &iter, bm, BM_VERTS_OF_MESH) { - if (!BM_elem_flag_test(eve, BM_ELEM_HIDDEN) && BM_elem_flag_test(eve, BM_ELEM_SELECT)) { - BM_elem_index_set(eve, TM_INDEX_ON); /* set_dirty! */ - tvs->transverts_tot++; - } - else { - BM_elem_index_set(eve, TM_INDEX_OFF); /* set_dirty! */ - } - } - } - else if (em->selectmode & SCE_SELECT_EDGE) { - BMEdge *eed; - - BM_ITER_MESH (eve, &iter, bm, BM_VERTS_OF_MESH) { - BM_elem_index_set(eve, TM_INDEX_OFF); /* set_dirty! */ - } - - BM_ITER_MESH (eed, &iter, bm, BM_EDGES_OF_MESH) { - if (!BM_elem_flag_test(eed, BM_ELEM_HIDDEN) && BM_elem_flag_test(eed, BM_ELEM_SELECT)) { - BM_elem_index_set(eed->v1, TM_INDEX_ON); /* set_dirty! */ - BM_elem_index_set(eed->v2, TM_INDEX_ON); /* set_dirty! */ - } - } - - BM_ITER_MESH (eve, &iter, bm, BM_VERTS_OF_MESH) { - if (BM_elem_index_get(eve) == TM_INDEX_ON) tvs->transverts_tot++; - } - } - else { - BMFace *efa; - - BM_ITER_MESH (eve, &iter, bm, BM_VERTS_OF_MESH) { - BM_elem_index_set(eve, TM_INDEX_OFF); /* set_dirty! */ - } - - BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) { - if (!BM_elem_flag_test(efa, BM_ELEM_HIDDEN) && BM_elem_flag_test(efa, BM_ELEM_SELECT)) { - BMIter liter; - BMLoop *l; - - BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) { - BM_elem_index_set(l->v, TM_INDEX_ON); /* set_dirty! */ - } - } - } - - BM_ITER_MESH (eve, &iter, bm, BM_VERTS_OF_MESH) { - if (BM_elem_index_get(eve) == TM_INDEX_ON) tvs->transverts_tot++; - } - } - /* for any of the 3 loops above which all dirty the indices */ - bm->elem_index_dirty |= BM_VERT; - - /* and now make transverts */ - if (tvs->transverts_tot) { - tv = tvs->transverts = MEM_callocN(tvs->transverts_tot * sizeof(TransVert), __func__); - - a = 0; - BM_ITER_MESH (eve, &iter, bm, BM_VERTS_OF_MESH) { - if (BM_elem_index_get(eve)) { - BM_elem_index_set(eve, a); /* set_dirty! */ - copy_v3_v3(tv->oldloc, eve->co); - tv->loc = eve->co; - tv->flag = (BM_elem_index_get(eve) == TM_INDEX_ON) ? SELECT : 0; - - if (mode & TM_CALC_NORMALS) { - tv->flag |= TX_VERT_USE_NORMAL; - copy_v3_v3(tv->normal, eve->no); - } - - tv++; - a++; - } - else { - BM_elem_index_set(eve, TM_INDEX_SKIP); /* set_dirty! */ - } - } - /* set dirty already, above */ - - userdata[1] = tvs->transverts; - } - - if (tvs->transverts && em->mesh_eval_cage) { - BM_mesh_elem_table_ensure(bm, BM_VERT); - BKE_mesh_foreach_mapped_vert(em->mesh_eval_cage, set_mapped_co, userdata, MESH_FOREACH_NOP); - } - } - else if (obedit->type == OB_ARMATURE) { - bArmature *arm = obedit->data; - int totmalloc = BLI_listbase_count(arm->edbo); - - totmalloc *= 2; /* probably overkill but bones can have 2 trans verts each */ - - tv = tvs->transverts = MEM_callocN(totmalloc * sizeof(TransVert), __func__); - - for (ebo = arm->edbo->first; ebo; ebo = ebo->next) { - if (ebo->layer & arm->layer) { - const bool tipsel = (ebo->flag & BONE_TIPSEL) != 0; - const bool rootsel = (ebo->flag & BONE_ROOTSEL) != 0; - const bool rootok = (!(ebo->parent && (ebo->flag & BONE_CONNECTED) && (ebo->parent->flag & BONE_TIPSEL))); - - if ((tipsel && rootsel) || (rootsel)) { - /* Don't add the tip (unless mode & TM_ALL_JOINTS, for getting all joints), - * otherwise we get zero-length bones as tips will snap to the same - * location as heads. - */ - if (rootok) { - copy_v3_v3(tv->oldloc, ebo->head); - tv->loc = ebo->head; - tv->flag = SELECT; - tv++; - tvs->transverts_tot++; - } - - if ((mode & TM_ALL_JOINTS) && (tipsel)) { - copy_v3_v3(tv->oldloc, ebo->tail); - tv->loc = ebo->tail; - tv->flag = SELECT; - tv++; - tvs->transverts_tot++; - } - } - else if (tipsel) { - copy_v3_v3(tv->oldloc, ebo->tail); - tv->loc = ebo->tail; - tv->flag = SELECT; - tv++; - tvs->transverts_tot++; - } - } - } - } - else if (ELEM(obedit->type, OB_CURVE, OB_SURF)) { - Curve *cu = obedit->data; - int totmalloc = 0; - ListBase *nurbs = BKE_curve_editNurbs_get(cu); - - for (nu = nurbs->first; nu; nu = nu->next) { - if (nu->type == CU_BEZIER) - totmalloc += 3 * nu->pntsu; - else - totmalloc += nu->pntsu * nu->pntsv; - } - tv = tvs->transverts = MEM_callocN(totmalloc * sizeof(TransVert), __func__); - - nu = nurbs->first; - while (nu) { - if (nu->type == CU_BEZIER) { - a = nu->pntsu; - bezt = nu->bezt; - while (a--) { - if (bezt->hide == 0) { - bool skip_handle = false; - if (bezt->f2 & SELECT) - skip_handle = (mode & TM_SKIP_HANDLES) != 0; - - if ((bezt->f1 & SELECT) && !skip_handle) { - copy_v3_v3(tv->oldloc, bezt->vec[0]); - tv->loc = bezt->vec[0]; - tv->flag = bezt->f1 & SELECT; - - if (mode & TM_CALC_NORMALS) { - tv->flag |= TX_VERT_USE_NORMAL; - BKE_nurb_bezt_calc_plane(nu, bezt, tv->normal); - } - - tv++; - tvs->transverts_tot++; - } - if (bezt->f2 & SELECT) { - copy_v3_v3(tv->oldloc, bezt->vec[1]); - tv->loc = bezt->vec[1]; - tv->flag = bezt->f2 & SELECT; - - if (mode & TM_CALC_NORMALS) { - tv->flag |= TX_VERT_USE_NORMAL; - BKE_nurb_bezt_calc_plane(nu, bezt, tv->normal); - } - - tv++; - tvs->transverts_tot++; - } - if ((bezt->f3 & SELECT) && !skip_handle) { - copy_v3_v3(tv->oldloc, bezt->vec[2]); - tv->loc = bezt->vec[2]; - tv->flag = bezt->f3 & SELECT; - - if (mode & TM_CALC_NORMALS) { - tv->flag |= TX_VERT_USE_NORMAL; - BKE_nurb_bezt_calc_plane(nu, bezt, tv->normal); - } - - tv++; - tvs->transverts_tot++; - } - } - bezt++; - } - } - else { - a = nu->pntsu * nu->pntsv; - bp = nu->bp; - while (a--) { - if (bp->hide == 0) { - if (bp->f1 & SELECT) { - copy_v3_v3(tv->oldloc, bp->vec); - tv->loc = bp->vec; - tv->flag = bp->f1 & SELECT; - tv++; - tvs->transverts_tot++; - } - } - bp++; - } - } - nu = nu->next; - } - } - else if (obedit->type == OB_MBALL) { - MetaBall *mb = obedit->data; - int totmalloc = BLI_listbase_count(mb->editelems); - - tv = tvs->transverts = MEM_callocN(totmalloc * sizeof(TransVert), __func__); - - ml = mb->editelems->first; - while (ml) { - if (ml->flag & SELECT) { - tv->loc = &ml->x; - copy_v3_v3(tv->oldloc, tv->loc); - tv->flag = SELECT; - tv++; - tvs->transverts_tot++; - } - ml = ml->next; - } - } - else if (obedit->type == OB_LATTICE) { - Lattice *lt = obedit->data; - - bp = lt->editlatt->latt->def; - - a = lt->editlatt->latt->pntsu * lt->editlatt->latt->pntsv * lt->editlatt->latt->pntsw; - - tv = tvs->transverts = MEM_callocN(a * sizeof(TransVert), __func__); - - while (a--) { - if (bp->f1 & SELECT) { - if (bp->hide == 0) { - copy_v3_v3(tv->oldloc, bp->vec); - tv->loc = bp->vec; - tv->flag = bp->f1 & SELECT; - tv++; - tvs->transverts_tot++; - } - } - bp++; - } - } - - if (!tvs->transverts_tot && tvs->transverts) { - /* prevent memory leak. happens for curves/latticies due to */ - /* difficult condition of adding points to trans data */ - MEM_freeN(tvs->transverts); - tvs->transverts = NULL; - } - - tvs->mode = mode; + Nurb *nu; + BezTriple *bezt; + BPoint *bp; + TransVert *tv = NULL; + MetaElem *ml; + BMVert *eve; + EditBone *ebo; + int a; + + tvs->transverts_tot = 0; + + if (obedit->type == OB_MESH) { + BMEditMesh *em = BKE_editmesh_from_object(obedit); + BMesh *bm = em->bm; + BMIter iter; + void *userdata[2] = {em, NULL}; + /*int proptrans = 0; */ /*UNUSED*/ + + /* abuses vertex index all over, set, just set dirty here, + * perhaps this could use its own array instead? - campbell */ + + /* transform now requires awareness for select mode, so we tag the f1 flags in verts */ + tvs->transverts_tot = 0; + if (em->selectmode & SCE_SELECT_VERTEX) { + BM_ITER_MESH (eve, &iter, bm, BM_VERTS_OF_MESH) { + if (!BM_elem_flag_test(eve, BM_ELEM_HIDDEN) && BM_elem_flag_test(eve, BM_ELEM_SELECT)) { + BM_elem_index_set(eve, TM_INDEX_ON); /* set_dirty! */ + tvs->transverts_tot++; + } + else { + BM_elem_index_set(eve, TM_INDEX_OFF); /* set_dirty! */ + } + } + } + else if (em->selectmode & SCE_SELECT_EDGE) { + BMEdge *eed; + + BM_ITER_MESH (eve, &iter, bm, BM_VERTS_OF_MESH) { + BM_elem_index_set(eve, TM_INDEX_OFF); /* set_dirty! */ + } + + BM_ITER_MESH (eed, &iter, bm, BM_EDGES_OF_MESH) { + if (!BM_elem_flag_test(eed, BM_ELEM_HIDDEN) && BM_elem_flag_test(eed, BM_ELEM_SELECT)) { + BM_elem_index_set(eed->v1, TM_INDEX_ON); /* set_dirty! */ + BM_elem_index_set(eed->v2, TM_INDEX_ON); /* set_dirty! */ + } + } + + BM_ITER_MESH (eve, &iter, bm, BM_VERTS_OF_MESH) { + if (BM_elem_index_get(eve) == TM_INDEX_ON) + tvs->transverts_tot++; + } + } + else { + BMFace *efa; + + BM_ITER_MESH (eve, &iter, bm, BM_VERTS_OF_MESH) { + BM_elem_index_set(eve, TM_INDEX_OFF); /* set_dirty! */ + } + + BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) { + if (!BM_elem_flag_test(efa, BM_ELEM_HIDDEN) && BM_elem_flag_test(efa, BM_ELEM_SELECT)) { + BMIter liter; + BMLoop *l; + + BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) { + BM_elem_index_set(l->v, TM_INDEX_ON); /* set_dirty! */ + } + } + } + + BM_ITER_MESH (eve, &iter, bm, BM_VERTS_OF_MESH) { + if (BM_elem_index_get(eve) == TM_INDEX_ON) + tvs->transverts_tot++; + } + } + /* for any of the 3 loops above which all dirty the indices */ + bm->elem_index_dirty |= BM_VERT; + + /* and now make transverts */ + if (tvs->transverts_tot) { + tv = tvs->transverts = MEM_callocN(tvs->transverts_tot * sizeof(TransVert), __func__); + + a = 0; + BM_ITER_MESH (eve, &iter, bm, BM_VERTS_OF_MESH) { + if (BM_elem_index_get(eve)) { + BM_elem_index_set(eve, a); /* set_dirty! */ + copy_v3_v3(tv->oldloc, eve->co); + tv->loc = eve->co; + tv->flag = (BM_elem_index_get(eve) == TM_INDEX_ON) ? SELECT : 0; + + if (mode & TM_CALC_NORMALS) { + tv->flag |= TX_VERT_USE_NORMAL; + copy_v3_v3(tv->normal, eve->no); + } + + tv++; + a++; + } + else { + BM_elem_index_set(eve, TM_INDEX_SKIP); /* set_dirty! */ + } + } + /* set dirty already, above */ + + userdata[1] = tvs->transverts; + } + + if (tvs->transverts && em->mesh_eval_cage) { + BM_mesh_elem_table_ensure(bm, BM_VERT); + BKE_mesh_foreach_mapped_vert(em->mesh_eval_cage, set_mapped_co, userdata, MESH_FOREACH_NOP); + } + } + else if (obedit->type == OB_ARMATURE) { + bArmature *arm = obedit->data; + int totmalloc = BLI_listbase_count(arm->edbo); + + totmalloc *= 2; /* probably overkill but bones can have 2 trans verts each */ + + tv = tvs->transverts = MEM_callocN(totmalloc * sizeof(TransVert), __func__); + + for (ebo = arm->edbo->first; ebo; ebo = ebo->next) { + if (ebo->layer & arm->layer) { + const bool tipsel = (ebo->flag & BONE_TIPSEL) != 0; + const bool rootsel = (ebo->flag & BONE_ROOTSEL) != 0; + const bool rootok = (!(ebo->parent && (ebo->flag & BONE_CONNECTED) && + (ebo->parent->flag & BONE_TIPSEL))); + + if ((tipsel && rootsel) || (rootsel)) { + /* Don't add the tip (unless mode & TM_ALL_JOINTS, for getting all joints), + * otherwise we get zero-length bones as tips will snap to the same + * location as heads. + */ + if (rootok) { + copy_v3_v3(tv->oldloc, ebo->head); + tv->loc = ebo->head; + tv->flag = SELECT; + tv++; + tvs->transverts_tot++; + } + + if ((mode & TM_ALL_JOINTS) && (tipsel)) { + copy_v3_v3(tv->oldloc, ebo->tail); + tv->loc = ebo->tail; + tv->flag = SELECT; + tv++; + tvs->transverts_tot++; + } + } + else if (tipsel) { + copy_v3_v3(tv->oldloc, ebo->tail); + tv->loc = ebo->tail; + tv->flag = SELECT; + tv++; + tvs->transverts_tot++; + } + } + } + } + else if (ELEM(obedit->type, OB_CURVE, OB_SURF)) { + Curve *cu = obedit->data; + int totmalloc = 0; + ListBase *nurbs = BKE_curve_editNurbs_get(cu); + + for (nu = nurbs->first; nu; nu = nu->next) { + if (nu->type == CU_BEZIER) + totmalloc += 3 * nu->pntsu; + else + totmalloc += nu->pntsu * nu->pntsv; + } + tv = tvs->transverts = MEM_callocN(totmalloc * sizeof(TransVert), __func__); + + nu = nurbs->first; + while (nu) { + if (nu->type == CU_BEZIER) { + a = nu->pntsu; + bezt = nu->bezt; + while (a--) { + if (bezt->hide == 0) { + bool skip_handle = false; + if (bezt->f2 & SELECT) + skip_handle = (mode & TM_SKIP_HANDLES) != 0; + + if ((bezt->f1 & SELECT) && !skip_handle) { + copy_v3_v3(tv->oldloc, bezt->vec[0]); + tv->loc = bezt->vec[0]; + tv->flag = bezt->f1 & SELECT; + + if (mode & TM_CALC_NORMALS) { + tv->flag |= TX_VERT_USE_NORMAL; + BKE_nurb_bezt_calc_plane(nu, bezt, tv->normal); + } + + tv++; + tvs->transverts_tot++; + } + if (bezt->f2 & SELECT) { + copy_v3_v3(tv->oldloc, bezt->vec[1]); + tv->loc = bezt->vec[1]; + tv->flag = bezt->f2 & SELECT; + + if (mode & TM_CALC_NORMALS) { + tv->flag |= TX_VERT_USE_NORMAL; + BKE_nurb_bezt_calc_plane(nu, bezt, tv->normal); + } + + tv++; + tvs->transverts_tot++; + } + if ((bezt->f3 & SELECT) && !skip_handle) { + copy_v3_v3(tv->oldloc, bezt->vec[2]); + tv->loc = bezt->vec[2]; + tv->flag = bezt->f3 & SELECT; + + if (mode & TM_CALC_NORMALS) { + tv->flag |= TX_VERT_USE_NORMAL; + BKE_nurb_bezt_calc_plane(nu, bezt, tv->normal); + } + + tv++; + tvs->transverts_tot++; + } + } + bezt++; + } + } + else { + a = nu->pntsu * nu->pntsv; + bp = nu->bp; + while (a--) { + if (bp->hide == 0) { + if (bp->f1 & SELECT) { + copy_v3_v3(tv->oldloc, bp->vec); + tv->loc = bp->vec; + tv->flag = bp->f1 & SELECT; + tv++; + tvs->transverts_tot++; + } + } + bp++; + } + } + nu = nu->next; + } + } + else if (obedit->type == OB_MBALL) { + MetaBall *mb = obedit->data; + int totmalloc = BLI_listbase_count(mb->editelems); + + tv = tvs->transverts = MEM_callocN(totmalloc * sizeof(TransVert), __func__); + + ml = mb->editelems->first; + while (ml) { + if (ml->flag & SELECT) { + tv->loc = &ml->x; + copy_v3_v3(tv->oldloc, tv->loc); + tv->flag = SELECT; + tv++; + tvs->transverts_tot++; + } + ml = ml->next; + } + } + else if (obedit->type == OB_LATTICE) { + Lattice *lt = obedit->data; + + bp = lt->editlatt->latt->def; + + a = lt->editlatt->latt->pntsu * lt->editlatt->latt->pntsv * lt->editlatt->latt->pntsw; + + tv = tvs->transverts = MEM_callocN(a * sizeof(TransVert), __func__); + + while (a--) { + if (bp->f1 & SELECT) { + if (bp->hide == 0) { + copy_v3_v3(tv->oldloc, bp->vec); + tv->loc = bp->vec; + tv->flag = bp->f1 & SELECT; + tv++; + tvs->transverts_tot++; + } + } + bp++; + } + } + + if (!tvs->transverts_tot && tvs->transverts) { + /* prevent memory leak. happens for curves/latticies due to */ + /* difficult condition of adding points to trans data */ + MEM_freeN(tvs->transverts); + tvs->transverts = NULL; + } + + tvs->mode = mode; } void ED_transverts_free(TransVertStore *tvs) { - MEM_SAFE_FREE(tvs->transverts); - tvs->transverts_tot = 0; + MEM_SAFE_FREE(tvs->transverts); + tvs->transverts_tot = 0; } bool ED_transverts_poll(bContext *C) { - Object *obedit = CTX_data_edit_object(C); - if (obedit) { - if (ED_transverts_check_obedit(obedit)) { - return true; - } - } - return false; + Object *obedit = CTX_data_edit_object(C); + if (obedit) { + if (ED_transverts_check_obedit(obedit)) { + return true; + } + } + return false; } diff --git a/source/blender/editors/util/ed_util.c b/source/blender/editors/util/ed_util.c index e2405591141..503910d1734 100644 --- a/source/blender/editors/util/ed_util.c +++ b/source/blender/editors/util/ed_util.c @@ -75,310 +75,311 @@ #include "WM_api.h" #include "RNA_access.h" - - /* ********* general editor util funcs, not BKE stuff please! ********* */ void ED_editors_init_for_undo(Main *bmain) { - wmWindowManager *wm = bmain->wm.first; - for (wmWindow *win = wm->windows.first; win; win = win->next) { - ViewLayer *view_layer = WM_window_get_active_view_layer(win); - Base *base = BASACT(view_layer); - if (base != NULL) { - Object *ob = base->object; - if (ob->mode & OB_MODE_TEXTURE_PAINT) { - Scene *scene = WM_window_get_active_scene(win); - - BKE_texpaint_slots_refresh_object(scene, ob); - BKE_paint_proj_mesh_data_check(scene, ob, NULL, NULL, NULL, NULL); - } - } - } + wmWindowManager *wm = bmain->wm.first; + for (wmWindow *win = wm->windows.first; win; win = win->next) { + ViewLayer *view_layer = WM_window_get_active_view_layer(win); + Base *base = BASACT(view_layer); + if (base != NULL) { + Object *ob = base->object; + if (ob->mode & OB_MODE_TEXTURE_PAINT) { + Scene *scene = WM_window_get_active_scene(win); + + BKE_texpaint_slots_refresh_object(scene, ob); + BKE_paint_proj_mesh_data_check(scene, ob, NULL, NULL, NULL, NULL); + } + } + } } void ED_editors_init(bContext *C) { - struct Depsgraph *depsgraph = CTX_data_depsgraph(C); - Main *bmain = CTX_data_main(C); - Scene *scene = CTX_data_scene(C); - wmWindowManager *wm = CTX_wm_manager(C); - - /* This is called during initialization, so we don't want to store any reports */ - ReportList *reports = CTX_wm_reports(C); - int reports_flag_prev = reports->flag & ~RPT_STORE; - - SWAP(int, reports->flag, reports_flag_prev); - - /* Don't do undo pushes when calling an operator. */ - wm->op_undo_depth++; - - /* toggle on modes for objects that were saved with these enabled. for - * e.g. linked objects we have to ensure that they are actually the - * active object in this scene. */ - Object *obact = CTX_data_active_object(C); - if (obact != NULL) { - for (Object *ob = bmain->objects.first; ob; ob = ob->id.next) { - int mode = ob->mode; - if (mode == OB_MODE_OBJECT) { - continue; - } - else if (BKE_object_has_mode_data(ob, mode)) { - continue; - } - else if (ob->type == OB_GPENCIL) { - /* For multi-edit mode we may already have mode data. - * (grease pencil does not need it) */ - continue; - } - - ID *ob_data = ob->data; - ob->mode = OB_MODE_OBJECT; - if ((ob->type == obact->type) && - !ID_IS_LINKED(ob) && - !(ob_data && ID_IS_LINKED(ob_data))) - { - if (mode == OB_MODE_EDIT) { - ED_object_editmode_enter_ex(bmain, scene, ob, 0); - } - else if (mode == OB_MODE_POSE) { - ED_object_posemode_enter_ex(bmain, ob); - } - else if (mode & OB_MODE_ALL_SCULPT) { - if (obact == ob) { - if (mode == OB_MODE_SCULPT) { - ED_object_sculptmode_enter_ex(bmain, depsgraph, scene, ob, true, reports); - } - else if (mode == OB_MODE_VERTEX_PAINT) { - ED_object_vpaintmode_enter_ex(bmain, depsgraph, wm, scene, ob); - } - else if (mode == OB_MODE_WEIGHT_PAINT) { - ED_object_wpaintmode_enter_ex(bmain, depsgraph, wm, scene, ob); - } - else { - BLI_assert(0); - } - } - else { - /* Create data for non-active objects which need it for - * mode-switching but don't yet support multi-editing. */ - if (mode & OB_MODE_ALL_SCULPT) { - ob->mode = mode; - BKE_object_sculpt_data_create(ob); - } - } - } - else { - /* TODO(campbell): avoid operator calls. */ - if (obact == ob) { - ED_object_mode_toggle(C, mode); - } - } - } - } - } - - - /* image editor paint mode */ - if (scene) { - ED_space_image_paint_update(bmain, wm, scene); - } - - SWAP(int, reports->flag, reports_flag_prev); - wm->op_undo_depth--; + struct Depsgraph *depsgraph = CTX_data_depsgraph(C); + Main *bmain = CTX_data_main(C); + Scene *scene = CTX_data_scene(C); + wmWindowManager *wm = CTX_wm_manager(C); + + /* This is called during initialization, so we don't want to store any reports */ + ReportList *reports = CTX_wm_reports(C); + int reports_flag_prev = reports->flag & ~RPT_STORE; + + SWAP(int, reports->flag, reports_flag_prev); + + /* Don't do undo pushes when calling an operator. */ + wm->op_undo_depth++; + + /* toggle on modes for objects that were saved with these enabled. for + * e.g. linked objects we have to ensure that they are actually the + * active object in this scene. */ + Object *obact = CTX_data_active_object(C); + if (obact != NULL) { + for (Object *ob = bmain->objects.first; ob; ob = ob->id.next) { + int mode = ob->mode; + if (mode == OB_MODE_OBJECT) { + continue; + } + else if (BKE_object_has_mode_data(ob, mode)) { + continue; + } + else if (ob->type == OB_GPENCIL) { + /* For multi-edit mode we may already have mode data. + * (grease pencil does not need it) */ + continue; + } + + ID *ob_data = ob->data; + ob->mode = OB_MODE_OBJECT; + if ((ob->type == obact->type) && !ID_IS_LINKED(ob) && !(ob_data && ID_IS_LINKED(ob_data))) { + if (mode == OB_MODE_EDIT) { + ED_object_editmode_enter_ex(bmain, scene, ob, 0); + } + else if (mode == OB_MODE_POSE) { + ED_object_posemode_enter_ex(bmain, ob); + } + else if (mode & OB_MODE_ALL_SCULPT) { + if (obact == ob) { + if (mode == OB_MODE_SCULPT) { + ED_object_sculptmode_enter_ex(bmain, depsgraph, scene, ob, true, reports); + } + else if (mode == OB_MODE_VERTEX_PAINT) { + ED_object_vpaintmode_enter_ex(bmain, depsgraph, wm, scene, ob); + } + else if (mode == OB_MODE_WEIGHT_PAINT) { + ED_object_wpaintmode_enter_ex(bmain, depsgraph, wm, scene, ob); + } + else { + BLI_assert(0); + } + } + else { + /* Create data for non-active objects which need it for + * mode-switching but don't yet support multi-editing. */ + if (mode & OB_MODE_ALL_SCULPT) { + ob->mode = mode; + BKE_object_sculpt_data_create(ob); + } + } + } + else { + /* TODO(campbell): avoid operator calls. */ + if (obact == ob) { + ED_object_mode_toggle(C, mode); + } + } + } + } + } + + /* image editor paint mode */ + if (scene) { + ED_space_image_paint_update(bmain, wm, scene); + } + + SWAP(int, reports->flag, reports_flag_prev); + wm->op_undo_depth--; } /* frees all editmode stuff */ void ED_editors_exit(Main *bmain, bool do_undo_system) { - if (!bmain) { - return; - } - - /* frees all editmode undos */ - if (do_undo_system && G_MAIN->wm.first) { - wmWindowManager *wm = G_MAIN->wm.first; - /* normally we don't check for NULL undo stack, - * do here since it may run in different context. */ - if (wm->undo_stack) { - BKE_undosys_stack_destroy(wm->undo_stack); - wm->undo_stack = NULL; - } - } - - for (Object *ob = bmain->objects.first; ob; ob = ob->id.next) { - if (ob->type == OB_MESH) { - Mesh *me = ob->data; - if (me->edit_mesh) { - EDBM_mesh_free(me->edit_mesh); - MEM_freeN(me->edit_mesh); - me->edit_mesh = NULL; - } - } - else if (ob->type == OB_ARMATURE) { - bArmature *arm = ob->data; - if (arm->edbo) { - ED_armature_edit_free(ob->data); - } - } - } - - /* global in meshtools... */ - ED_mesh_mirror_spatial_table(NULL, NULL, NULL, NULL, 'e'); - ED_mesh_mirror_topo_table(NULL, NULL, 'e'); + if (!bmain) { + return; + } + + /* frees all editmode undos */ + if (do_undo_system && G_MAIN->wm.first) { + wmWindowManager *wm = G_MAIN->wm.first; + /* normally we don't check for NULL undo stack, + * do here since it may run in different context. */ + if (wm->undo_stack) { + BKE_undosys_stack_destroy(wm->undo_stack); + wm->undo_stack = NULL; + } + } + + for (Object *ob = bmain->objects.first; ob; ob = ob->id.next) { + if (ob->type == OB_MESH) { + Mesh *me = ob->data; + if (me->edit_mesh) { + EDBM_mesh_free(me->edit_mesh); + MEM_freeN(me->edit_mesh); + me->edit_mesh = NULL; + } + } + else if (ob->type == OB_ARMATURE) { + bArmature *arm = ob->data; + if (arm->edbo) { + ED_armature_edit_free(ob->data); + } + } + } + + /* global in meshtools... */ + ED_mesh_mirror_spatial_table(NULL, NULL, NULL, NULL, 'e'); + ED_mesh_mirror_topo_table(NULL, NULL, 'e'); } /* flush any temp data from object editing to DNA before writing files, * rendering, copying, etc. */ bool ED_editors_flush_edits(Main *bmain, bool for_render) { - bool has_edited = false; - Object *ob; - - /* loop through all data to find edit mode or object mode, because during - * exiting we might not have a context for edit object and multiple sculpt - * objects can exist at the same time */ - for (ob = bmain->objects.first; ob; ob = ob->id.next) { - if (ob->mode & OB_MODE_SCULPT) { - /* Don't allow flushing while in the middle of a stroke (frees data in use). - * Auto-save prevents this from happening but scripts - * may cause a flush on saving: T53986. */ - if ((ob->sculpt && ob->sculpt->cache) == 0) { - /* flush multires changes (for sculpt) */ - multires_force_update(ob); - has_edited = true; - - if (for_render) { - /* flush changes from dynamic topology sculpt */ - BKE_sculptsession_bm_to_me_for_render(ob); - } - else { - /* Set reorder=false so that saving the file doesn't reorder - * the BMesh's elements */ - BKE_sculptsession_bm_to_me(ob, false); - } - } - } - else if (ob->mode & OB_MODE_EDIT) { - /* get editmode results */ - has_edited = true; - ED_object_editmode_load(bmain, ob); - } - } - - return has_edited; + bool has_edited = false; + Object *ob; + + /* loop through all data to find edit mode or object mode, because during + * exiting we might not have a context for edit object and multiple sculpt + * objects can exist at the same time */ + for (ob = bmain->objects.first; ob; ob = ob->id.next) { + if (ob->mode & OB_MODE_SCULPT) { + /* Don't allow flushing while in the middle of a stroke (frees data in use). + * Auto-save prevents this from happening but scripts + * may cause a flush on saving: T53986. */ + if ((ob->sculpt && ob->sculpt->cache) == 0) { + /* flush multires changes (for sculpt) */ + multires_force_update(ob); + has_edited = true; + + if (for_render) { + /* flush changes from dynamic topology sculpt */ + BKE_sculptsession_bm_to_me_for_render(ob); + } + else { + /* Set reorder=false so that saving the file doesn't reorder + * the BMesh's elements */ + BKE_sculptsession_bm_to_me(ob, false); + } + } + } + else if (ob->mode & OB_MODE_EDIT) { + /* get editmode results */ + has_edited = true; + ED_object_editmode_load(bmain, ob); + } + } + + return has_edited; } /* ***** XXX: functions are using old blender names, cleanup later ***** */ - /* now only used in 2d spaces, like time, ipo, nla, sima... */ /* XXX shift/ctrl not configurable */ -void apply_keyb_grid(int shift, int ctrl, float *val, float fac1, float fac2, float fac3, int invert) +void apply_keyb_grid( + int shift, int ctrl, float *val, float fac1, float fac2, float fac3, int invert) { - /* fac1 is for 'nothing', fac2 for CTRL, fac3 for SHIFT */ - if (invert) - ctrl = !ctrl; - - if (ctrl && shift) { - if (fac3 != 0.0f) *val = fac3 * floorf(*val / fac3 + 0.5f); - } - else if (ctrl) { - if (fac2 != 0.0f) *val = fac2 * floorf(*val / fac2 + 0.5f); - } - else { - if (fac1 != 0.0f) *val = fac1 * floorf(*val / fac1 + 0.5f); - } + /* fac1 is for 'nothing', fac2 for CTRL, fac3 for SHIFT */ + if (invert) + ctrl = !ctrl; + + if (ctrl && shift) { + if (fac3 != 0.0f) + *val = fac3 * floorf(*val / fac3 + 0.5f); + } + else if (ctrl) { + if (fac2 != 0.0f) + *val = fac2 * floorf(*val / fac2 + 0.5f); + } + else { + if (fac1 != 0.0f) + *val = fac1 * floorf(*val / fac1 + 0.5f); + } } -void unpack_menu(bContext *C, const char *opname, const char *id_name, const char *abs_name, const char *folder, struct PackedFile *pf) +void unpack_menu(bContext *C, + const char *opname, + const char *id_name, + const char *abs_name, + const char *folder, + struct PackedFile *pf) { - Main *bmain = CTX_data_main(C); - PointerRNA props_ptr; - uiPopupMenu *pup; - uiLayout *layout; - char line[FILE_MAX + 100]; - wmOperatorType *ot = WM_operatortype_find(opname, 1); - - pup = UI_popup_menu_begin(C, IFACE_("Unpack File"), ICON_NONE); - layout = UI_popup_menu_layout(pup); - - uiItemFullO_ptr( - layout, ot, IFACE_("Remove Pack"), ICON_NONE, - NULL, WM_OP_EXEC_DEFAULT, 0, &props_ptr); - RNA_enum_set(&props_ptr, "method", PF_REMOVE); - RNA_string_set(&props_ptr, "id", id_name); - - if (G.relbase_valid) { - char local_name[FILE_MAXDIR + FILE_MAX], fi[FILE_MAX]; - - BLI_split_file_part(abs_name, fi, sizeof(fi)); - BLI_snprintf(local_name, sizeof(local_name), "//%s/%s", folder, fi); - if (!STREQ(abs_name, local_name)) { - switch (checkPackedFile(BKE_main_blendfile_path(bmain), local_name, pf)) { - case PF_NOFILE: - BLI_snprintf(line, sizeof(line), IFACE_("Create %s"), local_name); - uiItemFullO_ptr(layout, ot, line, ICON_NONE, NULL, WM_OP_EXEC_DEFAULT, 0, &props_ptr); - RNA_enum_set(&props_ptr, "method", PF_WRITE_LOCAL); - RNA_string_set(&props_ptr, "id", id_name); - - break; - case PF_EQUAL: - BLI_snprintf(line, sizeof(line), IFACE_("Use %s (identical)"), local_name); - //uiItemEnumO_ptr(layout, ot, line, 0, "method", PF_USE_LOCAL); - uiItemFullO_ptr(layout, ot, line, ICON_NONE, NULL, WM_OP_EXEC_DEFAULT, 0, &props_ptr); - RNA_enum_set(&props_ptr, "method", PF_USE_LOCAL); - RNA_string_set(&props_ptr, "id", id_name); - - break; - case PF_DIFFERS: - BLI_snprintf(line, sizeof(line), IFACE_("Use %s (differs)"), local_name); - //uiItemEnumO_ptr(layout, ot, line, 0, "method", PF_USE_LOCAL); - uiItemFullO_ptr(layout, ot, line, ICON_NONE, NULL, WM_OP_EXEC_DEFAULT, 0, &props_ptr); - RNA_enum_set(&props_ptr, "method", PF_USE_LOCAL); - RNA_string_set(&props_ptr, "id", id_name); - - BLI_snprintf(line, sizeof(line), IFACE_("Overwrite %s"), local_name); - //uiItemEnumO_ptr(layout, ot, line, 0, "method", PF_WRITE_LOCAL); - uiItemFullO_ptr(layout, ot, line, ICON_NONE, NULL, WM_OP_EXEC_DEFAULT, 0, &props_ptr); - RNA_enum_set(&props_ptr, "method", PF_WRITE_LOCAL); - RNA_string_set(&props_ptr, "id", id_name); - break; - } - } - } - - switch (checkPackedFile(BKE_main_blendfile_path(bmain), abs_name, pf)) { - case PF_NOFILE: - BLI_snprintf(line, sizeof(line), IFACE_("Create %s"), abs_name); - //uiItemEnumO_ptr(layout, ot, line, 0, "method", PF_WRITE_ORIGINAL); - uiItemFullO_ptr(layout, ot, line, ICON_NONE, NULL, WM_OP_EXEC_DEFAULT, 0, &props_ptr); - RNA_enum_set(&props_ptr, "method", PF_WRITE_ORIGINAL); - RNA_string_set(&props_ptr, "id", id_name); - break; - case PF_EQUAL: - BLI_snprintf(line, sizeof(line), IFACE_("Use %s (identical)"), abs_name); - //uiItemEnumO_ptr(layout, ot, line, 0, "method", PF_USE_ORIGINAL); - uiItemFullO_ptr(layout, ot, line, ICON_NONE, NULL, WM_OP_EXEC_DEFAULT, 0, &props_ptr); - RNA_enum_set(&props_ptr, "method", PF_USE_ORIGINAL); - RNA_string_set(&props_ptr, "id", id_name); - break; - case PF_DIFFERS: - BLI_snprintf(line, sizeof(line), IFACE_("Use %s (differs)"), abs_name); - //uiItemEnumO_ptr(layout, ot, line, 0, "method", PF_USE_ORIGINAL); - uiItemFullO_ptr(layout, ot, line, ICON_NONE, NULL, WM_OP_EXEC_DEFAULT, 0, &props_ptr); - RNA_enum_set(&props_ptr, "method", PF_USE_ORIGINAL); - RNA_string_set(&props_ptr, "id", id_name); - - BLI_snprintf(line, sizeof(line), IFACE_("Overwrite %s"), abs_name); - //uiItemEnumO_ptr(layout, ot, line, 0, "method", PF_WRITE_ORIGINAL); - uiItemFullO_ptr(layout, ot, line, ICON_NONE, NULL, WM_OP_EXEC_DEFAULT, 0, &props_ptr); - RNA_enum_set(&props_ptr, "method", PF_WRITE_ORIGINAL); - RNA_string_set(&props_ptr, "id", id_name); - break; - } - - UI_popup_menu_end(C, pup); + Main *bmain = CTX_data_main(C); + PointerRNA props_ptr; + uiPopupMenu *pup; + uiLayout *layout; + char line[FILE_MAX + 100]; + wmOperatorType *ot = WM_operatortype_find(opname, 1); + + pup = UI_popup_menu_begin(C, IFACE_("Unpack File"), ICON_NONE); + layout = UI_popup_menu_layout(pup); + + uiItemFullO_ptr( + layout, ot, IFACE_("Remove Pack"), ICON_NONE, NULL, WM_OP_EXEC_DEFAULT, 0, &props_ptr); + RNA_enum_set(&props_ptr, "method", PF_REMOVE); + RNA_string_set(&props_ptr, "id", id_name); + + if (G.relbase_valid) { + char local_name[FILE_MAXDIR + FILE_MAX], fi[FILE_MAX]; + + BLI_split_file_part(abs_name, fi, sizeof(fi)); + BLI_snprintf(local_name, sizeof(local_name), "//%s/%s", folder, fi); + if (!STREQ(abs_name, local_name)) { + switch (checkPackedFile(BKE_main_blendfile_path(bmain), local_name, pf)) { + case PF_NOFILE: + BLI_snprintf(line, sizeof(line), IFACE_("Create %s"), local_name); + uiItemFullO_ptr(layout, ot, line, ICON_NONE, NULL, WM_OP_EXEC_DEFAULT, 0, &props_ptr); + RNA_enum_set(&props_ptr, "method", PF_WRITE_LOCAL); + RNA_string_set(&props_ptr, "id", id_name); + + break; + case PF_EQUAL: + BLI_snprintf(line, sizeof(line), IFACE_("Use %s (identical)"), local_name); + //uiItemEnumO_ptr(layout, ot, line, 0, "method", PF_USE_LOCAL); + uiItemFullO_ptr(layout, ot, line, ICON_NONE, NULL, WM_OP_EXEC_DEFAULT, 0, &props_ptr); + RNA_enum_set(&props_ptr, "method", PF_USE_LOCAL); + RNA_string_set(&props_ptr, "id", id_name); + + break; + case PF_DIFFERS: + BLI_snprintf(line, sizeof(line), IFACE_("Use %s (differs)"), local_name); + //uiItemEnumO_ptr(layout, ot, line, 0, "method", PF_USE_LOCAL); + uiItemFullO_ptr(layout, ot, line, ICON_NONE, NULL, WM_OP_EXEC_DEFAULT, 0, &props_ptr); + RNA_enum_set(&props_ptr, "method", PF_USE_LOCAL); + RNA_string_set(&props_ptr, "id", id_name); + + BLI_snprintf(line, sizeof(line), IFACE_("Overwrite %s"), local_name); + //uiItemEnumO_ptr(layout, ot, line, 0, "method", PF_WRITE_LOCAL); + uiItemFullO_ptr(layout, ot, line, ICON_NONE, NULL, WM_OP_EXEC_DEFAULT, 0, &props_ptr); + RNA_enum_set(&props_ptr, "method", PF_WRITE_LOCAL); + RNA_string_set(&props_ptr, "id", id_name); + break; + } + } + } + + switch (checkPackedFile(BKE_main_blendfile_path(bmain), abs_name, pf)) { + case PF_NOFILE: + BLI_snprintf(line, sizeof(line), IFACE_("Create %s"), abs_name); + //uiItemEnumO_ptr(layout, ot, line, 0, "method", PF_WRITE_ORIGINAL); + uiItemFullO_ptr(layout, ot, line, ICON_NONE, NULL, WM_OP_EXEC_DEFAULT, 0, &props_ptr); + RNA_enum_set(&props_ptr, "method", PF_WRITE_ORIGINAL); + RNA_string_set(&props_ptr, "id", id_name); + break; + case PF_EQUAL: + BLI_snprintf(line, sizeof(line), IFACE_("Use %s (identical)"), abs_name); + //uiItemEnumO_ptr(layout, ot, line, 0, "method", PF_USE_ORIGINAL); + uiItemFullO_ptr(layout, ot, line, ICON_NONE, NULL, WM_OP_EXEC_DEFAULT, 0, &props_ptr); + RNA_enum_set(&props_ptr, "method", PF_USE_ORIGINAL); + RNA_string_set(&props_ptr, "id", id_name); + break; + case PF_DIFFERS: + BLI_snprintf(line, sizeof(line), IFACE_("Use %s (differs)"), abs_name); + //uiItemEnumO_ptr(layout, ot, line, 0, "method", PF_USE_ORIGINAL); + uiItemFullO_ptr(layout, ot, line, ICON_NONE, NULL, WM_OP_EXEC_DEFAULT, 0, &props_ptr); + RNA_enum_set(&props_ptr, "method", PF_USE_ORIGINAL); + RNA_string_set(&props_ptr, "id", id_name); + + BLI_snprintf(line, sizeof(line), IFACE_("Overwrite %s"), abs_name); + //uiItemEnumO_ptr(layout, ot, line, 0, "method", PF_WRITE_ORIGINAL); + uiItemFullO_ptr(layout, ot, line, ICON_NONE, NULL, WM_OP_EXEC_DEFAULT, 0, &props_ptr); + RNA_enum_set(&props_ptr, "method", PF_WRITE_ORIGINAL); + RNA_string_set(&props_ptr, "id", id_name); + break; + } + + UI_popup_menu_end(C, pup); } /* ********************* generic callbacks for drawcall api *********************** */ @@ -388,32 +389,33 @@ void unpack_menu(bContext *C, const char *opname, const char *id_name, const cha */ void ED_region_draw_mouse_line_cb(const bContext *C, ARegion *ar, void *arg_info) { - wmWindow *win = CTX_wm_window(C); - const float *mval_src = (float *)arg_info; - const float mval_dst[2] = {win->eventstate->x - ar->winrct.xmin, - win->eventstate->y - ar->winrct.ymin}; + wmWindow *win = CTX_wm_window(C); + const float *mval_src = (float *)arg_info; + const float mval_dst[2] = {win->eventstate->x - ar->winrct.xmin, + win->eventstate->y - ar->winrct.ymin}; - const uint shdr_pos = GPU_vertformat_attr_add(immVertexFormat(), "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); + const uint shdr_pos = GPU_vertformat_attr_add( + immVertexFormat(), "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); - GPU_line_width(1.0f); + GPU_line_width(1.0f); - immBindBuiltinProgram(GPU_SHADER_2D_LINE_DASHED_UNIFORM_COLOR); + immBindBuiltinProgram(GPU_SHADER_2D_LINE_DASHED_UNIFORM_COLOR); - float viewport_size[4]; - GPU_viewport_size_get_f(viewport_size); - immUniform2f("viewport_size", viewport_size[2] / UI_DPI_FAC, viewport_size[3] / UI_DPI_FAC); + float viewport_size[4]; + GPU_viewport_size_get_f(viewport_size); + immUniform2f("viewport_size", viewport_size[2] / UI_DPI_FAC, viewport_size[3] / UI_DPI_FAC); - immUniform1i("colors_len", 0); /* "simple" mode */ - immUniformThemeColor(TH_VIEW_OVERLAY); - immUniform1f("dash_width", 6.0f); - immUniform1f("dash_factor", 0.5f); + immUniform1i("colors_len", 0); /* "simple" mode */ + immUniformThemeColor(TH_VIEW_OVERLAY); + immUniform1f("dash_width", 6.0f); + immUniform1f("dash_factor", 0.5f); - immBegin(GPU_PRIM_LINES, 2); - immVertex2fv(shdr_pos, mval_src); - immVertex2fv(shdr_pos, mval_dst); - immEnd(); + immBegin(GPU_PRIM_LINES, 2); + immVertex2fv(shdr_pos, mval_src); + immVertex2fv(shdr_pos, mval_dst); + immEnd(); - immUnbindProgram(); + immUnbindProgram(); } /** @@ -423,30 +425,30 @@ void ED_region_draw_mouse_line_cb(const bContext *C, ARegion *ar, void *arg_info */ void ED_spacedata_id_remap(struct ScrArea *sa, struct SpaceLink *sl, ID *old_id, ID *new_id) { - SpaceType *st = BKE_spacetype_from_id(sl->spacetype); + SpaceType *st = BKE_spacetype_from_id(sl->spacetype); - if (st && st->id_remap) { - st->id_remap(sa, sl, old_id, new_id); - } + if (st && st->id_remap) { + st->id_remap(sa, sl, old_id, new_id); + } } static int ed_flush_edits_exec(bContext *C, wmOperator *UNUSED(op)) { - Main *bmain = CTX_data_main(C); - ED_editors_flush_edits(bmain, false); - return OPERATOR_FINISHED; + Main *bmain = CTX_data_main(C); + ED_editors_flush_edits(bmain, false); + return OPERATOR_FINISHED; } void ED_OT_flush_edits(wmOperatorType *ot) { - /* identifiers */ - ot->name = "Flush Edits"; - ot->description = "Flush edit data from active editing modes"; - ot->idname = "ED_OT_flush_edits"; + /* identifiers */ + ot->name = "Flush Edits"; + ot->description = "Flush edit data from active editing modes"; + ot->idname = "ED_OT_flush_edits"; - /* api callbacks */ - ot->exec = ed_flush_edits_exec; + /* api callbacks */ + ot->exec = ed_flush_edits_exec; - /* flags */ - ot->flag = OPTYPE_INTERNAL; + /* flags */ + ot->flag = OPTYPE_INTERNAL; } diff --git a/source/blender/editors/util/gizmo_utils.c b/source/blender/editors/util/gizmo_utils.c index 002425b11b6..d330019c816 100644 --- a/source/blender/editors/util/gizmo_utils.c +++ b/source/blender/editors/util/gizmo_utils.c @@ -34,39 +34,39 @@ #include "ED_gizmo_utils.h" -bool ED_gizmo_poll_or_unlink_delayed_from_operator( - const bContext *C, wmGizmoGroupType *gzgt, - const char *idname) +bool ED_gizmo_poll_or_unlink_delayed_from_operator(const bContext *C, + wmGizmoGroupType *gzgt, + const char *idname) { #if 0 - /* Causes selection to continue showing the last gizmo. */ - wmOperator *op = WM_operator_last_redo(C); + /* Causes selection to continue showing the last gizmo. */ + wmOperator *op = WM_operator_last_redo(C); #else - wmWindowManager *wm = CTX_wm_manager(C); - wmOperator *op = wm->operators.last; + wmWindowManager *wm = CTX_wm_manager(C); + wmOperator *op = wm->operators.last; #endif - if (op == NULL || !STREQ(op->type->idname, idname)) { - WM_gizmo_group_type_unlink_delayed_ptr(gzgt); - return false; - } - return true; + if (op == NULL || !STREQ(op->type->idname, idname)) { + WM_gizmo_group_type_unlink_delayed_ptr(gzgt); + return false; + } + return true; } -bool ED_gizmo_poll_or_unlink_delayed_from_tool_ex(const bContext *C, wmGizmoGroupType *gzgt, const char *gzgt_idname) +bool ED_gizmo_poll_or_unlink_delayed_from_tool_ex(const bContext *C, + wmGizmoGroupType *gzgt, + const char *gzgt_idname) { - bToolRef_Runtime *tref_rt = WM_toolsystem_runtime_from_context((bContext *)C); - if ((tref_rt == NULL) || - !STREQ(gzgt_idname, tref_rt->gizmo_group)) - { - WM_gizmo_group_type_unlink_delayed_ptr(gzgt); - return false; - } - return true; + bToolRef_Runtime *tref_rt = WM_toolsystem_runtime_from_context((bContext *)C); + if ((tref_rt == NULL) || !STREQ(gzgt_idname, tref_rt->gizmo_group)) { + WM_gizmo_group_type_unlink_delayed_ptr(gzgt); + return false; + } + return true; } /** Can use this as poll function directly. */ bool ED_gizmo_poll_or_unlink_delayed_from_tool(const bContext *C, wmGizmoGroupType *gzgt) { - return ED_gizmo_poll_or_unlink_delayed_from_tool_ex(C, gzgt, gzgt->idname); + return ED_gizmo_poll_or_unlink_delayed_from_tool_ex(C, gzgt, gzgt->idname); } diff --git a/source/blender/editors/util/numinput.c b/source/blender/editors/util/numinput.c index aeb764f9960..0ab37d61ce4 100644 --- a/source/blender/editors/util/numinput.c +++ b/source/blender/editors/util/numinput.c @@ -36,7 +36,7 @@ #include "WM_types.h" #ifdef WITH_PYTHON -#include "BPY_extern.h" +# include "BPY_extern.h" #endif #include "ED_numinput.h" @@ -49,26 +49,26 @@ * (1 << 8) and below are reserved for public flags! */ enum { - /** Enable full editing, with units and math operators support. */ - NUM_EDIT_FULL = (1 << 9), + /** Enable full editing, with units and math operators support. */ + NUM_EDIT_FULL = (1 << 9), #ifdef USE_FAKE_EDIT - /** Fake edited state (temp, avoids issue with backspace). */ - NUM_FAKE_EDITED = (1 << 10), + /** Fake edited state (temp, avoids issue with backspace). */ + NUM_FAKE_EDITED = (1 << 10), #endif }; /* NumInput.val_flag[] */ enum { - /* (1 << 8) and below are reserved for public flags! */ - /** User has edited this value somehow. */ - NUM_EDITED = (1 << 9), - /** Current expression for this value is invalid. */ - NUM_INVALID = (1 << 10), + /* (1 << 8) and below are reserved for public flags! */ + /** User has edited this value somehow. */ + NUM_EDITED = (1 << 9), + /** Current expression for this value is invalid. */ + NUM_INVALID = (1 << 10), #ifdef USE_FAKE_EDIT - /** Current expression's result has to be negated. */ - NUM_NEGATE = (1 << 11), - /** Current expression's result has to be inverted. */ - NUM_INVERSE = (1 << 12), + /** Current expression's result has to be negated. */ + NUM_NEGATE = (1 << 11), + /** Current expression's result has to be inverted. */ + NUM_INVERSE = (1 << 12), #endif }; @@ -78,108 +78,123 @@ enum { void initNumInput(NumInput *n) { - n->idx_max = 0; - n->unit_sys = USER_UNIT_NONE; - copy_vn_i(n->unit_type, NUM_MAX_ELEMENTS, B_UNIT_NONE); - n->unit_use_radians = false; - - n->flag = 0; - copy_vn_short(n->val_flag, NUM_MAX_ELEMENTS, 0); - zero_v3(n->val); - copy_vn_fl(n->val_org, NUM_MAX_ELEMENTS, 0.0f); - copy_vn_fl(n->val_inc, NUM_MAX_ELEMENTS, 1.0f); - - n->idx = 0; - n->str[0] = '\0'; - n->str_cur = 0; + n->idx_max = 0; + n->unit_sys = USER_UNIT_NONE; + copy_vn_i(n->unit_type, NUM_MAX_ELEMENTS, B_UNIT_NONE); + n->unit_use_radians = false; + + n->flag = 0; + copy_vn_short(n->val_flag, NUM_MAX_ELEMENTS, 0); + zero_v3(n->val); + copy_vn_fl(n->val_org, NUM_MAX_ELEMENTS, 0.0f); + copy_vn_fl(n->val_inc, NUM_MAX_ELEMENTS, 1.0f); + + n->idx = 0; + n->str[0] = '\0'; + n->str_cur = 0; } /* str must be NUM_STR_REP_LEN * (idx_max + 1) length. */ void outputNumInput(NumInput *n, char *str, UnitSettings *unit_settings) { - short j; - const int ln = NUM_STR_REP_LEN; - int prec = 2; /* draw-only, and avoids too much issues with radian->degrees conversion. */ - - for (j = 0; j <= n->idx_max; j++) { - /* if AFFECTALL and no number typed and cursor not on number, use first number */ - const short i = (n->flag & NUM_AFFECT_ALL && n->idx != j && !(n->val_flag[j] & NUM_EDITED)) ? 0 : j; - - /* Use scale_length if needed! */ - const float fac = (float)BKE_scene_unit_scale(unit_settings, n->unit_type[j], 1.0); - - if (n->val_flag[i] & NUM_EDITED) { - /* Get the best precision, allows us to draw '10.0001' as '10' instead! */ - prec = UI_calc_float_precision(prec, (double)n->val[i]); - if (i == n->idx) { - const char *heading_exp = "", *trailing_exp = ""; - char before_cursor[NUM_STR_REP_LEN]; - char val[16]; + short j; + const int ln = NUM_STR_REP_LEN; + int prec = 2; /* draw-only, and avoids too much issues with radian->degrees conversion. */ + + for (j = 0; j <= n->idx_max; j++) { + /* if AFFECTALL and no number typed and cursor not on number, use first number */ + const short i = (n->flag & NUM_AFFECT_ALL && n->idx != j && !(n->val_flag[j] & NUM_EDITED)) ? + 0 : + j; + + /* Use scale_length if needed! */ + const float fac = (float)BKE_scene_unit_scale(unit_settings, n->unit_type[j], 1.0); + + if (n->val_flag[i] & NUM_EDITED) { + /* Get the best precision, allows us to draw '10.0001' as '10' instead! */ + prec = UI_calc_float_precision(prec, (double)n->val[i]); + if (i == n->idx) { + const char *heading_exp = "", *trailing_exp = ""; + char before_cursor[NUM_STR_REP_LEN]; + char val[16]; #ifdef USE_FAKE_EDIT - if (n->val_flag[i] & NUM_NEGATE) { - heading_exp = (n->val_flag[i] & NUM_INVERSE) ? "-1/(" : "-("; - trailing_exp = ")"; - } - else if (n->val_flag[i] & NUM_INVERSE) { - heading_exp = "1/("; - trailing_exp = ")"; - } + if (n->val_flag[i] & NUM_NEGATE) { + heading_exp = (n->val_flag[i] & NUM_INVERSE) ? "-1/(" : "-("; + trailing_exp = ")"; + } + else if (n->val_flag[i] & NUM_INVERSE) { + heading_exp = "1/("; + trailing_exp = ")"; + } #endif - if (n->val_flag[i] & NUM_INVALID) { - BLI_strncpy(val, "Invalid", sizeof(val)); - } - else { - bUnit_AsString(val, sizeof(val), (double)(n->val[i] * fac), prec, - n->unit_sys, n->unit_type[i], true, false); - } - - /* +1 because of trailing '\0' */ - BLI_strncpy(before_cursor, n->str, n->str_cur + 1); - BLI_snprintf(&str[j * ln], ln, "[%s%s|%s%s] = %s", - heading_exp, before_cursor, &n->str[n->str_cur], trailing_exp, val); - } - else { - const char *cur = (i == n->idx) ? "|" : ""; - if (n->unit_use_radians && n->unit_type[i] == B_UNIT_ROTATION) { - /* Radian exception... */ - BLI_snprintf(&str[j * ln], ln, "%s%.6gr%s", cur, n->val[i], cur); - } - else { - char tstr[NUM_STR_REP_LEN]; - bUnit_AsString(tstr, ln, (double)n->val[i], prec, n->unit_sys, n->unit_type[i], true, false); - BLI_snprintf(&str[j * ln], ln, "%s%s%s", cur, tstr, cur); - } - } - } - else { - const char *cur = (i == n->idx) ? "|" : ""; - BLI_snprintf(&str[j * ln], ln, "%sNONE%s", cur, cur); - } - /* We might have cut some multi-bytes utf8 chars - * (e.g. trailing '°' of degrees values can become only 'A')... */ - BLI_utf8_invalid_strip(&str[j * ln], strlen(&str[j * ln])); - } + if (n->val_flag[i] & NUM_INVALID) { + BLI_strncpy(val, "Invalid", sizeof(val)); + } + else { + bUnit_AsString(val, + sizeof(val), + (double)(n->val[i] * fac), + prec, + n->unit_sys, + n->unit_type[i], + true, + false); + } + + /* +1 because of trailing '\0' */ + BLI_strncpy(before_cursor, n->str, n->str_cur + 1); + BLI_snprintf(&str[j * ln], + ln, + "[%s%s|%s%s] = %s", + heading_exp, + before_cursor, + &n->str[n->str_cur], + trailing_exp, + val); + } + else { + const char *cur = (i == n->idx) ? "|" : ""; + if (n->unit_use_radians && n->unit_type[i] == B_UNIT_ROTATION) { + /* Radian exception... */ + BLI_snprintf(&str[j * ln], ln, "%s%.6gr%s", cur, n->val[i], cur); + } + else { + char tstr[NUM_STR_REP_LEN]; + bUnit_AsString( + tstr, ln, (double)n->val[i], prec, n->unit_sys, n->unit_type[i], true, false); + BLI_snprintf(&str[j * ln], ln, "%s%s%s", cur, tstr, cur); + } + } + } + else { + const char *cur = (i == n->idx) ? "|" : ""; + BLI_snprintf(&str[j * ln], ln, "%sNONE%s", cur, cur); + } + /* We might have cut some multi-bytes utf8 chars + * (e.g. trailing '°' of degrees values can become only 'A')... */ + BLI_utf8_invalid_strip(&str[j * ln], strlen(&str[j * ln])); + } } bool hasNumInput(const NumInput *n) { - short i; + short i; #ifdef USE_FAKE_EDIT - if (n->flag & NUM_FAKE_EDITED) { - return true; - } + if (n->flag & NUM_FAKE_EDITED) { + return true; + } #endif - for (i = 0; i <= n->idx_max; i++) { - if (n->val_flag[i] & NUM_EDITED) { - return true; - } - } + for (i = 0; i <= n->idx_max; i++) { + if (n->val_flag[i] & NUM_EDITED) { + return true; + } + } - return false; + return false; } /** @@ -187,410 +202,412 @@ bool hasNumInput(const NumInput *n) */ bool applyNumInput(NumInput *n, float *vec) { - short i, j; - float val; + short i, j; + float val; - if (hasNumInput(n)) { - for (j = 0; j <= n->idx_max; j++) { + if (hasNumInput(n)) { + for (j = 0; j <= n->idx_max; j++) { #ifdef USE_FAKE_EDIT - if (n->flag & NUM_FAKE_EDITED) { - val = n->val[j]; - } - else + if (n->flag & NUM_FAKE_EDITED) { + val = n->val[j]; + } + else #endif - { - /* if AFFECTALL and no number typed and cursor not on number, use first number */ - i = (n->flag & NUM_AFFECT_ALL && n->idx != j && !(n->val_flag[j] & NUM_EDITED)) ? 0 : j; - val = (!(n->val_flag[i] & NUM_EDITED) && n->val_flag[i] & NUM_NULL_ONE) ? 1.0f : n->val[i]; - - if (n->val_flag[i] & NUM_NO_NEGATIVE && val < 0.0f) { - val = 0.0f; - } - if (n->val_flag[i] & NUM_NO_FRACTION && val != floorf(val)) { - val = floorf(val + 0.5f); - if (n->val_flag[i] & NUM_NO_ZERO && val == 0.0f) { - val = 1.0f; - } - } - else if (n->val_flag[i] & NUM_NO_ZERO && val == 0.0f) { - val = 0.0001f; - } - } - vec[j] = val; - } + { + /* if AFFECTALL and no number typed and cursor not on number, use first number */ + i = (n->flag & NUM_AFFECT_ALL && n->idx != j && !(n->val_flag[j] & NUM_EDITED)) ? 0 : j; + val = (!(n->val_flag[i] & NUM_EDITED) && n->val_flag[i] & NUM_NULL_ONE) ? 1.0f : n->val[i]; + + if (n->val_flag[i] & NUM_NO_NEGATIVE && val < 0.0f) { + val = 0.0f; + } + if (n->val_flag[i] & NUM_NO_FRACTION && val != floorf(val)) { + val = floorf(val + 0.5f); + if (n->val_flag[i] & NUM_NO_ZERO && val == 0.0f) { + val = 1.0f; + } + } + else if (n->val_flag[i] & NUM_NO_ZERO && val == 0.0f) { + val = 0.0001f; + } + } + vec[j] = val; + } #ifdef USE_FAKE_EDIT - n->flag &= ~NUM_FAKE_EDITED; + n->flag &= ~NUM_FAKE_EDITED; #endif - return true; - } - else { - /* Else, we set the 'org' values for numinput! */ - for (j = 0; j <= n->idx_max; j++) { - n->val[j] = n->val_org[j] = vec[j]; - } - return false; - } + return true; + } + else { + /* Else, we set the 'org' values for numinput! */ + for (j = 0; j <= n->idx_max; j++) { + n->val[j] = n->val_org[j] = vec[j]; + } + return false; + } } - static void value_to_editstr(NumInput *n, int idx) { - const int prec = 6; /* editing, higher precision needed. */ - n->str_cur = bUnit_AsString(n->str, NUM_STR_REP_LEN, (double)n->val[idx], prec, - n->unit_sys, n->unit_type[idx], true, false); + const int prec = 6; /* editing, higher precision needed. */ + n->str_cur = bUnit_AsString(n->str, + NUM_STR_REP_LEN, + (double)n->val[idx], + prec, + n->unit_sys, + n->unit_type[idx], + true, + false); } static bool editstr_insert_at_cursor(NumInput *n, const char *buf, const int buf_len) { - int cur = n->str_cur; - int len = strlen(&n->str[cur]) + 1; /* +1 for the trailing '\0'. */ - int n_cur = cur + buf_len; + int cur = n->str_cur; + int len = strlen(&n->str[cur]) + 1; /* +1 for the trailing '\0'. */ + int n_cur = cur + buf_len; - if (n_cur + len >= NUM_STR_REP_LEN) { - return false; - } + if (n_cur + len >= NUM_STR_REP_LEN) { + return false; + } - memmove(&n->str[n_cur], &n->str[cur], len); - memcpy(&n->str[cur], buf, sizeof(char) * buf_len); + memmove(&n->str[n_cur], &n->str[cur], len); + memcpy(&n->str[cur], buf, sizeof(char) * buf_len); - n->str_cur = n_cur; - return true; + n->str_cur = n_cur; + return true; } -bool user_string_to_number(bContext *C, const char *str, const UnitSettings *unit, int type, double *r_value) +bool user_string_to_number( + bContext *C, const char *str, const UnitSettings *unit, int type, double *r_value) { #ifdef WITH_PYTHON - double unit_scale = BKE_scene_unit_scale(unit, type, 1.0); - if (bUnit_ContainsUnit(str, type)) { - char str_unit_convert[256]; - BLI_strncpy(str_unit_convert, str, sizeof(str_unit_convert)); - bUnit_ReplaceString( - str_unit_convert, sizeof(str_unit_convert), str, - unit_scale, unit->system, type); - - return BPY_execute_string_as_number(C, NULL, str_unit_convert, true, r_value); - } - else { - int success = BPY_execute_string_as_number(C, NULL, str, true, r_value); - *r_value *= bUnit_PreferredInputUnitScalar(unit, type); - *r_value /= unit_scale; - return success; - } + double unit_scale = BKE_scene_unit_scale(unit, type, 1.0); + if (bUnit_ContainsUnit(str, type)) { + char str_unit_convert[256]; + BLI_strncpy(str_unit_convert, str, sizeof(str_unit_convert)); + bUnit_ReplaceString( + str_unit_convert, sizeof(str_unit_convert), str, unit_scale, unit->system, type); + + return BPY_execute_string_as_number(C, NULL, str_unit_convert, true, r_value); + } + else { + int success = BPY_execute_string_as_number(C, NULL, str, true, r_value); + *r_value *= bUnit_PreferredInputUnitScalar(unit, type); + *r_value /= unit_scale; + return success; + } #else - *r_value = atof(str); - return true; + *r_value = atof(str); + return true; #endif } - static bool editstr_is_simple_numinput(const char ascii) { - if (ascii >= '0' && ascii <= '9') { - return true; - } - else if (ascii == '.') { - return true; - } - else { - return false; - } + if (ascii >= '0' && ascii <= '9') { + return true; + } + else if (ascii == '.') { + return true; + } + else { + return false; + } } bool handleNumInput(bContext *C, NumInput *n, const wmEvent *event) { - const char *utf8_buf = NULL; - char ascii[2] = {'\0', '\0'}; - bool updated = false; - short idx = n->idx, idx_max = n->idx_max; - short dir = STRCUR_DIR_NEXT, mode = STRCUR_JUMP_NONE; - int cur; + const char *utf8_buf = NULL; + char ascii[2] = {'\0', '\0'}; + bool updated = false; + short idx = n->idx, idx_max = n->idx_max; + short dir = STRCUR_DIR_NEXT, mode = STRCUR_JUMP_NONE; + int cur; #ifdef USE_FAKE_EDIT - if (U.flag & USER_FLAG_NUMINPUT_ADVANCED) + if (U.flag & USER_FLAG_NUMINPUT_ADVANCED) #endif - { - if ((event->ctrl == 0) && (event->alt == 0) && (event->ascii != '\0') && - strchr("01234567890@%^&*-+/{}()[]<>.|", event->ascii)) - { - if (!(n->flag & NUM_EDIT_FULL)) { - n->flag |= NUM_EDITED; - n->flag |= NUM_EDIT_FULL; - n->val_flag[idx] |= NUM_EDITED; - } - } - } - - switch (event->type) { - case EVT_MODAL_MAP: - if (ELEM(event->val, NUM_MODAL_INCREMENT_UP, NUM_MODAL_INCREMENT_DOWN)) { - n->val[idx] += (event->val == NUM_MODAL_INCREMENT_UP) ? n->val_inc[idx] : -n->val_inc[idx]; - value_to_editstr(n, idx); - n->val_flag[idx] |= NUM_EDITED; - updated = true; - } - else { - /* might be a char too... */ - utf8_buf = event->utf8_buf; - ascii[0] = event->ascii; - } - break; - case BACKSPACEKEY: - /* Part specific to backspace... */ - if (!(n->val_flag[idx] & NUM_EDITED)) { - copy_v3_v3(n->val, n->val_org); - n->val_flag[0] &= ~NUM_EDITED; - n->val_flag[1] &= ~NUM_EDITED; - n->val_flag[2] &= ~NUM_EDITED; + { + if ((event->ctrl == 0) && (event->alt == 0) && (event->ascii != '\0') && + strchr("01234567890@%^&*-+/{}()[]<>.|", event->ascii)) { + if (!(n->flag & NUM_EDIT_FULL)) { + n->flag |= NUM_EDITED; + n->flag |= NUM_EDIT_FULL; + n->val_flag[idx] |= NUM_EDITED; + } + } + } + + switch (event->type) { + case EVT_MODAL_MAP: + if (ELEM(event->val, NUM_MODAL_INCREMENT_UP, NUM_MODAL_INCREMENT_DOWN)) { + n->val[idx] += (event->val == NUM_MODAL_INCREMENT_UP) ? n->val_inc[idx] : -n->val_inc[idx]; + value_to_editstr(n, idx); + n->val_flag[idx] |= NUM_EDITED; + updated = true; + } + else { + /* might be a char too... */ + utf8_buf = event->utf8_buf; + ascii[0] = event->ascii; + } + break; + case BACKSPACEKEY: + /* Part specific to backspace... */ + if (!(n->val_flag[idx] & NUM_EDITED)) { + copy_v3_v3(n->val, n->val_org); + n->val_flag[0] &= ~NUM_EDITED; + n->val_flag[1] &= ~NUM_EDITED; + n->val_flag[2] &= ~NUM_EDITED; #ifdef USE_FAKE_EDIT - n->flag |= NUM_FAKE_EDITED; + n->flag |= NUM_FAKE_EDITED; #else - n->flag |= NUM_EDIT_FULL; + n->flag |= NUM_EDIT_FULL; #endif - updated = true; - break; - } - else if (event->shift || !n->str[0]) { - n->val[idx] = n->val_org[idx]; - n->val_flag[idx] &= ~NUM_EDITED; - n->str[0] = '\0'; - n->str_cur = 0; - updated = true; - break; - } - /* Else, common behavior with DELKEY, - * only difference is remove char(s) before/after the cursor. */ - dir = STRCUR_DIR_PREV; - ATTR_FALLTHROUGH; - case DELKEY: - if ((n->val_flag[idx] & NUM_EDITED) && n->str[0]) { - int t_cur = cur = n->str_cur; - if (event->ctrl) { - mode = STRCUR_JUMP_DELIM; - } - BLI_str_cursor_step_utf8(n->str, strlen(n->str), &t_cur, dir, mode, true); - if (t_cur != cur) { - if (t_cur < cur) { - SWAP(int, t_cur, cur); - n->str_cur = cur; - } - /* +1 for trailing '\0'. */ - memmove(&n->str[cur], &n->str[t_cur], strlen(&n->str[t_cur]) + 1); - updated = true; - } - if (!n->str[0]) { - n->val[idx] = n->val_org[idx]; - } - } - else { - return false; - } - break; - case LEFTARROWKEY: - dir = STRCUR_DIR_PREV; - ATTR_FALLTHROUGH; - case RIGHTARROWKEY: - cur = n->str_cur; - if (event->ctrl) { - mode = STRCUR_JUMP_DELIM; - } - BLI_str_cursor_step_utf8(n->str, strlen(n->str), &cur, dir, mode, true); - if (cur != n->str_cur) { - n->str_cur = cur; - return true; - } - return false; - case HOMEKEY: - if (n->str[0]) { - n->str_cur = 0; - return true; - } - return false; - case ENDKEY: - if (n->str[0]) { - n->str_cur = strlen(n->str); - return true; - } - return false; - case TABKEY: + updated = true; + break; + } + else if (event->shift || !n->str[0]) { + n->val[idx] = n->val_org[idx]; + n->val_flag[idx] &= ~NUM_EDITED; + n->str[0] = '\0'; + n->str_cur = 0; + updated = true; + break; + } + /* Else, common behavior with DELKEY, + * only difference is remove char(s) before/after the cursor. */ + dir = STRCUR_DIR_PREV; + ATTR_FALLTHROUGH; + case DELKEY: + if ((n->val_flag[idx] & NUM_EDITED) && n->str[0]) { + int t_cur = cur = n->str_cur; + if (event->ctrl) { + mode = STRCUR_JUMP_DELIM; + } + BLI_str_cursor_step_utf8(n->str, strlen(n->str), &t_cur, dir, mode, true); + if (t_cur != cur) { + if (t_cur < cur) { + SWAP(int, t_cur, cur); + n->str_cur = cur; + } + /* +1 for trailing '\0'. */ + memmove(&n->str[cur], &n->str[t_cur], strlen(&n->str[t_cur]) + 1); + updated = true; + } + if (!n->str[0]) { + n->val[idx] = n->val_org[idx]; + } + } + else { + return false; + } + break; + case LEFTARROWKEY: + dir = STRCUR_DIR_PREV; + ATTR_FALLTHROUGH; + case RIGHTARROWKEY: + cur = n->str_cur; + if (event->ctrl) { + mode = STRCUR_JUMP_DELIM; + } + BLI_str_cursor_step_utf8(n->str, strlen(n->str), &cur, dir, mode, true); + if (cur != n->str_cur) { + n->str_cur = cur; + return true; + } + return false; + case HOMEKEY: + if (n->str[0]) { + n->str_cur = 0; + return true; + } + return false; + case ENDKEY: + if (n->str[0]) { + n->str_cur = strlen(n->str); + return true; + } + return false; + case TABKEY: #ifdef USE_FAKE_EDIT - n->val_flag[idx] &= ~(NUM_NEGATE | NUM_INVERSE); + n->val_flag[idx] &= ~(NUM_NEGATE | NUM_INVERSE); #endif - idx = (idx + idx_max + (event->ctrl ? 0 : 2)) % (idx_max + 1); - n->idx = idx; - if (n->val_flag[idx] & NUM_EDITED) { - value_to_editstr(n, idx); - } - else { - n->str[0] = '\0'; - n->str_cur = 0; - } - return true; - case PADPERIOD: - case PERIODKEY: - /* Force numdot, some OSs/countries generate a comma char in this case, - * sic... (T37992) */ - ascii[0] = '.'; - utf8_buf = ascii; - break; + idx = (idx + idx_max + (event->ctrl ? 0 : 2)) % (idx_max + 1); + n->idx = idx; + if (n->val_flag[idx] & NUM_EDITED) { + value_to_editstr(n, idx); + } + else { + n->str[0] = '\0'; + n->str_cur = 0; + } + return true; + case PADPERIOD: + case PERIODKEY: + /* Force numdot, some OSs/countries generate a comma char in this case, + * sic... (T37992) */ + ascii[0] = '.'; + utf8_buf = ascii; + break; #if 0 - /* Those keys are not directly accessible in all layouts, preventing to generate matching events. - * So we use a hack (ascii value) instead, see below. - */ - case EQUALKEY: - case PADASTERKEY: - if (!(n->flag & NUM_EDIT_FULL)) { - n->flag |= NUM_EDIT_FULL; - n->val_flag[idx] |= NUM_EDITED; - return true; - } - else if (event->ctrl) { - n->flag &= ~NUM_EDIT_FULL; - return true; - } - break; + /* Those keys are not directly accessible in all layouts, preventing to generate matching events. + * So we use a hack (ascii value) instead, see below. + */ + case EQUALKEY: + case PADASTERKEY: + if (!(n->flag & NUM_EDIT_FULL)) { + n->flag |= NUM_EDIT_FULL; + n->val_flag[idx] |= NUM_EDITED; + return true; + } + else if (event->ctrl) { + n->flag &= ~NUM_EDIT_FULL; + return true; + } + break; #endif #ifdef USE_FAKE_EDIT - case PADMINUS: - case MINUSKEY: - if (event->ctrl || !(n->flag & NUM_EDIT_FULL)) { - n->val_flag[idx] ^= NUM_NEGATE; - updated = true; - } - break; - case PADSLASHKEY: - case SLASHKEY: - if (event->ctrl || !(n->flag & NUM_EDIT_FULL)) { - n->val_flag[idx] ^= NUM_INVERSE; - updated = true; - } - break; + case PADMINUS: + case MINUSKEY: + if (event->ctrl || !(n->flag & NUM_EDIT_FULL)) { + n->val_flag[idx] ^= NUM_NEGATE; + updated = true; + } + break; + case PADSLASHKEY: + case SLASHKEY: + if (event->ctrl || !(n->flag & NUM_EDIT_FULL)) { + n->val_flag[idx] ^= NUM_INVERSE; + updated = true; + } + break; #endif - case CKEY: - if (event->ctrl) { - /* Copy current str to the copypaste buffer. */ - WM_clipboard_text_set(n->str, 0); - updated = true; - } - break; - case VKEY: - if (event->ctrl) { - /* extract the first line from the clipboard */ - int pbuf_len; - char *pbuf = WM_clipboard_text_get_firstline(false, &pbuf_len); - - if (pbuf) { - const bool success = editstr_insert_at_cursor(n, pbuf, pbuf_len); - - MEM_freeN(pbuf); - if (!success) { - return false; - } - - n->val_flag[idx] |= NUM_EDITED; - } - updated = true; - } - break; - default: - break; - } - - if (!updated && !utf8_buf && (event->utf8_buf[0] || event->ascii)) { - utf8_buf = event->utf8_buf; - ascii[0] = event->ascii; - } + case CKEY: + if (event->ctrl) { + /* Copy current str to the copypaste buffer. */ + WM_clipboard_text_set(n->str, 0); + updated = true; + } + break; + case VKEY: + if (event->ctrl) { + /* extract the first line from the clipboard */ + int pbuf_len; + char *pbuf = WM_clipboard_text_get_firstline(false, &pbuf_len); + + if (pbuf) { + const bool success = editstr_insert_at_cursor(n, pbuf, pbuf_len); + + MEM_freeN(pbuf); + if (!success) { + return false; + } + + n->val_flag[idx] |= NUM_EDITED; + } + updated = true; + } + break; + default: + break; + } + + if (!updated && !utf8_buf && (event->utf8_buf[0] || event->ascii)) { + utf8_buf = event->utf8_buf; + ascii[0] = event->ascii; + } #ifdef USE_FAKE_EDIT - /* XXX Hack around keyboards without direct access to '=' nor '*'... */ - if (ELEM(ascii[0], '=', '*')) { - if (!(n->flag & NUM_EDIT_FULL)) { - n->flag |= NUM_EDIT_FULL; - n->val_flag[idx] |= NUM_EDITED; - return true; - } - else if (event->ctrl) { - n->flag &= ~NUM_EDIT_FULL; - return true; - } - } + /* XXX Hack around keyboards without direct access to '=' nor '*'... */ + if (ELEM(ascii[0], '=', '*')) { + if (!(n->flag & NUM_EDIT_FULL)) { + n->flag |= NUM_EDIT_FULL; + n->val_flag[idx] |= NUM_EDITED; + return true; + } + else if (event->ctrl) { + n->flag &= ~NUM_EDIT_FULL; + return true; + } + } #endif - /* Up to this point, if we have a ctrl modifier, skip. - * This allows to still access most of modals' shortcuts even in numinput mode. - */ - if (!updated && event->ctrl) { - return false; - } - - if ((!utf8_buf || !utf8_buf[0]) && ascii[0]) { - /* Fallback to ascii. */ - utf8_buf = ascii; - } - - if (utf8_buf && utf8_buf[0]) { - if (!(n->flag & NUM_EDIT_FULL)) { - /* In simple edit mode, we only keep a few chars as valid! */ - /* no need to decode unicode, ascii is first char only */ - if (!editstr_is_simple_numinput(utf8_buf[0])) { - return false; - } - } - - if (!editstr_insert_at_cursor(n, utf8_buf, BLI_str_utf8_size(utf8_buf))) { - return false; - } - - n->val_flag[idx] |= NUM_EDITED; - } - else if (!updated) { - return false; - } - - /* At this point, our value has changed, try to interpret it with python - * (if str is not empty!). */ - if (n->str[0]) { - const float val_prev = n->val[idx]; - Scene *sce = CTX_data_scene(C); - - double val; - int success = user_string_to_number(C, n->str, &sce->unit, n->unit_type[idx], &val); - - if (success) { - n->val[idx] = (float)val; - n->val_flag[idx] &= ~NUM_INVALID; - } - else { - n->val_flag[idx] |= NUM_INVALID; - } - + /* Up to this point, if we have a ctrl modifier, skip. + * This allows to still access most of modals' shortcuts even in numinput mode. + */ + if (!updated && event->ctrl) { + return false; + } + + if ((!utf8_buf || !utf8_buf[0]) && ascii[0]) { + /* Fallback to ascii. */ + utf8_buf = ascii; + } + + if (utf8_buf && utf8_buf[0]) { + if (!(n->flag & NUM_EDIT_FULL)) { + /* In simple edit mode, we only keep a few chars as valid! */ + /* no need to decode unicode, ascii is first char only */ + if (!editstr_is_simple_numinput(utf8_buf[0])) { + return false; + } + } + + if (!editstr_insert_at_cursor(n, utf8_buf, BLI_str_utf8_size(utf8_buf))) { + return false; + } + + n->val_flag[idx] |= NUM_EDITED; + } + else if (!updated) { + return false; + } + + /* At this point, our value has changed, try to interpret it with python + * (if str is not empty!). */ + if (n->str[0]) { + const float val_prev = n->val[idx]; + Scene *sce = CTX_data_scene(C); + + double val; + int success = user_string_to_number(C, n->str, &sce->unit, n->unit_type[idx], &val); + + if (success) { + n->val[idx] = (float)val; + n->val_flag[idx] &= ~NUM_INVALID; + } + else { + n->val_flag[idx] |= NUM_INVALID; + } #ifdef USE_FAKE_EDIT - if (n->val_flag[idx] & NUM_NEGATE) { - n->val[idx] = -n->val[idx]; - } - if (n->val_flag[idx] & NUM_INVERSE) { - val = n->val[idx]; - /* If we invert on radians when user is in degrees, - * you get unexpected results... See T53463. */ - if (!n->unit_use_radians && n->unit_type[idx] == B_UNIT_ROTATION) { - val = RAD2DEG(val); - } - val = 1.0 / val; - if (!n->unit_use_radians && n->unit_type[idx] == B_UNIT_ROTATION) { - val = DEG2RAD(val); - } - n->val[idx] = (float)val; - } + if (n->val_flag[idx] & NUM_NEGATE) { + n->val[idx] = -n->val[idx]; + } + if (n->val_flag[idx] & NUM_INVERSE) { + val = n->val[idx]; + /* If we invert on radians when user is in degrees, + * you get unexpected results... See T53463. */ + if (!n->unit_use_radians && n->unit_type[idx] == B_UNIT_ROTATION) { + val = RAD2DEG(val); + } + val = 1.0 / val; + if (!n->unit_use_radians && n->unit_type[idx] == B_UNIT_ROTATION) { + val = DEG2RAD(val); + } + n->val[idx] = (float)val; + } #endif - if (UNLIKELY(!isfinite(n->val[idx]))) { - n->val[idx] = val_prev; - n->val_flag[idx] |= NUM_INVALID; - } - } + if (UNLIKELY(!isfinite(n->val[idx]))) { + n->val[idx] = val_prev; + n->val_flag[idx] |= NUM_INVALID; + } + } - /* REDRAW SINCE NUMBERS HAVE CHANGED */ - return true; + /* REDRAW SINCE NUMBERS HAVE CHANGED */ + return true; } diff --git a/source/blender/editors/util/select_utils.c b/source/blender/editors/util/select_utils.c index b8167632fd9..13c623a2860 100644 --- a/source/blender/editors/util/select_utils.c +++ b/source/blender/editors/util/select_utils.c @@ -29,20 +29,20 @@ /** 1: select, 0: deselect, -1: pass. */ int ED_select_op_action(const eSelectOp sel_op, const bool is_select, const bool is_inside) { - switch (sel_op) { - case SEL_OP_ADD: - return (!is_select && (is_inside)) ? 1 : -1; - case SEL_OP_SUB: - return (is_select && is_inside) ? 0 : -1; - case SEL_OP_SET: - return is_inside ? 1 : 0; - case SEL_OP_AND: - return (is_select && is_inside) ? -1 : (is_select ? 0 : -1); - case SEL_OP_XOR: - return (is_select && is_inside) ? 0 : ((!is_select && is_inside) ? 1 : -1); - } - BLI_assert(!"invalid sel_op"); - return -1; + switch (sel_op) { + case SEL_OP_ADD: + return (!is_select && (is_inside)) ? 1 : -1; + case SEL_OP_SUB: + return (is_select && is_inside) ? 0 : -1; + case SEL_OP_SET: + return is_inside ? 1 : 0; + case SEL_OP_AND: + return (is_select && is_inside) ? -1 : (is_select ? 0 : -1); + case SEL_OP_XOR: + return (is_select && is_inside) ? 0 : ((!is_select && is_inside) ? 1 : -1); + } + BLI_assert(!"invalid sel_op"); + return -1; } /** * Use when we've de-selected all items first (for modes that need it). @@ -50,23 +50,25 @@ int ED_select_op_action(const eSelectOp sel_op, const bool is_select, const bool * \note In some cases changing selection needs to perform other checks, * so it's more straightforward to deselect all, then select. */ -int ED_select_op_action_deselected(const eSelectOp sel_op, const bool is_select, const bool is_inside) +int ED_select_op_action_deselected(const eSelectOp sel_op, + const bool is_select, + const bool is_inside) { - switch (sel_op) { - case SEL_OP_ADD: - return (!is_select && is_inside) ? 1 : -1; - case SEL_OP_SUB: - return (is_select && is_inside) ? 0 : -1; - case SEL_OP_SET: - /* Only difference w/ function above. */ - return is_inside ? 1 : -1; - case SEL_OP_AND: - return (is_select && is_inside) ? -1 : (is_select ? 0 : -1); - case SEL_OP_XOR: - return (is_select && is_inside) ? 0 : ((!is_select && is_inside) ? 1 : -1); - } - BLI_assert(!"invalid sel_op"); - return -1; + switch (sel_op) { + case SEL_OP_ADD: + return (!is_select && is_inside) ? 1 : -1; + case SEL_OP_SUB: + return (is_select && is_inside) ? 0 : -1; + case SEL_OP_SET: + /* Only difference w/ function above. */ + return is_inside ? 1 : -1; + case SEL_OP_AND: + return (is_select && is_inside) ? -1 : (is_select ? 0 : -1); + case SEL_OP_XOR: + return (is_select && is_inside) ? 0 : ((!is_select && is_inside) ? 1 : -1); + } + BLI_assert(!"invalid sel_op"); + return -1; } /** @@ -74,60 +76,63 @@ int ED_select_op_action_deselected(const eSelectOp sel_op, const bool is_select, */ eSelectOp ED_select_op_modal(const eSelectOp sel_op, const bool is_first) { - if (sel_op == SEL_OP_SET) { - if (is_first == false) { - return SEL_OP_ADD; - } - } - return sel_op; + if (sel_op == SEL_OP_SET) { + if (is_first == false) { + return SEL_OP_ADD; + } + } + return sel_op; } int ED_select_similar_compare_float(const float delta, const float thresh, const int compare) { - switch (compare) { - case SIM_CMP_EQ: - return (fabsf(delta) < thresh + FLT_EPSILON); - case SIM_CMP_GT: - return ((delta + thresh) > -FLT_EPSILON); - case SIM_CMP_LT: - return ((delta - thresh) < FLT_EPSILON); - default: - BLI_assert(0); - return 0; - } + switch (compare) { + case SIM_CMP_EQ: + return (fabsf(delta) < thresh + FLT_EPSILON); + case SIM_CMP_GT: + return ((delta + thresh) > -FLT_EPSILON); + case SIM_CMP_LT: + return ((delta - thresh) < FLT_EPSILON); + default: + BLI_assert(0); + return 0; + } } -bool ED_select_similar_compare_float_tree(const KDTree_1d *tree, const float length, const float thresh, const int compare) +bool ED_select_similar_compare_float_tree(const KDTree_1d *tree, + const float length, + const float thresh, + const int compare) { - /* Length of the edge we want to compare against. */ - float nearest_edge_length; + /* Length of the edge we want to compare against. */ + float nearest_edge_length; - switch (compare) { - case SIM_CMP_EQ: - /* Compare to the edge closest to the current edge. */ - nearest_edge_length = length; - break; - case SIM_CMP_GT: - /* Compare against the shortest edge. */ - /* -FLT_MAX leads to some precision issues and the wrong edge being selected. - * For example, in a tree with 1, 2 and 3, which is stored squared as 1, 4, 9, it returns as the nearest - * length/node the "4" instead of "1". */ - nearest_edge_length = -1.0f; - break; - case SIM_CMP_LT: - /* Compare against the longest edge. */ - nearest_edge_length = FLT_MAX; - break; - default: - BLI_assert(0); - return false; - } + switch (compare) { + case SIM_CMP_EQ: + /* Compare to the edge closest to the current edge. */ + nearest_edge_length = length; + break; + case SIM_CMP_GT: + /* Compare against the shortest edge. */ + /* -FLT_MAX leads to some precision issues and the wrong edge being selected. + * For example, in a tree with 1, 2 and 3, which is stored squared as 1, 4, 9, it returns as the nearest + * length/node the "4" instead of "1". */ + nearest_edge_length = -1.0f; + break; + case SIM_CMP_LT: + /* Compare against the longest edge. */ + nearest_edge_length = FLT_MAX; + break; + default: + BLI_assert(0); + return false; + } - KDTreeNearest_1d nearest; - if (BLI_kdtree_1d_find_nearest(tree, &nearest_edge_length, &nearest) != -1) { - float delta = length - nearest.co[0]; - return ED_select_similar_compare_float(delta, thresh, compare); - } + KDTreeNearest_1d nearest; + if (BLI_kdtree_1d_find_nearest(tree, &nearest_edge_length, &nearest) != -1) { + float delta = length - nearest.co[0]; + return ED_select_similar_compare_float(delta, thresh, compare); + } - return false; + return false; } |