mirror of
https://github.com/libsdl-org/SDL.git
synced 2026-06-06 06:34:35 +00:00
Use floating point values for viewport, clip rectangle, and texture sizes
These are integer values internally, but the API has been changed to make it easier to mix other render code with querying those values. Fixes https://github.com/libsdl-org/SDL/issues/7519
This commit is contained in:
parent
463984ec20
commit
9fb5a9ccac
29 changed files with 624 additions and 585 deletions
|
|
@ -99,21 +99,21 @@ struct GamepadImage
|
|||
SDL_Texture *touchpad_texture;
|
||||
SDL_Texture *button_texture;
|
||||
SDL_Texture *axis_texture;
|
||||
int gamepad_width;
|
||||
int gamepad_height;
|
||||
int face_width;
|
||||
int face_height;
|
||||
int battery_width;
|
||||
int battery_height;
|
||||
int touchpad_width;
|
||||
int touchpad_height;
|
||||
int button_width;
|
||||
int button_height;
|
||||
int axis_width;
|
||||
int axis_height;
|
||||
float gamepad_width;
|
||||
float gamepad_height;
|
||||
float face_width;
|
||||
float face_height;
|
||||
float battery_width;
|
||||
float battery_height;
|
||||
float touchpad_width;
|
||||
float touchpad_height;
|
||||
float button_width;
|
||||
float button_height;
|
||||
float axis_width;
|
||||
float axis_height;
|
||||
|
||||
int x;
|
||||
int y;
|
||||
float x;
|
||||
float y;
|
||||
SDL_bool showing_front;
|
||||
SDL_bool showing_touchpad;
|
||||
SDL_GamepadType type;
|
||||
|
|
@ -150,26 +150,26 @@ GamepadImage *CreateGamepadImage(SDL_Renderer *renderer)
|
|||
ctx->renderer = renderer;
|
||||
ctx->front_texture = CreateTexture(renderer, gamepad_front_bmp, gamepad_front_bmp_len);
|
||||
ctx->back_texture = CreateTexture(renderer, gamepad_back_bmp, gamepad_back_bmp_len);
|
||||
SDL_QueryTexture(ctx->front_texture, NULL, NULL, &ctx->gamepad_width, &ctx->gamepad_height);
|
||||
SDL_GetTextureSize(ctx->front_texture, &ctx->gamepad_width, &ctx->gamepad_height);
|
||||
|
||||
ctx->face_abxy_texture = CreateTexture(renderer, gamepad_face_abxy_bmp, gamepad_face_abxy_bmp_len);
|
||||
ctx->face_bayx_texture = CreateTexture(renderer, gamepad_face_bayx_bmp, gamepad_face_bayx_bmp_len);
|
||||
ctx->face_sony_texture = CreateTexture(renderer, gamepad_face_sony_bmp, gamepad_face_sony_bmp_len);
|
||||
SDL_QueryTexture(ctx->face_abxy_texture, NULL, NULL, &ctx->face_width, &ctx->face_height);
|
||||
SDL_GetTextureSize(ctx->face_abxy_texture, &ctx->face_width, &ctx->face_height);
|
||||
|
||||
ctx->battery_texture[0] = CreateTexture(renderer, gamepad_battery_bmp, gamepad_battery_bmp_len);
|
||||
ctx->battery_texture[1] = CreateTexture(renderer, gamepad_battery_wired_bmp, gamepad_battery_wired_bmp_len);
|
||||
SDL_QueryTexture(ctx->battery_texture[0], NULL, NULL, &ctx->battery_width, &ctx->battery_height);
|
||||
SDL_GetTextureSize(ctx->battery_texture[0], &ctx->battery_width, &ctx->battery_height);
|
||||
|
||||
ctx->touchpad_texture = CreateTexture(renderer, gamepad_touchpad_bmp, gamepad_touchpad_bmp_len);
|
||||
SDL_QueryTexture(ctx->touchpad_texture, NULL, NULL, &ctx->touchpad_width, &ctx->touchpad_height);
|
||||
SDL_GetTextureSize(ctx->touchpad_texture, &ctx->touchpad_width, &ctx->touchpad_height);
|
||||
|
||||
ctx->button_texture = CreateTexture(renderer, gamepad_button_bmp, gamepad_button_bmp_len);
|
||||
SDL_QueryTexture(ctx->button_texture, NULL, NULL, &ctx->button_width, &ctx->button_height);
|
||||
SDL_GetTextureSize(ctx->button_texture, &ctx->button_width, &ctx->button_height);
|
||||
SDL_SetTextureColorMod(ctx->button_texture, 10, 255, 21);
|
||||
|
||||
ctx->axis_texture = CreateTexture(renderer, gamepad_axis_bmp, gamepad_axis_bmp_len);
|
||||
SDL_QueryTexture(ctx->axis_texture, NULL, NULL, &ctx->axis_width, &ctx->axis_height);
|
||||
SDL_GetTextureSize(ctx->axis_texture, &ctx->axis_width, &ctx->axis_height);
|
||||
SDL_SetTextureColorMod(ctx->axis_texture, 10, 255, 21);
|
||||
|
||||
ctx->showing_front = SDL_TRUE;
|
||||
|
|
@ -177,7 +177,7 @@ GamepadImage *CreateGamepadImage(SDL_Renderer *renderer)
|
|||
return ctx;
|
||||
}
|
||||
|
||||
void SetGamepadImagePosition(GamepadImage *ctx, int x, int y)
|
||||
void SetGamepadImagePosition(GamepadImage *ctx, float x, float y)
|
||||
{
|
||||
if (!ctx) {
|
||||
return;
|
||||
|
|
@ -187,7 +187,7 @@ void SetGamepadImagePosition(GamepadImage *ctx, int x, int y)
|
|||
ctx->y = y;
|
||||
}
|
||||
|
||||
void GetGamepadImageArea(GamepadImage *ctx, SDL_Rect *area)
|
||||
void GetGamepadImageArea(GamepadImage *ctx, SDL_FRect *area)
|
||||
{
|
||||
if (!ctx) {
|
||||
SDL_zerop(area);
|
||||
|
|
@ -203,7 +203,7 @@ void GetGamepadImageArea(GamepadImage *ctx, SDL_Rect *area)
|
|||
}
|
||||
}
|
||||
|
||||
void GetGamepadTouchpadArea(GamepadImage *ctx, SDL_Rect *area)
|
||||
void GetGamepadTouchpadArea(GamepadImage *ctx, SDL_FRect *area)
|
||||
{
|
||||
if (!ctx) {
|
||||
SDL_zerop(area);
|
||||
|
|
@ -225,15 +225,6 @@ void SetGamepadImageShowingFront(GamepadImage *ctx, SDL_bool showing_front)
|
|||
ctx->showing_front = showing_front;
|
||||
}
|
||||
|
||||
void SetGamepadImageFaceButtonType(GamepadImage *ctx, SDL_GamepadType type)
|
||||
{
|
||||
if (!ctx) {
|
||||
return;
|
||||
}
|
||||
|
||||
ctx->type = type;
|
||||
}
|
||||
|
||||
SDL_GamepadType GetGamepadImageType(GamepadImage *ctx)
|
||||
{
|
||||
if (!ctx) {
|
||||
|
|
@ -252,7 +243,7 @@ void SetGamepadImageDisplayMode(GamepadImage *ctx, ControllerDisplayMode display
|
|||
ctx->display_mode = display_mode;
|
||||
}
|
||||
|
||||
int GetGamepadImageButtonWidth(GamepadImage *ctx)
|
||||
float GetGamepadImageButtonWidth(GamepadImage *ctx)
|
||||
{
|
||||
if (!ctx) {
|
||||
return 0;
|
||||
|
|
@ -261,7 +252,7 @@ int GetGamepadImageButtonWidth(GamepadImage *ctx)
|
|||
return ctx->button_width;
|
||||
}
|
||||
|
||||
int GetGamepadImageButtonHeight(GamepadImage *ctx)
|
||||
float GetGamepadImageButtonHeight(GamepadImage *ctx)
|
||||
{
|
||||
if (!ctx) {
|
||||
return 0;
|
||||
|
|
@ -270,7 +261,7 @@ int GetGamepadImageButtonHeight(GamepadImage *ctx)
|
|||
return ctx->button_height;
|
||||
}
|
||||
|
||||
int GetGamepadImageAxisWidth(GamepadImage *ctx)
|
||||
float GetGamepadImageAxisWidth(GamepadImage *ctx)
|
||||
{
|
||||
if (!ctx) {
|
||||
return 0;
|
||||
|
|
@ -279,7 +270,7 @@ int GetGamepadImageAxisWidth(GamepadImage *ctx)
|
|||
return ctx->axis_width;
|
||||
}
|
||||
|
||||
int GetGamepadImageAxisHeight(GamepadImage *ctx)
|
||||
float GetGamepadImageAxisHeight(GamepadImage *ctx)
|
||||
{
|
||||
if (!ctx) {
|
||||
return 0;
|
||||
|
|
@ -307,10 +298,10 @@ int GetGamepadImageElementAt(GamepadImage *ctx, float x, float y)
|
|||
|
||||
if (element == SDL_GAMEPAD_ELEMENT_AXIS_LEFT_TRIGGER ||
|
||||
element == SDL_GAMEPAD_ELEMENT_AXIS_RIGHT_TRIGGER) {
|
||||
rect.w = (float)ctx->axis_width;
|
||||
rect.h = (float)ctx->axis_height;
|
||||
rect.x = (float)ctx->x + axis_positions[i].x - rect.w / 2;
|
||||
rect.y = (float)ctx->y + axis_positions[i].y - rect.h / 2;
|
||||
rect.w = ctx->axis_width;
|
||||
rect.h = ctx->axis_height;
|
||||
rect.x = ctx->x + axis_positions[i].x - rect.w / 2;
|
||||
rect.y = ctx->y + axis_positions[i].y - rect.h / 2;
|
||||
if (SDL_PointInRectFloat(&point, &rect)) {
|
||||
if (element == SDL_GAMEPAD_ELEMENT_AXIS_LEFT_TRIGGER) {
|
||||
return SDL_GAMEPAD_ELEMENT_AXIS_LEFT_TRIGGER;
|
||||
|
|
@ -319,14 +310,14 @@ int GetGamepadImageElementAt(GamepadImage *ctx, float x, float y)
|
|||
}
|
||||
}
|
||||
} else if (element == SDL_GAMEPAD_ELEMENT_AXIS_LEFTX_POSITIVE) {
|
||||
rect.w = (float)ctx->button_width * 2.0f;
|
||||
rect.h = (float)ctx->button_height * 2.0f;
|
||||
rect.x = (float)ctx->x + button_positions[SDL_GAMEPAD_BUTTON_LEFT_STICK].x - rect.w / 2;
|
||||
rect.y = (float)ctx->y + button_positions[SDL_GAMEPAD_BUTTON_LEFT_STICK].y - rect.h / 2;
|
||||
rect.w = ctx->button_width * 2.0f;
|
||||
rect.h = ctx->button_height * 2.0f;
|
||||
rect.x = ctx->x + button_positions[SDL_GAMEPAD_BUTTON_LEFT_STICK].x - rect.w / 2;
|
||||
rect.y = ctx->y + button_positions[SDL_GAMEPAD_BUTTON_LEFT_STICK].y - rect.h / 2;
|
||||
if (SDL_PointInRectFloat(&point, &rect)) {
|
||||
float delta_x, delta_y;
|
||||
float delta_squared;
|
||||
float thumbstick_radius = (float)ctx->button_width * 0.1f;
|
||||
float thumbstick_radius = ctx->button_width * 0.1f;
|
||||
|
||||
delta_x = (x - (ctx->x + button_positions[SDL_GAMEPAD_BUTTON_LEFT_STICK].x));
|
||||
delta_y = (y - (ctx->y + button_positions[SDL_GAMEPAD_BUTTON_LEFT_STICK].y));
|
||||
|
|
@ -347,14 +338,14 @@ int GetGamepadImageElementAt(GamepadImage *ctx, float x, float y)
|
|||
}
|
||||
}
|
||||
} else if (element == SDL_GAMEPAD_ELEMENT_AXIS_RIGHTX_POSITIVE) {
|
||||
rect.w = (float)ctx->button_width * 2.0f;
|
||||
rect.h = (float)ctx->button_height * 2.0f;
|
||||
rect.x = (float)ctx->x + button_positions[SDL_GAMEPAD_BUTTON_RIGHT_STICK].x - rect.w / 2;
|
||||
rect.y = (float)ctx->y + button_positions[SDL_GAMEPAD_BUTTON_RIGHT_STICK].y - rect.h / 2;
|
||||
rect.w = ctx->button_width * 2.0f;
|
||||
rect.h = ctx->button_height * 2.0f;
|
||||
rect.x = ctx->x + button_positions[SDL_GAMEPAD_BUTTON_RIGHT_STICK].x - rect.w / 2;
|
||||
rect.y = ctx->y + button_positions[SDL_GAMEPAD_BUTTON_RIGHT_STICK].y - rect.h / 2;
|
||||
if (SDL_PointInRectFloat(&point, &rect)) {
|
||||
float delta_x, delta_y;
|
||||
float delta_squared;
|
||||
float thumbstick_radius = (float)ctx->button_width * 0.1f;
|
||||
float thumbstick_radius = ctx->button_width * 0.1f;
|
||||
|
||||
delta_x = (x - (ctx->x + button_positions[SDL_GAMEPAD_BUTTON_RIGHT_STICK].x));
|
||||
delta_y = (y - (ctx->y + button_positions[SDL_GAMEPAD_BUTTON_RIGHT_STICK].y));
|
||||
|
|
@ -386,10 +377,10 @@ int GetGamepadImageElementAt(GamepadImage *ctx, float x, float y)
|
|||
}
|
||||
if (on_front == ctx->showing_front) {
|
||||
SDL_FRect rect;
|
||||
rect.x = (float)ctx->x + button_positions[i].x - ctx->button_width / 2;
|
||||
rect.y = (float)ctx->y + button_positions[i].y - ctx->button_height / 2;
|
||||
rect.w = (float)ctx->button_width;
|
||||
rect.h = (float)ctx->button_height;
|
||||
rect.x = ctx->x + button_positions[i].x - ctx->button_width / 2;
|
||||
rect.y = ctx->y + button_positions[i].y - ctx->button_height / 2;
|
||||
rect.w = ctx->button_width;
|
||||
rect.h = ctx->button_height;
|
||||
if (SDL_PointInRectFloat(&point, &rect)) {
|
||||
return (SDL_GamepadButton)i;
|
||||
}
|
||||
|
|
@ -514,10 +505,10 @@ void RenderGamepadImage(GamepadImage *ctx)
|
|||
return;
|
||||
}
|
||||
|
||||
dst.x = (float)ctx->x;
|
||||
dst.y = (float)ctx->y;
|
||||
dst.w = (float)ctx->gamepad_width;
|
||||
dst.h = (float)ctx->gamepad_height;
|
||||
dst.x = ctx->x;
|
||||
dst.y = ctx->y;
|
||||
dst.w = ctx->gamepad_width;
|
||||
dst.h = ctx->gamepad_height;
|
||||
|
||||
if (ctx->showing_front) {
|
||||
SDL_RenderTexture(ctx->renderer, ctx->front_texture, NULL, &dst);
|
||||
|
|
@ -534,20 +525,20 @@ void RenderGamepadImage(GamepadImage *ctx)
|
|||
on_front = SDL_FALSE;
|
||||
}
|
||||
if (on_front == ctx->showing_front) {
|
||||
dst.w = (float)ctx->button_width;
|
||||
dst.h = (float)ctx->button_height;
|
||||
dst.x = (float)ctx->x + button_positions[button_position].x - dst.w / 2;
|
||||
dst.y = (float)ctx->y + button_positions[button_position].y - dst.h / 2;
|
||||
dst.w = ctx->button_width;
|
||||
dst.h = ctx->button_height;
|
||||
dst.x = ctx->x + button_positions[button_position].x - dst.w / 2;
|
||||
dst.y = ctx->y + button_positions[button_position].y - dst.h / 2;
|
||||
SDL_RenderTexture(ctx->renderer, ctx->button_texture, NULL, &dst);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (ctx->showing_front) {
|
||||
dst.x = (float)ctx->x + 363;
|
||||
dst.y = (float)ctx->y + 118;
|
||||
dst.w = (float)ctx->face_width;
|
||||
dst.h = (float)ctx->face_height;
|
||||
dst.x = ctx->x + 363;
|
||||
dst.y = ctx->y + 118;
|
||||
dst.w = ctx->face_width;
|
||||
dst.h = ctx->face_height;
|
||||
|
||||
switch (SDL_GetGamepadButtonLabelForType(ctx->type, SDL_GAMEPAD_BUTTON_SOUTH)) {
|
||||
case SDL_GAMEPAD_BUTTON_LABEL_A:
|
||||
|
|
@ -569,10 +560,10 @@ void RenderGamepadImage(GamepadImage *ctx)
|
|||
const int element = SDL_GAMEPAD_BUTTON_MAX + i;
|
||||
if (ctx->elements[element]) {
|
||||
const double angle = axis_positions[i].angle;
|
||||
dst.w = (float)ctx->axis_width;
|
||||
dst.h = (float)ctx->axis_height;
|
||||
dst.x = (float)ctx->x + axis_positions[i].x - dst.w / 2;
|
||||
dst.y = (float)ctx->y + axis_positions[i].y - dst.h / 2;
|
||||
dst.w = ctx->axis_width;
|
||||
dst.h = ctx->axis_height;
|
||||
dst.x = ctx->x + axis_positions[i].x - dst.w / 2;
|
||||
dst.y = ctx->y + axis_positions[i].y - dst.h / 2;
|
||||
SDL_RenderTextureRotated(ctx->renderer, ctx->axis_texture, NULL, &dst, angle, NULL, SDL_FLIP_NONE);
|
||||
}
|
||||
}
|
||||
|
|
@ -584,10 +575,10 @@ void RenderGamepadImage(GamepadImage *ctx)
|
|||
Uint8 r, g, b, a;
|
||||
SDL_FRect fill;
|
||||
|
||||
dst.x = (float)ctx->x + ctx->gamepad_width - ctx->battery_width;
|
||||
dst.y = (float)ctx->y;
|
||||
dst.w = (float)ctx->battery_width;
|
||||
dst.h = (float)ctx->battery_height;
|
||||
dst.x = ctx->x + ctx->gamepad_width - ctx->battery_width;
|
||||
dst.y = ctx->y;
|
||||
dst.w = ctx->battery_width;
|
||||
dst.h = ctx->battery_height;
|
||||
|
||||
SDL_GetRenderDrawColor(ctx->renderer, &r, &g, &b, &a);
|
||||
if (ctx->battery_percent > 40) {
|
||||
|
|
@ -614,24 +605,24 @@ void RenderGamepadImage(GamepadImage *ctx)
|
|||
}
|
||||
|
||||
if (ctx->display_mode == CONTROLLER_MODE_TESTING && ctx->showing_touchpad) {
|
||||
dst.x = (float)ctx->x + (ctx->gamepad_width - ctx->touchpad_width) / 2;
|
||||
dst.y = (float)ctx->y + ctx->gamepad_height;
|
||||
dst.w = (float)ctx->touchpad_width;
|
||||
dst.h = (float)ctx->touchpad_height;
|
||||
dst.x = ctx->x + (ctx->gamepad_width - ctx->touchpad_width) / 2;
|
||||
dst.y = ctx->y + ctx->gamepad_height;
|
||||
dst.w = ctx->touchpad_width;
|
||||
dst.h = ctx->touchpad_height;
|
||||
SDL_RenderTexture(ctx->renderer, ctx->touchpad_texture, NULL, &dst);
|
||||
|
||||
for (i = 0; i < ctx->num_fingers; ++i) {
|
||||
GamepadTouchpadFinger *finger = &ctx->fingers[i];
|
||||
|
||||
if (finger->state) {
|
||||
dst.x = (float)ctx->x + (ctx->gamepad_width - ctx->touchpad_width) / 2;
|
||||
dst.x = ctx->x + (ctx->gamepad_width - ctx->touchpad_width) / 2;
|
||||
dst.x += touchpad_area.x + finger->x * touchpad_area.w;
|
||||
dst.x -= ctx->button_width / 2;
|
||||
dst.y = (float)ctx->y + ctx->gamepad_height;
|
||||
dst.y = ctx->y + ctx->gamepad_height;
|
||||
dst.y += touchpad_area.y + finger->y * touchpad_area.h;
|
||||
dst.y -= ctx->button_height / 2;
|
||||
dst.w = (float)ctx->button_width;
|
||||
dst.h = (float)ctx->button_height;
|
||||
dst.w = ctx->button_width;
|
||||
dst.h = ctx->button_height;
|
||||
SDL_SetTextureAlphaMod(ctx->button_texture, (Uint8)(finger->pressure * SDL_ALPHA_OPAQUE));
|
||||
SDL_RenderTexture(ctx->renderer, ctx->button_texture, NULL, &dst);
|
||||
SDL_SetTextureAlphaMod(ctx->button_texture, SDL_ALPHA_OPAQUE);
|
||||
|
|
@ -706,10 +697,10 @@ struct GamepadDisplay
|
|||
SDL_Renderer *renderer;
|
||||
SDL_Texture *button_texture;
|
||||
SDL_Texture *arrow_texture;
|
||||
int button_width;
|
||||
int button_height;
|
||||
int arrow_width;
|
||||
int arrow_height;
|
||||
float button_width;
|
||||
float button_height;
|
||||
float arrow_width;
|
||||
float arrow_height;
|
||||
|
||||
float accel_data[3];
|
||||
float gyro_data[3];
|
||||
|
|
@ -720,7 +711,7 @@ struct GamepadDisplay
|
|||
SDL_bool element_pressed;
|
||||
int element_selected;
|
||||
|
||||
SDL_Rect area;
|
||||
SDL_FRect area;
|
||||
};
|
||||
|
||||
GamepadDisplay *CreateGamepadDisplay(SDL_Renderer *renderer)
|
||||
|
|
@ -730,10 +721,10 @@ GamepadDisplay *CreateGamepadDisplay(SDL_Renderer *renderer)
|
|||
ctx->renderer = renderer;
|
||||
|
||||
ctx->button_texture = CreateTexture(renderer, gamepad_button_small_bmp, gamepad_button_small_bmp_len);
|
||||
SDL_QueryTexture(ctx->button_texture, NULL, NULL, &ctx->button_width, &ctx->button_height);
|
||||
SDL_GetTextureSize(ctx->button_texture, &ctx->button_width, &ctx->button_height);
|
||||
|
||||
ctx->arrow_texture = CreateTexture(renderer, gamepad_axis_arrow_bmp, gamepad_axis_arrow_bmp_len);
|
||||
SDL_QueryTexture(ctx->arrow_texture, NULL, NULL, &ctx->arrow_width, &ctx->arrow_height);
|
||||
SDL_GetTextureSize(ctx->arrow_texture, &ctx->arrow_width, &ctx->arrow_height);
|
||||
|
||||
ctx->element_highlighted = SDL_GAMEPAD_ELEMENT_INVALID;
|
||||
ctx->element_selected = SDL_GAMEPAD_ELEMENT_INVALID;
|
||||
|
|
@ -750,7 +741,7 @@ void SetGamepadDisplayDisplayMode(GamepadDisplay *ctx, ControllerDisplayMode dis
|
|||
ctx->display_mode = display_mode;
|
||||
}
|
||||
|
||||
void SetGamepadDisplayArea(GamepadDisplay *ctx, const SDL_Rect *area)
|
||||
void SetGamepadDisplayArea(GamepadDisplay *ctx, const SDL_FRect *area)
|
||||
{
|
||||
if (!ctx) {
|
||||
return;
|
||||
|
|
@ -925,8 +916,8 @@ int GetGamepadDisplayElementAt(GamepadDisplay *ctx, SDL_Gamepad *gamepad, float
|
|||
|
||||
rect.x = ctx->area.x + margin;
|
||||
rect.y = ctx->area.y + margin + FONT_CHARACTER_SIZE / 2 - ctx->button_height / 2;
|
||||
rect.w = (float)ctx->area.w - (margin * 2);
|
||||
rect.h = (float)ctx->button_height;
|
||||
rect.w = ctx->area.w - (margin * 2);
|
||||
rect.h = ctx->button_height;
|
||||
|
||||
for (i = 0; i < SDL_GAMEPAD_BUTTON_MAX; ++i) {
|
||||
SDL_GamepadButton button = (SDL_GamepadButton)i;
|
||||
|
|
@ -941,7 +932,7 @@ int GetGamepadDisplayElementAt(GamepadDisplay *ctx, SDL_Gamepad *gamepad, float
|
|||
return i;
|
||||
}
|
||||
|
||||
rect.y += (float)ctx->button_height + 2.0f;
|
||||
rect.y += ctx->button_height + 2.0f;
|
||||
}
|
||||
|
||||
for (i = 0; i < SDL_GAMEPAD_AXIS_MAX; ++i) {
|
||||
|
|
@ -955,8 +946,8 @@ int GetGamepadDisplayElementAt(GamepadDisplay *ctx, SDL_Gamepad *gamepad, float
|
|||
|
||||
area.x = rect.x + center + 2.0f;
|
||||
area.y = rect.y + FONT_CHARACTER_SIZE / 2 - ctx->button_height / 2;
|
||||
area.w = (float)ctx->arrow_width + arrow_extent;
|
||||
area.h = (float)ctx->button_height;
|
||||
area.w = ctx->arrow_width + arrow_extent;
|
||||
area.h = ctx->button_height;
|
||||
|
||||
if (SDL_PointInRectFloat(&point, &area)) {
|
||||
switch (axis) {
|
||||
|
|
@ -994,7 +985,7 @@ int GetGamepadDisplayElementAt(GamepadDisplay *ctx, SDL_Gamepad *gamepad, float
|
|||
}
|
||||
}
|
||||
|
||||
rect.y += (float)ctx->button_height + 2.0f;
|
||||
rect.y += ctx->button_height + 2.0f;
|
||||
}
|
||||
return SDL_GAMEPAD_ELEMENT_INVALID;
|
||||
}
|
||||
|
|
@ -1056,8 +1047,8 @@ void RenderGamepadDisplay(GamepadDisplay *ctx, SDL_Gamepad *gamepad)
|
|||
|
||||
highlight.x = x;
|
||||
highlight.y = y + FONT_CHARACTER_SIZE / 2 - ctx->button_height / 2;
|
||||
highlight.w = (float)ctx->area.w - (margin * 2);
|
||||
highlight.h = (float)ctx->button_height;
|
||||
highlight.w = ctx->area.w - (margin * 2);
|
||||
highlight.h = ctx->button_height;
|
||||
RenderGamepadElementHighlight(ctx, i, &highlight);
|
||||
|
||||
SDL_snprintf(text, sizeof(text), "%s:", gamepad_button_names[i]);
|
||||
|
|
@ -1071,8 +1062,8 @@ void RenderGamepadDisplay(GamepadDisplay *ctx, SDL_Gamepad *gamepad)
|
|||
|
||||
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;
|
||||
dst.w = ctx->button_width;
|
||||
dst.h = ctx->button_height;
|
||||
SDL_RenderTexture(ctx->renderer, ctx->button_texture, NULL, &dst);
|
||||
|
||||
if (ctx->display_mode == CONTROLLER_MODE_BINDING) {
|
||||
|
|
@ -1102,8 +1093,8 @@ void RenderGamepadDisplay(GamepadDisplay *ctx, SDL_Gamepad *gamepad)
|
|||
|
||||
highlight.x = x + center + 2.0f;
|
||||
highlight.y = y + FONT_CHARACTER_SIZE / 2 - ctx->button_height / 2;
|
||||
highlight.w = (float)ctx->arrow_width + arrow_extent;
|
||||
highlight.h = (float)ctx->button_height;
|
||||
highlight.w = ctx->arrow_width + arrow_extent;
|
||||
highlight.h = ctx->button_height;
|
||||
|
||||
switch (axis) {
|
||||
case SDL_GAMEPAD_AXIS_LEFTX:
|
||||
|
|
@ -1149,8 +1140,8 @@ void RenderGamepadDisplay(GamepadDisplay *ctx, SDL_Gamepad *gamepad)
|
|||
|
||||
dst.x = x + center + 2.0f;
|
||||
dst.y = y + FONT_CHARACTER_SIZE / 2 - ctx->arrow_height / 2;
|
||||
dst.w = (float)ctx->arrow_width;
|
||||
dst.h = (float)ctx->arrow_height;
|
||||
dst.w = ctx->arrow_width;
|
||||
dst.h = ctx->arrow_height;
|
||||
|
||||
if (has_negative) {
|
||||
if (value == SDL_MIN_SINT16) {
|
||||
|
|
@ -1161,19 +1152,19 @@ void RenderGamepadDisplay(GamepadDisplay *ctx, SDL_Gamepad *gamepad)
|
|||
SDL_RenderTextureRotated(ctx->renderer, ctx->arrow_texture, NULL, &dst, 0.0f, NULL, SDL_FLIP_HORIZONTAL);
|
||||
}
|
||||
|
||||
dst.x += (float)ctx->arrow_width;
|
||||
dst.x += ctx->arrow_width;
|
||||
|
||||
SDL_SetRenderDrawColor(ctx->renderer, 200, 200, 200, SDL_ALPHA_OPAQUE);
|
||||
rect.x = dst.x + arrow_extent - 2.0f;
|
||||
rect.y = dst.y;
|
||||
rect.w = 4.0f;
|
||||
rect.h = (float)ctx->arrow_height;
|
||||
rect.h = ctx->arrow_height;
|
||||
SDL_RenderFillRect(ctx->renderer, &rect);
|
||||
SDL_SetRenderDrawColor(ctx->renderer, r, g, b, a);
|
||||
|
||||
if (value < 0) {
|
||||
SDL_SetRenderDrawColor(ctx->renderer, 8, 200, 16, SDL_ALPHA_OPAQUE);
|
||||
rect.w = ((float)value / SDL_MIN_SINT16) * arrow_extent;
|
||||
rect.w = (value / SDL_MIN_SINT16) * arrow_extent;
|
||||
rect.x = dst.x + arrow_extent - rect.w;
|
||||
rect.y = dst.y + ctx->arrow_height * 0.25f;
|
||||
rect.h = ctx->arrow_height / 2.0f;
|
||||
|
|
@ -1185,7 +1176,7 @@ void RenderGamepadDisplay(GamepadDisplay *ctx, SDL_Gamepad *gamepad)
|
|||
float text_x;
|
||||
|
||||
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 - (FONT_CHARACTER_SIZE * SDL_strlen(binding)) / 2;
|
||||
SDLTest_DrawString(ctx->renderer, text_x, y, binding);
|
||||
}
|
||||
}
|
||||
|
|
@ -1194,7 +1185,7 @@ void RenderGamepadDisplay(GamepadDisplay *ctx, SDL_Gamepad *gamepad)
|
|||
|
||||
if (value > 0) {
|
||||
SDL_SetRenderDrawColor(ctx->renderer, 8, 200, 16, SDL_ALPHA_OPAQUE);
|
||||
rect.w = ((float)value / SDL_MAX_SINT16) * arrow_extent;
|
||||
rect.w = (value / SDL_MAX_SINT16) * arrow_extent;
|
||||
rect.x = dst.x;
|
||||
rect.y = dst.y + ctx->arrow_height * 0.25f;
|
||||
rect.h = ctx->arrow_height / 2.0f;
|
||||
|
|
@ -1206,7 +1197,7 @@ void RenderGamepadDisplay(GamepadDisplay *ctx, SDL_Gamepad *gamepad)
|
|||
float text_x;
|
||||
|
||||
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 - (FONT_CHARACTER_SIZE * SDL_strlen(binding)) / 2;
|
||||
SDLTest_DrawString(ctx->renderer, text_x, y, binding);
|
||||
}
|
||||
}
|
||||
|
|
@ -1247,8 +1238,8 @@ void RenderGamepadDisplay(GamepadDisplay *ctx, SDL_Gamepad *gamepad)
|
|||
|
||||
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;
|
||||
dst.w = ctx->button_width;
|
||||
dst.h = ctx->button_height;
|
||||
SDL_RenderTexture(ctx->renderer, ctx->button_texture, NULL, &dst);
|
||||
|
||||
if (state) {
|
||||
|
|
@ -1319,7 +1310,7 @@ struct GamepadTypeDisplay
|
|||
int type_selected;
|
||||
SDL_GamepadType real_type;
|
||||
|
||||
SDL_Rect area;
|
||||
SDL_FRect area;
|
||||
};
|
||||
|
||||
GamepadTypeDisplay *CreateGamepadTypeDisplay(SDL_Renderer *renderer)
|
||||
|
|
@ -1335,7 +1326,7 @@ GamepadTypeDisplay *CreateGamepadTypeDisplay(SDL_Renderer *renderer)
|
|||
return ctx;
|
||||
}
|
||||
|
||||
void SetGamepadTypeDisplayArea(GamepadTypeDisplay *ctx, const SDL_Rect *area)
|
||||
void SetGamepadTypeDisplayArea(GamepadTypeDisplay *ctx, const SDL_FRect *area)
|
||||
{
|
||||
if (!ctx) {
|
||||
return;
|
||||
|
|
@ -1393,8 +1384,8 @@ int GetGamepadTypeDisplayAt(GamepadTypeDisplay *ctx, float x, float y)
|
|||
for (i = SDL_GAMEPAD_TYPE_UNKNOWN; i < SDL_GAMEPAD_TYPE_MAX; ++i) {
|
||||
highlight.x = x;
|
||||
highlight.y = y;
|
||||
highlight.w = (float)ctx->area.w - (margin * 2);
|
||||
highlight.h = (float)line_height;
|
||||
highlight.w = ctx->area.w - (margin * 2);
|
||||
highlight.h = line_height;
|
||||
|
||||
if (SDL_PointInRectFloat(&point, &highlight)) {
|
||||
return i;
|
||||
|
|
@ -1447,8 +1438,8 @@ void RenderGamepadTypeDisplay(GamepadTypeDisplay *ctx)
|
|||
for (i = SDL_GAMEPAD_TYPE_UNKNOWN; i < SDL_GAMEPAD_TYPE_MAX; ++i) {
|
||||
highlight.x = x;
|
||||
highlight.y = y;
|
||||
highlight.w = (float)ctx->area.w - (margin * 2);
|
||||
highlight.h = (float)line_height;
|
||||
highlight.w = ctx->area.w - (margin * 2);
|
||||
highlight.h = line_height;
|
||||
RenderGamepadTypeHighlight(ctx, i, &highlight);
|
||||
|
||||
if (i == SDL_GAMEPAD_TYPE_UNKNOWN) {
|
||||
|
|
@ -1487,12 +1478,12 @@ struct JoystickDisplay
|
|||
SDL_Renderer *renderer;
|
||||
SDL_Texture *button_texture;
|
||||
SDL_Texture *arrow_texture;
|
||||
int button_width;
|
||||
int button_height;
|
||||
int arrow_width;
|
||||
int arrow_height;
|
||||
float button_width;
|
||||
float button_height;
|
||||
float arrow_width;
|
||||
float arrow_height;
|
||||
|
||||
SDL_Rect area;
|
||||
SDL_FRect area;
|
||||
|
||||
char *element_highlighted;
|
||||
SDL_bool element_pressed;
|
||||
|
|
@ -1505,15 +1496,15 @@ JoystickDisplay *CreateJoystickDisplay(SDL_Renderer *renderer)
|
|||
ctx->renderer = renderer;
|
||||
|
||||
ctx->button_texture = CreateTexture(renderer, gamepad_button_small_bmp, gamepad_button_small_bmp_len);
|
||||
SDL_QueryTexture(ctx->button_texture, NULL, NULL, &ctx->button_width, &ctx->button_height);
|
||||
SDL_GetTextureSize(ctx->button_texture, &ctx->button_width, &ctx->button_height);
|
||||
|
||||
ctx->arrow_texture = CreateTexture(renderer, gamepad_axis_arrow_bmp, gamepad_axis_arrow_bmp_len);
|
||||
SDL_QueryTexture(ctx->arrow_texture, NULL, NULL, &ctx->arrow_width, &ctx->arrow_height);
|
||||
SDL_GetTextureSize(ctx->arrow_texture, &ctx->arrow_width, &ctx->arrow_height);
|
||||
}
|
||||
return ctx;
|
||||
}
|
||||
|
||||
void SetJoystickDisplayArea(JoystickDisplay *ctx, const SDL_Rect *area)
|
||||
void SetJoystickDisplayArea(JoystickDisplay *ctx, const SDL_FRect *area)
|
||||
{
|
||||
if (!ctx) {
|
||||
return;
|
||||
|
|
@ -1543,8 +1534,8 @@ char *GetJoystickDisplayElementAt(JoystickDisplay *ctx, SDL_Joystick *joystick,
|
|||
point.x = x;
|
||||
point.y = y;
|
||||
|
||||
x = (float)ctx->area.x + margin;
|
||||
y = (float)ctx->area.y + margin;
|
||||
x = ctx->area.x + margin;
|
||||
y = ctx->area.y + margin;
|
||||
|
||||
if (nbuttons > 0) {
|
||||
y += FONT_LINE_HEIGHT + 2;
|
||||
|
|
@ -1553,7 +1544,7 @@ char *GetJoystickDisplayElementAt(JoystickDisplay *ctx, SDL_Joystick *joystick,
|
|||
highlight.x = x;
|
||||
highlight.y = y + FONT_CHARACTER_SIZE / 2 - ctx->button_height / 2;
|
||||
highlight.w = center - (margin * 2);
|
||||
highlight.h = (float)ctx->button_height;
|
||||
highlight.h = ctx->button_height;
|
||||
if (SDL_PointInRectFloat(&point, &highlight)) {
|
||||
SDL_asprintf(&element, "b%d", i);
|
||||
return element;
|
||||
|
|
@ -1563,8 +1554,8 @@ char *GetJoystickDisplayElementAt(JoystickDisplay *ctx, SDL_Joystick *joystick,
|
|||
}
|
||||
}
|
||||
|
||||
x = (float)ctx->area.x + margin + center + margin;
|
||||
y = (float)ctx->area.y + margin;
|
||||
x = ctx->area.x + margin + center + margin;
|
||||
y = ctx->area.y + margin;
|
||||
|
||||
if (naxes > 0) {
|
||||
y += FONT_LINE_HEIGHT + 2;
|
||||
|
|
@ -1574,8 +1565,8 @@ char *GetJoystickDisplayElementAt(JoystickDisplay *ctx, SDL_Joystick *joystick,
|
|||
|
||||
highlight.x = x + FONT_CHARACTER_SIZE * SDL_strlen(text) + 2.0f;
|
||||
highlight.y = y + FONT_CHARACTER_SIZE / 2 - ctx->button_height / 2;
|
||||
highlight.w = (float)ctx->arrow_width + arrow_extent;
|
||||
highlight.h = (float)ctx->button_height;
|
||||
highlight.w = ctx->arrow_width + arrow_extent;
|
||||
highlight.h = ctx->button_height;
|
||||
if (SDL_PointInRectFloat(&point, &highlight)) {
|
||||
SDL_asprintf(&element, "-a%d", i);
|
||||
return element;
|
||||
|
|
@ -1601,27 +1592,27 @@ char *GetJoystickDisplayElementAt(JoystickDisplay *ctx, SDL_Joystick *joystick,
|
|||
|
||||
dst.x = x + FONT_CHARACTER_SIZE * SDL_strlen(text) + 2;
|
||||
dst.y = y + FONT_CHARACTER_SIZE / 2 - ctx->button_height / 2;
|
||||
dst.w = (float)ctx->button_width;
|
||||
dst.h = (float)ctx->button_height;
|
||||
dst.w = ctx->button_width;
|
||||
dst.h = ctx->button_height;
|
||||
if (SDL_PointInRectFloat(&point, &dst)) {
|
||||
SDL_asprintf(&element, "h%d.%d", i, SDL_HAT_LEFT);
|
||||
return element;
|
||||
}
|
||||
|
||||
dst.x += (float)ctx->button_width;
|
||||
dst.y -= (float)ctx->button_height;
|
||||
dst.x += ctx->button_width;
|
||||
dst.y -= ctx->button_height;
|
||||
if (SDL_PointInRectFloat(&point, &dst)) {
|
||||
SDL_asprintf(&element, "h%d.%d", i, SDL_HAT_UP);
|
||||
return element;
|
||||
}
|
||||
|
||||
dst.y += (float)ctx->button_height * 2;
|
||||
dst.y += ctx->button_height * 2;
|
||||
if (SDL_PointInRectFloat(&point, &dst)) {
|
||||
SDL_asprintf(&element, "h%d.%d", i, SDL_HAT_DOWN);
|
||||
return element;
|
||||
}
|
||||
|
||||
dst.x += (float)ctx->button_width;
|
||||
dst.x += ctx->button_width;
|
||||
dst.y = y + FONT_CHARACTER_SIZE / 2 - ctx->button_height / 2;
|
||||
if (SDL_PointInRectFloat(&point, &dst)) {
|
||||
SDL_asprintf(&element, "h%d.%d", i, SDL_HAT_RIGHT);
|
||||
|
|
@ -1735,8 +1726,8 @@ void RenderJoystickDisplay(JoystickDisplay *ctx, SDL_Joystick *joystick)
|
|||
|
||||
SDL_GetRenderDrawColor(ctx->renderer, &r, &g, &b, &a);
|
||||
|
||||
x = (float)ctx->area.x + margin;
|
||||
y = (float)ctx->area.y + margin;
|
||||
x = ctx->area.x + margin;
|
||||
y = ctx->area.y + margin;
|
||||
|
||||
if (nbuttons > 0) {
|
||||
SDLTest_DrawString(ctx->renderer, x, y, "BUTTONS");
|
||||
|
|
@ -1746,7 +1737,7 @@ void RenderJoystickDisplay(JoystickDisplay *ctx, SDL_Joystick *joystick)
|
|||
highlight.x = x;
|
||||
highlight.y = y + FONT_CHARACTER_SIZE / 2 - ctx->button_height / 2;
|
||||
highlight.w = center - (margin * 2);
|
||||
highlight.h = (float)ctx->button_height;
|
||||
highlight.h = ctx->button_height;
|
||||
RenderJoystickButtonHighlight(ctx, i, &highlight);
|
||||
|
||||
SDL_snprintf(text, sizeof(text), "%2d:", i);
|
||||
|
|
@ -1760,16 +1751,16 @@ void RenderJoystickDisplay(JoystickDisplay *ctx, SDL_Joystick *joystick)
|
|||
|
||||
dst.x = x + FONT_CHARACTER_SIZE * SDL_strlen(text) + 2;
|
||||
dst.y = y + FONT_CHARACTER_SIZE / 2 - ctx->button_height / 2;
|
||||
dst.w = (float)ctx->button_width;
|
||||
dst.h = (float)ctx->button_height;
|
||||
dst.w = ctx->button_width;
|
||||
dst.h = ctx->button_height;
|
||||
SDL_RenderTexture(ctx->renderer, ctx->button_texture, NULL, &dst);
|
||||
|
||||
y += ctx->button_height + 2;
|
||||
}
|
||||
}
|
||||
|
||||
x = (float)ctx->area.x + margin + center + margin;
|
||||
y = (float)ctx->area.y + margin;
|
||||
x = ctx->area.x + margin + center + margin;
|
||||
y = ctx->area.y + margin;
|
||||
|
||||
if (naxes > 0) {
|
||||
SDLTest_DrawString(ctx->renderer, x, y, "AXES");
|
||||
|
|
@ -1783,8 +1774,8 @@ void RenderJoystickDisplay(JoystickDisplay *ctx, SDL_Joystick *joystick)
|
|||
|
||||
highlight.x = x + FONT_CHARACTER_SIZE * SDL_strlen(text) + 2.0f;
|
||||
highlight.y = y + FONT_CHARACTER_SIZE / 2 - ctx->button_height / 2;
|
||||
highlight.w = (float)ctx->arrow_width + arrow_extent;
|
||||
highlight.h = (float)ctx->button_height;
|
||||
highlight.w = ctx->arrow_width + arrow_extent;
|
||||
highlight.h = ctx->button_height;
|
||||
RenderJoystickAxisHighlight(ctx, i, -1, &highlight);
|
||||
|
||||
highlight.x += highlight.w;
|
||||
|
|
@ -1792,8 +1783,8 @@ void RenderJoystickDisplay(JoystickDisplay *ctx, SDL_Joystick *joystick)
|
|||
|
||||
dst.x = x + FONT_CHARACTER_SIZE * SDL_strlen(text) + 2.0f;
|
||||
dst.y = y + FONT_CHARACTER_SIZE / 2 - ctx->arrow_height / 2;
|
||||
dst.w = (float)ctx->arrow_width;
|
||||
dst.h = (float)ctx->arrow_height;
|
||||
dst.w = ctx->arrow_width;
|
||||
dst.h = ctx->arrow_height;
|
||||
|
||||
if (value == SDL_MIN_SINT16) {
|
||||
SDL_SetTextureColorMod(ctx->arrow_texture, 10, 255, 21);
|
||||
|
|
@ -1802,19 +1793,19 @@ void RenderJoystickDisplay(JoystickDisplay *ctx, SDL_Joystick *joystick)
|
|||
}
|
||||
SDL_RenderTextureRotated(ctx->renderer, ctx->arrow_texture, NULL, &dst, 0.0f, NULL, SDL_FLIP_HORIZONTAL);
|
||||
|
||||
dst.x += (float)ctx->arrow_width;
|
||||
dst.x += ctx->arrow_width;
|
||||
|
||||
SDL_SetRenderDrawColor(ctx->renderer, 200, 200, 200, SDL_ALPHA_OPAQUE);
|
||||
rect.x = dst.x + arrow_extent - 2.0f;
|
||||
rect.y = dst.y;
|
||||
rect.w = 4.0f;
|
||||
rect.h = (float)ctx->arrow_height;
|
||||
rect.h = ctx->arrow_height;
|
||||
SDL_RenderFillRect(ctx->renderer, &rect);
|
||||
SDL_SetRenderDrawColor(ctx->renderer, r, g, b, a);
|
||||
|
||||
if (value < 0) {
|
||||
SDL_SetRenderDrawColor(ctx->renderer, 8, 200, 16, SDL_ALPHA_OPAQUE);
|
||||
rect.w = ((float)value / SDL_MIN_SINT16) * arrow_extent;
|
||||
rect.w = (value / SDL_MIN_SINT16) * arrow_extent;
|
||||
rect.x = dst.x + arrow_extent - rect.w;
|
||||
rect.y = dst.y + ctx->arrow_height * 0.25f;
|
||||
rect.h = ctx->arrow_height / 2.0f;
|
||||
|
|
@ -1825,7 +1816,7 @@ void RenderJoystickDisplay(JoystickDisplay *ctx, SDL_Joystick *joystick)
|
|||
|
||||
if (value > 0) {
|
||||
SDL_SetRenderDrawColor(ctx->renderer, 8, 200, 16, SDL_ALPHA_OPAQUE);
|
||||
rect.w = ((float)value / SDL_MAX_SINT16) * arrow_extent;
|
||||
rect.w = (value / SDL_MAX_SINT16) * arrow_extent;
|
||||
rect.x = dst.x;
|
||||
rect.y = dst.y + ctx->arrow_height * 0.25f;
|
||||
rect.h = ctx->arrow_height / 2.0f;
|
||||
|
|
@ -1867,8 +1858,8 @@ void RenderJoystickDisplay(JoystickDisplay *ctx, SDL_Joystick *joystick)
|
|||
|
||||
dst.x = x + FONT_CHARACTER_SIZE * SDL_strlen(text) + 2;
|
||||
dst.y = y + FONT_CHARACTER_SIZE / 2 - ctx->button_height / 2;
|
||||
dst.w = (float)ctx->button_width;
|
||||
dst.h = (float)ctx->button_height;
|
||||
dst.w = ctx->button_width;
|
||||
dst.h = ctx->button_height;
|
||||
SDL_RenderTexture(ctx->renderer, ctx->button_texture, NULL, &dst);
|
||||
|
||||
if (value & SDL_HAT_UP) {
|
||||
|
|
@ -1877,8 +1868,8 @@ void RenderJoystickDisplay(JoystickDisplay *ctx, SDL_Joystick *joystick)
|
|||
SDL_SetTextureColorMod(ctx->button_texture, 255, 255, 255);
|
||||
}
|
||||
|
||||
dst.x += (float)ctx->button_width;
|
||||
dst.y -= (float)ctx->button_height;
|
||||
dst.x += ctx->button_width;
|
||||
dst.y -= ctx->button_height;
|
||||
SDL_RenderTexture(ctx->renderer, ctx->button_texture, NULL, &dst);
|
||||
|
||||
if (value & SDL_HAT_DOWN) {
|
||||
|
|
@ -1887,7 +1878,7 @@ void RenderJoystickDisplay(JoystickDisplay *ctx, SDL_Joystick *joystick)
|
|||
SDL_SetTextureColorMod(ctx->button_texture, 255, 255, 255);
|
||||
}
|
||||
|
||||
dst.y += (float)ctx->button_height * 2;
|
||||
dst.y += ctx->button_height * 2;
|
||||
SDL_RenderTexture(ctx->renderer, ctx->button_texture, NULL, &dst);
|
||||
|
||||
if (value & SDL_HAT_RIGHT) {
|
||||
|
|
@ -1896,7 +1887,7 @@ void RenderJoystickDisplay(JoystickDisplay *ctx, SDL_Joystick *joystick)
|
|||
SDL_SetTextureColorMod(ctx->button_texture, 255, 255, 255);
|
||||
}
|
||||
|
||||
dst.x += (float)ctx->button_width;
|
||||
dst.x += ctx->button_width;
|
||||
dst.y = y + FONT_CHARACTER_SIZE / 2 - ctx->button_height / 2;
|
||||
SDL_RenderTexture(ctx->renderer, ctx->button_texture, NULL, &dst);
|
||||
|
||||
|
|
@ -1921,14 +1912,14 @@ struct GamepadButton
|
|||
{
|
||||
SDL_Renderer *renderer;
|
||||
SDL_Texture *background;
|
||||
int background_width;
|
||||
int background_height;
|
||||
float background_width;
|
||||
float background_height;
|
||||
|
||||
SDL_FRect area;
|
||||
|
||||
char *label;
|
||||
int label_width;
|
||||
int label_height;
|
||||
float label_width;
|
||||
float label_height;
|
||||
|
||||
SDL_bool highlight;
|
||||
SDL_bool pressed;
|
||||
|
|
@ -1941,37 +1932,32 @@ GamepadButton *CreateGamepadButton(SDL_Renderer *renderer, const char *label)
|
|||
ctx->renderer = renderer;
|
||||
|
||||
ctx->background = CreateTexture(renderer, gamepad_button_background_bmp, gamepad_button_background_bmp_len);
|
||||
SDL_QueryTexture(ctx->background, NULL, NULL, &ctx->background_width, &ctx->background_height);
|
||||
SDL_GetTextureSize(ctx->background, &ctx->background_width, &ctx->background_height);
|
||||
|
||||
ctx->label = SDL_strdup(label);
|
||||
ctx->label_width = (int)(FONT_CHARACTER_SIZE * SDL_strlen(label));
|
||||
ctx->label_height = FONT_CHARACTER_SIZE;
|
||||
ctx->label_width = (FONT_CHARACTER_SIZE * SDL_strlen(label));
|
||||
ctx->label_height = (float)FONT_CHARACTER_SIZE;
|
||||
}
|
||||
return ctx;
|
||||
}
|
||||
|
||||
void SetGamepadButtonArea(GamepadButton *ctx, const SDL_Rect *area)
|
||||
void SetGamepadButtonArea(GamepadButton *ctx, const SDL_FRect *area)
|
||||
{
|
||||
if (!ctx) {
|
||||
return;
|
||||
}
|
||||
|
||||
ctx->area.x = (float)area->x;
|
||||
ctx->area.y = (float)area->y;
|
||||
ctx->area.w = (float)area->w;
|
||||
ctx->area.h = (float)area->h;
|
||||
SDL_copyp(&ctx->area, area);
|
||||
}
|
||||
|
||||
void GetGamepadButtonArea(GamepadButton *ctx, SDL_Rect *area)
|
||||
void GetGamepadButtonArea(GamepadButton *ctx, SDL_FRect *area)
|
||||
{
|
||||
if (!ctx) {
|
||||
SDL_zerop(area);
|
||||
return;
|
||||
}
|
||||
|
||||
area->x = (int)ctx->area.x;
|
||||
area->y = (int)ctx->area.y;
|
||||
area->w = (int)ctx->area.w;
|
||||
area->h = (int)ctx->area.h;
|
||||
SDL_copyp(area, &ctx->area);
|
||||
}
|
||||
|
||||
void SetGamepadButtonHighlight(GamepadButton *ctx, SDL_bool highlight, SDL_bool pressed)
|
||||
|
|
@ -1988,7 +1974,7 @@ void SetGamepadButtonHighlight(GamepadButton *ctx, SDL_bool highlight, SDL_bool
|
|||
}
|
||||
}
|
||||
|
||||
int GetGamepadButtonLabelWidth(GamepadButton *ctx)
|
||||
float GetGamepadButtonLabelWidth(GamepadButton *ctx)
|
||||
{
|
||||
if (!ctx) {
|
||||
return 0;
|
||||
|
|
@ -1997,7 +1983,7 @@ int GetGamepadButtonLabelWidth(GamepadButton *ctx)
|
|||
return ctx->label_width;
|
||||
}
|
||||
|
||||
int GetGamepadButtonLabelHeight(GamepadButton *ctx)
|
||||
float GetGamepadButtonLabelHeight(GamepadButton *ctx)
|
||||
{
|
||||
if (!ctx) {
|
||||
return 0;
|
||||
|
|
@ -2029,8 +2015,8 @@ void RenderGamepadButton(GamepadButton *ctx)
|
|||
return;
|
||||
}
|
||||
|
||||
one_third_src_width = (float)ctx->background_width / 3;
|
||||
one_third_src_height = (float)ctx->background_height / 3;
|
||||
one_third_src_width = ctx->background_width / 3;
|
||||
one_third_src_height = ctx->background_height / 3;
|
||||
|
||||
if (ctx->pressed) {
|
||||
SDL_SetTextureColorMod(ctx->background, PRESSED_TEXTURE_MOD);
|
||||
|
|
@ -2052,12 +2038,12 @@ void RenderGamepadButton(GamepadButton *ctx)
|
|||
SDL_RenderTexture(ctx->renderer, ctx->background, &src, &dst);
|
||||
|
||||
/* Bottom left */
|
||||
src.y = (float)ctx->background_height - src.h;
|
||||
src.y = ctx->background_height - src.h;
|
||||
dst.y = ctx->area.y + ctx->area.h - dst.h;
|
||||
SDL_RenderTexture(ctx->renderer, ctx->background, &src, &dst);
|
||||
|
||||
/* Bottom right */
|
||||
src.x = (float)ctx->background_width - src.w;
|
||||
src.x = ctx->background_width - src.w;
|
||||
dst.x = ctx->area.x + ctx->area.w - dst.w;
|
||||
SDL_RenderTexture(ctx->renderer, ctx->background, &src, &dst);
|
||||
|
||||
|
|
@ -2072,11 +2058,11 @@ void RenderGamepadButton(GamepadButton *ctx)
|
|||
dst.x = ctx->area.x;
|
||||
dst.y = ctx->area.y + one_third_src_height;
|
||||
dst.w = one_third_src_width;
|
||||
dst.h = (float)ctx->area.h - 2 * one_third_src_height;
|
||||
dst.h = ctx->area.h - 2 * one_third_src_height;
|
||||
SDL_RenderTexture(ctx->renderer, ctx->background, &src, &dst);
|
||||
|
||||
/* Right */
|
||||
src.x = (float)ctx->background_width - one_third_src_width;
|
||||
src.x = ctx->background_width - one_third_src_width;
|
||||
dst.x = ctx->area.x + ctx->area.w - one_third_src_width;
|
||||
SDL_RenderTexture(ctx->renderer, ctx->background, &src, &dst);
|
||||
|
||||
|
|
@ -2090,7 +2076,7 @@ void RenderGamepadButton(GamepadButton *ctx)
|
|||
SDL_RenderTexture(ctx->renderer, ctx->background, &src, &dst);
|
||||
|
||||
/* Bottom */
|
||||
src.y = (float)ctx->background_height - src.h;
|
||||
src.y = ctx->background_height - src.h;
|
||||
dst.y = ctx->area.y + ctx->area.h - one_third_src_height;
|
||||
SDL_RenderTexture(ctx->renderer, ctx->background, &src, &dst);
|
||||
|
||||
|
|
@ -2100,7 +2086,7 @@ void RenderGamepadButton(GamepadButton *ctx)
|
|||
dst.x = ctx->area.x + one_third_src_width;
|
||||
dst.y = ctx->area.y + one_third_src_height;
|
||||
dst.w = ctx->area.w - 2 * one_third_src_width;
|
||||
dst.h = (float)ctx->area.h - 2 * one_third_src_height;
|
||||
dst.h = ctx->area.h - 2 * one_third_src_height;
|
||||
SDL_RenderTexture(ctx->renderer, ctx->background, &src, &dst);
|
||||
|
||||
/* Label */
|
||||
|
|
|
|||
|
|
@ -52,17 +52,16 @@ enum
|
|||
/* Gamepad image display */
|
||||
|
||||
extern GamepadImage *CreateGamepadImage(SDL_Renderer *renderer);
|
||||
extern void SetGamepadImagePosition(GamepadImage *ctx, int x, int y);
|
||||
extern void GetGamepadImageArea(GamepadImage *ctx, SDL_Rect *area);
|
||||
extern void GetGamepadTouchpadArea(GamepadImage *ctx, SDL_Rect *area);
|
||||
extern void SetGamepadImagePosition(GamepadImage *ctx, float x, float y);
|
||||
extern void GetGamepadImageArea(GamepadImage *ctx, SDL_FRect *area);
|
||||
extern void GetGamepadTouchpadArea(GamepadImage *ctx, SDL_FRect *area);
|
||||
extern void SetGamepadImageShowingFront(GamepadImage *ctx, SDL_bool showing_front);
|
||||
extern void SetGamepadImageType(GamepadImage *ctx, SDL_GamepadType type);
|
||||
extern SDL_GamepadType GetGamepadImageType(GamepadImage *ctx);
|
||||
extern void SetGamepadImageDisplayMode(GamepadImage *ctx, ControllerDisplayMode display_mode);
|
||||
extern int GetGamepadImageButtonWidth(GamepadImage *ctx);
|
||||
extern int GetGamepadImageButtonHeight(GamepadImage *ctx);
|
||||
extern int GetGamepadImageAxisWidth(GamepadImage *ctx);
|
||||
extern int GetGamepadImageAxisHeight(GamepadImage *ctx);
|
||||
extern float GetGamepadImageButtonWidth(GamepadImage *ctx);
|
||||
extern float GetGamepadImageButtonHeight(GamepadImage *ctx);
|
||||
extern float GetGamepadImageAxisWidth(GamepadImage *ctx);
|
||||
extern float GetGamepadImageAxisHeight(GamepadImage *ctx);
|
||||
extern int GetGamepadImageElementAt(GamepadImage *ctx, float x, float y);
|
||||
|
||||
extern void ClearGamepadImage(GamepadImage *ctx);
|
||||
|
|
@ -78,7 +77,7 @@ typedef struct GamepadDisplay GamepadDisplay;
|
|||
|
||||
extern GamepadDisplay *CreateGamepadDisplay(SDL_Renderer *renderer);
|
||||
extern void SetGamepadDisplayDisplayMode(GamepadDisplay *ctx, ControllerDisplayMode display_mode);
|
||||
extern void SetGamepadDisplayArea(GamepadDisplay *ctx, const SDL_Rect *area);
|
||||
extern void SetGamepadDisplayArea(GamepadDisplay *ctx, const SDL_FRect *area);
|
||||
extern int GetGamepadDisplayElementAt(GamepadDisplay *ctx, SDL_Gamepad *gamepad, float x, float y);
|
||||
extern void SetGamepadDisplayHighlight(GamepadDisplay *ctx, int element, SDL_bool pressed);
|
||||
extern void SetGamepadDisplaySelected(GamepadDisplay *ctx, int element);
|
||||
|
|
@ -95,7 +94,7 @@ enum
|
|||
typedef struct GamepadTypeDisplay GamepadTypeDisplay;
|
||||
|
||||
extern GamepadTypeDisplay *CreateGamepadTypeDisplay(SDL_Renderer *renderer);
|
||||
extern void SetGamepadTypeDisplayArea(GamepadTypeDisplay *ctx, const SDL_Rect *area);
|
||||
extern void SetGamepadTypeDisplayArea(GamepadTypeDisplay *ctx, const SDL_FRect *area);
|
||||
extern int GetGamepadTypeDisplayAt(GamepadTypeDisplay *ctx, float x, float y);
|
||||
extern void SetGamepadTypeDisplayHighlight(GamepadTypeDisplay *ctx, int type, SDL_bool pressed);
|
||||
extern void SetGamepadTypeDisplaySelected(GamepadTypeDisplay *ctx, int type);
|
||||
|
|
@ -108,7 +107,7 @@ extern void DestroyGamepadTypeDisplay(GamepadTypeDisplay *ctx);
|
|||
typedef struct JoystickDisplay JoystickDisplay;
|
||||
|
||||
extern JoystickDisplay *CreateJoystickDisplay(SDL_Renderer *renderer);
|
||||
extern void SetJoystickDisplayArea(JoystickDisplay *ctx, const SDL_Rect *area);
|
||||
extern void SetJoystickDisplayArea(JoystickDisplay *ctx, const SDL_FRect *area);
|
||||
extern char *GetJoystickDisplayElementAt(JoystickDisplay *ctx, SDL_Joystick *joystick, float x, float y);
|
||||
extern void SetJoystickDisplayHighlight(JoystickDisplay *ctx, const char *element, SDL_bool pressed);
|
||||
extern void RenderJoystickDisplay(JoystickDisplay *ctx, SDL_Joystick *joystick);
|
||||
|
|
@ -119,11 +118,11 @@ extern void DestroyJoystickDisplay(JoystickDisplay *ctx);
|
|||
typedef struct GamepadButton GamepadButton;
|
||||
|
||||
extern GamepadButton *CreateGamepadButton(SDL_Renderer *renderer, const char *label);
|
||||
extern void SetGamepadButtonArea(GamepadButton *ctx, const SDL_Rect *area);
|
||||
extern void GetGamepadButtonArea(GamepadButton *ctx, SDL_Rect *area);
|
||||
extern void SetGamepadButtonArea(GamepadButton *ctx, const SDL_FRect *area);
|
||||
extern void GetGamepadButtonArea(GamepadButton *ctx, SDL_FRect *area);
|
||||
extern void SetGamepadButtonHighlight(GamepadButton *ctx, SDL_bool highlight, SDL_bool pressed);
|
||||
extern int GetGamepadButtonLabelWidth(GamepadButton *ctx);
|
||||
extern int GetGamepadButtonLabelHeight(GamepadButton *ctx);
|
||||
extern float GetGamepadButtonLabelWidth(GamepadButton *ctx);
|
||||
extern float GetGamepadButtonLabelHeight(GamepadButton *ctx);
|
||||
extern SDL_bool GamepadButtonContains(GamepadButton *ctx, float x, float y);
|
||||
extern void RenderGamepadButton(GamepadButton *ctx);
|
||||
extern void DestroyGamepadButton(GamepadButton *ctx);
|
||||
|
|
|
|||
|
|
@ -155,7 +155,7 @@ static int render_testPrimitives(void *arg)
|
|||
checkFailCount1++;
|
||||
}
|
||||
|
||||
ret = SDL_RenderPoint(renderer, (float)x, (float)y);
|
||||
ret = SDL_RenderPoint(renderer, x, y);
|
||||
if (ret != 0) {
|
||||
checkFailCount2++;
|
||||
}
|
||||
|
|
@ -166,7 +166,7 @@ static int render_testPrimitives(void *arg)
|
|||
|
||||
/* Draw some lines. */
|
||||
CHECK_FUNC(SDL_SetRenderDrawColor, (renderer, 0, 255, 0, SDL_ALPHA_OPAQUE))
|
||||
CHECK_FUNC(SDL_RenderLine, (renderer, 0.0f, 30.0f, (float)TESTRENDER_SCREEN_W, 30.0f))
|
||||
CHECK_FUNC(SDL_RenderLine, (renderer, 0.0f, 30.0f, TESTRENDER_SCREEN_W, 30.0f))
|
||||
CHECK_FUNC(SDL_SetRenderDrawColor, (renderer, 55, 55, 5, SDL_ALPHA_OPAQUE))
|
||||
CHECK_FUNC(SDL_RenderLine, (renderer, 40.0f, 30.0f, 40.0f, 60.0f))
|
||||
CHECK_FUNC(SDL_SetRenderDrawColor, (renderer, 5, 105, 105, SDL_ALPHA_OPAQUE))
|
||||
|
|
@ -258,7 +258,7 @@ static int render_testPrimitivesBlend(void *arg)
|
|||
checkFailCount2++;
|
||||
}
|
||||
|
||||
ret = SDL_RenderLine(renderer, 0.0f, 0.0f, (float)i, 59.0f);
|
||||
ret = SDL_RenderLine(renderer, 0.0f, 0.0f, i, 59.0f);
|
||||
if (ret != 0) {
|
||||
checkFailCount3++;
|
||||
}
|
||||
|
|
@ -282,7 +282,7 @@ static int render_testPrimitivesBlend(void *arg)
|
|||
checkFailCount2++;
|
||||
}
|
||||
|
||||
ret = SDL_RenderLine(renderer, 0.0f, 0.0f, 79.0f, (float)i);
|
||||
ret = SDL_RenderLine(renderer, 0.0f, 0.0f, 79.0f, i);
|
||||
if (ret != 0) {
|
||||
checkFailCount3++;
|
||||
}
|
||||
|
|
@ -308,7 +308,7 @@ static int render_testPrimitivesBlend(void *arg)
|
|||
checkFailCount2++;
|
||||
}
|
||||
|
||||
ret = SDL_RenderPoint(renderer, (float)i, (float)j);
|
||||
ret = SDL_RenderPoint(renderer, i, j);
|
||||
if (ret != 0) {
|
||||
checkFailCount3++;
|
||||
}
|
||||
|
|
@ -342,7 +342,7 @@ static int render_testPrimitivesBlend(void *arg)
|
|||
*/
|
||||
static int render_testPrimitivesWithViewport(void *arg)
|
||||
{
|
||||
SDL_Rect viewport;
|
||||
SDL_FRect viewport;
|
||||
SDL_Surface *surface;
|
||||
|
||||
/* Clear surface. */
|
||||
|
|
@ -388,9 +388,8 @@ static int render_testBlit(void *arg)
|
|||
SDL_FRect rect;
|
||||
SDL_Texture *tface;
|
||||
SDL_Surface *referenceSurface = NULL;
|
||||
SDL_PixelFormatEnum tformat;
|
||||
int taccess, tw, th;
|
||||
int i, j, ni, nj;
|
||||
float tw, th;
|
||||
float i, j, ni, nj;
|
||||
int checkFailCount1;
|
||||
|
||||
/* Clear surface. */
|
||||
|
|
@ -407,9 +406,9 @@ static int render_testBlit(void *arg)
|
|||
}
|
||||
|
||||
/* Constant values. */
|
||||
CHECK_FUNC(SDL_QueryTexture, (tface, &tformat, &taccess, &tw, &th))
|
||||
rect.w = (float)tw;
|
||||
rect.h = (float)th;
|
||||
CHECK_FUNC(SDL_GetTextureSize, (tface, &tw, &th))
|
||||
rect.w = tw;
|
||||
rect.h = th;
|
||||
ni = TESTRENDER_SCREEN_W - tw;
|
||||
nj = TESTRENDER_SCREEN_H - th;
|
||||
|
||||
|
|
@ -418,8 +417,8 @@ static int render_testBlit(void *arg)
|
|||
for (j = 0; j <= nj; j += 4) {
|
||||
for (i = 0; i <= ni; i += 4) {
|
||||
/* Blitting. */
|
||||
rect.x = (float)i;
|
||||
rect.y = (float)j;
|
||||
rect.x = i;
|
||||
rect.y = j;
|
||||
ret = SDL_RenderTexture(renderer, tface, NULL, &rect);
|
||||
if (ret != 0) {
|
||||
checkFailCount1++;
|
||||
|
|
@ -456,8 +455,7 @@ static int render_testBlitColor(void *arg)
|
|||
SDL_FRect rect;
|
||||
SDL_Texture *tface;
|
||||
SDL_Surface *referenceSurface = NULL;
|
||||
SDL_PixelFormatEnum tformat;
|
||||
int taccess, tw, th;
|
||||
float tw, th;
|
||||
int i, j, ni, nj;
|
||||
int checkFailCount1;
|
||||
int checkFailCount2;
|
||||
|
|
@ -473,11 +471,11 @@ static int render_testBlitColor(void *arg)
|
|||
}
|
||||
|
||||
/* Constant values. */
|
||||
CHECK_FUNC(SDL_QueryTexture, (tface, &tformat, &taccess, &tw, &th))
|
||||
rect.w = (float)tw;
|
||||
rect.h = (float)th;
|
||||
ni = TESTRENDER_SCREEN_W - tw;
|
||||
nj = TESTRENDER_SCREEN_H - th;
|
||||
CHECK_FUNC(SDL_GetTextureSize, (tface, &tw, &th))
|
||||
rect.w = tw;
|
||||
rect.h = th;
|
||||
ni = TESTRENDER_SCREEN_W - (int)tw;
|
||||
nj = TESTRENDER_SCREEN_H - (int)th;
|
||||
|
||||
/* Test blitting with color mod. */
|
||||
checkFailCount1 = 0;
|
||||
|
|
@ -491,8 +489,8 @@ static int render_testBlitColor(void *arg)
|
|||
}
|
||||
|
||||
/* Blitting. */
|
||||
rect.x = (float)i;
|
||||
rect.y = (float)j;
|
||||
rect.x = i;
|
||||
rect.y = j;
|
||||
ret = SDL_RenderTexture(renderer, tface, NULL, &rect);
|
||||
if (ret != 0) {
|
||||
checkFailCount2++;
|
||||
|
|
@ -530,9 +528,8 @@ static int render_testBlitAlpha(void *arg)
|
|||
SDL_FRect rect;
|
||||
SDL_Texture *tface;
|
||||
SDL_Surface *referenceSurface = NULL;
|
||||
SDL_PixelFormatEnum tformat;
|
||||
int taccess, tw, th;
|
||||
int i, j, ni, nj;
|
||||
float tw, th;
|
||||
float i, j, ni, nj;
|
||||
int checkFailCount1;
|
||||
int checkFailCount2;
|
||||
|
||||
|
|
@ -550,9 +547,9 @@ static int render_testBlitAlpha(void *arg)
|
|||
}
|
||||
|
||||
/* Constant values. */
|
||||
CHECK_FUNC(SDL_QueryTexture, (tface, &tformat, &taccess, &tw, &th))
|
||||
rect.w = (float)tw;
|
||||
rect.h = (float)th;
|
||||
CHECK_FUNC(SDL_GetTextureSize, (tface, &tw, &th))
|
||||
rect.w = tw;
|
||||
rect.h = th;
|
||||
ni = TESTRENDER_SCREEN_W - tw;
|
||||
nj = TESTRENDER_SCREEN_H - th;
|
||||
|
||||
|
|
@ -568,8 +565,8 @@ static int render_testBlitAlpha(void *arg)
|
|||
}
|
||||
|
||||
/* Blitting. */
|
||||
rect.x = (float)i;
|
||||
rect.y = (float)j;
|
||||
rect.x = i;
|
||||
rect.y = j;
|
||||
ret = SDL_RenderTexture(renderer, tface, NULL, &rect);
|
||||
if (ret != 0) {
|
||||
checkFailCount2++;
|
||||
|
|
@ -604,9 +601,8 @@ static void
|
|||
testBlitBlendMode(SDL_Texture *tface, int mode)
|
||||
{
|
||||
int ret;
|
||||
SDL_PixelFormatEnum tformat;
|
||||
int taccess, tw, th;
|
||||
int i, j, ni, nj;
|
||||
float tw, th;
|
||||
float i, j, ni, nj;
|
||||
SDL_FRect rect;
|
||||
int checkFailCount1;
|
||||
int checkFailCount2;
|
||||
|
|
@ -615,9 +611,9 @@ testBlitBlendMode(SDL_Texture *tface, int mode)
|
|||
clearScreen();
|
||||
|
||||
/* Constant values. */
|
||||
CHECK_FUNC(SDL_QueryTexture, (tface, &tformat, &taccess, &tw, &th))
|
||||
rect.w = (float)tw;
|
||||
rect.h = (float)th;
|
||||
CHECK_FUNC(SDL_GetTextureSize, (tface, &tw, &th))
|
||||
rect.w = tw;
|
||||
rect.h = th;
|
||||
ni = TESTRENDER_SCREEN_W - tw;
|
||||
nj = TESTRENDER_SCREEN_H - th;
|
||||
|
||||
|
|
@ -633,8 +629,8 @@ testBlitBlendMode(SDL_Texture *tface, int mode)
|
|||
}
|
||||
|
||||
/* Blitting. */
|
||||
rect.x = (float)i;
|
||||
rect.y = (float)j;
|
||||
rect.x = i;
|
||||
rect.y = j;
|
||||
ret = SDL_RenderTexture(renderer, tface, NULL, &rect);
|
||||
if (ret != 0) {
|
||||
checkFailCount2++;
|
||||
|
|
@ -659,8 +655,7 @@ static int render_testBlitBlend(void *arg)
|
|||
SDL_FRect rect;
|
||||
SDL_Texture *tface;
|
||||
SDL_Surface *referenceSurface = NULL;
|
||||
SDL_PixelFormatEnum tformat;
|
||||
int taccess, tw, th;
|
||||
float tw, th;
|
||||
int i, j, ni, nj;
|
||||
int mode;
|
||||
int checkFailCount1;
|
||||
|
|
@ -680,11 +675,11 @@ static int render_testBlitBlend(void *arg)
|
|||
}
|
||||
|
||||
/* Constant values. */
|
||||
CHECK_FUNC(SDL_QueryTexture, (tface, &tformat, &taccess, &tw, &th))
|
||||
rect.w = (float)tw;
|
||||
rect.h = (float)th;
|
||||
ni = TESTRENDER_SCREEN_W - tw;
|
||||
nj = TESTRENDER_SCREEN_H - th;
|
||||
CHECK_FUNC(SDL_GetTextureSize, (tface, &tw, &th))
|
||||
rect.w = tw;
|
||||
rect.h = th;
|
||||
ni = TESTRENDER_SCREEN_W - (int)tw;
|
||||
nj = TESTRENDER_SCREEN_H - (int)th;
|
||||
|
||||
/* Set alpha mod. */
|
||||
CHECK_FUNC(SDL_SetTextureAlphaMod, (tface, 100))
|
||||
|
|
@ -757,7 +752,7 @@ static int render_testBlitBlend(void *arg)
|
|||
}
|
||||
|
||||
/* Crazy blending mode magic. */
|
||||
mode = (i / 4 * j / 4) % 4;
|
||||
mode = (int)(i / 4 * j / 4) % 4;
|
||||
if (mode == 0) {
|
||||
mode = SDL_BLENDMODE_NONE;
|
||||
} else if (mode == 1) {
|
||||
|
|
@ -773,8 +768,8 @@ static int render_testBlitBlend(void *arg)
|
|||
}
|
||||
|
||||
/* Blitting. */
|
||||
rect.x = (float)i;
|
||||
rect.y = (float)j;
|
||||
rect.x = i;
|
||||
rect.y = j;
|
||||
ret = SDL_RenderTexture(renderer, tface, NULL, &rect);
|
||||
if (ret != 0) {
|
||||
checkFailCount4++;
|
||||
|
|
@ -808,7 +803,7 @@ static int render_testBlitBlend(void *arg)
|
|||
static int render_testViewport(void *arg)
|
||||
{
|
||||
SDL_Surface *referenceSurface;
|
||||
SDL_Rect viewport;
|
||||
SDL_FRect viewport;
|
||||
|
||||
viewport.x = TESTRENDER_SCREEN_W / 3;
|
||||
viewport.y = TESTRENDER_SCREEN_H / 3;
|
||||
|
|
@ -818,7 +813,12 @@ static int render_testViewport(void *arg)
|
|||
/* Create expected result */
|
||||
referenceSurface = SDL_CreateSurface(TESTRENDER_SCREEN_W, TESTRENDER_SCREEN_H, RENDER_COMPARE_FORMAT);
|
||||
CHECK_FUNC(SDL_FillSurfaceRect, (referenceSurface, NULL, RENDER_COLOR_CLEAR))
|
||||
CHECK_FUNC(SDL_FillSurfaceRect, (referenceSurface, &viewport, RENDER_COLOR_GREEN))
|
||||
SDL_Rect v;
|
||||
v.x = (int)viewport.x;
|
||||
v.y = (int)viewport.y;
|
||||
v.w = (int)viewport.w;
|
||||
v.h = (int)viewport.h;
|
||||
CHECK_FUNC(SDL_FillSurfaceRect, (referenceSurface, &v, RENDER_COLOR_GREEN))
|
||||
|
||||
/* Clear surface. */
|
||||
clearScreen();
|
||||
|
|
@ -865,7 +865,7 @@ static int render_testViewport(void *arg)
|
|||
static int render_testClipRect(void *arg)
|
||||
{
|
||||
SDL_Surface *referenceSurface;
|
||||
SDL_Rect cliprect;
|
||||
SDL_FRect cliprect;
|
||||
|
||||
cliprect.x = TESTRENDER_SCREEN_W / 3;
|
||||
cliprect.y = TESTRENDER_SCREEN_H / 3;
|
||||
|
|
@ -875,7 +875,12 @@ static int render_testClipRect(void *arg)
|
|||
/* Create expected result */
|
||||
referenceSurface = SDL_CreateSurface(TESTRENDER_SCREEN_W, TESTRENDER_SCREEN_H, RENDER_COMPARE_FORMAT);
|
||||
CHECK_FUNC(SDL_FillSurfaceRect, (referenceSurface, NULL, RENDER_COLOR_CLEAR))
|
||||
CHECK_FUNC(SDL_FillSurfaceRect, (referenceSurface, &cliprect, RENDER_COLOR_GREEN))
|
||||
SDL_Rect c;
|
||||
c.x = (int)cliprect.x;
|
||||
c.y = (int)cliprect.y;
|
||||
c.w = (int)cliprect.w;
|
||||
c.h = (int)cliprect.h;
|
||||
CHECK_FUNC(SDL_FillSurfaceRect, (referenceSurface, &c, RENDER_COLOR_GREEN))
|
||||
|
||||
/* Clear surface. */
|
||||
clearScreen();
|
||||
|
|
@ -922,9 +927,9 @@ static int render_testClipRect(void *arg)
|
|||
static int render_testLogicalSize(void *arg)
|
||||
{
|
||||
SDL_Surface *referenceSurface;
|
||||
SDL_Rect viewport;
|
||||
SDL_FRect viewport;
|
||||
SDL_FRect rect;
|
||||
int w, h;
|
||||
float w, h;
|
||||
const int factor = 2;
|
||||
|
||||
viewport.x = ((TESTRENDER_SCREEN_W / 4) / factor) * factor;
|
||||
|
|
@ -935,7 +940,12 @@ static int render_testLogicalSize(void *arg)
|
|||
/* Create expected result */
|
||||
referenceSurface = SDL_CreateSurface(TESTRENDER_SCREEN_W, TESTRENDER_SCREEN_H, RENDER_COMPARE_FORMAT);
|
||||
CHECK_FUNC(SDL_FillSurfaceRect, (referenceSurface, NULL, RENDER_COLOR_CLEAR))
|
||||
CHECK_FUNC(SDL_FillSurfaceRect, (referenceSurface, &viewport, RENDER_COLOR_GREEN))
|
||||
SDL_Rect v;
|
||||
v.x = (int)viewport.x;
|
||||
v.y = (int)viewport.y;
|
||||
v.w = (int)viewport.w;
|
||||
v.h = (int)viewport.h;
|
||||
CHECK_FUNC(SDL_FillSurfaceRect, (referenceSurface, &v, RENDER_COLOR_GREEN))
|
||||
|
||||
/* Clear surface. */
|
||||
clearScreen();
|
||||
|
|
@ -946,10 +956,10 @@ static int render_testLogicalSize(void *arg)
|
|||
SDL_LOGICAL_PRESENTATION_LETTERBOX,
|
||||
SDL_SCALEMODE_NEAREST))
|
||||
CHECK_FUNC(SDL_SetRenderDrawColor, (renderer, 0, 255, 0, SDL_ALPHA_OPAQUE))
|
||||
rect.x = (float)viewport.x / factor;
|
||||
rect.y = (float)viewport.y / factor;
|
||||
rect.w = (float)viewport.w / factor;
|
||||
rect.h = (float)viewport.h / factor;
|
||||
rect.x = viewport.x / factor;
|
||||
rect.y = viewport.y / factor;
|
||||
rect.w = viewport.w / factor;
|
||||
rect.h = viewport.h / factor;
|
||||
CHECK_FUNC(SDL_RenderFillRect, (renderer, &rect))
|
||||
CHECK_FUNC(SDL_SetRenderLogicalPresentation, (renderer, 0, 0,
|
||||
SDL_LOGICAL_PRESENTATION_DISABLED,
|
||||
|
|
@ -992,7 +1002,11 @@ static int render_testLogicalSize(void *arg)
|
|||
|
||||
/* Create expected result */
|
||||
CHECK_FUNC(SDL_FillSurfaceRect, (referenceSurface, NULL, RENDER_COLOR_CLEAR))
|
||||
CHECK_FUNC(SDL_FillSurfaceRect, (referenceSurface, &viewport, RENDER_COLOR_GREEN))
|
||||
v.x = (int)viewport.x;
|
||||
v.y = (int)viewport.y;
|
||||
v.w = (int)viewport.w;
|
||||
v.h = (int)viewport.h;
|
||||
CHECK_FUNC(SDL_FillSurfaceRect, (referenceSurface, &v, RENDER_COLOR_GREEN))
|
||||
|
||||
/* Clear surface. */
|
||||
clearScreen();
|
||||
|
|
|
|||
|
|
@ -234,7 +234,7 @@ int SDL_AppIterate(void *appstate)
|
|||
SDL_SetRenderDrawColor(renderer, 0x99, 0x99, 0x99, 255);
|
||||
SDL_RenderClear(renderer);
|
||||
|
||||
int win_w, win_h, tw, th;
|
||||
float win_w, win_h, tw, th;
|
||||
SDL_FRect d;
|
||||
Uint64 timestampNS = 0;
|
||||
SDL_Surface *frame_next = camera ? SDL_AcquireCameraFrame(camera, ×tampNS) : NULL;
|
||||
|
|
@ -261,8 +261,8 @@ int SDL_AppIterate(void *appstate)
|
|||
|
||||
if (frame_current) {
|
||||
if (!texture ||
|
||||
SDL_QueryTexture(texture, NULL, NULL, &tw, &th) < 0 ||
|
||||
tw != frame_current->w || th != frame_current->h) {
|
||||
SDL_GetTextureSize(texture, &tw, &th) < 0 ||
|
||||
(int)tw != frame_current->w || (int)th != frame_current->h) {
|
||||
/* Resize the window to match */
|
||||
SDL_SetWindowSize(window, frame_current->w, frame_current->h);
|
||||
|
||||
|
|
@ -284,12 +284,12 @@ int SDL_AppIterate(void *appstate)
|
|||
texture_updated = SDL_TRUE;
|
||||
}
|
||||
|
||||
SDL_QueryTexture(texture, NULL, NULL, &tw, &th);
|
||||
SDL_GetTextureSize(texture, &tw, &th);
|
||||
SDL_GetRenderOutputSize(renderer, &win_w, &win_h);
|
||||
d.x = (float) ((win_w - tw) / 2);
|
||||
d.y = (float) ((win_h - th) / 2);
|
||||
d.w = (float) tw;
|
||||
d.h = (float) th;
|
||||
d.x = ((win_w - tw) / 2);
|
||||
d.y = ((win_h - th) / 2);
|
||||
d.w = tw;
|
||||
d.h = th;
|
||||
SDL_RenderTexture(renderer, texture, NULL, &d);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -28,14 +28,14 @@
|
|||
#define DEBUG_AXIS_MAPPING
|
||||
#endif
|
||||
|
||||
#define TITLE_HEIGHT 48
|
||||
#define PANEL_SPACING 25
|
||||
#define PANEL_WIDTH 250
|
||||
#define MINIMUM_BUTTON_WIDTH 96
|
||||
#define BUTTON_MARGIN 16
|
||||
#define BUTTON_PADDING 12
|
||||
#define GAMEPAD_WIDTH 512
|
||||
#define GAMEPAD_HEIGHT 560
|
||||
#define TITLE_HEIGHT 48.0f
|
||||
#define PANEL_SPACING 25.0f
|
||||
#define PANEL_WIDTH 250.0f
|
||||
#define MINIMUM_BUTTON_WIDTH 96.0f
|
||||
#define BUTTON_MARGIN 16.0f
|
||||
#define BUTTON_PADDING 12.0f
|
||||
#define GAMEPAD_WIDTH 512.0f
|
||||
#define GAMEPAD_HEIGHT 560.0f
|
||||
|
||||
#define SCREEN_WIDTH (PANEL_WIDTH + PANEL_SPACING + GAMEPAD_WIDTH + PANEL_SPACING + PANEL_WIDTH)
|
||||
#define SCREEN_HEIGHT (TITLE_HEIGHT + GAMEPAD_HEIGHT)
|
||||
|
|
@ -1245,7 +1245,7 @@ static void VirtualGamepadMouseMotion(float x, float y)
|
|||
}
|
||||
|
||||
if (virtual_touchpad_active) {
|
||||
SDL_Rect touchpad;
|
||||
SDL_FRect touchpad;
|
||||
GetGamepadTouchpadArea(image, &touchpad);
|
||||
virtual_touchpad_x = (x - touchpad.x) / touchpad.w;
|
||||
virtual_touchpad_y = (y - touchpad.y) / touchpad.h;
|
||||
|
|
@ -1258,10 +1258,10 @@ static void VirtualGamepadMouseDown(float x, float y)
|
|||
int element = GetGamepadImageElementAt(image, x, y);
|
||||
|
||||
if (element == SDL_GAMEPAD_ELEMENT_INVALID) {
|
||||
SDL_Point point = { (int)x, (int)y };
|
||||
SDL_Rect touchpad;
|
||||
SDL_FPoint point = { x, y };
|
||||
SDL_FRect touchpad;
|
||||
GetGamepadTouchpadArea(image, &touchpad);
|
||||
if (SDL_PointInRect(&point, &touchpad)) {
|
||||
if (SDL_PointInRectFloat(&point, &touchpad)) {
|
||||
virtual_touchpad_active = SDL_TRUE;
|
||||
virtual_touchpad_x = (x - touchpad.x) / touchpad.w;
|
||||
virtual_touchpad_y = (y - touchpad.y) / touchpad.h;
|
||||
|
|
@ -1328,8 +1328,8 @@ static void DrawGamepadWaiting(SDL_Renderer *renderer)
|
|||
const char *text = "Waiting for gamepad, press A to add a virtual controller";
|
||||
float x, y;
|
||||
|
||||
x = (float)SCREEN_WIDTH / 2 - (FONT_CHARACTER_SIZE * SDL_strlen(text)) / 2;
|
||||
y = (float)TITLE_HEIGHT / 2 - FONT_CHARACTER_SIZE / 2;
|
||||
x = SCREEN_WIDTH / 2 - (FONT_CHARACTER_SIZE * SDL_strlen(text)) / 2;
|
||||
y = TITLE_HEIGHT / 2 - FONT_CHARACTER_SIZE / 2;
|
||||
SDLTest_DrawString(renderer, x, y, text);
|
||||
}
|
||||
|
||||
|
|
@ -1372,7 +1372,7 @@ static void DrawGamepadInfo(SDL_Renderer *renderer)
|
|||
|
||||
if (controller->joystick) {
|
||||
SDL_snprintf(text, sizeof(text), "(%" SDL_PRIu32 ")", SDL_GetJoystickInstanceID(controller->joystick));
|
||||
x = (float)SCREEN_WIDTH - (FONT_CHARACTER_SIZE * SDL_strlen(text)) - 8.0f;
|
||||
x = SCREEN_WIDTH - (FONT_CHARACTER_SIZE * SDL_strlen(text)) - 8.0f;
|
||||
y = 8.0f;
|
||||
SDLTest_DrawString(renderer, x, y, text);
|
||||
}
|
||||
|
|
@ -1385,8 +1385,8 @@ static void DrawGamepadInfo(SDL_Renderer *renderer)
|
|||
|
||||
if (SDL_IsJoystickVirtual(controller->id)) {
|
||||
SDL_strlcpy(text, "Click on the gamepad image below to generate input", sizeof(text));
|
||||
x = (float)SCREEN_WIDTH / 2 - (FONT_CHARACTER_SIZE * SDL_strlen(text)) / 2;
|
||||
y = (float)TITLE_HEIGHT / 2 - FONT_CHARACTER_SIZE / 2 + FONT_LINE_HEIGHT + 2.0f;
|
||||
x = SCREEN_WIDTH / 2 - (FONT_CHARACTER_SIZE * SDL_strlen(text)) / 2;
|
||||
y = TITLE_HEIGHT / 2 - FONT_CHARACTER_SIZE / 2 + FONT_LINE_HEIGHT + 2.0f;
|
||||
SDLTest_DrawString(renderer, x, y, text);
|
||||
}
|
||||
|
||||
|
|
@ -1399,23 +1399,23 @@ static void DrawGamepadInfo(SDL_Renderer *renderer)
|
|||
Uint64 steam_handle = SDL_GetGamepadSteamHandle(controller->gamepad);
|
||||
if (steam_handle) {
|
||||
SDL_snprintf(text, SDL_arraysize(text), "Steam: 0x%.16" SDL_PRIx64, steam_handle);
|
||||
y = (float)SCREEN_HEIGHT - 2 * (8.0f + FONT_LINE_HEIGHT);
|
||||
x = (float)SCREEN_WIDTH - 8.0f - (FONT_CHARACTER_SIZE * SDL_strlen(text));
|
||||
y = SCREEN_HEIGHT - 2 * (8.0f + FONT_LINE_HEIGHT);
|
||||
x = SCREEN_WIDTH - 8.0f - (FONT_CHARACTER_SIZE * SDL_strlen(text));
|
||||
SDLTest_DrawString(renderer, x, y, text);
|
||||
}
|
||||
|
||||
SDL_snprintf(text, SDL_arraysize(text), "VID: 0x%.4x PID: 0x%.4x",
|
||||
SDL_GetJoystickVendor(controller->joystick),
|
||||
SDL_GetJoystickProduct(controller->joystick));
|
||||
y = (float)SCREEN_HEIGHT - 8.0f - FONT_LINE_HEIGHT;
|
||||
x = (float)SCREEN_WIDTH - 8.0f - (FONT_CHARACTER_SIZE * SDL_strlen(text));
|
||||
y = SCREEN_HEIGHT - 8.0f - FONT_LINE_HEIGHT;
|
||||
x = SCREEN_WIDTH - 8.0f - (FONT_CHARACTER_SIZE * SDL_strlen(text));
|
||||
SDLTest_DrawString(renderer, x, y, text);
|
||||
|
||||
serial = SDL_GetJoystickSerial(controller->joystick);
|
||||
if (serial && *serial) {
|
||||
SDL_snprintf(text, SDL_arraysize(text), "Serial: %s", serial);
|
||||
x = (float)SCREEN_WIDTH / 2 - (FONT_CHARACTER_SIZE * SDL_strlen(text)) / 2;
|
||||
y = (float)SCREEN_HEIGHT - 8.0f - FONT_LINE_HEIGHT;
|
||||
x = SCREEN_WIDTH / 2 - (FONT_CHARACTER_SIZE * SDL_strlen(text)) / 2;
|
||||
y = SCREEN_HEIGHT - 8.0f - FONT_LINE_HEIGHT;
|
||||
SDLTest_DrawString(renderer, x, y, text);
|
||||
}
|
||||
}
|
||||
|
|
@ -1448,8 +1448,8 @@ static const char *GetButtonLabel(SDL_GamepadType type, SDL_GamepadButton button
|
|||
static void DrawBindingTips(SDL_Renderer *renderer)
|
||||
{
|
||||
const char *text;
|
||||
SDL_Rect image_area, button_area;
|
||||
int x, y;
|
||||
SDL_FRect image_area, button_area;
|
||||
float x, y;
|
||||
|
||||
GetGamepadImageArea(image, &image_area);
|
||||
GetGamepadButtonArea(done_mapping_button, &button_area);
|
||||
|
|
@ -1460,7 +1460,7 @@ static void DrawBindingTips(SDL_Renderer *renderer)
|
|||
text = GetBindingInstruction();
|
||||
|
||||
if (binding_element == SDL_GAMEPAD_ELEMENT_INVALID) {
|
||||
SDLTest_DrawString(renderer, (float)x - (FONT_CHARACTER_SIZE * SDL_strlen(text)) / 2, (float)y, text);
|
||||
SDLTest_DrawString(renderer, x - (FONT_CHARACTER_SIZE * SDL_strlen(text)) / 2, y, text);
|
||||
} else {
|
||||
Uint8 r, g, b, a;
|
||||
SDL_FRect rect;
|
||||
|
|
@ -1475,14 +1475,14 @@ static void DrawBindingTips(SDL_Renderer *renderer)
|
|||
|
||||
rect.w = 2.0f + (FONT_CHARACTER_SIZE * SDL_strlen(text)) + 2.0f;
|
||||
rect.h = 2.0f + FONT_CHARACTER_SIZE + 2.0f;
|
||||
rect.x = (float)x - rect.w / 2;
|
||||
rect.y = (float)y - 2.0f;
|
||||
rect.x = x - rect.w / 2;
|
||||
rect.y = y - 2.0f;
|
||||
|
||||
SDL_GetRenderDrawColor(renderer, &r, &g, &b, &a);
|
||||
SDL_SetRenderDrawColor(renderer, SELECTED_COLOR);
|
||||
SDL_RenderFillRect(renderer, &rect);
|
||||
SDL_SetRenderDrawColor(renderer, r, g, b, a);
|
||||
SDLTest_DrawString(renderer, (float)x - (FONT_CHARACTER_SIZE * SDL_strlen(text)) / 2, (float)y, text);
|
||||
SDLTest_DrawString(renderer, x - (FONT_CHARACTER_SIZE * SDL_strlen(text)) / 2, y, text);
|
||||
|
||||
y += (FONT_CHARACTER_SIZE + BUTTON_MARGIN);
|
||||
|
||||
|
|
@ -1506,7 +1506,7 @@ static void DrawBindingTips(SDL_Renderer *renderer)
|
|||
text = "(press SPACE to delete and ESC to cancel)";
|
||||
}
|
||||
}
|
||||
SDLTest_DrawString(renderer, (float)x - (FONT_CHARACTER_SIZE * SDL_strlen(text)) / 2, (float)y, text);
|
||||
SDLTest_DrawString(renderer, x - (FONT_CHARACTER_SIZE * SDL_strlen(text)) / 2, y, text);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1988,7 +1988,7 @@ int main(int argc, char *argv[])
|
|||
int i;
|
||||
float content_scale;
|
||||
int screen_width, screen_height;
|
||||
SDL_Rect area;
|
||||
SDL_FRect area;
|
||||
int gamepad_index = -1;
|
||||
SDLTest_CommonState *state;
|
||||
|
||||
|
|
@ -2090,15 +2090,15 @@ int main(int argc, char *argv[])
|
|||
SDL_SCALEMODE_LINEAR);
|
||||
|
||||
|
||||
title_area.w = (float)GAMEPAD_WIDTH;
|
||||
title_area.h = (float)FONT_CHARACTER_SIZE + 2 * BUTTON_MARGIN;
|
||||
title_area.x = (float)PANEL_WIDTH + PANEL_SPACING;
|
||||
title_area.y = (float)TITLE_HEIGHT / 2 - title_area.h / 2;
|
||||
title_area.w = GAMEPAD_WIDTH;
|
||||
title_area.h = FONT_CHARACTER_SIZE + 2 * BUTTON_MARGIN;
|
||||
title_area.x = PANEL_WIDTH + PANEL_SPACING;
|
||||
title_area.y = TITLE_HEIGHT / 2 - title_area.h / 2;
|
||||
|
||||
type_area.w = (float)PANEL_WIDTH - 2 * BUTTON_MARGIN;
|
||||
type_area.h = (float)FONT_CHARACTER_SIZE + 2 * BUTTON_MARGIN;
|
||||
type_area.x = (float)BUTTON_MARGIN;
|
||||
type_area.y = (float)TITLE_HEIGHT / 2 - type_area.h / 2;
|
||||
type_area.w = PANEL_WIDTH - 2 * BUTTON_MARGIN;
|
||||
type_area.h = FONT_CHARACTER_SIZE + 2 * BUTTON_MARGIN;
|
||||
type_area.x = BUTTON_MARGIN;
|
||||
type_area.y = TITLE_HEIGHT / 2 - type_area.h / 2;
|
||||
|
||||
image = CreateGamepadImage(screen);
|
||||
if (!image) {
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ static void DrawPoints(SDL_Renderer *renderer)
|
|||
{
|
||||
int i;
|
||||
float x, y;
|
||||
SDL_Rect viewport;
|
||||
SDL_FRect viewport;
|
||||
|
||||
/* Query the sizes */
|
||||
SDL_GetRenderViewport(renderer, &viewport);
|
||||
|
|
@ -75,8 +75,8 @@ static void DrawPoints(SDL_Renderer *renderer)
|
|||
SDL_SetRenderDrawColor(renderer, 255, (Uint8)current_color,
|
||||
(Uint8)current_color, (Uint8)current_alpha);
|
||||
|
||||
x = (float)(rand() % viewport.w);
|
||||
y = (float)(rand() % viewport.h);
|
||||
x = (float)(rand() % (int)viewport.w);
|
||||
y = (float)(rand() % (int)viewport.h);
|
||||
SDL_RenderPoint(renderer, x, y);
|
||||
}
|
||||
}
|
||||
|
|
@ -85,7 +85,7 @@ static void DrawLines(SDL_Renderer *renderer)
|
|||
{
|
||||
int i;
|
||||
float x1, y1, x2, y2;
|
||||
SDL_Rect viewport;
|
||||
SDL_FRect viewport;
|
||||
|
||||
/* Query the sizes */
|
||||
SDL_GetRenderViewport(renderer, &viewport);
|
||||
|
|
@ -118,15 +118,15 @@ static void DrawLines(SDL_Renderer *renderer)
|
|||
(Uint8)current_color, (Uint8)current_alpha);
|
||||
|
||||
if (i == 0) {
|
||||
SDL_RenderLine(renderer, 0.0f, 0.0f, (float)(viewport.w - 1), (float)(viewport.h - 1));
|
||||
SDL_RenderLine(renderer, 0.0f, (float)(viewport.h - 1), (float)(viewport.w - 1), 0.0f);
|
||||
SDL_RenderLine(renderer, 0.0f, (float)(viewport.h / 2), (float)(viewport.w - 1), (float)(viewport.h / 2));
|
||||
SDL_RenderLine(renderer, (float)(viewport.w / 2), 0.0f, (float)(viewport.w / 2), (float)(viewport.h - 1));
|
||||
SDL_RenderLine(renderer, 0.0f, 0.0f, (viewport.w - 1), (viewport.h - 1));
|
||||
SDL_RenderLine(renderer, 0.0f, (viewport.h - 1), (viewport.w - 1), 0.0f);
|
||||
SDL_RenderLine(renderer, 0.0f, (viewport.h / 2), (viewport.w - 1), (viewport.h / 2));
|
||||
SDL_RenderLine(renderer, (viewport.w / 2), 0.0f, (viewport.w / 2), (viewport.h - 1));
|
||||
} else {
|
||||
x1 = (float)((rand() % (viewport.w * 2)) - viewport.w);
|
||||
x2 = (float)((rand() % (viewport.w * 2)) - viewport.w);
|
||||
y1 = (float)((rand() % (viewport.h * 2)) - viewport.h);
|
||||
y2 = (float)((rand() % (viewport.h * 2)) - viewport.h);
|
||||
x1 = ((rand() % ((int)viewport.w * 2)) - viewport.w);
|
||||
x2 = ((rand() % ((int)viewport.w * 2)) - viewport.w);
|
||||
y1 = ((rand() % ((int)viewport.h * 2)) - viewport.h);
|
||||
y2 = ((rand() % ((int)viewport.h * 2)) - viewport.h);
|
||||
SDL_RenderLine(renderer, x1, y1, x2, y2);
|
||||
}
|
||||
}
|
||||
|
|
@ -136,7 +136,7 @@ static void DrawRects(SDL_Renderer *renderer)
|
|||
{
|
||||
int i;
|
||||
SDL_FRect rect;
|
||||
SDL_Rect viewport;
|
||||
SDL_FRect viewport;
|
||||
|
||||
/* Query the sizes */
|
||||
SDL_GetRenderViewport(renderer, &viewport);
|
||||
|
|
@ -168,10 +168,10 @@ static void DrawRects(SDL_Renderer *renderer)
|
|||
SDL_SetRenderDrawColor(renderer, 255, (Uint8)current_color,
|
||||
(Uint8)current_color, (Uint8)current_alpha);
|
||||
|
||||
rect.w = (float)(rand() % (viewport.h / 2));
|
||||
rect.h = (float)(rand() % (viewport.h / 2));
|
||||
rect.x = (float)((rand() % (viewport.w * 2) - viewport.w) - (rect.w / 2));
|
||||
rect.y = (float)((rand() % (viewport.h * 2) - viewport.h) - (rect.h / 2));
|
||||
rect.w = (float)(rand() % ((int)viewport.h / 2));
|
||||
rect.h = (float)(rand() % ((int)viewport.h / 2));
|
||||
rect.x = ((rand() % ((int)viewport.w * 2) - viewport.w) - (rect.w / 2));
|
||||
rect.y = ((rand() % ((int)viewport.h * 2) - viewport.h) - (rect.h / 2));
|
||||
SDL_RenderFillRect(renderer, &rect);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ static void DrawChessBoard(void)
|
|||
{
|
||||
int row = 0, column = 0, x = 0;
|
||||
SDL_FRect rect;
|
||||
SDL_Rect darea;
|
||||
SDL_FRect darea;
|
||||
|
||||
/* Get the Size of drawing surface */
|
||||
SDL_GetRenderViewport(renderer, &darea);
|
||||
|
|
@ -43,10 +43,10 @@ static void DrawChessBoard(void)
|
|||
for (; column < 4 + (row % 2); column++) {
|
||||
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0xFF);
|
||||
|
||||
rect.w = (float)(darea.w / 8);
|
||||
rect.h = (float)(darea.h / 8);
|
||||
rect.x = (float)(x * rect.w);
|
||||
rect.y = (float)(row * rect.h);
|
||||
rect.w = (darea.w / 8);
|
||||
rect.h = (darea.h / 8);
|
||||
rect.x = (x * rect.w);
|
||||
rect.y = (row * rect.h);
|
||||
x = x + 2;
|
||||
SDL_RenderFillRect(renderer, &rect);
|
||||
|
||||
|
|
|
|||
|
|
@ -252,7 +252,7 @@ static SDL_Texture *CreateTexture(SDL_Renderer *r, unsigned char *data, unsigned
|
|||
|
||||
static void MoveSprite(void)
|
||||
{
|
||||
SDL_Rect viewport;
|
||||
SDL_FRect viewport;
|
||||
SDL_FRect *position, *velocity;
|
||||
int i;
|
||||
|
||||
|
|
@ -578,7 +578,10 @@ static SDL_bool GetTextureForMemoryFrame(AVFrame *frame, SDL_Texture **texture)
|
|||
SDL_PixelFormatEnum frame_format = GetTextureFormat(frame->format);
|
||||
|
||||
if (*texture) {
|
||||
SDL_QueryTexture(*texture, &texture_format, NULL, &texture_width, &texture_height);
|
||||
SDL_PropertiesID props = SDL_GetTextureProperties(*texture);
|
||||
texture_format = (SDL_PixelFormatEnum)SDL_GetNumberProperty(props, SDL_PROP_TEXTURE_FORMAT_NUMBER, SDL_PIXELFORMAT_UNKNOWN);
|
||||
texture_width = (int)SDL_GetNumberProperty(props, SDL_PROP_TEXTURE_WIDTH_NUMBER, 0);
|
||||
texture_height = (int)SDL_GetNumberProperty(props, SDL_PROP_TEXTURE_HEIGHT_NUMBER, 0);
|
||||
}
|
||||
if (!*texture || texture_width != frame->width || texture_height != frame->height ||
|
||||
(frame_format != SDL_PIXELFORMAT_UNKNOWN && texture_format != frame_format) ||
|
||||
|
|
@ -976,7 +979,9 @@ static SDL_bool GetTextureForD3D11Frame(AVFrame *frame, SDL_Texture **texture)
|
|||
UINT iSliceIndex = (UINT)(uintptr_t)frame->data[1];
|
||||
|
||||
if (*texture) {
|
||||
SDL_QueryTexture(*texture, NULL, NULL, &texture_width, &texture_height);
|
||||
SDL_PropertiesID props = SDL_GetTextureProperties(*texture);
|
||||
texture_width = (int)SDL_GetNumberProperty(props, SDL_PROP_TEXTURE_WIDTH_NUMBER, 0);
|
||||
texture_height = (int)SDL_GetNumberProperty(props, SDL_PROP_TEXTURE_HEIGHT_NUMBER, 0);
|
||||
}
|
||||
if (!*texture || texture_width != frames->width || texture_height != frames->height) {
|
||||
if (*texture) {
|
||||
|
|
@ -1479,12 +1484,12 @@ int main(int argc, char *argv[])
|
|||
}
|
||||
|
||||
/* Position sprites and set their velocities */
|
||||
SDL_Rect viewport;
|
||||
SDL_FRect viewport;
|
||||
SDL_GetRenderViewport(renderer, &viewport);
|
||||
srand((unsigned int)time(NULL));
|
||||
for (i = 0; i < num_sprites; ++i) {
|
||||
positions[i].x = (float)(rand() % (viewport.w - sprite_w));
|
||||
positions[i].y = (float)(rand() % (viewport.h - sprite_h));
|
||||
positions[i].x = (float)(rand() % (int)(viewport.w - sprite_w));
|
||||
positions[i].y = (float)(rand() % (int)(viewport.h - sprite_h));
|
||||
positions[i].w = (float)sprite_w;
|
||||
positions[i].h = (float)sprite_h;
|
||||
velocities[i].x = 0.0f;
|
||||
|
|
|
|||
|
|
@ -121,11 +121,11 @@ static void loop(void)
|
|||
SDL_RenderClear(renderer);
|
||||
|
||||
{
|
||||
SDL_Rect viewport;
|
||||
SDL_FRect viewport;
|
||||
SDL_Vertex verts[3];
|
||||
float a;
|
||||
float d;
|
||||
int cx, cy;
|
||||
float cx, cy;
|
||||
|
||||
/* Query the sizes */
|
||||
SDL_GetRenderViewport(renderer, &viewport);
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ static void DrawPoints(SDL_Renderer *renderer)
|
|||
{
|
||||
int i;
|
||||
float x, y;
|
||||
SDL_Rect viewport;
|
||||
SDL_FRect viewport;
|
||||
|
||||
/* Query the sizes */
|
||||
SDL_GetRenderViewport(renderer, &viewport);
|
||||
|
|
@ -77,8 +77,8 @@ static void DrawPoints(SDL_Renderer *renderer)
|
|||
SDL_SetRenderDrawColor(renderer, 255, (Uint8)current_color,
|
||||
(Uint8)current_color, (Uint8)current_alpha);
|
||||
|
||||
x = (float)(rand() % viewport.w);
|
||||
y = (float)(rand() % viewport.h);
|
||||
x = (float)(rand() % (int)viewport.w);
|
||||
y = (float)(rand() % (int)viewport.h);
|
||||
SDL_RenderPoint(renderer, x, y);
|
||||
}
|
||||
}
|
||||
|
|
@ -107,7 +107,7 @@ static int add_line(float x1, float y1, float x2, float y2)
|
|||
static void DrawLines(SDL_Renderer *renderer)
|
||||
{
|
||||
int i;
|
||||
SDL_Rect viewport;
|
||||
SDL_FRect viewport;
|
||||
|
||||
/* Query the sizes */
|
||||
SDL_GetRenderViewport(renderer, &viewport);
|
||||
|
|
@ -116,10 +116,10 @@ static void DrawLines(SDL_Renderer *renderer)
|
|||
|
||||
for (i = 0; i < num_lines; ++i) {
|
||||
if (i == -1) {
|
||||
SDL_RenderLine(renderer, 0.0f, 0.0f, (float)(viewport.w - 1), (float)(viewport.h - 1));
|
||||
SDL_RenderLine(renderer, 0.0f, (float)(viewport.h - 1), (float)(viewport.w - 1), 0.0f);
|
||||
SDL_RenderLine(renderer, 0.0f, (float)(viewport.h / 2), (float)(viewport.w - 1), (float)(viewport.h / 2));
|
||||
SDL_RenderLine(renderer, (float)(viewport.w / 2), 0.0f, (float)(viewport.w / 2), (float)(viewport.h - 1));
|
||||
SDL_RenderLine(renderer, 0.0f, 0.0f, (viewport.w - 1), (viewport.h - 1));
|
||||
SDL_RenderLine(renderer, 0.0f, (viewport.h - 1), (viewport.w - 1), 0.0f);
|
||||
SDL_RenderLine(renderer, 0.0f, (viewport.h / 2), (viewport.w - 1), (viewport.h / 2));
|
||||
SDL_RenderLine(renderer, (viewport.w / 2), 0.0f, (viewport.w / 2), (viewport.h - 1));
|
||||
} else {
|
||||
SDL_RenderLine(renderer, lines[i].x, lines[i].y, lines[i].w, lines[i].h);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -63,14 +63,14 @@ quit(int rc)
|
|||
|
||||
static void MoveSprites(SDL_Renderer *renderer, SDL_Texture *sprite)
|
||||
{
|
||||
int sprite_w, sprite_h;
|
||||
float sprite_w, sprite_h;
|
||||
int i;
|
||||
SDL_Rect viewport;
|
||||
SDL_FRect viewport;
|
||||
SDL_FRect *position, *velocity;
|
||||
|
||||
/* Query the sizes */
|
||||
SDL_GetRenderViewport(renderer, &viewport);
|
||||
SDL_QueryTexture(sprite, NULL, NULL, &sprite_w, &sprite_h);
|
||||
SDL_GetTextureSize(sprite, &sprite_w, &sprite_h);
|
||||
|
||||
/* Draw a gray background */
|
||||
SDL_SetRenderDrawColor(renderer, 0xA0, 0xA0, 0xA0, 0xFF);
|
||||
|
|
@ -108,7 +108,7 @@ int main(int argc, char *argv[])
|
|||
SDL_Renderer *renderer;
|
||||
SDL_Texture *sprite;
|
||||
int window_w, window_h;
|
||||
int sprite_w, sprite_h;
|
||||
float sprite_w, sprite_h;
|
||||
SDL_Event event;
|
||||
|
||||
/* Initialize test framework */
|
||||
|
|
@ -181,7 +181,7 @@ int main(int argc, char *argv[])
|
|||
|
||||
/* Allocate memory for the sprite info */
|
||||
SDL_GetWindowSize(window, &window_w, &window_h);
|
||||
SDL_QueryTexture(sprite, NULL, NULL, &sprite_w, &sprite_h);
|
||||
SDL_GetTextureSize(sprite, &sprite_w, &sprite_h);
|
||||
positions = (SDL_FRect *)SDL_malloc(NUM_SPRITES * sizeof(*positions));
|
||||
velocities = (SDL_FRect *)SDL_malloc(NUM_SPRITES * sizeof(*velocities));
|
||||
if (!positions || !velocities) {
|
||||
|
|
@ -190,10 +190,10 @@ int main(int argc, char *argv[])
|
|||
}
|
||||
srand((unsigned int)time(NULL));
|
||||
for (i = 0; i < NUM_SPRITES; ++i) {
|
||||
positions[i].x = (float)(rand() % (window_w - sprite_w));
|
||||
positions[i].y = (float)(rand() % (window_h - sprite_h));
|
||||
positions[i].w = (float)sprite_w;
|
||||
positions[i].h = (float)sprite_h;
|
||||
positions[i].x = (float)(rand() % (window_w - (int)sprite_w));
|
||||
positions[i].y = (float)(rand() % (window_h - (int)sprite_h));
|
||||
positions[i].w = sprite_w;
|
||||
positions[i].h = sprite_h;
|
||||
velocities[i].x = 0.0f;
|
||||
velocities[i].y = 0.0f;
|
||||
while (velocities[i].x == 0.f && velocities[i].y == 0.f) {
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ static void loop(void)
|
|||
}
|
||||
}
|
||||
for (i = 0; i < state->num_windows; ++i) {
|
||||
SDL_Rect viewport;
|
||||
SDL_FRect viewport;
|
||||
SDL_Renderer *renderer = state->renderers[i];
|
||||
if (state->windows[i] == NULL) {
|
||||
continue;
|
||||
|
|
|
|||
|
|
@ -49,14 +49,14 @@ quit(int rc)
|
|||
|
||||
static void Draw(DrawState *s)
|
||||
{
|
||||
SDL_Rect viewport;
|
||||
SDL_FRect viewport;
|
||||
SDL_Texture *target;
|
||||
SDL_FPoint *center = NULL;
|
||||
SDL_FPoint origin = { 0.0f, 0.0f };
|
||||
|
||||
SDL_GetRenderViewport(s->renderer, &viewport);
|
||||
|
||||
target = SDL_CreateTexture(s->renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_TARGET, viewport.w, viewport.h);
|
||||
target = SDL_CreateTexture(s->renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_TARGET, (int)viewport.w, (int)viewport.h);
|
||||
SDL_SetRenderTarget(s->renderer, target);
|
||||
|
||||
/* Draw the background */
|
||||
|
|
@ -75,8 +75,8 @@ static void Draw(DrawState *s)
|
|||
s->scale_direction = 1;
|
||||
}
|
||||
}
|
||||
s->sprite_rect.x = (float)((viewport.w - s->sprite_rect.w) / 2);
|
||||
s->sprite_rect.y = (float)((viewport.h - s->sprite_rect.h) / 2);
|
||||
s->sprite_rect.x = ((viewport.w - s->sprite_rect.w) / 2);
|
||||
s->sprite_rect.y = ((viewport.h - s->sprite_rect.h) / 2);
|
||||
|
||||
SDL_RenderTextureRotated(s->renderer, s->sprite, NULL, &s->sprite_rect, (double)s->sprite_rect.w, center, SDL_FLIP_NONE);
|
||||
|
||||
|
|
@ -135,7 +135,7 @@ int main(int argc, char *argv[])
|
|||
drawstates = SDL_stack_alloc(DrawState, state->num_windows);
|
||||
for (i = 0; i < state->num_windows; ++i) {
|
||||
DrawState *drawstate = &drawstates[i];
|
||||
int w, h;
|
||||
float w, h;
|
||||
|
||||
drawstate->window = state->windows[i];
|
||||
drawstate->renderer = state->renderers[i];
|
||||
|
|
@ -144,9 +144,9 @@ int main(int argc, char *argv[])
|
|||
if (!drawstate->sprite || !drawstate->background) {
|
||||
quit(2);
|
||||
}
|
||||
SDL_QueryTexture(drawstate->sprite, NULL, NULL, &w, &h);
|
||||
drawstate->sprite_rect.w = (float)w;
|
||||
drawstate->sprite_rect.h = (float)h;
|
||||
SDL_GetTextureSize(drawstate->sprite, &w, &h);
|
||||
drawstate->sprite_rect.w = w;
|
||||
drawstate->sprite_rect.h = h;
|
||||
drawstate->scale_direction = 1;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ quit(int rc)
|
|||
static SDL_bool
|
||||
DrawComposite(DrawState *s)
|
||||
{
|
||||
SDL_Rect viewport;
|
||||
SDL_FRect viewport;
|
||||
SDL_FRect R;
|
||||
SDL_Texture *target;
|
||||
SDL_Surface *surface;
|
||||
|
|
@ -91,7 +91,7 @@ DrawComposite(DrawState *s)
|
|||
|
||||
SDL_GetRenderViewport(s->renderer, &viewport);
|
||||
|
||||
target = SDL_CreateTexture(s->renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_TARGET, viewport.w, viewport.h);
|
||||
target = SDL_CreateTexture(s->renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_TARGET, (int)viewport.w, (int)viewport.h);
|
||||
SDL_SetTextureBlendMode(target, SDL_BLENDMODE_BLEND);
|
||||
SDL_SetRenderTarget(s->renderer, target);
|
||||
|
||||
|
|
@ -113,8 +113,8 @@ DrawComposite(DrawState *s)
|
|||
s->scale_direction = 1;
|
||||
}
|
||||
}
|
||||
s->sprite_rect.x = (float)((viewport.w - s->sprite_rect.w) / 2);
|
||||
s->sprite_rect.y = (float)((viewport.h - s->sprite_rect.h) / 2);
|
||||
s->sprite_rect.x = ((viewport.w - s->sprite_rect.w) / 2);
|
||||
s->sprite_rect.y = ((viewport.h - s->sprite_rect.h) / 2);
|
||||
|
||||
SDL_RenderTexture(s->renderer, s->sprite, NULL, &s->sprite_rect);
|
||||
|
||||
|
|
@ -141,12 +141,12 @@ DrawComposite(DrawState *s)
|
|||
static SDL_bool
|
||||
Draw(DrawState *s)
|
||||
{
|
||||
SDL_Rect viewport;
|
||||
SDL_FRect viewport;
|
||||
SDL_Texture *target;
|
||||
|
||||
SDL_GetRenderViewport(s->renderer, &viewport);
|
||||
|
||||
target = SDL_CreateTexture(s->renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_TARGET, viewport.w, viewport.h);
|
||||
target = SDL_CreateTexture(s->renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_TARGET, (int)viewport.w, (int)viewport.h);
|
||||
if (!target) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create render target texture: %s\n", SDL_GetError());
|
||||
return SDL_FALSE;
|
||||
|
|
@ -168,8 +168,8 @@ Draw(DrawState *s)
|
|||
s->scale_direction = 1;
|
||||
}
|
||||
}
|
||||
s->sprite_rect.x = (float)((viewport.w - s->sprite_rect.w) / 2);
|
||||
s->sprite_rect.y = (float)((viewport.h - s->sprite_rect.h) / 2);
|
||||
s->sprite_rect.x = ((viewport.w - s->sprite_rect.w) / 2);
|
||||
s->sprite_rect.y = ((viewport.h - s->sprite_rect.h) / 2);
|
||||
|
||||
SDL_RenderTexture(s->renderer, s->sprite, NULL, &s->sprite_rect);
|
||||
|
||||
|
|
@ -251,7 +251,7 @@ int main(int argc, char *argv[])
|
|||
drawstates = SDL_stack_alloc(DrawState, state->num_windows);
|
||||
for (i = 0; i < state->num_windows; ++i) {
|
||||
DrawState *drawstate = &drawstates[i];
|
||||
int w, h;
|
||||
float w, h;
|
||||
|
||||
drawstate->window = state->windows[i];
|
||||
drawstate->renderer = state->renderers[i];
|
||||
|
|
@ -264,9 +264,9 @@ int main(int argc, char *argv[])
|
|||
if (!drawstate->sprite || !drawstate->background) {
|
||||
quit(2);
|
||||
}
|
||||
SDL_QueryTexture(drawstate->sprite, NULL, NULL, &w, &h);
|
||||
drawstate->sprite_rect.w = (float)w;
|
||||
drawstate->sprite_rect.h = (float)h;
|
||||
SDL_GetTextureSize(drawstate->sprite, &w, &h);
|
||||
drawstate->sprite_rect.w = w;
|
||||
drawstate->sprite_rect.h = h;
|
||||
drawstate->scale_direction = 1;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ quit(int rc)
|
|||
|
||||
static void Draw(DrawState *s)
|
||||
{
|
||||
SDL_Rect viewport;
|
||||
SDL_FRect viewport;
|
||||
|
||||
SDL_GetRenderViewport(s->renderer, &viewport);
|
||||
|
||||
|
|
@ -68,8 +68,8 @@ static void Draw(DrawState *s)
|
|||
s->scale_direction = 1;
|
||||
}
|
||||
}
|
||||
s->sprite_rect.x = (float)((viewport.w - s->sprite_rect.w) / 2);
|
||||
s->sprite_rect.y = (float)((viewport.h - s->sprite_rect.h) / 2);
|
||||
s->sprite_rect.x = ((viewport.w - s->sprite_rect.w) / 2);
|
||||
s->sprite_rect.y = ((viewport.h - s->sprite_rect.h) / 2);
|
||||
|
||||
SDL_RenderTexture(s->renderer, s->sprite, NULL, &s->sprite_rect);
|
||||
|
||||
|
|
@ -126,7 +126,7 @@ int main(int argc, char *argv[])
|
|||
drawstates = SDL_stack_alloc(DrawState, state->num_windows);
|
||||
for (i = 0; i < state->num_windows; ++i) {
|
||||
DrawState *drawstate = &drawstates[i];
|
||||
int w, h;
|
||||
float w, h;
|
||||
|
||||
drawstate->window = state->windows[i];
|
||||
drawstate->renderer = state->renderers[i];
|
||||
|
|
@ -135,9 +135,9 @@ int main(int argc, char *argv[])
|
|||
if (!drawstate->sprite || !drawstate->background) {
|
||||
quit(2);
|
||||
}
|
||||
SDL_QueryTexture(drawstate->sprite, NULL, NULL, &w, &h);
|
||||
drawstate->sprite_rect.w = (float)w;
|
||||
drawstate->sprite_rect.h = (float)h;
|
||||
SDL_GetTextureSize(drawstate->sprite, &w, &h);
|
||||
drawstate->sprite_rect.w = w;
|
||||
drawstate->sprite_rect.h = h;
|
||||
drawstate->scale_direction = 1;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -79,7 +79,7 @@ static int LoadSprite(const char *file)
|
|||
static void MoveSprites(SDL_Renderer *renderer, SDL_Texture *sprite)
|
||||
{
|
||||
int i;
|
||||
SDL_Rect viewport;
|
||||
SDL_FRect viewport;
|
||||
SDL_FRect temp;
|
||||
SDL_FRect *position, *velocity;
|
||||
|
||||
|
|
@ -120,9 +120,9 @@ static void MoveSprites(SDL_Renderer *renderer, SDL_Texture *sprite)
|
|||
/* Test points */
|
||||
SDL_SetRenderDrawColor(renderer, 0xFF, 0x00, 0x00, 0xFF);
|
||||
SDL_RenderPoint(renderer, 0.0f, 0.0f);
|
||||
SDL_RenderPoint(renderer, (float)(viewport.w - 1), 0.0f);
|
||||
SDL_RenderPoint(renderer, 0.0f, (float)(viewport.h - 1));
|
||||
SDL_RenderPoint(renderer, (float)(viewport.w - 1), (float)(viewport.h - 1));
|
||||
SDL_RenderPoint(renderer, (viewport.w - 1), 0.0f);
|
||||
SDL_RenderPoint(renderer, 0.0f, (viewport.h - 1));
|
||||
SDL_RenderPoint(renderer, (viewport.w - 1), (viewport.h - 1));
|
||||
|
||||
/* Test horizontal and vertical lines */
|
||||
SDL_SetRenderDrawColor(renderer, 0x00, 0xFF, 0x00, 0xFF);
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@
|
|||
|
||||
static SDLTest_CommonState *state;
|
||||
|
||||
static SDL_Rect viewport;
|
||||
static SDL_FRect viewport;
|
||||
static int done, j;
|
||||
static SDL_bool use_target = SDL_FALSE;
|
||||
#ifdef SDL_PLATFORM_EMSCRIPTEN
|
||||
|
|
@ -47,8 +47,8 @@ quit(int rc)
|
|||
static void DrawOnViewport(SDL_Renderer *renderer)
|
||||
{
|
||||
SDL_FRect rect;
|
||||
SDL_Rect cliprect;
|
||||
int w, h;
|
||||
SDL_FRect cliprect;
|
||||
float w, h;
|
||||
|
||||
/* Set the viewport */
|
||||
SDL_SetRenderViewport(renderer, &viewport);
|
||||
|
|
@ -59,47 +59,47 @@ static void DrawOnViewport(SDL_Renderer *renderer)
|
|||
|
||||
/* Test inside points */
|
||||
SDL_SetRenderDrawColor(renderer, 0xFF, 0xFF, 0x00, 0xFF);
|
||||
SDL_RenderPoint(renderer, (float)(viewport.h / 2 + 20), (float)(viewport.w / 2));
|
||||
SDL_RenderPoint(renderer, (float)(viewport.h / 2 - 20), (float)(viewport.w / 2));
|
||||
SDL_RenderPoint(renderer, (float)(viewport.h / 2), (float)(viewport.w / 2 - 20));
|
||||
SDL_RenderPoint(renderer, (float)(viewport.h / 2), (float)(viewport.w / 2 + 20));
|
||||
SDL_RenderPoint(renderer, (viewport.h / 2 + 20), (viewport.w / 2));
|
||||
SDL_RenderPoint(renderer, (viewport.h / 2 - 20), (viewport.w / 2));
|
||||
SDL_RenderPoint(renderer, (viewport.h / 2), (viewport.w / 2 - 20));
|
||||
SDL_RenderPoint(renderer, (viewport.h / 2), (viewport.w / 2 + 20));
|
||||
|
||||
/* Test horizontal and vertical lines */
|
||||
SDL_SetRenderDrawColor(renderer, 0x00, 0xFF, 0x00, 0xFF);
|
||||
SDL_RenderLine(renderer, 1.0f, 0.0f, (float)(viewport.w - 2), 0.0f);
|
||||
SDL_RenderLine(renderer, 1.0f, (float)(viewport.h - 1), (float)(viewport.w - 2), (float)(viewport.h - 1));
|
||||
SDL_RenderLine(renderer, 0.0f, 1.0f, 0.0f, (float)(viewport.h - 2));
|
||||
SDL_RenderLine(renderer, (float)(viewport.w - 1), 1.0f, (float)(viewport.w - 1), (float)(viewport.h - 2));
|
||||
SDL_RenderLine(renderer, 1.0f, 0.0f, (viewport.w - 2), 0.0f);
|
||||
SDL_RenderLine(renderer, 1.0f, (viewport.h - 1), (viewport.w - 2), (viewport.h - 1));
|
||||
SDL_RenderLine(renderer, 0.0f, 1.0f, 0.0f, (viewport.h - 2));
|
||||
SDL_RenderLine(renderer, (viewport.w - 1), 1.0f, (viewport.w - 1), (viewport.h - 2));
|
||||
|
||||
/* Test diagonal lines */
|
||||
SDL_SetRenderDrawColor(renderer, 0x00, 0xff, 0xFF, 0xFF);
|
||||
SDL_RenderLine(renderer, 0.0f, 0.0f, (float)(viewport.w - 1), (float)(viewport.h - 1));
|
||||
SDL_RenderLine(renderer, (float)(viewport.w - 1), 0.0f, 0.0f, (float)(viewport.h - 1));
|
||||
SDL_RenderLine(renderer, 0.0f, 0.0f, (viewport.w - 1), (viewport.h - 1));
|
||||
SDL_RenderLine(renderer, (viewport.w - 1), 0.0f, 0.0f, (viewport.h - 1));
|
||||
|
||||
/* Test outside points */
|
||||
SDL_SetRenderDrawColor(renderer, 0xFF, 0xFF, 0x00, 0xFF);
|
||||
SDL_RenderPoint(renderer, (float)(viewport.h / 2 + viewport.h), (float)(viewport.w / 2));
|
||||
SDL_RenderPoint(renderer, (float)(viewport.h / 2 - viewport.h), (float)(viewport.w / 2));
|
||||
SDL_RenderPoint(renderer, (float)(viewport.h / 2), (float)(viewport.w / 2 - viewport.w));
|
||||
SDL_RenderPoint(renderer, (float)(viewport.h / 2), (float)(viewport.w / 2 + viewport.w));
|
||||
SDL_RenderPoint(renderer, (viewport.h / 2 + viewport.h), (viewport.w / 2));
|
||||
SDL_RenderPoint(renderer, (viewport.h / 2 - viewport.h), (viewport.w / 2));
|
||||
SDL_RenderPoint(renderer, (viewport.h / 2), (viewport.w / 2 - viewport.w));
|
||||
SDL_RenderPoint(renderer, (viewport.h / 2), (viewport.w / 2 + viewport.w));
|
||||
|
||||
/* Add a box at the top */
|
||||
rect.w = 8.0f;
|
||||
rect.h = 8.0f;
|
||||
rect.x = (float)((viewport.w - rect.w) / 2);
|
||||
rect.x = ((viewport.w - rect.w) / 2);
|
||||
rect.y = 0.0f;
|
||||
SDL_RenderFillRect(renderer, &rect);
|
||||
|
||||
/* Add a clip rect and fill it with the sprite */
|
||||
SDL_QueryTexture(sprite, NULL, NULL, &w, &h);
|
||||
SDL_GetTextureSize(sprite, &w, &h);
|
||||
cliprect.x = (viewport.w - w) / 2;
|
||||
cliprect.y = (viewport.h - h) / 2;
|
||||
cliprect.w = w;
|
||||
cliprect.h = h;
|
||||
rect.x = (float)cliprect.x;
|
||||
rect.y = (float)cliprect.y;
|
||||
rect.w = (float)cliprect.w;
|
||||
rect.h = (float)cliprect.h;
|
||||
rect.x = cliprect.x;
|
||||
rect.y = cliprect.y;
|
||||
rect.w = cliprect.w;
|
||||
rect.h = cliprect.h;
|
||||
SDL_SetRenderClipRect(renderer, &cliprect);
|
||||
SDL_RenderTexture(renderer, sprite, NULL, &rect);
|
||||
SDL_SetRenderClipRect(renderer, NULL);
|
||||
|
|
@ -127,7 +127,7 @@ static void loop(void)
|
|||
viewport.w = 100 + j * 50;
|
||||
viewport.h = 100 + j * 50;
|
||||
j = (j + 1) % 4;
|
||||
SDL_Log("Current Viewport x=%i y=%i w=%i h=%i", viewport.x, viewport.y, viewport.w, viewport.h);
|
||||
SDL_Log("Current Viewport x=%g y=%g w=%g h=%g", viewport.x, viewport.y, viewport.w, viewport.h);
|
||||
|
||||
for (i = 0; i < state->num_windows; ++i) {
|
||||
if (state->windows[i] == NULL) {
|
||||
|
|
|
|||
|
|
@ -225,8 +225,7 @@ static void loop(void)
|
|||
SDL_Renderer *renderer = state->renderers[i];
|
||||
if (window && renderer) {
|
||||
float y = 0.0f;
|
||||
SDL_Rect viewport;
|
||||
SDL_FRect menurect;
|
||||
SDL_FRect viewport, menurect;
|
||||
|
||||
SDL_GetRenderViewport(renderer, &viewport);
|
||||
|
||||
|
|
@ -238,8 +237,8 @@ static void loop(void)
|
|||
|
||||
menurect.x = 0.0f;
|
||||
menurect.y = y;
|
||||
menurect.w = (float)viewport.w;
|
||||
menurect.h = (float)viewport.h - y;
|
||||
menurect.w = viewport.w;
|
||||
menurect.h = viewport.h - y;
|
||||
draw_modes_menu(window, renderer, menurect);
|
||||
|
||||
SDL_Delay(16);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue