OLD | NEW |
| (Empty) |
1 /* libs/graphics/animator/SkDisplayRandom.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 "SkDisplayRandom.h" | |
19 #include "SkInterpolator.h" | |
20 | |
21 enum SkDisplayRandom_Properties { | |
22 SK_PROPERTY(random), | |
23 SK_PROPERTY(seed) | |
24 }; | |
25 | |
26 #if SK_USE_CONDENSED_INFO == 0 | |
27 | |
28 const SkMemberInfo SkDisplayRandom::fInfo[] = { | |
29 SK_MEMBER(blend, Float), | |
30 SK_MEMBER(max, Float), | |
31 SK_MEMBER(min, Float), | |
32 SK_MEMBER_DYNAMIC_PROPERTY(random, Float), | |
33 SK_MEMBER_PROPERTY(seed, Int) | |
34 }; | |
35 | |
36 #endif | |
37 | |
38 DEFINE_GET_MEMBER(SkDisplayRandom); | |
39 | |
40 SkDisplayRandom::SkDisplayRandom() : blend(0), min(0), max(SK_Scalar1) { | |
41 } | |
42 | |
43 #ifdef SK_DUMP_ENABLED | |
44 void SkDisplayRandom::dump(SkAnimateMaker* maker) { | |
45 dumpBase(maker); | |
46 #ifdef SK_CAN_USE_FLOAT | |
47 SkDebugf("min=\"%g\" ", SkScalarToFloat(min)); | |
48 SkDebugf("max=\"%g\" ", SkScalarToFloat(max)); | |
49 SkDebugf("blend=\"%g\" ", SkScalarToFloat(blend)); | |
50 #else | |
51 SkDebugf("min=\"%x\" ", min); | |
52 SkDebugf("max=\"%x\" ", max); | |
53 SkDebugf("blend=\"%x\" ", blend); | |
54 #endif | |
55 SkDebugf("/>\n"); | |
56 } | |
57 #endif | |
58 | |
59 bool SkDisplayRandom::getProperty(int index, SkScriptValue* value) const { | |
60 switch(index) { | |
61 case SK_PROPERTY(random): { | |
62 SkScalar random = fRandom.nextUScalar1(); | |
63 SkScalar relativeT = SkUnitCubicInterp(random, SK_Scalar1 - blend, 0
, 0, SK_Scalar1 - blend); | |
64 value->fOperand.fScalar = min + SkScalarMul(max - min, relativeT); | |
65 value->fType = SkType_Float; | |
66 return true; | |
67 } | |
68 default: | |
69 SkASSERT(0); | |
70 } | |
71 return false; | |
72 } | |
73 | |
74 bool SkDisplayRandom::setProperty(int index, SkScriptValue& value) { | |
75 SkASSERT(index == SK_PROPERTY(seed)); | |
76 SkASSERT(value.fType == SkType_Int); | |
77 fRandom.setSeed(value.fOperand.fS32); | |
78 return true; | |
79 } | |
80 | |
OLD | NEW |