void onDrawContent(SkCanvas *canvas) override { canvas->save(); canvas->resetMatrix(); // Force static control panel position fControlPanel.drawContent(canvas); canvas->restore(); SkLights::Builder builder; for (int i = 0; i < kNumLights; i++) { builder.add(SkLights::Light::MakeDirectional(fLightDefs[i].fColor, SkPoint3::Make(fLightDefs[i].fDirXY.fX, fLightDefs[i].fDirXY.fY, fLightDefs[i].fDirZ))); } builder.setAmbientLightColor(SkColor3f::Make(0.4f, 0.4f, 0.4f)); fLights = builder.finish(); // Draw shapes SkScalar xPos = kCtrlRange + 25.0f; SkScalar yPos = fShapeBounds.height(); for (Shape shape : { kCircle_Shape, kRect_Shape }) { canvas->save(); canvas->translate(xPos, yPos); this->drawShape(shape, canvas); canvas->restore(); xPos += 1.2f * fShapeBounds.width(); } }
sk_sp<SkLights> SkLights::makeColorSpace(SkColorSpaceXformer* xformer) const { SkLights::Builder builder; for (int i = 0; i < this->numLights(); i++) { Light light(fLights[i].type(), xform_color(fLights[i].color(), xformer), fLights[i].fDirOrPos, fLights[i].fIntensity); builder.add(light); } builder.setAmbientLightColor(xform_color(fAmbientLightColor, xformer)); return builder.finish(); }
static sk_sp<SkLights> create_lights(SkScalar angle, SkScalar blue) { const SkVector3 dir = SkVector3::Make(SkScalarSin(angle)*SkScalarSin(SK_ScalarPI*0.25f), SkScalarCos(angle)*SkScalarSin(SK_ScalarPI*0.25f), SkScalarCos(SK_ScalarPI*0.25f)); SkLights::Builder builder; builder.add(SkLights::Light::MakeDirectional(SkColor3f::Make(1.0f, 1.0f, blue), dir)); builder.setAmbientLightColor(SkColor3f::Make(0.1f, 0.1f, 0.1f)); return builder.finish(); }