* Calculate x and y coordinates for an aligned object within a window. * @param r Rectangle of the widget to be drawn in. * @param d Dimension of the object to be drawn. * @param align Alignment of the object. * @return A point containing the position at which to draw. */
| 136 | * @return A point containing the position at which to draw. |
| 137 | */ |
| 138 | static inline Point GetAlignedPosition(const Rect &r, const Dimension &d, StringAlignment align) |
| 139 | { |
| 140 | Point p; |
| 141 | /* In case we have a RTL language we swap the alignment. */ |
| 142 | if (!(align & SA_FORCE) && _current_text_dir == TD_RTL && (align & SA_HOR_MASK) != SA_HOR_CENTER) align ^= SA_RIGHT; |
| 143 | switch (align & SA_HOR_MASK) { |
| 144 | case SA_LEFT: p.x = r.left; break; |
| 145 | case SA_HOR_CENTER: p.x = CentreBounds(r.left, r.right, d.width); break; |
| 146 | case SA_RIGHT: p.x = r.right + 1 - d.width; break; |
| 147 | default: NOT_REACHED(); |
| 148 | } |
| 149 | switch (align & SA_VERT_MASK) { |
| 150 | case SA_TOP: p.y = r.top; break; |
| 151 | case SA_VERT_CENTER: p.y = CentreBounds(r.top, r.bottom, d.height); break; |
| 152 | case SA_BOTTOM: p.y = r.bottom + 1 - d.height; break; |
| 153 | default: NOT_REACHED(); |
| 154 | } |
| 155 | return p; |
| 156 | } |
| 157 | |
| 158 | /** |
| 159 | * Compute the vertical position of the draggable part of scrollbar |
no test coverage detected