Home | History | Annotate | Download | only in animator
      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 "SkDisplayRandom.h"
     11 #include "SkInterpolator.h"
     12 
     13 enum SkDisplayRandom_Properties {
     14     SK_PROPERTY(random),
     15     SK_PROPERTY(seed)
     16 };
     17 
     18 #if SK_USE_CONDENSED_INFO == 0
     19 
     20 const SkMemberInfo SkDisplayRandom::fInfo[] = {
     21     SK_MEMBER(blend, Float),
     22     SK_MEMBER(max, Float),
     23     SK_MEMBER(min, Float),
     24     SK_MEMBER_DYNAMIC_PROPERTY(random, Float),
     25     SK_MEMBER_PROPERTY(seed, Int)
     26 };
     27 
     28 #endif
     29 
     30 DEFINE_GET_MEMBER(SkDisplayRandom);
     31 
     32 SkDisplayRandom::SkDisplayRandom() : blend(0), min(0), max(SK_Scalar1) {
     33 }
     34 
     35 #ifdef SK_DUMP_ENABLED
     36 void SkDisplayRandom::dump(SkAnimateMaker* maker) {
     37     dumpBase(maker);
     38     SkDebugf("min=\"%g\" ", SkScalarToFloat(min));
     39     SkDebugf("max=\"%g\" ", SkScalarToFloat(max));
     40     SkDebugf("blend=\"%g\" ", SkScalarToFloat(blend));
     41     SkDebugf("/>\n");
     42 }
     43 #endif
     44 
     45 bool SkDisplayRandom::getProperty(int index, SkScriptValue* value) const {
     46     switch(index) {
     47         case SK_PROPERTY(random): {
     48             SkScalar random = fRandom.nextUScalar1();
     49             SkScalar relativeT = SkUnitCubicInterp(random, SK_Scalar1 - blend, 0, 0, SK_Scalar1 - blend);
     50             value->fOperand.fScalar = min + SkScalarMul(max - min, relativeT);
     51             value->fType = SkType_Float;
     52             return true;
     53         }
     54         default:
     55             SkASSERT(0);
     56     }
     57     return false;
     58 }
     59 
     60 bool SkDisplayRandom::setProperty(int index, SkScriptValue& value) {
     61     SkASSERT(index == SK_PROPERTY(seed));
     62     SkASSERT(value.fType == SkType_Int);
     63     fRandom.setSeed(value.fOperand.fS32);
     64     return true;
     65 }
     66