From f8b9b7e82038b381a87c102a2496ec571ce4e622 Mon Sep 17 00:00:00 2001 From: Stephen Houston Date: Thu, 19 Feb 2015 14:21:50 -0600 Subject: [PATCH] Ephoto: Fix crop calcs. Still needs constraint. --- data/themes/crop.edc | 62 +++++++++++++++---- src/bin/ephoto_cropper.c | 129 +++++++++++++++++---------------------- 2 files changed, 105 insertions(+), 86 deletions(-) diff --git a/data/themes/crop.edc b/data/themes/crop.edc index 39595fd..93a0272 100644 --- a/data/themes/crop.edc +++ b/data/themes/crop.edc @@ -3,22 +3,54 @@ collections { script { public message(Msg_Type:type, id, ...) { if ((type == MSG_INT_SET) && (id == 1)) { - new cox, coy, cw, ch, pox, poy; + new movetype, cox, coy, pox, poy; - cox = getarg(2); - coy = getarg(3); - cw = getarg(4); - ch = getarg(5); + movetype = getarg(2); + cox = getarg(3); + coy = getarg(4); - get_state_val(PART:"ephoto.swallow.cropper", STATE_REL1_OFFSET, pox, poy); - - cox += pox; - coy += poy; - custom_state(PART:"ephoto.swallow.cropper", "default", 0.0); - set_state_val(PART:"ephoto.swallow.cropper", STATE_MIN, cw, ch); - set_state_val(PART:"ephoto.swallow.cropper", STATE_MAX, cw, ch); - set_state_val(PART:"ephoto.swallow.cropper", STATE_REL1_OFFSET, cox, coy); + if (movetype == 0) { + new ppox, ppoy; + get_state_val(PART:"ephoto.swallow.cropper", STATE_REL1_OFFSET, pox, poy); + pox += cox; + poy += coy; + get_state_val(PART:"ephoto.swallow.cropper", STATE_REL2_OFFSET, ppox, ppoy); + ppox += cox; + ppoy += coy; + set_state_val(PART:"ephoto.swallow.cropper", STATE_REL1_OFFSET, pox, poy); + set_state_val(PART:"ephoto.swallow.cropper", STATE_REL2_OFFSET, ppox, ppoy); + } + if (movetype == 1 || movetype == 2 || movetype == 8) { + get_state_val(PART:"ephoto.swallow.cropper", STATE_REL1_OFFSET, pox, poy); + cox += pox; + coy += poy; + set_state_val(PART:"ephoto.swallow.cropper", STATE_REL1_OFFSET, cox, coy); + } + if (movetype == 3) { + new ppox, ppoy; + get_state_val(PART:"ephoto.swallow.cropper", STATE_REL1_OFFSET, pox, poy); + poy += coy; + get_state_val(PART:"ephoto.swallow.cropper", STATE_REL2_OFFSET, ppox, ppoy); + ppox += cox; + set_state_val(PART:"ephoto.swallow.cropper", STATE_REL1_OFFSET, pox, poy); + set_state_val(PART:"ephoto.swallow.cropper", STATE_REL2_OFFSET, ppox, ppoy); + } + if (movetype == 4 || movetype == 5 || movetype == 6) { + get_state_val(PART:"ephoto.swallow.cropper", STATE_REL2_OFFSET, pox, poy); + cox += pox; + coy += poy; + set_state_val(PART:"ephoto.swallow.cropper", STATE_REL2_OFFSET, cox, coy); + } + if (movetype == 7) { + new ppox, ppoy; + get_state_val(PART:"ephoto.swallow.cropper", STATE_REL1_OFFSET, pox, poy); + pox += cox; + get_state_val(PART:"ephoto.swallow.cropper", STATE_REL2_OFFSET, ppox, ppoy); + ppoy += coy; + set_state_val(PART:"ephoto.swallow.cropper", STATE_REL1_OFFSET, pox, poy); + set_state_val(PART:"ephoto.swallow.cropper", STATE_REL2_OFFSET, ppox, ppoy); + } set_state(PART:"ephoto.swallow.cropper", "custom", 0.0); } } @@ -43,6 +75,10 @@ collections { mouse_events: 1; clip_to: "clipper"; description { state: "default" 0.0; + rel1.to: "ephoto.swallow.image"; + rel1.relative: 0.2 0.2; + rel2.to: "ephoto.swallow.image"; + rel2.relative: 0.8 0.8; } } part { name: "shader_top"; diff --git a/src/bin/ephoto_cropper.c b/src/bin/ephoto_cropper.c index 3bc72a3..cc84f46 100644 --- a/src/bin/ephoto_cropper.c +++ b/src/bin/ephoto_cropper.c @@ -9,10 +9,9 @@ struct _Ephoto_Cropper Evas_Object *layout; int startx; int starty; - int startcx; - int startcy; int offsetx; int offsety; + int resizing; }; static void @@ -27,36 +26,22 @@ _cropper_both_mouse_move(void *data, Evas_Object *obj EINA_UNUSED, const char *e nx = mx - ec->startx; ny = my - ec->starty; - ec->startx += nx; - ec->starty += ny; + ec->startx = mx; + ec->starty = my; + msg = alloca(sizeof(Edje_Message_Int_Set) + (3*sizeof(int))); + msg->count = 3; if (!strcmp(source, "handle1")) - { - cw -= nx; - ch -= ny; - } + msg->val[0] = 1; else if (!strcmp(source, "handle3")) - { - cw += nx; - ch -= ny; - } + msg->val[0] = 3; else if (!strcmp(source, "handle5")) - { - cw += nx; - ch += ny; - } + msg->val[0] = 5; else if (!strcmp(source, "handle7")) - { - cw -= nx; - ch += ny; - } - - msg = alloca(sizeof(Edje_Message_Int_Set) + (4*sizeof(int))); - msg->count = 4; - msg->val[0] = nx/2; - msg->val[1] = ny/2; - msg->val[2] = cw; - msg->val[3] = ch; + msg->val[0] = 7; + + msg->val[1] = nx; + msg->val[2] = ny; edje_object_message_send(elm_layout_edje_get(ec->layout), EDJE_MESSAGE_INT_SET, 1, msg); } @@ -67,6 +52,7 @@ _cropper_both_mouse_up(void *data, Evas_Object *obj EINA_UNUSED, const char *emi edje_object_signal_callback_del_full(ec->cropper, "mouse,move", source, _cropper_both_mouse_move, ec); edje_object_signal_callback_del_full(ec->cropper, "mouse,up,1", source, _cropper_both_mouse_up, ec); + ec->resizing = 0; } static void @@ -75,14 +61,13 @@ _cropper_resize_both(void *data, Evas_Object *obj EINA_UNUSED, const char *emiss Ephoto_Cropper *ec = data; int mx, my, cx, cy; + ec->resizing = 1; evas_pointer_canvas_xy_get(evas_object_evas_get(ec->cropper), &mx, &my); evas_object_geometry_get(ec->cropper, &cx, &cy, 0, 0); ec->offsetx = mx - cx; ec->offsety = my - cy; ec->startx = mx; ec->starty = my; - ec->startcx = cx; - ec->startcy = cy; edje_object_signal_callback_add(ec->cropper, "mouse,move", source, _cropper_both_mouse_move, ec); edje_object_signal_callback_add(ec->cropper, "mouse,up,1", source, _cropper_both_mouse_up, ec); @@ -100,19 +85,16 @@ _cropper_horiz_mouse_move(void *data, Evas_Object *obj EINA_UNUSED, const char * nx = mx - ec->startx; - ec->startx += nx; + ec->startx = mx; - if (!strcmp(source, "handle8")) - cw -= nx; - else if (!strcmp(source, "handle4")) - cw += nx; - - msg = alloca(sizeof(Edje_Message_Int_Set) + (4*sizeof(int))); - msg->count = 4; - msg->val[0] = nx/2; - msg->val[1] = 0; - msg->val[2] = cw; - msg->val[3] = ch; + msg = alloca(sizeof(Edje_Message_Int_Set) + (3*sizeof(int))); + msg->count = 3; + if (!strcmp(source, "handle4")) + msg->val[0] = 4; + else if (!strcmp(source, "handle8")) + msg->val[0] = 8; + msg->val[1] = nx; + msg->val[2] = 0; edje_object_message_send(elm_layout_edje_get(ec->layout), EDJE_MESSAGE_INT_SET, 1, msg); } @@ -123,6 +105,7 @@ _cropper_horiz_mouse_up(void *data, Evas_Object *obj EINA_UNUSED, const char *em edje_object_signal_callback_del_full(ec->cropper, "mouse,move", source, _cropper_horiz_mouse_move, ec); edje_object_signal_callback_del_full(ec->cropper, "mouse,up,1", source, _cropper_horiz_mouse_up, ec); + ec->resizing = 0; } @@ -132,14 +115,14 @@ _cropper_resize_horiz(void *data, Evas_Object *obj EINA_UNUSED, const char *emis Ephoto_Cropper *ec = data; int mx, my, cx, cy; + ec->resizing = 1; evas_pointer_canvas_xy_get(evas_object_evas_get(ec->cropper), &mx, &my); evas_object_geometry_get(ec->cropper, &cx, &cy, 0, 0); ec->offsetx = mx - cx; ec->offsety = my - cy; ec->startx = mx; ec->starty = my; - ec->startcx = cx; - ec->startcy = cy; + edje_object_signal_callback_add(ec->cropper, "mouse,move", source, _cropper_horiz_mouse_move, ec); edje_object_signal_callback_add(ec->cropper, "mouse,up,1", source, _cropper_horiz_mouse_up, ec); @@ -156,19 +139,17 @@ _cropper_vert_mouse_move(void *data, Evas_Object *obj EINA_UNUSED, const char *e evas_object_geometry_get(ec->cropper, &cx, &cy, &cw, &ch); ny = my - ec->starty; - ec->starty += ny; + ec->starty = my; + + msg = alloca(sizeof(Edje_Message_Int_Set) + (3*sizeof(int))); + msg->count = 3; if (!strcmp(source, "handle2")) - ch -= ny; + msg->val[0] = 2; else if (!strcmp(source, "handle6")) - ch += ny; - - msg = alloca(sizeof(Edje_Message_Int_Set) + (4*sizeof(int))); - msg->count = 4; - msg->val[0] = 0; - msg->val[1] = ny/2; - msg->val[2] = cw; - msg->val[3] = ch; + msg->val[0] = 6; + msg->val[1] = 0; + msg->val[2] = ny; edje_object_message_send(elm_layout_edje_get(ec->layout), EDJE_MESSAGE_INT_SET, 1, msg); } @@ -179,6 +160,7 @@ _cropper_vert_mouse_up(void *data, Evas_Object *obj EINA_UNUSED, const char *emi edje_object_signal_callback_del_full(ec->cropper, "mouse,move", source, _cropper_vert_mouse_move, ec); edje_object_signal_callback_del_full(ec->cropper, "mouse,up,1", source, _cropper_vert_mouse_up, ec); + ec->resizing = 0; } static void @@ -187,14 +169,13 @@ _cropper_resize_vert(void *data, Evas_Object *obj EINA_UNUSED, const char *emiss Ephoto_Cropper *ec = data; int mx, my, cx, cy; + ec->resizing = 1; evas_pointer_canvas_xy_get(evas_object_evas_get(ec->cropper), &mx, &my); evas_object_geometry_get(ec->cropper, &cx, &cy, 0, 0); ec->offsetx = mx - cx; ec->offsety = my - cy; ec->startx = mx; ec->starty = my; - ec->startcx = cx; - ec->startcy = cy; edje_object_signal_callback_add(ec->cropper, "mouse,move", source, _cropper_vert_mouse_move, ec); edje_object_signal_callback_add(ec->cropper, "mouse,up,1", source, _cropper_vert_mouse_up, ec); @@ -205,22 +186,26 @@ static void _cropper_mouse_move(void *data, Evas_Object *obj EINA_UNUSED, const char *emission EINA_UNUSED, const char *source EINA_UNUSED) { Ephoto_Cropper *ec = data; - Edje_Message_Int_Set *msg; - int mx, my, cx, cy, cw, ch; + if (!ec->resizing) + { + Edje_Message_Int_Set *msg; + int mx, my, cx, cy, cw, ch, nx, ny; - evas_pointer_canvas_xy_get(evas_object_evas_get(ec->cropper), &mx, &my); - evas_object_geometry_get(ec->cropper, &cx, &cy, &cw, &ch); + evas_pointer_canvas_xy_get(evas_object_evas_get(ec->cropper), &mx, &my); + evas_object_geometry_get(ec->cropper, &cx, &cy, &cw, &ch); - mx -= ec->offsetx; - my -= ec->offsety; + nx = mx - ec->startx; + ny = my - ec->starty; + ec->startx = mx; + ec->starty = my; - msg = alloca(sizeof(Edje_Message_Int_Set) + (4*sizeof(int))); - msg->count = 4; - msg->val[0] = mx-cx; - msg->val[1] = my-cy; - msg->val[2] = cw; - msg->val[3] = ch; - edje_object_message_send(elm_layout_edje_get(ec->layout), EDJE_MESSAGE_INT_SET, 1, msg); + msg = alloca(sizeof(Edje_Message_Int_Set) + (3*sizeof(int))); + msg->count = 3; + msg->val[0] = 0; + msg->val[1] = nx; + msg->val[2] = ny; + edje_object_message_send(elm_layout_edje_get(ec->layout), EDJE_MESSAGE_INT_SET, 1, msg); + } } static void @@ -244,8 +229,6 @@ _cropper_move(void *data, Evas_Object *obj EINA_UNUSED, const char *emission EIN ec->starty = my; ec->offsetx = mx - cx; ec->offsety = my - cy; - ec->startcx = cx; - ec->startcy = cy; edje_object_signal_callback_add(ec->cropper, "mouse,move", "dragger", _cropper_mouse_move, ec); edje_object_signal_callback_add(ec->cropper, "mouse,up,1", "dragger", _cropper_mouse_up, ec); @@ -284,7 +267,7 @@ _image_resize(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, voi msg->val[1] = 0; msg->val[2] = cw; msg->val[3] = ch; - 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); } else { @@ -335,7 +318,7 @@ _image_resize(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, voi msg->val[1] = 0; msg->val[2] = cw; msg->val[3] = ch; - 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); } } @@ -350,6 +333,7 @@ Evas_Object * ephoto_cropper_add(Evas_Object *parent, const char *file, const char *key) { Ephoto_Cropper *ec = calloc(1, sizeof(Ephoto_Cropper)); + ec->resizing = 0; ec->box = elm_box_add(parent); evas_object_size_hint_weight_set(ec->box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); @@ -392,4 +376,3 @@ ephoto_cropper_add(Evas_Object *parent, const char *file, const char *key) return ec->box; } -