Skip to content

OpenToonz - An open-source full-featured 2D animation creation software

C

#assistants: tglDrawDoubleSegment

Ivan Mahonin5a5ed17c30e2
diff --git a/toonz/sources/common/tgl/tgl.cpp b/toonz/sources/common/tgl/tgl.cpp
index 88c69891d..705c47a43 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 &center, double radius) {
if (radius <= 0) return;
diff --git a/toonz/sources/include/tgl.h b/toonz/sources/include/tgl.h
index 5c993b173..67435ead5 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));
}