Input: Convert rescaleValuatorAxis to double

Instead of passing fractional pointers around everywhere, just pass
doubles instead.  Much easier.

Signed-off-by: Daniel Stone <daniel@fooishbar.org>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
Daniel Stone 2011-03-02 16:49:53 +00:00 committed by Peter Hutterer
parent 5680fa41ea
commit 4c364a312d

View File

@ -259,39 +259,29 @@ CreateClassesChangedEvent(InternalEvent* event,
/** /**
* Rescale the coord between the two axis ranges. * Rescale the coord between the two axis ranges.
*/ */
static int static double
rescaleValuatorAxis(int coord, float remainder, float *remainder_return, AxisInfoPtr from, AxisInfoPtr to, rescaleValuatorAxis(double coord, AxisInfoPtr from, AxisInfoPtr to,
int defmax) double defmax)
{ {
int fmin = 0, tmin = 0, fmax = defmax, tmax = defmax, coord_return; double fmin = 0.0, fmax = defmax;
float value; double tmin = 0.0, tmax = defmax;
if(from && from->min_value < from->max_value) { if (from && from->min_value < from->max_value) {
fmin = from->min_value; fmin = from->min_value;
fmax = from->max_value; fmax = from->max_value;
} }
if(to && to->min_value < to->max_value) { if (to && to->min_value < to->max_value) {
tmin = to->min_value; tmin = to->min_value;
tmax = to->max_value; tmax = to->max_value;
} }
if(fmin == tmin && fmax == tmax) { if (fmin == tmin && fmax == tmax)
if (remainder_return)
*remainder_return = remainder;
return coord; return coord;
}
if(fmax == fmin) { /* avoid division by 0 */ if (fmax == fmin) /* avoid division by 0 */
if (remainder_return) return 0.0;
*remainder_return = 0.0;
return 0;
}
value = (coord + remainder - fmin) * (tmax - tmin) / (fmax - fmin) + tmin; return (coord - fmin) * (tmax - tmin) / (fmax - fmin) + tmin;
coord_return = lroundf(value);
if (remainder_return)
*remainder_return = value - coord_return;
return coord_return;
} }
/** /**
@ -307,6 +297,7 @@ updateSlaveDeviceCoords(DeviceIntPtr master, DeviceIntPtr pDev)
{ {
ScreenPtr scr = miPointerGetScreen(pDev); ScreenPtr scr = miPointerGetScreen(pDev);
int i; int i;
double val, ret;
DeviceIntPtr lastSlave; DeviceIntPtr lastSlave;
/* master->last.valuators[0]/[1] is in screen coords and the actual /* master->last.valuators[0]/[1] is in screen coords and the actual
@ -321,11 +312,21 @@ updateSlaveDeviceCoords(DeviceIntPtr master, DeviceIntPtr pDev)
/* scale back to device coordinates */ /* scale back to device coordinates */
if(pDev->valuator->numAxes > 0) if(pDev->valuator->numAxes > 0)
pDev->last.valuators[0] = rescaleValuatorAxis(pDev->last.valuators[0], pDev->last.remainder[0], {
&pDev->last.remainder[0], NULL, pDev->valuator->axes + 0, scr->width); val = pDev->last.valuators[0] + pDev->last.remainder[0];
ret = rescaleValuatorAxis(val, NULL, pDev->valuator->axes + 0,
scr->width);
pDev->last.valuators[0] = trunc(ret);
pDev->last.remainder[0] = ret - trunc(ret);
}
if(pDev->valuator->numAxes > 1) if(pDev->valuator->numAxes > 1)
pDev->last.valuators[1] = rescaleValuatorAxis(pDev->last.valuators[1], pDev->last.remainder[1], {
&pDev->last.remainder[1], NULL, pDev->valuator->axes + 1, scr->height); val = pDev->last.valuators[1] + pDev->last.remainder[1];
ret = rescaleValuatorAxis(val, NULL, pDev->valuator->axes + 1,
scr->height);
pDev->last.valuators[1] = trunc(ret);
pDev->last.remainder[1] = ret - trunc(ret);
}
/* calculate the other axis as well based on info from the old /* calculate the other axis as well based on info from the old
* slave-device. If the old slave had less axes than this one, * slave-device. If the old slave had less axes than this one,
@ -340,12 +341,11 @@ updateSlaveDeviceCoords(DeviceIntPtr master, DeviceIntPtr pDev)
} }
else else
{ {
pDev->last.valuators[i] = val = pDev->last.valuators[i] + pDev->last.remainder[i];
rescaleValuatorAxis(pDev->last.valuators[i], ret = rescaleValuatorAxis(val, lastSlave->valuator->axes + i,
pDev->last.remainder[i], pDev->valuator->axes + i, 0);
&pDev->last.remainder[i], pDev->last.valuators[i] = trunc(ret);
lastSlave->valuator->axes + i, pDev->last.remainder[i] = ret - trunc(ret);
pDev->valuator->axes + i, 0);
} }
} }
} }
@ -456,7 +456,7 @@ GetMotionHistory(DeviceIntPtr pDev, xTimecoord **buff, unsigned long start,
/* scale to screen coords */ /* scale to screen coords */
to = &core_axis; to = &core_axis;
to->max_value = pScreen->width; to->max_value = pScreen->width;
coord = rescaleValuatorAxis(coord, 0.0, NULL, &from, to, pScreen->width); coord = rescaleValuatorAxis(coord, &from, to, pScreen->width);
memcpy(corebuf, &coord, sizeof(INT16)); memcpy(corebuf, &coord, sizeof(INT16));
corebuf++; corebuf++;
@ -467,7 +467,7 @@ GetMotionHistory(DeviceIntPtr pDev, xTimecoord **buff, unsigned long start,
memcpy(&coord, icbuf++, sizeof(INT32)); memcpy(&coord, icbuf++, sizeof(INT32));
to->max_value = pScreen->height; to->max_value = pScreen->height;
coord = rescaleValuatorAxis(coord, 0.0, NULL, &from, to, pScreen->height); coord = rescaleValuatorAxis(coord, &from, to, pScreen->height);
memcpy(corebuf, &coord, sizeof(INT16)); memcpy(corebuf, &coord, sizeof(INT16));
} else if (IsMaster(pDev)) } else if (IsMaster(pDev))
@ -495,7 +495,7 @@ GetMotionHistory(DeviceIntPtr pDev, xTimecoord **buff, unsigned long start,
from.max_value = pScreen->height; from.max_value = pScreen->height;
/* scale from stored range into current range */ /* scale from stored range into current range */
coord = rescaleValuatorAxis(coord, 0.0, NULL, &from, to, 0); coord = rescaleValuatorAxis(coord, &from, to, 0);
memcpy(ocbuf, &coord, sizeof(INT32)); memcpy(ocbuf, &coord, sizeof(INT32));
ocbuf++; ocbuf++;
} }
@ -790,19 +790,26 @@ positionSprite(DeviceIntPtr dev, int mode,
ScreenPtr scr, int *screenx, int *screeny, float *screenx_frac, float *screeny_frac) ScreenPtr scr, int *screenx, int *screeny, float *screenx_frac, float *screeny_frac)
{ {
int old_screenx, old_screeny; int old_screenx, old_screeny;
double val, ret;
/* scale x&y to screen */ /* scale x&y to screen */
if (dev->valuator && dev->valuator->numAxes > 0) { if (dev->valuator && dev->valuator->numAxes > 0) {
*screenx = rescaleValuatorAxis(*x, x_frac, screenx_frac, val = *x + x_frac;
dev->valuator->axes + 0, NULL, scr->width); ret = rescaleValuatorAxis(val, dev->valuator->axes + 0, NULL,
scr->width);
*screenx = trunc(ret);
*screenx_frac = ret - trunc(ret);
} else { } else {
*screenx = dev->last.valuators[0]; *screenx = dev->last.valuators[0];
*screenx_frac = dev->last.remainder[0]; *screenx_frac = dev->last.remainder[0];
} }
if (dev->valuator && dev->valuator->numAxes > 1) { if (dev->valuator && dev->valuator->numAxes > 1) {
*screeny = rescaleValuatorAxis(*y, y_frac, screeny_frac, val = *y + y_frac;
dev->valuator->axes + 1, NULL, scr->height); ret = rescaleValuatorAxis(val, dev->valuator->axes + 1, NULL,
scr->height);
*screeny = trunc(ret);
*screeny_frac = ret - trunc(ret);
} else { } else {
*screeny = dev->last.valuators[1]; *screeny = dev->last.valuators[1];
*screeny_frac = dev->last.remainder[1]; *screeny_frac = dev->last.remainder[1];
@ -841,14 +848,20 @@ positionSprite(DeviceIntPtr dev, int mode,
if(*screenx != old_screenx) if(*screenx != old_screenx)
{ {
scr = miPointerGetScreen(dev); scr = miPointerGetScreen(dev);
*x = rescaleValuatorAxis(*screenx, *screenx_frac, &x_frac, NULL, val = *screenx + *screenx_frac;
dev->valuator->axes + 0, scr->width); ret = rescaleValuatorAxis(val, NULL, dev->valuator->axes + 0,
scr->width);
*x = trunc(ret);
x_frac = ret - trunc(ret);
} }
if(*screeny != old_screeny) if(*screeny != old_screeny)
{ {
scr = miPointerGetScreen(dev); scr = miPointerGetScreen(dev);
*y = rescaleValuatorAxis(*screeny, *screeny_frac, &y_frac, NULL, val = *screeny + *screeny_frac;
dev->valuator->axes + 1, scr->height); ret = rescaleValuatorAxis(val, NULL, dev->valuator->axes + 1,
scr->height);
*y = trunc(ret);
y_frac = ret - trunc(ret);
} }
} }
@ -1155,19 +1168,17 @@ GetPointerEvents(InternalEvent *events, DeviceIntPtr pDev, int type, int buttons
if (valuator_mask_isset(&mask, 0)) if (valuator_mask_isset(&mask, 0))
{ {
scaled = rescaleValuatorAxis(valuator_mask_get(&mask, 0), scaled = rescaleValuatorAxis(valuator_mask_get_double(&mask, 0),
0.0, &x_frac, NULL, NULL, pDev->valuator->axes + 0,
pDev->valuator->axes + 0,
scr->width); scr->width);
valuator_mask_set(&mask, 0, scaled); valuator_mask_set_double(&mask, 0, scaled);
} }
if (valuator_mask_isset(&mask, 1)) if (valuator_mask_isset(&mask, 1))
{ {
scaled = rescaleValuatorAxis(valuator_mask_get(&mask, 1), scaled = rescaleValuatorAxis(valuator_mask_get_double(&mask, 1),
0.0, &y_frac, NULL, NULL, pDev->valuator->axes + 1,
pDev->valuator->axes + 1,
scr->height); scr->height);
valuator_mask_set(&mask, 1, scaled); valuator_mask_set_double(&mask, 1, scaled);
} }
} }