MCPcopy Create free account
hub / github.com/XCSoar/XCSoar / TextInBox

Function TextInBox

src/Renderer/TextInBox.cpp:93–164  ·  view source on GitHub ↗

returns true if really wrote something

Source from the content-addressed store, hash-verified

91
92// returns true if really wrote something
93bool
94TextInBox(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);

Callers 10

DrawMethod · 0.85
DrawMethod · 0.85
DrawMethod · 0.85
MapWaypointLabelRenderFunction · 0.85
DrawPanInfoMethod · 0.85
DrawGPSStatusMethod · 0.85
DrawMapScaleMethod · 0.85
DrawFLARMTrafficMethod · 0.85
DrawGLinkTrafficMethod · 0.85
DrawSkyLinesTrafficMethod · 0.85

Calls 15

GetTextPaddingFunction · 0.85
TextInBoxMoveInViewFunction · 0.85
VptScaleFunction · 0.85
RenderShadowedTextFunction · 0.85
checkMethod · 0.80
BrushClass · 0.70
CalcTextSizeMethod · 0.45
SelectBlackPenMethod · 0.45
SelectWhitePenMethod · 0.45
SelectMethod · 0.45
WithAlphaMethod · 0.45
SelectWhiteBrushMethod · 0.45

Tested by

no test coverage detected