void MathMacro::metrics(MetricsInfo & mi, Dimension & dim) const { // set edit mode for which we will have calculated metrics. But only editing_[mi.base.bv] = editMode(mi.base.bv); // calculate new metrics according to display mode if (displayMode_ == DISPLAY_INIT || displayMode_ == DISPLAY_INTERACTIVE_INIT) { mathed_string_dim(mi.base.font, from_ascii("\\") + name(), dim); } else if (displayMode_ == DISPLAY_UNFOLDED) { cell(0).metrics(mi, dim); Dimension bsdim; mathed_string_dim(mi.base.font, from_ascii("\\"), bsdim); dim.wid += bsdim.width() + 1; dim.asc = max(bsdim.ascent(), dim.ascent()); dim.des = max(bsdim.descent(), dim.descent()); metricsMarkers(dim); } else if (lyxrc.macro_edit_style == LyXRC::MACRO_EDIT_LIST && editing_[mi.base.bv]) { // Macro will be edited in a old-style list mode here: LASSERT(macro_ != 0, /**/); Dimension fontDim; FontInfo labelFont = sane_font; math_font_max_dim(labelFont, fontDim.asc, fontDim.des); // get dimension of components of list view Dimension nameDim; nameDim.wid = mathed_string_width(mi.base.font, from_ascii("Macro \\") + name() + ": "); nameDim.asc = fontDim.asc; nameDim.des = fontDim.des; Dimension argDim; argDim.wid = mathed_string_width(labelFont, from_ascii("#9: ")); argDim.asc = fontDim.asc; argDim.des = fontDim.des; Dimension defDim; definition_.metrics(mi, defDim); // add them up dim.wid = nameDim.wid + defDim.wid; dim.asc = max(nameDim.asc, defDim.asc); dim.des = max(nameDim.des, defDim.des); for (idx_type i = 0; i < nargs(); ++i) { Dimension cdim; cell(i).metrics(mi, cdim); dim.des += max(argDim.height(), cdim.height()) + 1; dim.wid = max(dim.wid, argDim.wid + cdim.wid); } // make space for box and markers, 2 pixels dim.asc += 1; dim.des += 1; dim.wid += 2; metricsMarkers2(dim); } else {
void Inset::drawMarkers(PainterInfo & pi, int x, int y) const { ColorCode pen_color = mouseHovered(pi.base.bv) || editing(pi.base.bv)? Color_mathframe : Color_mathcorners; Dimension const dim = dimension(*pi.base.bv); int const t = x + dim.width() - 1; int const d = y + dim.descent(); pi.pain.line(x, d - 3, x, d, pen_color); pi.pain.line(t, d - 3, t, d, pen_color); pi.pain.line(x, d, x + 3, d, pen_color); pi.pain.line(t - 3, d, t, d, pen_color); }
void InsetMathSqrt::draw(PainterInfo & pi, int x, int y) const { cell(0).draw(pi, x + 10, y); Dimension const dim = dimension(*pi.base.bv); int const a = dim.ascent(); int const d = dim.descent(); int xp[3]; int yp[3]; pi.pain.line(x + dim.width(), y - a + 1, x + 8, y - a + 1, pi.base.font.color()); xp[0] = x + 8; yp[0] = y - a + 1; xp[1] = x + 5; yp[1] = y + d - 1; xp[2] = x; yp[2] = y + (d - a)/2; pi.pain.lines(xp, yp, 3, pi.base.font.color()); drawMarkers(pi, x, y); }