/// <summary> /// draws the box for the subircuit on the screen /// will only be called on the first execute of this command, since after this point it will /// store a stroke, so that it works in conjunction with the stored stroke in moveresizecmd /// </summary> private Stroke addSubCircuitBox(Point addpoint) { //Make a box at the point with these specifications int width = 100; int height = 70; System.Windows.Input.StylusPointCollection line = new System.Windows.Input.StylusPointCollection(); //Need to create a lot of points so that the sub circuit will select correctly for (double m = 0; m <= 1; m += 0.01) { double midX = addpoint.X + m * (width); double midY = addpoint.Y; line.Add(new System.Windows.Input.StylusPoint(midX, midY)); } for (double m = 0; m <= 1; m += 0.01) { double midX = addpoint.X + width; double midY = addpoint.Y + m * (height); line.Add(new System.Windows.Input.StylusPoint(midX, midY)); } for (double m = 0; m <= 1; m += 0.01) { double midX = (addpoint.X + width) + m * (-width); double midY = addpoint.Y + height; line.Add(new System.Windows.Input.StylusPoint(midX, midY)); } for (double m = 0; m <= 1; m += 0.01) { double midX = addpoint.X; double midY = (addpoint.Y + height) + m * (-height); line.Add(new System.Windows.Input.StylusPoint(midX, midY)); } Stroke newStroke = new Stroke(line); sketchPanel.InkSketch.AddStroke(newStroke); return(newStroke); }
/// <summary> /// Helper that transforms and scales in one go /// </summary> internal StylusPointCollection Reformat(StylusPointDescription subsetToReformatTo, GeneralTransform transform) { if (!subsetToReformatTo.IsSubsetOf(this.Description)) { throw new ArgumentException(SR.Get(SRID.InvalidStylusPointDescriptionSubset), "subsetToReformatTo"); } StylusPointDescription subsetToReformatToWithCurrentMetrics = StylusPointDescription.GetCommonDescription(subsetToReformatTo, this.Description); //preserve metrics from this spd if (StylusPointDescription.AreCompatible(this.Description, subsetToReformatToWithCurrentMetrics) && (transform is Transform) && ((Transform)transform).IsIdentity) { //subsetToReformatTo might have different x, y, p metrics return(this.Clone(transform, subsetToReformatToWithCurrentMetrics)); } // // we really need to reformat this... // StylusPointCollection newCollection = new StylusPointCollection(subsetToReformatToWithCurrentMetrics, this.Count); int additionalDataCount = subsetToReformatToWithCurrentMetrics.GetExpectedAdditionalDataCount(); ReadOnlyCollection <StylusPointPropertyInfo> properties = subsetToReformatToWithCurrentMetrics.GetStylusPointProperties(); bool isIdentity = (transform is Transform) ? ((Transform)transform).IsIdentity : false; for (int i = 0; i < this.Count; i++) { StylusPoint stylusPoint = this[i]; double xCoord = stylusPoint.X; double yCoord = stylusPoint.Y; float pressure = stylusPoint.GetUntruncatedPressureFactor(); if (!isIdentity) { Point p = new Point(xCoord, yCoord); transform.TryTransform(p, out p); xCoord = p.X; yCoord = p.Y; } int[] newData = null; if (additionalDataCount > 0) { //don't init, we'll do that below newData = new int[additionalDataCount]; } StylusPoint newStylusPoint = new StylusPoint(xCoord, yCoord, pressure, subsetToReformatToWithCurrentMetrics, newData, false, false); //start at 3, skipping x, y, pressure for (int x = StylusPointDescription.RequiredCountOfProperties /*3*/; x < properties.Count; x++) { int value = stylusPoint.GetPropertyValue(properties[x]); newStylusPoint.SetPropertyValue(properties[x], value, false /*copy on write*/); } //bypass validation ((List <StylusPoint>)newCollection.Items).Add(newStylusPoint); } return(newCollection); }
public static StrokeCollection XMLtoSrokes(XElement xml) { var xmlElem = xml; XNamespace xmlns = xmlElem.GetDefaultNamespace(); StrokeCollection objStrokes = new StrokeCollection(); double _width=7; double _height=7; byte _colorA=255; byte _outerColorA=255; byte _colorB=0; byte _colorG=0; byte _colorR=0; byte _outerColorB=0; byte _outerColorG=0; byte _outerColorR=0; //Query the XAML to extract the Strokes var strokes = from s in xmlElem.Descendants(xmlns+ "Stroke") select s; foreach (XElement strokeNodeElement in strokes) { //query the stroke to extract the drawingattributes var da = from d in strokeNodeElement.Descendants(xmlns + "DrawingAttributes") select d; foreach (XElement daElement in da) { //Grab Brush Sizes _width=Convert.ToDouble(daElement.Attribute("Width").Value); _height = Convert.ToDouble(daElement.Attribute("Height").Value); //Grab Brush Colors var colors = from c in da.Descendants("Color") select c; foreach (XElement colorElement in colors) { _colorA = Convert.ToByte(colorElement.Attribute("A").Value); _colorR = Convert.ToByte(colorElement.Attribute("R").Value); _colorG = Convert.ToByte(colorElement.Attribute("G").Value); _colorB = Convert.ToByte(colorElement.Attribute("B").Value); } //Grab Outline Brush Colors var outlineColors = from c in da.Descendants("OutlineColor") select c; foreach (XElement colorElement in outlineColors) { _outerColorA = Convert.ToByte(colorElement.Attribute("A").Value); _outerColorR = Convert.ToByte(colorElement.Attribute("R").Value); _outerColorG = Convert.ToByte(colorElement.Attribute("G").Value); _outerColorB = Convert.ToByte(colorElement.Attribute("B").Value); } } //query the stroke to extract its StylusPoints var points = from p in strokeNodeElement.Descendants(xmlns + "StylusPoint") select p; //create Stylus points collection from point element values StylusPointCollection pointData = new System.Windows.Input.StylusPointCollection(); foreach (XElement pointElement in points) { double Xpoint = Convert.ToDouble(pointElement.Attribute("X").Value); double Ypoint = Convert.ToDouble(pointElement.Attribute("Y").Value); pointData.Add(new StylusPoint(Xpoint, Ypoint)); } //create a new Stroke from the StylusPointCollection System.Windows.Ink.Stroke newstroke = new System.Windows.Ink.Stroke(pointData); newstroke.DrawingAttributes.Width = _width; newstroke.DrawingAttributes.Height=_height; newstroke.DrawingAttributes.Color = Color.FromArgb(_colorA,_colorR,_colorG,_colorB); newstroke.DrawingAttributes.OutlineColor = Color.FromArgb(_outerColorA, _outerColorR, _outerColorG, _outerColorB); //add the new stroke to the StrokeCollection objStrokes.Add(newstroke); } return objStrokes; }