From 77c664ca3b72630907d52a467e664185200f1cac Mon Sep 17 00:00:00 2001 From: raster Date: Wed, 11 Feb 2009 11:48:15 +0000 Subject: [PATCH] fix some min size calc and aspect calc issues. git-svn-id: svn+ssh://svn.enlightenment.org/var/svn/e/trunk/edje@38994 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33 --- src/lib/edje_calc.c | 358 ++++++++++++++++++++++++++-------------------------- 1 file changed, 181 insertions(+), 177 deletions(-) diff --git a/src/lib/edje_calc.c b/src/lib/edje_calc.c index fe68f49..554e4e9 100644 --- a/src/lib/edje_calc.c +++ b/src/lib/edje_calc.c @@ -391,188 +391,192 @@ _edje_part_recalc_single(Edje *ed, } /* aspect */ - if ((params->h > 0) && - (((flags | ep->calculated) & FLAG_XY) == FLAG_XY)) + if (((flags | ep->calculated) & FLAG_XY) == FLAG_XY) { - int apref; + int apref = -10; double aspect, amax, amin; double new_w = 0, new_h = 0, want_x, want_y, want_w, want_h; - want_x = params->x; - want_w = new_w = params->w; - - want_y = params->y; - want_h = new_h = params->h; - - aspect = (double)params->w / (double)params->h; - apref = desc->aspect.prefer; - amax = desc->aspect.max; - amin = desc->aspect.min; - if ((ep->swallow_params.aspect.w > 0) && - (ep->swallow_params.aspect.h > 0)) - amin = amax = - (double)ep->swallow_params.aspect.w / - (double)ep->swallow_params.aspect.h; - if (ep->swallow_params.aspect.mode > EDJE_ASPECT_CONTROL_NONE) - { - switch (ep->swallow_params.aspect.mode) - { - case EDJE_ASPECT_CONTROL_NEITHER: - apref = EDJE_ASPECT_PREFER_NONE; - break; - case EDJE_ASPECT_CONTROL_HORIZONTAL: - apref = EDJE_ASPECT_PREFER_HORIZONTAL; - break; - case EDJE_ASPECT_CONTROL_VERTICAL: - apref = EDJE_ASPECT_PREFER_VERTICAL; - break; - case EDJE_ASPECT_CONTROL_BOTH: - apref = EDJE_ASPECT_PREFER_BOTH; - break; - default: - break; - } - } - - switch (apref) - { - case EDJE_ASPECT_PREFER_NONE: - /* keep botth dimensions in check */ - /* adjust for min aspect (width / height) */ - if ((amin > 0.0) && (aspect < amin)) - { - new_h = (params->w / amin); - new_w = (params->h * amin); - } - /* adjust for max aspect (width / height) */ - if ((amax > 0.0) && (aspect > amax)) - { - new_h = (params->w / amax); - new_w = (params->h * amax); - } - if ((amax > 0.0) && (new_w < params->w)) - { - new_w = params->w; - new_h = params->w / amax; - } - if ((amax > 0.0) && (new_h < params->h)) - { - new_w = params->h * amax; - new_h = params->h; - } - break; - /* prefer vertical size as determiner */ - case EDJE_ASPECT_PREFER_VERTICAL: - /* keep both dimensions in check */ - /* adjust for max aspect (width / height) */ - if ((amax > 0.0) && (aspect > amax)) - new_w = (params->h * amax); - /* adjust for min aspect (width / height) */ - if ((amin > 0.0) && (aspect < amin)) - new_w = (params->h * amin); - break; - /* prefer horizontal size as determiner */ - case EDJE_ASPECT_PREFER_HORIZONTAL: - /* keep both dimensions in check */ - /* adjust for max aspect (width / height) */ - if ((amax > 0.0) && (aspect > amax)) - new_h = (params->w / amax); - /* adjust for min aspect (width / height) */ - if ((amin > 0.0) && (aspect < amin)) - new_h = (params->w / amin); - break; - case EDJE_ASPECT_PREFER_BOTH: - /* keep both dimensions in check */ - /* adjust for max aspect (width / height) */ - if ((amax > 0.0) && (aspect > amax)) - { - new_w = (params->h * amax); - new_h = (params->w / amax); - } - /* adjust for min aspect (width / height) */ - if ((amin > 0.0) && (aspect < amin)) - { - new_w = (params->h * amin); - new_h = (params->w / amin); - } - break; - } - - if (!((amin > 0.0) && (amax > 0.0) && (apref == EDJE_ASPECT_PREFER_NONE))) - { - if ((maxw >= 0) && (new_w > maxw)) new_w = maxw; - if (new_w < minw) new_w = minw; - - if ((maxh >= 0) && (new_h > maxh)) new_h = maxh; - if (new_h < minh) new_h = minh; - } - - /* do real adjustment */ - if (apref == EDJE_ASPECT_PREFER_BOTH) - { - if (amin == 0.0) amin = amax; - if (amin != 0.0) - { - /* fix h and vary w */ - if (new_w > params->w) - { -// params->w = new_w; -// EXCEEDS BOUNDS in W - new_h = (params->w / amin); - new_w = params->w; - if (new_h > params->h) - { - new_h = params->h; - new_w = (params->h * amin); - } - } - /* fix w and vary h */ - else - { -// params->h = new_h; -// EXCEEDS BOUNDS in H - new_h = params->h; - new_w = (params->h * amin); - if (new_w > params->w) - { - new_h = (params->w / amin); - new_w = params->w; - } - } - params->w = new_w; - params->h = new_h; - } - } - else - { - if ((amin > 0.0) && (amax > 0.0) && (apref == EDJE_ASPECT_PREFER_NONE)) - { - params->w = new_w; - params->h = new_h; - } - else if ((params->h - new_h) > (params->w - new_w)) - { - if (params->h < new_h) - params->h = new_h; - else if (params->h > new_h) - params->h = new_h; - if (apref == EDJE_ASPECT_PREFER_VERTICAL) - params->w = new_w; - } - else - { - if (params->w < new_w) - params->w = new_w; - else if (params->w > new_w) - params->w = new_w; - if (apref == EDJE_ASPECT_PREFER_HORIZONTAL) - params->h = new_h; - } - } - params->x = want_x + ((want_w - params->w) * desc->align.x); - params->y = want_y + ((want_h - params->h) * desc->align.y); + if (params->h <= 0) aspect = 999999.0; + else aspect = (double)params->w / (double)params->h; + amax = desc->aspect.max; + amin = desc->aspect.min; + if ((ep->swallow_params.aspect.w > 0) && + (ep->swallow_params.aspect.h > 0)) + amin = amax = + (double)ep->swallow_params.aspect.w / + (double)ep->swallow_params.aspect.h; + want_x = params->x; + want_w = new_w = params->w; + + want_y = params->y; + want_h = new_h = params->h; + + if ((amin > 0.0) && (amax > 0.0)) + { + apref = desc->aspect.prefer; + if (ep->swallow_params.aspect.mode > EDJE_ASPECT_CONTROL_NONE) + { + switch (ep->swallow_params.aspect.mode) + { + case EDJE_ASPECT_CONTROL_NEITHER: + apref = EDJE_ASPECT_PREFER_NONE; + break; + case EDJE_ASPECT_CONTROL_HORIZONTAL: + apref = EDJE_ASPECT_PREFER_HORIZONTAL; + break; + case EDJE_ASPECT_CONTROL_VERTICAL: + apref = EDJE_ASPECT_PREFER_VERTICAL; + break; + case EDJE_ASPECT_CONTROL_BOTH: + apref = EDJE_ASPECT_PREFER_BOTH; + break; + default: + break; + } + } + switch (apref) + { + case EDJE_ASPECT_PREFER_NONE: + /* keep both dimensions in check */ + /* adjust for min aspect (width / height) */ + if ((amin > 0.0) && (aspect < amin)) + { + new_h = (params->w / amin); + new_w = (params->h * amin); + } + /* adjust for max aspect (width / height) */ + if ((amax > 0.0) && (aspect > amax)) + { + new_h = (params->w / amax); + new_w = (params->h * amax); + } + if ((amax > 0.0) && (new_w < params->w)) + { + new_w = params->w; + new_h = params->w / amax; + } + if ((amax > 0.0) && (new_h < params->h)) + { + new_w = params->h * amax; + new_h = params->h; + } + break; + /* prefer vertical size as determiner */ + case EDJE_ASPECT_PREFER_VERTICAL: + /* keep both dimensions in check */ + /* adjust for max aspect (width / height) */ + if ((amax > 0.0) && (aspect > amax)) + new_w = (params->h * amax); + /* adjust for min aspect (width / height) */ + if ((amin > 0.0) && (aspect < amin)) + new_w = (params->h * amin); + break; + /* prefer horizontal size as determiner */ + case EDJE_ASPECT_PREFER_HORIZONTAL: + /* keep both dimensions in check */ + /* adjust for max aspect (width / height) */ + if ((amax > 0.0) && (aspect > amax)) + new_h = (params->w / amax); + /* adjust for min aspect (width / height) */ + if ((amin > 0.0) && (aspect < amin)) + new_h = (params->w / amin); + break; + case EDJE_ASPECT_PREFER_BOTH: + /* keep both dimensions in check */ + /* adjust for max aspect (width / height) */ + if ((amax > 0.0) && (aspect > amax)) + { + new_w = (params->h * amax); + new_h = (params->w / amax); + } + /* adjust for min aspect (width / height) */ + if ((amin > 0.0) && (aspect < amin)) + { + new_w = (params->h * amin); + new_h = (params->w / amin); + } + break; + default: + break; + } + + if (!((amin > 0.0) && (amax > 0.0) && (apref == EDJE_ASPECT_PREFER_NONE))) + { + if ((maxw >= 0) && (new_w > maxw)) new_w = maxw; + if (new_w < minw) new_w = minw; + + if ((maxh >= 0) && (new_h > maxh)) new_h = maxh; + if (new_h < minh) new_h = minh; + } + + /* do real adjustment */ + if (apref == EDJE_ASPECT_PREFER_BOTH) + { + if (amin == 0.0) amin = amax; + if (amin != 0.0) + { + /* fix h and vary w */ + if (new_w > params->w) + { + // params->w = new_w; + // EXCEEDS BOUNDS in W + new_h = (params->w / amin); + new_w = params->w; + if (new_h > params->h) + { + new_h = params->h; + new_w = (params->h * amin); + } + } + /* fix w and vary h */ + else + { + // params->h = new_h; + // EXCEEDS BOUNDS in H + new_h = params->h; + new_w = (params->h * amin); + if (new_w > params->w) + { + new_h = (params->w / amin); + new_w = params->w; + } + } + params->w = new_w; + params->h = new_h; + } + } + } + if (apref != EDJE_ASPECT_PREFER_BOTH) + { + if ((amin > 0.0) && (amax > 0.0) && (apref == EDJE_ASPECT_PREFER_NONE)) + { + params->w = new_w; + params->h = new_h; + } + else if ((params->h - new_h) > (params->w - new_w)) + { + if (params->h < new_h) + params->h = new_h; + else if (params->h > new_h) + params->h = new_h; + if (apref == EDJE_ASPECT_PREFER_VERTICAL) + params->w = new_w; + } + else + { + if (params->w < new_w) + params->w = new_w; + else if (params->w > new_w) + params->w = new_w; + if (apref == EDJE_ASPECT_PREFER_HORIZONTAL) + params->h = new_h; + } + } + params->x = want_x + ((want_w - params->w) * desc->align.x); + params->y = want_y + ((want_h - params->h) * desc->align.y); } - + /* size step */ if (flags & FLAG_X) { -- 2.7.4