blob: dd636da4d7ad5b69536fb652c7dcc5b34f8635a9 [file] [log] [blame]
reed@android.com8a1c16f2008-12-17 15:59:43 +00001/* libs/graphics/animator/SkAnimateSet.cpp
2**
3** Copyright 2006, The Android Open Source Project
4**
5** Licensed under the Apache License, Version 2.0 (the "License");
6** you may not use this file except in compliance with the License.
7** You may obtain a copy of the License at
8**
9** http://www.apache.org/licenses/LICENSE-2.0
10**
11** Unless required by applicable law or agreed to in writing, software
12** distributed under the License is distributed on an "AS IS" BASIS,
13** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14** See the License for the specific language governing permissions and
15** limitations under the License.
16*/
17
18#include "SkAnimateSet.h"
19#include "SkAnimateMaker.h"
20#include "SkAnimateProperties.h"
21#include "SkParse.h"
22
23#if SK_USE_CONDENSED_INFO == 0
24
25const SkMemberInfo SkSet::fInfo[] = {
26 SK_MEMBER(begin, MSec),
27 SK_MEMBER(dur, MSec),
28 SK_MEMBER_PROPERTY(dynamic, Boolean),
29 SK_MEMBER(field, String),
30// SK_MEMBER(formula, DynamicString),
31 SK_MEMBER(lval, DynamicString),
32// SK_MEMBER_PROPERTY(reset, Boolean),
33 SK_MEMBER_PROPERTY(step, Int),
34 SK_MEMBER(target, DynamicString),
35 SK_MEMBER(to, DynamicString)
36};
37
38#endif
39
40DEFINE_GET_MEMBER(SkSet);
41
42SkSet::SkSet() {
43 dur = 1;
44}
45
46#ifdef SK_DUMP_ENABLED
47void SkSet::dump(SkAnimateMaker* maker) {
48 INHERITED::dump(maker);
49 if (dur != 1) {
50#ifdef SK_CAN_USE_FLOAT
51 SkDebugf("dur=\"%g\" ", SkScalarToFloat(SkScalarDiv(dur,1000)));
52#else
53 SkDebugf("dur=\"%x\" ", SkScalarDiv(dur,1000));
54#endif
55 }
56 //don't want double />\n's
57 SkDebugf("/>\n");
58
59}
60#endif
61
62void SkSet::refresh(SkAnimateMaker& maker) {
63 fFieldInfo->setValue(maker, &fValues, 0, fFieldInfo->fCount, NULL,
64 fFieldInfo->getType(), to);
65}
66
67void SkSet::onEndElement(SkAnimateMaker& maker) {
68 if (resolveCommon(maker) == false)
69 return;
70 if (fFieldInfo == NULL) {
71 maker.setErrorCode(SkDisplayXMLParserError::kFieldNotInTarget);
72 return;
73 }
74 fReset = dur != 1;
75 SkDisplayTypes outType = fFieldInfo->getType();
76 int comps = outType == SkType_String || outType == SkType_DynamicString ? 1 :
77 fFieldInfo->getSize((const SkDisplayable*) fTarget) / sizeof(int);
78 if (fValues.getType() == SkType_Unknown) {
79 fValues.setType(outType);
80 fValues.setCount(comps);
81 if (outType == SkType_String || outType == SkType_DynamicString)
82 fValues[0].fString = SkNEW(SkString);
83 else
84 memset(fValues.begin(), 0, fValues.count() * sizeof(fValues.begin()[0]));
85 } else {
86 SkASSERT(fValues.getType() == outType);
87 if (fFieldInfo->fType == SkType_Array)
88 comps = fValues.count();
89 else
90 SkASSERT(fValues.count() == comps);
91 }
92 if (formula.size() > 0) {
93 comps = 1;
94 outType = SkType_MSec;
95 }
96 fFieldInfo->setValue(maker, &fValues, fFieldOffset, comps, this, outType, formula.size() > 0 ? formula : to);
97 fComponents = fValues.count();
98}