loadXML()
import compose.remember.*; import compose.commands.*; import compose.grips.*; Remember remember; Commands commands; GripDispatcher dispatch; MemorableGrip c1, c2, c3; void setup() { remember = new Remember(this); dispatch = new GripDispatcher(this); c1 = new MemorableGrip(30, 30, 40); c2 = new MemorableGrip(50, 50, 40); c3 = new MemorableGrip(70, 70, 40); commands = new Commands(this); commands.add("undo", remember, CONTROL, 'z' ); commands.add("redo", remember, CONTROL, SHIFT, 'z' ); } void draw() { background(100); dispatch.update(); dispatch.draw(); } // These are the only two methods we need to write ... // in order to enable save, load, undo and redo. XMLElement getXML() { XMLElement root = new XMLElement(); root.setName("Composition"); root.addChild(c1.getNode()); root.addChild(c2.getNode()); root.addChild(c3.getNode()); return root; } void loadXML(XMLElement element) { dispatch.clear(); c1 = new MemorableGrip(element.getChild(0)); c2 = new MemorableGrip(element.getChild(1)); c3 = new MemorableGrip(element.getChild(2)); }// storeUndoStep() appears twice in this class ... FIND THEM ALL! class MemorableGrip extends Grip { float x, y, diameter; // MemorableGrip has two constructors ... // One for loading data via XML // (Back at the other tab, we use this in loadXML()) MemorableGrip(XMLElement node) { this(node.getFloatAttribute("x"), node.getFloatAttribute("y"), node.getFloatAttribute("d")); } // And one the old fashioned way. // (Note that the XML constructor actually just calls this one) MemorableGrip(float x, float y, float diameter) { this.x = x; this.y = y; this.diameter = diameter; this.selectable = true; } // (Back at the other tab, we use this in getXML()) XMLElement getNode() { XMLElement node = new XMLElement(); node.setName("CircleGrip"); node.setAttribute("x", x + ""); node.setAttribute("y", y + ""); node.setAttribute("d", diameter + ""); return node; } boolean isHovering() { return dist(mouseX, mouseY, x, y) < diameter / 2; } void draw() { if (isTheActive()) { fill(255, 0, 0); } else if (isTheHover()) { fill(255, 200, 200); } else { fill(255); } ellipse(x, y, diameter, diameter); } void mouseDragged() { if (isTheActive()) { x += mouseX - pmouseX; y += mouseY - pmouseY; } } void mouseFirstDragged() { if (isTheActive()) { remember.storeUndoStep(); // Undo step sighting!!~ } } int lastWheelTime; void mouseWheeled(int steps) { if (isTheActive()) { // We only want to store undo steps after you've // taken a break from the mouse wheel for a bit. if (millis() - lastWheelTime > 300) { remember.storeUndoStep(); // Undo step sighting!!~ } diameter += steps; lastWheelTime = millis(); } } }- Description
Implement this method in order to interpret an XML node that represents a composition. You must implement this method to enable open() and redo(). This method performs the inverse operation of getXML().
- Syntax
void loadXML(XMLElement node) { statements }- Parameters
- an XMLElement that represents a composition
- Returns
- None
- Usage
- Web & Applications
- Related
No Comments
You must be logged in to post a comment.