tests/elm: add util function for dragging the pointer in an arc

useful for throwing in non-linear drags

Reviewed-by: Cedric BAIL <cedric.bail@free.fr>
Differential Revision: https://phab.enlightenment.org/D11054
This commit is contained in:
Mike Blumenkrantz 2020-01-08 14:40:18 -05:00 committed by Marcel Hollerbach
parent f1bbd2bcab
commit 6e685e61c7
2 changed files with 30 additions and 0 deletions

View File

@ -620,3 +620,31 @@ drag_object(Eo *obj, int x, int y, int dx, int dy, Eina_Bool iterate)
evas_event_feed_mouse_move(e, x + dx, y + dy, ts++, NULL);
evas_event_feed_mouse_up(e, 1, 0, ts++, NULL);
}
int
drag_object_around(Eo *obj, int cx, int cy, int radius, int degrees)
{
Evas *e = evas_object_evas_get(obj);
/* clamp num mouse moves to a vaguely sane value */
int i, num = MIN(degrees, DRAG_OBJECT_AROUND_NUM_MOVES);
int last_x = round(cx + radius);
int last_y = round(cy);
/* start at 0 degrees */
evas_event_feed_mouse_move(e, last_x, last_y, ts++, NULL);
evas_event_feed_mouse_down(e, 1, 0, ts++, NULL);
for (i = 1; i < num; i++)
{
/* x = cx + r * cos(a), y = cy + r * sin(a) */
int ax, ay;
/* each iteration is 1 degree */
double angle = (i * (degrees / DRAG_OBJECT_AROUND_NUM_MOVES)) * M_PI / 180.0;
ax = round(cx + radius * cos(angle));
ay = round(cy + radius * sin(angle));
if ((ax == last_x) && (ay == last_y)) continue;
evas_event_feed_mouse_move(e, ax, ay, ts++, NULL);
last_x = ax, last_y = ay;
}
evas_event_feed_mouse_up(e, 1, 0, ts++, NULL);
/* only count arc motion: subtract initial move, mouse down, mouse up */
return num;
}

View File

@ -4,6 +4,7 @@
#include <Evas.h>
#define DRAG_OBJECT_NUM_MOVES 4
#define DRAG_OBJECT_AROUND_NUM_MOVES 60
int suite_setup(Eina_Bool legacy);
void _elm2_suite_init(void);
@ -23,6 +24,7 @@ void click_part_flags(Eo *obj, const char *part, int flags);
void click_object_at(Eo *obj, int x, int y);
void click_object_at_flags(Eo *obj, int x, int y, int flags);
void drag_object(Eo *obj, int x, int y, int dx, int dy, Eina_Bool iterate);
int drag_object_around(Eo *obj, int cx, int cy, int radius, int degrees);
void wheel_object(Eo *obj, Eina_Bool horiz, Eina_Bool down);
void wheel_part(Eo *obj, const char *part, Eina_Bool horiz, Eina_Bool down);
void wheel_object_at(Eo *obj, int x, int y, Eina_Bool horiz, Eina_Bool down);