ObjectivelyMVC 0.1.0
Object oriented MVC framework for OpenGL, SDL2 and GNU C
Functions
Window.h File Reference
#include <ObjectivelyMVC/Types.h>

Go to the source code of this file.

Functions

OBJECTIVELYMVC_EXPORT SDL_Rect MVC_TransformToWindow (SDL_Window *window, const SDL_Rect *rect)
 Transforms the specified rectangle to normalized device coordinates in window. More...
 
OBJECTIVELYMVC_EXPORT double MVC_WindowScale (SDL_Window *window, int *height, int *drawableHeight)
 Resolves the scale factor of the specified window for High-DPI support. More...
 

Function Documentation

◆ MVC_TransformToWindow()

OBJECTIVELYMVC_EXPORT 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 28 of file Window.c.

28 {
29
30 assert(rect);
31
32 SDL_Rect transformed = *rect;
33
34 int dh = 0;
35 const double scale = MVC_WindowScale(window, NULL, &dh);
36
37 transformed.x *= scale;
38 transformed.y *= scale;
39 transformed.w *= scale;
40 transformed.h *= scale;
41
42 transformed.y = dh - transformed.h - transformed.y;
43
44 return transformed;
45}
double MVC_WindowScale(SDL_Window *window, int *height, int *drawableHeight)
Resolves the scale factor of the specified window for High-DPI support.
Definition: Window.c:47

◆ MVC_WindowScale()

OBJECTIVELYMVC_EXPORT double MVC_WindowScale ( SDL_Window *  window,
int *  height,
int *  drawableHeight 
)

Resolves the scale factor of the specified window for High-DPI support.

Parameters
windowThe window, or NULL for the current OpenGL window.
heightAn optional output parameter to retrieve the window height.
drawableHeightAn optional output parameter to retrieve the window drawable height.
Returns
The scale factor of the specified window.
Remarks
Views and other classes should invoke this method to alter their rendering behavior for High-DPI displays. This is particularly relevant for Views that render textures.

Definition at line 47 of file Window.c.

47 {
48
49 window = window ?: SDL_GL_GetCurrentWindow();
50 assert(window);
51
52 int h;
53 SDL_GetWindowSize(window, NULL, &h);
54
55 if (height) {
56 *height = h;
57 }
58
59 if (h) {
60
61 int dh;
62 SDL_GL_GetDrawableSize(window, NULL, &dh);
63
64 if (drawableHeight) {
65 *drawableHeight = dh;
66 }
67
68 if (dh) {
69 return dh / (double) h;
70 }
71 }
72
73 return 1.0;
74}