sdlxRenderCoordinatesToWindow function render

bool sdlxRenderCoordinatesToWindow(
  1. Pointer<SdlRenderer> renderer, {
  2. required SdlxFPoint renderPosition,
  3. required SdlxFPoint windowPosition,
})

Get a point in window coordinates when given a point in render coordinates.

This takes into account several states:

  • The window dimensions.
  • The logical presentation settings (SDL_SetRenderLogicalPresentation)
  • The scale (SDL_SetRenderScale)
  • The viewport (SDL_SetRenderViewport)

\param renderer the rendering context. \param x the x coordinate in render coordinates. \param y the y coordinate in render coordinates. \param window_x a pointer filled with the x coordinate in window coordinates. \param window_y a pointer filled with the y coordinate in window coordinates. \returns true on success or false on failure; call SDL_GetError() for more information.

\threadsafety This function should only be called on the main thread.

\since This function is available since SDL 3.2.0.

\sa SDL_SetRenderLogicalPresentation \sa SDL_SetRenderScale \sa SDL_SetRenderViewport

extern SDL_DECLSPEC bool SDLCALL SDL_RenderCoordinatesToWindow(SDL_Renderer *renderer, float x, float y, float *window_x, float *window_y)

Implementation

bool sdlxRenderCoordinatesToWindow(
  Pointer<SdlRenderer> renderer, {
  required SdlxFPoint renderPosition,
  required SdlxFPoint windowPosition,
}) {
  final windowXPointer = calloc<Float>();
  final windowYPointer = calloc<Float>();
  final result = sdlRenderCoordinatesToWindow(
    renderer,
    renderPosition.x,
    renderPosition.y,
    windowXPointer,
    windowYPointer,
  );
  if (result) {
    windowPosition
      ..x = windowXPointer.value
      ..y = windowYPointer.value;
  }
  windowXPointer.callocFree();
  windowYPointer.callocFree();
  return result;
}