From 5a5ed17c30e24c994c51c11078a533f0937c5de5 Mon Sep 17 00:00:00 2001 From: Ivan Mahonin Date: May 01 2023 07:52:44 +0000 Subject: #assistants: tglDrawDoubleSegment --- diff --git a/toonz/sources/common/tgl/tgl.cpp b/toonz/sources/common/tgl/tgl.cpp index 88c6989..705c47a 100644 --- a/toonz/sources/common/tgl/tgl.cpp +++ b/toonz/sources/common/tgl/tgl.cpp @@ -123,6 +123,34 @@ void tglDrawSegment(const TPointD &p1, const TPointD &p2) { //----------------------------------------------------------------------------- +void tglDrawDoubleSegment(const TPointD &p1, const TPointD &p2) { + double color[4] = {}; + double width = 1.0; + glGetDoublev(GL_CURRENT_COLOR, color); + glGetDoublev(GL_LINE_WIDTH, &width); + if (width < 1.0) width = 1.0; + + TPointD d = p2 - p1; + double k = sqrt(d.x*d.x + d.y*d.y); + if (k <= 1e-9) return; + k = 0.5*width/k; + TPointD offset(-k*d.y, k*d.x); + + glColor4d(1.0 - color[0], 1.0 - color[1], 1.0 - color[2], color[3]); + glBegin(GL_LINES); + tglVertex(p1 - offset); + tglVertex(p2 - offset); + glEnd(); + + glColor4dv(color); + glBegin(GL_LINES); + tglVertex(p1 + offset); + tglVertex(p2 + offset); + glEnd(); +} + +//----------------------------------------------------------------------------- + void tglDrawCircle(const TPointD ¢er, double radius) { if (radius <= 0) return; diff --git a/toonz/sources/include/tgl.h b/toonz/sources/include/tgl.h index 5c993b1..67435ea 100644 --- a/toonz/sources/include/tgl.h +++ b/toonz/sources/include/tgl.h @@ -141,6 +141,11 @@ DVAPI void tglDrawDisk(const TPointD &c, double r); */ DVAPI void tglDrawSegment(const TPointD &p1, const TPointD &p2); +/*! + Draw a segment pair - positive and negative. + */ +DVAPI void tglDrawDoubleSegment(const TPointD &p1, const TPointD &p2); + inline void tglDrawSegment(const TPoint &p1, const TPoint &p2) { tglDrawSegment(convert(p1), convert(p2)); }