Ephoto: Fix cropper slider math.
This commit is contained in:
parent
41a24cf1a6
commit
1acaef0e10
|
@ -18,119 +18,130 @@ struct _Ephoto_Cropper
|
||||||
int offsetx;
|
int offsetx;
|
||||||
int offsety;
|
int offsety;
|
||||||
int resizing;
|
int resizing;
|
||||||
int sliding;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static void
|
static void
|
||||||
_calculate_cropper_size(void *data, Evas_Object *obj EINA_UNUSED, const char *emission EINA_UNUSED, const char *source EINA_UNUSED)
|
_calculate_cropper_size(void *data, Evas_Object *obj EINA_UNUSED, const char *emission EINA_UNUSED, const char *source EINA_UNUSED)
|
||||||
{
|
{
|
||||||
Ephoto_Cropper *ec = data;
|
Ephoto_Cropper *ec = data;
|
||||||
|
Edje_Message_Int_Set *msg;
|
||||||
|
char buf[PATH_MAX];
|
||||||
|
int w, h, cw, ch, iw, ih, nw, nh;
|
||||||
|
double scalew, scaleh;
|
||||||
|
|
||||||
if (!ec->sliding)
|
evas_object_geometry_get(ec->layout, 0, 0, &w, &h);
|
||||||
{
|
edje_object_part_geometry_get(elm_layout_edje_get(ec->layout),
|
||||||
Edje_Message_Int_Set *msg;
|
|
||||||
char buf[PATH_MAX];
|
|
||||||
int w, h, cw, ch, iw, ih, nw, nh;
|
|
||||||
double scalew, scaleh;
|
|
||||||
|
|
||||||
evas_object_geometry_get(ec->layout, 0, 0, &w, &h);
|
|
||||||
edje_object_part_geometry_get(elm_layout_edje_get(ec->layout),
|
|
||||||
"ephoto.swallow.cropper", 0, 0, &cw, &ch);
|
"ephoto.swallow.cropper", 0, 0, &cw, &ch);
|
||||||
evas_object_image_size_get(elm_image_object_get(ec->image), &iw, &ih);
|
evas_object_image_size_get(elm_image_object_get(ec->image), &iw, &ih);
|
||||||
|
|
||||||
scalew = (double)cw/(double)w;
|
scalew = (double)cw/(double)w;
|
||||||
scaleh = (double)ch/(double)h;
|
scaleh = (double)ch/(double)h;
|
||||||
|
|
||||||
nw = iw*scalew;
|
nw = iw*scalew;
|
||||||
nh = ih*scaleh;
|
nh = ih*scaleh;
|
||||||
|
|
||||||
elm_slider_value_set(ec->cropw, nw);
|
elm_slider_value_set(ec->cropw, nw);
|
||||||
elm_slider_value_set(ec->croph, nh);
|
elm_slider_value_set(ec->croph, nh);
|
||||||
|
|
||||||
msg = alloca(sizeof(Edje_Message_Int_Set) + (3*sizeof(int)));
|
msg = alloca(sizeof(Edje_Message_Int_Set) + (3*sizeof(int)));
|
||||||
msg->count = 3;
|
msg->count = 3;
|
||||||
msg->val[0] = 11;
|
msg->val[0] = 11;
|
||||||
msg->val[1] = nw;
|
msg->val[1] = nw;
|
||||||
msg->val[2] = nh;
|
msg->val[2] = nh;
|
||||||
edje_object_message_send(elm_layout_edje_get(ec->layout), EDJE_MESSAGE_INT_SET, 1, msg);
|
edje_object_message_send(elm_layout_edje_get(ec->layout), EDJE_MESSAGE_INT_SET, 1, msg);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
_cropper_changed_width(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
|
_cropper_changed_width(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
|
||||||
{
|
{
|
||||||
Ephoto_Cropper *ec = data;
|
Ephoto_Cropper *ec = data;
|
||||||
Edje_Message_Int_Set *msg;
|
Edje_Message_Int_Set *msgl, *msgr;
|
||||||
int mw, cx, cw, ch, nw, nh, lx, lw, iw;
|
int mw, cx, cw, nw, lx, lw, iw, left, right;
|
||||||
double scalew;
|
double scalew;
|
||||||
|
|
||||||
ec->sliding = 1;
|
|
||||||
|
|
||||||
mw = elm_slider_value_get(ec->cropw);
|
mw = elm_slider_value_get(ec->cropw);
|
||||||
|
|
||||||
evas_object_geometry_get(ec->cropper, &cx, 0, &cw, &ch);
|
|
||||||
evas_object_geometry_get(ec->layout, &lx, 0, &lw, 0);
|
evas_object_geometry_get(ec->layout, &lx, 0, &lw, 0);
|
||||||
|
evas_object_geometry_get(ec->cropper, &cx, 0, &cw, 0);
|
||||||
evas_object_image_size_get(elm_image_object_get(ec->image), &iw, 0);
|
evas_object_image_size_get(elm_image_object_get(ec->image), &iw, 0);
|
||||||
|
|
||||||
scalew = (double)lw/(double)iw;
|
scalew = (double)mw/(double)iw;
|
||||||
nw = mw * scalew;
|
|
||||||
nh = ch;
|
|
||||||
|
|
||||||
msg = alloca(sizeof(Edje_Message_Int_Set) + (3*sizeof(int)));
|
nw = lw*scalew;
|
||||||
msg->count = 3;
|
left = (nw-cw)/2;
|
||||||
if ((nw+cx) >= (lx+lw))
|
right = (nw-cw)/2;
|
||||||
{
|
|
||||||
msg->val[0] = 8;
|
|
||||||
nw = cw-nw;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
msg->val[0] = 4;
|
|
||||||
nw -= cw;
|
|
||||||
}
|
|
||||||
msg->val[1] = nw;
|
|
||||||
msg->val[2] = 0;
|
|
||||||
edje_object_message_send(elm_layout_edje_get(ec->layout), EDJE_MESSAGE_INT_SET, 1, msg);
|
|
||||||
|
|
||||||
ec->sliding = 0;
|
if ((cx+cw+right) >= (lx+lw))
|
||||||
|
{
|
||||||
|
right = (lx+lw)-(cx+cw);
|
||||||
|
left += left - right;
|
||||||
|
}
|
||||||
|
else if ((cx-left) <= lx)
|
||||||
|
{
|
||||||
|
left = cx-lx;
|
||||||
|
right += right - left;
|
||||||
|
}
|
||||||
|
left *= -1;
|
||||||
|
|
||||||
|
msgl = alloca(sizeof(Edje_Message_Int_Set) + (3*sizeof(int)));
|
||||||
|
msgl->count = 3;
|
||||||
|
msgl->val[0] = 8;
|
||||||
|
msgl->val[1] = left;
|
||||||
|
msgl->val[2] = 0;
|
||||||
|
edje_object_message_send(elm_layout_edje_get(ec->layout), EDJE_MESSAGE_INT_SET, 1, msgl);
|
||||||
|
|
||||||
|
msgr = alloca(sizeof(Edje_Message_Int_Set) + (3*sizeof(int)));
|
||||||
|
msgr->count = 3;
|
||||||
|
msgr->val[0] = 4;
|
||||||
|
msgr->val[1] = right;
|
||||||
|
msgr->val[2] = 0;
|
||||||
|
edje_object_message_send(elm_layout_edje_get(ec->layout), EDJE_MESSAGE_INT_SET, 1, msgr);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
_cropper_changed_height(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
|
_cropper_changed_height(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
|
||||||
{
|
{
|
||||||
Ephoto_Cropper *ec = data;
|
Ephoto_Cropper *ec = data;
|
||||||
Edje_Message_Int_Set *msg;
|
Edje_Message_Int_Set *msgt, *msgb;
|
||||||
int mh, ch, cy, nh, lh, ly, ih;
|
int mh, ch, cy, nh, lh, ly, ih, left, top, bottom;
|
||||||
double scaleh;
|
double scaleh;
|
||||||
|
|
||||||
ec->sliding = 1;
|
|
||||||
|
|
||||||
mh = elm_slider_value_get(ec->croph);
|
mh = elm_slider_value_get(ec->croph);
|
||||||
|
|
||||||
evas_object_geometry_get(ec->cropper, 0, &cy, 0, &ch);
|
|
||||||
evas_object_geometry_get(ec->layout, 0, &ly, 0, &lh);
|
evas_object_geometry_get(ec->layout, 0, &ly, 0, &lh);
|
||||||
|
evas_object_geometry_get(ec->cropper, 0, &cy, 0, &ch);
|
||||||
evas_object_image_size_get(elm_image_object_get(ec->image), 0, &ih);
|
evas_object_image_size_get(elm_image_object_get(ec->image), 0, &ih);
|
||||||
|
|
||||||
scaleh = (double)lh/(double)ih;
|
scaleh = (double)mh/(double)ih;
|
||||||
nh = mh * scaleh;
|
nh = lh*scaleh;
|
||||||
|
top = (nh-ch)/2;
|
||||||
|
bottom = (nh-ch)/2;
|
||||||
|
|
||||||
msg = alloca(sizeof(Edje_Message_Int_Set) + (3*sizeof(int)));
|
if ((cy+ch+bottom) >= (ly+lh))
|
||||||
msg->count = 3;
|
|
||||||
if ((nh+cy) >= (ly+lh))
|
|
||||||
{
|
{
|
||||||
msg->val[0] = 2;
|
bottom = (ly+lh)-(cy+ch);
|
||||||
nh = ch-nh;
|
top += top - bottom;
|
||||||
}
|
}
|
||||||
else
|
else if ((cy-top) <= ly)
|
||||||
{
|
{
|
||||||
msg->val[0] = 6;
|
top = cy-ly;
|
||||||
nh -= ch;
|
bottom += bottom - top;
|
||||||
}
|
}
|
||||||
msg->val[1] = 0;
|
top *= -1;
|
||||||
msg->val[2] = nh;
|
|
||||||
edje_object_message_send(elm_layout_edje_get(ec->layout), EDJE_MESSAGE_INT_SET, 1, msg);
|
|
||||||
|
|
||||||
ec->sliding = 0;
|
msgt = alloca(sizeof(Edje_Message_Int_Set) + (3*sizeof(int)));
|
||||||
|
msgt->count = 3;
|
||||||
|
msgt->val[0] = 2;
|
||||||
|
msgt->val[1] = 0;
|
||||||
|
msgt->val[2] = top;
|
||||||
|
edje_object_message_send(elm_layout_edje_get(ec->layout), EDJE_MESSAGE_INT_SET, 1, msgt);
|
||||||
|
|
||||||
|
msgb = alloca(sizeof(Edje_Message_Int_Set) + (3*sizeof(int)));
|
||||||
|
msgb->count = 3;
|
||||||
|
msgb->val[0] = 6;
|
||||||
|
msgb->val[1] = 0;
|
||||||
|
msgb->val[2] = bottom;
|
||||||
|
edje_object_message_send(elm_layout_edje_get(ec->layout), EDJE_MESSAGE_INT_SET, 1, msgb);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
Loading…
Reference in New Issue