Evas events: Store position as double only

This splits pixel and subpixel precision by using
different methods rather than two different storage values.
This commit is contained in:
Jean-Philippe Andre 2016-05-31 12:15:25 +09:00
parent 02716d03c8
commit 4381d3a824
6 changed files with 81 additions and 63 deletions

View File

@ -4291,27 +4291,24 @@ ecore_evas_psl1ght_new(const char* name, int w, int h)
* 3. let evas send legacy & eo events to the objects
*/
#define EVENT_XY_SET(EV, X, Y, MX, MY, FX, FY) do { \
EV->cur.x = (X) - (FX); EV->cur.xsub = (MX) - (FX); \
EV->cur.y = (Y) - (FY); EV->cur.ysub = (MY) - (FY); \
#define EVENT_XY_SET(EV, MX, MY, FX, FY) do { \
EV->cur.x = (MX) - (FX); EV->cur.y = (MY) - (FY); \
} while (0)
static inline void
_pointer_position_set(Efl_Pointer_Event_Data *ev, Ecore_Evas *ee, int x, int y, double mx, double my)
_pointer_position_set(Efl_Pointer_Event_Data *ev, Ecore_Evas *ee, double mx, double my)
{
int fx, fy, fw, fh;
evas_output_framespace_get(ee->evas, &fx, &fy, &fw, &fh);
if (ee->rotation == 0)
EVENT_XY_SET(ev, x, y, mx, my, fx, fy);
EVENT_XY_SET(ev, mx, my, fx, fy);
else if (ee->rotation == 90)
EVENT_XY_SET(ev, ee->h + fw - y - 1, x, ee->h + fw - my - 1, mx, fx, fy);
EVENT_XY_SET(ev, ee->h + fw - my - 1, mx, fx, fy);
else if (ee->rotation == 180)
EVENT_XY_SET(ev, ee->w + fw - x - 1, ee->h + fh - y - 1,
ee->w + fw - mx - 1, ee->h + fh - my - 1,
fx, fy);
EVENT_XY_SET(ev, ee->w + fw - mx - 1, ee->h + fh - my - 1, fx, fy);
else if (ee->rotation == 270)
EVENT_XY_SET(ev, y, ee->w + fh - x - 1, y, ee->w + fh - mx - 1, fx, fy);
EVENT_XY_SET(ev, my, ee->w + fh - mx - 1, fx, fy);
}
static const Eo_Event_Description *
@ -4363,7 +4360,7 @@ _direct_mouse_updown(Ecore_Evas *ee, const Ecore_Event_Mouse_Button *info, Efl_P
if (info->triple_click) ev->button_flags |= EFL_POINTER_BUTTON_FLAGS_TRIPLE_CLICK;
ev->timestamp = info->timestamp;
ev->finger = info->multi.device;
_pointer_position_set(ev, ee, info->x, info->y, info->multi.x, info->multi.y);
_pointer_position_set(ev, ee, info->multi.x, info->multi.y);
ev->radius = info->multi.radius;
ev->radius_x = info->multi.radius_x;
ev->radius_y = info->multi.radius_y;
@ -4418,7 +4415,7 @@ _direct_mouse_move_cb(Ecore_Evas *ee, const Ecore_Event_Mouse_Move *info)
ev->action = EFL_POINTER_ACTION_MOVE;
ev->timestamp = info->timestamp;
ev->finger = info->multi.device;
_pointer_position_set(ev, ee, info->x, info->y, info->multi.x, info->multi.y);
_pointer_position_set(ev, ee, info->multi.x, info->multi.y);
ev->radius = info->multi.radius;
ev->radius_x = info->multi.radius_x;
@ -4454,7 +4451,7 @@ _direct_mouse_wheel_cb(Ecore_Evas *ee, const Ecore_Event_Mouse_Wheel *info)
ev->action = EFL_POINTER_ACTION_WHEEL;
ev->timestamp = info->timestamp;
_pointer_position_set(ev, ee, info->x, info->y, info->x, info->y);
_pointer_position_set(ev, ee, info->x, info->y);
ev->wheel.z = info->z;
ev->wheel.dir = info->direction ? EFL_ORIENT_HORIZONTAL : EFL_ORIENT_VERTICAL;
@ -4483,7 +4480,7 @@ _direct_mouse_inout(Ecore_Evas *ee, const Ecore_Event_Mouse_IO *info, Efl_Pointe
ev->action = action;
ev->timestamp = info->timestamp;
_pointer_position_set(ev, ee, info->x, info->y, info->x, info->y);
_pointer_position_set(ev, ee, info->x, info->y);
eo_event_callback_call(e, _event_description_get(ev->action), evt);
processed = ev->evas_done;

View File

@ -33,8 +33,7 @@ struct _Efl_Pointer_Event_Data
double pressure;
double angle;
struct {
int x, y;
double xsub, ysub; // couldn't we just cast from double to int?
double x, y;
} cur, prev;
struct {
Efl_Orient dir;

View File

@ -151,32 +151,56 @@ _efl_pointer_event_button_pressed_get(Eo *obj EINA_UNUSED, Efl_Pointer_Event_Dat
}
EOLIAN static void
_efl_pointer_event_position_set(Eo *obj EINA_UNUSED, Efl_Pointer_Event_Data *pd, int x, int y, double xsub, double ysub)
_efl_pointer_event_position_set(Eo *obj EINA_UNUSED, Efl_Pointer_Event_Data *pd, int x, int y)
{
pd->cur.x = x;
pd->cur.y = y;
pd->cur.xsub = xsub;
pd->cur.ysub = ysub;
pd->cur.x = (double) x;
pd->cur.y = (double) y;
}
EOLIAN static void
_efl_pointer_event_position_get(Eo *obj EINA_UNUSED, Efl_Pointer_Event_Data *pd, int *x, int *y, double *xsub, double *ysub)
_efl_pointer_event_position_get(Eo *obj EINA_UNUSED, Efl_Pointer_Event_Data *pd, int *x, int *y)
{
if (x) *x = (int) pd->cur.x;
if (y) *y = (int) pd->cur.y;
}
EOLIAN static void
_efl_pointer_event_position_precise_set(Eo *obj EINA_UNUSED, Efl_Pointer_Event_Data *pd, double x, double y)
{
pd->cur.x = x;
pd->cur.y = y;
}
EOLIAN static void
_efl_pointer_event_position_precise_get(Eo *obj EINA_UNUSED, Efl_Pointer_Event_Data *pd, double *x, double *y)
{
if (x) *x = pd->cur.x;
if (y) *y = pd->cur.y;
if (xsub) *xsub = pd->cur.xsub;
if (ysub) *ysub = pd->cur.ysub;
}
EOLIAN static void
_efl_pointer_event_previous_position_set(Eo *obj EINA_UNUSED, Efl_Pointer_Event_Data *pd, int x, int y)
{
pd->prev.x = (double) x;
pd->prev.y = (double) y;
}
EOLIAN static void
_efl_pointer_event_previous_position_get(Eo *obj EINA_UNUSED, Efl_Pointer_Event_Data *pd, int *x, int *y)
{
if (x) *x = (int) pd->prev.x;
if (y) *y = (int) pd->prev.y;
}
EOLIAN static void
_efl_pointer_event_previous_position_precise_set(Eo *obj EINA_UNUSED, Efl_Pointer_Event_Data *pd, double x, double y)
{
pd->prev.x = x;
pd->prev.y = y;
}
EOLIAN static void
_efl_pointer_event_previous_position_get(Eo *obj EINA_UNUSED, Efl_Pointer_Event_Data *pd, int *x, int *y)
_efl_pointer_event_previous_position_precise_get(Eo *obj EINA_UNUSED, Efl_Pointer_Event_Data *pd, double *x, double *y)
{
if (x) *x = pd->prev.x;
if (y) *y = pd->prev.y;

View File

@ -29,14 +29,21 @@ class Efl.Pointer.Event (Eo.Base, Efl.Event, Efl.Input.State)
pressed: bool;
}
}
/* FIXME: output vs. canvas position??? */
@property position {
[[Position where the event happened, relative to the window.]]
values {
x: int;
y: int;
xsub: double;
ysub: double;
}
}
@property position_precise {
[[Position where the event happened, with subpixel precision
Note: Same value as @.position, relative to the window.
]]
values {
x: double;
y: double;
}
}
@property previous_position {
@ -49,6 +56,17 @@ class Efl.Pointer.Event (Eo.Base, Efl.Event, Efl.Input.State)
y: int;
}
}
@property previous_position_precise {
[[Position of the previous event, with subpixel precision.
Valid for move events, may not be valid for other events.
Relative to the window. May be equal to @.position_precise.
]]
values {
x: double;
y: double;
}
}
@property device {
[[Pointing device that originated this event.]]
values {

View File

@ -3207,7 +3207,7 @@ _evas_canvas_event_pointer_cb(void *data, const Eo_Event *event)
_canvas_event_feed_multi_move_internal(eo_e, e, ev->finger, ev->cur.x, ev->cur.y,
ev->radius, ev->radius_x, ev->radius_y,
ev->pressure, ev->angle,
ev->cur.xsub, ev->cur.ysub,
ev->cur.x, ev->cur.y,
ev->timestamp, ev->data, ev);
}
break;
@ -3222,7 +3222,7 @@ _evas_canvas_event_pointer_cb(void *data, const Eo_Event *event)
_canvas_event_feed_multi_down_internal(eo_e, e, ev->finger, ev->cur.x, ev->cur.y,
ev->radius, ev->radius_x, ev->radius_y,
ev->pressure, ev->angle,
ev->cur.xsub, ev->cur.ysub, ev->button_flags,
ev->cur.x, ev->cur.y, ev->button_flags,
ev->timestamp, ev->data, ev);
}
break;
@ -3237,7 +3237,7 @@ _evas_canvas_event_pointer_cb(void *data, const Eo_Event *event)
_canvas_event_feed_multi_up_internal(eo_e, e, ev->finger, ev->cur.x, ev->cur.y,
ev->radius, ev->radius_x, ev->radius_y,
ev->pressure, ev->angle,
ev->cur.xsub, ev->cur.ysub, ev->button_flags,
ev->cur.x, ev->cur.y, ev->button_flags,
ev->timestamp, ev->data, ev);
}
break;

View File

@ -30,8 +30,6 @@ efl_pointer_event_legacy_info_set(Efl_Pointer_Event *evt, const void *event_info
ev->action = EFL_POINTER_ACTION_IN;
ev->cur.x = e->canvas.x;
ev->cur.y = e->canvas.y;
ev->cur.xsub = e->canvas.x;
ev->cur.ysub = e->canvas.y;
ev->data = e->data;
ev->timestamp = e->timestamp;
ev->event_flags = e->event_flags;
@ -49,8 +47,6 @@ efl_pointer_event_legacy_info_set(Efl_Pointer_Event *evt, const void *event_info
ev->action = EFL_POINTER_ACTION_OUT;
ev->cur.x = e->canvas.x;
ev->cur.y = e->canvas.y;
ev->cur.xsub = e->canvas.x;
ev->cur.ysub = e->canvas.y;
ev->data = e->data;
ev->timestamp = e->timestamp;
ev->event_flags = e->event_flags;
@ -69,8 +65,6 @@ efl_pointer_event_legacy_info_set(Efl_Pointer_Event *evt, const void *event_info
ev->button = e->button;
ev->cur.x = e->canvas.x;
ev->cur.y = e->canvas.y;
ev->cur.xsub = e->canvas.x;
ev->cur.ysub = e->canvas.y;
ev->data = e->data;
ev->button_flags = e->flags;
ev->timestamp = e->timestamp;
@ -90,8 +84,6 @@ efl_pointer_event_legacy_info_set(Efl_Pointer_Event *evt, const void *event_info
ev->button = e->button;
ev->cur.x = e->canvas.x;
ev->cur.y = e->canvas.y;
ev->cur.xsub = e->canvas.x;
ev->cur.ysub = e->canvas.y;
ev->data = e->data;
ev->button_flags = e->flags;
ev->timestamp = e->timestamp;
@ -111,12 +103,8 @@ efl_pointer_event_legacy_info_set(Efl_Pointer_Event *evt, const void *event_info
ev->pressed_buttons = e->buttons;
ev->cur.x = e->cur.canvas.x;
ev->cur.y = e->cur.canvas.y;
ev->cur.xsub = e->cur.canvas.x;
ev->cur.ysub = e->cur.canvas.y;
ev->prev.x = e->prev.canvas.x;
ev->prev.y = e->prev.canvas.y;
ev->prev.xsub = e->prev.canvas.x;
ev->prev.ysub = e->prev.canvas.y;
ev->data = e->data;
ev->timestamp = e->timestamp;
ev->event_flags = e->event_flags;
@ -136,8 +124,6 @@ efl_pointer_event_legacy_info_set(Efl_Pointer_Event *evt, const void *event_info
ev->wheel.z = e->z;
ev->cur.x = e->canvas.x;
ev->cur.y = e->canvas.y;
ev->cur.xsub = e->canvas.x;
ev->cur.ysub = e->canvas.y;
ev->data = e->data;
ev->timestamp = e->timestamp;
ev->event_flags = e->event_flags;
@ -158,10 +144,8 @@ efl_pointer_event_legacy_info_set(Efl_Pointer_Event *evt, const void *event_info
ev->radius_y = e->radius_y;
ev->pressure = e->pressure;
ev->angle = e->angle;
ev->cur.x = e->canvas.x;
ev->cur.y = e->canvas.y;
ev->cur.xsub = e->canvas.xsub;
ev->cur.ysub = e->canvas.ysub;
ev->cur.x = e->canvas.xsub;
ev->cur.y = e->canvas.ysub;
ev->data = e->data;
ev->button_flags = e->flags;
ev->timestamp = e->timestamp;
@ -183,10 +167,8 @@ efl_pointer_event_legacy_info_set(Efl_Pointer_Event *evt, const void *event_info
ev->radius_y = e->radius_y;
ev->pressure = e->pressure;
ev->angle = e->angle;
ev->cur.x = e->canvas.x;
ev->cur.y = e->canvas.y;
ev->cur.xsub = e->canvas.xsub;
ev->cur.ysub = e->canvas.ysub;
ev->cur.x = e->canvas.xsub;
ev->cur.y = e->canvas.ysub;
ev->data = e->data;
ev->button_flags = e->flags;
ev->timestamp = e->timestamp;
@ -208,10 +190,8 @@ efl_pointer_event_legacy_info_set(Efl_Pointer_Event *evt, const void *event_info
ev->radius_y = e->radius_y;
ev->pressure = e->pressure;
ev->angle = e->angle;
ev->cur.x = e->cur.canvas.x;
ev->cur.y = e->cur.canvas.y;
ev->cur.xsub = e->cur.canvas.xsub;
ev->cur.ysub = e->cur.canvas.ysub;
ev->cur.x = e->cur.canvas.xsub;
ev->cur.y = e->cur.canvas.ysub;
ev->data = e->data;
ev->timestamp = e->timestamp;
ev->event_flags = e->event_flags;
@ -318,8 +298,8 @@ efl_pointer_event_legacy_info_get(const Efl_Pointer_Event *evt, Evas_Callback_Ty
e->angle = ev->angle;
e->canvas.x = ev->cur.x;
e->canvas.y = ev->cur.y;
e->canvas.xsub = ev->cur.xsub;
e->canvas.ysub = ev->cur.ysub;
e->canvas.xsub = ev->cur.x;
e->canvas.ysub = ev->cur.y;
e->output.x = ev->cur.x;
e->output.y = ev->cur.y;
e->data = ev->data;
@ -369,8 +349,8 @@ efl_pointer_event_legacy_info_get(const Efl_Pointer_Event *evt, Evas_Callback_Ty
e->angle = ev->angle;
e->canvas.x = ev->cur.x;
e->canvas.y = ev->cur.y;
e->canvas.xsub = ev->cur.xsub;
e->canvas.ysub = ev->cur.ysub;
e->canvas.xsub = ev->cur.x;
e->canvas.ysub = ev->cur.y;
e->output.x = ev->cur.x;
e->output.y = ev->cur.y;
e->data = ev->data;
@ -424,8 +404,8 @@ efl_pointer_event_legacy_info_get(const Efl_Pointer_Event *evt, Evas_Callback_Ty
e->angle = ev->angle;
e->cur.canvas.x = ev->cur.x;
e->cur.canvas.y = ev->cur.y;
e->cur.canvas.xsub = ev->cur.xsub;
e->cur.canvas.ysub = ev->cur.ysub;
e->cur.canvas.xsub = ev->cur.x;
e->cur.canvas.ysub = ev->cur.y;
e->cur.output.x = ev->cur.x;
e->cur.output.y = ev->cur.y;
e->data = ev->data;