/// <summary> /// Key up /// </summary> /// <param name="sender">Sender</param> /// <param name="args">Arguments</param> private void keyPress(object sender, KeyPressEventArgs args) { if (keySymbol != null) { MathSymbol sym = keySymbol.GetSymbol(args); if (sym == null) { return; } sym = Find(sym); if (sym == null) { return; } if (newCursor is MathSymbol) { MathSymbol ds = newCursor as MathSymbol; newCursor = MathSymbolDrawable.InsertObject(ds, sym) as IInsertedObject; } else if (newCursor is MathFormulaDrawable) { MathFormulaDrawable mf = newCursor as MathFormulaDrawable; newCursor = mf.InsertObject(sym) as IInsertedObject; } //newCursor = newCursor.InsertObject(movedSymbol); movedSymbol = null; DrawCursor(); DrawFormulaOnComponent(); oldCursor = movedSymbol as IInsertedObject; control.Cursor = CURSOR_EDIT; } }
private void BeforePrepare() { Control control = panelFormula; performer = new FormulaEditor.FormulaEditorPerformer(panelFormula, null); Hashtable table = new Hashtable(); string[,] el = new string[, ] { { "=", "=" }, { "&", "AND" }, { "\u2216", "AND" }, { "\u2217", "OR" }, { "|", "OR" }, { "\u8835", "=>" }, { "l", "LIKE" }, { "p", "=>" }, { "¬", "NOT" }, { "(", "(" }, { ".", "." }, { ":", ":" }, { "?", "?" }, { "<", "<" }, { ">", ">" }, { "+", "+" }, { "-", "-" }, { "*", "*" }, { "=", "=" }, { "/", "/" }, { "﹪", "%" }, { "A", "atan2" }, { "'", "d/dt" } }; for (int i = 0; i < el.GetLength(0); i++) { table[el[i, 0]] = el[i, 1]; } MathFormulaDrawable formula = new MathFormulaDrawable(new MathFormula((byte)0, sizes), DrawableConverter.Object); Color[] cols = new Color[] { Color.FromArgb(216, 203, 187), Color.Black }; performer.SetColors(cols[0], cols[1]); Graphics g = Graphics.FromHwnd(control.Handle); SimpleSymbolDrawable.Prepare(sizes, g); BracketsSymbolDrawable.Prepare(sizes, g); AbsSymbolDrawable.Prepare(sizes, g); }
/// <summary> /// Calculates positions of child formulas /// </summary> public void CalculateChildPositions() { Point[] p = new Point[] { GetChildPosition(0), GetChildPosition(1) }; pDrawable.Font = PureDrawableSymbol.FontsBold[level]; MathFormulaDrawable[] f = { this[0] as MathFormulaDrawable, this[1] as MathFormulaDrawable }; Rectangle[] r = new Rectangle[] { f[0].FullRelativeRectangle, f[1].FullRelativeRectangle }; warc = (int)(h * (1 - Math.Cos(40.0 * Math.PI / 180.0))); MathFormula child = this[0]; int dx = 2 + warc; string str = s; if (s.Equals("(,)")) { str = ""; } int x = pDrawable.Position.X + dx + (int)PureDrawableSymbol.Graphics.MeasureString(str, pDrawable.Font).Width; for (int i = 0; i < 2; i++) { p[i].X = x; p[i].Y = pDrawable.Position.Y; MathFormulaDrawable dr = this[i] as MathFormulaDrawable; x += (int)PureDrawableSymbol.Graphics.MeasureString(" , ", pDrawable.Font).Width + dr.FullRelativeRectangle.Width; pDrawable.ChildPositions[i].X = p[i].X; pDrawable.ChildPositions[i].Y = p[i].Y; } }
/// <summary> /// Draws itself /// </summary> /// <param name="g">Graphics to draw</param> public void DrawSelf(Graphics g) { string str = s; if (s.Equals("(,)")) { str = ""; } int y = pDrawable.Position.Y - pDrawable.Font.Height / 2; g.DrawString(str, pDrawable.Font, PureDrawableSymbol.SymbolBrush, pDrawable.Position.X + (int)((PureDrawableSymbol.W_SHIFT / 2) * g.MeasureString(str, pDrawable.Font).Width), y); int x = pDrawable.Position.X + (int)g.MeasureString(str, pDrawable.Font).Width; warc = (int)((double)h * (1 - Math.Cos(40.0 * Math.PI / 180.0))); MathFormulaDrawable f0 = this[0] as MathFormulaDrawable; int wc = (int)g.MeasureString(" , ", pDrawable.Font).Width; g.DrawString(" , ", pDrawable.Font, PureDrawableSymbol.SymbolBrush, x + warc + f0.FullRelativeRectangle.Width, y); int ww = 0; for (int i = 0; i < Count; i++) { MathFormulaDrawable f = this[i] as MathFormulaDrawable; if (f != null) { ww += (int)f.FullRelativeRectangle.Width; } } g.DrawArc(PureDrawableSymbol.LinePen, x + 2, y - 2 * h, 4 * h, 4 * h, 140, 80); g.DrawArc(PureDrawableSymbol.LinePen, x + 2 + 2 * warc + ww + wc - 4 * h, y - 2 * h, 4 * h, 4 * h, -40, 80); }
/// <summary> /// Calculates positions of children /// </summary> public void CalculateChildPositions() { Rectangle r = pDrawable.FullRelativeRectangle; int x = pDrawable.Position.X; int y = pDrawable.Position.Y; if (true) { MathFormula child = this[0]; int dx = 0;//2 + warc; Point p = GetChildPosition(0); p.X = pDrawable.Position.X; p.Y = pDrawable.Position.Y; p.X += dx; pDrawable.ChildPositions[0].X = p.X; pDrawable.ChildPositions[0].Y = p.Y; if (Count == 2) { if (this[1] != null) { p = GetChildPosition(1); p.X = pDrawable.Position.X; p.Y = pDrawable.Position.Y; int dy = -updown; MathFormulaDrawable f0 = this[0] as MathFormulaDrawable; dx = 4 + /* 2 * warc +*/ f0.FullRelativeRectangle.Width; p.X += dx; p.Y += dy; pDrawable.ChildPositions[1].X = p.X; pDrawable.ChildPositions[1].Y = p.Y; } } } }
public override void SetToFormula(MathFormula formula) { sizes = formula.Sizes; level = formula.Level; pDrawable.SetToFormula(formula); pDrawable.Font = PureDrawableSymbol.FontsBold[level]; pDrawable.WidthInsert = (int)PureDrawableSymbol.Graphics.MeasureString("y", pDrawable.Font, 100).Width; if (!GetType().Equals(typeof(AbsSymbolDrawable))) { return; } MathFormula child1 = new MathFormulaDrawable(new MathFormula((byte)(level), sizes), DrawableConverter.Object); children.Add(child1); pDrawable.ChildPositions = new Point[] { new Point() }; if (sizes == null) { return; } if (level < (sizes.Length - 1)) { MathFormula child2 = new MathFormulaDrawable(new MathFormula((byte)(level + 1), sizes), DrawableConverter.Object); children.Add(child2); pDrawable.ChildPositions = new Point[] { new Point(), new Point() }; return; } }
private void AfrerPrepare(int bottom) { this.bottom = bottom; Control control = panelFormula; Rectangle r = new Rectangle(40, bottom + 3, control.Width - 45, control.Height - bottom - 6); performer.FormulaRectangle = r; Image back = new Bitmap(control.Width, control.Height); Graphics g = Graphics.FromImage(back); g.FillRectangle(new SolidBrush(Color.LightGray), 0, 0, back.Width, back.Height); g.DrawRectangle(new Pen(Color.Black), 0, 0, back.Width - 1, back.Height - 1); Font f = new Font("Serif", sizes[0], FontStyle.Bold | FontStyle.Italic); int delta = 15; Brush bBrush = new SolidBrush(Color.Black); g.DrawString("f = ", f, bBrush, 10, r.Y + r.Height / 2 + delta); g.Dispose(); performer.Prepare(back); MathFormulaDrawable formula = new MathFormulaDrawable(new MathFormula((byte)0, sizes), DrawableConverter.Object); performer.Formula = formula; performer.InitEventHandlers(); performer.DrawFormula(); }
public void CalculateFullRelativeRectangle() { if (GetType().Equals(typeof(BracketsSymbol)) | GetType().Equals(typeof(BracketsSymbolDrawable))) { return; } CalculateRelativeRectangle(); Rectangle rr = pDrawable.RelativeRectangle; int w = rr.Width; int up = rr.Y; int delta = 0; if (children != null) { if (this[0].Count != 0) { MathFormulaDrawable dr = this[0] as MathFormulaDrawable; Rectangle r = dr.FullRelativeRectangle; w += r.Width; delta = rr.Height / 2 - r.Height; up = rr.Y + delta; } } pDrawable.FullRelativeRectangleX = 0; pDrawable.FullRelativeRectangleY = up; pDrawable.FullRelativeRectangleWidth = w; pDrawable.FullRelativeRectangleHeight = rr.Height - delta; }
private void buttonCalc_Click(object sender, EventArgs e) { // try // { MathFormula f = new MathFormula(panel.Performer.Formula, UndrawableConverter.Object); // MathFormula f = MathFormula.FromString(panel.Performer.Formula.Sizes, fs); f = f.FullTransform(null); /*FormulaTree tree = new FormulaTree(f); * FormulaTree der = tree.Deriv(textBoxDerivType.Text); * der.SimplifyAll(); * derivFormula = der.GetFormula(0, FormulaEditorPanel.sizes);*/ ObjectFormulaTree tree = ObjectFormulaTree.CreateTree(f, ElementaryFunctionsCreator.Object); ObjectFormulaTree der = tree.Derivation(textBoxDerivType.Text); //der = ElementaryFormulaSimplification.Object.Simplify(der);//der.SimplifyAll(); MathFormula form = FormulaCreator.CreateFormula(der, (byte)0, MathSymbolFactory.Sizes); form.Simplify(); derivFormula = new MathFormulaDrawable(form, DrawableConverter.Object); derivFormula.Position = pointDeriv; derivFormula.CalculateFullRelativeRectangle(); derivFormula.CalculatePositions(); paintDeriv(); Refresh(); /* } * catch (System.Exception ex) * { * WindowsExtensions.ControlExtensions.ShowMessageBoxModal(this, ex.Message); * }*/ }
/// <summary> /// Constructor /// </summary> /// <param name="control">component the editor component</param> /// <param name="formula">formula the formula for edit</param> public FormulaEditorPerformer(Control control, MathFormulaDrawable formula) : base(new ControlWrapper(control), formula) { this.control = control; keyPressEventHandler = new KeyPressEventHandler(keyPress); keyUpEventHandler = new KeyEventHandler(keyUp); keySymbol = this; }
/// <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; }
public void Set(string formula, System.Drawing.Point point) { this.point.X = point.X; this.point.Y = point.Y; this.formula = new MathFormulaDrawable(MathFormula.FromString(MathSymbolFactory.Sizes, formula), DrawableConverter.Object); this.formula.Position = point; this.formula.CalculateFullRelativeRectangle(); this.formula.CalculatePositions(); }
/// <summary> /// Draws itself /// </summary> /// <param name="g">The graphics to draw</param> public void DrawSelf(Graphics g) { int x = pDrawable.Position.X; int y = pDrawable.Position.Y; MathFormulaDrawable f = this[0] as MathFormulaDrawable; Rectangle r = f.FullRelativeRectangle; // warc = (int)((double)h * (1 - Math.Cos(40.0 * Math.PI / 180.0))); g.DrawLine(PureDrawableSymbol.LinePen, x + 2, y - h, x + 2, y + h); g.DrawLine(PureDrawableSymbol.LinePen, x + 4 + r.Width, y - h, x + 4 + r.Width, y + h); }
/// <summary> /// Calculates relative rectangle without children /// </summary> public void CalculateRelativeRectangle() { if (children != null) { if (this[0] != null) { MathFormulaDrawable f = this[0] as MathFormulaDrawable; Rectangle r = f.FullRelativeRectangle; int a1 = Math.Abs(r.Y); int a2 = r.Height + r.Y; down = (a1 > a2) ? a1 : a2; updown = down; pDrawable.RelativeRectangleX = 0; pDrawable.RelativeRectangleY = -down; pDrawable.RelativeRectangleWidth = r.Width; pDrawable.RelativeRectangleHeight = 2 * down; } } }
/// <summary> /// Calculates relative rectangle with children /// </summary> public void CalculateFullRelativeRectangle() { MathSymbolDrawable.CalculateFullRelativeRectangle(this); CalculateRelativeRectangle(); Rectangle rr = pDrawable.RelativeRectangle; int w = rr.Width; int up = rr.Y; MathFormulaDrawable[] f = new MathFormulaDrawable[] { this[0] as MathFormulaDrawable, this[1] as MathFormulaDrawable, this[2] as MathFormulaDrawable }; Rectangle r1 = f[0].FullRelativeRectangle; Rectangle r2 = f[1].FullRelativeRectangle; Rectangle r3 = f[2].FullRelativeRectangle; up = (r1.Y < r2.Y) ? r1.Y : r2.Y; up = (r3.Y < up) ? up : r3.Y; if (rr.Y < up) { up = rr.Y; } int a1 = Math.Abs(r1.Y); int a2 = r1.Height + r1.Y; down = (a1 > a2) ? a1 : a2; if (rr.Y < up) { up = rr.Y; } int wc = (int)PureDrawableSymbol.Graphics.MeasureString(" , , ", PureDrawableSymbol.FontsBold[level]).Width; h = (int)((double)down / Math.Sin(40.0 * 3.1415926 / 180.0)); warc = (int)((double)h * (1 - Math.Cos(40.0 * 3.1415926 / 180.0))); int wpow = 0, hpow = 0; pDrawable.FullRelativeRectangleX = 0; pDrawable.FullRelativeRectangleY = -down - hpow; pDrawable.FullRelativeRectangleWidth = rr.Width + r1.Width + r2.Width + r3.Width + 6 * warc + 4 + wpow; pDrawable.FullRelativeRectangleHeight = 2 * down + hpow; }
/// <summary> /// Calculates relative rectangle wihout children /// </summary> public void CalculateRelativeRectangle() { string str = s; if (str.Equals("(,)")) { str = ""; } Font f = PureDrawableSymbol.FontsBold[level]; int h = (int)((1 + 2 * PureDrawableSymbol.H_SHIFT) * (f.Height)); int w = (int)PureDrawableSymbol.Graphics.MeasureString(str, f).Width; pDrawable.RelativeRectangleX = 0; pDrawable.RelativeRectangleY = -h / 2; pDrawable.RelativeRectangleWidth = w; pDrawable.RelativeRectangleHeight = h; int dd = 0; if (children != null) { for (int i = 0; i < Count; i++) { if (this[i] != null) { MathFormulaDrawable df = this[i] as MathFormulaDrawable; Rectangle r = df.FullRelativeRectangle; int a1 = Math.Abs(r.Y); int a2 = r.Height + r.Y; down = (a1 > a2) ? a1 : a2; if (dd < Math.Abs(down)) { dd = Math.Abs(down); } updown = down; } } } down = dd; updown = dd; }
/// <summary> /// Creates image from formula /// </summary> /// <param name="formula">Formula</param> /// <returns>Image</returns> public static Image CreateImage(string formula) { Image im = new Bitmap(10, 10); Graphics g = Graphics.FromImage(im); SimpleSymbolDrawable.Prepare(new int[] { 8, 6, 5, 4 }, g); MathFormulaDrawable f = new MathFormulaDrawable(MathFormula.FromString(new int[] { 8, 6, 5, 4 }, formula), DrawableConverter.Object); f.CalculateFullRelativeRectangle(); Rectangle r = f.FullRelativeRectangle; Point p = new Point(10, -r.Y); f.Position = p; f.CalculatePositions(); im = new Bitmap(r.Width + 20, r.Height); Brush brush = new SolidBrush(Color.White); g = Graphics.FromImage(im); g.FillRectangle(brush, 0, 0, im.Width, im.Height); f.Draw(g); SimpleSymbolDrawable.Prepare(MathSymbolFactory.Sizes, g); g.Dispose(); return(im); }
/// <summary> /// Preparation /// </summary> /// <param name="sx">Variable symbols</param> /// <param name="n">Level</param> /// <param name="sSubscript">Subscripted symbols</param> /// <param name="symbols">Text symbols</param> public void Prepare(string sx, int n, string[,] sSubscript, string[] symbols) { string[] all = symbols; Hashtable table = new Hashtable(); string[,] el = new string[, ] { { "=", "=" }, { "&", "AND" }, { "\u2216", "AND" }, { "\u2217", "OR" }, { "|", "OR" }, { "\u8835", "=>" }, { "l", "LIKE" }, { "p", "=>" }, { "¬", "NOT" }, { "(", "(" }, { ".", "." }, { ":", ":" }, { "?", "?" }, { "<", "<" }, { ">", ">" }, { "+", "+" }, { "-", "-" }, { "*", "*" }, { "/", "/" }, { "﹪", "%" }, { "=", "=" }, { "A", "atan2" }, { "'", "d/dt" } }; for (int i = 0; i < el.GetLength(0); i++) { table[el[i, 0]] = el[i, 1]; } // MathFormula.Resources = table; int[] sizes = MathSymbolFactory.Sizes; int sub = (sSubscript == null) ? 0 : sSubscript.GetLength(0); MathFormulaDrawable formula = new MathFormulaDrawable(new MathFormula((byte)0, sizes), DrawableConverter.Object); Control control = this; performer = new FormulaEditor.FormulaEditorPerformer(control, formula); Color[] cols = new Color[] { Color.FromArgb(216, 203, 187), Color.Black }; performer.SetColors(cols[0], cols[1]); Graphics g = Graphics.FromHwnd(control.Handle); SimpleSymbolDrawable.Prepare(sizes, g); BracketsSymbolDrawable.Prepare(sizes, g); AbsSymbolDrawable.Prepare(sizes, g); if (all != null) { foreach (string str in all) { foreach (char c in str) { performer.Add(new SimpleSymbolDrawable( new SimpleSymbol(c, 0x0, false, false))); } } } string ss = sx; for (int i = 0; i < sub; i++) { performer.Add(new SubscriptedSymbolDrawable(new SubscriptedSymbol(sSubscript[i, 0], sSubscript[i, 1]))); } for (int i = 0; i < ss.Length; i++) { performer.Add(new SimpleSymbolDrawable(new SimpleSymbol(ss[i]))); } string elem = "scletqabjkfgw'\u2211\u03B4\u0442"; for (int i = 0; i < elem.Length; i++) { performer.Add(new SimpleSymbolDrawable(new SimpleSymbol(elem[i], false, (byte)4))); } string integerSym = "ABCDEFGH"; performer.Add(new BinaryFunctionSymbolDrawable(new BinaryFunctionSymbol('A', "atan2"))); for (int i = 0; i < integerSym.Length; i++) { char c = integerSym[i]; performer.Add(new SimpleSymbolDrawable(new SimpleSymbol(c, (byte)4, false, ElementaryIntegerOperation.GetString(c)))); } string numbers = "x0123456789ABCDEF"; for (int i = 0; i < numbers.Length; i++) { performer.Add(new SimpleSymbolDrawable(new SimpleSymbol(numbers[i], false, (byte)5))); } string binary = ".+-*×=><\u2264\u2265\u2260?:&|^\u2266\u2267\u2216\u2217\u8835l\u2270"; //string[,] el = new string[,] {{"\u2216", "AND"}, {"\u2217", "OR"}}; //string binary = ".+-*=><?:&|^\u2217l"; for (int i = 0; i < binary.Length; i++) { performer.Add(new BinarySymbolDrawable(new BinarySymbol(binary[i]))); } string unary = "¬~"; for (int i = 0; i < unary.Length; i++) { performer.Add(new SimpleSymbolDrawable(new SimpleSymbol(unary[i], false, (byte)4))); } performer.Add(new BracketsSymbolDrawable(new BracketsSymbol())); performer.Add(new AbsSymbolDrawable(new AbsSymbol())); performer.Add(new RootSymbolDrawable(new RootSymbol())); performer.Add(new FractionSymbolDrawable(new FractionSymbol())); performer.Add(new BinarySymbolDrawable(MathSymbol.Bra as BinarySymbol)); performer.Add(new SimpleSymbolDrawable(MathSymbol.Ket as SimpleSymbol)); performer.Add(new SimpleSymbolDrawable(new SimpleSymbol('e'))); performer.Add(new SimpleSymbolDrawable(new SimpleSymbol('%', (byte)FormulaConstants.Variable, true, "\u03c0"))); for (int i = 0; i < n; i++) { performer.Add(new SeriesSymbolDrawable(new SeriesSymbol(i))); } int x = 10, y = 10; int bottom = 0; IDrawableSymbol symbol = null; int ns = 0; if (all != null) { foreach (string str in all) { foreach (char c in str) { symbol = performer[ns]; Point p = new Point(x, y); MathSymbolDrawable.SetComponentPosition(symbol, p); symbol.PureDrawable.RectForShow = new Rectangle(x, y, symbol.StandardWidth, (int)(1.5 * 20)); x += symbol.PureDrawable.RectForShow.Width; ++ns; } bottom = y + symbol.PureDrawable.RectForShow.Height; y = bottom; x = 10; } } if (sub != 0) { for (int i = ns; i < sub + ns; i++) { symbol = performer[i]; Point p = new Point(x, y); MathSymbolDrawable.SetComponentPosition(symbol, p); symbol.PureDrawable.RectForShow = new Rectangle(x, y, symbol.StandardWidth, (int)(1.5 * 20)); x += symbol.PureDrawable.RectForShow.Width; } bottom = y + symbol.PureDrawable.RectForShow.Height; y = bottom; x = 10; } for (int i = sub + ns; i < sub + ns + ss.Length; i++) { symbol = performer[i]; Point p = new Point(x, y); MathSymbolDrawable.SetComponentPosition(symbol, p); symbol.PureDrawable.RectForShow = new Rectangle(x, y, 30, (int)(1.5 * 20)); x += symbol.PureDrawable.RectForShow.Width; } bottom = y + symbol.PureDrawable.RectForShow.Height; y = bottom; x = 10; for (int i = ss.Length + ns + sub; i < ss.Length + elem.Length + 2 + sub + ns; i++) { symbol = performer[i]; Point p = new Point(x, y); MathSymbolDrawable.SetComponentPosition(symbol, p); symbol.PureDrawable.RectForShow = new Rectangle(x, y, symbol.StandardWidth + 10, (int)(1.5 * 20)); x += symbol.PureDrawable.RectForShow.Width; } bottom = y + symbol.PureDrawable.RectForShow.Height; y = bottom; x = 10; for (int i = sub + ns + ss.Length + elem.Length + 1; i < sub + ns + ss.Length + elem.Length + integerSym.Length + 1; i++) { symbol = performer[i]; Point p = new Point(x, y); MathSymbolDrawable.SetComponentPosition(symbol, p); symbol.PureDrawable.RectForShow = new Rectangle(x, y, symbol.StandardWidth + 10, (int)(1.5 * 20)); x += symbol.PureDrawable.RectForShow.Width; } bottom = y + symbol.PureDrawable.RectForShow.Height; y = bottom; x = 10; for (int i = sub + ns + ss.Length + elem.Length + integerSym.Length + 1; i < sub + ns + ss.Length + elem.Length + numbers.Length + integerSym.Length + 2; i++) { symbol = performer[i]; Point p = new Point(x, y); MathSymbolDrawable.SetComponentPosition(symbol, p); symbol.PureDrawable.RectForShow = new Rectangle(x, y, symbol.StandardWidth + 10, (int)(1.5 * 20)); x += symbol.PureDrawable.RectForShow.Width; } bottom = y + symbol.PureDrawable.RectForShow.Height; y = bottom; x = 10; for (int i = sub + ns + ss.Length + elem.Length + integerSym.Length + numbers.Length + 1; i < sub + ns + ss.Length + elem.Length + numbers.Length + integerSym.Length + binary.Length + unary.Length + 8 + n; i++) { symbol = performer[i]; Point p = new Point(x, y); MathSymbolDrawable.SetComponentPosition(symbol, p); symbol.PureDrawable.RectForShow = new Rectangle(x, y, symbol.StandardWidth + 10, (int)(1.5 * 20)); x += symbol.PureDrawable.RectForShow.Width; } bottom = y + symbol.PureDrawable.RectForShow.Height; Rectangle r = new Rectangle(80, bottom, 1100, control.Height - bottom - 20); performer.FormulaRectangle = r; Image back = new Bitmap(1200, r.Y + r.Height + 10); g = Graphics.FromImage(back); g.FillRectangle(new SolidBrush(Color.LightGray), 0, 0, back.Width, back.Height); g.DrawRectangle(new Pen(Color.Black), 0, 0, back.Width - 1, back.Height - 1); Font f = new Font("Serif", sizes[0], FontStyle.Bold | FontStyle.Italic); int delta = 15; Brush bBrush = new SolidBrush(Color.Black); g.DrawString("f = ", f, bBrush, 10, r.Y + r.Height / 2 + delta); g.Dispose(); performer.Prepare(back); formula = new MathFormulaDrawable(new MathFormula((byte)0, sizes), DrawableConverter.Object); performer.Formula = formula; performer.InitEventHandlers(); performer.DrawFormula(); }
/// <summary> /// The "on click" event handler /// </summary> /// <param name="sender">The sender</param> /// <param name="e">The event arguments</param> private void onMouseClicked(object sender, MouseEventArgs e) { translate(e); if (movedSymbol == null) { movedSymbol = newSymbol; if (movedSymbol != null) { if (movedSymbol is DateTimeSymbol) { DateTimeSymbol dts = movedSymbol as DateTimeSymbol; dts.DateTime = dateTime.DateTime; } IDrawableSymbol ds = movedSymbol as IDrawableSymbol; wImage = ds.PureDrawable.SymbolImage.Width; hImage = ds.PureDrawable.SymbolImage.Height; control.Cursor = CURSOR_MOVE; oldX = imagePoint.X; oldY = imagePoint.Y; DrawCursor(); if (newCursor != null) { DrawCursor(newCursor, true, true); } } if (newRemoveCursor != null) { MathSymbol s = (MathSymbol)newRemoveCursor; if (s.Contains(newCursor)) { newCursor = null; oldCursor = null; } s.Remove(); newRemoveCursor = null; oldRemoveCursor = null; DrawFormulaOnComponent(); } } else { if (newCursor == null) { movedSymbol = null; DrawCursor(); newCursor = null; oldCursor = null; control.Cursor = CURSOR_EDIT; } else { if (newCursor is MathSymbol) { MathSymbol ds = newCursor as MathSymbol; newCursor = MathSymbolDrawable.InsertObject(ds, movedSymbol) as IInsertedObject; } else if (newCursor is MathFormulaDrawable) { MathFormulaDrawable mf = newCursor as MathFormulaDrawable; newCursor = mf.InsertObject(movedSymbol) as IInsertedObject; } //newCursor = newCursor.InsertObject(movedSymbol); movedSymbol = null; DrawCursor(); DrawFormulaOnComponent(); oldCursor = movedSymbol as IInsertedObject; control.Cursor = CURSOR_EDIT; } } }