| 60 | // -------------------------------------------------------------------------------------------------------------------- |
| 61 | |
| 62 | static void applyGeometryConstraints(const uint minimumWidth, |
| 63 | const uint minimumHeight, |
| 64 | const bool keepAspectRatio, |
| 65 | v3_view_rect* const rect) |
| 66 | { |
| 67 | d_debug("applyGeometryConstraints %u %u %d {%d,%d,%d,%d} | BEFORE", |
| 68 | minimumWidth, minimumHeight, keepAspectRatio, rect->top, rect->left, rect->right, rect->bottom); |
| 69 | const int32_t minWidth = static_cast<int32_t>(minimumWidth); |
| 70 | const int32_t minHeight = static_cast<int32_t>(minimumHeight); |
| 71 | |
| 72 | if (keepAspectRatio) |
| 73 | { |
| 74 | if (rect->right < 1) |
| 75 | rect->right = 1; |
| 76 | if (rect->bottom < 1) |
| 77 | rect->bottom = 1; |
| 78 | |
| 79 | const double ratio = static_cast<double>(minWidth) / static_cast<double>(minHeight); |
| 80 | const double reqRatio = static_cast<double>(rect->right) / static_cast<double>(rect->bottom); |
| 81 | |
| 82 | if (d_isNotEqual(ratio, reqRatio)) |
| 83 | { |
| 84 | // fix width |
| 85 | if (reqRatio > ratio) |
| 86 | rect->right = d_roundToIntPositive(rect->bottom * ratio); |
| 87 | // fix height |
| 88 | else |
| 89 | rect->bottom = d_roundToIntPositive(static_cast<double>(rect->right) / ratio); |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | if (minWidth > rect->right) |
| 94 | rect->right = minWidth; |
| 95 | if (minHeight > rect->bottom) |
| 96 | rect->bottom = minHeight; |
| 97 | |
| 98 | d_debug("applyGeometryConstraints %u %u %d {%d,%d,%d,%d} | AFTER", |
| 99 | minimumWidth, minimumHeight, keepAspectRatio, rect->top, rect->left, rect->right, rect->bottom); |
| 100 | } |
| 101 | |
| 102 | // -------------------------------------------------------------------------------------------------------------------- |
| 103 |
no test coverage detected