els_icon/elm_image - added features to aspect_ratio changeable
authorChunEon Park <chuneon.park@samsung.com>
Mon, 27 Jun 2011 07:31:26 +0000 (16:31 +0900)
committerChunEon Park <chuneon.park@samsung.com>
Mon, 27 Jun 2011 10:59:35 +0000 (19:59 +0900)
src/lib/Elementary.h.in
src/lib/elm_image.c
src/lib/els_icon.c
src/lib/els_icon.h

index baee20d..b6f3e01 100644 (file)
@@ -675,6 +675,9 @@ extern "C" {
    EAPI Elm_Image_Orient elm_image_orient_get(const Evas_Object *obj) EINA_ARG_NONNULL(1);
    EAPI void             elm_image_editable_set(Evas_Object *obj, Eina_Bool set) EINA_ARG_NONNULL(1);
    EAPI Eina_Bool        elm_image_editable_get(const Evas_Object *obj) EINA_ARG_NONNULL(1);
+   EAPI void             elm_image_aspect_ratio_retained_set(Evas_Object *obj, Eina_Bool retained) EINA_ARG_NONNULL(1);
+   EAPI Eina_Bool        elm_image_aspect_ratio_retained_get(const Evas_Object *obj) EINA_ARG_NONNULL(1);
+
    /* smart callbacks called:
     * "clicked" - the user clicked the image
     */
index adbab36..5816db6 100644 (file)
@@ -481,4 +481,38 @@ elm_image_editable_get(const Evas_Object *obj)
 }
 
 
-/* vim:set ts=8 sw=3 sts=3 expandtab cino=>5n-2f0^-2{2(0W1st0 :*/
+/**
+ * Enable/disable retaining up the aspect ratio of the image.
+ *
+ * @param obj The image object.
+ * @param retained Retaining or Non retaining.
+ *
+ * @ingroup Image
+ */
+EAPI void
+elm_image_aspect_ratio_retained_set(Evas_Object *obj, Eina_Bool retained)
+{
+   ELM_CHECK_WIDTYPE(obj, widtype);
+   Widget_Data *wd = elm_widget_data_get(obj);
+   if (!wd) return;
+   return _els_smart_icon_aspect_ratio_retained_set(wd->img, retained);
+}
+
+/**
+ * Get if the object retains the aspect ratio.
+ *
+ * @param obj The image object.
+ * @return If the object retains the aspect ratio.
+ *
+ * @ingroup Image
+ */
+EAPI Eina_Bool
+elm_image_aspect_ratio_retained_get(const Evas_Object *obj)
+{
+   ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
+   Widget_Data *wd = elm_widget_data_get(obj);
+   if (!wd) return EINA_FALSE;
+   return _els_smart_icon_aspect_ratio_retained_get(wd->img);
+}
+
+/* vim:set ts=8 sw=3 sts=3 expandtab cino=>5n-3f0^-2{2(0W1st0 :*/
index 83fd876..5f9b579 100755 (executable)
@@ -16,6 +16,7 @@ struct _Smart_Data
    Eina_Bool show : 1;
    Eina_Bool edit : 1;
    Eina_Bool edje : 1;
+   Eina_Bool aspect_ratio_retained: 1;
    Elm_Image_Orient orient;
 };
 
@@ -418,6 +419,30 @@ _els_smart_icon_edje_get(Evas_Object *obj)
    return sd->obj;
 }
 
+void
+_els_smart_icon_aspect_ratio_retained_set(Evas_Object *obj, Eina_Bool retained)
+{
+   Smart_Data *sd;
+
+   sd = evas_object_smart_data_get(obj);
+   if (!sd) return;
+
+   retained = !!retained;
+   if (sd->aspect_ratio_retained == retained) return;
+   sd->aspect_ratio_retained = retained;
+   _smart_reconfigure(sd);
+}
+
+Eina_Bool
+_els_smart_icon_aspect_ratio_retained_get(const Evas_Object *obj)
+{
+   Smart_Data *sd;
+
+   sd = evas_object_smart_data_get(obj);
+   if (!sd) return EINA_FALSE;
+   return sd->aspect_ratio_retained;
+}
+
 /* local subsystem globals */
 static void
 _smart_reconfigure(Smart_Data *sd)
@@ -425,10 +450,12 @@ _smart_reconfigure(Smart_Data *sd)
    Evas_Coord x, y, w, h;
 
    if (!sd->obj) return;
+
+   w = sd->w;
+   h = sd->h;
+
    if (!strcmp(evas_object_type_get(sd->obj), "edje"))
      {
-        w = sd->w;
-        h = sd->h;
         x = sd->x;
         y = sd->y;
         evas_object_move(sd->obj, x, y);
@@ -446,41 +473,35 @@ _smart_reconfigure(Smart_Data *sd)
         if (iw < 1) iw = 1;
         if (ih < 1) ih = 1;
 
-        if (sd->fill_inside)
+        if (sd->aspect_ratio_retained)
           {
-             w = sd->w;
              h = ((double)ih * w) / (double)iw;
-             if (h > sd->h)
+             if (sd->fill_inside)
                {
-                  h = sd->h;
-                  w = ((double)iw * h) / (double)ih;
+                  if (h > sd->h)
+                    {
+                       h = sd->h;
+                       w = ((double)iw * h) / (double)ih;
+                    }
                }
-          }
-        else
-          {
-             w = sd->w;
-             h = ((double)ih * w) / (double)iw;
-             if (h < sd->h)
+             else
                {
-                  h = sd->h;
-                  w = ((double)iw * h) / (double)ih;
+                  if (h < sd->h)
+                    {
+                       h = sd->h;
+                       w = ((double)iw * h) / (double)ih;
+                    }
                }
           }
         if (!sd->scale_up)
           {
-             if ((w > iw) || (h > ih))
-               {
-                  w = iw;
-                  h = ih;
-               }
+             if (w > iw) w = iw;
+             if (h > ih) h = ih;
           }
         if (!sd->scale_down)
           {
-             if ((w < iw) || (h < ih))
-               {
-                  w = iw;
-                  h = ih;
-               }
+             if (w < iw) w = iw;
+             if (h < ih) h = ih;
           }
         x = sd->x + ((sd->w - w) / 2);
         y = sd->y + ((sd->h - h) / 2);
@@ -536,6 +557,7 @@ _smart_add(Evas_Object *obj)
    sd->fill_inside = EINA_TRUE;
    sd->scale_up = EINA_TRUE;
    sd->scale_down = EINA_TRUE;
+   sd->aspect_ratio_retained = EINA_TRUE;
    sd->size = 64;
    sd->scale = 1.0;
    evas_object_smart_member_add(sd->obj, obj);
index f4325c8..bd49bb2 100644 (file)
@@ -21,3 +21,6 @@ Elm_Image_Orient _els_smart_icon_orient_get   (const Evas_Object *obj);
 void         _els_smart_icon_edit_set         (Evas_Object *obj, Eina_Bool, Evas_Object *parent);
 Eina_Bool    _els_smart_icon_edit_get         (const Evas_Object *obj);
 Evas_Object *_els_smart_icon_edje_get(Evas_Object *obj);
+void         _els_smart_icon_aspect_ratio_retained_set(Evas_Object *obj, Eina_Bool retained);
+Eina_Bool    _els_smart_icon_aspect_ratio_retained_get(const Evas_Object *obj);
+