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