mirror of
https://github.com/libsdl-org/SDL.git
synced 2026-06-02 15:47:31 +08:00
Added binding mode to testcontroller
This commit is contained in:
+119
-136
@@ -114,9 +114,9 @@ struct GamepadImage
|
|||||||
int x;
|
int x;
|
||||||
int y;
|
int y;
|
||||||
SDL_bool showing_front;
|
SDL_bool showing_front;
|
||||||
SDL_bool showing_battery;
|
|
||||||
SDL_bool showing_touchpad;
|
SDL_bool showing_touchpad;
|
||||||
GamepadImageFaceStyle face_style;
|
GamepadImageFaceStyle face_style;
|
||||||
|
ControllerDisplayMode display_mode;
|
||||||
|
|
||||||
SDL_bool buttons[SDL_GAMEPAD_BUTTON_MAX];
|
SDL_bool buttons[SDL_GAMEPAD_BUTTON_MAX];
|
||||||
int axes[SDL_GAMEPAD_AXIS_MAX];
|
int axes[SDL_GAMEPAD_AXIS_MAX];
|
||||||
@@ -231,57 +231,13 @@ void SetGamepadImageFaceStyle(GamepadImage *ctx, GamepadImageFaceStyle face_styl
|
|||||||
ctx->face_style = face_style;
|
ctx->face_style = face_style;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetGamepadImageShowingBattery(GamepadImage *ctx, SDL_bool showing_battery)
|
void SetGamepadImageDisplayMode(GamepadImage *ctx, ControllerDisplayMode display_mode)
|
||||||
{
|
{
|
||||||
if (!ctx) {
|
if (!ctx) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx->showing_battery = showing_battery;
|
ctx->display_mode = display_mode;
|
||||||
}
|
|
||||||
|
|
||||||
void SetGamepadImageShowingTouchpad(GamepadImage *ctx, SDL_bool showing_touchpad)
|
|
||||||
{
|
|
||||||
if (!ctx) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx->showing_touchpad = showing_touchpad;
|
|
||||||
}
|
|
||||||
|
|
||||||
void GetGamepadImageArea(GamepadImage *ctx, int *x, int *y, int *width, int *height)
|
|
||||||
{
|
|
||||||
if (!ctx) {
|
|
||||||
if (x) {
|
|
||||||
*x = 0;
|
|
||||||
}
|
|
||||||
if (y) {
|
|
||||||
*y = 0;
|
|
||||||
}
|
|
||||||
if (width) {
|
|
||||||
*width = 0;
|
|
||||||
}
|
|
||||||
if (height) {
|
|
||||||
*height = 0;
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (x) {
|
|
||||||
*x = ctx->x;
|
|
||||||
}
|
|
||||||
if (y) {
|
|
||||||
*y = ctx->y;
|
|
||||||
}
|
|
||||||
if (width) {
|
|
||||||
*width = ctx->gamepad_width;
|
|
||||||
}
|
|
||||||
if (height) {
|
|
||||||
*height = ctx->gamepad_height;
|
|
||||||
if (ctx->showing_touchpad) {
|
|
||||||
*height += ctx->touchpad_height;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int GetGamepadImageButtonWidth(GamepadImage *ctx)
|
int GetGamepadImageButtonWidth(GamepadImage *ctx)
|
||||||
@@ -482,12 +438,14 @@ void UpdateGamepadImageFromGamepad(GamepadImage *ctx, SDL_Gamepad *gamepad)
|
|||||||
|
|
||||||
SDL_GetGamepadTouchpadFinger(gamepad, 0, i, &finger->state, &finger->x, &finger->y, &finger->pressure);
|
SDL_GetGamepadTouchpadFinger(gamepad, 0, i, &finger->state, &finger->x, &finger->y, &finger->pressure);
|
||||||
}
|
}
|
||||||
|
ctx->showing_touchpad = SDL_TRUE;
|
||||||
} else {
|
} else {
|
||||||
if (ctx->fingers) {
|
if (ctx->fingers) {
|
||||||
SDL_free(ctx->fingers);
|
SDL_free(ctx->fingers);
|
||||||
ctx->fingers = NULL;
|
ctx->fingers = NULL;
|
||||||
ctx->num_fingers = 0;
|
ctx->num_fingers = 0;
|
||||||
}
|
}
|
||||||
|
ctx->showing_touchpad = SDL_FALSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -568,7 +526,7 @@ void RenderGamepadImage(GamepadImage *ctx)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ctx->showing_battery) {
|
if (ctx->display_mode == CONTROLLER_MODE_TESTING && ctx->battery_level != SDL_JOYSTICK_POWER_UNKNOWN) {
|
||||||
dst.x = (float)ctx->x + ctx->gamepad_width - ctx->battery_width;
|
dst.x = (float)ctx->x + ctx->gamepad_width - ctx->battery_width;
|
||||||
dst.y = (float)ctx->y;
|
dst.y = (float)ctx->y;
|
||||||
dst.w = (float)ctx->battery_width;
|
dst.w = (float)ctx->battery_width;
|
||||||
@@ -576,7 +534,7 @@ void RenderGamepadImage(GamepadImage *ctx)
|
|||||||
SDL_RenderTexture(ctx->renderer, ctx->battery_texture[1 + ctx->battery_level], NULL, &dst);
|
SDL_RenderTexture(ctx->renderer, ctx->battery_texture[1 + ctx->battery_level], NULL, &dst);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ctx->showing_touchpad) {
|
if (ctx->display_mode == CONTROLLER_MODE_TESTING && ctx->showing_touchpad) {
|
||||||
dst.x = (float)ctx->x + (ctx->gamepad_width - ctx->touchpad_width) / 2;
|
dst.x = (float)ctx->x + (ctx->gamepad_width - ctx->touchpad_width) / 2;
|
||||||
dst.y = (float)ctx->y + ctx->gamepad_height;
|
dst.y = (float)ctx->y + ctx->gamepad_height;
|
||||||
dst.w = (float)ctx->touchpad_width;
|
dst.w = (float)ctx->touchpad_width;
|
||||||
@@ -673,6 +631,8 @@ struct GamepadDisplay
|
|||||||
float gyro_data[3];
|
float gyro_data[3];
|
||||||
Uint64 last_sensor_update;
|
Uint64 last_sensor_update;
|
||||||
|
|
||||||
|
ControllerDisplayMode display_mode;
|
||||||
|
|
||||||
SDL_Rect area;
|
SDL_Rect area;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -691,16 +651,22 @@ GamepadDisplay *CreateGamepadDisplay(SDL_Renderer *renderer)
|
|||||||
return ctx;
|
return ctx;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetGamepadDisplayArea(GamepadDisplay *ctx, int x, int y, int w, int h)
|
void SetGamepadDisplayDisplayMode(GamepadDisplay *ctx, ControllerDisplayMode display_mode)
|
||||||
{
|
{
|
||||||
if (!ctx) {
|
if (!ctx) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx->area.x = x;
|
ctx->display_mode = display_mode;
|
||||||
ctx->area.y = y;
|
}
|
||||||
ctx->area.w = w;
|
|
||||||
ctx->area.h = h;
|
void SetGamepadDisplayArea(GamepadDisplay *ctx, const SDL_Rect *area)
|
||||||
|
{
|
||||||
|
if (!ctx) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
SDL_copyp(&ctx->area, area);
|
||||||
}
|
}
|
||||||
|
|
||||||
static SDL_bool GetBindingString(const char *label, char *mapping, char *text, size_t size)
|
static SDL_bool GetBindingString(const char *label, char *mapping, char *text, size_t size)
|
||||||
@@ -794,7 +760,7 @@ void RenderGamepadDisplay(GamepadDisplay *ctx, SDL_Gamepad *gamepad)
|
|||||||
const float arrow_extent = 48.0f;
|
const float arrow_extent = 48.0f;
|
||||||
SDL_FRect dst, rect;
|
SDL_FRect dst, rect;
|
||||||
Uint8 r, g, b, a;
|
Uint8 r, g, b, a;
|
||||||
char *mapping;
|
char *mapping = NULL;
|
||||||
SDL_bool has_accel;
|
SDL_bool has_accel;
|
||||||
SDL_bool has_gyro;
|
SDL_bool has_gyro;
|
||||||
|
|
||||||
@@ -812,6 +778,11 @@ void RenderGamepadDisplay(GamepadDisplay *ctx, SDL_Gamepad *gamepad)
|
|||||||
for (i = 0; i < SDL_GAMEPAD_BUTTON_MAX; ++i) {
|
for (i = 0; i < SDL_GAMEPAD_BUTTON_MAX; ++i) {
|
||||||
SDL_GamepadButton button = (SDL_GamepadButton)i;
|
SDL_GamepadButton button = (SDL_GamepadButton)i;
|
||||||
|
|
||||||
|
if (ctx->display_mode == CONTROLLER_MODE_TESTING &&
|
||||||
|
!SDL_GamepadHasButton(gamepad, button)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
SDL_snprintf(text, sizeof(text), "%s:", gamepad_button_names[i]);
|
SDL_snprintf(text, sizeof(text), "%s:", gamepad_button_names[i]);
|
||||||
SDLTest_DrawString(ctx->renderer, x + center - SDL_strlen(text) * FONT_CHARACTER_SIZE, y, text);
|
SDLTest_DrawString(ctx->renderer, x + center - SDL_strlen(text) * FONT_CHARACTER_SIZE, y, text);
|
||||||
|
|
||||||
@@ -827,9 +798,11 @@ void RenderGamepadDisplay(GamepadDisplay *ctx, SDL_Gamepad *gamepad)
|
|||||||
dst.h = (float)ctx->button_height;
|
dst.h = (float)ctx->button_height;
|
||||||
SDL_RenderTexture(ctx->renderer, ctx->button_texture, NULL, &dst);
|
SDL_RenderTexture(ctx->renderer, ctx->button_texture, NULL, &dst);
|
||||||
|
|
||||||
if (GetButtonBindingString(button, mapping, binding, sizeof(binding))) {
|
if (ctx->display_mode == CONTROLLER_MODE_BINDING) {
|
||||||
dst.x += dst.w + 2 * margin;
|
if (GetButtonBindingString(button, mapping, binding, sizeof(binding))) {
|
||||||
SDLTest_DrawString(ctx->renderer, dst.x, y, binding);
|
dst.x += dst.w + 2 * margin;
|
||||||
|
SDLTest_DrawString(ctx->renderer, dst.x, y, binding);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
y += ctx->button_height + 2.0f;
|
y += ctx->button_height + 2.0f;
|
||||||
@@ -838,7 +811,14 @@ void RenderGamepadDisplay(GamepadDisplay *ctx, SDL_Gamepad *gamepad)
|
|||||||
for (i = 0; i < SDL_GAMEPAD_AXIS_MAX; ++i) {
|
for (i = 0; i < SDL_GAMEPAD_AXIS_MAX; ++i) {
|
||||||
SDL_GamepadAxis axis = (SDL_GamepadAxis)i;
|
SDL_GamepadAxis axis = (SDL_GamepadAxis)i;
|
||||||
SDL_bool has_negative = (axis != SDL_GAMEPAD_AXIS_LEFT_TRIGGER && axis != SDL_GAMEPAD_AXIS_RIGHT_TRIGGER);
|
SDL_bool has_negative = (axis != SDL_GAMEPAD_AXIS_LEFT_TRIGGER && axis != SDL_GAMEPAD_AXIS_RIGHT_TRIGGER);
|
||||||
Sint16 value = SDL_GetGamepadAxis(gamepad, axis);
|
Sint16 value;
|
||||||
|
|
||||||
|
if (ctx->display_mode == CONTROLLER_MODE_TESTING &&
|
||||||
|
!SDL_GamepadHasAxis(gamepad, axis)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
value = SDL_GetGamepadAxis(gamepad, axis);
|
||||||
|
|
||||||
SDL_snprintf(text, sizeof(text), "%s:", gamepad_axis_names[i]);
|
SDL_snprintf(text, sizeof(text), "%s:", gamepad_axis_names[i]);
|
||||||
SDLTest_DrawString(ctx->renderer, x + center - SDL_strlen(text) * FONT_CHARACTER_SIZE, y, text);
|
SDLTest_DrawString(ctx->renderer, x + center - SDL_strlen(text) * FONT_CHARACTER_SIZE, y, text);
|
||||||
@@ -875,12 +855,14 @@ void RenderGamepadDisplay(GamepadDisplay *ctx, SDL_Gamepad *gamepad)
|
|||||||
SDL_RenderFillRect(ctx->renderer, &rect);
|
SDL_RenderFillRect(ctx->renderer, &rect);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (has_negative && GetAxisBindingString(axis, -1, mapping, binding, sizeof(binding))) {
|
if (ctx->display_mode == CONTROLLER_MODE_BINDING && has_negative) {
|
||||||
float text_x;
|
if (GetAxisBindingString(axis, -1, mapping, binding, sizeof(binding))) {
|
||||||
|
float text_x;
|
||||||
|
|
||||||
SDL_SetRenderDrawColor(ctx->renderer, r, g, b, a);
|
SDL_SetRenderDrawColor(ctx->renderer, r, g, b, a);
|
||||||
text_x = dst.x + arrow_extent / 2 - ((float)FONT_CHARACTER_SIZE * SDL_strlen(binding)) / 2;
|
text_x = dst.x + arrow_extent / 2 - ((float)FONT_CHARACTER_SIZE * SDL_strlen(binding)) / 2;
|
||||||
SDLTest_DrawString(ctx->renderer, text_x, y, binding);
|
SDLTest_DrawString(ctx->renderer, text_x, y, binding);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dst.x += arrow_extent;
|
dst.x += arrow_extent;
|
||||||
@@ -894,12 +876,14 @@ void RenderGamepadDisplay(GamepadDisplay *ctx, SDL_Gamepad *gamepad)
|
|||||||
SDL_RenderFillRect(ctx->renderer, &rect);
|
SDL_RenderFillRect(ctx->renderer, &rect);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (GetAxisBindingString(axis, 1, mapping, binding, sizeof(binding))) {
|
if (ctx->display_mode == CONTROLLER_MODE_BINDING) {
|
||||||
float text_x;
|
if (GetAxisBindingString(axis, 1, mapping, binding, sizeof(binding))) {
|
||||||
|
float text_x;
|
||||||
|
|
||||||
SDL_SetRenderDrawColor(ctx->renderer, r, g, b, a);
|
SDL_SetRenderDrawColor(ctx->renderer, r, g, b, a);
|
||||||
text_x = dst.x + arrow_extent / 2 - ((float)FONT_CHARACTER_SIZE * SDL_strlen(binding)) / 2;
|
text_x = dst.x + arrow_extent / 2 - ((float)FONT_CHARACTER_SIZE * SDL_strlen(binding)) / 2;
|
||||||
SDLTest_DrawString(ctx->renderer, text_x, y, binding);
|
SDLTest_DrawString(ctx->renderer, text_x, y, binding);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dst.x += arrow_extent;
|
dst.x += arrow_extent;
|
||||||
@@ -916,72 +900,74 @@ void RenderGamepadDisplay(GamepadDisplay *ctx, SDL_Gamepad *gamepad)
|
|||||||
y += ctx->button_height + 2;
|
y += ctx->button_height + 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (SDL_GetNumGamepadTouchpads(gamepad) > 0) {
|
if (ctx->display_mode == CONTROLLER_MODE_TESTING) {
|
||||||
int num_fingers = SDL_GetNumGamepadTouchpadFingers(gamepad, 0);
|
if (SDL_GetNumGamepadTouchpads(gamepad) > 0) {
|
||||||
for (i = 0; i < num_fingers; ++i) {
|
int num_fingers = SDL_GetNumGamepadTouchpadFingers(gamepad, 0);
|
||||||
Uint8 state;
|
for (i = 0; i < num_fingers; ++i) {
|
||||||
float finger_x, finger_y, finger_pressure;
|
Uint8 state;
|
||||||
|
float finger_x, finger_y, finger_pressure;
|
||||||
|
|
||||||
if (SDL_GetGamepadTouchpadFinger(gamepad, 0, i, &state, &finger_x, &finger_y, &finger_pressure) < 0) {
|
if (SDL_GetGamepadTouchpadFinger(gamepad, 0, i, &state, &finger_x, &finger_y, &finger_pressure) < 0) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
SDL_snprintf(text, sizeof(text), "Touch finger %d:", i);
|
||||||
|
SDLTest_DrawString(ctx->renderer, x + center - SDL_strlen(text) * FONT_CHARACTER_SIZE, y, text);
|
||||||
|
|
||||||
|
if (state) {
|
||||||
|
SDL_SetTextureColorMod(ctx->button_texture, 10, 255, 21);
|
||||||
|
} else {
|
||||||
|
SDL_SetTextureColorMod(ctx->button_texture, 255, 255, 255);
|
||||||
|
}
|
||||||
|
|
||||||
|
dst.x = x + center + 2.0f;
|
||||||
|
dst.y = y + FONT_CHARACTER_SIZE / 2 - ctx->button_height / 2;
|
||||||
|
dst.w = (float)ctx->button_width;
|
||||||
|
dst.h = (float)ctx->button_height;
|
||||||
|
SDL_RenderTexture(ctx->renderer, ctx->button_texture, NULL, &dst);
|
||||||
|
|
||||||
|
if (state) {
|
||||||
|
SDL_snprintf(text, sizeof(text), "(%.2f,%.2f)", finger_x, finger_y);
|
||||||
|
SDLTest_DrawString(ctx->renderer, x + center + ctx->button_width + 4.0f, y, text);
|
||||||
|
}
|
||||||
|
|
||||||
|
y += ctx->button_height + 2.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_snprintf(text, sizeof(text), "Touch finger %d:", i);
|
|
||||||
SDLTest_DrawString(ctx->renderer, x + center - SDL_strlen(text) * FONT_CHARACTER_SIZE, y, text);
|
|
||||||
|
|
||||||
if (state) {
|
|
||||||
SDL_SetTextureColorMod(ctx->button_texture, 10, 255, 21);
|
|
||||||
} else {
|
|
||||||
SDL_SetTextureColorMod(ctx->button_texture, 255, 255, 255);
|
|
||||||
}
|
|
||||||
|
|
||||||
dst.x = x + center + 2.0f;
|
|
||||||
dst.y = y + FONT_CHARACTER_SIZE / 2 - ctx->button_height / 2;
|
|
||||||
dst.w = (float)ctx->button_width;
|
|
||||||
dst.h = (float)ctx->button_height;
|
|
||||||
SDL_RenderTexture(ctx->renderer, ctx->button_texture, NULL, &dst);
|
|
||||||
|
|
||||||
if (state) {
|
|
||||||
SDL_snprintf(text, sizeof(text), "(%.2f,%.2f)", finger_x, finger_y);
|
|
||||||
SDLTest_DrawString(ctx->renderer, x + center + ctx->button_width + 4.0f, y, text);
|
|
||||||
}
|
|
||||||
|
|
||||||
y += ctx->button_height + 2.0f;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
has_accel = SDL_GamepadHasSensor(gamepad, SDL_SENSOR_ACCEL);
|
has_accel = SDL_GamepadHasSensor(gamepad, SDL_SENSOR_ACCEL);
|
||||||
has_gyro = SDL_GamepadHasSensor(gamepad, SDL_SENSOR_GYRO);
|
has_gyro = SDL_GamepadHasSensor(gamepad, SDL_SENSOR_GYRO);
|
||||||
if (has_accel || has_gyro) {
|
if (has_accel || has_gyro) {
|
||||||
const int SENSOR_UPDATE_INTERVAL_MS = 100;
|
const int SENSOR_UPDATE_INTERVAL_MS = 100;
|
||||||
Uint64 now = SDL_GetTicks();
|
Uint64 now = SDL_GetTicks();
|
||||||
|
|
||||||
|
if (now >= ctx->last_sensor_update + SENSOR_UPDATE_INTERVAL_MS) {
|
||||||
|
if (has_accel) {
|
||||||
|
SDL_GetGamepadSensorData(gamepad, SDL_SENSOR_ACCEL, ctx->accel_data, SDL_arraysize(ctx->accel_data));
|
||||||
|
}
|
||||||
|
if (has_gyro) {
|
||||||
|
SDL_GetGamepadSensorData(gamepad, SDL_SENSOR_GYRO, ctx->gyro_data, SDL_arraysize(ctx->gyro_data));
|
||||||
|
}
|
||||||
|
ctx->last_sensor_update = now;
|
||||||
|
}
|
||||||
|
|
||||||
if (now >= ctx->last_sensor_update + SENSOR_UPDATE_INTERVAL_MS) {
|
|
||||||
if (has_accel) {
|
if (has_accel) {
|
||||||
SDL_GetGamepadSensorData(gamepad, SDL_SENSOR_ACCEL, ctx->accel_data, SDL_arraysize(ctx->accel_data));
|
SDL_strlcpy(text, "Accelerometer:", sizeof(text));
|
||||||
|
SDLTest_DrawString(ctx->renderer, x + center - SDL_strlen(text) * FONT_CHARACTER_SIZE, y, text);
|
||||||
|
SDL_snprintf(text, sizeof(text), "(%.2f,%.2f,%.2f)", ctx->accel_data[0], ctx->accel_data[1], ctx->accel_data[2]);
|
||||||
|
SDLTest_DrawString(ctx->renderer, x + center + 2.0f, y, text);
|
||||||
|
|
||||||
|
y += ctx->button_height + 2.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (has_gyro) {
|
if (has_gyro) {
|
||||||
SDL_GetGamepadSensorData(gamepad, SDL_SENSOR_GYRO, ctx->gyro_data, SDL_arraysize(ctx->gyro_data));
|
SDL_strlcpy(text, "Gyro:", sizeof(text));
|
||||||
|
SDLTest_DrawString(ctx->renderer, x + center - SDL_strlen(text) * FONT_CHARACTER_SIZE, y, text);
|
||||||
|
SDL_snprintf(text, sizeof(text), "(%.2f,%.2f,%.2f)", ctx->gyro_data[0], ctx->gyro_data[1], ctx->gyro_data[2]);
|
||||||
|
SDLTest_DrawString(ctx->renderer, x + center + 2.0f, y, text);
|
||||||
|
|
||||||
|
y += ctx->button_height + 2.0f;
|
||||||
}
|
}
|
||||||
ctx->last_sensor_update = now;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (has_accel) {
|
|
||||||
SDL_strlcpy(text, "Accelerometer:", sizeof(text));
|
|
||||||
SDLTest_DrawString(ctx->renderer, x + center - SDL_strlen(text) * FONT_CHARACTER_SIZE, y, text);
|
|
||||||
SDL_snprintf(text, sizeof(text), "(%.2f,%.2f,%.2f)", ctx->accel_data[0], ctx->accel_data[1], ctx->accel_data[2]);
|
|
||||||
SDLTest_DrawString(ctx->renderer, x + center + 2.0f, y, text);
|
|
||||||
|
|
||||||
y += ctx->button_height + 2.0f;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (has_gyro) {
|
|
||||||
SDL_strlcpy(text, "Gyro:", sizeof(text));
|
|
||||||
SDLTest_DrawString(ctx->renderer, x + center - SDL_strlen(text) * FONT_CHARACTER_SIZE, y, text);
|
|
||||||
SDL_snprintf(text, sizeof(text), "(%.2f,%.2f,%.2f)", ctx->gyro_data[0], ctx->gyro_data[1], ctx->gyro_data[2]);
|
|
||||||
SDLTest_DrawString(ctx->renderer, x + center + 2.0f, y, text);
|
|
||||||
|
|
||||||
y += ctx->button_height + 2.0f;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1028,16 +1014,13 @@ JoystickDisplay *CreateJoystickDisplay(SDL_Renderer *renderer)
|
|||||||
return ctx;
|
return ctx;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetJoystickDisplayArea(JoystickDisplay *ctx, int x, int y, int w, int h)
|
void SetJoystickDisplayArea(JoystickDisplay *ctx, const SDL_Rect *area)
|
||||||
{
|
{
|
||||||
if (!ctx) {
|
if (!ctx) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx->area.x = x;
|
SDL_copyp(&ctx->area, area);
|
||||||
ctx->area.y = y;
|
|
||||||
ctx->area.w = w;
|
|
||||||
ctx->area.h = h;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderJoystickDisplay(JoystickDisplay *ctx, SDL_Joystick *joystick)
|
void RenderJoystickDisplay(JoystickDisplay *ctx, SDL_Joystick *joystick)
|
||||||
@@ -1259,16 +1242,16 @@ GamepadButton *CreateGamepadButton(SDL_Renderer *renderer, const char *label)
|
|||||||
return ctx;
|
return ctx;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetGamepadButtonArea(GamepadButton *ctx, int x, int y, int w, int h)
|
void SetGamepadButtonArea(GamepadButton *ctx, const SDL_Rect *area)
|
||||||
{
|
{
|
||||||
if (!ctx) {
|
if (!ctx) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx->area.x = (float)x;
|
ctx->area.x = (float)area->x;
|
||||||
ctx->area.y = (float)y;
|
ctx->area.y = (float)area->y;
|
||||||
ctx->area.w = (float)w;
|
ctx->area.w = (float)area->w;
|
||||||
ctx->area.h = (float)h;
|
ctx->area.h = (float)area->h;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetGamepadButtonHighlight(GamepadButton *ctx, SDL_bool highlight)
|
void SetGamepadButtonHighlight(GamepadButton *ctx, SDL_bool highlight)
|
||||||
|
|||||||
+11
-6
@@ -14,6 +14,12 @@
|
|||||||
|
|
||||||
typedef struct GamepadImage GamepadImage;
|
typedef struct GamepadImage GamepadImage;
|
||||||
|
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
CONTROLLER_MODE_TESTING,
|
||||||
|
CONTROLLER_MODE_BINDING,
|
||||||
|
} ControllerDisplayMode;
|
||||||
|
|
||||||
typedef enum
|
typedef enum
|
||||||
{
|
{
|
||||||
GAMEPAD_IMAGE_FACE_BLANK,
|
GAMEPAD_IMAGE_FACE_BLANK,
|
||||||
@@ -26,9 +32,7 @@ extern GamepadImage *CreateGamepadImage(SDL_Renderer *renderer);
|
|||||||
extern void SetGamepadImagePosition(GamepadImage *ctx, int x, int y);
|
extern void SetGamepadImagePosition(GamepadImage *ctx, int x, int y);
|
||||||
extern void SetGamepadImageShowingFront(GamepadImage *ctx, SDL_bool showing_front);
|
extern void SetGamepadImageShowingFront(GamepadImage *ctx, SDL_bool showing_front);
|
||||||
extern void SetGamepadImageFaceStyle(GamepadImage *ctx, GamepadImageFaceStyle face_style);
|
extern void SetGamepadImageFaceStyle(GamepadImage *ctx, GamepadImageFaceStyle face_style);
|
||||||
extern void SetGamepadImageShowingBattery(GamepadImage *ctx, SDL_bool showing_battery);
|
extern void SetGamepadImageDisplayMode(GamepadImage *ctx, ControllerDisplayMode display_mode);
|
||||||
extern void SetGamepadImageShowingTouchpad(GamepadImage *ctx, SDL_bool showing_touchpad);
|
|
||||||
extern void GetGamepadImageArea(GamepadImage *ctx, int *x, int *y, int *width, int *height);
|
|
||||||
extern int GetGamepadImageButtonWidth(GamepadImage *ctx);
|
extern int GetGamepadImageButtonWidth(GamepadImage *ctx);
|
||||||
extern int GetGamepadImageButtonHeight(GamepadImage *ctx);
|
extern int GetGamepadImageButtonHeight(GamepadImage *ctx);
|
||||||
extern int GetGamepadImageAxisWidth(GamepadImage *ctx);
|
extern int GetGamepadImageAxisWidth(GamepadImage *ctx);
|
||||||
@@ -50,7 +54,8 @@ extern void DestroyGamepadImage(GamepadImage *ctx);
|
|||||||
typedef struct GamepadDisplay GamepadDisplay;
|
typedef struct GamepadDisplay GamepadDisplay;
|
||||||
|
|
||||||
extern GamepadDisplay *CreateGamepadDisplay(SDL_Renderer *renderer);
|
extern GamepadDisplay *CreateGamepadDisplay(SDL_Renderer *renderer);
|
||||||
extern void SetGamepadDisplayArea(GamepadDisplay *ctx, int x, int y, int w, int h);
|
extern void SetGamepadDisplayDisplayMode(GamepadDisplay *ctx, ControllerDisplayMode display_mode);
|
||||||
|
extern void SetGamepadDisplayArea(GamepadDisplay *ctx, const SDL_Rect *area);
|
||||||
extern void RenderGamepadDisplay(GamepadDisplay *ctx, SDL_Gamepad *gamepad);
|
extern void RenderGamepadDisplay(GamepadDisplay *ctx, SDL_Gamepad *gamepad);
|
||||||
extern void DestroyGamepadDisplay(GamepadDisplay *ctx);
|
extern void DestroyGamepadDisplay(GamepadDisplay *ctx);
|
||||||
|
|
||||||
@@ -59,7 +64,7 @@ extern void DestroyGamepadDisplay(GamepadDisplay *ctx);
|
|||||||
typedef struct JoystickDisplay JoystickDisplay;
|
typedef struct JoystickDisplay JoystickDisplay;
|
||||||
|
|
||||||
extern JoystickDisplay *CreateJoystickDisplay(SDL_Renderer *renderer);
|
extern JoystickDisplay *CreateJoystickDisplay(SDL_Renderer *renderer);
|
||||||
extern void SetJoystickDisplayArea(JoystickDisplay *ctx, int x, int y, int w, int h);
|
extern void SetJoystickDisplayArea(JoystickDisplay *ctx, const SDL_Rect *area);
|
||||||
extern void RenderJoystickDisplay(JoystickDisplay *ctx, SDL_Joystick *joystick);
|
extern void RenderJoystickDisplay(JoystickDisplay *ctx, SDL_Joystick *joystick);
|
||||||
extern void DestroyJoystickDisplay(JoystickDisplay *ctx);
|
extern void DestroyJoystickDisplay(JoystickDisplay *ctx);
|
||||||
|
|
||||||
@@ -68,7 +73,7 @@ extern void DestroyJoystickDisplay(JoystickDisplay *ctx);
|
|||||||
typedef struct GamepadButton GamepadButton;
|
typedef struct GamepadButton GamepadButton;
|
||||||
|
|
||||||
extern GamepadButton *CreateGamepadButton(SDL_Renderer *renderer, const char *label);
|
extern GamepadButton *CreateGamepadButton(SDL_Renderer *renderer, const char *label);
|
||||||
extern void SetGamepadButtonArea(GamepadButton *ctx, int x, int y, int w, int h);
|
extern void SetGamepadButtonArea(GamepadButton *ctx, const SDL_Rect *area);
|
||||||
extern void SetGamepadButtonHighlight(GamepadButton *ctx, SDL_bool highlight);
|
extern void SetGamepadButtonHighlight(GamepadButton *ctx, SDL_bool highlight);
|
||||||
extern int GetGamepadButtonLabelWidth(GamepadButton *ctx);
|
extern int GetGamepadButtonLabelWidth(GamepadButton *ctx);
|
||||||
extern int GetGamepadButtonLabelHeight(GamepadButton *ctx);
|
extern int GetGamepadButtonLabelHeight(GamepadButton *ctx);
|
||||||
|
|||||||
+313
-136
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user