- allow for stepping through a picture with 'n' and 'p'
authorreed <reed@chromium.org>
Wed, 5 Aug 2015 01:46:38 +0000 (18:46 -0700)
committerCommit bot <commit-bot@chromium.org>
Wed, 5 Aug 2015 01:46:38 +0000 (18:46 -0700)
- save current slide as .skp with 'K'

BUG=skia:
TBR=

Review URL: https://codereview.chromium.org/1272063002

samplecode/SampleApp.cpp
samplecode/SampleApp.h
samplecode/SamplePictFile.cpp

index 318a8224c0adeb075e55379953abd1666ce2b034..2d12bfd67293bbaccc9107befbdb11d3ad6e317a 100644 (file)
@@ -823,9 +823,7 @@ SampleWindow::SampleWindow(void* hwnd, int argc, char** argv, DeviceManager* dev
     fMagnify = false;
 
     fSaveToPdf = false;
-
-    fTransitionNext = 6;
-    fTransitionPrev = 2;
+    fSaveToSKP = false;
 
     int sinkID = this->getSinkID();
     fAppMenu = new SkOSMenu;
@@ -888,16 +886,7 @@ SampleWindow::SampleWindow(void* hwnd, int argc, char** argv, DeviceManager* dev
     fAppMenu->assignKeyEquivalentToItem(itemID, 'z');
     itemID = fAppMenu->appendSwitch("Magnify", "Magnify" , sinkID, fMagnify);
     fAppMenu->assignKeyEquivalentToItem(itemID, 'm');
-    itemID =fAppMenu->appendList("Transition-Next", "Transition-Next", sinkID,
-                                fTransitionNext, "Up", "Up and Right", "Right",
-                                "Down and Right", "Down", "Down and Left",
-                                "Left", "Up and Left", NULL);
-    fAppMenu->assignKeyEquivalentToItem(itemID, 'j');
-    itemID =fAppMenu->appendList("Transition-Prev", "Transition-Prev", sinkID,
-                                fTransitionPrev, "Up", "Up and Right", "Right",
-                                "Down and Right", "Down", "Down and Left",
-                                "Left", "Up and Left", NULL);
-    fAppMenu->assignKeyEquivalentToItem(itemID, 'k');
+
     itemID = fAppMenu->appendAction("Save to PDF", sinkID);
     fAppMenu->assignKeyEquivalentToItem(itemID, 'e');
 
@@ -1259,6 +1248,12 @@ void SampleWindow::afterChildren(SkCanvas* orig) {
     if (kPicture_DeviceType == fDeviceType) {
         SkAutoTUnref<const SkPicture> picture(fRecorder.endRecording());
 
+        if (fSaveToSKP) {
+            SkFILEWStream stream("sample_app.skp");
+            picture->serialize(&stream);
+            fSaveToSKP = false;
+        }
+
         if (true) {
             if (true) {
                 SkImageInfo info;
@@ -1496,9 +1491,8 @@ bool SampleWindow::onEvent(const SkEvent& evt) {
         SkOSMenu::FindListIndex(evt, "Hinting", &fHintingState) ||
         SkOSMenu::FindSwitchState(evt, "Clip", &fUseClip) ||
         SkOSMenu::FindSwitchState(evt, "Zoomer", &fShowZoomer) ||
-        SkOSMenu::FindSwitchState(evt, "Magnify", &fMagnify) ||
-        SkOSMenu::FindListIndex(evt, "Transition-Next", &fTransitionNext) ||
-        SkOSMenu::FindListIndex(evt, "Transition-Prev", &fTransitionPrev)) {
+        SkOSMenu::FindSwitchState(evt, "Magnify", &fMagnify))
+    {
         this->inval(NULL);
         this->updateTitle();
         return true;
@@ -1653,6 +1647,10 @@ bool SampleWindow::onHandleChar(SkUnichar uni) {
             this->inval(NULL);
             this->updateTitle();
             return true;
+        case 'K':
+            fSaveToSKP = true;
+            this->inval(NULL);
+            return true;
 #if SK_SUPPORT_GPU
         case 'p':
             {
index 32581931100c73e0d5007132e0bc8569c99eee49..97854fcb972170caaf43208a75701e8053f8e3ac 100644 (file)
@@ -174,6 +174,7 @@ private:
     DeviceManager* fDevManager;
 
     bool fSaveToPdf;
+    bool fSaveToSKP;
     SkAutoTUnref<SkDocument> fPDFDocument;
 
     bool fUseClip;
@@ -218,9 +219,6 @@ private:
     //Stores slide specific settings
     SkOSMenu* fSlideMenu; // We pass ownership to SkWindow, when we call addMenu
 
-    int fTransitionNext;
-    int fTransitionPrev;
-
     void loadView(SkView*);
     void updateTitle();
     bool getRawTitle(SkString*);
index a0bab7da4ebd016f45097dd645a729bc4f1325ec..c0973a5042697e2a40ae88e16bd251eb7fc117e3 100644 (file)
 
 #include "SkGlyphCache.h"
 
+#include "SkDrawFilter.h"
+class SkCounterDrawFilter : public SkDrawFilter {
+public:
+    SkCounterDrawFilter(int count) : fCount(count) {}
+
+    bool filter(SkPaint*, Type t) override {
+        return --fCount >= 0;
+    }
+
+    int fCount;
+};
+
 class PictFileView : public SampleView {
 public:
     PictFileView(const char name[] = NULL)
@@ -41,6 +53,7 @@ public:
         for (int i = 0; i < kBBoxTypeCount; ++i) {
             fPictures[i] = NULL;
         }
+        fCount = 0;
     }
 
     virtual ~PictFileView() {
@@ -76,6 +89,15 @@ protected:
             SampleCode::TitleR(evt, name.c_str());
             return true;
         }
+        SkUnichar uni;
+        if (SampleCode::CharQ(*evt, &uni)) {
+            switch (uni) {
+                case 'n': fCount += 1; this->inval(nullptr); return true;
+                case 'p': fCount -= 1; this->inval(nullptr); return true;
+                case 's': fCount =  0; this->inval(nullptr); return true;
+                default: break;
+            }
+        }
         return this->INHERITED::onQuery(evt);
     }
 
@@ -99,7 +121,12 @@ protected:
             *picture = LoadPicture(fFilename.c_str(), fBBox);
         }
         if (*picture) {
+            SkCounterDrawFilter filter(fCount);
+            if (fCount > 0) {
+                canvas->setDrawFilter(&filter);
+            }
             canvas->drawPicture(*picture);
+            canvas->setDrawFilter(NULL);
         }
 
 #ifdef SK_GLYPHCACHE_TRACK_HASH_STATS
@@ -121,6 +148,7 @@ private:
     SkPicture*  fPictures[kBBoxTypeCount];
     BBoxType    fBBox;
     SkSize      fTileSize;
+    int         fCount;
 
     SkPicture* LoadPicture(const char path[], BBoxType bbox) {
         SkAutoTUnref<SkPicture> pic;