]> git.lyx.org Git - features.git/commitdiff
simplify rectText and buttonText add separate metric methods for these
authorLars Gullik Bjønnes <larsbj@gullik.org>
Tue, 24 Jul 2001 09:12:20 +0000 (09:12 +0000)
committerLars Gullik Bjønnes <larsbj@gullik.org>
Tue, 24 Jul 2001 09:12:20 +0000 (09:12 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2314 a592a061-630c-0410-9148-cb99ea01b6c8

po/POTFILES.in
src/ChangeLog
src/PainterBase.C
src/PainterBase.h
src/font.C
src/font.h
src/insets/ChangeLog
src/insets/insetbutton.C
src/insets/insetcollapsable.C
src/text.C

index 1542be87a71873953ddf9b40b18f12fc4fe98c87..2edfc3058c6e888f88fd7fe88f7a1fda2b78bd4c 100644 (file)
@@ -9,7 +9,6 @@ src/converter.C
 src/CutAndPaste.C
 src/debug.C
 src/exporter.C
-src/ext_l10n.h
 src/figure_form.C
 src/figureForm.C
 src/FontLoader.C
index 9a0aa0fb80f3f48a87cd8bdc5e539a04084a2eea..12b51084e686286205e0a6247d92f53602fee2f2 100644 (file)
@@ -1,3 +1,13 @@
+2001-07-24  Lars Gullik Bjønnes  <larsbj@birdstep.com>
+
+       * text.C (getVisibleRow): adjust
+
+       * font.[Ch] (rectText): new method, metrics
+       (buttonText): new method, metrics
+
+       * PainterBase.[hC]: make rectText and buttonText always draw and take
+       fewer paramteres.
+
 2001-07-22  Jean-Marc Lasgouttes  <lasgouttes@lyx.org>
 
        * ToolbarDefaults.C (read): 
index cd29b781aa34e688e0de2f13baf0d49204d3cad7..f29ef37a2b411218712f69fd0bf4e39e4786158e 100644 (file)
@@ -90,6 +90,7 @@ PainterBase & PainterBase::buttonFrame(int x, int y, int w, int h)
 }
 
 
+#if 0
 PainterBase & PainterBase::rectText(int x, int baseline, 
                                    string const & str, 
                                    LyXFont const & font,
@@ -97,17 +98,24 @@ PainterBase & PainterBase::rectText(int x, int baseline,
                                    LColor::color frame, bool draw,
                                    int & width, int & ascent, int & descent)
 {
+#if 0
        static int const d = 2;
        width = lyxfont::width(str, font) + d * 2 + 2;
        ascent = lyxfont::maxAscent(font) + d;
        descent = lyxfont::maxDescent(font) + d;
-
+#else
+       lyxfont::rectText(str, font, width, axcent, descent);
+#endif
        if (!draw) return *this;
 
        rectangle(x, baseline - ascent, width, ascent + descent, frame);
        fillRectangle(x + 1, baseline - ascent + 1, width - 1, 
                      ascent + descent - 1, back);
+#if 0
        text(x + d, baseline, str, font);
+#else
+       text(x + 2, baseline, str, font);
+#endif
        return *this;
 }
 
@@ -117,13 +125,50 @@ PainterBase & PainterBase::buttonText(int x, int baseline,
                                      LyXFont const & font, bool draw,
                                      int & width, int & ascent, int & descent)
 {
+#if 0
        width = lyxfont::width(str, font) + 8;
        ascent = lyxfont::maxAscent(font) + 3;
        descent = lyxfont::maxDescent(font) + 3;
-
+#else
+       lyxfont::buttonText(str, font, width, ascent, descent);
+#endif
        if (!draw) return *this;
 
        button(x, baseline - ascent, width, descent + ascent);
        text(x + 4, baseline, str, font);
        return *this;
 }
+#else
+PainterBase & PainterBase::rectText(int x, int baseline, 
+                                   string const & str, 
+                                   LyXFont const & font,
+                                   LColor::color back,
+                                   LColor::color frame)
+{
+       int width;
+       int ascent;
+       int descent;
+       
+       lyxfont::rectText(str, font, width, ascent, descent);
+       rectangle(x, baseline - ascent, width, ascent + descent, frame);
+       fillRectangle(x + 1, baseline - ascent + 1, width - 1, 
+                     ascent + descent - 1, back);
+       text(x + 2, baseline, str, font);
+       return *this;
+}
+
+
+PainterBase & PainterBase::buttonText(int x, int baseline,
+                                     string const & str, 
+                                     LyXFont const & font)
+{
+       int width;
+       int ascent;
+       int descent;
+       
+       lyxfont::buttonText(str, font, width, ascent, descent);
+       button(x, baseline - ascent, width, descent + ascent);
+       text(x + 4, baseline, str, font);
+       return *this;
+}
+#endif
index df650cd78bae1b6cd68fbbc632f5407a65d1cf10..71a39f987f400533ace30993521019903ebdc510 100644 (file)
@@ -161,7 +161,8 @@ public:
 
        /// Draw a char at position x, y (y is the baseline)
        virtual PainterBase & text(int x, int y, char c, LyXFont const & f)=0;
-       
+
+#if 0
        /** Draws a string and encloses it inside a rectangle. Returns
            the size of the rectangle. If draw is false, we only calculate
            the size. */
@@ -182,6 +183,22 @@ public:
                             int & width = PainterBase::dummy1,
                             int & ascent = PainterBase::dummy2, 
                             int & descent = PainterBase::dummy3);
+#else
+       /** Draws a string and encloses it inside a rectangle. Returns
+           the size of the rectangle. If draw is false, we only calculate
+           the size. */
+       PainterBase & rectText(int x, int baseline, 
+                          string const & string, 
+                          LyXFont const & font,
+                          LColor::color back,
+                              LColor::color frame);
+
+       /** Draw a string and encloses it inside a button frame. Returns
+           the size of the frame. If draw is false, we only calculate
+           the size. */
+       PainterBase & buttonText(int x, int baseline, string const & s,
+                                LyXFont const & font);
+#endif
 protected:
        ///
        WorkArea & owner;
index 65e2b427665992486acba1ed41f683d6b117e32e..210d10bd60e61a0feccdbd16703736a1a6803b79 100644 (file)
@@ -186,7 +186,7 @@ int lyxfont::width(XChar2b const * s, int n, LyXFont const & f)
                                result += ::XTextWidth16(getXFontstruct(smallfont), &c, 1);
                        } else {
                                result += ::XTextWidth16(getXFontstruct(f), &s[i], 1);
-                       }
+               }
                }
                return result;
        }
@@ -209,5 +209,26 @@ void lyxfont::XSetFont(Display * display, GC gc, LyXFont const & f)
        ::XSetFont(display, gc, getFontID(f));
 }
 
+
+void lyxfont::rectText(string const & str, LyXFont const & font,
+             int & width, int & ascent, int & descent)
+{
+       static int const d = 2;
+       width = lyxfont::width(str, font) + d * 2 + 2;
+       ascent = lyxfont::maxAscent(font) + d;
+       descent = lyxfont::maxDescent(font) + d;
+}
+
+
+
+void lyxfont::buttonText(string const & str, LyXFont const & font,
+               int & width, int & ascent, int & descent)
+{
+       width = lyxfont::width(str, font) + 8;
+       ascent = lyxfont::maxAscent(font) + 3;
+       descent = lyxfont::maxDescent(font) + 3;
+}
+
+
 //} // end of namespace font
 //} // end of namespace lyx
index 7e286e48f1502fc2756926a1e69cfe6850fdd507..51d50e93d6d692c1a35701135ec8d0d95e8cdd04 100644 (file)
@@ -78,6 +78,15 @@ struct lyxfont {
        ///
        static
        void XSetFont(Display * display, GC gc, LyXFont const & f);
+       // A couple of more high-level metrics
+       ///
+       static
+       void rectText(string const & str, LyXFont const & font,
+                     int & width, int & ascent, int & descent);
+       ///
+       static
+       void buttonText(string const & str, LyXFont const & font,
+                       int & width, int & ascent, int & descent);
 };
 
 //} // end of namespace font
index 451e07d328aba30e65435ebc156ff89ffde4ea70..3ea458ea18aaec6353886f7279d42adc6291bd5b 100644 (file)
@@ -1,3 +1,9 @@
+2001-07-24  Lars Gullik Bjønnes  <larsbj@birdstep.com>
+
+       * insetcollapsable.C: adjust
+
+       * insetbutton.C: adjust
+
 2001-07-23  Juergen Vigna  <jug@sad.it>
 
        * insetcollapsable.h: removed widthCollapsed variable, LyXFont
index 8b0d3d6d5f26fc095397fc9be16c0e5843e893d3..617b2bf8200dba10272bf095ed2692842173e3bb 100644 (file)
@@ -20,6 +20,7 @@
 #include "Painter.h"
 #include "support/LAssert.h"
 #include "lyxfont.h"
+#include "font.h"
 
 using std::ostream;
 using std::endl;
@@ -36,7 +37,8 @@ int InsetButton::ascent(BufferView * bv, LyXFont const &) const
        int ascent;
        int descent;
         string const s = getScreenLabel();
-       
+
+#if 0
         if (editable()) {
                bv->painter().buttonText(0, 0, s, font,
                                         false, width, ascent, descent);
@@ -45,6 +47,13 @@ int InsetButton::ascent(BufferView * bv, LyXFont const &) const
                                       LColor::commandbg, LColor::commandframe,
                                       false, width, ascent, descent);
        }
+#else
+        if (editable()) {
+               lyxfont::buttonText(s, font, width, ascent, descent);
+       } else {
+               lyxfont::rectText(s, font, width, ascent, descent);
+       }
+#endif
        return ascent;
 }
 
@@ -60,7 +69,8 @@ int InsetButton::descent(BufferView * bv, LyXFont const &) const
        int ascent;
        int descent;
         string const s = getScreenLabel();
-       
+
+#if 0
         if (editable()) {
                bv->painter().buttonText(0, 0, s, font,
                                         false, width, ascent, descent);
@@ -69,6 +79,13 @@ int InsetButton::descent(BufferView * bv, LyXFont const &) const
                                   LColor::commandbg, LColor::commandframe,
                                   false, width, ascent, descent);
        }
+#else
+        if (editable()) {
+               lyxfont::buttonText(s, font, width, ascent, descent);
+       } else {
+               lyxfont::rectText(s, font, width, ascent, descent);
+       }
+#endif
        return descent;
 }
 
@@ -84,7 +101,8 @@ int InsetButton::width(BufferView * bv, LyXFont const &) const
        int ascent;
        int descent;
         string const s = getScreenLabel();
-       
+
+#if 0
         if (editable()) {
                bv->painter().buttonText(0, 0, s, font,
                                         false, width, ascent, descent);
@@ -93,6 +111,13 @@ int InsetButton::width(BufferView * bv, LyXFont const &) const
                                       LColor::commandbg, LColor::commandframe,
                                       false, width, ascent, descent);
        }
+#else
+        if (editable()) {
+               lyxfont::buttonText(s, font, width, ascent, descent);
+       } else {
+               lyxfont::rectText(s, font, width, ascent, descent);
+       }
+#endif
        return width + 4;
 }
 
@@ -107,9 +132,10 @@ void InsetButton::draw(BufferView * bv, LyXFont const &,
        LyXFont font(LyXFont::ALL_SANE);
        font.setColor(LColor::command).decSize();
 
-       int width;
        string const s = getScreenLabel();
 
+#if 0
+       int width;
        if (editable()) {
                pain.buttonText(int(x) + 2, baseline, s, font, true, width);
        } else {
@@ -117,6 +143,18 @@ void InsetButton::draw(BufferView * bv, LyXFont const &,
                              LColor::commandbg, LColor::commandframe,
                              true, width);
        }
+#else
+       if (editable()) {
+               pain.buttonText(int(x) + 2, baseline, s, font);
+       } else {
+               pain.rectText(int(x) + 2, baseline, s, font,
+                             LColor::commandbg, LColor::commandframe);
+       }
+#endif
 
+#if 0
        x += width + 4;
+#else
+       x += width(bv, font);
+#endif
 }
index 596a8cb39f502457ccae00c119d9338801ef8d96..a5149e020f5cb6246ba846741ced5ea9e25df94a 100644 (file)
@@ -24,6 +24,7 @@
 #include "support/lstrings.h"
 #include "debug.h"
 #include "lyxtext.h"
+#include "font.h"
 
 class LyXText;
 
@@ -90,35 +91,50 @@ void InsetCollapsable::read(Buffer const * buf, LyXLex & lex)
 }
 
 
-int InsetCollapsable::ascent_collapsed(Painter & pain) const
+//int InsetCollapsable::ascent_collapsed(Painter & pain) const
+int InsetCollapsable::ascent_collapsed(Painter & /*pain*/) const
 {
        int width = 0;
        int ascent = 0;
        int descent = 0;
+#if 0
        pain.buttonText(0, 0, draw_label, labelfont, false, 
                        width, ascent, descent);
+#else
+       lyxfont::buttonText(draw_label, labelfont, width, ascent, descent);
+#endif
        return ascent;
 }
 
 
-int InsetCollapsable::descent_collapsed(Painter & pain) const
+//int InsetCollapsable::descent_collapsed(Painter & pain) const
+int InsetCollapsable::descent_collapsed(Painter & /*pain*/) const
 {
        int width = 0;
        int ascent = 0;
        int descent = 0;
+#if 0
        pain.buttonText(0, 0, draw_label, labelfont, false, 
                        width, ascent, descent);
+#else
+       lyxfont::buttonText(draw_label, labelfont, width, ascent, descent);
+#endif
        return descent;
 }
 
 
-int InsetCollapsable::width_collapsed(Painter & pain) const
+//int InsetCollapsable::width_collapsed(Painter & pain) const
+int InsetCollapsable::width_collapsed(Painter & /*pain*/) const
 {
        int width;
        int ascent;
        int descent;
+#if 0
        pain.buttonText(TEXT_TO_INSET_OFFSET, 0, draw_label, labelfont, false,
                        width, ascent, descent);
+#else
+       lyxfont::buttonText(draw_label, labelfont, width, ascent, descent);
+#endif
        return width + (2*TEXT_TO_INSET_OFFSET);
 }
 
@@ -155,10 +171,19 @@ int InsetCollapsable::width(BufferView * bv, LyXFont const & font) const
 
 void InsetCollapsable::draw_collapsed(Painter & pain, int baseline, float & x) const
 {
+#if 0
        int width = 0;
        pain.buttonText(int(x) + TEXT_TO_INSET_OFFSET,
                        baseline, draw_label, labelfont, true, width);
+#else
+       pain.buttonText(int(x) + TEXT_TO_INSET_OFFSET,
+                       baseline, draw_label, labelfont);
+#endif
+#if 0
        x += width + TEXT_TO_INSET_OFFSET;
+#else
+       x += width_collapsed(pain) + TEXT_TO_INSET_OFFSET;
+#endif
 }
 
 
index 01349da75ca65ec2f6c54a2c97f44d8db960c684..8d499450130ce4290454865a3885718f0a4855a1 100644 (file)
@@ -37,6 +37,7 @@
 #include "language.h"
 #include "ParagraphParameters.h"
 #include "undo_funcs.h"
+#include "font.h"
 
 using std::max;
 using std::min;
@@ -3152,12 +3153,18 @@ void LyXText::getVisibleRow(BufferView * bview, int y_offset, int x_offset,
                                  y_offset + y_top + 2 * defaultHeight(),
                                  LColor::pagebreak, 
                                  Painter::line_onoffdash)
+#if 0
                                .rectText(0,
                                          0,
                                          _("Page Break (top)"),
                                          pb_font,
                                          LColor::background,
                                          LColor::background, false, w, a, d);
+#else
+                       ;
+                       lyxfont::rectText(_("Page Break (top)"), pb_font,
+                                         w, a, d);
+#endif
                        pain.rectText((ww - w)/2,
                                      y_offset + y_top + 2 * defaultHeight() + d,
                                      _("Page Break (top)"),
@@ -3343,11 +3350,17 @@ void LyXText::getVisibleRow(BufferView * bview, int y_offset, int x_offset,
                                .line(0, y_place, ww, y_place,
                                      LColor::pagebreak,
                                      Painter::line_onoffdash)
+#if 0
                                .rectText(0, 0,
                                          _("Page Break (bottom)"),
                                          pb_font,
                                          LColor::background,
                                          LColor::background, false, w, a, d);
+#else
+                       ;
+                       lyxfont::rectText(_("Page Break (bottom)"), pb_font,
+                                         w, a, d);
+#endif
                        pain.rectText((ww - w) / 2, y_place + d,
                                      _("Page Break (bottom)"),
                                      pb_font,