forked from enlightenment/efl
From: Viktor Kojouharov <vkojouharov@gmail.com>
this is a patch for the elm_image so far. After some valgrind work and with the help of Gustavo, the orient code for the image is not leak free (according to valgrind). According to k-s, this way of doing things would avoid any nasty caching errors I've been getting though valgrind before. SVN revision: 40314
This commit is contained in:
parent
87e7d4b5d7
commit
7b2198b7d3
|
@ -241,7 +241,6 @@ extern "C" {
|
|||
EAPI Evas_Object *elm_win_inwin_add(Evas_Object *obj);
|
||||
EAPI void elm_win_inwin_activate(Evas_Object *obj);
|
||||
EAPI void elm_win_inwin_style_set(Evas_Object *obj, const char *style);
|
||||
EAPI void elm_win_inwin_activate(Evas_Object *obj);
|
||||
EAPI void elm_win_inwin_content_set(Evas_Object *obj, Evas_Object *content);
|
||||
/* available styles:
|
||||
* default
|
||||
|
@ -274,6 +273,30 @@ extern "C" {
|
|||
* "clicked" - the user clicked the icon
|
||||
*/
|
||||
|
||||
typedef enum _Elm_Image_Orient
|
||||
{
|
||||
ELM_IMAGE_ORIENT_NONE,
|
||||
ELM_IMAGE_ROTATE_90_CW,
|
||||
ELM_IMAGE_ROTATE_180_CW,
|
||||
ELM_IMAGE_ROTATE_90_CCW,
|
||||
ELM_IMAGE_FLIP_HORIZONTAL,
|
||||
ELM_IMAGE_FLIP_VERTICAL,
|
||||
ELM_IMAGE_FLIP_TRANSPOSE,
|
||||
ELM_IMAGE_FLIP_TRANSVERSE
|
||||
} Elm_Image_Orient;
|
||||
|
||||
EAPI Evas_Object *elm_image_add(Evas_Object *parent);
|
||||
EAPI Eina_Bool elm_image_file_set(Evas_Object *obj, const char *file, const char *group);
|
||||
EAPI void elm_image_smooth_set(Evas_Object *obj, Evas_Bool smooth);
|
||||
EAPI void elm_image_no_scale_set(Evas_Object *obj, Evas_Bool no_scale);
|
||||
EAPI void elm_image_scale_set(Evas_Object *obj, Evas_Bool scale_up, Evas_Bool scale_down);
|
||||
EAPI void elm_image_fill_outside_set(Evas_Object *obj, Evas_Bool fill_outside);
|
||||
EAPI void elm_image_prescale_set(Evas_Object *obj, int size);
|
||||
EAPI void elm_image_orient_set(Evas_Object *obj, Elm_Image_Orient orient);
|
||||
/* smart callbacks called:
|
||||
* "clicked" - the user clicked the image
|
||||
*/
|
||||
|
||||
EAPI Evas_Object *elm_box_add(Evas_Object *parent);
|
||||
EAPI void elm_box_horizontal_set(Evas_Object *obj, Evas_Bool horizontal);
|
||||
EAPI void elm_box_homogenous_set(Evas_Object *obj, Evas_Bool homogenous);
|
||||
|
|
|
@ -32,6 +32,7 @@ elm_win.c \
|
|||
elm_widget.c \
|
||||
elm_bg.c \
|
||||
elm_icon.c \
|
||||
elm_image.c \
|
||||
elm_box.c \
|
||||
elm_button.c \
|
||||
elm_scroller.c \
|
||||
|
|
|
@ -0,0 +1,181 @@
|
|||
/*
|
||||
* vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2,t0,(0
|
||||
*/
|
||||
#include <Elementary.h>
|
||||
#include "elm_priv.h"
|
||||
|
||||
typedef struct _Widget_Data Widget_Data;
|
||||
|
||||
struct _Widget_Data
|
||||
{
|
||||
Evas_Object *img;
|
||||
Evas_Bool scale_up : 1;
|
||||
Evas_Bool scale_down : 1;
|
||||
Evas_Bool smooth : 1;
|
||||
Evas_Bool fill_outside : 1;
|
||||
Evas_Bool no_scale : 1;
|
||||
};
|
||||
|
||||
static void _del_hook(Evas_Object *obj);
|
||||
static void _theme_hook(Evas_Object *obj);
|
||||
static void _sizing_eval(Evas_Object *obj);
|
||||
static void _mouse_up(void *data, Evas *e, Evas_Object *obj, void *event_info);
|
||||
|
||||
static void
|
||||
_del_hook(Evas_Object *obj)
|
||||
{
|
||||
Widget_Data *wd = elm_widget_data_get(obj);
|
||||
if (!wd) return;
|
||||
evas_object_del(wd->img);
|
||||
free(wd);
|
||||
}
|
||||
|
||||
static void
|
||||
_theme_hook(Evas_Object *obj)
|
||||
{
|
||||
Widget_Data *wd = elm_widget_data_get(obj);
|
||||
if (!wd) return;
|
||||
_sizing_eval(obj);
|
||||
}
|
||||
|
||||
static void
|
||||
_sizing_eval(Evas_Object *obj)
|
||||
{
|
||||
Widget_Data *wd = elm_widget_data_get(obj);
|
||||
if (!wd) return;
|
||||
Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
|
||||
int w, h;
|
||||
|
||||
_els_smart_icon_size_get(wd->img, &w, &h);
|
||||
_els_smart_icon_scale_up_set(wd->img, wd->scale_up);
|
||||
_els_smart_icon_scale_down_set(wd->img, wd->scale_down);
|
||||
_els_smart_icon_smooth_scale_set(wd->img, wd->smooth);
|
||||
_els_smart_icon_fill_inside_set(wd->img, !(wd->fill_outside));
|
||||
if (wd->no_scale) _els_smart_icon_scale_set(wd->img, 1.0);
|
||||
else
|
||||
{
|
||||
_els_smart_icon_scale_set(wd->img, elm_widget_scale_get(obj) * _elm_config->scale);
|
||||
_els_smart_icon_size_get(wd->img, &w, &h);
|
||||
}
|
||||
if (!wd->scale_down)
|
||||
{
|
||||
minw = w;
|
||||
minh = h;
|
||||
}
|
||||
if (!wd->scale_up)
|
||||
{
|
||||
maxw = w;
|
||||
maxh = h;
|
||||
}
|
||||
evas_object_size_hint_min_set(obj, minw, minh);
|
||||
evas_object_size_hint_max_set(obj, maxw, maxh);
|
||||
}
|
||||
|
||||
static void
|
||||
_mouse_up(void *data, Evas *e, Evas_Object *obj, void *event_info)
|
||||
{
|
||||
evas_object_smart_callback_call(data, "clicked", NULL);
|
||||
}
|
||||
|
||||
EAPI Evas_Object *
|
||||
elm_image_add(Evas_Object *parent)
|
||||
{
|
||||
Evas_Object *obj;
|
||||
Evas *e;
|
||||
Widget_Data *wd;
|
||||
|
||||
wd = ELM_NEW(Widget_Data);
|
||||
e = evas_object_evas_get(parent);
|
||||
obj = elm_widget_add(e);
|
||||
elm_widget_data_set(obj, wd);
|
||||
elm_widget_del_hook_set(obj, _del_hook);
|
||||
elm_widget_theme_hook_set(obj, _theme_hook);
|
||||
elm_widget_can_focus_set(obj, 0);
|
||||
|
||||
wd->img = _els_smart_icon_add(e);
|
||||
evas_object_event_callback_add(wd->img, EVAS_CALLBACK_MOUSE_UP,
|
||||
_mouse_up, obj);
|
||||
evas_object_repeat_events_set(wd->img, 1);
|
||||
elm_widget_resize_object_set(obj, wd->img);
|
||||
|
||||
wd->smooth = 1;
|
||||
wd->scale_up = 1;
|
||||
wd->scale_down = 1;
|
||||
|
||||
_els_smart_icon_scale_size_set(wd->img, 0);
|
||||
|
||||
_sizing_eval(obj);
|
||||
return obj;
|
||||
}
|
||||
|
||||
EAPI Eina_Bool
|
||||
elm_image_file_set(Evas_Object *obj, const char *file, const char *group)
|
||||
{
|
||||
Widget_Data *wd = elm_widget_data_get(obj);
|
||||
Eina_Bool ret;
|
||||
if (!wd) return 0;
|
||||
const char *p;
|
||||
|
||||
if (!file) return 0;
|
||||
if (((p = strrchr(file, '.'))) && (!strcasecmp(p, ".edj")))
|
||||
ret = _els_smart_icon_file_edje_set(wd->img, file, group);
|
||||
else
|
||||
ret = _els_smart_icon_file_key_set(wd->img, file, group);
|
||||
_sizing_eval(obj);
|
||||
return ret;
|
||||
}
|
||||
|
||||
EAPI void
|
||||
elm_image_smooth_set(Evas_Object *obj, Evas_Bool smooth)
|
||||
{
|
||||
Widget_Data *wd = elm_widget_data_get(obj);
|
||||
if (!wd) return;
|
||||
wd->smooth = smooth;
|
||||
_sizing_eval(obj);
|
||||
}
|
||||
|
||||
EAPI void
|
||||
elm_image_no_scale_set(Evas_Object *obj, Evas_Bool no_scale)
|
||||
{
|
||||
Widget_Data *wd = elm_widget_data_get(obj);
|
||||
if (!wd) return;
|
||||
wd->no_scale = no_scale;
|
||||
_sizing_eval(obj);
|
||||
}
|
||||
|
||||
EAPI void
|
||||
elm_image_scale_set(Evas_Object *obj, Evas_Bool scale_up, Evas_Bool scale_down)
|
||||
{
|
||||
Widget_Data *wd = elm_widget_data_get(obj);
|
||||
if (!wd) return;
|
||||
wd->scale_up = scale_up;
|
||||
wd->scale_down = scale_down;
|
||||
_sizing_eval(obj);
|
||||
}
|
||||
|
||||
EAPI void
|
||||
elm_image_fill_outside_set(Evas_Object *obj, Evas_Bool fill_outside)
|
||||
{
|
||||
Widget_Data *wd = elm_widget_data_get(obj);
|
||||
if (!wd) return;
|
||||
wd->fill_outside = fill_outside;
|
||||
_sizing_eval(obj);
|
||||
}
|
||||
|
||||
EAPI void
|
||||
elm_image_prescale_set(Evas_Object *obj, int size)
|
||||
{
|
||||
Widget_Data *wd = elm_widget_data_get(obj);
|
||||
if (!wd) return;
|
||||
|
||||
_els_smart_icon_scale_size_set(wd->img, size);
|
||||
}
|
||||
|
||||
EAPI void
|
||||
elm_image_orient_set(Evas_Object *obj, Elm_Image_Orient orient)
|
||||
{
|
||||
Widget_Data *wd = elm_widget_data_get(obj);
|
||||
if (!wd) return;
|
||||
|
||||
_els_smart_icon_orient_set(wd->img, orient);
|
||||
}
|
|
@ -27,6 +27,10 @@ static void _smart_color_set(Evas_Object *obj, int r, int g, int b, int a);
|
|||
static void _smart_clip_set(Evas_Object *obj, Evas_Object * clip);
|
||||
static void _smart_clip_unset(Evas_Object *obj);
|
||||
|
||||
static void _els_smart_icon_flip_horizontal(Smart_Data *sd);
|
||||
static void _els_smart_icon_flip_vertical(Smart_Data *sd);
|
||||
static void _els_smart_icon_rotate_180(Smart_Data *sd);
|
||||
|
||||
/* local subsystem globals */
|
||||
static Evas_Smart *_e_smart = NULL;
|
||||
|
||||
|
@ -149,6 +153,7 @@ _els_smart_icon_scale_size_set(Evas_Object *obj, int size)
|
|||
sd = evas_object_smart_data_get(obj);
|
||||
if (!sd) return;
|
||||
sd->size = size;
|
||||
if (!sd->obj) return;
|
||||
if (!strcmp(evas_object_type_get(sd->obj), "edje"))
|
||||
return;
|
||||
evas_object_image_load_size_set(sd->obj, sd->size, sd->size);
|
||||
|
@ -165,6 +170,84 @@ _els_smart_icon_scale_set(Evas_Object *obj, double scale)
|
|||
_smart_reconfigure(sd);
|
||||
}
|
||||
|
||||
void
|
||||
_els_smart_icon_orient_set(Evas_Object *obj, Elm_Image_Orient orient)
|
||||
{
|
||||
Smart_Data *sd;
|
||||
Evas_Object *tmp;
|
||||
unsigned int *data, *data2, *to, *from;
|
||||
int x, y, w, hw, iw, ih;
|
||||
const char *file, *key;
|
||||
|
||||
sd = evas_object_smart_data_get(obj);
|
||||
if (!sd) return;
|
||||
if (!strcmp(evas_object_type_get(sd->obj), "edje"))
|
||||
return;
|
||||
|
||||
switch (orient)
|
||||
{
|
||||
case ELM_IMAGE_FLIP_HORIZONTAL:
|
||||
_els_smart_icon_flip_horizontal(sd);
|
||||
return;
|
||||
case ELM_IMAGE_FLIP_VERTICAL:
|
||||
_els_smart_icon_flip_vertical(sd);
|
||||
return;
|
||||
case ELM_IMAGE_ROTATE_180_CW:
|
||||
_els_smart_icon_rotate_180(sd);
|
||||
return;
|
||||
}
|
||||
|
||||
evas_object_image_size_get(sd->obj, &iw, &ih);
|
||||
evas_object_image_file_get(sd->obj, &file, &key);
|
||||
tmp = evas_object_image_add(evas_object_evas_get(sd->obj));
|
||||
evas_object_image_file_set(tmp, file, key);
|
||||
data2 = evas_object_image_data_get(tmp, 0);
|
||||
|
||||
w = ih;
|
||||
ih = iw;
|
||||
iw = w;
|
||||
hw = w * ih;
|
||||
|
||||
evas_object_image_size_set(sd->obj, iw, ih);
|
||||
data = evas_object_image_data_get(sd->obj, 1);
|
||||
switch (orient)
|
||||
{
|
||||
case ELM_IMAGE_FLIP_TRANSPOSE:
|
||||
to = data;
|
||||
hw = -hw + 1;
|
||||
break;
|
||||
case ELM_IMAGE_FLIP_TRANSVERSE:
|
||||
to = data + hw - 1;
|
||||
w = -w;
|
||||
hw = hw - 1;
|
||||
break;
|
||||
case ELM_IMAGE_ROTATE_90_CW:
|
||||
to = data + w - 1;
|
||||
hw = -hw - 1;
|
||||
break;
|
||||
case ELM_IMAGE_ROTATE_90_CCW:
|
||||
to = data + hw - w;
|
||||
w = -w;
|
||||
hw = hw + 1;
|
||||
break;
|
||||
}
|
||||
from = data2;
|
||||
for (x = iw; --x >= 0;)
|
||||
{
|
||||
for (y = ih; --y >= 0;)
|
||||
{
|
||||
*to = *from;
|
||||
from++;
|
||||
to += w;
|
||||
}
|
||||
to += hw;
|
||||
}
|
||||
evas_object_del(tmp);
|
||||
evas_object_image_data_set(sd->obj, data);
|
||||
evas_object_image_data_update_add(sd->obj, 0, 0, iw, ih);
|
||||
_smart_reconfigure(sd);
|
||||
}
|
||||
|
||||
/* local subsystem globals */
|
||||
static void
|
||||
_smart_reconfigure(Smart_Data *sd)
|
||||
|
@ -184,7 +267,7 @@ _smart_reconfigure(Smart_Data *sd)
|
|||
}
|
||||
else
|
||||
{
|
||||
ih = 0;
|
||||
iw = 0;
|
||||
ih = 0;
|
||||
evas_object_image_size_get(sd->obj, &iw, &ih);
|
||||
|
||||
|
@ -372,3 +455,89 @@ _smart_clip_unset(Evas_Object *obj)
|
|||
if (!sd) return;
|
||||
evas_object_clip_unset(sd->obj);
|
||||
}
|
||||
|
||||
static void
|
||||
_els_smart_icon_flip_horizontal(Smart_Data *sd)
|
||||
{
|
||||
unsigned int *data;
|
||||
unsigned int *p1, *p2, tmp;
|
||||
int x, y, iw, ih;
|
||||
|
||||
evas_object_image_size_get(sd->obj, &iw, &ih);
|
||||
data = evas_object_image_data_get(sd->obj, 1);
|
||||
|
||||
for (y = 0; y < ih; y++)
|
||||
{
|
||||
p1 = data + (y * iw);
|
||||
p2 = data + ((y + 1) * iw) - 1;
|
||||
for (x = 0; x < (iw >> 1); x++)
|
||||
{
|
||||
tmp = *p1;
|
||||
*p1 = *p2;
|
||||
*p2 = tmp;
|
||||
p1++;
|
||||
p2--;
|
||||
}
|
||||
}
|
||||
|
||||
evas_object_image_data_set(sd->obj, data);
|
||||
evas_object_image_data_update_add(sd->obj, 0, 0, iw, ih);
|
||||
_smart_reconfigure(sd);
|
||||
}
|
||||
|
||||
static void
|
||||
_els_smart_icon_flip_vertical(Smart_Data *sd)
|
||||
{
|
||||
unsigned int *data;
|
||||
unsigned int *p1, *p2, tmp;
|
||||
int x, y, iw, ih;
|
||||
|
||||
evas_object_image_size_get(sd->obj, &iw, &ih);
|
||||
data = evas_object_image_data_get(sd->obj, 1);
|
||||
|
||||
for (y = 0; y < (ih >> 1); y++)
|
||||
{
|
||||
p1 = data + (y * iw);
|
||||
p2 = data + ((ih - 1 - y) * iw);
|
||||
for (x = 0; x < iw; x++)
|
||||
{
|
||||
tmp = *p1;
|
||||
*p1 = *p2;
|
||||
*p2 = tmp;
|
||||
p1++;
|
||||
p2++;
|
||||
}
|
||||
}
|
||||
|
||||
evas_object_image_data_set(sd->obj, data);
|
||||
evas_object_image_data_update_add(sd->obj, 0, 0, iw, ih);
|
||||
_smart_reconfigure(sd);
|
||||
}
|
||||
|
||||
static void
|
||||
_els_smart_icon_rotate_180(Smart_Data *sd)
|
||||
{
|
||||
unsigned int *data;
|
||||
unsigned int *p1, *p2, tmp;
|
||||
int x, hw, iw, ih;
|
||||
|
||||
evas_object_image_size_get(sd->obj, &iw, &ih);
|
||||
data = evas_object_image_data_get(sd->obj, 1);
|
||||
|
||||
hw = iw * ih;
|
||||
x = (hw / 2);
|
||||
p1 = data;
|
||||
p2 = data + hw - 1;
|
||||
for (; --x > 0;)
|
||||
{
|
||||
tmp = *p1;
|
||||
*p1 = *p2;
|
||||
*p2 = tmp;
|
||||
p1++;
|
||||
p2--;
|
||||
}
|
||||
evas_object_image_data_set(sd->obj, data);
|
||||
evas_object_image_data_update_add(sd->obj, 0, 0, iw, ih);
|
||||
_smart_reconfigure(sd);
|
||||
}
|
||||
|
||||
|
|
|
@ -8,3 +8,4 @@ void _els_smart_icon_scale_up_set (Evas_Object *obj, int scale_up);
|
|||
void _els_smart_icon_scale_down_set (Evas_Object *obj, int scale_down);
|
||||
void _els_smart_icon_scale_size_set (Evas_Object *obj, int size);
|
||||
void _els_smart_icon_scale_set (Evas_Object *obj, double scale);
|
||||
void _els_smart_icon_orient_set (Evas_Object *obj, Elm_Image_Orient orient);
|
||||
|
|
Loading…
Reference in New Issue