MCPcopy Create free account
hub / github.com/Tom94/tev / drawCoordinateSystem

Method drawCoordinateSystem

src/ImageCanvas.cpp:218–364  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

216}
217
218void ImageCanvas::drawCoordinateSystem(NVGcontext* ctx) {
219 TEV_ASSERT(mImage, "Can only draw coordinate system if there exists an image.");
220
221 const auto displayWindowToNano = displayWindowToNanogui(mImage.get());
222
223 enum DrawFlags {
224 Label = 1,
225 Region = 2,
226 };
227
228 const auto drawWindow = [&](Box2f window, Color color, bool top, bool right, string_view name, DrawFlags flags) {
229 float fontSize = 20;
230 float strokeWidth = 3.0f;
231
232 Vector2i topLeft = m_pos +
233 Vector2i{
234 displayWindowToNano * Vector2f{window.min.x(), window.min.y()}
235 };
236 Vector2i topRight = m_pos +
237 Vector2i{
238 displayWindowToNano * Vector2f{window.max.x(), window.min.y()}
239 };
240 Vector2i bottomLeft = m_pos +
241 Vector2i{
242 displayWindowToNano * Vector2f{window.min.x(), window.max.y()}
243 };
244 Vector2i bottomRight = m_pos +
245 Vector2i{
246 displayWindowToNano * Vector2f{window.max.x(), window.max.y()}
247 };
248
249 nvgSave(ctx);
250
251 nvgFontFace(ctx, "sans-bold");
252 nvgFontSize(ctx, fontSize);
253 nvgTextAlign(ctx, (right ? NVG_ALIGN_RIGHT : NVG_ALIGN_LEFT) | (top ? NVG_ALIGN_BOTTOM : NVG_ALIGN_TOP));
254 float textWidth = nvgTextBounds(ctx, 0, 0, name.data(), name.data() + name.size(), nullptr);
255 float textAlpha = std::max(std::min(1.0f, (((topRight.x() - topLeft.x() - textWidth - 5) / 30))), 0.0f);
256 float regionAlpha = std::max(std::min(1.0f, (((topRight.x() - topLeft.x() - textWidth - 5) / 30))), 0.0f);
257
258 Color textColor = Color(190, 255);
259 textColor.a() = textAlpha;
260
261 if (flags & Region) {
262 color.a() = regionAlpha;
263
264 nvgBeginPath(ctx);
265 nvgMoveTo(ctx, bottomLeft.x(), bottomLeft.y());
266 nvgLineTo(ctx, topLeft.x(), topLeft.y());
267 nvgLineTo(ctx, topRight.x(), topRight.y());
268 nvgLineTo(ctx, bottomRight.x(), bottomRight.y());
269 nvgLineTo(ctx, bottomLeft.x(), bottomLeft.y());
270 nvgStrokeWidth(ctx, strokeWidth);
271 nvgStrokeColor(ctx, color);
272 nvgStroke(ctx);
273 }
274
275 if (!name.empty() && (flags & Label)) {

Callers

nothing calls this directly

Calls 10

maxFunction · 0.85
minFunction · 0.85
ColorClass · 0.85
dataWindowMethod · 0.80
displayWindowMethod · 0.80
valueMethod · 0.80
getMethod · 0.45
dataMethod · 0.45
sizeMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected