michael@0: michael@0: /* michael@0: * Copyright 2006 The Android Open Source Project michael@0: * michael@0: * Use of this source code is governed by a BSD-style license that can be michael@0: * found in the LICENSE file. michael@0: */ michael@0: michael@0: michael@0: #include "SkDisplayRandom.h" michael@0: #include "SkInterpolator.h" michael@0: michael@0: enum SkDisplayRandom_Properties { michael@0: SK_PROPERTY(random), michael@0: SK_PROPERTY(seed) michael@0: }; michael@0: michael@0: #if SK_USE_CONDENSED_INFO == 0 michael@0: michael@0: const SkMemberInfo SkDisplayRandom::fInfo[] = { michael@0: SK_MEMBER(blend, Float), michael@0: SK_MEMBER(max, Float), michael@0: SK_MEMBER(min, Float), michael@0: SK_MEMBER_DYNAMIC_PROPERTY(random, Float), michael@0: SK_MEMBER_PROPERTY(seed, Int) michael@0: }; michael@0: michael@0: #endif michael@0: michael@0: DEFINE_GET_MEMBER(SkDisplayRandom); michael@0: michael@0: SkDisplayRandom::SkDisplayRandom() : blend(0), min(0), max(SK_Scalar1) { michael@0: } michael@0: michael@0: #ifdef SK_DUMP_ENABLED michael@0: void SkDisplayRandom::dump(SkAnimateMaker* maker) { michael@0: dumpBase(maker); michael@0: SkDebugf("min=\"%g\" ", SkScalarToFloat(min)); michael@0: SkDebugf("max=\"%g\" ", SkScalarToFloat(max)); michael@0: SkDebugf("blend=\"%g\" ", SkScalarToFloat(blend)); michael@0: SkDebugf("/>\n"); michael@0: } michael@0: #endif michael@0: michael@0: bool SkDisplayRandom::getProperty(int index, SkScriptValue* value) const { michael@0: switch(index) { michael@0: case SK_PROPERTY(random): { michael@0: SkScalar random = fRandom.nextUScalar1(); michael@0: SkScalar relativeT = SkUnitCubicInterp(random, SK_Scalar1 - blend, 0, 0, SK_Scalar1 - blend); michael@0: value->fOperand.fScalar = min + SkScalarMul(max - min, relativeT); michael@0: value->fType = SkType_Float; michael@0: return true; michael@0: } michael@0: default: michael@0: SkASSERT(0); michael@0: } michael@0: return false; michael@0: } michael@0: michael@0: bool SkDisplayRandom::setProperty(int index, SkScriptValue& value) { michael@0: SkASSERT(index == SK_PROPERTY(seed)); michael@0: SkASSERT(value.fType == SkType_Int); michael@0: fRandom.setSeed(value.fOperand.fS32); michael@0: return true; michael@0: }