public override void onSubjectChanged(ISubject subject) { if (subject is Container) { Container shapes = (subject as Container); for (ContainerIterator it = shapes.Begin(); it != shapes.End(); ++it) { if (it.getNode().key.intersectWith(path) && !observers.Contains(it.getNode().key) && it.getNode().key != this) { addObserver(it.getNode().key); } else { if (!it.getNode().key.intersectWith(path) && observers.Contains(it.getNode().key)) { observers.Remove(it.getNode().key); } } } return; } if (subject is StickyRectangle) { stickyFlag = true; offset((subject as StickyRectangle).deltaX, (subject as StickyRectangle).deltaY); stickyFlag = false; } }
public override void fillPath() { for (ContainerIterator it = shapes.Begin(); it != shapes.End(); ++it) { it.getNode().key.fillPath(); } }
private void unmarkAll() { for (ContainerIterator it = container.Begin(); it != container.End(); ++it) { it.getNode().key.setMarked(false); } }
public override void draw(Graphics graphics, SolidBrush brush) { for (ContainerIterator it = shapes.Begin(); it != shapes.End(); ++it) { it.getNode().key.setMarked(this.marked); it.getNode().key.draw(graphics, brush); } }
public override void updateBoarders(RectangleF boarders) { this.boarders = boarders; for (ContainerIterator it = shapes.Begin(); it != shapes.End(); ++it) { it.getNode().key.updateBoarders(boarders); } }
public Container split() { for (ContainerIterator it = shapes.Begin(); it != shapes.End(); ++it) { it.getNode().key.setGroupFlag(false); } return(shapes); }
private void Form1_Paint(object sender, PaintEventArgs e) { graphics.Clear(Color.White); for (ContainerIterator it = container.Begin(); it != container.End(); ++it) { it.getNode().key.draw(graphics, brush); } canvas.Image = bitmap; }
public override void scale(int delta) { for (ContainerIterator it = shapes.Begin(); it != shapes.End(); ++it) { it.getNode().key.scale(delta); } lastCommand = "scale"; relocate(); }
public override void offset(int deltaX, int deltaY) { for (ContainerIterator it = shapes.Begin(); it != shapes.End(); ++it) { it.getNode().key.offset(deltaX, deltaY); } lastCommand = "offset"; relocate(); }
public override bool intersectWith(GraphicsPath _path) { for (ContainerIterator it = shapes.Begin(); it != shapes.End(); ++it) { if (it.getNode().key.intersectWith(_path)) { return(true); } } return(false); }
public override bool isPointed(int x, int y) { for (ContainerIterator it = shapes.Begin(); it != shapes.End(); ++it) { if (it.getNode().key.isPointed(x, y)) { return(true); } } return(false); }
public override void save(StreamWriter writer) { writer.WriteLine(code); writer.WriteLine("maxCount: " + maxCount.ToString()); writer.WriteLine("count: " + count.ToString()); writer.WriteLine("relocateFlag: " + groupFlag.ToString()); for (ContainerIterator it = shapes.Begin(); it != shapes.End(); ++it) { it.getNode().key.save(writer); } writer.WriteLine(); }
public ContainerIterator Begin() { if (head != null) { ContainerIterator beginIterator = new ContainerIterator(head); return(beginIterator); } else { ContainerIterator beginIterator = new ContainerIterator(endNode); return(beginIterator); } }
public override bool checkBoarders() { for (ContainerIterator it = shapes.Begin(); it != shapes.End(); ++it) { if (!it.getNode().key.checkBoarders()) { path = it.getNode().key.getPath(); return(false); } } return(true); }
public ContainerIterator Last() { if (back != null) { ContainerIterator beginIterator = new ContainerIterator(back); return(beginIterator); } else { ContainerIterator beginIterator = new ContainerIterator(endNode); return(beginIterator); } }
public override void setMarked(bool value) { marked = value; for (ContainerIterator it = shapes.Begin(); it != shapes.End(); ++it) { it.getNode().key.setMarked(value); } if (!groupFlag) { notifyEveryone(); } }
public void onSubjectChanged(ISubject subject) { if (subject is Container) { this.Nodes.Clear(); for (ContainerIterator it = (subject as Container).Begin(); it != (subject as Container).End(); ++it) { TreeNode newNode = new TreeNode(); processNode(newNode, it.getNode().key); this.Nodes.Add(newNode); } return; } }
protected void processNode(TreeNode node, Shape shape) { node.Text = shape.getID().ToString() + " x: " + shape.getX().ToString() + " y: " + shape.getY().ToString() + " lastCommand: " + shape.getLastCommand(); if (shape.getMarked() == true) { node.ForeColor = Color.Red; node.Checked = true; } else { node.ForeColor = Color.Black; } if (shape is CGroup) { Container subset = (shape as CGroup).getShapes(); for (ContainerIterator it = subset.Begin(); it != subset.End(); ++it) { TreeNode newNode = new TreeNode(); processNode(newNode, it.getNode().key); node.Nodes.Add(newNode); } } }
private void contextMenu_ItemClicked(object sender, ToolStripItemClickedEventArgs e) { if (e.ClickedItem.Text == "Группировка") { CGroup group = new CGroup(100, boarders); bool IsThereSomething = false; ContainerIterator it = container.Begin(); while (it != container.End()) { if (it.getNode().key.getMarked() == true && !(it.getNode().key is StickyRectangle)) { IsThereSomething = true; group.addShape(it.getNode().key); container.Remove(it.getNode().key); if (container.Count() != 0) { it = container.Begin(); } else { it = container.End(); } } else { it++; } } if (IsThereSomething) { container.Push_back(group); } return; } if (e.ClickedItem.Text == "Разгруппировать") { Container extractedShapes = new Container(); for (ContainerIterator it = container.Begin(); it != container.End(); ++it) { if (it.getNode().key.getMarked() == true && (it.getNode().key is CGroup)) { Container shapes = ((CGroup)it.getNode().key).split(); for (ContainerIterator it2 = shapes.Begin(); it2 != shapes.End(); ++it2) { extractedShapes.Push_back(it2.getNode().key); } container.Remove(it.getNode().key); } } for (ContainerIterator it = extractedShapes.Begin(); it != extractedShapes.End(); ++it) { container.Push_back(it.getNode().key); } return; } if (e.ClickedItem.Text == "Сохранить") { container.saveShapes(pathToTheFileOfShapes); using (StreamWriter writer = new StreamWriter(pathToTheFileOfFormsParams, false, System.Text.Encoding.Default)) { this.save(writer); } return; } if (e.ClickedItem.Text == "Загрузить") { using (StreamReader reader = new StreamReader(pathToTheFileOfFormsParams, System.Text.Encoding.Default)) { this.load(reader); } ShapeFactory factory = new MyShapeFactory(); treeView.removeObserver(container); container = new Container(); container.addObserver(treeView); treeView.addObserver(container); container.loadShapes(pathToTheFileOfShapes, factory); this.Invalidate(); } }
private void canvas_MouseClick(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { ContainerIterator it = container.Last(); while (it != container.End()) { Shape current = it.getNode().key; if (current.isPointed(e.X, e.Y)) { if (!isControlPressed) { bool tmp = (current.getMarked() == true ? false : true); unmarkAll(); current.setMarked(tmp); } else { current.setMarked((current.getMarked() ? false : true)); } this.Invalidate(); return; } if (it == container.Begin()) { break; } --it; } unmarkAll(); Shape newShape = null; switch (lastShapeButton.Text) { case "Круг": { newShape = new CCircle(e.X, e.Y, boarders); break; } case "Прямоугольник": { newShape = new CRectangle(e.X, e.Y, boarders); break; } case "Квадрат": { newShape = new CSquare(e.X, e.Y, boarders); break; } case "Треугольник": { newShape = new CTriangle(e.X, e.Y, boarders); break; } case "Липкая фигура": { newShape = new StickyRectangle(e.X, e.Y, boarders); break; } } container.Push_back(newShape); this.Invalidate(); } }
public ContainerIterator End() { ContainerIterator endIterator = new ContainerIterator(endNode); return(endIterator); }
private void Form1_KeyDown(object sender, KeyEventArgs e) { if (e.Control) { isControlPressed = true; } if (e.KeyCode == Keys.Delete) { for (ContainerIterator it = container.Begin(); it != container.End(); ++it) { if ((it.getNode().key.getMarked())) { container.Remove(it.getNode().key); } } } if (e.KeyCode == Keys.L || e.KeyCode == Keys.K) { for (ContainerIterator it = container.Begin(); it != container.End(); ++it) { if (it.getNode().key.getMarked() == true) { if (e.KeyCode == Keys.L) { it.getNode().key.scale(1); } else { it.getNode().key.scale(-1); } } } } if (e.KeyCode == Keys.A || e.KeyCode == Keys.D || e.KeyCode == Keys.S || e.KeyCode == Keys.W) { switch (e.KeyCode) { case Keys.A: deltaX = -10; break; case Keys.D: deltaX = 10; break; case Keys.W: deltaY = -10; break; case Keys.S: deltaY = 10; break; } for (ContainerIterator it = container.Begin(); it != container.End(); ++it) { if (it.getNode().key.getMarked() == true) { it.getNode().key.offset(deltaX, deltaY); } } } else { deltaX = deltaY = 0; } this.Invalidate(); }