/** * change the current slot for further screenshot * @param index The target index of the slot * @param closeOld True if need to close previous screenshot; False if you like to preserve * previous screenshot for future need. * @return 0 if success */ public int SetActiveSlot(int index, bool closeOld) { int ret = 0; if (index < 0 || index >= mScreenshotSlotCount) { throw new IndexOutOfRangeException("index " + index + " is not legal"); } Log.D(TAG, "Change screenshot slot from " + mScreenshotCurrentSlot + " to " + index); if (mScreenshotCurrentSlot != index && closeOld) { // close opened screenshot slot, but even if release failed, we don't need to handle it if (mDevice.ScreenshotState(mScreenshotCurrentSlot) == GameDevice.SCREENSHOT_OPENED) { ret = mDevice.ScreenshotClose(mScreenshotCurrentSlot); if (ret != GameDevice.SCREENSHOT_NO_ERROR) { Log.W(TAG, "close screenshot failed: " + ret); } ret = mDevice.ScreenshotRelease(mScreenshotCurrentSlot); if (ret != GameDevice.SCREENSHOT_NO_ERROR) { Log.W(TAG, "release screenshot failed " + ret); } } } mScreenshotCurrentSlot = index; return(ret); }
private int MouseInteract(int x, int y, int tx, int ty, int type) { int ret = 0; Random random = new Random(); int x_shift = (int)(random.NextDouble() * mRandomMouseInputShift) - mRandomMouseInputShift / 2; int y_shift = (int)(random.NextDouble() * mRandomMouseInputShift) - mRandomMouseInputShift / 2; x = x + x_shift; y = y + y_shift; if (mScreenHeight > 0 && y > (mCurrentGameOrientation == ScreenPoint.SO_Portrait ? mScreenHeight : mScreenWidth)) { y = (mCurrentGameOrientation == ScreenPoint.SO_Portrait ? mScreenHeight : mScreenWidth); } else if (y < 0) { y = 0; } if (mScreenWidth > 0 && x > (mCurrentGameOrientation == ScreenPoint.SO_Landscape ? mScreenHeight : mScreenWidth)) { x = (mCurrentGameOrientation == ScreenPoint.SO_Portrait ? mScreenHeight : mScreenWidth); } else if (x < 0) { x = 0; } switch (type) { case GameDevice.MOUSE_TAP: case GameDevice.MOUSE_DOUBLE_TAP: case GameDevice.MOUSE_TRIPLE_TAP: case GameDevice.MOUSE_PRESS: case GameDevice.MOUSE_MOVE_TO: case GameDevice.MOUSE_RELEASE: ret = mDevice.MouseInteract(x, y, type); break; case GameDevice.MOUSE_SWIPE: ret = mDevice.MouseInteract(x, y, tx, ty, type); break; default: Log.W(TAG, "touchOnScreen: type " + type + "is invalid."); break; } return(ret); }
public DeviceInteract(JoshGameLibrary20 gl, GameDevice device) { if (device == null) { throw new Exception("Initial DeviceScreen with null device"); } else { mDevice = device; } Log = mDevice.GetLogger(); int[] resolution = device.GetScreenDimension(); if (resolution == null || resolution.Length != 2) { Log.W(TAG, "Auto detect for device resolution failed, use default 1080x2340. Override this."); mScreenWidth = 1080; mScreenHeight = 2340; } else { mScreenWidth = resolution[0]; mScreenHeight = resolution[1]; } int orientation = device.GetScreenMainOrientation(); if (orientation < 0) { throw new Exception("Device report illegal default screen orientation"); } else { mCurrentGameOrientation = orientation; } }