1 /*
2 * Copyright 2006 The Android Open Source Project
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #include "SkXMLAnimatorWriter.h"
9 #include "SkAnimator.h"
10 #include "SkAnimateMaker.h"
11 #include "SkDisplayXMLParser.h"
12
SkXMLAnimatorWriter(SkAnimator * animator)13 SkXMLAnimatorWriter::SkXMLAnimatorWriter(SkAnimator* animator) : fAnimator(animator)
14 {
15 fParser = new SkDisplayXMLParser(*fAnimator->fMaker);
16 }
17
~SkXMLAnimatorWriter()18 SkXMLAnimatorWriter::~SkXMLAnimatorWriter() {
19 delete fParser;
20 }
21
onAddAttributeLen(const char name[],const char value[],size_t length)22 void SkXMLAnimatorWriter::onAddAttributeLen(const char name[], const char value[], size_t length)
23 {
24 fParser->onAddAttributeLen(name, value, length);
25 }
26
onAddText(const char text[],size_t length)27 void SkXMLAnimatorWriter::onAddText(const char text[], size_t length) {
28 SkDebugf("not implemented: SkXMLAnimatorWriter::onAddText()\n");
29 }
30
onEndElement()31 void SkXMLAnimatorWriter::onEndElement()
32 {
33 Elem* elem = getEnd();
34 fParser->onEndElement(elem->fName.c_str());
35 doEnd(elem);
36 }
37
onStartElementLen(const char name[],size_t length)38 void SkXMLAnimatorWriter::onStartElementLen(const char name[], size_t length)
39 {
40 doStart(name, length);
41 fParser->onStartElementLen(name, length);
42 }
43
writeHeader()44 void SkXMLAnimatorWriter::writeHeader()
45 {
46 }
47
48 #ifdef SK_DEBUG
49 #include "SkCanvas.h"
50 #include "SkPaint.h"
51
UnitTest(SkCanvas * canvas)52 void SkXMLAnimatorWriter::UnitTest(SkCanvas* canvas)
53 {
54 SkAnimator s;
55 SkXMLAnimatorWriter w(&s);
56 w.startElement("screenplay");
57 w.startElement("animateField");
58 w.addAttribute("field", "x1");
59 w.addAttribute("id", "to100");
60 w.addAttribute("from", "0");
61 w.addAttribute("to", "100");
62 w.addAttribute("dur", "1");
63 w.endElement();
64 w.startElement("event");
65 w.addAttribute("kind", "onLoad");
66 w.startElement("line");
67 w.addAttribute("id", "line");
68 w.addAttribute("x1", "-1");
69 w.addAttribute("y1", "20");
70 w.addAttribute("x2", "150");
71 w.addAttribute("y2", "40");
72 w.endElement();
73 w.startElement("apply");
74 w.addAttribute("animator", "to100");
75 w.addAttribute("scope", "line");
76 w.endElement();
77 w.endElement();
78 w.endElement();
79 SkPaint paint;
80 canvas->drawColor(SK_ColorWHITE);
81 s.draw(canvas, &paint, 0);
82 }
83
84 #endif
85