| 99 | } |
| 100 | |
| 101 | void ImageWidget::transformDrawables() { |
| 102 | m_drawables.clear(); |
| 103 | for (auto drawable : m_baseDrawables) |
| 104 | m_drawables.append(Drawable(drawable)); |
| 105 | |
| 106 | if (m_rotation != 0) |
| 107 | Drawable::rotateAll(m_drawables, m_rotation); |
| 108 | |
| 109 | // When 'centered' is true, the drawables provided are pre-centered |
| 110 | // around 0,0. Tooltips use this, as well as quest dialog portraits. |
| 111 | if (m_centered) { |
| 112 | auto boundBox = Drawable::boundBoxAll(m_drawables, m_trim); |
| 113 | Drawable::translateAll(m_drawables, -boundBox.center()); |
| 114 | } |
| 115 | |
| 116 | auto boundBox = Drawable::boundBoxAll(m_drawables, m_trim); |
| 117 | auto size = boundBox.size().piecewiseMax({0, 0}); |
| 118 | if (size[0] && size[1]) { |
| 119 | if ((size[0] > m_maxSize[0]) || (size[1] > m_maxSize[1])) { |
| 120 | m_scale = std::min(m_maxSize[0] / size[0], m_maxSize[1] / size[1]); |
| 121 | } else if ((size[0] < m_minSize[0]) || (size[1] < m_minSize[1])) { |
| 122 | m_scale = std::min(m_minSize[0] / size[0], m_minSize[1] / size[1]); |
| 123 | } |
| 124 | } |
| 125 | |
| 126 | Drawable::scaleAll(m_drawables, m_scale); |
| 127 | |
| 128 | setSize(Vec2I((size * m_scale).ceil())); |
| 129 | } |
| 130 | |
| 131 | } |