EAPI Cutout_Rects*
evas_common_draw_context_apply_cutouts(RGBA_Draw_Context *dc)
{
   Cutout_Rects*        res;
   int                  i;
   int                  j;

   if (!dc->clip.use) return NULL;
   if ((dc->clip.w <= 0) || (dc->clip.h <= 0)) return NULL;

   res = evas_common_draw_context_cutouts_new();
   evas_common_draw_context_cutouts_add(res, dc->clip.x, dc->clip.y, dc->clip.w, dc->clip.h);

   for (i = 0; i < dc->cutout.active; ++i)
     {
        /* Don't loop on the element just added to the list as they are already correctly clipped. */
        int active = res->active;

        for (j = 0; j < active; )
          {
             if (evas_common_draw_context_cutout_split(res, j, dc->cutout.rects + i))
               ++j;
             else
               active--;
          }
     }
   return res;
}
示例#2
0
EAPI Cutout_Rects*
evas_common_draw_context_apply_cutouts(RGBA_Draw_Context *dc, Cutout_Rects *reuse)
{
   Cutout_Rects*        res = NULL;
   int                  i;
   int                  j;

   if (!dc->clip.use) return NULL;
   if ((dc->clip.w <= 0) || (dc->clip.h <= 0)) return NULL;


   if (!reuse)
     {
        res = evas_common_draw_context_cutouts_new();
     }
   else
     {
        evas_common_draw_context_cutouts_free(reuse);
        res = reuse;
     }
   evas_common_draw_context_cutouts_add(res, dc->clip.x, dc->clip.y, dc->clip.w, dc->clip.h);

   for (i = 0; i < dc->cutout.active; ++i)
     {
        /* Don't loop on the element just added to the list as they are already correctly clipped. */
        int active = res->active;

        for (j = 0; j < active; )
          {
             if (evas_common_draw_context_cutout_split(res, j, dc->cutout.rects + i))
               ++j;
             else
               active--;
          }
     }
   /* merge rects */
#define RI res->rects[i]
#define RJ res->rects[j]
   if (res->active > 1)
     {
        int found = 1;
        
        while (found)
          {
             found = 0;
             for (i = 0; i < res->active; i++)
               {
                  for (j = i + 1; j < res->active; j++)
                    {
                       /* skip empty rects we are removing */
                       if (RJ.w == 0) continue;
                       /* check if its same width, immediately above or below */
                       if ((RJ.w == RI.w) && (RJ.x == RI.x))
                         {
                            if ((RJ.y + RJ.h) == RI.y) /* above */
                              {
                                 RI.y = RJ.y;
                                 RI.h += RJ.h;
                                 RJ.w = 0;
                                 found = 1;
                              }
                            else if ((RI.y + RI.h) == RJ.y) /* below */
                              {
                                 RI.h += RJ.h;
                                 RJ.w = 0;
                                 found = 1;
                              }
                         }
                       /* check if its same height, immediately left or right */
                       else if ((RJ.h == RI.h) && (RJ.y == RI.y))
                         {
                            if ((RJ.x + RJ.w) == RI.x) /* left */
                              {
                                 RI.x = RJ.x;
                                 RI.w += RJ.w;
                                 RJ.w = 0;
                                 found = 1;
                              }
                            else if ((RI.x + RI.w) == RJ.x) /* right */
                              {
                                 RI.w += RJ.w;
                                 RJ.w = 0;
                                 found = 1;
                              }
                         }
                    }
               }
          }

        /* Repack the cutout */
        j = 0;
        for (i = 0; i < res->active; i++)
          {
             if (RI.w == 0) continue;
             if (i != j)
               RJ = RI;
             j++;
          }
        res->active = j;
        return res;
     }
   return res;
}