コード例 #1
0
static void handlePOVChange(struct Gamepad_device * device, DWORD lastValue, DWORD value) {
	struct Gamepad_devicePrivate * devicePrivate;
	int lastX, lastY, newX, newY;
	
	devicePrivate = device->privateData;
	
	if (devicePrivate->povXAxisIndex == -1 || devicePrivate->povYAxisIndex == -1) {
		return;
	}
	
	povToXY(lastValue, &lastX, &lastY);
	povToXY(value, &newX, &newY);
	
	if (newX != lastX) {
		device->axisStates[devicePrivate->povXAxisIndex] = newX;
		if (Gamepad_axisMoveCallback != NULL) {
			Gamepad_axisMoveCallback(device, devicePrivate->povXAxisIndex, newX, lastX, currentTime(), Gamepad_axisMoveContext);
		}
	}
	if (newY != lastY) {
		device->axisStates[devicePrivate->povYAxisIndex] = newY;
		if (Gamepad_axisMoveCallback != NULL) {
			Gamepad_axisMoveCallback(device, devicePrivate->povYAxisIndex, newY, lastY, currentTime(), Gamepad_axisMoveContext);
		}
	}
}
コード例 #2
0
static void handleAxisChange(struct Gamepad_device * device, int axisIndex, DWORD ivalue) {
	float value, lastValue;
	struct Gamepad_devicePrivate * devicePrivate;
	
	if (axisIndex < 0 || axisIndex >= (int) device->numAxes) {
		return;
	}
	
	devicePrivate = device->privateData;
	value = (ivalue - devicePrivate->axisRanges[axisIndex][0]) / (float) (devicePrivate->axisRanges[axisIndex][1] - devicePrivate->axisRanges[axisIndex][0]) * 2.0f - 1.0f;
	
	lastValue = device->axisStates[axisIndex];
	device->axisStates[axisIndex] = value;
	if (Gamepad_axisMoveCallback != NULL) {
		Gamepad_axisMoveCallback(device, axisIndex, value, lastValue, currentTime(), Gamepad_axisMoveContext);
	}
}
コード例 #3
0
static void processQueuedEvent(struct Gamepad_queuedEvent event) {
  switch (event.eventType) {
  case GAMEPAD_EVENT_DEVICE_ATTACHED:
    if (Gamepad_deviceAttachCallback != NULL) {
      Gamepad_deviceAttachCallback(event.eventData, Gamepad_deviceAttachContext);
    }
    break;
			
  case GAMEPAD_EVENT_DEVICE_REMOVED:
    if (Gamepad_deviceRemoveCallback != NULL) {
      Gamepad_deviceRemoveCallback(event.eventData, Gamepad_deviceRemoveContext);
    }
    break;
			
  case GAMEPAD_EVENT_BUTTON_DOWN:
    if (Gamepad_buttonDownCallback != NULL) {
      struct Gamepad_buttonEvent * buttonEvent = event.eventData;
      Gamepad_buttonDownCallback(buttonEvent->device, buttonEvent->buttonID, buttonEvent->timestamp, Gamepad_buttonDownContext);
    }
    break;
			
  case GAMEPAD_EVENT_BUTTON_UP:
    if (Gamepad_buttonUpCallback != NULL) {
      struct Gamepad_buttonEvent * buttonEvent = event.eventData;
      Gamepad_buttonUpCallback(buttonEvent->device, buttonEvent->buttonID, buttonEvent->timestamp, Gamepad_buttonUpContext);
    }
    break;
			
  case GAMEPAD_EVENT_AXIS_MOVED:
    if (Gamepad_axisMoveCallback != NULL) {
      struct Gamepad_axisEvent * axisEvent = event.eventData;
      Gamepad_axisMoveCallback(axisEvent->device, axisEvent->axisID, axisEvent->value, axisEvent->lastValue, axisEvent->timestamp, Gamepad_axisMoveContext);
    }
    break;
  }
}