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:
Sam Lantinga 2024-06-12 09:21:02 -07:00
parent 463984ec20
commit 9fb5a9ccac
29 changed files with 624 additions and 585 deletions

View File

@ -1153,7 +1153,9 @@ SDL_CreateRenderer()'s flags parameter has been removed. See specific flags belo
SDL_CreateWindowAndRenderer() now takes the window title as the first parameter.
SDL_GetRendererInfo() has been removed, the name of a renderer can be retrieved using SDL_GetRendererName(), and the other information is available as properties on the renderer.
SDL_GetRendererInfo() has been removed. The name of a renderer can be retrieved using SDL_GetRendererName(), and the other information is available as properties on the renderer.
SDL_QueryTexture() has been removed. The properties of the texture can be queried using SDL_PROP_TEXTURE_FORMAT_NUMBER, SDL_PROP_TEXTURE_ACCESS_NUMBER, SDL_PROP_TEXTURE_WIDTH_NUMBER, and SDL_PROP_TEXTURE_HEIGHT_NUMBER. A function SDL_GetTextureSize() has been added to get the size of the texture as floating point values.
Mouse and touch events are no longer filtered to change their coordinates, instead you
can call SDL_ConvertEventToRenderCoordinates() to explicitly map event coordinates into
@ -1163,6 +1165,15 @@ SDL_RenderWindowToLogical() and SDL_RenderLogicalToWindow() have been renamed SD
The viewport, clipping state, and scale for render targets are now persistent and will remain set whenever they are active.
The following functions have been changed to take floating point values to make them easier to use with the rest of the rendering API:
* SDL_GetCurrentRenderOutputSize()
* SDL_GetRenderClipRect()
* SDL_GetRenderLogicalPresentation()
* SDL_GetRenderOutputSize()
* SDL_GetRenderViewport()
* SDL_SetRenderLogicalPresentation()
* SDL_SetRenderViewport()
SDL_Vertex has been changed to use floating point colors, in the range of [0..1] for SDR content.
SDL_RenderReadPixels() returns a surface instead of filling in preallocated memory.

View File

@ -459,7 +459,7 @@ extern SDL_DECLSPEC SDL_PropertiesID SDLCALL SDL_GetRendererProperties(SDL_Rende
*
* \sa SDL_GetCurrentRenderOutputSize
*/
extern SDL_DECLSPEC int SDLCALL SDL_GetRenderOutputSize(SDL_Renderer *renderer, int *w, int *h);
extern SDL_DECLSPEC int SDLCALL SDL_GetRenderOutputSize(SDL_Renderer *renderer, float *w, float *h);
/**
* Get the current output size in pixels of a rendering context.
@ -479,7 +479,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetRenderOutputSize(SDL_Renderer *renderer,
*
* \sa SDL_GetRenderOutputSize
*/
extern SDL_DECLSPEC int SDLCALL SDL_GetCurrentRenderOutputSize(SDL_Renderer *renderer, int *w, int *h);
extern SDL_DECLSPEC int SDLCALL SDL_GetCurrentRenderOutputSize(SDL_Renderer *renderer, float *w, float *h);
/**
* Create a texture for a rendering context.
@ -498,7 +498,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetCurrentRenderOutputSize(SDL_Renderer *ren
* \sa SDL_CreateTextureFromSurface
* \sa SDL_CreateTextureWithProperties
* \sa SDL_DestroyTexture
* \sa SDL_QueryTexture
* \sa SDL_GetTextureSize
* \sa SDL_UpdateTexture
*/
extern SDL_DECLSPEC SDL_Texture *SDLCALL SDL_CreateTexture(SDL_Renderer *renderer, SDL_PixelFormatEnum format, int access, int w, int h);
@ -512,8 +512,7 @@ extern SDL_DECLSPEC SDL_Texture *SDLCALL SDL_CreateTexture(SDL_Renderer *rendere
* `SDL_TEXTUREACCESS_STATIC`.
*
* The pixel format of the created texture may be different from the pixel
* format of the surface. Use SDL_QueryTexture() to query the pixel format of
* the texture.
* format of the surface, and can be queried using the SDL_PROP_TEXTURE_FORMAT_NUMBER property.
*
* \param renderer the rendering context
* \param surface the SDL_Surface structure containing pixel data used to fill
@ -526,7 +525,6 @@ extern SDL_DECLSPEC SDL_Texture *SDLCALL SDL_CreateTexture(SDL_Renderer *rendere
* \sa SDL_CreateTexture
* \sa SDL_CreateTextureWithProperties
* \sa SDL_DestroyTexture
* \sa SDL_QueryTexture
*/
extern SDL_DECLSPEC SDL_Texture *SDLCALL SDL_CreateTextureFromSurface(SDL_Renderer *renderer, SDL_Surface *surface);
@ -636,7 +634,7 @@ extern SDL_DECLSPEC SDL_Texture *SDLCALL SDL_CreateTextureFromSurface(SDL_Render
* \sa SDL_CreateTexture
* \sa SDL_CreateTextureFromSurface
* \sa SDL_DestroyTexture
* \sa SDL_QueryTexture
* \sa SDL_GetTextureSize
* \sa SDL_UpdateTexture
*/
extern SDL_DECLSPEC SDL_Texture *SDLCALL SDL_CreateTextureWithProperties(SDL_Renderer *renderer, SDL_PropertiesID props);
@ -670,8 +668,14 @@ extern SDL_DECLSPEC SDL_Texture *SDLCALL SDL_CreateTextureWithProperties(SDL_Ren
*
* The following read-only properties are provided by SDL:
*
* - `SDL_PROP_TEXTURE_COLORSPACE_NUMBER`: an SDL_ColorSpace value describing
* the colorspace used by the texture
* - `SDL_PROP_TEXTURE_COLORSPACE_NUMBER`: an SDL_ColorSpace value
* describing the texture colorspace.
* - `SDL_PROP_TEXTURE_FORMAT_NUMBER`: one of the enumerated values in
* SDL_PixelFormatEnum.
* - `SDL_PROP_TEXTURE_ACCESS_NUMBER`: one of the enumerated values in
* SDL_TextureAccess.
* - `SDL_PROP_TEXTURE_WIDTH_NUMBER`: the width of the texture in pixels.
* - `SDL_PROP_TEXTURE_HEIGHT_NUMBER`: the height of the texture in pixels.
* - `SDL_PROP_TEXTURE_SDR_WHITE_POINT_FLOAT`: for HDR10 and floating point
* textures, this defines the value of 100% diffuse white, with higher
* values being displayed in the High Dynamic Range headroom. This defaults
@ -760,6 +764,10 @@ extern SDL_DECLSPEC SDL_Texture *SDLCALL SDL_CreateTextureWithProperties(SDL_Ren
extern SDL_DECLSPEC SDL_PropertiesID SDLCALL SDL_GetTextureProperties(SDL_Texture *texture);
#define SDL_PROP_TEXTURE_COLORSPACE_NUMBER "SDL.texture.colorspace"
#define SDL_PROP_TEXTURE_FORMAT_NUMBER "SDL.texture.format"
#define SDL_PROP_TEXTURE_ACCESS_NUMBER "SDL.texture.access"
#define SDL_PROP_TEXTURE_WIDTH_NUMBER "SDL.texture.width"
#define SDL_PROP_TEXTURE_HEIGHT_NUMBER "SDL.texture.height"
#define SDL_PROP_TEXTURE_SDR_WHITE_POINT_FLOAT "SDL.texture.SDR_white_point"
#define SDL_PROP_TEXTURE_HDR_HEADROOM_FLOAT "SDL.texture.HDR_headroom"
#define SDL_PROP_TEXTURE_D3D11_TEXTURE_POINTER "SDL.texture.d3d11.texture"
@ -796,16 +804,9 @@ extern SDL_DECLSPEC SDL_PropertiesID SDLCALL SDL_GetTextureProperties(SDL_Textur
extern SDL_DECLSPEC SDL_Renderer *SDLCALL SDL_GetRendererFromTexture(SDL_Texture *texture);
/**
* Query the attributes of a texture.
* Get the size of a texture, as floating point values.
*
* \param texture the texture to query
* \param format a pointer filled in with the raw format of the texture; the
* actual format may differ, but pixel transfers will use this
* format (one of the SDL_PixelFormatEnum values). This argument
* can be NULL if you don't need this information.
* \param access a pointer filled in with the actual access to the texture
* (one of the SDL_TextureAccess values). This argument can be
* NULL if you don't need this information.
* \param w a pointer filled in with the width of the texture in pixels. This
* argument can be NULL if you don't need this information.
* \param h a pointer filled in with the height of the texture in pixels. This
@ -815,7 +816,7 @@ extern SDL_DECLSPEC SDL_Renderer *SDLCALL SDL_GetRendererFromTexture(SDL_Texture
*
* \since This function is available since SDL 3.0.0.
*/
extern SDL_DECLSPEC int SDLCALL SDL_QueryTexture(SDL_Texture *texture, SDL_PixelFormatEnum *format, int *access, int *w, int *h);
extern SDL_DECLSPEC int SDLCALL SDL_GetTextureSize(SDL_Texture *texture, float *w, float *h);
/**
* Set an additional color value multiplied into render copy operations.
@ -1055,8 +1056,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetTextureScaleMode(SDL_Texture *texture, SD
/**
* Update the given texture rectangle with new pixel data.
*
* The pixel data must be in the pixel format of the texture. Use
* SDL_QueryTexture() to query the pixel format of the texture.
* The pixel data must be in the pixel format of the texture, which can be queried using the SDL_PROP_TEXTURE_FORMAT_NUMBER property.
*
* This is a fairly slow function, intended for use with static textures that
* do not change often.
@ -1296,7 +1296,7 @@ extern SDL_DECLSPEC SDL_Texture *SDLCALL SDL_GetRenderTarget(SDL_Renderer *rende
* \sa SDL_ConvertEventToRenderCoordinates
* \sa SDL_GetRenderLogicalPresentation
*/
extern SDL_DECLSPEC int SDLCALL SDL_SetRenderLogicalPresentation(SDL_Renderer *renderer, int w, int h, SDL_RendererLogicalPresentation mode, SDL_ScaleMode scale_mode);
extern SDL_DECLSPEC int SDLCALL SDL_SetRenderLogicalPresentation(SDL_Renderer *renderer, float w, float h, SDL_RendererLogicalPresentation mode, SDL_ScaleMode scale_mode);
/**
* Get device independent resolution and presentation mode for rendering.
@ -1316,7 +1316,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_SetRenderLogicalPresentation(SDL_Renderer *r
*
* \sa SDL_SetRenderLogicalPresentation
*/
extern SDL_DECLSPEC int SDLCALL SDL_GetRenderLogicalPresentation(SDL_Renderer *renderer, int *w, int *h, SDL_RendererLogicalPresentation *mode, SDL_ScaleMode *scale_mode);
extern SDL_DECLSPEC int SDLCALL SDL_GetRenderLogicalPresentation(SDL_Renderer *renderer, float *w, float *h, SDL_RendererLogicalPresentation *mode, SDL_ScaleMode *scale_mode);
/**
* Get a point in render coordinates when given a point in window coordinates.
@ -1379,7 +1379,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_ConvertEventToRenderCoordinates(SDL_Renderer
* Set the drawing area for rendering on the current target.
*
* \param renderer the rendering context
* \param rect the SDL_Rect structure representing the drawing area, or NULL
* \param rect the SDL_FRect structure representing the drawing area, or NULL
* to set the viewport to the entire target
* \returns 0 on success or a negative error code on failure; call
* SDL_GetError() for more information.
@ -1389,13 +1389,13 @@ extern SDL_DECLSPEC int SDLCALL SDL_ConvertEventToRenderCoordinates(SDL_Renderer
* \sa SDL_GetRenderViewport
* \sa SDL_RenderViewportSet
*/
extern SDL_DECLSPEC int SDLCALL SDL_SetRenderViewport(SDL_Renderer *renderer, const SDL_Rect *rect);
extern SDL_DECLSPEC int SDLCALL SDL_SetRenderViewport(SDL_Renderer *renderer, const SDL_FRect *rect);
/**
* Get the drawing area for the current target.
*
* \param renderer the rendering context
* \param rect an SDL_Rect structure filled in with the current drawing area
* \param rect an SDL_FRect structure filled in with the current drawing area
* \returns 0 on success or a negative error code on failure; call
* SDL_GetError() for more information.
*
@ -1404,7 +1404,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_SetRenderViewport(SDL_Renderer *renderer, co
* \sa SDL_RenderViewportSet
* \sa SDL_SetRenderViewport
*/
extern SDL_DECLSPEC int SDLCALL SDL_GetRenderViewport(SDL_Renderer *renderer, SDL_Rect *rect);
extern SDL_DECLSPEC int SDLCALL SDL_GetRenderViewport(SDL_Renderer *renderer, SDL_FRect *rect);
/**
* Return whether an explicit rectangle was set as the viewport.
@ -1428,7 +1428,7 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_RenderViewportSet(SDL_Renderer *rendere
* Set the clip rectangle for rendering on the specified target.
*
* \param renderer the rendering context
* \param rect an SDL_Rect structure representing the clip area, relative to
* \param rect an SDL_FRect structure representing the clip area, relative to
* the viewport, or NULL to disable clipping
* \returns 0 on success or a negative error code on failure; call
* SDL_GetError() for more information.
@ -1438,13 +1438,13 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_RenderViewportSet(SDL_Renderer *rendere
* \sa SDL_GetRenderClipRect
* \sa SDL_RenderClipEnabled
*/
extern SDL_DECLSPEC int SDLCALL SDL_SetRenderClipRect(SDL_Renderer *renderer, const SDL_Rect *rect);
extern SDL_DECLSPEC int SDLCALL SDL_SetRenderClipRect(SDL_Renderer *renderer, const SDL_FRect *rect);
/**
* Get the clip rectangle for the current target.
*
* \param renderer the rendering context
* \param rect an SDL_Rect structure filled in with the current clipping area
* \param rect an SDL_FRect structure filled in with the current clipping area
* or an empty rectangle if clipping is disabled
* \returns 0 on success or a negative error code on failure; call
* SDL_GetError() for more information.
@ -1454,7 +1454,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_SetRenderClipRect(SDL_Renderer *renderer, co
* \sa SDL_RenderClipEnabled
* \sa SDL_SetRenderClipRect
*/
extern SDL_DECLSPEC int SDLCALL SDL_GetRenderClipRect(SDL_Renderer *renderer, SDL_Rect *rect);
extern SDL_DECLSPEC int SDLCALL SDL_GetRenderClipRect(SDL_Renderer *renderer, SDL_FRect *rect);
/**
* Get whether clipping is enabled on the given renderer.

View File

@ -443,6 +443,7 @@ SDL3_0.0.0 {
SDL_GetTextureColorModFloat;
SDL_GetTextureProperties;
SDL_GetTextureScaleMode;
SDL_GetTextureSize;
SDL_GetThreadID;
SDL_GetThreadName;
SDL_GetTicks;
@ -604,7 +605,6 @@ SDL3_0.0.0 {
SDL_PumpEvents;
SDL_PushEvent;
SDL_PutAudioStreamData;
SDL_QueryTexture;
SDL_Quit;
SDL_QuitSubSystem;
SDL_RaiseWindow;

View File

@ -468,6 +468,7 @@
#define SDL_GetTextureColorModFloat SDL_GetTextureColorModFloat_REAL
#define SDL_GetTextureProperties SDL_GetTextureProperties_REAL
#define SDL_GetTextureScaleMode SDL_GetTextureScaleMode_REAL
#define SDL_GetTextureSize SDL_GetTextureSize_REAL
#define SDL_GetThreadID SDL_GetThreadID_REAL
#define SDL_GetThreadName SDL_GetThreadName_REAL
#define SDL_GetTicks SDL_GetTicks_REAL
@ -629,7 +630,6 @@
#define SDL_PumpEvents SDL_PumpEvents_REAL
#define SDL_PushEvent SDL_PushEvent_REAL
#define SDL_PutAudioStreamData SDL_PutAudioStreamData_REAL
#define SDL_QueryTexture SDL_QueryTexture_REAL
#define SDL_Quit SDL_Quit_REAL
#define SDL_QuitSubSystem SDL_QuitSubSystem_REAL
#define SDL_RaiseWindow SDL_RaiseWindow_REAL

View File

@ -243,7 +243,7 @@ SDL_DYNAPI_PROC(const char*,SDL_GetCurrentAudioDriver,(void),(),return)
SDL_DYNAPI_PROC(const char*,SDL_GetCurrentCameraDriver,(void),(),return)
SDL_DYNAPI_PROC(const SDL_DisplayMode*,SDL_GetCurrentDisplayMode,(SDL_DisplayID a),(a),return)
SDL_DYNAPI_PROC(SDL_DisplayOrientation,SDL_GetCurrentDisplayOrientation,(SDL_DisplayID a),(a),return)
SDL_DYNAPI_PROC(int,SDL_GetCurrentRenderOutputSize,(SDL_Renderer *a, int *b, int *c),(a,b,c),return)
SDL_DYNAPI_PROC(int,SDL_GetCurrentRenderOutputSize,(SDL_Renderer *a, float *b, float *c),(a,b,c),return)
SDL_DYNAPI_PROC(SDL_ThreadID,SDL_GetCurrentThreadID,(void),(),return)
SDL_DYNAPI_PROC(int,SDL_GetCurrentTime,(SDL_Time *a),(a),return)
SDL_DYNAPI_PROC(const char*,SDL_GetCurrentVideoDriver,(void),(),return)
@ -430,20 +430,20 @@ SDL_DYNAPI_PROC(int,SDL_GetRectUnion,(const SDL_Rect *a, const SDL_Rect *b, SDL_
SDL_DYNAPI_PROC(int,SDL_GetRectUnionFloat,(const SDL_FRect *a, const SDL_FRect *b, SDL_FRect *c),(a,b,c),return)
SDL_DYNAPI_PROC(SDL_bool,SDL_GetRelativeMouseMode,(void),(),return)
SDL_DYNAPI_PROC(SDL_MouseButtonFlags,SDL_GetRelativeMouseState,(float *a, float *b),(a,b),return)
SDL_DYNAPI_PROC(int,SDL_GetRenderClipRect,(SDL_Renderer *a, SDL_Rect *b),(a,b),return)
SDL_DYNAPI_PROC(int,SDL_GetRenderClipRect,(SDL_Renderer *a, SDL_FRect *b),(a,b),return)
SDL_DYNAPI_PROC(int,SDL_GetRenderColorScale,(SDL_Renderer *a, float *b),(a,b),return)
SDL_DYNAPI_PROC(int,SDL_GetRenderDrawBlendMode,(SDL_Renderer *a, SDL_BlendMode *b),(a,b),return)
SDL_DYNAPI_PROC(int,SDL_GetRenderDrawColor,(SDL_Renderer *a, Uint8 *b, Uint8 *c, Uint8 *d, Uint8 *e),(a,b,c,d,e),return)
SDL_DYNAPI_PROC(int,SDL_GetRenderDrawColorFloat,(SDL_Renderer *a, float *b, float *c, float *d, float *e),(a,b,c,d,e),return)
SDL_DYNAPI_PROC(const char*,SDL_GetRenderDriver,(int a),(a),return)
SDL_DYNAPI_PROC(int,SDL_GetRenderLogicalPresentation,(SDL_Renderer *a, int *b, int *c, SDL_RendererLogicalPresentation *d, SDL_ScaleMode *e),(a,b,c,d,e),return)
SDL_DYNAPI_PROC(int,SDL_GetRenderLogicalPresentation,(SDL_Renderer *a, float *b, float *c, SDL_RendererLogicalPresentation *d, SDL_ScaleMode *e),(a,b,c,d,e),return)
SDL_DYNAPI_PROC(void*,SDL_GetRenderMetalCommandEncoder,(SDL_Renderer *a),(a),return)
SDL_DYNAPI_PROC(void*,SDL_GetRenderMetalLayer,(SDL_Renderer *a),(a),return)
SDL_DYNAPI_PROC(int,SDL_GetRenderOutputSize,(SDL_Renderer *a, int *b, int *c),(a,b,c),return)
SDL_DYNAPI_PROC(int,SDL_GetRenderOutputSize,(SDL_Renderer *a, float *b, float *c),(a,b,c),return)
SDL_DYNAPI_PROC(int,SDL_GetRenderScale,(SDL_Renderer *a, float *b, float *c),(a,b,c),return)
SDL_DYNAPI_PROC(SDL_Texture*,SDL_GetRenderTarget,(SDL_Renderer *a),(a),return)
SDL_DYNAPI_PROC(int,SDL_GetRenderVSync,(SDL_Renderer *a, int *b),(a,b),return)
SDL_DYNAPI_PROC(int,SDL_GetRenderViewport,(SDL_Renderer *a, SDL_Rect *b),(a,b),return)
SDL_DYNAPI_PROC(int,SDL_GetRenderViewport,(SDL_Renderer *a, SDL_FRect *b),(a,b),return)
SDL_DYNAPI_PROC(SDL_Window*,SDL_GetRenderWindow,(SDL_Renderer *a),(a),return)
SDL_DYNAPI_PROC(SDL_Renderer*,SDL_GetRenderer,(SDL_Window *a),(a),return)
SDL_DYNAPI_PROC(SDL_Renderer*,SDL_GetRendererFromTexture,(SDL_Texture *a),(a),return)
@ -488,6 +488,7 @@ SDL_DYNAPI_PROC(int,SDL_GetTextureColorMod,(SDL_Texture *a, Uint8 *b, Uint8 *c,
SDL_DYNAPI_PROC(int,SDL_GetTextureColorModFloat,(SDL_Texture *a, float *b, float *c, float *d),(a,b,c,d),return)
SDL_DYNAPI_PROC(SDL_PropertiesID,SDL_GetTextureProperties,(SDL_Texture *a),(a),return)
SDL_DYNAPI_PROC(int,SDL_GetTextureScaleMode,(SDL_Texture *a, SDL_ScaleMode *b),(a,b),return)
SDL_DYNAPI_PROC(int,SDL_GetTextureSize,(SDL_Texture *a, float *b, float *c),(a,b,c),return)
SDL_DYNAPI_PROC(SDL_ThreadID,SDL_GetThreadID,(SDL_Thread *a),(a),return)
SDL_DYNAPI_PROC(const char*,SDL_GetThreadName,(SDL_Thread *a),(a),return)
SDL_DYNAPI_PROC(Uint64,SDL_GetTicks,(void),(),return)
@ -640,7 +641,6 @@ SDL_DYNAPI_PROC(int,SDL_PremultiplyAlpha,(int a, int b, SDL_PixelFormatEnum c, c
SDL_DYNAPI_PROC(void,SDL_PumpEvents,(void),(),)
SDL_DYNAPI_PROC(int,SDL_PushEvent,(SDL_Event *a),(a),return)
SDL_DYNAPI_PROC(int,SDL_PutAudioStreamData,(SDL_AudioStream *a, const void *b, int c),(a,b,c),return)
SDL_DYNAPI_PROC(int,SDL_QueryTexture,(SDL_Texture *a, SDL_PixelFormatEnum *b, int *c, int *d, int *e),(a,b,c,d,e),return)
SDL_DYNAPI_PROC(void,SDL_Quit,(void),(),)
SDL_DYNAPI_PROC(void,SDL_QuitSubSystem,(SDL_InitFlags a),(a),)
SDL_DYNAPI_PROC(int,SDL_RaiseWindow,(SDL_Window *a),(a),return)
@ -757,16 +757,16 @@ SDL_DYNAPI_PROC(int,SDL_SetPrimarySelectionText,(const char *a),(a),return)
SDL_DYNAPI_PROC(int,SDL_SetProperty,(SDL_PropertiesID a, const char *b, void *c),(a,b,c),return)
SDL_DYNAPI_PROC(int,SDL_SetPropertyWithCleanup,(SDL_PropertiesID a, const char *b, void *c, SDL_CleanupPropertyCallback d, void *e),(a,b,c,d,e),return)
SDL_DYNAPI_PROC(int,SDL_SetRelativeMouseMode,(SDL_bool a),(a),return)
SDL_DYNAPI_PROC(int,SDL_SetRenderClipRect,(SDL_Renderer *a, const SDL_Rect *b),(a,b),return)
SDL_DYNAPI_PROC(int,SDL_SetRenderClipRect,(SDL_Renderer *a, const SDL_FRect *b),(a,b),return)
SDL_DYNAPI_PROC(int,SDL_SetRenderColorScale,(SDL_Renderer *a, float b),(a,b),return)
SDL_DYNAPI_PROC(int,SDL_SetRenderDrawBlendMode,(SDL_Renderer *a, SDL_BlendMode b),(a,b),return)
SDL_DYNAPI_PROC(int,SDL_SetRenderDrawColor,(SDL_Renderer *a, Uint8 b, Uint8 c, Uint8 d, Uint8 e),(a,b,c,d,e),return)
SDL_DYNAPI_PROC(int,SDL_SetRenderDrawColorFloat,(SDL_Renderer *a, float b, float c, float d, float e),(a,b,c,d,e),return)
SDL_DYNAPI_PROC(int,SDL_SetRenderLogicalPresentation,(SDL_Renderer *a, int b, int c, SDL_RendererLogicalPresentation d, SDL_ScaleMode e),(a,b,c,d,e),return)
SDL_DYNAPI_PROC(int,SDL_SetRenderLogicalPresentation,(SDL_Renderer *a, float b, float c, SDL_RendererLogicalPresentation d, SDL_ScaleMode e),(a,b,c,d,e),return)
SDL_DYNAPI_PROC(int,SDL_SetRenderScale,(SDL_Renderer *a, float b, float c),(a,b,c),return)
SDL_DYNAPI_PROC(int,SDL_SetRenderTarget,(SDL_Renderer *a, SDL_Texture *b),(a,b),return)
SDL_DYNAPI_PROC(int,SDL_SetRenderVSync,(SDL_Renderer *a, int b),(a,b),return)
SDL_DYNAPI_PROC(int,SDL_SetRenderViewport,(SDL_Renderer *a, const SDL_Rect *b),(a,b),return)
SDL_DYNAPI_PROC(int,SDL_SetRenderViewport,(SDL_Renderer *a, const SDL_FRect *b),(a,b),return)
SDL_DYNAPI_PROC(int,SDL_SetStringProperty,(SDL_PropertiesID a, const char *b, const char *c),(a,b,c),return)
SDL_DYNAPI_PROC(int,SDL_SetSurfaceAlphaMod,(SDL_Surface *a, Uint8 b),(a,b),return)
SDL_DYNAPI_PROC(int,SDL_SetSurfaceBlendMode,(SDL_Surface *a, SDL_BlendMode b),(a,b),return)

View File

@ -402,19 +402,19 @@ static SDL_RenderCommand *AllocateRenderCommand(SDL_Renderer *renderer)
return retval;
}
static void GetRenderViewportInPixels(SDL_Renderer *renderer, SDL_Rect *rect)
static void UpdatePixelViewport(SDL_Renderer *renderer, SDL_RenderViewState *view)
{
rect->x = (int)SDL_floorf(renderer->view->viewport.x * renderer->view->scale.x);
rect->y = (int)SDL_floorf(renderer->view->viewport.y * renderer->view->scale.y);
if (renderer->view->viewport.w >= 0) {
rect->w = (int)SDL_floorf(renderer->view->viewport.w * renderer->view->scale.x);
view->pixel_viewport.x = (int)SDL_floorf(view->viewport.x * view->scale.x);
view->pixel_viewport.y = (int)SDL_floorf(view->viewport.y * view->scale.y);
if (view->viewport.w >= 0) {
view->pixel_viewport.w = (int)SDL_ceilf(view->viewport.w * view->scale.x);
} else {
rect->w = renderer->view->pixel_w;
view->pixel_viewport.w = (int)SDL_ceilf(view->pixel_w);
}
if (renderer->view->viewport.h >= 0) {
rect->h = (int)SDL_floorf(renderer->view->viewport.h * renderer->view->scale.y);
if (view->viewport.h >= 0) {
view->pixel_viewport.h = (int)SDL_ceilf(view->viewport.h * view->scale.y);
} else {
rect->h = renderer->view->pixel_h;
view->pixel_viewport.h = (int)SDL_ceilf(view->pixel_h);
}
}
@ -423,7 +423,7 @@ static int QueueCmdSetViewport(SDL_Renderer *renderer)
SDL_Rect viewport;
int retval = 0;
GetRenderViewportInPixels(renderer, &viewport);
viewport = renderer->view->pixel_viewport;
if (!renderer->viewport_queued ||
SDL_memcmp(&viewport, &renderer->last_queued_viewport, sizeof(viewport)) != 0) {
@ -446,15 +446,20 @@ static int QueueCmdSetViewport(SDL_Renderer *renderer)
return retval;
}
static void UpdatePixelClipRect(SDL_Renderer *renderer, SDL_RenderViewState *view)
{
view->pixel_cliprect.x = (int)SDL_floorf(view->clip_rect.x * view->scale.x);
view->pixel_cliprect.y = (int)SDL_floorf(view->clip_rect.y * view->scale.y);
view->pixel_cliprect.w = (int)SDL_ceilf(view->clip_rect.w * view->scale.x);
view->pixel_cliprect.h = (int)SDL_ceilf(view->clip_rect.h * view->scale.y);
}
static int QueueCmdSetClipRect(SDL_Renderer *renderer)
{
SDL_Rect clip_rect;
int retval = 0;
clip_rect.x = (int)SDL_floorf(renderer->view->clip_rect.x * renderer->view->scale.x);
clip_rect.y = (int)SDL_floorf(renderer->view->clip_rect.y * renderer->view->scale.y);
clip_rect.w = (int)SDL_floorf(renderer->view->clip_rect.w * renderer->view->scale.x);
clip_rect.h = (int)SDL_floorf(renderer->view->clip_rect.h * renderer->view->scale.y);
clip_rect = renderer->view->pixel_cliprect;
if (!renderer->cliprect_queued ||
renderer->view->clipping_enabled != renderer->last_queued_cliprect_enabled ||
@ -721,12 +726,13 @@ static void UpdateMainViewDimensions(SDL_Renderer *renderer)
}
SDL_GetRenderOutputSize(renderer, &renderer->main_view.pixel_w, &renderer->main_view.pixel_h);
if (window_w > 0 && window_h > 0) {
renderer->dpi_scale.x = (float)renderer->main_view.pixel_w / window_w;
renderer->dpi_scale.y = (float)renderer->main_view.pixel_h / window_h;
renderer->dpi_scale.x = renderer->main_view.pixel_w / window_w;
renderer->dpi_scale.y = renderer->main_view.pixel_h / window_h;
} else {
renderer->dpi_scale.x = 1.0f;
renderer->dpi_scale.y = 1.0f;
}
UpdatePixelViewport(renderer, &renderer->main_view);
}
static void UpdateHDRProperties(SDL_Renderer *renderer)
@ -1023,8 +1029,8 @@ SDL_Renderer *SDL_CreateRendererWithProperties(SDL_PropertiesID props)
renderer->window = window;
renderer->target_mutex = SDL_CreateMutex();
if (surface) {
renderer->main_view.pixel_w = surface->w;
renderer->main_view.pixel_h = surface->h;
renderer->main_view.pixel_w = (float)surface->w;
renderer->main_view.pixel_h = (float)surface->h;
}
renderer->main_view.viewport.w = -1;
renderer->main_view.viewport.h = -1;
@ -1033,6 +1039,8 @@ SDL_Renderer *SDL_CreateRendererWithProperties(SDL_PropertiesID props)
renderer->view = &renderer->main_view;
renderer->dpi_scale.x = 1.0f;
renderer->dpi_scale.y = 1.0f;
UpdatePixelViewport(renderer, &renderer->main_view);
UpdatePixelClipRect(renderer, &renderer->main_view);
UpdateMainViewDimensions(renderer);
/* Default value, if not specified by the renderer back-end */
@ -1181,21 +1189,35 @@ SDL_PropertiesID SDL_GetRendererProperties(SDL_Renderer *renderer)
return renderer->props;
}
int SDL_GetRenderOutputSize(SDL_Renderer *renderer, int *w, int *h)
int SDL_GetRenderOutputSize(SDL_Renderer *renderer, float *w, float *h)
{
CHECK_RENDERER_MAGIC(renderer, -1);
int output_w = 0;
int output_h = 0;
if (renderer->GetOutputSize) {
return renderer->GetOutputSize(renderer, w, h);
if (renderer->GetOutputSize(renderer, &output_w, &output_h) < 0) {
return -1;
}
} else if (renderer->window) {
return SDL_GetWindowSizeInPixels(renderer->window, w, h);
if (SDL_GetWindowSizeInPixels(renderer->window, &output_w, &output_h) < 0) {
return -1;
}
} else {
SDL_assert(!"This should never happen");
return SDL_SetError("Renderer doesn't support querying output size");
}
if (w) {
*w = (float)output_w;
}
if (h) {
*h = (float)output_h;
}
return 0;
}
int SDL_GetCurrentRenderOutputSize(SDL_Renderer *renderer, int *w, int *h)
int SDL_GetCurrentRenderOutputSize(SDL_Renderer *renderer, float *w, float *h)
{
CHECK_RENDERER_MAGIC(renderer, -1);
@ -1326,8 +1348,8 @@ SDL_Texture *SDL_CreateTextureWithProperties(SDL_Renderer *renderer, SDL_Propert
texture->color.b = 1.0f;
texture->color.a = 1.0f;
texture->scaleMode = SDL_SCALEMODE_LINEAR;
texture->view.pixel_w = w;
texture->view.pixel_h = h;
texture->view.pixel_w = (float)w;
texture->view.pixel_h = (float)h;
texture->view.viewport.w = -1;
texture->view.viewport.h = -1;
texture->view.scale.x = 1.0f;
@ -1339,6 +1361,9 @@ SDL_Texture *SDL_CreateTextureWithProperties(SDL_Renderer *renderer, SDL_Propert
}
renderer->textures = texture;
UpdatePixelViewport(renderer, &texture->view);
UpdatePixelClipRect(renderer, &texture->view);
texture->SDR_white_point = SDL_GetFloatProperty(props, SDL_PROP_TEXTURE_CREATE_SDR_WHITE_POINT_FLOAT, SDL_GetDefaultSDRWhitePoint(texture->colorspace));
texture->HDR_headroom = SDL_GetFloatProperty(props, SDL_PROP_TEXTURE_CREATE_HDR_HEADROOM_FLOAT, SDL_GetDefaultHDRHeadroom(texture->colorspace));
@ -1417,6 +1442,10 @@ SDL_Texture *SDL_CreateTextureWithProperties(SDL_Renderer *renderer, SDL_Propert
/* Now set the properties for the new texture */
props = SDL_GetTextureProperties(texture);
SDL_SetNumberProperty(props, SDL_PROP_TEXTURE_COLORSPACE_NUMBER, texture->colorspace);
SDL_SetNumberProperty(props, SDL_PROP_TEXTURE_FORMAT_NUMBER, texture->format);
SDL_SetNumberProperty(props, SDL_PROP_TEXTURE_ACCESS_NUMBER, texture->access);
SDL_SetNumberProperty(props, SDL_PROP_TEXTURE_WIDTH_NUMBER, texture->w);
SDL_SetNumberProperty(props, SDL_PROP_TEXTURE_HEIGHT_NUMBER, texture->h);
SDL_SetFloatProperty(props, SDL_PROP_TEXTURE_SDR_WHITE_POINT_FLOAT, texture->SDR_white_point);
if (texture->HDR_headroom > 0.0f) {
SDL_SetFloatProperty(props, SDL_PROP_TEXTURE_HDR_HEADROOM_FLOAT, texture->HDR_headroom);
@ -1647,21 +1676,15 @@ SDL_PropertiesID SDL_GetTextureProperties(SDL_Texture *texture)
return texture->props;
}
int SDL_QueryTexture(SDL_Texture *texture, SDL_PixelFormatEnum *format, int *access, int *w, int *h)
int SDL_GetTextureSize(SDL_Texture *texture, float *w, float *h)
{
CHECK_TEXTURE_MAGIC(texture, -1);
if (format) {
*format = texture->format;
}
if (access) {
*access = texture->access;
}
if (w) {
*w = texture->w;
*w = (float)texture->w;
}
if (h) {
*h = texture->h;
*h = (float)texture->h;
}
return 0;
}
@ -2410,9 +2433,9 @@ SDL_Texture *SDL_GetRenderTarget(SDL_Renderer *renderer)
static int UpdateLogicalPresentation(SDL_Renderer *renderer)
{
int logical_w = 1, logical_h = 1;
int output_w = renderer->main_view.pixel_w;
int output_h = renderer->main_view.pixel_h;
float logical_w = 1.0f, logical_h = 1.0f;
float output_w = renderer->main_view.pixel_w;
float output_h = renderer->main_view.pixel_h;
float want_aspect = 1.0f;
float real_aspect = 1.0f;
float scale;
@ -2422,23 +2445,23 @@ static int UpdateLogicalPresentation(SDL_Renderer *renderer)
return 0;
}
if (SDL_QueryTexture(renderer->logical_target, NULL, NULL, &logical_w, &logical_h) < 0) {
if (SDL_GetTextureSize(renderer->logical_target, &logical_w, &logical_h) < 0) {
goto error;
}
want_aspect = (float)logical_w / logical_h;
real_aspect = (float)output_w / output_h;
want_aspect = logical_w / logical_h;
real_aspect = output_w / output_h;
renderer->logical_src_rect.x = 0.0f;
renderer->logical_src_rect.y = 0.0f;
renderer->logical_src_rect.w = (float)logical_w;
renderer->logical_src_rect.h = (float)logical_h;
renderer->logical_src_rect.w = logical_w;
renderer->logical_src_rect.h = logical_h;
if (renderer->logical_presentation_mode == SDL_LOGICAL_PRESENTATION_INTEGER_SCALE) {
if (want_aspect > real_aspect) {
scale = (float)(output_w / logical_w); /* This an integer division! */
scale = (float)((int)output_w / (int)logical_w); /* This an integer division! */
} else {
scale = (float)(output_h / logical_h); /* This an integer division! */
scale = (float)((int)output_h / (int)logical_h); /* This an integer division! */
}
if (scale < 1.0f) {
@ -2454,15 +2477,15 @@ static int UpdateLogicalPresentation(SDL_Renderer *renderer)
SDL_fabsf(want_aspect - real_aspect) < 0.0001f) {
renderer->logical_dst_rect.x = 0.0f;
renderer->logical_dst_rect.y = 0.0f;
renderer->logical_dst_rect.w = (float)output_w;
renderer->logical_dst_rect.h = (float)output_h;
renderer->logical_dst_rect.w = output_w;
renderer->logical_dst_rect.h = output_h;
} else if (want_aspect > real_aspect) {
if (renderer->logical_presentation_mode == SDL_LOGICAL_PRESENTATION_LETTERBOX) {
/* We want a wider aspect ratio than is available - letterbox it */
scale = (float)output_w / logical_w;
scale = output_w / logical_w;
renderer->logical_dst_rect.x = 0.0f;
renderer->logical_dst_rect.w = (float)output_w;
renderer->logical_dst_rect.w = output_w;
renderer->logical_dst_rect.h = SDL_floorf(logical_h * scale);
renderer->logical_dst_rect.y = (output_h - renderer->logical_dst_rect.h) / 2.0f;
} else { /* renderer->logical_presentation_mode == SDL_LOGICAL_PRESENTATION_OVERSCAN */
@ -2470,18 +2493,18 @@ static int UpdateLogicalPresentation(SDL_Renderer *renderer)
zoom so logical height matches the real height
and the width will grow off the screen
*/
scale = (float)output_h / logical_h;
scale = output_h / logical_h;
renderer->logical_dst_rect.y = 0.0f;
renderer->logical_dst_rect.h = (float)output_h;
renderer->logical_dst_rect.h = output_h;
renderer->logical_dst_rect.w = SDL_floorf(logical_w * scale);
renderer->logical_dst_rect.x = (output_w - renderer->logical_dst_rect.w) / 2.0f;
}
} else {
if (renderer->logical_presentation_mode == SDL_LOGICAL_PRESENTATION_LETTERBOX) {
/* We want a narrower aspect ratio than is available - use side-bars */
scale = (float)output_h / logical_h;
scale = output_h / logical_h;
renderer->logical_dst_rect.y = 0.0f;
renderer->logical_dst_rect.h = (float)output_h;
renderer->logical_dst_rect.h = output_h;
renderer->logical_dst_rect.w = SDL_floorf(logical_w * scale);
renderer->logical_dst_rect.x = (output_w - renderer->logical_dst_rect.w) / 2.0f;
} else { /* renderer->logical_presentation_mode == SDL_LOGICAL_PRESENTATION_OVERSCAN */
@ -2489,9 +2512,9 @@ static int UpdateLogicalPresentation(SDL_Renderer *renderer)
zoom so logical width matches the real width
and the height will grow off the screen
*/
scale = (float)output_w / logical_w;
scale = output_w / logical_w;
renderer->logical_dst_rect.x = 0.0f;
renderer->logical_dst_rect.w = (float)output_w;
renderer->logical_dst_rect.w = output_w;
renderer->logical_dst_rect.h = SDL_floorf(logical_h * scale);
renderer->logical_dst_rect.y = (output_h - renderer->logical_dst_rect.h) / 2.0f;
}
@ -2506,23 +2529,26 @@ static int UpdateLogicalPresentation(SDL_Renderer *renderer)
return 0;
error:
SDL_SetRenderLogicalPresentation(renderer, 0, 0, SDL_LOGICAL_PRESENTATION_DISABLED, SDL_SCALEMODE_NEAREST);
SDL_SetRenderLogicalPresentation(renderer, 0.0f, 0.0f, SDL_LOGICAL_PRESENTATION_DISABLED, SDL_SCALEMODE_NEAREST);
return -1;
}
int SDL_SetRenderLogicalPresentation(SDL_Renderer *renderer, int w, int h, SDL_RendererLogicalPresentation mode, SDL_ScaleMode scale_mode)
int SDL_SetRenderLogicalPresentation(SDL_Renderer *renderer, float w, float h, SDL_RendererLogicalPresentation mode, SDL_ScaleMode scale_mode)
{
CHECK_RENDERER_MAGIC(renderer, -1);
w = SDL_ceilf(w);
h = SDL_ceilf(h);
if (mode == SDL_LOGICAL_PRESENTATION_DISABLED) {
if (renderer->logical_target) {
SDL_DestroyTexture(renderer->logical_target);
}
} else {
if (renderer->logical_target) {
int existing_w = 0, existing_h = 0;
float existing_w = 0.0f, existing_h = 0.0f;
if (SDL_QueryTexture(renderer->logical_target, NULL, NULL, &existing_w, &existing_h) < 0) {
if (SDL_GetTextureSize(renderer->logical_target, &existing_w, &existing_h) < 0) {
goto error;
}
if (w != existing_w || h != existing_h) {
@ -2530,7 +2556,7 @@ int SDL_SetRenderLogicalPresentation(SDL_Renderer *renderer, int w, int h, SDL_R
}
}
if (!renderer->logical_target) {
renderer->logical_target = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_UNKNOWN, SDL_TEXTUREACCESS_TARGET, w, h);
renderer->logical_target = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_UNKNOWN, SDL_TEXTUREACCESS_TARGET, (int)w, (int)h);
if (!renderer->logical_target) {
goto error;
}
@ -2544,24 +2570,24 @@ int SDL_SetRenderLogicalPresentation(SDL_Renderer *renderer, int w, int h, SDL_R
return UpdateLogicalPresentation(renderer);
error:
SDL_SetRenderLogicalPresentation(renderer, 0, 0, SDL_LOGICAL_PRESENTATION_DISABLED, SDL_SCALEMODE_NEAREST);
SDL_SetRenderLogicalPresentation(renderer, 0.0f, 0.0f, SDL_LOGICAL_PRESENTATION_DISABLED, SDL_SCALEMODE_NEAREST);
return -1;
}
int SDL_GetRenderLogicalPresentation(SDL_Renderer *renderer, int *w, int *h, SDL_RendererLogicalPresentation *mode, SDL_ScaleMode *scale_mode)
int SDL_GetRenderLogicalPresentation(SDL_Renderer *renderer, float *w, float *h, SDL_RendererLogicalPresentation *mode, SDL_ScaleMode *scale_mode)
{
CHECK_RENDERER_MAGIC(renderer, -1);
if (renderer->logical_target) {
if (SDL_QueryTexture(renderer->logical_target, NULL, NULL, w, h) < 0) {
if (SDL_GetTextureSize(renderer->logical_target, w, h) < 0) {
return -1;
}
} else {
if (w) {
*w = 0;
*w = 0.0f;
}
if (h) {
*h = 0;
*h = 0.0f;
}
}
@ -2591,11 +2617,11 @@ static void SDL_RenderLogicalBorders(SDL_Renderer *renderer)
rect.x = 0.0f;
rect.y = 0.0f;
rect.w = dst->x;
rect.h = (float)renderer->view->pixel_h;
rect.h = renderer->view->pixel_h;
SDL_RenderFillRect(renderer, &rect);
rect.x = dst->x + dst->w;
rect.w = (float)renderer->view->pixel_w - rect.x;
rect.w = renderer->view->pixel_w - rect.x;
SDL_RenderFillRect(renderer, &rect);
}
@ -2604,12 +2630,12 @@ static void SDL_RenderLogicalBorders(SDL_Renderer *renderer)
rect.x = 0.0f;
rect.y = 0.0f;
rect.w = (float)renderer->view->pixel_w;
rect.w = renderer->view->pixel_w;
rect.h = dst->y;
SDL_RenderFillRect(renderer, &rect);
rect.y = dst->y + dst->h;
rect.h = (float)renderer->view->pixel_h - rect.y;
rect.h = renderer->view->pixel_h - rect.y;
SDL_RenderFillRect(renderer, &rect);
}
@ -2794,25 +2820,24 @@ int SDL_ConvertEventToRenderCoordinates(SDL_Renderer *renderer, SDL_Event *event
return 0;
}
int SDL_SetRenderViewport(SDL_Renderer *renderer, const SDL_Rect *rect)
int SDL_SetRenderViewport(SDL_Renderer *renderer, const SDL_FRect *rect)
{
CHECK_RENDERER_MAGIC(renderer, -1);
if (rect) {
renderer->view->viewport.x = rect->x;
renderer->view->viewport.y = rect->y;
renderer->view->viewport.w = rect->w;
renderer->view->viewport.h = rect->h;
SDL_copyp(&renderer->view->viewport, rect);
} else {
renderer->view->viewport.x = 0;
renderer->view->viewport.y = 0;
renderer->view->viewport.w = -1;
renderer->view->viewport.h = -1;
renderer->view->viewport.x = 0.0f;
renderer->view->viewport.y = 0.0f;
renderer->view->viewport.w = -1.0f;
renderer->view->viewport.h = -1.0f;
}
UpdatePixelViewport(renderer, renderer->view);
return QueueCmdSetViewport(renderer);
}
int SDL_GetRenderViewport(SDL_Renderer *renderer, SDL_Rect *rect)
int SDL_GetRenderViewport(SDL_Renderer *renderer, SDL_FRect *rect)
{
CHECK_RENDERER_MAGIC(renderer, -1);
@ -2822,12 +2847,12 @@ int SDL_GetRenderViewport(SDL_Renderer *renderer, SDL_Rect *rect)
if (renderer->view->viewport.w >= 0) {
rect->w = renderer->view->viewport.w;
} else {
rect->w = (int)SDL_ceilf(renderer->view->pixel_w / renderer->view->scale.x);
rect->w = SDL_ceilf(renderer->view->pixel_w / renderer->view->scale.x);
}
if (renderer->view->viewport.h >= 0) {
rect->h = renderer->view->viewport.h;
} else {
rect->h = (int)SDL_ceilf(renderer->view->pixel_h / renderer->view->scale.y);
rect->h = SDL_ceilf(renderer->view->pixel_h / renderer->view->scale.y);
}
}
return 0;
@ -2837,8 +2862,8 @@ SDL_bool SDL_RenderViewportSet(SDL_Renderer *renderer)
{
CHECK_RENDERER_MAGIC(renderer, -1);
if (renderer->view->viewport.w >= 0 &&
renderer->view->viewport.h >= 0) {
if (renderer->view->viewport.w >= 0.0f &&
renderer->view->viewport.h >= 0.0f) {
return SDL_TRUE;
}
return SDL_FALSE;
@ -2848,45 +2873,40 @@ static void GetRenderViewportSize(SDL_Renderer *renderer, SDL_FRect *rect)
{
rect->x = 0.0f;
rect->y = 0.0f;
if (renderer->view->viewport.w >= 0) {
rect->w = (float)renderer->view->viewport.w;
if (renderer->view->viewport.w >= 0.0f) {
rect->w = renderer->view->viewport.w;
} else {
rect->w = renderer->view->pixel_w / renderer->view->scale.x;
}
if (renderer->view->viewport.h >= 0) {
rect->h = (float)renderer->view->viewport.h;
if (renderer->view->viewport.h >= 0.0f) {
rect->h = renderer->view->viewport.h;
} else {
rect->h = renderer->view->pixel_h / renderer->view->scale.y;
}
}
int SDL_SetRenderClipRect(SDL_Renderer *renderer, const SDL_Rect *rect)
int SDL_SetRenderClipRect(SDL_Renderer *renderer, const SDL_FRect *rect)
{
CHECK_RENDERER_MAGIC(renderer, -1)
if (rect && rect->w >= 0 && rect->h >= 0) {
renderer->view->clipping_enabled = SDL_TRUE;
renderer->view->clip_rect.x = rect->x;
renderer->view->clip_rect.y = rect->y;
renderer->view->clip_rect.w = rect->w;
renderer->view->clip_rect.h = rect->h;
SDL_copyp(&renderer->view->clip_rect, rect);
} else {
renderer->view->clipping_enabled = SDL_FALSE;
SDL_zero(renderer->view->clip_rect);
}
UpdatePixelClipRect(renderer, renderer->view);
return QueueCmdSetClipRect(renderer);
}
int SDL_GetRenderClipRect(SDL_Renderer *renderer, SDL_Rect *rect)
int SDL_GetRenderClipRect(SDL_Renderer *renderer, SDL_FRect *rect)
{
CHECK_RENDERER_MAGIC(renderer, -1)
if (rect) {
rect->x = renderer->view->clip_rect.x;
rect->y = renderer->view->clip_rect.y;
rect->w = renderer->view->clip_rect.w;
rect->h = renderer->view->clip_rect.h;
SDL_copyp(rect, &renderer->view->clip_rect);
}
return 0;
}
@ -2910,6 +2930,8 @@ int SDL_SetRenderScale(SDL_Renderer *renderer, float scaleX, float scaleY)
renderer->view->scale.x = scaleX;
renderer->view->scale.y = scaleY;
UpdatePixelViewport(renderer, renderer->view);
UpdatePixelClipRect(renderer, renderer->view);
/* The scale affects the existing viewport and clip rectangle */
retval += QueueCmdSetViewport(renderer);
@ -3120,7 +3142,7 @@ int SDL_RenderLine(SDL_Renderer *renderer, float x1, float y1, float x2, float y
static int RenderLineBresenham(SDL_Renderer *renderer, int x1, int y1, int x2, int y2, SDL_bool draw_last)
{
const int MAX_PIXELS = SDL_max(renderer->view->pixel_w, renderer->view->pixel_h) * 4;
const int MAX_PIXELS = (int)SDL_max(renderer->view->pixel_w, renderer->view->pixel_h) * 4;
int i, deltax, deltay, numpixels;
int d, dinc1, dinc2;
int x, xinc1, xinc2;
@ -3133,7 +3155,7 @@ static int RenderLineBresenham(SDL_Renderer *renderer, int x1, int y1, int x2, i
/* the backend might clip this further to the clipping rect, but we
just want a basic safety against generating millions of points for
massive lines. */
GetRenderViewportInPixels(renderer, &viewport);
viewport = renderer->view->pixel_viewport;
viewport.x = 0;
viewport.y = 0;
if (!SDL_GetRectAndLineIntersection(&viewport, &x1, &y1, &x2, &y2)) {
@ -3901,7 +3923,7 @@ static int SDLCALL SDL_SW_RenderGeometryRaw(SDL_Renderer *renderer,
int retval = 0;
int count = indices ? num_indices : num_vertices;
int prev[3]; /* Previous triangle vertex indices */
int texw = 0, texh = 0;
float texw = 0.0f, texh = 0.0f;
SDL_BlendMode blendMode = SDL_BLENDMODE_NONE;
float r = 0, g = 0, b = 0, a = 0;
@ -3910,7 +3932,7 @@ static int SDLCALL SDL_SW_RenderGeometryRaw(SDL_Renderer *renderer,
SDL_GetRenderDrawColorFloat(renderer, &r, &g, &b, &a);
if (texture) {
SDL_QueryTexture(texture, NULL, NULL, &texw, &texh);
SDL_GetTextureSize(texture, &texw, &texh);
}
prev[0] = -1;
@ -4357,7 +4379,7 @@ SDL_Surface *SDL_RenderReadPixels(SDL_Renderer *renderer, const SDL_Rect *rect)
FlushRenderCommands(renderer); /* we need to render before we read the results. */
GetRenderViewportInPixels(renderer, &real_rect);
real_rect = renderer->view->pixel_viewport;
if (rect) {
if (!SDL_GetRectIntersection(rect, &real_rect, &real_rect)) {

View File

@ -48,10 +48,12 @@ typedef struct SDL_RenderDriver SDL_RenderDriver;
/* Rendering view state */
typedef struct SDL_RenderViewState
{
int pixel_w;
int pixel_h;
SDL_Rect viewport;
SDL_Rect clip_rect;
float pixel_w;
float pixel_h;
SDL_FRect viewport;
SDL_Rect pixel_viewport;
SDL_FRect clip_rect;
SDL_Rect pixel_cliprect;
SDL_bool clipping_enabled;
SDL_FPoint scale;

View File

@ -1453,7 +1453,7 @@ static SDL_Surface *GL_RenderReadPixels(SDL_Renderer *renderer, const SDL_Rect *
SDL_PixelFormatEnum format = renderer->target ? renderer->target->format : SDL_PIXELFORMAT_ARGB8888;
GLint internalFormat;
GLenum targetFormat, type;
int w, h;
float h;
SDL_Surface *surface;
GL_ActivateRenderer(renderer);
@ -1468,12 +1468,12 @@ static SDL_Surface *GL_RenderReadPixels(SDL_Renderer *renderer, const SDL_Rect *
return NULL;
}
SDL_GetCurrentRenderOutputSize(renderer, &w, &h);
SDL_GetCurrentRenderOutputSize(renderer, NULL, &h);
data->glPixelStorei(GL_PACK_ALIGNMENT, 1);
data->glPixelStorei(GL_PACK_ROW_LENGTH, (surface->pitch / SDL_BYTESPERPIXEL(format)));
data->glReadPixels(rect->x, renderer->target ? rect->y : (h - rect->y) - rect->h,
data->glReadPixels(rect->x, renderer->target ? rect->y : ((int)h - rect->y) - rect->h,
rect->w, rect->h, targetFormat, type, surface->pixels);
if (GL_CheckError("glReadPixels()", renderer) < 0) {

View File

@ -1967,7 +1967,7 @@ static SDL_Surface *GLES2_RenderReadPixels(SDL_Renderer *renderer, const SDL_Rec
{
GLES2_RenderData *data = (GLES2_RenderData *)renderer->driverdata;
SDL_PixelFormatEnum format = renderer->target ? renderer->target->format : SDL_PIXELFORMAT_RGBA32;
int w, h;
float h;
SDL_Surface *surface;
surface = SDL_CreateSurface(rect->w, rect->h, format);
@ -1975,9 +1975,9 @@ static SDL_Surface *GLES2_RenderReadPixels(SDL_Renderer *renderer, const SDL_Rec
return NULL;
}
SDL_GetCurrentRenderOutputSize(renderer, &w, &h);
SDL_GetCurrentRenderOutputSize(renderer, NULL, &h);
data->glReadPixels(rect->x, renderer->target ? rect->y : (h - rect->y) - rect->h,
data->glReadPixels(rect->x, renderer->target ? rect->y : ((int)h - rect->y) - rect->h,
rect->w, rect->h, GL_RGBA, GL_UNSIGNED_BYTE, surface->pixels);
if (GL_CheckError("glReadPixels()", renderer) < 0) {
SDL_DestroySurface(surface);

View File

@ -1081,7 +1081,7 @@ void read_pixels(int x, int y, size_t width, size_t height, void *data)
static SDL_Surface *VITA_GXM_RenderReadPixels(SDL_Renderer *renderer, const SDL_Rect *rect)
{
Uint32 format = renderer->target ? renderer->target->format : SDL_PIXELFORMAT_ABGR8888;
int w, h;
float h;
SDL_Surface *surface;
// TODO: read from texture rendertarget.
@ -1095,9 +1095,9 @@ static SDL_Surface *VITA_GXM_RenderReadPixels(SDL_Renderer *renderer, const SDL_
return NULL;
}
SDL_GetCurrentRenderOutputSize(renderer, &w, &h);
SDL_GetCurrentRenderOutputSize(renderer, NULL, &h);
read_pixels(rect->x, renderer->target ? rect->y : (h - rect->y) - rect->h,
read_pixels(rect->x, renderer->target ? rect->y : ((int)h - rect->y) - rect->h,
rect->w, rect->h, surface->pixels);
/* Flip the rows to be top-down if necessary */

View File

@ -2509,8 +2509,9 @@ void SDLTest_CommonDrawWindowInfo(SDL_Renderer *renderer, SDL_Window *window, fl
float textY = 0.0f;
const int lineHeight = 10;
int x, y, w, h;
float fx, fy;
float fx, fy, fw, fh;
SDL_Rect rect;
SDL_FRect frect;
const SDL_DisplayMode *mode;
float scaleX, scaleY;
SDL_MouseButtonFlags flags;
@ -2544,21 +2545,21 @@ void SDLTest_CommonDrawWindowInfo(SDL_Renderer *renderer, SDL_Window *window, fl
SDLTest_DrawString(renderer, 0.0f, textY, text);
textY += lineHeight;
if (0 == SDL_GetRenderOutputSize(renderer, &w, &h)) {
(void)SDL_snprintf(text, sizeof(text), "SDL_GetRenderOutputSize: %dx%d", w, h);
if (0 == SDL_GetRenderOutputSize(renderer, &fw, &fh)) {
(void)SDL_snprintf(text, sizeof(text), "SDL_GetRenderOutputSize: %gx%g", fw, fh);
SDLTest_DrawString(renderer, 0.0f, textY, text);
textY += lineHeight;
}
if (0 == SDL_GetCurrentRenderOutputSize(renderer, &w, &h)) {
(void)SDL_snprintf(text, sizeof(text), "SDL_GetCurrentRenderOutputSize: %dx%d", w, h);
if (0 == SDL_GetCurrentRenderOutputSize(renderer, &fw, &fh)) {
(void)SDL_snprintf(text, sizeof(text), "SDL_GetCurrentRenderOutputSize: %gx%g", fw, fh);
SDLTest_DrawString(renderer, 0.0f, textY, text);
textY += lineHeight;
}
SDL_GetRenderViewport(renderer, &rect);
(void)SDL_snprintf(text, sizeof(text), "SDL_GetRenderViewport: %d,%d, %dx%d",
rect.x, rect.y, rect.w, rect.h);
SDL_GetRenderViewport(renderer, &frect);
(void)SDL_snprintf(text, sizeof(text), "SDL_GetRenderViewport: %g,%g, %gx%g",
frect.x, frect.y, frect.w, frect.h);
SDLTest_DrawString(renderer, 0.0f, textY, text);
textY += lineHeight;
@ -2568,8 +2569,8 @@ void SDLTest_CommonDrawWindowInfo(SDL_Renderer *renderer, SDL_Window *window, fl
SDLTest_DrawString(renderer, 0.0f, textY, text);
textY += lineHeight;
SDL_GetRenderLogicalPresentation(renderer, &w, &h, &logical_presentation, &logical_scale_mode);
(void)SDL_snprintf(text, sizeof(text), "SDL_GetRenderLogicalPresentation: %dx%d ", w, h);
SDL_GetRenderLogicalPresentation(renderer, &fw, &fh, &logical_presentation, &logical_scale_mode);
(void)SDL_snprintf(text, sizeof(text), "SDL_GetRenderLogicalPresentation: %gx%g ", fw, fh);
SDLTest_PrintLogicalPresentation(text, sizeof(text), logical_presentation);
SDL_snprintfcat(text, sizeof(text), ", ");
SDLTest_PrintScaleMode(text, sizeof(text), logical_scale_mode);

View File

@ -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 */

View File

@ -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);

View File

@ -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();

View File

@ -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, &timestampNS) : 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);
}

View File

@ -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) {

View File

@ -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);
}
}

View File

@ -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);

View File

@ -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;

View File

@ -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);

View File

@ -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);
}

View File

@ -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) {

View File

@ -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;

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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);

View File

@ -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) {

View File

@ -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);