Enlightenment CVS committal

Author  : rephorm
Project : e17
Module  : apps/iconbar

Dir     : e17/apps/iconbar/src


Modified Files:
        container.c container.h iconbar.c 


Log Message:

more work on container fill policies.

fix a bug in loading icons if no order.txt exists. (thanks sytse)

===================================================================
RCS file: /cvsroot/enlightenment/e17/apps/iconbar/src/container.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -3 -r1.5 -r1.6
--- container.c 12 Aug 2003 04:23:12 -0000      1.5
+++ container.c 20 Aug 2003 23:37:03 -0000      1.6
@@ -29,7 +29,7 @@
 Container *_container_fetch(Evas_Object *obj);
 Container_Element *_container_element_new(Container *cont, Evas_Object *obj);
 void _container_elements_fix(Container *cont);
-double _container_elements_length_get(Container *cont);
+double _container_elements_orig_length_get(Container *cont);
 void _cb_container(void *data, Evas *e, Evas_Object *obj, void *event_info);
 void _cb_element_down(void *data, Evas *e, Evas_Object *obj, void *event_info);
 void _cb_element_up(void *data, Evas *e, Evas_Object *obj, void *event_info);
@@ -213,6 +213,8 @@
   if (!el) return;
 
   cont->elements = evas_list_append(cont->elements, el);
+
+  _container_elements_fix(cont);
 }
 
 void e_container_element_prepend(Evas_Object *container, Evas_Object *element)
@@ -227,6 +229,8 @@
   if (!el) return;
 
   cont->elements = evas_list_prepend(cont->elements, el);
+
+  _container_elements_fix(cont);
 }
 
 void e_container_element_append_relative(Evas_Object *container,
@@ -246,6 +250,8 @@
   if (!rel) return;
 
   cont->elements = evas_list_append_relative(cont->elements, el, rel);
+
+  _container_elements_fix(cont);
 }
 
 void e_container_element_prepend_relative(Evas_Object *container,
@@ -265,6 +271,8 @@
   if (!rel) return;
 
   cont->elements = evas_list_prepend_relative(cont->elements, el, rel);
+
+  _container_elements_fix(cont);
 }
 
 void e_container_element_remove(Evas_Object *container, Evas_Object *element)
@@ -277,6 +285,8 @@
 
   el = evas_object_data_get(element, "Container_Element");
   cont->elements = evas_list_remove(cont->elements, el);
+
+  _container_elements_fix(cont);
 }
 
 Evas_List *e_container_elements_get(Evas_Object *container)
@@ -308,6 +318,36 @@
   cont->data_order_change = data;
 }
 
+double
+e_container_elements_length_get(Evas_Object *container)
+{
+  Container *cont;
+  Evas_List *l;
+  double length = 0;
+
+  cont = _container_fetch(container);
+  if (!cont) return 0;
+
+  //_container_elements_fix(cont);
+    
+  for (l = cont->elements; l; l = l->next)
+  {
+    Container_Element *el = l->data;
+    double w, h;
+
+    evas_object_geometry_get(el->obj, NULL, NULL, &w, &h);
+
+    length += cont->direction ? h : w;
+    length += cont->spacing; 
+  }
+
+  /* subtract off extra spacing from last element */
+  length -= cont->spacing;
+
+  return length;
+}
+
+
 
 /*** internal  functions ***/
 
@@ -365,7 +405,13 @@
   Evas_List *l;
   double ax, ay, aw, ah; // element area geom
   double ix, iy, iw, ih; // new x, y, w, h
+  double L; // length of all objects at original size (for nonhomog)
   int num; // number of elements
+  double error = 0;
+
+  /* FIXME: add a 'changed' flag to prevent multiple recalcs */
+
+  
 
   evas_object_geometry_get(cont->grabber, &ax, &ay, &aw, &ah);
 
@@ -381,6 +427,7 @@
   ix = ax;
   iy = ay;
 
+  L = _container_elements_orig_length_get(cont);
   num = evas_list_count(cont->elements);
 
   for (l = cont->elements; l; l = l->next)
@@ -404,7 +451,12 @@
       if (cont->fill & CONTAINER_FILL_POLICY_FILL)
       {
         iw = aw;
-        ih = (ah - cont->spacing * (num - 1) ) / num;
+
+        if (cont->fill & CONTAINER_FILL_POLICY_HOMOGENOUS)
+          ih = (ah - cont->spacing * (num - 1) ) / num;
+        else
+          ih = el->orig_h * (ah - cont->spacing * (num - 1) ) / L;
+          
       }
       else if (cont->fill & CONTAINER_FILL_POLICY_FILL_X)
       {
@@ -421,16 +473,15 @@
       }
       else if (cont->fill & CONTAINER_FILL_POLICY_FILL_Y)
       {
-        if (cont->fill & CONTAINER_FILL_POLICY_KEEP_ASPECT)
-        {
+        if (cont->fill & CONTAINER_FILL_POLICY_HOMOGENOUS)
           ih = (ah - cont->spacing * (num - 1) ) / num;
+        else
+          ih = el->orig_h * (ah - cont->spacing * (num - 1) ) / L;
+
+        if (cont->fill & CONTAINER_FILL_POLICY_KEEP_ASPECT)
           iw = ew * ih/eh;
-        }
         else
-        {
-          ih = (ah - cont->spacing * (num - 1) ) / num;
           iw = ew;
-        }
       }
       else
       {
@@ -447,6 +498,10 @@
 
       evas_object_move(el->obj, ix, iy);
       evas_object_resize(el->obj, iw, ih);
+      if (!strcmp(evas_object_type_get(el->obj), "image"))
+      {
+        evas_object_image_fill_set(el->obj, 0, 0, iw, ih);
+      }
       evas_object_move(el->grabber, ix, iy);
       evas_object_resize(el->grabber, iw, ih);
 
@@ -458,21 +513,36 @@
     {
       if (cont->fill & CONTAINER_FILL_POLICY_FILL)
       {
+        //printf("fill\n");
         ih = ah;
-        iw = (aw - cont->spacing * (num - 1) ) / num;
+        
+        if (cont->fill & CONTAINER_FILL_POLICY_HOMOGENOUS)
+          iw = (aw - cont->spacing * (num - 1) ) / num;
+        else
+        {
+          //printf("nonhomog\n");
+          iw = el->orig_w * (aw - cont->spacing * (num - 1) ) / L;
+        }
       }
       else if (cont->fill & CONTAINER_FILL_POLICY_FILL_X)
       {
-        if (cont->fill & CONTAINER_FILL_POLICY_KEEP_ASPECT)
+        //printf("fill x\n");
+
+        if (cont->fill & CONTAINER_FILL_POLICY_HOMOGENOUS)
         {
+          //printf ("homog\n");
           iw = (aw - cont->spacing * (num - 1) ) / num;
-          ih = eh * iw/ew;
         }
         else
         {
-          iw = (aw - cont->spacing * (num - 1) ) / num;
-          ih = eh;
+          //printf("nonhomog - L: %f, ew: %f\n", L, ew);
+          iw = el->orig_w * (aw - cont->spacing * (num - 1) ) / L;
         }
+
+        if (cont->fill & CONTAINER_FILL_POLICY_KEEP_ASPECT)
+          ih = eh * iw/ew;
+        else
+          ih = eh;
       }
       else if (cont->fill & CONTAINER_FILL_POLICY_FILL_Y)
       {
@@ -480,7 +550,6 @@
         {
           ih = ah;
           iw = ew * ih/eh;
-          printf("**** ih: %f, eh: %f, iw: %f\n", ih, eh, iw);
         }
         else
         {
@@ -501,9 +570,26 @@
       else if (cont->align == CONTAINER_ALIGN_BOTTOM)
         iy = ay + ah - eh;
 
-      printf("**********ix: %f, iw: %f, cont->spacing: %d\n", ix, iw, cont->spacing);
+ 
+      if (error >= 1)
+      {
+        iw++;
+        error -= 1;
+      }
+      else if (error <= -1)
+      {
+        iw--;
+        error += 1;
+      }
+
+      error += iw - (int)iw; 
+      iw = (int)iw;
       evas_object_move(el->obj, ix, iy);
       evas_object_resize(el->obj, iw, ih);
+      if (!strcmp(evas_object_type_get(el->obj), "image"))
+      {
+        evas_object_image_fill_set(el->obj, 0, 0, iw, ih);
+      }
       evas_object_move(el->grabber, ix, iy);
       evas_object_resize(el->grabber, iw, ih);
       ix += iw + cont->spacing;
@@ -516,7 +602,7 @@
 }
 
 double
-_container_elements_length_get(Container *cont)
+_container_elements_orig_length_get(Container *cont)
 {
   Evas_List *l;
   double length = 0;
@@ -528,15 +614,14 @@
 
     evas_object_geometry_get(el->obj, NULL, NULL, &w, &h);
 
-    length += cont->direction ? h : w;
-    length += cont->spacing; 
+    length += cont->direction ? el->orig_h : el->orig_w;
   }
 
-  /* subtract off extra spacing from last element */
-  length -= cont->spacing;
-
   return length;
 }
+
+
+
 
 void
 _container_element_move(Container_Element *el)
===================================================================
RCS file: /cvsroot/enlightenment/e17/apps/iconbar/src/container.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -3 -r1.4 -r1.5
--- container.h 12 Aug 2003 04:23:12 -0000      1.4
+++ container.h 20 Aug 2003 23:37:03 -0000      1.5
@@ -34,7 +34,8 @@
   CONTAINER_FILL_POLICY_KEEP_ASPECT = 0x01,
   CONTAINER_FILL_POLICY_FILL_X = 0x02,
   CONTAINER_FILL_POLICY_FILL_Y = 0x04,
-  CONTAINER_FILL_POLICY_FILL = 0x08 
+  CONTAINER_FILL_POLICY_FILL = 0x08, 
+  CONTAINER_FILL_POLICY_HOMOGENOUS = 0x10
 };
 
 struct _Container
@@ -130,4 +131,5 @@
                                            void (*func)(void *data),
                                            void *data);
 
+double e_container_elements_length_get(Evas_Object *container);
 #endif
===================================================================
RCS file: /cvsroot/enlightenment/e17/apps/iconbar/src/iconbar.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -3 -r1.5 -r1.6
--- iconbar.c   12 Aug 2003 04:23:12 -0000      1.5
+++ iconbar.c   20 Aug 2003 23:37:03 -0000      1.6
@@ -396,7 +396,7 @@
   DIR *dirp;
   struct dirent *dp;
   char dir[PATH_MAX];
-  Evas_List *icons;
+  Evas_List *icons, *new = NULL;
 
   snprintf(dir, sizeof(dir), "%s/icons", ib->path);
   dirp = opendir(dir);
@@ -433,7 +433,6 @@
 
     if (f)
     {
-      Evas_List *new = NULL;
 
       while (fgets(buf, sizeof(buf) - 1, f))
       {
@@ -456,28 +455,30 @@
           }
         }
       }
-
       fclose(f);
+    }
 
-      /* add the ones not mentioned to the end */
-      for (l = icons; l; l = evas_list_next(l))
-      {
-        if (!evas_list_find(new, evas_list_data(l)))
-        {
-          new = evas_list_append(new, evas_list_data(l));
-        }
-      }
 
-      for (l = new; l; l = evas_list_next(l))
+    /* add the ones not mentioned to the end */
+    for (l = icons; l; l = evas_list_next(l))
+    {
+      if (!evas_list_find(new, evas_list_data(l)))
       {
-        Icon *ic = evas_list_data(l);
-
-        e_container_element_append(ib->cont, ic->image);
+        new = evas_list_append(new, evas_list_data(l));
+        
       }
+    }
+
+    for (l = new; l; l = evas_list_next(l))
+    {
+      Icon *ic = evas_list_data(l);
 
-      evas_list_free(icons);
-      evas_list_free(new);
+      printf("append icon: %s\n", ic->file);
+      e_container_element_append(ib->cont, ic->image);
     }
+
+    evas_list_free(icons);
+    evas_list_free(new);
   }
 
   write_out_order(ib);
@@ -497,6 +498,7 @@
 
   if (f)
   {
+    printf("file opened ok\n");
     for (l = e_container_elements_get(ib->cont); l; l = l->next)
     {
       Evas_Object *obj = l->data;
@@ -509,10 +511,11 @@
         p++;
         fputs(p, f);
         fputs("\n", f);
+        printf("write: %s\n", p);
       }
     }
-    fclose(f);
   }
+    fclose(f);
 }
 
 




-------------------------------------------------------
This SF.net email is sponsored by: VM Ware
With VMware you can run multiple operating systems on a single machine.
WITHOUT REBOOTING! Mix Linux / Windows / Novell virtual machines
at the same time. Free trial click here:http://www.vmware.com/wl/offer/358/0
_______________________________________________
enlightenment-cvs mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs

Reply via email to