git-svn-id: http://skia.googlecode.com/svn/trunk@685 2bbb7eff-a529-9590-31e7-b0007b416f81
authorreed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Tue, 11 Jan 2011 19:45:38 +0000 (19:45 +0000)
committerreed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Tue, 11 Jan 2011 19:45:38 +0000 (19:45 +0000)
samplecode/SampleGM.cpp
src/core/SkCanvas.cpp

index d85cad1..5c9ea76 100644 (file)
@@ -15,6 +15,10 @@ public:
         fReg = GMRegistry::Head();
     }
        
+    void reset() {
+        fReg = GMRegistry::Head();
+    }
+        
     GM* next() {
         if (fReg) {
             GMRegistry::Factory fact = fReg->factory();
@@ -46,6 +50,7 @@ class GMView : public SkView {
 public:
        GMView() {
         fGM = fIter.next();
+        this->postNextGM();
     }
     
 protected:
@@ -58,6 +63,20 @@ protected:
         return this->INHERITED::onQuery(evt);
     }
 
+    virtual bool onEvent(const SkEvent& evt) {
+        if (evt.isType("next-gm")) {
+            delete fGM;
+            if (!(fGM = fIter.next())) {
+                fIter.reset();
+                fGM = fIter.next();
+            }
+            this->inval(NULL);
+            this->postNextGM();
+            return true;
+        }
+        return this->INHERITED::onEvent(evt);
+    }
+
     void drawBG(SkCanvas* canvas) {
         canvas->drawColor(0xFFDDDDDD);
     }
@@ -67,6 +86,10 @@ protected:
     }
     
 private:
+    void postNextGM() {
+        (new SkEvent("next-gm"))->post(this->getSinkID(), 1500);
+    }
+
     typedef SkView INHERITED;
 };
 
index 8f53621..a88a22a 100644 (file)
@@ -560,6 +560,7 @@ bool SkCanvas::readPixels(const SkIRect& srcRect, SkBitmap* bitmap) {
 SkDeviceFactory* SkCanvas::setDeviceFactory(SkDeviceFactory* factory) {
     SkDELETE(fDeviceFactory);
     fDeviceFactory = factory;
+    return factory;
 }
 
 //////////////////////////////////////////////////////////////////////////////