Samples: clean up cruft
- replace virtual with override.
- remove default constructor.
- use default field initializers
- move work from constructor into onOnceBeforeDraw
- mark everything private
- enum { N = 100 }; constants to constexpr
- remove unused variables
Change-Id: I8c7a19bc24fec416a6b88d634ee948d3e842b986
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/228056
Commit-Queue: Ben Wagner <bungeman@google.com>
Auto-Submit: Hal Canary <halcanary@google.com>
Reviewed-by: Ben Wagner <bungeman@google.com>
diff --git a/samplecode/SampleCowboy.cpp b/samplecode/SampleCowboy.cpp
index db60229..6ba3177 100644
--- a/samplecode/SampleCowboy.cpp
+++ b/samplecode/SampleCowboy.cpp
@@ -20,37 +20,36 @@
#include "tools/Resources.h"
namespace {
-
-class CowboyView : public Sample {
-public:
- CowboyView()
- : fLabel("SampleCowboy")
- , fState(kZoomIn)
- , fAnimationLoop(kAnimationIterations)
- , fDelta(1) {}
- ~CowboyView() override = default;
-
-protected:
+class AnimatedSVGSample : public Sample {
static constexpr auto kAnimationIterations = 5;
-
enum State {
kZoomIn,
kScroll,
kZoomOut
};
+ sk_sp<SkSVGDOM> fDom;
+ const char* fResource = nullptr;
+ const char* fName = nullptr;
+ State fState = kZoomIn;
+ int fAnimationLoop = kAnimationIterations;
+ SkScalar fDelta = 1;
+public:
+ AnimatedSVGSample(const char* r, const char* n) : fResource(r), fName(n) {}
+
+private:
void onOnceBeforeDraw() override {
- constexpr char path[] = "Cowboy.svg";
- auto data = GetResourceAsData(path);
+ SkASSERT(fResource);
+ auto data = GetResourceAsData(fResource);
if (!data) {
- SkDebugf("file not found: \"%s\"\n", path);
+ SkDebugf("Resource not found: \"%s\"\n", fResource);
return;
}
SkMemoryStream svgStream(std::move(data));
SkDOM xmlDom;
if (!xmlDom.build(svgStream)) {
- SkDebugf("XML parsing failed: \"path\"\n", fPath.c_str());
+ SkDebugf("XML parsing failed: \"%s\"\n", fResource);
return;
}
@@ -92,11 +91,9 @@
if (fDom) {
fDom->setContainerSize(SkSize::Make(this->width(), this->height()));
}
-
- this->INHERITED::onSizeChange();
}
- SkString name() override { return fLabel; }
+ SkString name() override { return SkASSERT(fName), SkString(fName); }
bool onAnimate(double nanos) override {
if (!fDom) {
@@ -123,20 +120,9 @@
}
return true;
}
-
-private:
- sk_sp<SkSVGDOM> fDom;
- SkString fPath;
- SkString fLabel;
- State fState;
- int fAnimationLoop;
- SkScalar fDelta;
-
- typedef Sample INHERITED;
};
+} // namespace
-} // anonymous namespace
-
-DEF_SAMPLE( return new CowboyView(); )
+DEF_SAMPLE( return new AnimatedSVGSample("Cowboy.svg", "SampleCowboy"); )
#endif // SK_XML