ObjectivelyMVC
Object oriented MVC framework for SDL3 and GNU C
Loading...
Searching...
No Matches
Window.c File Reference
#include <assert.h>
#include <math.h>
#include "Window.h"

Go to the source code of this file.

Functions

SDL_Rect MVC_TransformToWindow (SDL_Window *window, const SDL_Rect *rect)
 Transforms the specified rectangle to normalized device coordinates in window.
 

Function Documentation

◆ MVC_TransformToWindow()

SDL_Rect MVC_TransformToWindow ( SDL_Window *  window,
const SDL_Rect *  rect 
)

Transforms the specified rectangle to normalized device coordinates in window.

Parameters
windowThe window.
rectA rectangle defined in object space.
Returns
The transformed rectangle.

Definition at line 29 of file Window.c.

29 {
30
31 assert(rect);
32
33 const float pixelDensity = SDL_GetWindowPixelDensity(window);
34
35 // SDL_gpu uses top-left origin (same as SDL), so no Y-flip is required.
36 const float x = SDL_roundf(rect->x * pixelDensity);
37 const float y = SDL_roundf(rect->y * pixelDensity);
38 const float w = SDL_roundf(rect->w * pixelDensity);
39 const float h = SDL_roundf(rect->h * pixelDensity);
40
41 return (SDL_Rect) {
42 .x = (int) x,
43 .y = (int) y,
44 .w = (int) w,
45 .h = (int) h,
46 };
47}