Re: [AD] new GUI focus selection algorithm

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


On Sat, 2003-11-29 at 20:56, Eric Botcazou wrote:
> > Ok, improved patch attached.
> 
> Thanks.  I think the algorithm is now good enough.  I've made some 
> modifications, the result is attached.
> 


> -   int ret = (d2->x - d1->x) + ABS(d1->y - d2->y) * 8;
> +   int ret = min_dist(d1, d2, X_AXIS);
>  
> -   if (d1->x >= d2->x)
> +   /* Penalize if d2 is not fully contained in the half-plan delimited
> +      by d1's right edge and not containing d1. */
> +   if (d2->x < d1->x + d1->w)
>        ret += 0x10000;

Hm, the 0x10000 is not to penalize, but it's the wrap with. So, it
should be used like I did (since there's now a different, always
positive distance, unlike in the previous code). I.e., if moving right,
don't use min_dist from d1 to d2, but to d2 'warped' to the right (and
of course, I forgot to comment it - but neither did Shawn):

> -   int ret = (d2->x - d1->x) + ABS(d1->y - d2->y) * 8;
> -
> -   if (d1->x >= d2->x)
> -      ret += 0x10000;
> -
> -   return ret;
> +   if (d1->x + d1->w > d2->x)
> +       return min_dist(d1, 0x10000 + d2->x, d2->y, d2->w, d2->h, DISTANCE_RATIO, 1);
> +   else
> +       return  min_dist(d1, d2->x, d2->y, d2->w, d2->h, DISTANCE_RATIO, 1);

Here, the x position of d2 becomes 0x10000 + d2->x instead of d2->x:

 |  d2    |            |        |  d2
 |   d1   |   becomes  |   d1   |

Which allows wrapping around when going over the screen edge, just like
the original code.

-- 
Elias Pschernig <elias@xxxxxxxxxx>





Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/