/// <summary> /// Calculates relative rectangle with its children /// </summary> public static void CalculateFullRelativeRectangle(IDrawableSymbol symbol) { SimpleSymbolDrawable.CalculateFullRelativeRectangle(symbol); //SimpleSymbolDrawable.C symbol.CalculateRelativeRectangle(); if (symbol is RootSymbol | symbol is FractionSymbol | symbol is BinaryFunctionSymbol) { return; } if (!(symbol is BracketsSymbolDrawable)) { return; } BracketsSymbolDrawable sym = symbol as BracketsSymbolDrawable; Rectangle rr = symbol.PureDrawable.RelativeRectangle; int w = rr.Width; int up = rr.Y; MathSymbol ms = symbol as MathSymbol; MathFormulaDrawable df = ms[0] as MathFormulaDrawable; Rectangle r1 = df.FullRelativeRectangle; Rectangle r2 = new Rectangle(); if (ms.Children != null) { if (ms.Count > 1) { if (ms[1] != null) { if (!ms[1].IsEmpty) { MathFormulaDrawable dr = ms[1] as MathFormulaDrawable; r2 = dr.FullRelativeRectangle; } } } } sym.h = (int)((double)sym.down / Math.Sin(40.0 * 3.1415926 / 180.0)); sym.warc = (int)((double)sym.h * (1 - Math.Cos(40.0 * 3.1415926 / 180.0))); int wpow = 0, hpow = 0; if (sym.Count > 1) { sym.h = (int)((double)sym.down / Math.Sin(40.0 * 3.1415926 / 180.0)); sym.warc = (int)((double)sym.h * (1 - Math.Cos(40.0 * 3.1415926 / 180.0))); if (ms.Count > 1) { wpow = r2.Width; hpow = -r2.Y; } } PureDrawableSymbol pDrawable = symbol.PureDrawable; pDrawable.FullRelativeRectangleX = 0; pDrawable.FullRelativeRectangleY = -sym.down - hpow; pDrawable.FullRelativeRectangleWidth = r1.Width + 2 * sym.warc + 4 + wpow; pDrawable.FullRelativeRectangleHeight = 2 * sym.down + sym.hpow; }
/// <summary> /// Calculates its and its children positions /// </summary> public static void CalculatePositions(IDrawableSymbol symbol) { SimpleSymbolDrawable.CalculatePositions(symbol); PureDrawableSymbol pDrawable = symbol.PureDrawable; pDrawable.InsertedRectX = pDrawable.Rectangle.X; pDrawable.InsertedRectY = pDrawable.Rectangle.Y; pDrawable.InsertedRectHeight = pDrawable.Rectangle.Height; pDrawable.InsertedRectWidth = pDrawable.WidthInsert; pDrawable.InsertedRectX = pDrawable.InsertedRect.X - pDrawable.WidthInsert / 2; }
/// <summary> /// Sets location on toolbar /// </summary> /// <param name="x">the x position</param> /// <param name="y">the y position</param> /*public void SetLocationOnTable(int x, int y) * { * pDrawable.RectForShow.Location = new Point(x, y); * }*/ public void CalculatePositions() { SimpleSymbolDrawable.CalculatePositions(this); IDrawableSymbol ds = this; PureDrawableSymbol pDrawable = ds.PureDrawable; pDrawable.InsertedRectX = pDrawable.Rectangle.X; pDrawable.InsertedRectY = pDrawable.Rectangle.Y; pDrawable.InsertedRectHeight = pDrawable.Rectangle.Height; pDrawable.InsertedRectWidth = pDrawable.WidthInsert; pDrawable.InsertedRectX = pDrawable.InsertedRect.X - pDrawable.WidthInsert / 2; }
/// <summary> /// Draws itself on component /// </summary> /// <param name="g">The graphics to draw</param> /// <param name="brush">The drawing brush</param> /// <param name="pen">The drawing pen</param> public static void DrawOnComponent(IDrawableSymbol sym, Graphics g, Brush brush, Pen pen) { MathSymbol ms = sym as MathSymbol; char ch = ms.Symbol; if ((ch != '\u2216') & (ch != '\u2217') & (ch != '\u8835') & (ch != '\u2295') & (ch != '\u2297') | MathFormula.Resources.ContainsKey(ms.Symbol + "")) { SimpleSymbolDrawable.DrawOnComponent(sym, g, brush, pen); return; } PureDrawableSymbol pDrawable = sym.PureDrawable; int shift = 8; string ss = ms.String; if (ss == null) { ss = "" + ch; } if (ss.Length == 0) { ss += ch; } int w = (int)g.MeasureString(ss, BracketsSymbolDrawable.FontB).Width; int h = pDrawable.RectForShow.Height; int s = (w < h) ? w : h; s = (int)(0.6 * (float)s); int x = pDrawable.RectForShow.X + w / 2; int y = pDrawable.RectForShow.Y + h / 2; if (ch == '\u2216') { g.DrawLine(PureDrawableSymbol.WidePen, pDrawable.RectForShow.X + shift, pDrawable.RectForShow.Y + pDrawable.RectForShow.Height - shift, pDrawable.RectForShow.X + pDrawable.RectForShow.Width / 2, pDrawable.RectForShow.Y + shift); g.DrawLine(PureDrawableSymbol.WidePen, pDrawable.RectForShow.X + pDrawable.RectForShow.Width / 2, pDrawable.RectForShow.Y + shift, pDrawable.RectForShow.X + pDrawable.RectForShow.Width - shift, pDrawable.RectForShow.Y + pDrawable.RectForShow.Height - shift); } else if (ch == '\u2217') { g.DrawLine(PureDrawableSymbol.WidePen, pDrawable.RectForShow.X + shift, pDrawable.RectForShow.Y + shift, pDrawable.RectForShow.X + pDrawable.RectForShow.Width / 2, pDrawable.RectForShow.Y + pDrawable.RectForShow.Height - shift); g.DrawLine(PureDrawableSymbol.WidePen, pDrawable.RectForShow.X + pDrawable.RectForShow.Width / 2, pDrawable.RectForShow.Y + pDrawable.RectForShow.Height - shift, pDrawable.RectForShow.X + pDrawable.RectForShow.Width - shift, pDrawable.RectForShow.Y + shift); } else if (ch == '\u8835') { g.DrawLine(PureDrawableSymbol.WidePen, pDrawable.RectForShow.X + shift, pDrawable.RectForShow.Y + shift, pDrawable.RectForShow.X + pDrawable.RectForShow.Width / 2, pDrawable.RectForShow.Y + pDrawable.RectForShow.Height - shift); g.DrawLine(PureDrawableSymbol.WidePen, pDrawable.RectForShow.X + pDrawable.RectForShow.Width / 2, pDrawable.RectForShow.Y + pDrawable.RectForShow.Height - shift, pDrawable.RectForShow.X + pDrawable.RectForShow.Width - shift, pDrawable.RectForShow.Y + shift); } else if (ch == '\u2295') { DrawCircledPlus(g, PureDrawableSymbol.LinePen, x, y, s); } else if (ch == '\u2297') { DrawCircledProduct(g, PureDrawableSymbol.LinePen, x, y, s); } }