// this finds the object in which the point is lying in, uses the bounding box idea to basically calculate if it is in between the box // this could do with some tweaking but its big and scary // the general idea is to loop through every object and check if it lies in between the box, if not ignore // the concept is repeated for all the object types, but they all do the same thing public void findSelected(VectorPoint seletedPoint) { foreach (KeyValuePair <string, VectorObject> obj in objects) { if (obj.Value is VectorBox) { VectorBox box = obj.Value as VectorBox; if (box.position.x <= seletedPoint.x && box.position.x + box.size.x >= seletedPoint.x) { if (box.position.y <= seletedPoint.y && box.position.y + box.size.y >= seletedPoint.y) { outlinedObject = obj.Key; } } } else if (obj.Value is VectorLine) { VectorLine line = obj.Value as VectorLine; if (line.minX + line.position.x <= seletedPoint.x && line.maxX + line.position.x >= seletedPoint.x) { if (line.minY + line.position.y <= seletedPoint.y && line.maxY + line.position.y >= seletedPoint.y) { outlinedObject = obj.Key; } } } else if (obj.Value is VectorEllipse) { VectorEllipse ellipse = obj.Value as VectorEllipse; if (ellipse.position.x - ellipse.radii.x <= seletedPoint.x && ellipse.position.x + ellipse.radii.x >= seletedPoint.x) { if (ellipse.position.y - ellipse.radii.y <= seletedPoint.y && ellipse.position.y + ellipse.radii.y >= seletedPoint.y) { outlinedObject = obj.Key; } } } else if (obj.Value is VectorText) { VectorText text = obj.Value as VectorText; if (text.position.x <= seletedPoint.x && text.position.x + text.width >= seletedPoint.x) { if (text.position.y - text.fontSize <= seletedPoint.y && text.position.y >= seletedPoint.y) { outlinedObject = obj.Key; } } } } }
private void drawEllipse(SKCanvas canvas, VectorEllipse ellipse, bool outline) { // make the paint style SKPaint paint = new SKPaint(); paint.StrokeWidth = ellipse.strokeThickness; paint.Color = SKColor.Parse(ellipse.colour); paint.IsStroke = ellipse.fillin; // draw an oval as an ellpise canvas.DrawOval(convertXCoord(ellipse.position.x), convertYCoord(ellipse.position.y), ellipse.radii.x * scale, ellipse.radii.y * scale, paint); // if applicable, calculate the bounding box and draw it if (outline) { // creates a box around the oval, does some calculations to get the position and size because theyre different for the different shapes float x = convertXCoord(ellipse.position.x) - (ellipse.radii.x * scale) - outlinePadding; float y = convertYCoord(ellipse.position.y) - (ellipse.radii.y * scale) - outlinePadding; float w = (ellipse.radii.x * scale + outlinePadding) * 2; float h = (ellipse.radii.y * scale + outlinePadding) * 2; canvas.DrawRect(x, y, w, h, outlinePaint); } }
public static Screen Unconvert(string path) { // creates an xml doc and loads it XmlDocument doc = new XmlDocument(); Screen screen = new Screen(); doc.Load(path); if (doc.HasChildNodes) // ensures we have a screen element { // gets the stuff from the screen node XmlElement xml = (XmlElement)doc.ChildNodes[0]; screen.current_colour = xml.GetAttributeNode("colour").InnerXml; screen.translateX = float.Parse(xml.GetAttributeNode("translateX").InnerXml); screen.translateY = float.Parse(xml.GetAttributeNode("translateY").InnerXml); screen.outlinedObject = xml.GetAttributeNode("outlined").InnerXml; screen.stroke_thickness = float.Parse(xml.GetAttributeNode("stroke").InnerXml); screen.font_size = float.Parse(xml.GetAttributeNode("fontSize").InnerXml); screen.current_fill_in = bool.Parse(xml.GetAttributeNode("currentFillIn").InnerXml); if (xml.HasChildNodes) { // loops through all the objects and creates objects then adds them to the screen class, mostly self explanatory and repetitive code for (int i = 0; i < xml.ChildNodes.Count; i++) { XmlElement child = (XmlElement)xml.ChildNodes[i]; string[] xandy = child.GetAttributeNode("position").InnerXml.Split(','); float x = float.Parse(xandy[0]); float y = float.Parse(xandy[1]); VectorPoint position = new VectorPoint(x, y); string colour = child.GetAttributeNode("colour").InnerXml; string uid = child.GetAttributeNode("uid").InnerXml; switch (child.Name) { case "line": VectorLine line = new VectorLine(position); line.minX = float.Parse(child.GetAttributeNode("minX").InnerXml); line.minY = float.Parse(child.GetAttributeNode("minY").InnerXml); line.maxX = float.Parse(child.GetAttributeNode("maxX").InnerXml); line.maxY = float.Parse(child.GetAttributeNode("maxY").InnerXml); line.colour = colour; line.strokeThickness = float.Parse(child.GetAttributeNode("stroke").InnerXml); for (int u = 0; u < child.ChildNodes.Count; u++) { XmlElement point = (XmlElement)child.ChildNodes[u]; xandy = point.GetAttributeNode("position").InnerXml.Split(','); x = float.Parse(xandy[0]); y = float.Parse(xandy[1]); line.addPoint(new VectorPoint(x, y)); } screen.addObject(uid, line); break; case "box": xandy = child.GetAttributeNode("size").InnerXml.Split(','); x = float.Parse(xandy[0]); y = float.Parse(xandy[1]); VectorPoint size = new VectorPoint(x, y); bool fillin = bool.Parse(child.GetAttributeNode("fillin").InnerXml); float stroke = float.Parse(child.GetAttributeNode("stroke").InnerXml); VectorBox box = new VectorBox(position, size, fillin); box.strokeThickness = stroke; screen.addObject(uid, box); break; case "ellipse": xandy = child.GetAttributeNode("radii").InnerXml.Split(','); x = float.Parse(xandy[0]); y = float.Parse(xandy[1]); VectorPoint radii = new VectorPoint(x, y); fillin = bool.Parse(child.GetAttributeNode("fillin").InnerXml); stroke = float.Parse(child.GetAttributeNode("stroke").InnerXml); VectorEllipse ellipse = new VectorEllipse(position, radii, fillin); ellipse.strokeThickness = stroke; screen.addObject(uid, ellipse); break; case "text": string text = child.GetAttributeNode("text").InnerXml; float fontsize = float.Parse(child.GetAttributeNode("fontSize").InnerXml); VectorText obj = new VectorText(position, text); obj.colour = colour; obj.fontSize = fontsize; screen.addObject(uid, obj); break; } } } } return(screen); }