Enlightenment CVS committal

Author  : rbdpngn
Project : e17
Module  : libs/ewl

Dir     : e17/libs/ewl/src/lib


Modified Files:
        ewl_button.c ewl_button.h ewl_image.c ewl_image.h 
        ewl_menu_item.c 


Log Message:
Change the image API to be more symmetric. Improve the behavior when mixing
absolute and relative scaling.

===================================================================
RCS file: /cvsroot/enlightenment/e17/libs/ewl/src/lib/ewl_button.c,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -3 -r1.30 -r1.31
--- ewl_button.c        22 Feb 2006 18:16:41 -0000      1.30
+++ ewl_button.c        9 Mar 2006 04:37:58 -0000       1.31
@@ -289,7 +289,7 @@
  * @brief Set the size of the image inside the button.
  */
 void
-ewl_button_image_scale_to(Ewl_Button *b, int width, int height)
+ewl_button_image_size_set(Ewl_Button *b, int width, int height)
 {
        DENTER_FUNCTION(DLEVEL_STABLE);
        DCHECK_PARAM_PTR("b", b);
@@ -298,8 +298,25 @@
        if (!b->image_object)
                ewl_button_image_set(b, "", NULL);
 
-       ewl_image_proportional_set(EWL_IMAGE(b->image_object), TRUE);
-       ewl_image_scale_to(EWL_IMAGE(b->image_object), width, height);
+       ewl_image_size_set(EWL_IMAGE(b->image_object), width, height);
+
+       DLEAVE_FUNCTION(DLEVEL_STABLE);
+}
+
+/**
+ * @param b: The button to get the image size on
+ * @return Returns no value.
+ * @brief Get the size of the image inside the button.
+ */
+void
+ewl_button_image_size_get(Ewl_Button *b, int *width, int *height)
+{
+       DENTER_FUNCTION(DLEVEL_STABLE);
+       DCHECK_PARAM_PTR("b", b);
+       DCHECK_TYPE("b", b, EWL_BUTTON_TYPE);
+
+       if (!b->image_object)
+               ewl_image_size_get(EWL_IMAGE(b->image_object), width, height);
 
        DLEAVE_FUNCTION(DLEVEL_STABLE);
 }
===================================================================
RCS file: /cvsroot/enlightenment/e17/libs/ewl/src/lib/ewl_button.h,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -3 -r1.14 -r1.15
--- ewl_button.h        22 Feb 2006 18:16:41 -0000      1.14
+++ ewl_button.h        9 Mar 2006 04:37:58 -0000       1.15
@@ -52,7 +52,8 @@
 
 void            ewl_button_image_set(Ewl_Button *b, const char *file, const 
char *key);
 const char     *ewl_button_image_get(Ewl_Button *b);
-void             ewl_button_image_scale_to(Ewl_Button *b, int width, int 
height);
+void             ewl_button_image_scale_set(Ewl_Button *b, int width, int 
height);
+void             ewl_button_image_scale_get(Ewl_Button *b, int *width, int 
*height);
 unsigned int     ewl_button_alignment_get(Ewl_Button *b);
 void             ewl_button_alignment_set(Ewl_Button *b, unsigned int align);
 unsigned int     ewl_button_fill_policy_get(Ewl_Button *b);
===================================================================
RCS file: /cvsroot/enlightenment/e17/libs/ewl/src/lib/ewl_image.c,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -3 -r1.26 -r1.27
--- ewl_image.c 17 Feb 2006 06:43:33 -0000      1.26
+++ ewl_image.c 9 Mar 2006 04:37:58 -0000       1.27
@@ -278,24 +278,65 @@
  * the lesser of @a wp and @a hp is applied for both directions.
  */
 void
-ewl_image_scale(Ewl_Image *i, double wp, double hp)
+ewl_image_scale_set(Ewl_Image *i, double wp, double hp)
 {
+       int aw, ah;
+
        DENTER_FUNCTION(DLEVEL_STABLE);
        DCHECK_PARAM_PTR("i", i);
        DCHECK_TYPE("i", i, EWL_IMAGE_TYPE);
 
+       i->sw = wp;
+       i->sh = hp;
+
+       /*
+        * Use set bounds if available, otherwise original image size.
+        */
+       if (i->aw)
+               aw = i->aw;
+       else
+               aw = i->ow;
+
+       if (i->ah)
+               ah = i->ah;
+       else
+               ah = i->oh;
+
+       /*
+        * Check for proportional scaling and adjust to fit.
+        */
        if (i->proportional) {
                if (wp < hp)
                        hp = wp;
                else
-                       wp = hp;
+                       hp = wp;
        }
 
-       i->sw = wp;
-       i->sh = hp;
+       ewl_object_preferred_inner_w_set(EWL_OBJECT(i), wp * aw);
+       ewl_object_preferred_inner_h_set(EWL_OBJECT(i), hp * ah);
+
+       DLEAVE_FUNCTION(DLEVEL_STABLE);
+}
+
+/**
+ * @param i: the image to retrieve the current scale
+ * @param wp: stores the percentage to scale width
+ * @param hp: stores the percentage to scale height
+ * @brief Retrieve the percentage an image is scaled.
+ *
+ * @return Returns no value.
+ */
+void
+ewl_image_scale_get(Ewl_Image *i, double *wp, double *hp)
+{
+       DENTER_FUNCTION(DLEVEL_STABLE);
+       DCHECK_PARAM_PTR("i", i);
+       DCHECK_TYPE("i", i, EWL_IMAGE_TYPE);
 
-       ewl_object_preferred_inner_w_set(EWL_OBJECT(i), wp * i->ow);
-       ewl_object_preferred_inner_h_set(EWL_OBJECT(i), hp * i->oh);
+       if (wp)
+               *wp = i->sw;
+       if (hp)
+               *hp = i->sh;
 
        DLEAVE_FUNCTION(DLEVEL_STABLE);
 }
@@ -312,15 +353,13 @@
  * percentage of preferred size.
  */
 void
-ewl_image_scale_to(Ewl_Image *i, int w, int h)
+ewl_image_size_set(Ewl_Image *i, int w, int h)
 {
 
        DENTER_FUNCTION(DLEVEL_STABLE);
        DCHECK_PARAM_PTR("i", i);
        DCHECK_TYPE("i", i, EWL_IMAGE_TYPE);
 
-       i->sw = 1.0;
-       i->sh = 1.0;
        i->aw = w;
        i->ah = h;
        ewl_object_preferred_inner_size_set(EWL_OBJECT(i), w, h);
@@ -329,6 +368,33 @@
 }
 
 /**
+ * @param i: the image to scale
+ * @param w: the size to scale width
+ * @param h: the size to scale height
+ * @return Returns no value.
+ * @brief Scale image dimensions to a specific size
+ *
+ * Scales the given image to @a w by @a hp. If @a i->proportional
+ * is set to TRUE, the image is scaled proportional to the lesser scale
+ * percentage of preferred size.
+ */
+void
+ewl_image_size_get(Ewl_Image *i, int *w, int *h)
+{
+
+       DENTER_FUNCTION(DLEVEL_STABLE);
+       DCHECK_PARAM_PTR("i", i);
+       DCHECK_TYPE("i", i, EWL_IMAGE_TYPE);
+
+       if (w)
+               *w = i->aw;
+       if (h)
+               *h = i->ah;
+
+       DLEAVE_FUNCTION(DLEVEL_STABLE);
+}
+
+/**
  * @param i: the image to tile
  * @param x: the x position of the top right corner
  * @param y: the y position of the top right corner
@@ -362,6 +428,8 @@
 {
        Ewl_Image *i;
        Ewl_Embed *emb;
+       int ww, hh;
+       double sw, sh;
 
        DENTER_FUNCTION(DLEVEL_STABLE);
        DCHECK_PARAM_PTR("w", w);
@@ -411,27 +479,34 @@
        if (!i->oh)
                i->oh = 1;
 
-       if (i->aw || i->ah) {
-               ewl_image_scale_to(i, i->aw, i->ah);
-       }
-       else {
-               ewl_object_preferred_inner_w_set(EWL_OBJECT(i), i->ow);
-               ewl_object_preferred_inner_h_set(EWL_OBJECT(i), i->oh);
-               ewl_image_scale(i, i->sw, i->sh);
+       /*
+        * Bound the scales when proportional.
+        */
+       if (i->proportional) {
+               if (i->sw < i->sh)
+                       sh = i->sw;
+               else
+                       sw = i->sh;
        }
 
-       /*Constrain settings*/
-       if (i->cs && (i->ow > i->cs || i->oh > i->cs)) {
-               double cp = 0;
-               if (i->ow > i->oh) 
-                       cp = i->cs / (double)i->ow;
-               else 
-                       cp = i->cs / (double)i->oh;
+       sw = i->sw;
+       sh = i->sh;
 
-               ewl_image_scale(i, cp,cp);
-               ewl_image_tile_set(i,0,0,cp*i->ow,cp*i->oh);
+       /*
+        * Bound to absolute size.
+        */
+       if (i->aw)
+               ww = i->aw;
+       else
+               ww = i->ow;
+
+       if (i->ah)
+               hh = i->ah;
+       else
+               hh = i->oh;
 
-       }
+       ewl_object_preferred_inner_w_set(EWL_OBJECT(i), sw * ww);
+       ewl_object_preferred_inner_h_set(EWL_OBJECT(i), sh * hh);
 
        DLEAVE_FUNCTION(DLEVEL_STABLE);
 }
@@ -502,6 +577,7 @@
        Ewl_Image *i;
        Ewl_Embed *emb;
        int ww, hh;
+       int dx = 0, dy = 0;
 
        DENTER_FUNCTION(DLEVEL_STABLE);
        DCHECK_PARAM_PTR("w", w);
@@ -513,31 +589,43 @@
 
        emb = ewl_embed_widget_find(w);
 
-       ww = CURRENT_W(w);
-       hh = CURRENT_H(w);
+       if (i->cs)
+               ww = hh = i->cs;
+       else {
+               ww = CURRENT_W(w);
+               hh = CURRENT_H(w);
+       }
 
+       /*
+        * Fit the proportional scale.
+        */
        if (i->proportional) {
-               double op;
-
-               op = (double)i->ow / (double)i->oh;
+               double sw, sh;
 
-               if (i->ow < i->oh) {
-                       ww /= op;
+               sw = (double)ww / (double)i->ow;
+               sh = (double)hh / (double)i->oh;
+               printf("Image size: %dx%d\n", ww, hh);
+               printf("Scale ratios: %fx%f\n", sw, sh);
+               if (sw < sh) {
+                       hh = sw * i->oh;
                }
                else {
-                       hh *= op;
+                       ww = sh * i->ow;
                }
        }
 
        /*
         * set the tile width and height if not set already
-       */
+        */
        if (!i->tile.set) {
                i->tile.x = i->tile.y = 0;
-               i->tile.w = i->sw * ww;
-               i->tile.h = i->sh * hh;
+               i->tile.w = ww;
+               i->tile.h = hh;
        }
 
+       dx = (CURRENT_W(w) - ww) / 2;
+       dy = (CURRENT_H(w) - hh) / 2;
+
        /*
         * Move the image into place based on type.
         */
@@ -545,7 +633,7 @@
                evas_object_image_fill_set(i->image, i->tile.x, i->tile.y,
                                        i->tile.w, i->tile.h);
 
-       evas_object_move(i->image, CURRENT_X(w), CURRENT_Y(w));
+       evas_object_move(i->image, CURRENT_X(w) + dx, CURRENT_Y(w) + dy);
        evas_object_resize(i->image, ww, hh);
 
        DLEAVE_FUNCTION(DLEVEL_STABLE);
===================================================================
RCS file: /cvsroot/enlightenment/e17/libs/ewl/src/lib/ewl_image.h,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -3 -r1.15 -r1.16
--- ewl_image.h 17 Feb 2006 02:19:26 -0000      1.15
+++ ewl_image.h 9 Mar 2006 04:37:58 -0000       1.16
@@ -73,8 +73,10 @@
 const char     *ewl_image_file_key_get(Ewl_Image *i);
 
 void            ewl_image_proportional_set(Ewl_Image *i, char p);
-void            ewl_image_scale(Ewl_Image *i, double wp, double hp);
-void            ewl_image_scale_to(Ewl_Image *i, int w, int h);
+void            ewl_image_scale_set(Ewl_Image *i, double wp, double hp);
+void            ewl_image_scale_get(Ewl_Image *i, double *wp, double *hp);
+void            ewl_image_size_set(Ewl_Image *i, int w, int h);
+void            ewl_image_size_get(Ewl_Image *i, int *w, int *h);
 void            ewl_image_tile_set(Ewl_Image *i, int x, int y, 
                                                int w, int h);
 void            ewl_image_constrain_set(Ewl_Image *i, unsigned int size);
===================================================================
RCS file: /cvsroot/enlightenment/e17/libs/ewl/src/lib/ewl_menu_item.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -3 -r1.10 -r1.11
--- ewl_menu_item.c     22 Feb 2006 18:12:01 -0000      1.10
+++ ewl_menu_item.c     9 Mar 2006 04:37:58 -0000       1.11
@@ -47,7 +47,7 @@
        ewl_button_fill_policy_set(EWL_BUTTON(item), EWL_FLAG_FILL_HFILL);
        ewl_button_alignment_set(EWL_BUTTON(item), EWL_FLAG_ALIGN_LEFT);
        ewl_button_label_set(EWL_BUTTON(item), "");
-       ewl_button_image_scale_to(EWL_BUTTON(item), 16, 16);
+       ewl_button_image_size_set(EWL_BUTTON(item), 16, 16);
        ewl_widget_appearance_set(EWL_WIDGET(item), EWL_MENU_ITEM_TYPE);
        ewl_widget_inherit(EWL_WIDGET(item), EWL_MENU_ITEM_TYPE);
 




-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
enlightenment-cvs mailing list
enlightenment-cvs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs

Reply via email to