diff options
author | Tamito Kajiyama <rd6t-kjym@asahi-net.or.jp> | 2012-12-19 05:49:58 +0400 |
---|---|---|
committer | Tamito Kajiyama <rd6t-kjym@asahi-net.or.jp> | 2012-12-19 05:49:58 +0400 |
commit | d433cd65f7127d60e17d05a824290423ad226eae (patch) | |
tree | f0a9c821f6046e97b74c6969d41269b558fd52ab /source/blender/editors/uvedit/uvedit_draw.c | |
parent | 10f0f66560234a04aed3295c74fff20adacbc57f (diff) | |
parent | f10dea7e3b9b431edae9c787fa1a9e09cd567ed7 (diff) |
Merged changes in the trunk up to revision 53146.
Conflicts resolved:
release/datafiles/startup.blend
source/blender/blenkernel/CMakeLists.txt
source/blender/blenlib/intern/bpath.c
source/blender/blenloader/intern/readfile.c
Diffstat (limited to 'source/blender/editors/uvedit/uvedit_draw.c')
-rw-r--r-- | source/blender/editors/uvedit/uvedit_draw.c | 131 |
1 files changed, 49 insertions, 82 deletions
diff --git a/source/blender/editors/uvedit/uvedit_draw.c b/source/blender/editors/uvedit/uvedit_draw.c index 9c2c300c530..607640090aa 100644 --- a/source/blender/editors/uvedit/uvedit_draw.c +++ b/source/blender/editors/uvedit/uvedit_draw.c @@ -60,48 +60,49 @@ #include "ED_uvedit.h" #include "UI_resources.h" +#include "UI_interface.h" +#include "UI_view2d.h" #include "uvedit_intern.h" void draw_image_cursor(SpaceImage *sima, ARegion *ar) { - float zoomx, zoomy, w, h; - int width, height; + float zoom[2], x_fac, y_fac; - ED_space_image_get_size(sima, &width, &height); - ED_space_image_get_zoom(sima, ar, &zoomx, &zoomy); + UI_view2d_getscale_inverse(&ar->v2d, &zoom[0], &zoom[1]); - w = zoomx * width / 256.0f; - h = zoomy * height / 256.0f; + mul_v2_fl(zoom, 256.0f * UI_DPI_FAC); + x_fac = zoom[0]; + y_fac = zoom[1]; cpack(0xFFFFFF); glTranslatef(sima->cursor[0], sima->cursor[1], 0.0); - fdrawline(-0.05f / w, 0, 0, 0.05f / h); - fdrawline(0, 0.05f / h, 0.05f / w, 0.0f); - fdrawline(0.05f / w, 0.0f, 0.0f, -0.05f / h); - fdrawline(0.0f, -0.05f / h, -0.05f / w, 0.0f); + fdrawline(-0.05f * x_fac, 0, 0, 0.05f * y_fac); + fdrawline(0, 0.05f * y_fac, 0.05f * x_fac, 0.0f); + fdrawline(0.05f * x_fac, 0.0f, 0.0f, -0.05f * y_fac); + fdrawline(0.0f, -0.05f * y_fac, -0.05f * x_fac, 0.0f); setlinestyle(4); cpack(0xFF); - fdrawline(-0.05f / w, 0.0f, 0.0f, 0.05f / h); - fdrawline(0.0f, 0.05f / h, 0.05f / w, 0.0f); - fdrawline(0.05f / w, 0.0f, 0.0f, -0.05f / h); - fdrawline(0.0f, -0.05f / h, -0.05f / w, 0.0f); + fdrawline(-0.05f * x_fac, 0.0f, 0.0f, 0.05f * y_fac); + fdrawline(0.0f, 0.05f * y_fac, 0.05f * x_fac, 0.0f); + fdrawline(0.05f * x_fac, 0.0f, 0.0f, -0.05f * y_fac); + fdrawline(0.0f, -0.05f * y_fac, -0.05f * x_fac, 0.0f); setlinestyle(0.0f); cpack(0x0); - fdrawline(-0.020f / w, 0.0f, -0.1f / w, 0.0f); - fdrawline(0.1f / w, 0.0f, 0.020f / w, 0.0f); - fdrawline(0.0f, -0.020f / h, 0.0f, -0.1f / h); - fdrawline(0.0f, 0.1f / h, 0.0f, 0.020f / h); + fdrawline(-0.020f * x_fac, 0.0f, -0.1f * x_fac, 0.0f); + fdrawline(0.1f * x_fac, 0.0f, 0.020f * x_fac, 0.0f); + fdrawline(0.0f, -0.020f * y_fac, 0.0f, -0.1f * y_fac); + fdrawline(0.0f, 0.1f * y_fac, 0.0f, 0.020f * y_fac); setlinestyle(1); cpack(0xFFFFFF); - fdrawline(-0.020f / w, 0.0f, -0.1f / w, 0.0f); - fdrawline(0.1f / w, 0.0f, 0.020f / w, 0.0f); - fdrawline(0.0f, -0.020f / h, 0.0f, -0.1f / h); - fdrawline(0.0f, 0.1f / h, 0.0f, 0.020f / h); + fdrawline(-0.020f * x_fac, 0.0f, -0.1f * x_fac, 0.0f); + fdrawline(0.1f * x_fac, 0.0f, 0.020f * x_fac, 0.0f); + fdrawline(0.0f, -0.020f * y_fac, 0.0f, -0.1f * y_fac); + fdrawline(0.0f, 0.1f * y_fac, 0.0f, 0.020f * y_fac); glTranslatef(-sima->cursor[0], -sima->cursor[1], 0.0); setlinestyle(0); @@ -169,10 +170,8 @@ static void draw_uvs_stretch(SpaceImage *sima, Scene *scene, BMEditMesh *em, MTe MTexPoly *tf; MLoopUV *luv; Image *ima = sima->image; - BLI_array_declare(tf_uv); - BLI_array_declare(tf_uvorig); - float aspx, aspy, col[4], (*tf_uv)[2] = NULL, (*tf_uvorig)[2] = NULL; - int i, j, nverts; + float aspx, aspy, col[4]; + int i; ED_space_image_get_uv_aspect(sima, &aspx, &aspy); @@ -182,20 +181,14 @@ static void draw_uvs_stretch(SpaceImage *sima, Scene *scene, BMEditMesh *em, MTe float totarea = 0.0f, totuvarea = 0.0f, areadiff, uvarea, area; BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) { + const int efa_len = efa->len; + float (*tf_uv)[2] = BLI_array_alloca(tf_uv, efa_len); + float (*tf_uvorig)[2] = BLI_array_alloca(tf_uvorig, efa_len); tf = CustomData_bmesh_get(&bm->pdata, efa->head.data, CD_MTEXPOLY); - - BLI_array_empty(tf_uv); - BLI_array_empty(tf_uvorig); - BLI_array_grow_items(tf_uv, efa->len); - BLI_array_grow_items(tf_uvorig, efa->len); - i = 0; - BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) { + BM_ITER_ELEM_INDEX (l, &liter, efa, BM_LOOPS_OF_FACE, i) { luv = CustomData_bmesh_get(&bm->ldata, l->head.data, CD_MLOOPUV); - copy_v2_v2(tf_uvorig[i], luv->uv); - - i++; } uv_poly_copy_aspect(tf_uvorig, tf_uv, aspx, aspy, efa->len); @@ -232,20 +225,15 @@ static void draw_uvs_stretch(SpaceImage *sima, Scene *scene, BMEditMesh *em, MTe else { BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) { if (BM_elem_flag_test(efa, BM_ELEM_TAG)) { - area = BM_face_calc_area(efa) / totarea; + const int efa_len = efa->len; + float (*tf_uv)[2] = BLI_array_alloca(tf_uv, efa_len); + float (*tf_uvorig)[2] = BLI_array_alloca(tf_uvorig, efa_len); - BLI_array_empty(tf_uv); - BLI_array_empty(tf_uvorig); - BLI_array_grow_items(tf_uv, efa->len); - BLI_array_grow_items(tf_uvorig, efa->len); + area = BM_face_calc_area(efa) / totarea; - i = 0; - BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) { + BM_ITER_ELEM_INDEX (l, &liter, efa, BM_LOOPS_OF_FACE, i) { luv = CustomData_bmesh_get(&bm->ldata, l->head.data, CD_MLOOPUV); - copy_v2_v2(tf_uvorig[i], luv->uv); - - i++; } uv_poly_copy_aspect(tf_uvorig, tf_uv, aspx, aspy, efa->len); @@ -276,18 +264,9 @@ static void draw_uvs_stretch(SpaceImage *sima, Scene *scene, BMEditMesh *em, MTe } case SI_UVDT_STRETCH_ANGLE: { - float *uvang = NULL; - float *ang = NULL; - float (*av)[3] = NULL; /* use for 2d and 3d angle vectors */ - float (*auv)[2] = NULL; float a; - BLI_array_declare(uvang); - BLI_array_declare(ang); - BLI_array_declare(av); - BLI_array_declare(auv); - - col[3] = 0.5; /* hard coded alpha, not that nice */ + col[3] = 0.5f; /* hard coded alpha, not that nice */ glShadeModel(GL_SMOOTH); @@ -295,44 +274,40 @@ static void draw_uvs_stretch(SpaceImage *sima, Scene *scene, BMEditMesh *em, MTe tf = CustomData_bmesh_get(&bm->pdata, efa->head.data, CD_MTEXPOLY); if (uvedit_face_visible_test(scene, ima, efa, tf)) { - nverts = efa->len; + const int efa_len = efa->len; + float (*tf_uv)[2] = BLI_array_alloca(tf_uv, efa_len); + float (*tf_uvorig)[2] = BLI_array_alloca(tf_uvorig, efa_len); + float *uvang = BLI_array_alloca(uvang, efa_len); + float *ang = BLI_array_alloca(ang, efa_len); + float (*av)[3] = BLI_array_alloca(av, efa_len); /* use for 2d and 3d angle vectors */ + float (*auv)[2] = BLI_array_alloca(auv, efa_len); + int j; + BM_elem_flag_enable(efa, BM_ELEM_TAG); - BLI_array_empty(tf_uv); - BLI_array_empty(tf_uvorig); - BLI_array_empty(uvang); - BLI_array_empty(ang); - BLI_array_empty(av); - BLI_array_empty(auv); - BLI_array_grow_items(tf_uv, nverts); - BLI_array_grow_items(tf_uvorig, nverts); - BLI_array_grow_items(uvang, nverts); - BLI_array_grow_items(ang, nverts); - BLI_array_grow_items(av, nverts); - BLI_array_grow_items(auv, nverts); BM_ITER_ELEM_INDEX (l, &liter, efa, BM_LOOPS_OF_FACE, i) { luv = CustomData_bmesh_get(&bm->ldata, l->head.data, CD_MLOOPUV); copy_v2_v2(tf_uvorig[i], luv->uv); } - uv_poly_copy_aspect(tf_uvorig, tf_uv, aspx, aspy, nverts); + uv_poly_copy_aspect(tf_uvorig, tf_uv, aspx, aspy, efa_len); - j = nverts - 1; + j = efa_len - 1; BM_ITER_ELEM_INDEX (l, &liter, efa, BM_LOOPS_OF_FACE, i) { sub_v2_v2v2(auv[i], tf_uv[j], tf_uv[i]); normalize_v2(auv[i]); sub_v3_v3v3(av[i], l->prev->v->co, l->v->co); normalize_v3(av[i]); j = i; } - for (i = 0; i < nverts; i++) { + for (i = 0; i < efa_len; i++) { #if 0 /* Simple but slow, better reuse normalized vectors * (Not ported to bmesh, copied for reference) */ uvang1 = RAD2DEG(angle_v2v2v2(tf_uv[3], tf_uv[0], tf_uv[1])); ang1 = RAD2DEG(angle_v3v3v3(efa->v4->co, efa->v1->co, efa->v2->co)); #endif - uvang[i] = angle_normalized_v2v2(auv[i], auv[(i + 1) % nverts]); - ang[i] = angle_normalized_v3v3(av[i], av[(i + 1) % nverts]); + uvang[i] = angle_normalized_v2v2(auv[i], auv[(i + 1) % efa_len]); + ang[i] = angle_normalized_v3v3(av[i], av[(i + 1) % efa_len]); } glBegin(GL_POLYGON); @@ -354,17 +329,9 @@ static void draw_uvs_stretch(SpaceImage *sima, Scene *scene, BMEditMesh *em, MTe glShadeModel(GL_FLAT); - BLI_array_free(uvang); - BLI_array_free(ang); - BLI_array_free(av); - BLI_array_free(auv); - break; } } - - BLI_array_free(tf_uv); - BLI_array_free(tf_uvorig); } static void draw_uvs_other(Scene *scene, Object *obedit, Image *curimage) |