| 180 | } |
| 181 | |
| 182 | void CalculateTextOffsets(dp::TitleDecl const titleDecl, m2::PointF const & primaryTextSize, |
| 183 | m2::PointF const & secondaryTextSize, glsl::vec2 & primaryResultOffset, |
| 184 | glsl::vec2 & secondaryResultOffset) |
| 185 | { |
| 186 | primaryResultOffset = glsl::vec2(0.0f, 0.0f); |
| 187 | secondaryResultOffset = glsl::vec2(0.0f, 0.0f); |
| 188 | |
| 189 | bool const hasSecondary = !titleDecl.m_secondaryText.empty(); |
| 190 | |
| 191 | if (titleDecl.m_anchor & dp::Top) |
| 192 | { |
| 193 | // In the case when the anchor is dp::Top the value of primary offset y > 0, |
| 194 | // the text shape is below the POI. |
| 195 | primaryResultOffset.y = titleDecl.m_primaryOffset.y; |
| 196 | if (hasSecondary) |
| 197 | secondaryResultOffset.y = titleDecl.m_primaryOffset.y + primaryTextSize.y + titleDecl.m_secondaryOffset.y; |
| 198 | } |
| 199 | else if (titleDecl.m_anchor & dp::Bottom) |
| 200 | { |
| 201 | // In the case when the anchor is dp::Bottom the value of primary offset y < 0, |
| 202 | // the text shape is above the POI. |
| 203 | primaryResultOffset.y = titleDecl.m_primaryOffset.y; |
| 204 | if (hasSecondary) |
| 205 | { |
| 206 | primaryResultOffset.y -= secondaryTextSize.y + titleDecl.m_secondaryOffset.y; |
| 207 | secondaryResultOffset.y = titleDecl.m_primaryOffset.y; |
| 208 | } |
| 209 | } |
| 210 | else if (hasSecondary) |
| 211 | { |
| 212 | // In the case when the anchor is dp::Center there isn't primary offset y. |
| 213 | primaryResultOffset.y = -(primaryTextSize.y + titleDecl.m_secondaryOffset.y) / 2.0f; |
| 214 | secondaryResultOffset.y = (secondaryTextSize.y + titleDecl.m_secondaryOffset.y) / 2.0f; |
| 215 | } |
| 216 | |
| 217 | if (titleDecl.m_anchor & dp::Left) |
| 218 | { |
| 219 | // In the case when the anchor is dp::Left the value of primary offset x > 0, |
| 220 | // the text shape is on the right from the POI. |
| 221 | primaryResultOffset.x = titleDecl.m_primaryOffset.x; |
| 222 | if (hasSecondary) |
| 223 | secondaryResultOffset.x = primaryResultOffset.x; |
| 224 | } |
| 225 | else if (titleDecl.m_anchor & dp::Right) |
| 226 | { |
| 227 | // In the case when the anchor is dp::Right the value of primary offset x < 0, |
| 228 | // the text shape is on the left from the POI. |
| 229 | primaryResultOffset.x = titleDecl.m_primaryOffset.x; |
| 230 | if (hasSecondary) |
| 231 | secondaryResultOffset.x = primaryResultOffset.x; |
| 232 | } |
| 233 | } |
| 234 | |
| 235 | void TextShape::Draw(ref_ptr<dp::GraphicsContext> context, ref_ptr<dp::Batcher> batcher, |
| 236 | ref_ptr<dp::TextureManager> textures) const |