From: Jean-Marc Lasgouttes Date: Tue, 19 Dec 2017 21:32:32 +0000 (+0100) Subject: Do not draw inactive math corners when they have mathbg color X-Git-Tag: 2.3.0rc2~128 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=546a6a2a310b12fa0d3692cca10920a938f07f9c;p=features.git Do not draw inactive math corners when they have mathbg color By default, inactive math corners are invisible. In practice they are annoying because they are visible when selecting text, and they can also overwrite some parts of the equation. The code in Inset::drawMarkers2, which is only used for maths, is moved to InsetMathHull. Moreover, the inactive corners are not drawn when they have the same color as the math background. A better way to achieve this would be to set the color to transparent, but we do not support this yet. (cherry picked from commit 68614e9783382b6267fc9ce32ed45bc2477007dd) --- diff --git a/src/insets/Inset.cpp b/src/insets/Inset.cpp index f2e2d4bcb8..0257ed0c45 100644 --- a/src/insets/Inset.cpp +++ b/src/insets/Inset.cpp @@ -553,22 +553,6 @@ void Inset::drawMarkers(PainterInfo & pi, int x, int y) const } -void Inset::drawMarkers2(PainterInfo & pi, int x, int y) const -{ - ColorCode pen_color = mouseHovered(pi.base.bv) || editing(pi.base.bv)? - Color_mathframe : Color_mathcorners; - - drawMarkers(pi, x, y); - Dimension const dim = dimension(*pi.base.bv); - int const t = x + dim.width() - 1; - int const a = y - dim.ascent(); - pi.pain.line(x, a + 3, x, a, pen_color); - pi.pain.line(t, a + 3, t, a, pen_color); - pi.pain.line(x, a, x + 3, a, pen_color); - pi.pain.line(t - 3, a, t, a, pen_color); -} - - bool Inset::editing(BufferView const * bv) const { return bv->cursor().isInside(this); diff --git a/src/insets/Inset.h b/src/insets/Inset.h index 94e9d1a668..5a7b32e8d6 100644 --- a/src/insets/Inset.h +++ b/src/insets/Inset.h @@ -210,9 +210,7 @@ public: virtual bool showInsetDialog(BufferView *) const; /// draw two angular markers - void drawMarkers(PainterInfo & pi, int x, int y) const; - /// draw four angular markers - void drawMarkers2(PainterInfo & pi, int x, int y) const; + virtual void drawMarkers(PainterInfo & pi, int x, int y) const; /// add space for markers void metricsMarkers(Dimension & dim, int framesize = 1) const; /// add space for markers diff --git a/src/mathed/InsetMathHull.cpp b/src/mathed/InsetMathHull.cpp index 78175f3f70..4e29d4ce24 100644 --- a/src/mathed/InsetMathHull.cpp +++ b/src/mathed/InsetMathHull.cpp @@ -599,6 +599,25 @@ ColorCode InsetMathHull::backgroundColor(PainterInfo const & pi) const } +void InsetMathHull::drawMarkers(PainterInfo & pi, int x, int y) const +{ + ColorCode pen_color = mouseHovered(pi.base.bv) || editing(pi.base.bv)? + Color_mathframe : Color_mathcorners; + // If the corners have the same color as the background, do not paint them. + if (lcolor.getX11Name(Color_mathbg) == lcolor.getX11Name(pen_color)) + return; + + Inset::drawMarkers(pi, x, y); + Dimension const dim = dimension(*pi.base.bv); + int const t = x + dim.width() - 1; + int const a = y - dim.ascent(); + pi.pain.line(x, a + 3, x, a, pen_color); + pi.pain.line(t, a + 3, t, a, pen_color); + pi.pain.line(x, a, x + 3, a, pen_color); + pi.pain.line(t - 3, a, t, a, pen_color); +} + + void InsetMathHull::drawBackground(PainterInfo & pi, int x, int y) const { Dimension const dim = dimension(*pi.base.bv); @@ -659,7 +678,7 @@ void InsetMathHull::draw(PainterInfo & pi, int x, int y) const } InsetMathGrid::draw(pi, xmath + 1, y); - drawMarkers2(pi, x, y); + drawMarkers(pi, x, y); if (numberedType()) { Changer dummy = pi.base.changeFontSet("mathrm"); diff --git a/src/mathed/InsetMathHull.h b/src/mathed/InsetMathHull.h index 183b851ba5..6f9f90873c 100644 --- a/src/mathed/InsetMathHull.h +++ b/src/mathed/InsetMathHull.h @@ -260,6 +260,8 @@ private: bool colChangeOK() const; /// are any of the equations numbered? bool haveNumbers() const; + /// draw four angular markers + virtual void drawMarkers(PainterInfo & pi, int x, int y) const; /// "none", "simple", "display", "eqnarray",... HullType type_; diff --git a/src/mathed/MathRow.cpp b/src/mathed/MathRow.cpp index 71e7a5234a..345962096f 100644 --- a/src/mathed/MathRow.cpp +++ b/src/mathed/MathRow.cpp @@ -18,6 +18,7 @@ #include "MathSupport.h" #include "BufferView.h" +#include "ColorSet.h" #include "CoordCache.h" #include "MetricsInfo.h" @@ -97,11 +98,6 @@ void drawMarkers(PainterInfo const & pi, MathRow::Element const & e, if (e.marker == InsetMath::NO_MARKER) return; - // The color - bool const highlight = e.inset->mouseHovered(pi.base.bv) - || e.inset->editing(pi.base.bv); - ColorCode const pen_color = highlight ? Color_mathframe : Color_mathcorners; - CoordCache const & coords = pi.base.bv->coordCache(); Dimension const dim = coords.getInsets().dim(e.inset); @@ -122,6 +118,14 @@ void drawMarkers(PainterInfo const & pi, MathRow::Element const & e, pi.pain.text(l, y + dim.des - namedim.des - 1, e.inset->name(), font); } + // Color for corners + bool const highlight = e.inset->mouseHovered(pi.base.bv) + || e.inset->editing(pi.base.bv); + ColorCode const pen_color = highlight ? Color_mathframe : Color_mathcorners; + // If the corners have the same color as the background, do not paint them. + if (lcolor.getX11Name(Color_mathbg) == lcolor.getX11Name(pen_color)) + return; + // Lower corners in all cases int const d = y + dim.descent(); pi.pain.line(l, d - 3, l, d, pen_color);