本文整理汇总了C#中Android.Views.MotionEvent.GetPointerCoords方法的典型用法代码示例。如果您正苦于以下问题:C# MotionEvent.GetPointerCoords方法的具体用法?C# MotionEvent.GetPointerCoords怎么用?C# MotionEvent.GetPointerCoords使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Android.Views.MotionEvent
的用法示例。
在下文中一共展示了MotionEvent.GetPointerCoords方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Display_OnTouchEvent
public bool Display_OnTouchEvent( MotionEvent e )
{
if( e.Action == MotionEventActions.Down
|| e.Action != MotionEventActions.Up ) {
if( !touch_down )
first_down = true;
else
first_down = false;
touch_down = true;
} else {
foreach( EventConsumer consumer in game.EventManager.ConsumerList )
consumer.MouseButtonRelease( MouseButton.Button1, mouse_x, mouse_y );
touch_down = false;
return true; // nothing to compute
}
MotionEvent.PointerCoords coords = new MotionEvent.PointerCoords();
/*
Log.log( "Motion Events {0} on display of {1} {2}", e.PointerCount, Width, Height );
//if( e.EdgeFlags & Edge.Top )
for( int n = 0; n < e.PointerCount; n++ ) {
e.GetPointerCoords( n, coords );
float x = coords.X;
float y = coords.Y;
float p = e.GetPressure( n );
Log.log( "got event at {0},{1} {2}", x, y, p );
}
*/
e.GetPointerCoords( 0, coords );
mouse_x = coords.X * 2.0f / Width - 1;
mouse_y = ( Height - coords.Y ) * 2.0f / Height - 1;
if( first_down ) {
_mouse_x = mouse_x;
_mouse_y = mouse_y;
foreach( EventConsumer consumer in game.EventManager.ConsumerList )
consumer.MouseButtonClick( MouseButton.Button1, mouse_x, mouse_y );
} else {
if( _mouse_x != -2 ) {
del_mouse_x += mouse_x - _mouse_x;
del_mouse_y += mouse_y - _mouse_y;
}
foreach (EventConsumer consumer in game.EventManager.ConsumerList)
consumer.MouseMove( del_mouse_x, del_mouse_y, mouse_x, mouse_y );
if( HiddenMouse ) {
#if !USE_GLES2
System.Windows.Forms.Cursor.Position = new Point( ( X + Width ) / 2, ( Y + Height ) / 2 );
#endif
//_mouse_x = 0;
//_mouse_y = 0;
} else {
//_mouse_x = mouse_x;
//_mouse_y = mouse_y;
}
_mouse_x = mouse_x;
_mouse_y = mouse_y;
}
return true;
}
示例2: OnTouchEvent
public override bool OnTouchEvent(MotionEvent e)
{
MotionEvent.PointerCoords mepc = new MotionEvent.PointerCoords();
int iEventPointerIndex = (int)(e.Action & MotionEventActions.PointerIdMask) >> (int)MotionEventActions.PointerIdShift;
int iEventPointerId = e.GetPointerId(iEventPointerIndex);
MotionEventActions action = e.Action & MotionEventActions.Mask;
switch (action)
{
case MotionEventActions.Down:
case MotionEventActions.PointerDown:
Log.Debug(tag, String.Format("Point Down"));
//DataClass.Drawables[iEventPointerId].Visible = true;
e.GetPointerCoords(iEventPointerIndex, mepc);
bool bFound = false;
foreach (var item in DataClass.Sources)
{
if (item.Collision(mepc.X, mepc.Y))
{
var nc = new Circle(item) { Visible = true };
DataClass.Drawables.Add(nc);
dctControlable.Add(iEventPointerId, nc);
bFound = true;
break;
}
}
if (bFound) break;
foreach (var item in DataClass.Drawables)
{
if (item.Collision(mepc.X, mepc.Y))
{
dctControlable.Add(iEventPointerId, item);
break;
}
}
break;
case MotionEventActions.Move:
var l = new List<string>();
for (int iPointerIndex = 0; iPointerIndex < e.PointerCount; iPointerIndex++)
{
int iPointerId = e.GetPointerId(iPointerIndex);
l.Add(String.Format("{0} => {1}", iPointerIndex, iPointerId));
try
{
e.GetPointerCoords(iPointerIndex, mepc);
dctControlable[iPointerId].X = mepc.X;
dctControlable[iPointerId].Y = mepc.Y;
}
catch
{
l.Add(String.Format("ex", iPointerIndex, iPointerId));
}
}
Log.Debug(tag, string.Format("{0}, {1}", iEventPointerIndex, string.Join(", ", l)));
break;
case MotionEventActions.Up:
case MotionEventActions.PointerUp:
Log.Debug(tag, String.Format("Point Up"));
//DataClass.Drawables[iEventPointerId].Visible = false;
dctControlable.Remove(iEventPointerId);
break;
}
this.Invalidate();
return true;
}
示例3: OnTouchEvent
public override bool OnTouchEvent(MotionEvent e)
{
// Get current position of pointer at index 0.
// This will be the first pointer down and the last pointer up even if not the same
System.Drawing.PointF curr = new System.Drawing.PointF(e.GetX(), e.GetY());
switch (e.Action) {
case MotionEventActions.PointerDown:
pointer2Index = 1;
break;
case MotionEventActions.Down:
// Set the current box and add it to the List<Box> mBoxes
if (mCurrentBox == null) {
mCurrentBox = new Box(curr, e.GetPointerId(0));
mBoxes.Add(mCurrentBox);
}
break;
case MotionEventActions.Pointer2Down:
// Handle 2nd touch. Set the start point of the rotation
if (mRotationStart == null) {
// Get coordinates of pointer 2
MotionEvent.PointerCoords pCoords = new MotionEvent.PointerCoords();
e.GetPointerCoords(1, pCoords);
// Set the starting coordinates for the rotation
mRotationStart = new Box(new System.Drawing.PointF(pCoords.X, pCoords.Y), e.GetPointerId(1));
mInitialRotation = mCurrentBox.Rotation;
pointer2Index = 1;
}
break;
case MotionEventActions.Move:
// Handle first pointer move, set end point for rectangle
if (mCurrentBox != null && mCurrentBox.PointerId == e.GetPointerId(0)) {
mCurrentBox.Current = curr;
}
// Handle second pointer move, set rotation amount
if (mRotationStart != null && mRotationStart.PointerId == e.GetPointerId(pointer2Index)) {
// Get coordinates of pointer 2
MotionEvent.PointerCoords pCoords = new MotionEvent.PointerCoords();
e.GetPointerCoords(pointer2Index, pCoords);
// Set the rotation of the box to the difference between the origin of mRotation and the current position of pointer 2
mCurrentBox.Rotation = mInitialRotation + pCoords.Y - mRotationStart.Origin.Y;
}
Invalidate();
break;
case MotionEventActions.Pointer2Up:
mRotationStart = null;
break;
case MotionEventActions.PointerUp:
pointer2Index = 0;
break;
case MotionEventActions.Up:
mCurrentBox = null;
mRotationStart = null;
break;
case MotionEventActions.Cancel:
mCurrentBox = null;
mRotationStart = null;
break;
}
return true;
}