returns true if really wrote something
| 91 | |
| 92 | // returns true if really wrote something |
| 93 | bool |
| 94 | TextInBox(Canvas &canvas, const TCHAR *text, PixelPoint p, |
| 95 | TextInBoxMode mode, const PixelRect &map_rc, |
| 96 | LabelBlock *label_block) noexcept |
| 97 | { |
| 98 | // landable waypoint label inside white box |
| 99 | |
| 100 | PixelSize tsize = canvas.CalcTextSize(text); |
| 101 | |
| 102 | if (mode.align == TextInBoxMode::Alignment::RIGHT) |
| 103 | p.x -= tsize.width; |
| 104 | else if (mode.align == TextInBoxMode::Alignment::CENTER) |
| 105 | p.x -= tsize.width / 2; |
| 106 | |
| 107 | if (mode.vertical_position == TextInBoxMode::VerticalPosition::ABOVE) |
| 108 | p.y -= tsize.height; |
| 109 | else if (mode.vertical_position == TextInBoxMode::VerticalPosition::CENTERED) |
| 110 | p.y -= tsize.height / 2; |
| 111 | |
| 112 | const unsigned padding = Layout::GetTextPadding(); |
| 113 | PixelRect rc; |
| 114 | rc.left = p.x - padding - 1; |
| 115 | rc.right = p.x + tsize.width + padding; |
| 116 | rc.top = p.y; |
| 117 | rc.bottom = p.y + tsize.height + 1; |
| 118 | |
| 119 | if (mode.move_in_view) { |
| 120 | auto offset = TextInBoxMoveInView(rc, map_rc); |
| 121 | p.x += offset.x; |
| 122 | p.y += offset.y; |
| 123 | } |
| 124 | |
| 125 | if (label_block != nullptr && !label_block->check(rc)) |
| 126 | return false; |
| 127 | |
| 128 | if (mode.shape == LabelShape::ROUNDED_BLACK || |
| 129 | mode.shape == LabelShape::ROUNDED_WHITE) { |
| 130 | if (mode.shape == LabelShape::ROUNDED_BLACK) |
| 131 | canvas.SelectBlackPen(); |
| 132 | else |
| 133 | canvas.SelectWhitePen(); |
| 134 | |
| 135 | { |
| 136 | #ifdef ENABLE_OPENGL |
| 137 | const ScopeAlphaBlend alpha_blend; |
| 138 | canvas.Select(Brush(COLOR_WHITE.WithAlpha(0xa0))); |
| 139 | #else |
| 140 | canvas.SelectWhiteBrush(); |
| 141 | #endif |
| 142 | |
| 143 | canvas.DrawRoundRectangle(rc, PixelSize{Layout::VptScale(8)}); |
| 144 | } |
| 145 | |
| 146 | canvas.SetBackgroundTransparent(); |
| 147 | canvas.SetTextColor(COLOR_BLACK); |
| 148 | canvas.DrawText(p, text); |
| 149 | } else if (mode.shape == LabelShape::FILLED) { |
| 150 | canvas.SetBackgroundColor(COLOR_WHITE); |
no test coverage detected